From aa4a242f534008d4d4d3179e19a94f58eca5184b Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 6 Nov 2012 17:30:23 +0000 Subject: [PATCH] Modern objective-C translator: Start adding line info to the translated source where it is needed. wip. llvm-svn: 167469 --- clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp b/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp index 245e809..005020d 100644 --- a/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp +++ b/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp @@ -278,6 +278,7 @@ namespace { // Syntactic Rewriting. void RewriteRecordBody(RecordDecl *RD); void RewriteInclude(); + void RewriteLineDirective(const Decl *D); void RewriteForwardClassDecl(DeclGroupRef D); void RewriteForwardClassDecl(const llvm::SmallVector &DG); void RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl, @@ -3075,6 +3076,34 @@ static SourceLocation getFunctionSourceLocation (RewriteModernObjC &R, return FD->getTypeSpecStartLoc(); } +void RewriteModernObjC::RewriteLineDirective(const Decl *D) { + + SourceLocation Location = D->getLocation(); + + if (Location.isFileID()) { + std::string LineString("#line "); + PresumedLoc PLoc = SM->getPresumedLoc(Location); + LineString += utostr(PLoc.getLine()); + LineString += " \""; + LineString += PLoc.getFilename(); + if (isa(D)) + LineString += "\""; + else LineString += "\"\n"; + + Location = D->getLocStart(); + if (const FunctionDecl *FD = dyn_cast(D)) { + if (FD->isExternC() && !FD->isMain()) { + const DeclContext *DC = FD->getDeclContext(); + if (const LinkageSpecDecl *LSD = dyn_cast(DC)) + // if it is extern "C" {...}, return function decl's own location. + if (!LSD->getRBraceLoc().isValid()) + Location = LSD->getExternLoc(); + } + } + InsertText(Location, LineString); + } +} + /// SynthMsgSendStretCallExpr - This routine translates message expression /// into a call to objc_msgSend_stret() entry point. Tricky part is that /// nil check on receiver must be performed before calling objc_msgSend_stret. @@ -5664,6 +5693,7 @@ void RewriteModernObjC::HandleDeclInMainFile(Decl *D) { // This synthesizes and inserts the block "impl" struct, invoke function, // and any copy/dispose helper functions. InsertBlockLiteralsWithinFunction(FD); + RewriteLineDirective(D); CurFunctionDef = 0; } break; @@ -5682,6 +5712,7 @@ void RewriteModernObjC::HandleDeclInMainFile(Decl *D) { PropParentMap = 0; } InsertBlockLiteralsWithinMethod(MD); + RewriteLineDirective(D); CurMethodDef = 0; } break; -- 2.7.4