зеркало из https://github.com/microsoft/clang-1.git
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
This commit is contained in:
Родитель
e66894c3de
Коммит
7a9d49fd2b
|
@ -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<DeclStmt>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<std::string>& triples,
|
||||
TargetInfo *clang::CreateTargetInfo(SourceManager& SrcMgr,
|
||||
const std::vector<std::string>& triples,
|
||||
Diagnostic *Diags) {
|
||||
|
||||
assert (!triples.empty() && "No target triple.");
|
||||
|
@ -713,7 +714,7 @@ TargetInfo *clang::CreateTargetInfo(const std::vector<std::string>& 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) {
|
||||
|
|
|
@ -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 *,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<std::string> 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
|
||||
|
|
|
@ -989,10 +989,10 @@ int main(int argc, char **argv) {
|
|||
std::auto_ptr<TextDiagnostics> 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<std::string> 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;
|
||||
}
|
||||
|
|
|
@ -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<std::string>& triples,
|
||||
TargetInfo *CreateTargetInfo(SourceManager& SrcMgr,
|
||||
const std::vector<std::string>& triples,
|
||||
Diagnostic *Diags);
|
||||
|
||||
/// EmitLLVMFromASTs - Implement -emit-llvm, which generates llvm IR from C.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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. '['/']'),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче