]> granicus.if.org Git - clang/commitdiff
Make Lexer::ComputePreamble accept a LangOptions parameter, otherwise it may be
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 25 Aug 2011 20:39:19 +0000 (20:39 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 25 Aug 2011 20:39:19 +0000 (20:39 +0000)
out-of-sync how a file is compiled. Patch by Matthias Kleine!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138580 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Lexer.h
lib/Frontend/ASTUnit.cpp
lib/Frontend/FrontendActions.cpp
lib/Lex/Lexer.cpp
test/Lexer/preamble.c

index 3bc44b192acc75955ecee667c89eb90ad601dd5d..21f3f8df86bffbac93e255f70a99a47948a3871d 100644 (file)
@@ -322,7 +322,8 @@ public:
   /// 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.
index e369f430b7ac1e97f65f038a9d7e33ae81a5228c..71f9c0dada8b5902a0df35390965429950770b40 100644 (file)
@@ -1122,7 +1122,9 @@ ASTUnit::ComputePreamble(CompilerInvocation &Invocation,
     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,
index 4eb9cda3987a60401185154dba69fb26ba0d5fbf..d6df141905ae54d8f2f6be8f96d4b89316a63b3d 100644 (file)
@@ -220,7 +220,7 @@ void PrintPreambleAction::ExecuteAction() {
   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;
   }
index d8ebc9ffe6bffefa4580976748258ba55cc21b5c..1ec50cd2c5d68c9d4068f4daf005bcdfeb38e195 100644 (file)
@@ -505,14 +505,14 @@ namespace {
 }
 
 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;
index 7735b475e1ae881043fee467b5d1bfc23a9207b7..5b2739abefcc943c3315c335270880476346f878 100644 (file)
@@ -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 @@ int foo();
 // 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