]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/lib/Lex/PreprocessorLexer.cpp
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / tools / clang / lib / Lex / PreprocessorLexer.cpp
1 //===--- 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/Lex/LexDiagnostic.h"
17 #include "clang/Basic/SourceManager.h"
18 using namespace clang;
19
20 PreprocessorLexer::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
28 /// LexIncludeFilename - After the preprocessor has parsed a #include, lex and
29 /// (potentially) macro expand the filename.
30 void 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::eod))
46     PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
47 }
48
49 /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
50 /// getFileID(), this only works for lexers with attached preprocessors.
51 const FileEntry *PreprocessorLexer::getFileEntry() const {
52   return PP->getSourceManager().getFileEntryForID(getFileID());
53 }