blob: 5a59849720f67a8fc2088b5ef03ee9a3f40bc3f1 [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"
Ted Kremenekab91b702008-11-12 22:43:05 +000015#include "clang/Basic/SourceManager.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000016#include "clang/Lex/LexDiagnostic.h"
17#include "clang/Lex/Preprocessor.h"
Ted Kremenekab91b702008-11-12 22:43:05 +000018using namespace clang;
19
David Blaikie99ba9e32011-12-20 02:48:34 +000020void PreprocessorLexer::anchor() { }
21
Argyrios Kyrtzidisd9d2b672011-08-21 23:33:04 +000022PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
23 : PP(pp), FID(fid), InitialNumSLocEntries(0),
24 ParsingPreprocessorDirective(false),
Daniel Dunbar6e649732012-11-13 19:12:37 +000025 ParsingFilename(false), LexingRawMode(false) {
Argyrios Kyrtzidisd9d2b672011-08-21 23:33:04 +000026 if (pp)
27 InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
28}
29
James Dennettd9868532012-06-17 03:41:54 +000030/// \brief After the preprocessor has parsed a \#include, lex and
Ted Kremenekab91b702008-11-12 22:43:05 +000031/// (potentially) macro expand the filename.
32void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
33 assert(ParsingPreprocessorDirective &&
34 ParsingFilename == false &&
35 "Must be in a preprocessing directive!");
36
37 // We are now parsing a filename!
38 ParsingFilename = true;
Mike Stump1eb44332009-09-09 15:08:12 +000039
Ted Kremenekab91b702008-11-12 22:43:05 +000040 // Lex the filename.
41 IndirectLex(FilenameTok);
42
43 // We should have obtained the filename now.
44 ParsingFilename = false;
Mike Stump1eb44332009-09-09 15:08:12 +000045
Ted Kremenekab91b702008-11-12 22:43:05 +000046 // No filename?
Peter Collingbourne84021552011-02-28 02:37:51 +000047 if (FilenameTok.is(tok::eod))
Chris Lattner306fda72008-11-22 06:20:42 +000048 PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
Ted Kremenekab91b702008-11-12 22:43:05 +000049}
Chris Lattner2b2453a2009-01-17 06:22:33 +000050
51/// getFileEntry - Return the FileEntry corresponding to this FileID. Like
52/// getFileID(), this only works for lexers with attached preprocessors.
53const FileEntry *PreprocessorLexer::getFileEntry() const {
54 return PP->getSourceManager().getFileEntryForID(getFileID());
55}