blob: 6e479625e0fde38ed13d5f139fa44f3a4c5daff8 [file] [log] [blame]
Ted Kremenek97017da2008-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"
18
19using namespace clang;
20
Ted Kremenek56758d22008-11-19 21:57:25 +000021PreprocessorLexer::PreprocessorLexer(Preprocessor* pp, SourceLocation L)
Ted Kremenekc62e3a82008-11-20 01:29:45 +000022 : PP(pp), FileID(pp->getSourceManager().getPhysicalLoc(L).getFileID()),
23 ParsingPreprocessorDirective(false),
24 ParsingFilename(false),
25 LexingRawMode(false) {}
Ted Kremenek56758d22008-11-19 21:57:25 +000026
Ted Kremenek957be412008-11-12 22:48:57 +000027PreprocessorLexer::~PreprocessorLexer() {}
28
Ted Kremenek7ecfa132008-11-12 23:13:54 +000029void PreprocessorLexer::Diag(SourceLocation Loc, unsigned DiagID,
30 const std::string &Msg) const {
Chris Lattnerb7284dc2008-11-18 21:48:13 +000031 PP->Diag(Loc, DiagID) << Msg;
Ted Kremenek7ecfa132008-11-12 23:13:54 +000032}
33
Ted Kremenek97017da2008-11-12 22:43:05 +000034/// LexIncludeFilename - After the preprocessor has parsed a #include, lex and
35/// (potentially) macro expand the filename.
36void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
37 assert(ParsingPreprocessorDirective &&
38 ParsingFilename == false &&
39 "Must be in a preprocessing directive!");
40
41 // We are now parsing a filename!
42 ParsingFilename = true;
43
44 // Lex the filename.
45 IndirectLex(FilenameTok);
46
47 // We should have obtained the filename now.
48 ParsingFilename = false;
49
50 // No filename?
51 if (FilenameTok.is(tok::eom))
52 Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
53}