PreprocessorLexer.cpp revision 306fda76b0818eb7c215094123f2e16729a44aed
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/Lex/Preprocessor.h"
16#include "clang/Basic/Diagnostic.h"
17#include "clang/Basic/SourceManager.h"
18using namespace clang;
19
20PreprocessorLexer::PreprocessorLexer(Preprocessor* pp, SourceLocation L)
21  :  PP(pp), FileID(pp->getSourceManager().getPhysicalLoc(L).getFileID()),
22     ParsingPreprocessorDirective(false),
23     ParsingFilename(false),
24     LexingRawMode(false) {}
25
26PreprocessorLexer::~PreprocessorLexer() {}
27
28/// LexIncludeFilename - After the preprocessor has parsed a #include, lex and
29/// (potentially) macro expand the filename.
30void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
31  assert(ParsingPreprocessorDirective &&
32         ParsingFilename == false &&
33         "Must be in a preprocessing directive!");
34
35  // We are now parsing a filename!
36  ParsingFilename = true;
37
38  // Lex the filename.
39  IndirectLex(FilenameTok);
40
41  // We should have obtained the filename now.
42  ParsingFilename = false;
43
44  // No filename?
45  if (FilenameTok.is(tok::eom))
46    PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
47}
48