clang API Documentation
00001 //===--- PreprocessorLexer.cpp - C Language Family Lexer ------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the PreprocessorLexer and Token interfaces. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "clang/Lex/PreprocessorLexer.h" 00015 #include "clang/Lex/Preprocessor.h" 00016 #include "clang/Lex/LexDiagnostic.h" 00017 #include "clang/Basic/SourceManager.h" 00018 using namespace clang; 00019 00020 void PreprocessorLexer::anchor() { } 00021 00022 PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid) 00023 : PP(pp), FID(fid), InitialNumSLocEntries(0), 00024 ParsingPreprocessorDirective(false), 00025 ParsingFilename(false), LexingRawMode(false) { 00026 if (pp) 00027 InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size(); 00028 } 00029 00030 /// LexIncludeFilename - After the preprocessor has parsed a #include, lex and 00031 /// (potentially) macro expand the filename. 00032 void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) { 00033 assert(ParsingPreprocessorDirective && 00034 ParsingFilename == false && 00035 "Must be in a preprocessing directive!"); 00036 00037 // We are now parsing a filename! 00038 ParsingFilename = true; 00039 00040 // Lex the filename. 00041 IndirectLex(FilenameTok); 00042 00043 // We should have obtained the filename now. 00044 ParsingFilename = false; 00045 00046 // No filename? 00047 if (FilenameTok.is(tok::eod)) 00048 PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename); 00049 } 00050 00051 /// getFileEntry - Return the FileEntry corresponding to this FileID. Like 00052 /// getFileID(), this only works for lexers with attached preprocessors. 00053 const FileEntry *PreprocessorLexer::getFileEntry() const { 00054 return PP->getSourceManager().getFileEntryForID(getFileID()); 00055 }