1193326Sed//===--- PreprocessorLexer.cpp - C Language Family Lexer ------------------===//
2193326Sed//
3193326Sed//                     The LLVM Compiler Infrastructure
4193326Sed//
5193326Sed// This file is distributed under the University of Illinois Open Source
6193326Sed// License. See LICENSE.TXT for details.
7193326Sed//
8193326Sed//===----------------------------------------------------------------------===//
9193326Sed//
10193326Sed//  This file implements the PreprocessorLexer and Token interfaces.
11193326Sed//
12193326Sed//===----------------------------------------------------------------------===//
13193326Sed
14193326Sed#include "clang/Lex/PreprocessorLexer.h"
15249423Sdim#include "clang/Basic/SourceManager.h"
16249423Sdim#include "clang/Lex/LexDiagnostic.h"
17193326Sed#include "clang/Lex/Preprocessor.h"
18193326Sedusing namespace clang;
19193326Sed
20234353Sdimvoid PreprocessorLexer::anchor() { }
21234353Sdim
22226633SdimPreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
23226633Sdim  : PP(pp), FID(fid), InitialNumSLocEntries(0),
24226633Sdim    ParsingPreprocessorDirective(false),
25226633Sdim    ParsingFilename(false), LexingRawMode(false) {
26226633Sdim  if (pp)
27226633Sdim    InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
28226633Sdim}
29226633Sdim
30239462Sdim/// \brief After the preprocessor has parsed a \#include, lex and
31193326Sed/// (potentially) macro expand the filename.
32193326Sedvoid PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
33193326Sed  assert(ParsingPreprocessorDirective &&
34193326Sed         ParsingFilename == false &&
35193326Sed         "Must be in a preprocessing directive!");
36193326Sed
37193326Sed  // We are now parsing a filename!
38193326Sed  ParsingFilename = true;
39198092Srdivacky
40193326Sed  // Lex the filename.
41263508Sdim  if (LexingRawMode)
42263508Sdim    IndirectLex(FilenameTok);
43263508Sdim  else
44263508Sdim    PP->Lex(FilenameTok);
45193326Sed
46193326Sed  // We should have obtained the filename now.
47193326Sed  ParsingFilename = false;
48198092Srdivacky
49193326Sed  // No filename?
50221345Sdim  if (FilenameTok.is(tok::eod))
51193326Sed    PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
52193326Sed}
53193326Sed
54193326Sed/// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
55193326Sed/// getFileID(), this only works for lexers with attached preprocessors.
56193326Sedconst FileEntry *PreprocessorLexer::getFileEntry() const {
57193326Sed  return PP->getSourceManager().getFileEntryForID(getFileID());
58193326Sed}
59