clang 8.0.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
14 #include "clang/Lex/PreprocessorLexer.h"
15 #include "clang/Basic/SourceManager.h"
16 #include "clang/Lex/LexDiagnostic.h"
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
25 PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
26 : PP(pp), FID(fid) {
27 if (pp)
28 InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
29 }
30
31 /// After the preprocessor has parsed a \#include, lex and
32 /// (potentially) macro expand the filename.
33 void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
34 assert(ParsingPreprocessorDirective &&
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.
57 const FileEntry *PreprocessorLexer::getFileEntry() const {
58 return PP->getSourceManager().getFileEntryForID(getFileID());
59 }
clang::Token::is
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
clang::PreprocessorLexer::InitialNumSLocEntries
unsigned InitialNumSLocEntries
Number of SLocEntries before lexing the file.
Definition: PreprocessorLexer.h:43
SourceManager.h
Defines the SourceManager interface.
clang::PreprocessorLexer::ParsingPreprocessorDirective
bool ParsingPreprocessorDirective
True when parsing #XXX; turns &#39;\n&#39; into a tok::eod token.
Definition: PreprocessorLexer.h:50
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
clang::PreprocessorLexer::FID
const FileID FID
The SourceManager FileID corresponding to the file being lexed.
Definition: PreprocessorLexer.h:40
clang::SourceManager::local_sloc_entry_size
unsigned local_sloc_entry_size() const
Get the number of local SLocEntries we have.
Definition: SourceManager.h:1617
clang::PreprocessorLexer::ParsingFilename
bool ParsingFilename
True after #include; turns <xx> into a tok::angle_string_literal token.
Definition: PreprocessorLexer.h:54
clang::PreprocessorLexer::LexingRawMode
bool LexingRawMode
True if in raw mode.
Definition: PreprocessorLexer.h:69
clang::SourceManager::getFileEntryForID
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
Definition: SourceManager.h:986
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:124
Preprocessor.h
Defines the clang::Preprocessor interface.
clang::PreprocessorLexer::getFileID
FileID getFileID() const
Definition: PreprocessorLexer.h:152
clang::PreprocessorLexer::PreprocessorLexer
PreprocessorLexer()
Definition: PreprocessorLexer.h:79
LexDiagnostic.h
clang::Preprocessor::getSourceManager
SourceManager & getSourceManager() const
Definition: Preprocessor.h:819
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:60
clang::Preprocessor::Lex
void Lex(Token &Result)
Lex the next token for this preprocessor.
Definition: Preprocessor.cpp:863
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:40
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::PreprocessorLexer::getFileEntry
const FileEntry * getFileEntry() const
getFileEntry - Return the FileEntry corresponding to this FileID.
Definition: PreprocessorLexer.cpp:57
clang::PreprocessorLexer::PP
Preprocessor * PP
Definition: PreprocessorLexer.h:37
clang::PreprocessorLexer::IndirectLex
virtual void IndirectLex(Token &Result)=0
PreprocessorLexer.h
Defines the PreprocessorLexer interface.
clang::PreprocessorLexer::LexIncludeFilename
void LexIncludeFilename(Token &FilenameTok)
After the preprocessor has parsed a #include, lex and (potentially) macro expand the filename...
Definition: PreprocessorLexer.cpp:33
Token.h
clang::Preprocessor::Diag
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
Definition: Preprocessor.h:1549
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:125