clang
10.0.0git
|
#include "clang/Basic/Attributes.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/CodeCompletionHandler.h"
#include "clang/Lex/DirectoryLookup.h"
#include "clang/Lex/ExternalPreprocessorSource.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/LexDiagnostic.h"
#include "clang/Lex/MacroArgs.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/PreprocessorLexer.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Lex/Token.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstring>
#include <ctime>
#include <string>
#include <tuple>
#include <utility>
#include "clang/Basic/Features.def"
Go to the source code of this file.
Macros | |
#define | FEATURE(Name, Predicate) .Case(#Name, Predicate) |
#define | EXTENSION(Name, Predicate) .Case(#Name, Predicate) |
Enumerations | |
enum | Bracket { Brace, Paren } |
Functions | |
static IdentifierInfo * | RegisterBuiltinMacro (Preprocessor &PP, const char *Name) |
RegisterBuiltinMacro - Register the specified identifier in the identifier table and mark it as a builtin macro to be expanded. More... | |
static bool | isTrivialSingleTokenExpansion (const MacroInfo *MI, const IdentifierInfo *MacroIdent, Preprocessor &PP) |
isTrivialSingleTokenExpansion - Return true if MI, which has a single token in its expansion, currently expands to that token literally. More... | |
static bool | CheckMatchedBrackets (const SmallVectorImpl< Token > &Tokens) |
CheckMatchedBrackets - Returns true if the braces and parentheses in the token vector are properly nested. More... | |
static bool | GenerateNewArgTokens (Preprocessor &PP, SmallVectorImpl< Token > &OldTokens, SmallVectorImpl< Token > &NewTokens, unsigned &NumArgs, SmallVectorImpl< SourceRange > &ParenHints, SmallVectorImpl< SourceRange > &InitLists) |
GenerateNewArgTokens - Returns true if OldTokens can be converted to a new vector of tokens in NewTokens. More... | |
static void | ComputeDATE_TIME (SourceLocation &DATELoc, SourceLocation &TIMELoc, Preprocessor &PP) |
ComputeDATE_TIME - Compute the current time, enter it into the specified scratch buffer, then return DATELoc/TIMELoc locations with the position of the identifier tokens inserted. More... | |
static bool | HasFeature (const Preprocessor &PP, StringRef Feature) |
HasFeature - Return true if we recognize and implement the feature specified by the identifier as a standard language feature. More... | |
static bool | HasExtension (const Preprocessor &PP, StringRef Extension) |
HasExtension - Return true if we recognize and implement the feature specified by the identifier, either as an extension or a standard language feature. More... | |
static bool | EvaluateHasIncludeCommon (Token &Tok, IdentifierInfo *II, Preprocessor &PP, const DirectoryLookup *LookupFrom, const FileEntry *LookupFromFile) |
EvaluateHasIncludeCommon - Process a '__has_include("path")' or '__has_include_next("path")' expression. More... | |
static bool | EvaluateHasInclude (Token &Tok, IdentifierInfo *II, Preprocessor &PP) |
EvaluateHasInclude - Process a '__has_include("path")' expression. More... | |
static bool | EvaluateHasIncludeNext (Token &Tok, IdentifierInfo *II, Preprocessor &PP) |
EvaluateHasIncludeNext - Process '__has_include_next("path")' expression. More... | |
static void | EvaluateFeatureLikeBuiltinMacro (llvm::raw_svector_ostream &OS, Token &Tok, IdentifierInfo *II, Preprocessor &PP, llvm::function_ref< int(Token &Tok, bool &HasLexedNextTok)> Op) |
Process single-argument builtin feature-like macros that return integer values. More... | |
static IdentifierInfo * | ExpectFeatureIdentifierInfo (Token &Tok, Preprocessor &PP, signed DiagID) |
Helper function to return the IdentifierInfo structure of a Token or generate a diagnostic if none available. More... | |
static bool | isTargetArch (const TargetInfo &TI, const IdentifierInfo *II) |
Implements the __is_target_arch builtin macro. More... | |
static bool | isTargetVendor (const TargetInfo &TI, const IdentifierInfo *II) |
Implements the __is_target_vendor builtin macro. More... | |
static bool | isTargetOS (const TargetInfo &TI, const IdentifierInfo *II) |
Implements the __is_target_os builtin macro. More... | |
static bool | isTargetEnvironment (const TargetInfo &TI, const IdentifierInfo *II) |
Implements the __is_target_environment builtin macro. More... | |
static void | remapMacroPath (SmallString< 256 > &Path, const std::map< std::string, std::string, std::greater< std::string >> &MacroPrefixMap) |
#define EXTENSION | ( | Name, | |
Predicate | |||
) | .Case(#Name, Predicate) |
#define FEATURE | ( | Name, | |
Predicate | |||
) | .Case(#Name, Predicate) |
enum Bracket |
Enumerator | |
---|---|
Brace | |
Paren |
Definition at line 627 of file PPMacroExpansion.cpp.
|
static |
CheckMatchedBrackets - Returns true if the braces and parentheses in the token vector are properly nested.
Definition at line 634 of file PPMacroExpansion.cpp.
Referenced by GenerateNewArgTokens().
|
static |
ComputeDATE_TIME - Compute the current time, enter it into the specified scratch buffer, then return DATELoc/TIMELoc locations with the position of the identifier tokens inserted.
Definition at line 1075 of file PPMacroExpansion.cpp.
References clang::Preprocessor::CreateString(), clang::Token::getLocation(), and clang::Token::startToken().
Referenced by remapMacroPath().
|
static |
Process single-argument builtin feature-like macros that return integer values.
Definition at line 1286 of file PPMacroExpansion.cpp.
References clang::Preprocessor::Diag(), clang::comments::tok::eof, clang::Token::getIdentifierInfo(), clang::Token::getKind(), clang::Token::getLocation(), clang::Token::isNot(), clang::Token::isOneOf(), clang::Preprocessor::LexUnexpandedToken(), clang::Result, clang::Token::setKind(), and clang::format::Tok.
Referenced by remapMacroPath().
|
static |
EvaluateHasInclude - Process a '__has_include("path")' expression.
Returns true if successful.
Definition at line 1245 of file PPMacroExpansion.cpp.
References EvaluateHasIncludeCommon().
Referenced by remapMacroPath().
|
static |
EvaluateHasIncludeCommon - Process a '__has_include("path")' or '__has_include_next("path")' expression.
Returns true if successful.
Definition at line 1155 of file PPMacroExpansion.cpp.
References clang::SrcMgr::C_User, clang::Preprocessor::Diag(), Filename, clang::HeaderSearch::getFileDirFlavor(), clang::Preprocessor::getHeaderSearchInfo(), clang::Preprocessor::GetIncludeFilenameSpelling(), clang::Token::getKind(), clang::Token::getLocation(), clang::Preprocessor::getLocForEndOfToken(), clang::Preprocessor::getPPCallbacks(), clang::Preprocessor::getSpelling(), clang::Token::is(), clang::Token::isNot(), clang::Preprocessor::isParsingIfOrElifDirective(), clang::Preprocessor::LexHeaderName(), clang::Preprocessor::LexNonComment(), clang::Preprocessor::LookupFile(), and clang::Token::setIdentifierInfo().
Referenced by EvaluateHasInclude(), and EvaluateHasIncludeNext().
|
static |
EvaluateHasIncludeNext - Process '__has_include_next("path")' expression.
Returns true if successful.
Definition at line 1252 of file PPMacroExpansion.cpp.
References clang::Preprocessor::Diag(), EvaluateHasIncludeCommon(), clang::Preprocessor::GetCurDirLookup(), clang::Preprocessor::getCurrentLexer(), clang::Preprocessor::getCurrentLexerSubmodule(), clang::PreprocessorLexer::getFileEntry(), clang::Preprocessor::getLangOpts(), clang::LangOptions::IsHeaderFile, and clang::Preprocessor::isInPrimaryFile().
Referenced by remapMacroPath().
|
static |
Helper function to return the IdentifierInfo structure of a Token or generate a diagnostic if none available.
Definition at line 1393 of file PPMacroExpansion.cpp.
References clang::Preprocessor::Diag(), clang::Token::getIdentifierInfo(), clang::Token::getLocation(), and clang::Token::isAnnotation().
Referenced by remapMacroPath().
|
static |
GenerateNewArgTokens - Returns true if OldTokens can be converted to a new vector of tokens in NewTokens.
The new number of arguments will be placed in NumArgs and the ranges which need to surrounded in parentheses will be in ParenHints. Returns false if the token stream cannot be changed. If this is because of an initializer list starting a macro argument, the range of those initializer lists will be place in InitLists.
Definition at line 663 of file PPMacroExpansion.cpp.
References CheckMatchedBrackets(), clang::Token::clearFlag(), clang::CodeCompletionHandler::CodeCompleteMacroArgument(), clang::MacroArgs::create(), clang::FixItHint::CreateInsertion(), clang::Preprocessor::Diag(), clang::Token::DisableExpand, clang::comments::tok::eof, clang::MacroInfo::getDefinitionLoc(), clang::Token::getFlags(), clang::Token::getIdentifierInfo(), clang::Token::getKind(), clang::Token::getLocation(), clang::Preprocessor::getLocForEndOfToken(), clang::Preprocessor::getMacroInfo(), clang::MacroInfo::getNumParams(), clang::MacroInfo::hasCommaPasting(), clang::Token::IgnoredComma, clang::Token::is(), clang::Token::isAnnotation(), clang::MacroInfo::isEnabled(), clang::SourceLocation::isInvalid(), clang::Token::isNot(), clang::Token::isOneOf(), clang::MacroInfo::isVariadic(), clang::Preprocessor::LexUnexpandedToken(), clang::Token::setFlag(), clang::Token::setKind(), clang::Token::setLength(), clang::Token::setLocation(), clang::Token::startToken(), and clang::format::Tok.
|
static |
HasExtension - Return true if we recognize and implement the feature specified by the identifier, either as an extension or a standard language feature.
Definition at line 1126 of file PPMacroExpansion.cpp.
References clang::Default, clang::diag::Error, clang::Preprocessor::getDiagnostics(), clang::DiagnosticsEngine::getExtensionHandlingBehavior(), clang::Preprocessor::getLangOpts(), and HasFeature().
Referenced by remapMacroPath().
|
static |
HasFeature - Return true if we recognize and implement the feature specified by the identifier as a standard language feature.
Definition at line 1109 of file PPMacroExpansion.cpp.
References clang::Default, and clang::Preprocessor::getLangOpts().
Referenced by HasExtension(), hasFeature(), and remapMacroPath().
|
static |
Implements the __is_target_arch builtin macro.
Definition at line 1405 of file PPMacroExpansion.cpp.
References clang::IdentifierInfo::getName(), and clang::TargetInfo::getTriple().
Referenced by remapMacroPath().
|
static |
Implements the __is_target_environment builtin macro.
Definition at line 1447 of file PPMacroExpansion.cpp.
References clang::IdentifierInfo::getName(), and clang::TargetInfo::getTriple().
Referenced by remapMacroPath().
|
static |
Implements the __is_target_os builtin macro.
Definition at line 1435 of file PPMacroExpansion.cpp.
References clang::IdentifierInfo::getName(), and clang::TargetInfo::getTriple().
Referenced by remapMacroPath().
|
static |
Implements the __is_target_vendor builtin macro.
Definition at line 1427 of file PPMacroExpansion.cpp.
References clang::IdentifierInfo::getName(), and clang::TargetInfo::getTriple().
Referenced by remapMacroPath().
|
static |
isTrivialSingleTokenExpansion - Return true if MI, which has a single token in its expansion, currently expands to that token literally.
Definition at line 400 of file PPMacroExpansion.cpp.
References clang::SourceManager::createExpansionLoc(), clang::MacroArgs::destroy(), clang::Preprocessor::Diag(), clang::Token::DisableExpand, clang::Preprocessor::EnterMacro(), clang::MultipleIncludeOpt::ExpandedMacro(), clang::MacroDefinition::forAllDefinitions(), clang::MacroInfo::getDefinitionLoc(), clang::Preprocessor::getExternalSource(), clang::Token::getIdentifierInfo(), clang::Token::getLength(), clang::Token::getLocation(), clang::MacroDefinition::getMacroInfo(), clang::Preprocessor::getMacroInfo(), clang::MacroInfo::getNumTokens(), clang::MacroInfo::getReplacementToken(), clang::Token::hasLeadingSpace(), Identifier, clang::MacroDefinition::isAmbiguous(), clang::Token::isAtStartOfLine(), clang::MacroInfo::isBuiltinMacro(), clang::MacroInfo::isFunctionLike(), clang::MacroInfo::isObjectLike(), clang::IdentifierInfo::isOutOfDate(), clang::Token::LeadingEmptyMacro, clang::Token::LeadingSpace, clang::Preprocessor::markMacroAsUsed(), clang::PreprocessorLexer::MIOpt, clang::MacroInfo::param_begin(), clang::MacroInfo::param_end(), clang::Token::setFlag(), clang::Token::setFlagValue(), clang::Token::setLocation(), clang::Token::StartOfLine, and clang::ExternalPreprocessorSource::updateOutOfDateIdentifier().
|
static |
RegisterBuiltinMacro - Register the specified identifier in the identifier table and mark it as a builtin macro to be expanded.
Definition at line 326 of file PPMacroExpansion.cpp.
|
static |
Definition at line 1454 of file PPMacroExpansion.cpp.
References clang::Preprocessor::AdvanceToTokenCharacter(), clang::C, clang::Token::clearFlag(), ComputeDATE_TIME(), clang::SourceManager::createExpansionLoc(), clang::Preprocessor::CreateString(), clang::LangOptions::CurrentModule, clang::CXX, clang::Declspec, Depth, clang::Preprocessor::Diag(), clang::comments::tok::eof, EvaluateFeatureLikeBuiltinMacro(), EvaluateHasInclude(), EvaluateHasIncludeNext(), ExpectFeatureIdentifierInfo(), clang::Preprocessor::FinishLexStringLiteral(), clang::IdentifierInfo::getBuiltinID(), clang::Preprocessor::getCurrentFileLexer(), clang::DiagnosticsEngine::getDiagnosticIDs(), clang::Preprocessor::getDiagnostics(), getDiagnosticsInGroup(), clang::CharSourceRange::getEnd(), clang::SourceManager::getExpansionRange(), clang::SourceManager::getFileEntryForID(), clang::PreprocessorLexer::getFileID(), clang::PresumedLoc::getFilename(), clang::Token::getIdentifierInfo(), clang::Preprocessor::getIdentifierInfo(), clang::PresumedLoc::getIncludeLoc(), clang::Token::getKind(), clang::Preprocessor::getLangOpts(), clang::Token::getLength(), clang::PresumedLoc::getLine(), clang::Token::getLocation(), clang::Preprocessor::getLocForEndOfToken(), clang::IdentifierInfo::getName(), clang::SourceManager::getPresumedLoc(), clang::Preprocessor::getTargetInfo(), clang::IdentifierInfo::getTokenID(), clang::GNU, clang::hasAttribute(), HasExtension(), HasFeature(), clang::Token::hasLeadingSpace(), clang::IdentifierInfo::hasRevertedTokenIDToIdentifier(), clang::Token::is(), clang::Token::isAnnotation(), clang::Token::isAtStartOfLine(), clang::LangOptions::isCompilingModule(), clang::PresumedLoc::isInvalid(), clang::Token::isNot(), clang::Token::isOneOf(), isTargetArch(), isTargetEnvironment(), isTargetOS(), isTargetVendor(), clang::SourceLocation::isValid(), clang::PresumedLoc::isValid(), clang::Token::LeadingSpace, clang::Preprocessor::LexNonComment(), clang::Preprocessor::LexUnexpandedToken(), clang::Token::NeedsCleaning, clang::Result, clang::Token::setFlagValue(), clang::Token::setIdentifierInfo(), clang::Token::setKind(), clang::Token::setLength(), clang::Token::setLocation(), clang::Token::StartOfLine, clang::Lexer::Stringify(), clang::format::Tok, and clang::diag::WarningOrError.