llvm.org GIT mirror llvm / e45a5dc
Merging r142132: ------------------------------------------------------------------------ r142132 | d0k | 2011-10-16 03:48:29 -0700 (Sun, 16 Oct 2011) | 3 lines PR11143: Save the old diagnostic handler and call it when munging diagnostics for #line directives. This reenables proper inline asm diagnostics in clang ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_30@142156 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 9 years ago
2 changed file(s) with 43 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
7676 DiagHandler = DH;
7777 DiagContext = Ctx;
7878 }
79
80 DiagHandlerTy getDiagHandler() const { return DiagHandler; }
81 void *getDiagContext() const { return DiagContext; }
7982
8083 const SrcBuffer &getBufferInfo(unsigned i) const {
8184 assert(i < Buffers.size() && "Invalid Buffer ID!");
8686 MCStreamer &Out;
8787 const MCAsmInfo &MAI;
8888 SourceMgr &SrcMgr;
89 SourceMgr::DiagHandlerTy SavedDiagHandler;
90 void *SavedDiagContext;
8991 MCAsmParserExtension *GenericParser;
9092 MCAsmParserExtension *PlatformParser;
9193
141143 virtual MCContext &getContext() { return Ctx; }
142144 virtual MCStreamer &getStreamer() { return Out; }
143145
144 virtual bool Warning(SMLoc L, const Twine &Msg);
145 virtual bool Error(SMLoc L, const Twine &Msg);
146 virtual bool Warning(SMLoc L, const Twine &Msg,
147 ArrayRef Ranges = ArrayRef());
148 virtual bool Error(SMLoc L, const Twine &Msg,
149 ArrayRef Ranges = ArrayRef());
146150
147151 const AsmToken &Lex();
148152
168172 void HandleMacroExit();
169173
170174 void PrintMacroInstantiations();
171 void PrintMessage(SMLoc Loc, const Twine &Msg, const char *Type,
172 bool ShowLine = true) const {
173 SrcMgr.PrintMessage(Loc, Msg, Type, ShowLine);
175 void PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind, const Twine &Msg,
176 ArrayRef Ranges = ArrayRef()) const {
177 SrcMgr.PrintMessage(Loc, Kind, Msg, Ranges);
174178 }
175179 static void DiagHandler(const SMDiagnostic &Diag, void *Context);
176180
350354 : Lexer(_MAI), Ctx(_Ctx), Out(_Out), MAI(_MAI), SrcMgr(_SM),
351355 GenericParser(new GenericAsmParser), PlatformParser(0),
352356 CurBuffer(0), MacrosEnabled(true), CppHashLineNumber(0) {
357 // Save the old handler.
358 SavedDiagHandler = SrcMgr.getDiagHandler();
359 SavedDiagContext = SrcMgr.getDiagContext();
360 // Set our own handler which calls the saved handler.
353361 SrcMgr.setDiagHandler(DiagHandler, this);
354362 Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer));
355363
388396 // Print the active macro instantiation stack.
389397 for (std::vector::const_reverse_iterator
390398 it = ActiveMacros.rbegin(), ie = ActiveMacros.rend(); it != ie; ++it)
391 PrintMessage((*it)->InstantiationLoc, "while in macro instantiation",
392 "note");
393 }
394
395 bool AsmParser::Warning(SMLoc L, const Twine &Msg) {
399 PrintMessage((*it)->InstantiationLoc, SourceMgr::DK_Note,
400 "while in macro instantiation");
401 }
402
403 bool AsmParser::Warning(SMLoc L, const Twine &Msg, ArrayRef Ranges) {
396404 if (FatalAssemblerWarnings)
397 return Error(L, Msg);
398 PrintMessage(L, Msg, "warning");
405 return Error(L, Msg, Ranges);
406 PrintMessage(L, SourceMgr::DK_Warning, Msg, Ranges);
399407 PrintMacroInstantiations();
400408 return false;
401409 }
402410
403 bool AsmParser::Error(SMLoc L, const Twine &Msg) {
411 bool AsmParser::Error(SMLoc L, const Twine &Msg, ArrayRef Ranges) {
404412 HadError = true;
405 PrintMessage(L, Msg, "error");
413 PrintMessage(L, SourceMgr::DK_Error, Msg, Ranges);
406414 PrintMacroInstantiations();
407415 return true;
408416 }
494502 // FIXME: We would really like to refer back to where the symbol was
495503 // first referenced for a source location. We need to add something
496504 // to track that. Currently, we just point to the end of the file.
497 PrintMessage(getLexer().getLoc(), "assembler local symbol '" +
498 Sym->getName() + "' not defined", "error", false);
505 PrintMessage(getLexer().getLoc(), SourceMgr::DK_Error,
506 "assembler local symbol '" + Sym->getName() +
507 "' not defined");
499508 }
500509 }
501510
11981207 }
11991208 OS << "]";
12001209
1201 PrintMessage(IDLoc, OS.str(), "note");
1210 PrintMessage(IDLoc, SourceMgr::DK_Note, OS.str());
12021211 }
12031212
12041213 // If parsing succeeded, match the instruction.
12721281 // Like SourceMgr::PrintMessage() we need to print the include stack if any
12731282 // before printing the message.
12741283 int DiagCurBuffer = DiagSrcMgr.FindBufferContainingLoc(DiagLoc);
1275 if (DiagCurBuffer > 0) {
1284 if (!Parser->SavedDiagHandler && DiagCurBuffer > 0) {
12761285 SMLoc ParentIncludeLoc = DiagSrcMgr.getParentIncludeLoc(DiagCurBuffer);
12771286 DiagSrcMgr.PrintIncludeStack(ParentIncludeLoc, OS);
12781287 }
12831292 if (!Parser->CppHashLineNumber ||
12841293 &DiagSrcMgr != &Parser->SrcMgr ||
12851294 DiagBuf != CppHashBuf) {
1286 Diag.Print(0, OS);
1295 if (Parser->SavedDiagHandler)
1296 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
1297 else
1298 Diag.print(0, OS);
12871299 return;
12881300 }
12891301
12981310 int LineNo = Parser->CppHashLineNumber - 1 +
12991311 (DiagLocLineNo - CppHashLocLineNo);
13001312
1301 SMDiagnostic NewDiag(*Diag.getSourceMgr(),
1302 Diag.getLoc(),
1303 Filename,
1304 LineNo,
1305 Diag.getColumnNo(),
1306 Diag.getMessage(),
1307 Diag.getLineContents(),
1308 Diag.getShowLine());
1309
1310 NewDiag.Print(0, OS);
1313 SMDiagnostic NewDiag(*Diag.getSourceMgr(), Diag.getLoc(),
1314 Filename, LineNo, Diag.getColumnNo(),
1315 Diag.getKind(), Diag.getMessage(),
1316 Diag.getLineContents(), Diag.getRanges());
1317
1318 if (Parser->SavedDiagHandler)
1319 Parser->SavedDiagHandler(NewDiag, Parser->SavedDiagContext);
1320 else
1321 NewDiag.print(0, OS);
13111322 }
13121323
13131324 bool AsmParser::expandMacro(SmallString<256> &Buf, StringRef Body,