]> granicus.if.org Git - clang/commitdiff
objective-C modern translator. Generate #line
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 8 Feb 2013 00:27:34 +0000 (00:27 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 8 Feb 2013 00:27:34 +0000 (00:27 +0000)
info in the translated code under -g only.
// rdar://13138170

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174684 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Rewrite/Frontend/ASTConsumers.h
lib/Rewrite/Frontend/FrontendActions.cpp
lib/Rewrite/Frontend/RewriteModernObjC.cpp
test/Rewriter/line-generation-test.m [new file with mode: 0644]

index c9c92e3a0188af259cb3a56f3fca493c860fd7aa..584af3fa18b0523f4e0680c74a0a1a84ae9b5142 100644 (file)
@@ -35,7 +35,8 @@ ASTConsumer *CreateModernObjCRewriter(const std::string &InFile,
                                 raw_ostream *OS,
                                 DiagnosticsEngine &Diags,
                                 const LangOptions &LOpts,
-                                bool SilenceRewriteMacroWarning);
+                                bool SilenceRewriteMacroWarning,
+                                bool LineInfo);
 
 /// CreateHTMLPrinter - Create an AST consumer which rewrites source code to
 /// HTML with syntax highlighting suitable for viewing in a web-browser.
index 2e18be93207e808a5dfc4457ad4f34b78956e845..9935aeb63e58037826f7faea9adfb205af12c264 100644 (file)
@@ -158,7 +158,9 @@ ASTConsumer *RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI,
     if (CI.getLangOpts().ObjCRuntime.isNonFragile())
       return CreateModernObjCRewriter(InFile, OS,
                                 CI.getDiagnostics(), CI.getLangOpts(),
-                                CI.getDiagnosticOpts().NoRewriteMacros);
+                                CI.getDiagnosticOpts().NoRewriteMacros,
+                                (CI.getCodeGenOpts().getDebugInfo() !=
+                                 CodeGenOptions::NoDebugInfo));
     return CreateObjCRewriter(InFile, OS,
                               CI.getDiagnostics(), CI.getLangOpts(),
                               CI.getDiagnosticOpts().NoRewriteMacros);
index a3a4afc6bbb3404d7ab6ac866d62a13d9521f466..68babb4ef00d20e799d3d8e65acb2cf39d36689f 100644 (file)
@@ -163,6 +163,7 @@ namespace {
     // Needed for header files being rewritten
     bool IsHeader;
     bool SilenceRewriteMacroWarning;
+    bool GenerateLineInfo;
     bool objc_impl_method;
     
     bool DisableReplaceStmt;
@@ -224,7 +225,7 @@ namespace {
     void HandleDeclInMainFile(Decl *D);
     RewriteModernObjC(std::string inFile, raw_ostream *OS,
                 DiagnosticsEngine &D, const LangOptions &LOpts,
-                bool silenceMacroWarn);
+                bool silenceMacroWarn, bool LineInfo);
     
     ~RewriteModernObjC() {}
     
@@ -633,9 +634,10 @@ static bool IsHeaderFile(const std::string &Filename) {
 
 RewriteModernObjC::RewriteModernObjC(std::string inFile, raw_ostream* OS,
                          DiagnosticsEngine &D, const LangOptions &LOpts,
-                         bool silenceMacroWarn)
+                         bool silenceMacroWarn,
+                         bool LineInfo)
       : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(OS),
-        SilenceRewriteMacroWarning(silenceMacroWarn) {
+        SilenceRewriteMacroWarning(silenceMacroWarn), GenerateLineInfo(LineInfo) {
   IsHeader = IsHeaderFile(inFile);
   RewriteFailedDiag = Diags.getCustomDiagID(DiagnosticsEngine::Warning,
                "rewriting sub-expression within a macro (may not be correct)");
@@ -654,8 +656,10 @@ ASTConsumer *clang::CreateModernObjCRewriter(const std::string& InFile,
                                        raw_ostream* OS,
                                        DiagnosticsEngine &Diags,
                                        const LangOptions &LOpts,
-                                       bool SilenceRewriteMacroWarning) {
-    return new RewriteModernObjC(InFile, OS, Diags, LOpts, SilenceRewriteMacroWarning);
+                                       bool SilenceRewriteMacroWarning,
+                                       bool LineInfo) {
+    return new RewriteModernObjC(InFile, OS, Diags, LOpts,
+                                 SilenceRewriteMacroWarning, LineInfo);
 }
 
 void RewriteModernObjC::InitializeCommon(ASTContext &context) {
@@ -1654,7 +1658,7 @@ Stmt *RewriteModernObjC::RewriteBreakStmt(BreakStmt *S) {
 void RewriteModernObjC::ConvertSourceLocationToLineDirective(
                                           SourceLocation Loc,
                                           std::string &LineString) {
-  if (Loc.isFileID()) {
+  if (Loc.isFileID() && GenerateLineInfo) {
     LineString += "\n#line ";
     PresumedLoc PLoc = SM->getPresumedLoc(Loc);
     LineString += utostr(PLoc.getLine());
@@ -3147,7 +3151,7 @@ void RewriteModernObjC::RewriteLineDirective(const Decl *D) {
   
   SourceLocation Location = D->getLocation();
   
-  if (Location.isFileID()) {
+  if (Location.isFileID() && GenerateLineInfo) {
     std::string LineString("\n#line ");
     PresumedLoc PLoc = SM->getPresumedLoc(Location);
     LineString += utostr(PLoc.getLine());
diff --git a/test/Rewriter/line-generation-test.m b/test/Rewriter/line-generation-test.m
new file mode 100644 (file)
index 0000000..dad7371
--- /dev/null
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -E %s -o %t.mm
+// RUN: %clang_cc1 -fms-extensions -rewrite-objc -g %t.mm -o %t-rw.cpp
+// RUN: FileCheck  -check-prefix LINE --input-file=%t-rw.cpp %s
+// RUN: %clang_cc1 -fms-extensions -rewrite-objc %t.mm -o %t-rwnog.cpp
+// RUN: FileCheck  -check-prefix NOLINE --input-file=%t-rwnog.cpp %s
+// rdar://13138170
+
+__attribute__((objc_root_class)) @interface MyObject {
+@public
+    id _myMaster;
+    id _isTickledPink;
+}
+@property(retain) id myMaster;
+@property(assign) id isTickledPink;
+@end
+
+@implementation MyObject
+
+@synthesize myMaster = _myMaster;
+@synthesize isTickledPink = _isTickledPink;
+
+- (void) doSomething {
+    _myMaster = _isTickledPink;
+}
+
+@end
+
+MyObject * foo ()
+{
+       MyObject* p;
+        p.isTickledPink = p.myMaster;  // ok
+       p->_isTickledPink = p->_myMaster;
+       return p->_isTickledPink;
+}
+
+// CHECK-LINE: #line 22
+// CHECK-LINE: #line 28
+// CHECK-NOLINE-NOT: #line 22
+// CHECK-NOLINE-NOT: #line 28
+