From: Ted Kremenek Date: Tue, 11 Dec 2007 21:27:55 +0000 (+0000) Subject: Mega-patch: ripped SourceManager out of Diagnostic/DiagnosticClient. Now X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a9d49fd2bfac00e905b361ba76d26ab5b6c3b09;p=clang Mega-patch: ripped SourceManager out of Diagnostic/DiagnosticClient. Now SourceManager is passed by reference, allowing the SourceManager to be associated with a specific translation unit, and not the entire execution of the driver. Modified all users of Diagnostics to comply with this new interface. Integrated SourceManager as a member variable of TargetInfo. TargetInfo will eventually be associated with a single translation unit (just like SourceManager). Made the SourceManager reference in ASTContext private. Provided accessor getSourceManager() for clients to use instead. Modified clients to comply with new interface. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44878 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/DeadStores.cpp b/Analysis/DeadStores.cpp index 658fe949a8..80e5ba7b48 100644 --- a/Analysis/DeadStores.cpp +++ b/Analysis/DeadStores.cpp @@ -41,7 +41,7 @@ public: if (VD->hasLocalStorage() && !Live(VD,AD)) { SourceRange R = B->getRHS()->getSourceRange(); Diags.Report(DR->getSourceRange().getBegin(), diag::warn_dead_store, - 0, 0, &R, 1); + Ctx.getSourceManager(), 0, 0, &R, 1); } } else if(DeclStmt* DS = dyn_cast(S)) @@ -62,8 +62,8 @@ public: if (!E->isConstantExpr(Ctx,NULL)) { // Flag a warning. SourceRange R = E->getSourceRange(); - Diags.Report(V->getLocation(), diag::warn_dead_store, 0, 0, - &R,1); + Diags.Report(V->getLocation(), diag::warn_dead_store, + Ctx.getSourceManager(), 0, 0, &R, 1); } } } diff --git a/Analysis/UninitializedValues.cpp b/Analysis/UninitializedValues.cpp index 35d6124e62..4e2969659d 100644 --- a/Analysis/UninitializedValues.cpp +++ b/Analysis/UninitializedValues.cpp @@ -222,7 +222,8 @@ public: if (V(VD,AD) == Uninitialized) if (AlreadyWarned.insert(VD)) - Diags.Report(DR->getSourceRange().getBegin(), diag::warn_uninit_val); + Diags.Report(DR->getSourceRange().getBegin(), diag::warn_uninit_val, + Ctx.getSourceManager()); } }; } // end anonymous namespace diff --git a/Basic/Diagnostic.cpp b/Basic/Diagnostic.cpp index b5853a2531..399419b85e 100644 --- a/Basic/Diagnostic.cpp +++ b/Basic/Diagnostic.cpp @@ -198,6 +198,7 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const { /// compilation, return true, otherwise return false. DiagID is a member of /// the diag::kind enum. void Diagnostic::Report(SourceLocation Pos, unsigned DiagID, + SourceManager& SrcMgr, const std::string *Strs, unsigned NumStrs, const SourceRange *Ranges, unsigned NumRanges) { // Figure out the diagnostic level of this message. @@ -213,11 +214,11 @@ void Diagnostic::Report(SourceLocation Pos, unsigned DiagID, } // Are we going to ignore this diagnosic? - if (Client.IgnoreDiagnostic(DiagLevel, Pos)) + if (Client.IgnoreDiagnostic(DiagLevel, Pos, SrcMgr)) return; // Finally, report it. - Client.HandleDiagnostic(*this, DiagLevel, Pos, (diag::kind)DiagID, + Client.HandleDiagnostic(*this, DiagLevel, Pos, (diag::kind)DiagID, SrcMgr, Strs, NumStrs, Ranges, NumRanges); ++NumDiagnostics; } diff --git a/Basic/TargetInfo.cpp b/Basic/TargetInfo.cpp index fcaeccffc0..63b3cf8462 100644 --- a/Basic/TargetInfo.cpp +++ b/Basic/TargetInfo.cpp @@ -65,7 +65,7 @@ const char *TargetInfo::getTargetPrefix() const { /// non-portable. void TargetInfo::DiagnoseNonPortability(SourceLocation Loc, unsigned DiagKind) { NonPortable = true; - if (Diag && Loc.isValid()) Diag->Report(Loc, DiagKind); + if (Diag && Loc.isValid()) Diag->Report(Loc, DiagKind, SrcMgr); } /// GetTargetDefineMap - Get the set of target #defines in an associative diff --git a/CodeGen/CGExprComplex.cpp b/CodeGen/CGExprComplex.cpp index 3368c2801d..6263bb7707 100644 --- a/CodeGen/CGExprComplex.cpp +++ b/CodeGen/CGExprComplex.cpp @@ -67,7 +67,7 @@ public: //===--------------------------------------------------------------------===// ComplexPairTy VisitStmt(Stmt *S) { - S->dump(CGF.getContext().SourceMgr); + S->dump(CGF.getContext().getSourceManager()); assert(0 && "Stmt can't have complex result type!"); return ComplexPairTy(); } diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp index d088195db9..9846d81d1e 100644 --- a/CodeGen/CGExprScalar.cpp +++ b/CodeGen/CGExprScalar.cpp @@ -85,7 +85,7 @@ public: //===--------------------------------------------------------------------===// Value *VisitStmt(Stmt *S) { - S->dump(CGF.getContext().SourceMgr); + S->dump(CGF.getContext().getSourceManager()); assert(0 && "Stmt can't have complex result type!"); return 0; } diff --git a/CodeGen/CodeGenModule.cpp b/CodeGen/CodeGenModule.cpp index bd4df467f6..cc8ecd585b 100644 --- a/CodeGen/CodeGenModule.cpp +++ b/CodeGen/CodeGenModule.cpp @@ -40,7 +40,8 @@ void CodeGenModule::WarnUnsupported(const Stmt *S, const char *Type) { "cannot codegen this %0 yet"); SourceRange Range = S->getSourceRange(); std::string Msg = Type; - getDiags().Report(S->getLocStart(), DiagID, &Msg, 1, &Range, 1); + getDiags().Report(S->getLocStart(), DiagID, Context.getSourceManager(), + &Msg, 1, &Range, 1); } /// ReplaceMapValuesWith - This is a really slow and bad function that diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index 5cd3f77562..85140bc060 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -356,7 +356,7 @@ namespace { ASTDumper() : DeclPrinter() {} void Initialize(ASTContext &Context, unsigned MainFileID) { - SM = &Context.SourceMgr; + SM = &Context.getSourceManager(); } virtual void HandleTopLevelDecl(Decl *D) { @@ -400,7 +400,7 @@ namespace { SourceManager *SM; public: void Initialize(ASTContext &Context, unsigned MainFileID) { - SM = &Context.SourceMgr; + SM = &Context.getSourceManager(); } virtual void HandleTopLevelDecl(Decl *D) { @@ -482,7 +482,7 @@ namespace { SourceManager *SM; public: virtual void Initialize(ASTContext &Context, unsigned MainFileID) { - SM = &Context.SourceMgr; + SM = &Context.getSourceManager(); } virtual void VisitCFG(CFG& C) { diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index 77adafecba..cc10ab0d38 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -64,7 +64,7 @@ namespace { public: void Initialize(ASTContext &context, unsigned mainFileID) { Context = &context; - SM = &Context->SourceMgr; + SM = &Context->getSourceManager(); MsgSendFunctionDecl = 0; MsgSendSuperFunctionDecl = 0; MsgSendStretFunctionDecl = 0; @@ -87,7 +87,7 @@ namespace { MainFileEnd = MainBuf->getBufferEnd(); - Rewrite.setSourceMgr(Context->SourceMgr); + Rewrite.setSourceMgr(Context->getSourceManager()); // declaring objc_selector outside the parameter list removes a silly // scope related warning... const char *s = "struct objc_selector; struct objc_class;\n" @@ -917,7 +917,8 @@ Stmt *RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) { unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error, "rewriter could not replace sub-expression due to macros"); SourceRange Range = Exp->getSourceRange(); - Diags.Report(Exp->getAtLoc(), DiagID, 0, 0, &Range, 1); + Diags.Report(Exp->getAtLoc(), DiagID, Context->getSourceManager(), + 0, 0, &Range, 1); delete Replacement; return Exp; } diff --git a/Driver/Targets.cpp b/Driver/Targets.cpp index 23f8307caa..6e810efd3c 100644 --- a/Driver/Targets.cpp +++ b/Driver/Targets.cpp @@ -702,7 +702,8 @@ static TargetInfoImpl *CreateTarget(const std::string& T) { /// CreateTargetInfo - Return the set of target info objects as specified by /// the -arch command line option. -TargetInfo *clang::CreateTargetInfo(const std::vector& triples, +TargetInfo *clang::CreateTargetInfo(SourceManager& SrcMgr, + const std::vector& triples, Diagnostic *Diags) { assert (!triples.empty() && "No target triple."); @@ -713,7 +714,7 @@ TargetInfo *clang::CreateTargetInfo(const std::vector& triples, if (!PrimaryTarget) return NULL; - TargetInfo *TI = new TargetInfo(PrimaryTarget, Diags); + TargetInfo *TI = new TargetInfo(SrcMgr, PrimaryTarget, Diags); // Add all secondary targets. for (unsigned i = 1, e = triples.size(); i != e; ++i) { diff --git a/Driver/TextDiagnosticBuffer.cpp b/Driver/TextDiagnosticBuffer.cpp index d0e2f900c5..c77801b767 100644 --- a/Driver/TextDiagnosticBuffer.cpp +++ b/Driver/TextDiagnosticBuffer.cpp @@ -21,6 +21,7 @@ void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level Level, SourceLocation Pos, diag::kind ID, + SourceManager& SrcMgr, const std::string *Strs, unsigned NumStrs, const SourceRange *, diff --git a/Driver/TextDiagnosticBuffer.h b/Driver/TextDiagnosticBuffer.h index d155874458..5da37c3e27 100644 --- a/Driver/TextDiagnosticBuffer.h +++ b/Driver/TextDiagnosticBuffer.h @@ -30,7 +30,7 @@ public: private: DiagList Errors, Warnings; public: - TextDiagnosticBuffer(SourceManager &SM) : TextDiagnostics(SM) {} + TextDiagnosticBuffer() {} const_iterator err_begin() const { return Errors.begin(); } const_iterator err_end() const { return Errors.end(); } @@ -40,7 +40,9 @@ public: virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel, SourceLocation Pos, - diag::kind ID, const std::string *Strs, + diag::kind ID, + SourceManager& SrcMgr, + const std::string *Strs, unsigned NumStrs, const SourceRange *Ranges, unsigned NumRanges); diff --git a/Driver/TextDiagnosticPrinter.cpp b/Driver/TextDiagnosticPrinter.cpp index 463a3d7e8e..d2eaacaace 100644 --- a/Driver/TextDiagnosticPrinter.cpp +++ b/Driver/TextDiagnosticPrinter.cpp @@ -31,13 +31,13 @@ NoCaretDiagnostics("fno-caret-diagnostics", " diagnostics")); void TextDiagnosticPrinter:: -PrintIncludeStack(SourceLocation Pos) { +PrintIncludeStack(SourceLocation Pos, SourceManager& SourceMgr) { if (Pos.isInvalid()) return; Pos = SourceMgr.getLogicalLoc(Pos); // Print out the other include frames first. - PrintIncludeStack(SourceMgr.getIncludeLoc(Pos)); + PrintIncludeStack(SourceMgr.getIncludeLoc(Pos),SourceMgr); unsigned LineNo = SourceMgr.getLineNumber(Pos); std::cerr << "In file included from " << SourceMgr.getSourceName(Pos) @@ -46,7 +46,8 @@ PrintIncludeStack(SourceLocation Pos) { /// HighlightRange - Given a SourceRange and a line number, highlight (with ~'s) /// any characters in LineNo that intersect the SourceRange. -void TextDiagnosticPrinter::HighlightRange(const SourceRange &R, +void TextDiagnosticPrinter::HighlightRange(const SourceRange &R, + SourceManager& SourceMgr, unsigned LineNo, std::string &CaratLine, const std::string &SourceLine) { @@ -101,6 +102,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level Level, SourceLocation Pos, diag::kind ID, + SourceManager& SourceMgr, const std::string *Strs, unsigned NumStrs, const SourceRange *Ranges, @@ -116,7 +118,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags, // "included from" lines. if (LastWarningLoc != SourceMgr.getIncludeLoc(LPos)) { LastWarningLoc = SourceMgr.getIncludeLoc(LPos); - PrintIncludeStack(LastWarningLoc); + PrintIncludeStack(LastWarningLoc,SourceMgr); } // Compute the column number. Rewind from the current position to the start @@ -162,7 +164,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags, // Highlight all of the characters covered by Ranges with ~ characters. for (unsigned i = 0; i != NumRanges; ++i) - HighlightRange(Ranges[i], LineNo, CaratLine, SourceLine); + HighlightRange(Ranges[i], SourceMgr, LineNo, CaratLine, SourceLine); // Next, insert the carat itself. if (ColNo-1 < CaratLine.size()) diff --git a/Driver/TextDiagnosticPrinter.h b/Driver/TextDiagnosticPrinter.h index beb9d808e9..c87c20e4f0 100644 --- a/Driver/TextDiagnosticPrinter.h +++ b/Driver/TextDiagnosticPrinter.h @@ -24,17 +24,20 @@ class SourceManager; class TextDiagnosticPrinter : public TextDiagnostics { SourceLocation LastWarningLoc; public: - TextDiagnosticPrinter(SourceManager &sourceMgr) - : TextDiagnostics(sourceMgr) {} + TextDiagnosticPrinter() {} - void PrintIncludeStack(SourceLocation Pos); - void HighlightRange(const SourceRange &R, unsigned LineNo, + void PrintIncludeStack(SourceLocation Pos, SourceManager& SrcMgr); + void HighlightRange(const SourceRange &R, + SourceManager& SrcMgr, + unsigned LineNo, std::string &CaratLine, const std::string &SourceLine); virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel, SourceLocation Pos, - diag::kind ID, const std::string *Strs, + diag::kind ID, + SourceManager& SrcMgr, + const std::string *Strs, unsigned NumStrs, const SourceRange *Ranges, unsigned NumRanges); diff --git a/Driver/TextDiagnostics.cpp b/Driver/TextDiagnostics.cpp index 5b14cdda82..46e535de90 100644 --- a/Driver/TextDiagnostics.cpp +++ b/Driver/TextDiagnostics.cpp @@ -40,7 +40,8 @@ std::string TextDiagnostics::FormatDiagnostic(Diagnostic &Diags, } bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level, - SourceLocation Pos) { + SourceLocation Pos, + SourceManager& SourceMgr) { if (Pos.isValid()) { // If this is a warning or note, and if it a system header, suppress the // diagnostic. diff --git a/Driver/TextDiagnostics.h b/Driver/TextDiagnostics.h index 27d9d3a8e4..ad5e4cb89b 100644 --- a/Driver/TextDiagnostics.h +++ b/Driver/TextDiagnostics.h @@ -24,23 +24,25 @@ class Preprocessor; class TextDiagnostics : public DiagnosticClient { HeaderSearch *TheHeaderSearch; protected: - SourceManager &SourceMgr; - std::string FormatDiagnostic(Diagnostic &Diags, Diagnostic::Level Level, diag::kind ID, const std::string *Strs, unsigned NumStrs); public: - TextDiagnostics(SourceManager &sourceMgr) : SourceMgr(sourceMgr) {} + TextDiagnostics() {} virtual ~TextDiagnostics(); void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; } virtual bool IgnoreDiagnostic(Diagnostic::Level Level, - SourceLocation Pos); + SourceLocation Pos, + SourceManager& SrcMgr); + virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel, SourceLocation Pos, - diag::kind ID, const std::string *Strs, + diag::kind ID, + SourceManager& SrcMgr, + const std::string *Strs, unsigned NumStrs, const SourceRange *Ranges, unsigned NumRanges) = 0; diff --git a/Driver/TranslationUnit.cpp b/Driver/TranslationUnit.cpp index 627657aa92..6f35a32371 100644 --- a/Driver/TranslationUnit.cpp +++ b/Driver/TranslationUnit.cpp @@ -102,7 +102,7 @@ void TranslationUnit::Emit(llvm::Serializer& Sezr) const { Sezr.EnterBlock(); // Emit the SourceManager. - Sezr.Emit(Context->SourceMgr); + Sezr.Emit(Context->getSourceManager()); // Emit the LangOptions. Sezr.Emit(LangOpts); @@ -184,7 +184,7 @@ TranslationUnit* TranslationUnit::Create(llvm::Deserializer& Dezr, assert (FoundBlock); // Read the SourceManager. - SourceManager::CreateAndRegister(Dezr,FMgr); + SourceManager& SrcMgr = *SourceManager::CreateAndRegister(Dezr,FMgr); // Read the LangOptions. TU->LangOpts.Read(Dezr); @@ -196,7 +196,7 @@ TranslationUnit* TranslationUnit::Create(llvm::Deserializer& Dezr, std::vector triples; triples.push_back(triple); delete [] triple; - Dezr.RegisterPtr(PtrID,CreateTargetInfo(triples,NULL)); + Dezr.RegisterPtr(PtrID,CreateTargetInfo(SrcMgr,triples,NULL)); } // For Selectors, we must read the identifier table first because the diff --git a/Driver/clang.cpp b/Driver/clang.cpp index eb469d87ec..c009e06860 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -989,10 +989,10 @@ int main(int argc, char **argv) { std::auto_ptr DiagClient; if (!VerifyDiagnostics) { // Print diagnostics to stderr by default. - DiagClient.reset(new TextDiagnosticPrinter(SourceMgr)); + DiagClient.reset(new TextDiagnosticPrinter()); } else { // When checking diagnostics, just buffer them up. - DiagClient.reset(new TextDiagnosticBuffer(SourceMgr)); + DiagClient.reset(new TextDiagnosticBuffer()); if (InputFilenames.size() != 1) { fprintf(stderr, @@ -1013,7 +1013,7 @@ int main(int argc, char **argv) { { // Create triples, and create the TargetInfo. std::vector triples; CreateTargetTriples(triples); - Target = CreateTargetInfo(triples,&Diags); + Target = CreateTargetInfo(SourceMgr,triples,&Diags); if (Target == 0) { fprintf(stderr, "Sorry, I don't know what target this is: %s\n", @@ -1026,7 +1026,9 @@ int main(int argc, char **argv) { // -I- is a deprecated GCC feature, scan for it and reject it. for (unsigned i = 0, e = I_dirs.size(); i != e; ++i) { if (I_dirs[i] == "-") { - Diags.Report(SourceLocation(), diag::err_pp_I_dash_not_supported); + Diags.Report(SourceLocation(), diag::err_pp_I_dash_not_supported, + SourceMgr); + I_dirs.erase(I_dirs.begin()+i); --i; } diff --git a/Driver/clang.h b/Driver/clang.h index 098c51b39f..c4bbb84658 100644 --- a/Driver/clang.h +++ b/Driver/clang.h @@ -25,6 +25,7 @@ class TargetInfo; class Diagnostic; class ASTConsumer; class IdentifierTable; +class SourceManager; /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(unsigned MainFileID, Preprocessor &PP, @@ -36,7 +37,8 @@ MinimalAction *CreatePrintParserActionsAction(IdentifierTable &); /// CreateTargetInfo - Return the set of target info objects as specified by /// the -arch command line option. -TargetInfo *CreateTargetInfo(const std::vector& triples, +TargetInfo *CreateTargetInfo(SourceManager& SrcMgr, + const std::vector& triples, Diagnostic *Diags); /// EmitLLVMFromASTs - Implement -emit-llvm, which generates llvm IR from C. diff --git a/Lex/Preprocessor.cpp b/Lex/Preprocessor.cpp index d2630584a5..51d8e5d410 100644 --- a/Lex/Preprocessor.cpp +++ b/Lex/Preprocessor.cpp @@ -120,12 +120,12 @@ PPCallbacks::~PPCallbacks() { /// the specified Token's location, translating the token's start /// position in the current buffer into a SourcePosition object for rendering. void Preprocessor::Diag(SourceLocation Loc, unsigned DiagID) { - Diags.Report(Loc, DiagID); + Diags.Report(Loc, DiagID, SourceMgr); } void Preprocessor::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) { - Diags.Report(Loc, DiagID, &Msg, 1); + Diags.Report(Loc, DiagID, SourceMgr, &Msg, 1); } void Preprocessor::DumpToken(const Token &Tok, bool DumpFlags) const { diff --git a/Parse/DeclSpec.cpp b/Parse/DeclSpec.cpp index 19e643d27c..b50c1a7958 100644 --- a/Parse/DeclSpec.cpp +++ b/Parse/DeclSpec.cpp @@ -209,7 +209,8 @@ bool DeclSpec::SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec){ /// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or /// diag::NUM_DIAGNOSTICS if there is no error. After calling this method, /// DeclSpec is guaranteed self-consistent, even if an error occurred. -void DeclSpec::Finish(Diagnostic &D, const LangOptions &Lang) { +void DeclSpec::Finish(Diagnostic &D, SourceManager& SrcMgr, + const LangOptions &Lang) { // Check the type specifier components first. // signed/unsigned are only valid with int/char. @@ -217,7 +218,7 @@ void DeclSpec::Finish(Diagnostic &D, const LangOptions &Lang) { if (TypeSpecType == TST_unspecified) TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int. else if (TypeSpecType != TST_int && TypeSpecType != TST_char) { - Diag(D, TSSLoc, diag::err_invalid_sign_spec, + Diag(D, TSSLoc, SrcMgr, diag::err_invalid_sign_spec, getSpecifierName( (TST)TypeSpecType)); // signed double -> double. TypeSpecSign = TSS_unspecified; @@ -232,7 +233,7 @@ void DeclSpec::Finish(Diagnostic &D, const LangOptions &Lang) { if (TypeSpecType == TST_unspecified) TypeSpecType = TST_int; // short -> short int, long long -> long long int. else if (TypeSpecType != TST_int) { - Diag(D, TSWLoc, + Diag(D, TSWLoc, SrcMgr, TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec : diag::err_invalid_longlong_spec, getSpecifierName( (TST)TypeSpecType)); @@ -243,7 +244,7 @@ void DeclSpec::Finish(Diagnostic &D, const LangOptions &Lang) { if (TypeSpecType == TST_unspecified) TypeSpecType = TST_int; // long -> long int. else if (TypeSpecType != TST_int && TypeSpecType != TST_double) { - Diag(D, TSWLoc, diag::err_invalid_long_spec, + Diag(D, TSWLoc, SrcMgr, diag::err_invalid_long_spec, getSpecifierName( (TST)TypeSpecType)); TypeSpecType = TST_int; } @@ -254,13 +255,13 @@ void DeclSpec::Finish(Diagnostic &D, const LangOptions &Lang) { // disallow their use. Need information about the backend. if (TypeSpecComplex != TSC_unspecified) { if (TypeSpecType == TST_unspecified) { - Diag(D, TSCLoc, diag::ext_plain_complex); + Diag(D, TSCLoc, SrcMgr, diag::ext_plain_complex); TypeSpecType = TST_double; // _Complex -> _Complex double. } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) { // Note that this intentionally doesn't include _Complex _Bool. - Diag(D, TSTLoc, diag::ext_integer_complex); + Diag(D, TSTLoc, SrcMgr, diag::ext_integer_complex); } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) { - Diag(D, TSCLoc, diag::err_invalid_complex_spec, + Diag(D, TSCLoc, SrcMgr, diag::err_invalid_complex_spec, getSpecifierName( (TST)TypeSpecType)); TypeSpecComplex = TSC_unspecified; } @@ -272,7 +273,7 @@ void DeclSpec::Finish(Diagnostic &D, const LangOptions &Lang) { StorageClassSpec = SCS_extern; // '__thread int' -> 'extern __thread int' } else if (StorageClassSpec != SCS_extern && StorageClassSpec != SCS_static) { - Diag(D, getStorageClassSpecLoc(), diag::err_invalid_thread_spec, + Diag(D, getStorageClassSpecLoc(), SrcMgr, diag::err_invalid_thread_spec, getSpecifierName( (SCS)StorageClassSpec)); SCS_thread_specified = false; } diff --git a/Parse/ParseDecl.cpp b/Parse/ParseDecl.cpp index 3c2eb2a840..2781c8f2f5 100644 --- a/Parse/ParseDecl.cpp +++ b/Parse/ParseDecl.cpp @@ -424,7 +424,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { default: // If this is not a declaration specifier token, we're done reading decl // specifiers. First verify that DeclSpec's are consistent. - DS.Finish(Diags, getLang()); + DS.Finish(Diags, PP.getSourceManager(), getLang()); return; // GNU attributes support. @@ -1037,7 +1037,7 @@ void Parser::ParseTypeQualifierListOpt(DeclSpec &DS) { default: // If this is not a type-qualifier token, we're done reading type // qualifiers. First verify that DeclSpec's are consistent. - DS.Finish(Diags, getLang()); + DS.Finish(Diags, PP.getSourceManager(), getLang()); return; case tok::kw_const: isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec, diff --git a/Parse/Parser.cpp b/Parse/Parser.cpp index 8a0d8c7ecd..f2f331ed69 100644 --- a/Parse/Parser.cpp +++ b/Parse/Parser.cpp @@ -31,7 +31,7 @@ Action::~Action() {} void Parser::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) { - Diags.Report(Loc, DiagID, &Msg, 1); + Diags.Report(Loc, DiagID, PP.getSourceManager(), &Msg, 1); } /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'), diff --git a/Sema/Sema.cpp b/Sema/Sema.cpp index 7a657cd5e1..5ec5fa7ede 100644 --- a/Sema/Sema.cpp +++ b/Sema/Sema.cpp @@ -118,51 +118,54 @@ void Sema::DeleteStmt(StmtTy *S) { //===----------------------------------------------------------------------===// bool Sema::Diag(SourceLocation Loc, unsigned DiagID) { - PP.getDiagnostics().Report(Loc, DiagID); + PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager()); return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) { - PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1); + PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), &Msg, 1); return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1, const std::string &Msg2) { std::string MsgArr[] = { Msg1, Msg2 }; - PP.getDiagnostics().Report(Loc, DiagID, MsgArr, 2); + PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), MsgArr, 2); return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, SourceRange Range) { - PP.getDiagnostics().Report(Loc, DiagID, 0, 0, &Range, 1); + PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), 0,0, &Range,1); return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg, SourceRange Range) { - PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1, &Range, 1); + PP.getDiagnostics().Report(Loc,DiagID,PP.getSourceManager(),&Msg,1,&Range,1); return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1, const std::string &Msg2, SourceRange Range) { std::string MsgArr[] = { Msg1, Msg2 }; - PP.getDiagnostics().Report(Loc, DiagID, MsgArr, 2, &Range, 1); + PP.getDiagnostics().Report(Loc,DiagID,PP.getSourceManager(), + MsgArr,2,&Range,1); return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1, SourceRange R2) { SourceRange RangeArr[] = { R1, R2 }; - PP.getDiagnostics().Report(Loc, DiagID, 0, 0, RangeArr, 2); + PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), + 0, 0, RangeArr, 2); return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg, SourceRange R1, SourceRange R2) { SourceRange RangeArr[] = { R1, R2 }; - PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1, RangeArr, 2); + PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), &Msg, + 1, RangeArr, 2); return true; } @@ -170,7 +173,8 @@ bool Sema::Diag(SourceLocation Range, unsigned DiagID, const std::string &Msg1, const std::string &Msg2, SourceRange R1, SourceRange R2) { std::string MsgArr[] = { Msg1, Msg2 }; SourceRange RangeArr[] = { R1, R2 }; - PP.getDiagnostics().Report(Range, DiagID, MsgArr, 2, RangeArr, 2); + PP.getDiagnostics().Report(Range, DiagID, PP.getSourceManager(), MsgArr, 2, + RangeArr, 2); return true; } diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index c8a80b02f6..7170f4572b 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -69,13 +69,15 @@ class ASTContext { QualType ObjcConstantStringType; RecordDecl *CFConstantStringTypeDecl; -public: - + SourceManager &SourceMgr; +public: TargetInfo &Target; IdentifierTable &Idents; SelectorTable &Selectors; + SourceManager& getSourceManager() { return SourceMgr; } + /// This is intentionally not serialized. It is populated by the /// ASTContext ctor, and there are no external pointers/references to /// internal variables of BuiltinInfo. diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index b9029d9bca..5abc28f2e4 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -21,6 +21,7 @@ namespace clang { class DiagnosticClient; class SourceLocation; class SourceRange; + class SourceManager; // Import the diagnostic enums themselves. namespace diag { @@ -146,7 +147,7 @@ public: /// Report - Issue the message to the client. DiagID is a member of the /// diag::kind enum. - void Report(SourceLocation Pos, unsigned DiagID, + void Report(SourceLocation Pos, unsigned DiagID, SourceManager& SrcMgr, const std::string *Strs = 0, unsigned NumStrs = 0, const SourceRange *Ranges = 0, unsigned NumRanges = 0); }; @@ -160,13 +161,15 @@ public: /// IgnoreDiagnostic - If the client wants to ignore this diagnostic, then /// return true. virtual bool IgnoreDiagnostic(Diagnostic::Level DiagLevel, - SourceLocation Pos) = 0; + SourceLocation Pos, + SourceManager& SrcMgr) = 0; /// HandleDiagnostic - Handle this diagnostic, reporting it to the user or /// capturing it to a log as needed. virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel, SourceLocation Pos, - diag::kind ID, const std::string *Strs, + diag::kind ID, SourceManager& SrcMgr, + const std::string *Strs, unsigned NumStrs, const SourceRange *Ranges, unsigned NumRanges) = 0; }; diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index d02af435fc..30c6e05ee3 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -25,6 +25,8 @@ namespace clang { class TargetInfoImpl; class Diagnostic; +class SourceManager; + namespace Builtin { struct Info; } /// TargetInfo - This class exposes information about the current target set. @@ -40,6 +42,9 @@ namespace Builtin { struct Info; } /// diagnostic info, but does expect them to be alive for as long as it is. /// class TargetInfo { + /// SrcMgr - The SourceManager associated with this TargetInfo. + SourceManager& SrcMgr; + /// Primary - This tracks the primary target in the target set. /// const TargetInfoImpl *PrimaryTarget; @@ -61,7 +66,8 @@ class TargetInfo { unsigned WCharWidth, WCharAlign; public: - TargetInfo(const TargetInfoImpl *Primary, Diagnostic *D = 0) { + TargetInfo(SourceManager& SMgr, const TargetInfoImpl *Primary, + Diagnostic *D = 0) : SrcMgr(SMgr) { PrimaryTarget = Primary; Diag = D; NonPortable = false; diff --git a/include/clang/Parse/DeclSpec.h b/include/clang/Parse/DeclSpec.h index a23aaf7789..d55e716bc7 100644 --- a/include/clang/Parse/DeclSpec.h +++ b/include/clang/Parse/DeclSpec.h @@ -24,8 +24,8 @@ namespace clang { class IdentifierInfo; /// DeclSpec - This class captures information about "declaration specifiers", -/// which encompasses storage-class-specifiers, type-specifiers, type-qualifiers, -/// and function-specifiers. +/// which encompasses storage-class-specifiers, type-specifiers, +/// type-qualifiers, and function-specifiers. class DeclSpec { public: SourceRange Range; @@ -266,15 +266,17 @@ public: /// Finish - This does final analysis of the declspec, issuing diagnostics for /// things like "_Imaginary" (lacking an FP type). After calling this method, /// DeclSpec is guaranteed self-consistent, even if an error occurred. - void Finish(Diagnostic &D, const LangOptions &Lang); + void Finish(Diagnostic &D, SourceManager& SrcMgr, const LangOptions &Lang); private: - void Diag(Diagnostic &D, SourceLocation Loc, unsigned DiagID) { - D.Report(Loc, DiagID); + void Diag(Diagnostic &D, SourceLocation Loc, SourceManager& SrcMgr, + unsigned DiagID) { + D.Report(Loc, DiagID, SrcMgr); } - void Diag(Diagnostic &D, SourceLocation Loc, unsigned DiagID, - const std::string &info) { - D.Report(Loc, DiagID, &info, 1); + + void Diag(Diagnostic &D, SourceLocation Loc, SourceManager& SrcMgr, + unsigned DiagID, const std::string &info) { + D.Report(Loc, DiagID, SrcMgr, &info, 1); } };