clang API Documentation

PreprocessorLexer.cpp
Go to the documentation of this file.
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/Basic/SourceManager.h"
00016 #include "clang/Lex/LexDiagnostic.h"
00017 #include "clang/Lex/Preprocessor.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 /// \brief 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   if (LexingRawMode)
00042     IndirectLex(FilenameTok);
00043   else
00044     PP->Lex(FilenameTok);
00045 
00046   // We should have obtained the filename now.
00047   ParsingFilename = false;
00048 
00049   // No filename?
00050   if (FilenameTok.is(tok::eod))
00051     PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
00052 }
00053 
00054 /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
00055 /// getFileID(), this only works for lexers with attached preprocessors.
00056 const FileEntry *PreprocessorLexer::getFileEntry() const {
00057   return PP->getSourceManager().getFileEntryForID(getFileID());
00058 }