1*f4a2713aSLionel Sambuc //===--- PreprocessorLexer.cpp - C Language Family Lexer ------------------===//
2*f4a2713aSLionel Sambuc //
3*f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*f4a2713aSLionel Sambuc //
5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7*f4a2713aSLionel Sambuc //
8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9*f4a2713aSLionel Sambuc //
10*f4a2713aSLionel Sambuc //  This file implements the PreprocessorLexer and Token interfaces.
11*f4a2713aSLionel Sambuc //
12*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc #include "clang/Lex/PreprocessorLexer.h"
15*f4a2713aSLionel Sambuc #include "clang/Basic/SourceManager.h"
16*f4a2713aSLionel Sambuc #include "clang/Lex/LexDiagnostic.h"
17*f4a2713aSLionel Sambuc #include "clang/Lex/Preprocessor.h"
18*f4a2713aSLionel Sambuc using namespace clang;
19*f4a2713aSLionel Sambuc 
anchor()20*f4a2713aSLionel Sambuc void PreprocessorLexer::anchor() { }
21*f4a2713aSLionel Sambuc 
PreprocessorLexer(Preprocessor * pp,FileID fid)22*f4a2713aSLionel Sambuc PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
23*f4a2713aSLionel Sambuc   : PP(pp), FID(fid), InitialNumSLocEntries(0),
24*f4a2713aSLionel Sambuc     ParsingPreprocessorDirective(false),
25*f4a2713aSLionel Sambuc     ParsingFilename(false), LexingRawMode(false) {
26*f4a2713aSLionel Sambuc   if (pp)
27*f4a2713aSLionel Sambuc     InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
28*f4a2713aSLionel Sambuc }
29*f4a2713aSLionel Sambuc 
30*f4a2713aSLionel Sambuc /// \brief After the preprocessor has parsed a \#include, lex and
31*f4a2713aSLionel Sambuc /// (potentially) macro expand the filename.
LexIncludeFilename(Token & FilenameTok)32*f4a2713aSLionel Sambuc void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
33*f4a2713aSLionel Sambuc   assert(ParsingPreprocessorDirective &&
34*f4a2713aSLionel Sambuc          ParsingFilename == false &&
35*f4a2713aSLionel Sambuc          "Must be in a preprocessing directive!");
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc   // We are now parsing a filename!
38*f4a2713aSLionel Sambuc   ParsingFilename = true;
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc   // Lex the filename.
41*f4a2713aSLionel Sambuc   if (LexingRawMode)
42*f4a2713aSLionel Sambuc     IndirectLex(FilenameTok);
43*f4a2713aSLionel Sambuc   else
44*f4a2713aSLionel Sambuc     PP->Lex(FilenameTok);
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc   // We should have obtained the filename now.
47*f4a2713aSLionel Sambuc   ParsingFilename = false;
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc   // No filename?
50*f4a2713aSLionel Sambuc   if (FilenameTok.is(tok::eod))
51*f4a2713aSLionel Sambuc     PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
52*f4a2713aSLionel Sambuc }
53*f4a2713aSLionel Sambuc 
54*f4a2713aSLionel Sambuc /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
55*f4a2713aSLionel Sambuc /// getFileID(), this only works for lexers with attached preprocessors.
getFileEntry() const56*f4a2713aSLionel Sambuc const FileEntry *PreprocessorLexer::getFileEntry() const {
57*f4a2713aSLionel Sambuc   return PP->getSourceManager().getFileEntryForID(getFileID());
58*f4a2713aSLionel Sambuc }
59