[cfe-commits] r138580 - in /cfe/trunk: include/clang/Lex/Lexer.h lib/Frontend/ASTUnit.cpp lib/Frontend/FrontendActions.cpp lib/Lex/Lexer.cpp test/Lexer/preamble.c

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Aug 25 13:39:19 PDT 2011


Author: akirtzidis
Date: Thu Aug 25 15:39:19 2011
New Revision: 138580

URL: http://llvm.org/viewvc/llvm-project?rev=138580&view=rev
Log:
Make Lexer::ComputePreamble accept a LangOptions parameter, otherwise it may be
out-of-sync how a file is compiled. Patch by Matthias Kleine!

Modified:
    cfe/trunk/include/clang/Lex/Lexer.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/lib/Frontend/FrontendActions.cpp
    cfe/trunk/lib/Lex/Lexer.cpp
    cfe/trunk/test/Lexer/preamble.c

Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=138580&r1=138579&r2=138580&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Thu Aug 25 15:39:19 2011
@@ -322,7 +322,8 @@
   /// of the file begins along with a boolean value indicating whether 
   /// the preamble ends at the beginning of a new line.
   static std::pair<unsigned, bool>
-  ComputePreamble(const llvm::MemoryBuffer *Buffer, unsigned MaxLines = 0);
+  ComputePreamble(const llvm::MemoryBuffer *Buffer, const LangOptions &Features,
+                  unsigned MaxLines = 0);
                                         
   //===--------------------------------------------------------------------===//
   // Internal implementation interfaces.

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=138580&r1=138579&r2=138580&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Thu Aug 25 15:39:19 2011
@@ -1122,7 +1122,9 @@
     CreatedBuffer = true;
   }
   
-  return std::make_pair(Buffer, Lexer::ComputePreamble(Buffer, MaxLines));
+  return std::make_pair(Buffer, Lexer::ComputePreamble(Buffer,
+                                                       Invocation.getLangOpts(),
+                                                       MaxLines));
 }
 
 static llvm::MemoryBuffer *CreatePaddedMainFileBuffer(llvm::MemoryBuffer *Old,

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=138580&r1=138579&r2=138580&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Thu Aug 25 15:39:19 2011
@@ -220,7 +220,7 @@
   llvm::MemoryBuffer *Buffer
       = CI.getFileManager().getBufferForFile(getCurrentFile());
   if (Buffer) {
-    unsigned Preamble = Lexer::ComputePreamble(Buffer).first;
+    unsigned Preamble = Lexer::ComputePreamble(Buffer, CI.getLangOpts()).first;
     llvm::outs().write(Buffer->getBufferStart(), Preamble);
     delete Buffer;
   }

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=138580&r1=138579&r2=138580&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Thu Aug 25 15:39:19 2011
@@ -505,14 +505,14 @@
 }
 
 std::pair<unsigned, bool>
-Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer, unsigned MaxLines) {
+Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer,
+                       const LangOptions &Features, unsigned MaxLines) {
   // Create a lexer starting at the beginning of the file. Note that we use a
   // "fake" file source location at offset 1 so that the lexer will track our
   // position within the file.
   const unsigned StartOffset = 1;
   SourceLocation StartLoc = SourceLocation::getFromRawEncoding(StartOffset);
-  LangOptions LangOpts;
-  Lexer TheLexer(StartLoc, LangOpts, Buffer->getBufferStart(), 
+  Lexer TheLexer(StartLoc, Features, Buffer->getBufferStart(),
                  Buffer->getBufferStart(), Buffer->getBufferEnd());
   
   bool InPreprocessorDirective = false;

Modified: cfe/trunk/test/Lexer/preamble.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/preamble.c?rev=138580&r1=138579&r2=138580&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/preamble.c (original)
+++ cfe/trunk/test/Lexer/preamble.c Thu Aug 25 15:39:19 2011
@@ -1,5 +1,5 @@
 // Preamble detection test: see below for comments and test commands.
-//
+//* A BCPL comment that includes '/*'
 #include <blah>
 #ifndef FOO
 #else
@@ -24,7 +24,7 @@
 // RUN: FileCheck < %t %s
 
 // CHECK: // Preamble detection test: see below for comments and test commands.
-// CHECK-NEXT: //
+// CHECK-NEXT: //* A BCPL comment that includes '/*'
 // CHECK-NEXT: #include <blah>
 // CHECK-NEXT: #ifndef FOO
 // CHECK-NEXT: #else





More information about the cfe-commits mailing list