• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 using namespace clang;
19 
anchor()20 void PreprocessorLexer::anchor() { }
21 
PreprocessorLexer(Preprocessor * pp,FileID fid)22 PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
23   : PP(pp), FID(fid), InitialNumSLocEntries(0),
24     ParsingPreprocessorDirective(false),
25     ParsingFilename(false), LexingRawMode(false) {
26   if (pp)
27     InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
28 }
29 
30 /// \brief After the preprocessor has parsed a \#include, lex and
31 /// (potentially) macro expand the filename.
LexIncludeFilename(Token & FilenameTok)32 void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
33   assert(ParsingPreprocessorDirective &&
34          ParsingFilename == false &&
35          "Must be in a preprocessing directive!");
36 
37   // We are now parsing a filename!
38   ParsingFilename = true;
39 
40   // Lex the filename.
41   IndirectLex(FilenameTok);
42 
43   // We should have obtained the filename now.
44   ParsingFilename = false;
45 
46   // No filename?
47   if (FilenameTok.is(tok::eod))
48     PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
49 }
50 
51 /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
52 /// getFileID(), this only works for lexers with attached preprocessors.
getFileEntry() const53 const FileEntry *PreprocessorLexer::getFileEntry() const {
54   return PP->getSourceManager().getFileEntryForID(getFileID());
55 }
56