1 //===- PreprocessorLexer.cpp - C Language Family Lexer --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the PreprocessorLexer and Token interfaces.
12 //===----------------------------------------------------------------------===//
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"
21 using namespace clang;
23 void PreprocessorLexer::anchor() {}
25 PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
28 InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
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!");
38 // We are now parsing a filename!
39 ParsingFilename = true;
43 IndirectLex(FilenameTok);
47 // We should have obtained the filename now.
48 ParsingFilename = false;
51 if (FilenameTok.is(tok::eod))
52 PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
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());