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 } 60