blob: 2ce181ef83a2afb17c48dd9ede4f0af9f9daa3bb [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"
18
19using namespace clang;
20
Ted Kremenek41938c82008-11-19 21:57:25 +000021PreprocessorLexer::PreprocessorLexer(Preprocessor* pp, SourceLocation L)
22 : PP(pp), FileID(pp->getSourceManager().getPhysicalLoc(L).getFileID()) {}
23
Ted Kremenek2c71d0f2008-11-12 22:48:57 +000024PreprocessorLexer::~PreprocessorLexer() {}
25
Ted Kremenekd6a2e7d2008-11-12 23:13:54 +000026void PreprocessorLexer::Diag(SourceLocation Loc, unsigned DiagID,
27 const std::string &Msg) const {
28 if (LexingRawMode && Diagnostic::isBuiltinNoteWarningOrExtension(DiagID))
29 return;
Chris Lattner204b2fe2008-11-18 21:48:13 +000030 PP->Diag(Loc, DiagID) << Msg;
Ted Kremenekd6a2e7d2008-11-12 23:13:54 +000031}
32
Ted Kremenekab91b702008-11-12 22:43:05 +000033/// LexIncludeFilename - After the preprocessor has parsed a #include, lex and
34/// (potentially) macro expand the filename.
35void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
36 assert(ParsingPreprocessorDirective &&
37 ParsingFilename == false &&
38 "Must be in a preprocessing directive!");
39
40 // We are now parsing a filename!
41 ParsingFilename = true;
42
43 // Lex the filename.
44 IndirectLex(FilenameTok);
45
46 // We should have obtained the filename now.
47 ParsingFilename = false;
48
49 // No filename?
50 if (FilenameTok.is(tok::eom))
51 Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
52}