1e5dd7070Spatrick //===- PreprocessorLexer.cpp - C Language Family Lexer --------------------===// 2e5dd7070Spatrick // 3e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information. 5e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e5dd7070Spatrick // 7e5dd7070Spatrick //===----------------------------------------------------------------------===// 8e5dd7070Spatrick // 9e5dd7070Spatrick // This file implements the PreprocessorLexer and Token interfaces. 10e5dd7070Spatrick // 11e5dd7070Spatrick //===----------------------------------------------------------------------===// 12e5dd7070Spatrick 13e5dd7070Spatrick #include "clang/Lex/PreprocessorLexer.h" 14e5dd7070Spatrick #include "clang/Basic/SourceManager.h" 15e5dd7070Spatrick #include "clang/Lex/LexDiagnostic.h" 16e5dd7070Spatrick #include "clang/Lex/Preprocessor.h" 17e5dd7070Spatrick #include "clang/Lex/Token.h" 18e5dd7070Spatrick #include <cassert> 19e5dd7070Spatrick 20e5dd7070Spatrick using namespace clang; 21e5dd7070Spatrick anchor()22e5dd7070Spatrickvoid PreprocessorLexer::anchor() {} 23e5dd7070Spatrick PreprocessorLexer(Preprocessor * pp,FileID fid)24e5dd7070SpatrickPreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid) 25e5dd7070Spatrick : PP(pp), FID(fid) { 26e5dd7070Spatrick if (pp) 27e5dd7070Spatrick InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size(); 28e5dd7070Spatrick } 29e5dd7070Spatrick 30e5dd7070Spatrick /// After the preprocessor has parsed a \#include, lex and 31e5dd7070Spatrick /// (potentially) macro expand the filename. LexIncludeFilename(Token & FilenameTok)32e5dd7070Spatrickvoid PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) { 33e5dd7070Spatrick assert(ParsingFilename == false && "reentered LexIncludeFilename"); 34e5dd7070Spatrick 35e5dd7070Spatrick // We are now parsing a filename! 36e5dd7070Spatrick ParsingFilename = true; 37e5dd7070Spatrick 38e5dd7070Spatrick // Lex the filename. 39e5dd7070Spatrick if (LexingRawMode) 40e5dd7070Spatrick IndirectLex(FilenameTok); 41e5dd7070Spatrick else 42e5dd7070Spatrick PP->Lex(FilenameTok); 43e5dd7070Spatrick 44e5dd7070Spatrick // We should have obtained the filename now. 45e5dd7070Spatrick ParsingFilename = false; 46e5dd7070Spatrick } 47e5dd7070Spatrick 48e5dd7070Spatrick /// getFileEntry - Return the FileEntry corresponding to this FileID. Like 49e5dd7070Spatrick /// getFileID(), this only works for lexers with attached preprocessors. 50*12c85518Srobert OptionalFileEntryRefDegradesToFileEntryPtr getFileEntry() const51*12c85518SrobertPreprocessorLexer::getFileEntry() const { 52*12c85518Srobert return PP->getSourceManager().getFileEntryRefForID(getFileID()); 53e5dd7070Spatrick } 54