]> granicus.if.org Git - clang/commitdiff
wean the diagnostics machinery off the preprocessor.
authorChris Lattner <sabre@nondot.org>
Wed, 17 Oct 2007 20:53:57 +0000 (20:53 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 17 Oct 2007 20:53:57 +0000 (20:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43085 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/TextDiagnosticPrinter.cpp
Driver/TextDiagnostics.h
Driver/clang.cpp

index 2a3bd0d95461ef36a0754b8ae4ab02d8aefee27d..76809d7dea9021528c39f6ae44ba19f44cab5ffa 100644 (file)
@@ -104,13 +104,19 @@ unsigned TextDiagnosticPrinter::GetTokenLength(SourceLocation Loc) {
   // the token this macro expanded to.
   Loc = SourceMgr.getLogicalLoc(Loc);
   const char *StrData = SourceMgr.getCharacterData(Loc);
+  const char *BufEnd = SourceMgr.getBufferData(Loc.getFileID()).second;
   
   // TODO: this could be special cased for common tokens like identifiers, ')',
   // etc to make this faster, if it mattered.  This could use 
   // Lexer::isObviouslySimpleCharacter for example.
   
+  // Create a langops struct and enable trigraphs.  This is sufficient for
+  // measuring tokens.
+  LangOptions LangOpts;
+  LangOpts.Trigraphs = true;
+  
   // Create a lexer starting at the beginning of this token.
-  Lexer TheLexer(Loc, *ThePreprocessor, StrData);
+  Lexer TheLexer(Loc, LangOpts, StrData, BufEnd);
   Token TheTok;
   TheLexer.LexRawToken(TheTok);
   return TheTok.getLength();
index faf1b412b2c116cb4fe8e5363fbc4d4f8299f810..2ab0066d034b3ca90193e2ddd6a7a5ac0c5c87f7 100644 (file)
@@ -25,7 +25,6 @@ class TextDiagnostics : public DiagnosticClient {
   HeaderSearch *TheHeaderSearch;
 protected:
   SourceManager &SourceMgr;
-  Preprocessor *ThePreprocessor;
 
   std::string FormatDiagnostic(Diagnostic::Level Level,
                                diag::kind ID,
@@ -36,7 +35,6 @@ public:
   virtual ~TextDiagnostics();
 
   void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; }
-  void setPreprocessor(Preprocessor &P) { ThePreprocessor = &P; }
 
   virtual bool IgnoreDiagnostic(Diagnostic::Level Level, 
                                 SourceLocation Pos);
index 082f5ed07406fcc41c4afd0f6bc11390f6487885..6e0ed914e2b98f9720407c46ab326d047a2ba586 100644 (file)
@@ -908,7 +908,6 @@ int main(int argc, char **argv) {
   for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
     // Set up the preprocessor with these options.
     Preprocessor PP(Diags, LangInfo, *Target, SourceMgr, HeaderInfo);
-    DiagClient->setPreprocessor(PP);
     const std::string &InFile = InputFilenames[i];
     std::vector<char> PredefineBuffer;
     unsigned MainFileID = InitializePreprocessor(PP, InFile, SourceMgr,