blob: 0da9ef5531e7f70e4c2500cf7775a5ed82aee213 [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"
Chris Lattner500d3292009-01-29 05:15:15 +000016#include "clang/Lex/LexDiagnostic.h"
Ted Kremenekab91b702008-11-12 22:43:05 +000017#include "clang/Basic/SourceManager.h"
Ted Kremenekab91b702008-11-12 22:43:05 +000018using namespace clang;
19
Argyrios Kyrtzidisd9d2b672011-08-21 23:33:04 +000020PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
21 : PP(pp), FID(fid), InitialNumSLocEntries(0),
22 ParsingPreprocessorDirective(false),
23 ParsingFilename(false), LexingRawMode(false) {
24 if (pp)
25 InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
26}
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;
Mike Stump1eb44332009-09-09 15:08:12 +000037
Ted Kremenekab91b702008-11-12 22:43:05 +000038 // Lex the filename.
39 IndirectLex(FilenameTok);
40
41 // We should have obtained the filename now.
42 ParsingFilename = false;
Mike Stump1eb44332009-09-09 15:08:12 +000043
Ted Kremenekab91b702008-11-12 22:43:05 +000044 // No filename?
Peter Collingbourne84021552011-02-28 02:37:51 +000045 if (FilenameTok.is(tok::eod))
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}
Chris Lattner2b2453a2009-01-17 06:22:33 +000048
49/// getFileEntry - Return the FileEntry corresponding to this FileID. Like
50/// getFileID(), this only works for lexers with attached preprocessors.
51const FileEntry *PreprocessorLexer::getFileEntry() const {
52 return PP->getSourceManager().getFileEntryForID(getFileID());
53}