 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
12.5% |
1 / 8 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
25.0% |
2 / 8 |
| |
|
Line Coverage: |
100.0% |
29 / 29 |
| |
 |
|
 |
1 : //===--- PreprocessorLexer.h - C Language Family Lexer ----------*- C++ -*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This file defines the PreprocessorLexer interface.
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #ifndef LLVM_CLANG_PreprocessorLexer_H
15 : #define LLVM_CLANG_PreprocessorLexer_H
16 :
17 : #include "clang/Lex/MultipleIncludeOpt.h"
18 : #include "clang/Lex/Token.h"
19 : #include "llvm/ADT/SmallVector.h"
20 : #include <string>
21 :
22 : namespace clang {
23 :
24 : class Preprocessor;
25 :
26 : class PreprocessorLexer {
27 : protected:
28 : Preprocessor *PP; // Preprocessor object controlling lexing.
29 :
30 : /// The SourceManager FileID corresponding to the file being lexed.
31 : const FileID FID;
32 :
33 : //===--------------------------------------------------------------------===//
34 : // Context-specific lexing flags set by the preprocessor.
35 : //===--------------------------------------------------------------------===//
36 :
37 : /// ParsingPreprocessorDirective - This is true when parsing #XXX. This turns
38 : /// '\n' into a tok::eom token.
39 : bool ParsingPreprocessorDirective;
40 :
41 : /// ParsingFilename - True after #include: this turns <xx> into a
42 : /// tok::angle_string_literal token.
43 : bool ParsingFilename;
44 :
45 : /// LexingRawMode - True if in raw mode: This flag disables interpretation of
46 : /// tokens and is a far faster mode to lex in than non-raw-mode. This flag:
47 : /// 1. If EOF of the current lexer is found, the include stack isn't popped.
48 : /// 2. Identifier information is not looked up for identifier tokens. As an
49 : /// effect of this, implicit macro expansion is naturally disabled.
50 : /// 3. "#" tokens at the start of a line are treated as normal tokens, not
51 : /// implicitly transformed by the lexer.
52 : /// 4. All diagnostic messages are disabled.
53 : /// 5. No callbacks are made into the preprocessor.
54 : ///
55 : /// Note that in raw mode that the PP pointer may be null.
56 : bool LexingRawMode;
57 :
58 : /// MIOpt - This is a state machine that detects the #ifndef-wrapping a file
59 : /// idiom for the multiple-include optimization.
60 : MultipleIncludeOpt MIOpt;
61 :
62 : /// ConditionalStack - Information about the set of #if/#ifdef/#ifndef blocks
63 : /// we are currently in.
64 : llvm::SmallVector<PPConditionalInfo, 4> ConditionalStack;
65 :
66 : PreprocessorLexer(const PreprocessorLexer&); // DO NOT IMPLEMENT
67 : void operator=(const PreprocessorLexer&); // DO NOT IMPLEMENT
68 : friend class Preprocessor;
69 :
70 5622: PreprocessorLexer(Preprocessor *pp, FileID fid)
71 : : PP(pp), FID(fid), ParsingPreprocessorDirective(false),
72 5622: ParsingFilename(false), LexingRawMode(false) {}
73 :
74 138969: PreprocessorLexer()
75 : : PP(0),
76 : ParsingPreprocessorDirective(false),
77 : ParsingFilename(false),
78 138969: LexingRawMode(false) {}
79 :
0: branch 1 not taken
144591: branch 2 taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 9 not taken
0: branch 10 not taken
80 144591: virtual ~PreprocessorLexer() {}
81 :
82 : virtual void IndirectLex(Token& Result) = 0;
83 :
84 : /// getSourceLocation - Return the source location for the next observable
85 : /// location.
86 : virtual SourceLocation getSourceLocation() = 0;
87 :
88 : //===--------------------------------------------------------------------===//
89 : // #if directive handling.
90 :
91 : /// pushConditionalLevel - When we enter a #if directive, this keeps track of
92 : /// what we are currently in for diagnostic emission (e.g. #if with missing
93 : /// #endif).
94 : void pushConditionalLevel(SourceLocation DirectiveStart, bool WasSkipping,
95 7234: bool FoundNonSkip, bool FoundElse) {
96 7234: PPConditionalInfo CI;
97 7234: CI.IfLoc = DirectiveStart;
98 7234: CI.WasSkipping = WasSkipping;
99 7234: CI.FoundNonSkip = FoundNonSkip;
100 7234: CI.FoundElse = FoundElse;
101 7234: ConditionalStack.push_back(CI);
102 7234: }
103 : void pushConditionalLevel(const PPConditionalInfo &CI) {
104 : ConditionalStack.push_back(CI);
105 : }
106 :
107 : /// popConditionalLevel - Remove an entry off the top of the conditional
108 : /// stack, returning information about it. If the conditional stack is empty,
109 : /// this returns true and does not fill in the arguments.
110 7233: bool popConditionalLevel(PPConditionalInfo &CI) {
111 7233: if (ConditionalStack.empty()) return true;
112 7233: CI = ConditionalStack.back();
113 7233: ConditionalStack.pop_back();
114 7233: return false;
115 : }
116 :
117 : /// peekConditionalLevel - Return the top of the conditional stack. This
118 : /// requires that there be a conditional active.
119 1316: PPConditionalInfo &peekConditionalLevel() {
120 1316: assert(!ConditionalStack.empty() && "No conditionals active!");
121 1316: return ConditionalStack.back();
122 : }
123 :
124 8527: unsigned getConditionalStackDepth() const { return ConditionalStack.size(); }
125 :
126 : public:
127 :
128 : //===--------------------------------------------------------------------===//
129 : // Misc. lexing methods.
130 :
131 : /// LexIncludeFilename - After the preprocessor has parsed a #include, lex and
132 : /// (potentially) macro expand the filename. If the sequence parsed is not
133 : /// lexically legal, emit a diagnostic and return a result EOM token.
134 : void LexIncludeFilename(Token &Result);
135 :
136 : /// setParsingPreprocessorDirective - Inform the lexer whether or not
137 : /// we are currently lexing a preprocessor directive.
138 2: void setParsingPreprocessorDirective(bool f) {
139 2: ParsingPreprocessorDirective = f;
140 2: }
141 :
142 : /// isLexingRawMode - Return true if this lexer is in raw mode or not.
143 57884: bool isLexingRawMode() const { return LexingRawMode; }
144 :
145 : /// getPP - Return the preprocessor object for this lexer.
146 : Preprocessor *getPP() const { return PP; }
147 :
148 979: FileID getFileID() const {
149 : assert(PP &&
0: branch 0 not taken
0: branch 1 not taken
150 979: "PreprocessorLexer::getFileID() should only be used with a Preprocessor");
151 979: return FID;
152 : }
153 :
154 : /// getFileEntry - Return the FileEntry corresponding to this FileID. Like
155 : /// getFileID(), this only works for lexers with attached preprocessors.
156 : const FileEntry *getFileEntry() const;
157 : };
158 :
159 : } // end namespace clang
160 :
161 : #endif
Generated: 2010-02-10 01:31 by zcov