clang  6.0.0svn
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 #include "clang/Lex/Token.h"
19 #include <cassert>
20 
21 using namespace clang;
22 
23 void PreprocessorLexer::anchor() {}
24 
26  : PP(pp), FID(fid) {
27  if (pp)
29 }
30 
31 /// \brief After the preprocessor has parsed a \#include, lex and
32 /// (potentially) macro expand the filename.
35  ParsingFilename == false &&
36  "Must be in a preprocessing directive!");
37 
38  // We are now parsing a filename!
39  ParsingFilename = true;
40 
41  // Lex the filename.
42  if (LexingRawMode)
43  IndirectLex(FilenameTok);
44  else
45  PP->Lex(FilenameTok);
46 
47  // We should have obtained the filename now.
48  ParsingFilename = false;
49 
50  // No filename?
51  if (FilenameTok.is(tok::eod))
52  PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
53 }
54 
55 /// getFileEntry - Return the FileEntry corresponding to this FileID. Like
56 /// getFileID(), this only works for lexers with attached preprocessors.
59 }
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:95
unsigned InitialNumSLocEntries
Number of SLocEntries before lexing the file.
Defines the SourceManager interface.
bool ParsingPreprocessorDirective
True when parsing #XXX; turns &#39;\n&#39; into a tok::eod token.
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
const FileID FID
The SourceManager FileID corresponding to the file being lexed.
unsigned local_sloc_entry_size() const
Get the number of local SLocEntries we have.
bool ParsingFilename
True after #include; turns <xx> into a tok::angle_string_literal token.
bool LexingRawMode
True if in raw mode.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:124
Defines the clang::Preprocessor interface.
SourceManager & getSourceManager() const
Definition: Preprocessor.h:819
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:59
void Lex(Token &Result)
Lex the next token for this preprocessor.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
const FileEntry * getFileEntry() const
getFileEntry - Return the FileEntry corresponding to this FileID.
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.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:127