2017-12-05 07:16:21 +08:00
|
|
|
//===- PreprocessorLexer.cpp - C Language Family Lexer --------------------===//
|
2008-11-13 06:43:05 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2008-11-13 06:43:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the PreprocessorLexer and Token interfaces.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Lex/PreprocessorLexer.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Lex/LexDiagnostic.h"
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2017-12-05 07:16:21 +08:00
|
|
|
#include "clang/Lex/Token.h"
|
|
|
|
#include <cassert>
|
|
|
|
|
2008-11-13 06:43:05 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2017-12-05 07:16:21 +08:00
|
|
|
void PreprocessorLexer::anchor() {}
|
2011-12-20 10:48:34 +08:00
|
|
|
|
2011-08-22 07:33:04 +08:00
|
|
|
PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
|
2017-12-05 07:16:21 +08:00
|
|
|
: PP(pp), FID(fid) {
|
2011-08-22 07:33:04 +08:00
|
|
|
if (pp)
|
|
|
|
InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// After the preprocessor has parsed a \#include, lex and
|
2008-11-13 06:43:05 +08:00
|
|
|
/// (potentially) macro expand the filename.
|
|
|
|
void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
|
|
|
|
assert(ParsingPreprocessorDirective &&
|
|
|
|
ParsingFilename == false &&
|
|
|
|
"Must be in a preprocessing directive!");
|
|
|
|
|
|
|
|
// We are now parsing a filename!
|
|
|
|
ParsingFilename = true;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-11-13 06:43:05 +08:00
|
|
|
// Lex the filename.
|
2013-09-19 08:41:32 +08:00
|
|
|
if (LexingRawMode)
|
|
|
|
IndirectLex(FilenameTok);
|
|
|
|
else
|
|
|
|
PP->Lex(FilenameTok);
|
2008-11-13 06:43:05 +08:00
|
|
|
|
|
|
|
// We should have obtained the filename now.
|
|
|
|
ParsingFilename = false;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-11-13 06:43:05 +08:00
|
|
|
// No filename?
|
2011-02-28 10:37:51 +08:00
|
|
|
if (FilenameTok.is(tok::eod))
|
2008-11-22 14:20:42 +08:00
|
|
|
PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
|
2008-11-13 06:43:05 +08:00
|
|
|
}
|
2009-01-17 14:22:33 +08:00
|
|
|
|
|
|
|
/// getFileEntry - Return the FileEntry corresponding to this FileID. Like
|
|
|
|
/// getFileID(), this only works for lexers with attached preprocessors.
|
|
|
|
const FileEntry *PreprocessorLexer::getFileEntry() const {
|
|
|
|
return PP->getSourceManager().getFileEntryForID(getFileID());
|
|
|
|
}
|