Changeset View
Changeset View
Standalone View
Standalone View
clang/include/clang/Lex/PreprocessorLexer.h
//===- PreprocessorLexer.h - C Language Family Lexer ------------*- C++ -*-===// | //===- PreprocessorLexer.h - C Language Family Lexer ------------*- C++ -*-===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// | // | ||||
/// \file | /// \file | ||||
/// Defines the PreprocessorLexer interface. | /// Defines the PreprocessorLexer interface. | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#ifndef LLVM_CLANG_LEX_PREPROCESSORLEXER_H | #ifndef LLVM_CLANG_LEX_PREPROCESSORLEXER_H | ||||
#define LLVM_CLANG_LEX_PREPROCESSORLEXER_H | #define LLVM_CLANG_LEX_PREPROCESSORLEXER_H | ||||
#include "clang/Basic/SourceLocation.h" | |||||
#include "clang/Lex/HeaderSearch.h" | |||||
#include "clang/Lex/MultipleIncludeOpt.h" | #include "clang/Lex/MultipleIncludeOpt.h" | ||||
#include "clang/Lex/Token.h" | #include "clang/Lex/Token.h" | ||||
#include "clang/Basic/SourceLocation.h" | |||||
#include "llvm/ADT/ArrayRef.h" | #include "llvm/ADT/ArrayRef.h" | ||||
#include "llvm/ADT/SmallVector.h" | #include "llvm/ADT/SmallVector.h" | ||||
#include "llvm/ADT/StringMap.h" | |||||
#include <cassert> | #include <cassert> | ||||
namespace clang { | namespace clang { | ||||
class FileEntry; | class FileEntry; | ||||
class Preprocessor; | class Preprocessor; | ||||
class PreprocessorLexer { | class PreprocessorLexer { | ||||
Show All 39 Lines | protected: | ||||
/// A state machine that detects the \#ifndef-wrapping a file | /// A state machine that detects the \#ifndef-wrapping a file | ||||
/// idiom for the multiple-include optimization. | /// idiom for the multiple-include optimization. | ||||
MultipleIncludeOpt MIOpt; | MultipleIncludeOpt MIOpt; | ||||
/// Information about the set of \#if/\#ifdef/\#ifndef blocks | /// Information about the set of \#if/\#ifdef/\#ifndef blocks | ||||
/// we are currently in. | /// we are currently in. | ||||
SmallVector<PPConditionalInfo, 4> ConditionalStack; | SmallVector<PPConditionalInfo, 4> ConditionalStack; | ||||
struct IncludeInfo { | |||||
const FileEntry *File; | |||||
SourceLocation Location; | |||||
}; | |||||
// A complete history of all the files included by the current file. | |||||
llvm::StringMap<IncludeInfo> IncludeHistory; | |||||
PreprocessorLexer() : FID() {} | PreprocessorLexer() : FID() {} | ||||
PreprocessorLexer(Preprocessor *pp, FileID fid); | PreprocessorLexer(Preprocessor *pp, FileID fid); | ||||
virtual ~PreprocessorLexer() = default; | virtual ~PreprocessorLexer() = default; | ||||
virtual void IndirectLex(Token& Result) = 0; | virtual void IndirectLex(Token& Result) = 0; | ||||
/// Return the source location for the next observable location. | /// Return the source location for the next observable location. | ||||
virtual SourceLocation getSourceLocation() = 0; | virtual SourceLocation getSourceLocation() = 0; | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | public: | ||||
conditional_iterator conditional_end() const { | conditional_iterator conditional_end() const { | ||||
return ConditionalStack.end(); | return ConditionalStack.end(); | ||||
} | } | ||||
void setConditionalLevels(ArrayRef<PPConditionalInfo> CL) { | void setConditionalLevels(ArrayRef<PPConditionalInfo> CL) { | ||||
ConditionalStack.clear(); | ConditionalStack.clear(); | ||||
ConditionalStack.append(CL.begin(), CL.end()); | ConditionalStack.append(CL.begin(), CL.end()); | ||||
} | } | ||||
void addInclude(StringRef Filename, const FileEntry &File, | |||||
SourceLocation Location) { | |||||
aaron.ballman: It's not wrong, but we don't usually do top-level `const` qualification of value types. | |||||
IncludeHistory.insert({Filename, {&File, Location}}); | |||||
} | |||||
const llvm::StringMap<IncludeInfo> &getIncludeHistory() const { | |||||
return IncludeHistory; | |||||
} | |||||
}; | }; | ||||
} // namespace clang | } // namespace clang | ||||
#endif // LLVM_CLANG_LEX_PREPROCESSORLEXER_H | #endif // LLVM_CLANG_LEX_PREPROCESSORLEXER_H |
It's not wrong, but we don't usually do top-level const qualification of value types.