clang  3.9.0
PreprocessorLexer.cpp
Go to the documentation of this file.
1 //===--- PreprocessorLexer.cpp - C Language Family Lexer ------------------===//
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 implements the PreprocessorLexer and Token interfaces.
11 //
12 //===----------------------------------------------------------------------===//
13 
17 #include "clang/Lex/Preprocessor.h"
18 using namespace clang;
19 
20 void PreprocessorLexer::anchor() { }
21 
23  : PP(pp), FID(fid), InitialNumSLocEntries(0),
24  ParsingPreprocessorDirective(false),
25  ParsingFilename(false), LexingRawMode(false) {
26  if (pp)
28 }
29 
30 /// \brief After the preprocessor has parsed a \#include, lex and
31 /// (potentially) macro expand the filename.
34  ParsingFilename == false &&
35  "Must be in a preprocessing directive!");
36 
37  // We are now parsing a filename!
38  ParsingFilename = true;
39 
40  // Lex the filename.
41  if (LexingRawMode)
42  IndirectLex(FilenameTok);
43  else
44  PP->Lex(FilenameTok);
45 
46  // We should have obtained the filename now.
47  ParsingFilename = false;
48 
49  // No filename?
50  if (FilenameTok.is(tok::eod))
51  PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
52 }
53 
54 /// getFileEntry - Return the FileEntry corresponding to this FileID. Like
55 /// getFileID(), this only works for lexers with attached preprocessors.
58 }
SourceManager & getSourceManager() const
Definition: Preprocessor.h:694
unsigned local_sloc_entry_size() const
Get the number of local SLocEntries we have.
unsigned InitialNumSLocEntries
Number of SLocEntries before lexing the file.
Defines the SourceManager interface.
bool ParsingPreprocessorDirective
True when parsing #XXX; turns '\n' into a tok::eod token.
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
const FileEntry * getFileEntry() const
getFileEntry - Return the FileEntry corresponding to this FileID.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
bool ParsingFilename
True after #include; turns <xx> into a tok::angle_string_literal token.
bool LexingRawMode
True if in raw mode.
Defines the clang::Preprocessor interface.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:123
#define false
Definition: stdbool.h:33
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:53
void Lex(Token &Result)
Lex the next token for this preprocessor.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
Definition: Token.h:94
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
void LexIncludeFilename(Token &Result)
After the preprocessor has parsed a #include, lex and (potentially) macro expand the filename...
virtual void IndirectLex(Token &Result)=0
Defines the PreprocessorLexer interface.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:97