blob: f9dfad9c808ec505b55e4dfefbc581636e1bc743 [file] [log] [blame]
Ted Kremenekab91b702008-11-12 22:43:05 +00001//===--- 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"
Chris Lattner500d3292009-01-29 05:15:15 +000016#include "clang/Lex/LexDiagnostic.h"
Ted Kremenekab91b702008-11-12 22:43:05 +000017#include "clang/Basic/SourceManager.h"
Ted Kremenekab91b702008-11-12 22:43:05 +000018using namespace clang;
19
Ted Kremenekab91b702008-11-12 22:43:05 +000020/// LexIncludeFilename - After the preprocessor has parsed a #include, lex and
21/// (potentially) macro expand the filename.
22void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
23 assert(ParsingPreprocessorDirective &&
24 ParsingFilename == false &&
25 "Must be in a preprocessing directive!");
26
27 // We are now parsing a filename!
28 ParsingFilename = true;
29
30 // Lex the filename.
31 IndirectLex(FilenameTok);
32
33 // We should have obtained the filename now.
34 ParsingFilename = false;
35
36 // No filename?
37 if (FilenameTok.is(tok::eom))
Chris Lattner306fda72008-11-22 06:20:42 +000038 PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
Ted Kremenekab91b702008-11-12 22:43:05 +000039}
Chris Lattner2b2453a2009-01-17 06:22:33 +000040
41/// getFileEntry - Return the FileEntry corresponding to this FileID. Like
42/// getFileID(), this only works for lexers with attached preprocessors.
43const FileEntry *PreprocessorLexer::getFileEntry() const {
44 return PP->getSourceManager().getFileEntryForID(getFileID());
45}