[cfe-commits] r59168 - in /cfe/trunk/include/clang/Lex: Lexer.h PreprocessorLexer.h

Ted Kremenek kremenek at apple.com
Wed Nov 12 13:34:13 PST 2008


Author: kremenek
Date: Wed Nov 12 15:33:59 2008
New Revision: 59168

URL: http://llvm.org/viewvc/llvm-project?rev=59168&view=rev
Log:
Move pieces of Lexer that the Preprocessor mutates to a new base class 'PreprocessorLexer'.  This will also be the base class of the new Preprocessed-Token-Header (PTH) lexer.  No functionality change.

Added:
    cfe/trunk/include/clang/Lex/PreprocessorLexer.h
Modified:
    cfe/trunk/include/clang/Lex/Lexer.h

Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=59168&r1=59167&r2=59168&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Wed Nov 12 15:33:59 2008
@@ -14,8 +14,7 @@
 #ifndef LLVM_CLANG_LEXER_H
 #define LLVM_CLANG_LEXER_H
 
-#include "clang/Lex/Token.h"
-#include "clang/Lex/MultipleIncludeOpt.h"
+#include "clang/Lex/PreprocessorLexer.h"
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/SmallVector.h"
 #include <string>
@@ -31,7 +30,7 @@
 /// stream of tokens.  This provides no support for file reading or buffering,
 /// or buffering/seeking of tokens, only forward lexing is supported.  It relies
 /// on the specified Preprocessor object to handle preprocessor directives, etc.
