blob: 07329e0cc780408b8aed9570f41c493eee2b94cc [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"
Ted Kremenek97017da2008-11-12 22:43:05 +000018using namespace clang;
19
Ted Kremenek56758d22008-11-19 21:57:25 +000020PreprocessorLexer::PreprocessorLexer(Preprocessor* pp, SourceLocation L)
Chris Lattnercdf600e2009-01-16 07:00:02 +000021 : PP(pp), FileID(pp->getSourceManager().getSpellingLoc(L).getFileID()),
Ted Kremenekc62e3a82008-11-20 01:29:45 +000022 ParsingPreprocessorDirective(false),
23 ParsingFilename(false),
24 LexingRawMode(false) {}
Ted Kremenek56758d22008-11-19 21:57:25 +000025
Ted Kremenek957be412008-11-12 22:48:57 +000026PreprocessorLexer::~PreprocessorLexer() {}
27
Ted Kremenek97017da2008-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 Lattner82b474f2008-11-22 06:20:42 +000046 PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
Ted Kremenek97017da2008-11-12 22:43:05 +000047}