r174684 - objective-C modern translator. Generate #line
Fariborz Jahanian
fjahanian at apple.com
Thu Feb 7 16:27:35 PST 2013
Author: fjahanian
Date: Thu Feb 7 18:27:34 2013
New Revision: 174684
URL: http://llvm.org/viewvc/llvm-project?rev=174684&view=rev
Log:
objective-C modern translator. Generate #line
info in the translated code under -g only.
// rdar://13138170
Added:
cfe/trunk/test/Rewriter/line-generation-test.m
Modified:
cfe/trunk/include/clang/Rewrite/Frontend/ASTConsumers.h
cfe/trunk/lib/Rewrite/Frontend/FrontendActions.cpp
cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp
Modified: cfe/trunk/include/clang/Rewrite/Frontend/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/Frontend/ASTConsumers.h?rev=174684&r1=174683&r2=174684&view=diff
==============================================================================
--- cfe/trunk/include/clang/Rewrite/Frontend/ASTConsumers.h (original)
+++ cfe/trunk/include/clang/Rewrite/Frontend/ASTConsumers.h Thu Feb 7 18:27:34 2013
@@ -35,7 +35,8 @@ ASTConsumer *CreateModernObjCRewriter(co
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.
Modified: cfe/trunk/lib/Rewrite/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Frontend/FrontendActions.cpp?rev=174684&r1=174683&r2=174684&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Rewrite/Frontend/FrontendActions.cpp Thu Feb 7 18:27:34 2013
@@ -158,7 +158,9 @@ ASTConsumer *RewriteObjCAction::CreateAS
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);
Modified: cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp?rev=174684&r1=174683&r2=174684&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp Thu Feb 7 18:27:34 2013
@@ -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::stri
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::CreateModernObjCRewr
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::RewriteBreakStm
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::RewriteLineDirec
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());
Added: cfe/trunk/test/Rewriter/line-generation-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/line-generation-test.m?rev=174684&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/line-generation-test.m (added)
+++ cfe/trunk/test/Rewriter/line-generation-test.m Thu Feb 7 18:27:34 2013
@@ -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 {
+ at public
+ id _myMaster;
+ id _isTickledPink;
+}
+ at property(retain) id myMaster;
+ at property(assign) id isTickledPink;
+ at end
+
+ at implementation MyObject
+
+ at synthesize myMaster = _myMaster;
+ at synthesize isTickledPink = _isTickledPink;
+
+- (void) doSomething {
+ _myMaster = _isTickledPink;
+}
+
+ at 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
+
More information about the cfe-commits
mailing list