-class Lexer {
+class Lexer : public PreprocessorLexer {
   //===--------------------------------------------------------------------===//
   // Constant configuration values for this lexer.
   const char *BufferStart;       // Start of the buffer.
@@ -45,27 +44,6 @@
   // Context-specific lexing flags set by the preprocessor.
   //
   
-  /// ParsingPreprocessorDirective - This is true when parsing #XXX.  This turns
-  /// '\n' into a tok::eom token.
-  bool ParsingPreprocessorDirective;
-  
-  /// ParsingFilename - True after #include: this turns <xx> into a
-  /// tok::angle_string_literal token.
-  bool ParsingFilename;
-  
-  /// LexingRawMode - True if in raw mode:  This flag disables interpretation of
-  /// tokens and is a far faster mode to lex in than non-raw-mode.  This flag:
-  ///  1. If EOF of the current lexer is found, the include stack isn't popped.
-  ///  2. Identifier information is not looked up for identifier tokens.  As an
-  ///     effect of this, implicit macro expansion is naturally disabled.
-  ///  3. "#" tokens at the start of a line are treated as normal tokens, not
-  ///     implicitly transformed by the lexer.
-  ///  4. All diagnostic messages are disabled.
-  ///  5. No callbacks are made into the preprocessor.
-  ///
-  /// Note that in raw mode that the PP pointer may be null.
-  bool LexingRawMode;
-  
   /// ExtendedTokenMode - The lexer can optionally keep comments and whitespace
   /// and return them as tokens.  This is used for -C and -CC modes, and
   /// whitespace preservation can be useful for some clients that want to lex
@@ -87,14 +65,6 @@
   // IsAtStartOfLine - True if the next lexed token should get the "start of
   // line" flag set on it.
   bool IsAtStartOfLine;
-
-  /// MIOpt - This is a state machine that detects the #ifndef-wrapping a file 
-  /// idiom for the multiple-include optimization.
-  MultipleIncludeOpt MIOpt;
-  
-  /// ConditionalStack - Information about the set of #if/#ifdef/#ifndef blocks
-  /// we are currently in.
-  std::vector<PPConditionalInfo> ConditionalStack;
   
   Lexer(const Lexer&);          // DO NOT IMPLEMENT
   void operator=(const Lexer&); // DO NOT IMPLEMENT
@@ -347,44 +317,6 @@
                                        const LangOptions &Features);
   
   //===--------------------------------------------------------------------===//
-  // #if directive handling.
-  
-  /// pushConditionalLevel - When we enter a #if directive, this keeps track of
-  /// what we are currently in for diagnostic emission (e.g. #if with missing
-  /// #endif).
-  void pushConditionalLevel(SourceLocation DirectiveStart, bool WasSkipping,
-                            bool FoundNonSkip, bool FoundElse) {
-    PPConditionalInfo CI;
-    CI.IfLoc = DirectiveStart;
-    CI.WasSkipping = WasSkipping;
-    CI.FoundNonSkip = FoundNonSkip;
-    CI.FoundElse = FoundElse;
-    ConditionalStack.push_back(CI);
-  }
-  void pushConditionalLevel(const PPConditionalInfo &CI) {
-    ConditionalStack.push_back(CI);
-  }    
-  
-  /// popConditionalLevel - Remove an entry off the top of the conditional
-  /// stack, returning information about it.  If the conditional stack is empty,
-  /// this returns true and does not fill in the arguments.
-  bool popConditionalLevel(PPConditionalInfo &CI) {
-    if (ConditionalStack.empty()) return true;
-    CI = ConditionalStack.back();
-    ConditionalStack.pop_back();
-    return false;
-  }
-  
-  /// peekConditionalLevel - Return the top of the conditional stack.  This
-  /// requires that there be a conditional active.
-  PPConditionalInfo &peekConditionalLevel() {
-    assert(!ConditionalStack.empty() && "No conditionals active!");
-    return ConditionalStack.back();
-  }
-  
-  unsigned getConditionalStackDepth() const { return ConditionalStack.size(); }
-  
-  //===--------------------------------------------------------------------===//
   // Other lexer functions.
   
   // Helper functions to lex the remainder of a token of the specific type.

Added: cfe/trunk/include/clang/Lex/PreprocessorLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorLexer.h?rev=59168&view=auto

==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessorLexer.h (added)
+++ cfe/trunk/include/clang/Lex/PreprocessorLexer.h Wed Nov 12 15:33:59 2008
@@ -0,0 +1,107 @@
+//===--- PreprocessorLexer.h - C Language Family Lexer ----------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines the PreprocessorLexer interface.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_PreprocessorLexer_H
+#define LLVM_CLANG_PreprocessorLexer_H
+
+#include "clang/Lex/MultipleIncludeOpt.h"
+#include "clang/Lex/Token.h"
+#include <vector>
+
+namespace clang {
+
+class Preprocessor;
+
+class PreprocessorLexer {
+protected:  
+  // Context-specific lexing flags set by the preprocessor.
+  
+  /// ParsingPreprocessorDirective - This is true when parsing #XXX.  This turns
+  /// '\n' into a tok::eom token.
+  bool ParsingPreprocessorDirective;
+  
+  /// ParsingFilename - True after #include: this turns <xx> into a
+  /// tok::angle_string_literal token.
+  bool ParsingFilename;
+  
+  /// LexingRawMode - True if in raw mode:  This flag disables interpretation of
+  /// tokens and is a far faster mode to lex in than non-raw-mode.  This flag:
+  ///  1. If EOF of the current lexer is found, the include stack isn't popped.
+  ///  2. Identifier information is not looked up for identifier tokens.  As an
+  ///     effect of this, implicit macro expansion is naturally disabled.
+  ///  3. "#" tokens at the start of a line are treated as normal tokens, not
+  ///     implicitly transformed by the lexer.
+  ///  4. All diagnostic messages are disabled.
+  ///  5. No callbacks are made into the preprocessor.
+  ///
+  /// Note that in raw mode that the PP pointer may be null.
+  bool LexingRawMode;
+  
+  /// MIOpt - This is a state machine that detects the #ifndef-wrapping a file 
+  /// idiom for the multiple-include optimization.
+  MultipleIncludeOpt MIOpt;
+  
+  /// ConditionalStack - Information about the set of #if/#ifdef/#ifndef blocks
+  /// we are currently in.
+  std::vector<PPConditionalInfo> ConditionalStack;
+  
+  PreprocessorLexer(const PreprocessorLexer&);          // DO NOT IMPLEMENT
+  void operator=(const PreprocessorLexer&); // DO NOT IMPLEMENT
+  friend class Preprocessor;
+  
+  PreprocessorLexer() {}
+  
+protected:
+  
+  //===--------------------------------------------------------------------===//
+  // #if directive handling.
+  
+  /// pushConditionalLevel - When we enter a #if directive, this keeps track of
+  /// what we are currently in for diagnostic emission (e.g. #if with missing
+  /// #endif).
+  void pushConditionalLevel(SourceLocation DirectiveStart, bool WasSkipping,
+                            bool FoundNonSkip, bool FoundElse) {
+    PPConditionalInfo CI;
+    CI.IfLoc = DirectiveStart;
+    CI.WasSkipping = WasSkipping;
+    CI.FoundNonSkip = FoundNonSkip;
+    CI.FoundElse = FoundElse;
+    ConditionalStack.push_back(CI);
+  }
+  void pushConditionalLevel(const PPConditionalInfo &CI) {
+    ConditionalStack.push_back(CI);
+  }    
+  
+  /// popConditionalLevel - Remove an entry off the top of the conditional
+  /// stack, returning information about it.  If the conditional stack is empty,
+  /// this returns true and does not fill in the arguments.
+  bool popConditionalLevel(PPConditionalInfo &CI) {
+    if (ConditionalStack.empty()) return true;
+    CI = ConditionalStack.back();
+    ConditionalStack.pop_back();
+    return false;
+  }
+  
+  /// peekConditionalLevel - Return the top of the conditional stack.  This
+  /// requires that there be a conditional active.
+  PPConditionalInfo &peekConditionalLevel() {
+    assert(!ConditionalStack.empty() && "No conditionals active!");
+    return ConditionalStack.back();
+  }
+  
+  unsigned getConditionalStackDepth() const { return ConditionalStack.size(); }    
+};
+
+}  // end namespace clang
+
+#endif





More information about the cfe-commits mailing list