blob: 5b3538a45b1466df0ac668a1632d02d202978a88 [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"
16#include "clang/Basic/Diagnostic.h"
17#include "clang/Basic/SourceManager.h"
Ted Kremenekab91b702008-11-12 22:43:05 +000018using namespace clang;
19
Ted Kremenek41938c82008-11-19 21:57:25 +000020PreprocessorLexer::PreprocessorLexer(Preprocessor* pp, SourceLocation L)
Ted Kremenek452e3782008-11-20 01:29:45 +000021 : PP(pp), FileID(pp->getSourceManager().getPhysicalLoc(L).getFileID()),
22 ParsingPreprocessorDirective(false),
23 ParsingFilename(false),
24 LexingRawMode(false) {}
Ted Kremenek41938c82008-11-19 21:57:25 +000025
Ted Kremenek2c71d0f2008-11-12 22:48:57 +000026PreprocessorLexer::~PreprocessorLexer() {}
27
Ted Kremenekab91b702008-11-12 22:43:05 +000028/// 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))
Chris Lattner306fda72008-11-22 06:20:42 +000046 PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
Ted Kremenekab91b702008-11-12 22:43:05 +000047}