diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-18 07:04:44 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-18 07:04:44 +0000 |
commit | 0a14eee528a901c16f0e288fbc10a3abc1660d87 (patch) | |
tree | 1c6a7acf8be19bebf1f390638bfa52045a7dcf97 /lib/Sema/Sema.cpp | |
parent | 46bbacac37141ed9d01d5b6473e8211554b02710 (diff) |
This reworks some of the Diagnostic interfaces a bit to change how diagnostics
are formed. In particular, a diagnostic with all its strings and ranges is now
packaged up and sent to DiagnosticClients as a DiagnosticInfo instead of as a
ton of random stuff. This has the benefit of simplifying the interface, making
it more extensible, and allowing us to do more checking for things like access
past the end of the various arrays passed in.
In addition to introducing DiagnosticInfo, this also substantially changes how
Diagnostic::Report works. Instead of being passed in all of the info required
to issue a diagnostic, Report now takes only the required info (a location and
ID) and returns a fresh DiagnosticInfo *by value*. The caller is then free to
stuff strings and ranges into the DiagnosticInfo with the << operator. When
the dtor runs on the DiagnosticInfo object (which should happen at the end of
the statement), the diagnostic is actually emitted with all of the accumulated
information. This is a somewhat tricky dance, but it means that the
accumulated DiagnosticInfo is allowed to keep pointers to other expression
temporaries without those pointers getting invalidated.
This is just the minimal change to get this stuff working, but this will allow
us to eliminate the zillions of variant "Diag" methods scattered throughout
(e.g.) sema. For example, instead of calling:
Diag(BuiltinLoc, diag::err_overload_no_match, typeNames,
SourceRange(BuiltinLoc, RParenLoc));
We will soon be able to just do:
Diag(BuiltinLoc, diag::err_overload_no_match)
<< typeNames << SourceRange(BuiltinLoc, RParenLoc));
This scales better to support arbitrary types being passed in (not just
strings) in a type-safe way. Go operator overloading?!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59502 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/Sema.cpp')
-rw-r--r-- | lib/Sema/Sema.cpp | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 5ea27c979b..c064e2448b 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -18,11 +18,9 @@ #include "clang/AST/Expr.h" #include "clang/Lex/Preprocessor.h" #include "clang/Basic/Diagnostic.h" - using namespace clang; -static inline RecordDecl *CreateStructDecl(ASTContext &C, const char *Name) -{ +static inline RecordDecl *CreateStructDecl(ASTContext &C, const char *Name) { if (C.getLangOptions().CPlusPlus) return CXXRecordDecl::Create(C, TagDecl::TK_struct, C.getTranslationUnitDecl(), @@ -176,66 +174,58 @@ bool Sema::Diag(SourceLocation Loc, unsigned DiagID) { } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) { - const std::string *Strs[] = { &Msg }; - PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, Strs, 1); + PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID) << Msg; return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1, const std::string &Msg2) { - const std::string *MsgArr[] = { &Msg1, &Msg2 }; - PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, MsgArr, 2); + PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID) << Msg1 << Msg2; return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const SourceRange& Range) { - PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, 0, 0, &Range,1); + PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID) << Range; return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg, const SourceRange& Range) { - const std::string *Strs[] = { &Msg }; - PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, Strs, 1, &Range,1); + PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID) << Msg << Range; return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1, - const std::string &Msg2, const SourceRange& Range) { - const std::string *MsgArr[] = { &Msg1, &Msg2 }; - PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, MsgArr, 2, &Range, 1); + const std::string &Msg2, const SourceRange &R) { + PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID) << Msg1 << Msg2 << R; return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1, const std::string &Msg2, const std::string &Msg3, const SourceRange &R1) { - const std::string *MsgArr[] = { &Msg1, &Msg2, &Msg3 }; - PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, MsgArr, 3, &R1, 1); + PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID) + << Msg1 << Msg2 << Msg3 << R1; return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const SourceRange& R1, const SourceRange& R2) { - SourceRange RangeArr[] = { R1, R2 }; - PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, 0, 0, RangeArr, 2); + PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID) << R1 << R2; return true; } bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg, const SourceRange& R1, const SourceRange& R2) { - SourceRange RangeArr[] = { R1, R2 }; - const std::string *Strs[] = { &Msg }; - PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, Strs, 1, RangeArr, 2); + PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID) << Msg << R1 << R2; return true; } bool Sema::Diag(SourceLocation Range, unsigned DiagID, const std::string &Msg1, const std::string &Msg2, const SourceRange& R1, const SourceRange& R2) { - const std::string *MsgArr[] = { &Msg1, &Msg2 }; - SourceRange RangeArr[] = { R1, R2 }; - PP.getDiagnostics().Report(PP.getFullLoc(Range),DiagID, MsgArr,2,RangeArr, 2); + PP.getDiagnostics().Report(PP.getFullLoc(Range),DiagID) + << Msg1 << Msg2 << R1 << R2; return true; } |