clang 10.0.0git

Classes | Enumerations | Functions
PPDirectives.cpp File Reference

Implements # directive processing for the Preprocessor. More...

`#include "clang/Basic/CharInfo.h"`
`#include "clang/Basic/FileManager.h"`
`#include "clang/Basic/IdentifierTable.h"`
`#include "clang/Basic/LangOptions.h"`
`#include "clang/Basic/Module.h"`
`#include "clang/Basic/SourceLocation.h"`
`#include "clang/Basic/SourceManager.h"`
`#include "clang/Basic/TokenKinds.h"`
`#include "clang/Lex/CodeCompletionHandler.h"`
`#include "clang/Lex/HeaderSearch.h"`
`#include "clang/Lex/LexDiagnostic.h"`
`#include "clang/Lex/LiteralSupport.h"`
`#include "clang/Lex/MacroInfo.h"`
`#include "clang/Lex/ModuleLoader.h"`
`#include "clang/Lex/ModuleMap.h"`
`#include "clang/Lex/PPCallbacks.h"`
`#include "clang/Lex/Pragma.h"`
`#include "clang/Lex/Preprocessor.h"`
`#include "clang/Lex/PreprocessorOptions.h"`
`#include "clang/Lex/Token.h"`
`#include "clang/Lex/VariadicMacroSupport.h"`
`#include "llvm/ADT/ArrayRef.h"`
`#include "llvm/ADT/ScopeExit.h"`
`#include "llvm/ADT/SmallString.h"`
`#include "llvm/ADT/SmallVector.h"`
`#include "llvm/ADT/STLExtras.h"`
`#include "llvm/ADT/StringSwitch.h"`
`#include "llvm/ADT/StringRef.h"`
`#include "llvm/Support/AlignOf.h"`
`#include "llvm/Support/ErrorHandling.h"`
`#include "llvm/Support/Path.h"`
`#include <algorithm>`
`#include <cassert>`
`#include <cstring>`
`#include <new>`
`#include <string>`
`#include <utility>`
Include dependency graph for PPDirectives.cpp:

Go to the source code of this file.

## Classes
class | clang::Preprocessor::ResetMacroExpansionHelper

## Enumerations
enum | MacroDiag { MD_NoWarn, MD_KeywordDef, MD_ReservedMacro }
| Enumerates possible cases of #define/#undef a reserved identifier. More...

## Functions
static bool | isReservedId (StringRef Text, const LangOptions &Lang)
| Checks if the specified identifier is reserved in the specified language. More...
static bool | isForModuleBuilding (Module *M, StringRef CurrentModule, StringRef ModuleName)
static MacroDiag | shouldWarnOnMacroDef (Preprocessor &PP, IdentifierInfo *II)
static MacroDiag | shouldWarnOnMacroUndef (Preprocessor &PP, IdentifierInfo *II)
static bool | warnByDefaultOnWrongCase (StringRef Include)
static bool | GetLineValue (Token &DigitTok, unsigned &Val, unsigned DiagID, Preprocessor &PP, bool IsGNULineDirective=false)
| GetLineValue - Convert a numeric token into an unsigned value, emitting Diagnostic DiagID if it is invalid, and returning the value in Val. More...
static bool | ReadLineMarkerFlags (bool &IsFileEntry, bool &IsFileExit, SrcMgr::CharacteristicKind &FileKind, Preprocessor &PP)
| ReadLineMarkerFlags - Parse and validate any flags at the end of a GNU line marker directive. More...
static void | diagnoseAutoModuleImport (Preprocessor &PP, SourceLocation HashLoc, Token &IncludeTok, ArrayRef< std::pair< IdentifierInfo *, SourceLocation >> Path, SourceLocation PathEnd)
| Produce a diagnostic informing the user that a #include or similar was implicitly treated as a module import. More...
static bool | trySimplifyPath (SmallVectorImpl< StringRef > &Components, StringRef RealPathName)
static bool | isConfigurationPattern (Token &MacroName, MacroInfo *MI, const LangOptions &LOptions)

## Detailed Description

Implements # directive processing for the Preprocessor.

Definition in file PPDirectives.cpp.

## Enumeration Type Documentation

## ◆ MacroDiag

enum MacroDiag

Enumerates possible cases of #define/#undef a reserved identifier.

Enumerator
MD_NoWarn |
MD_KeywordDef |
MD_ReservedMacro |

Definition at line 97 of file PPDirectives.cpp.

## Function Documentation

## ◆ diagnoseAutoModuleImport()

static void diagnoseAutoModuleImport | ( | Preprocessor & | PP,
|  | SourceLocation | HashLoc,
|  | Token & | IncludeTok,
|  | ArrayRef< std::pair< IdentifierInfo *, SourceLocation >> | Path,
|  | SourceLocation | PathEnd
| ) |  |
| static

Produce a diagnostic informing the user that a #include or similar was implicitly treated as a module import.

Definition at line 1562 of file PPDirectives.cpp.

References clang::FixItHint::CreateReplacement(), clang::Preprocessor::Diag(), clang::Token::getIdentifierInfo(), clang::Preprocessor::getLangOpts(), clang::IdentifierInfo::getPPKeywordID(), clang::minimize_source_to_dependency_directives::pp___include_macros, clang::minimize_source_to_dependency_directives::pp_import, clang::minimize_source_to_dependency_directives::pp_include, and clang::minimize_source_to_dependency_directives::pp_include_next.

Referenced by clang::Preprocessor::checkModuleIsAvailable().

## ◆ GetLineValue()

static bool GetLineValue | ( | Token & | DigitTok,
|  | unsigned & | Val,
|  | unsigned | DiagID,
|  | Preprocessor & | PP,
|  | bool | IsGNULineDirective = `false`
| ) |  |
| static

GetLineValue - Convert a numeric token into an unsigned value, emitting Diagnostic DiagID if it is invalid, and returning the value in Val.

Definition at line 1089 of file PPDirectives.cpp.

References clang::Preprocessor::AdvanceToTokenCharacter(), clang::Preprocessor::CheckEndOfDirective(), clang::Preprocessor::Diag(), clang::Preprocessor::DiscardUntilEndOfDirective(), clang::Token::getLength(), clang::Token::getLocation(), clang::Preprocessor::getSpelling(), clang::StringLiteralParser::GetString(), clang::StringLiteralParser::hadError, clang::Token::hasUDSuffix(), clang::Token::is(), clang::StringLiteralParser::isAscii(), clang::isDigit(), clang::Token::isNot(), clang::Preprocessor::Lex(), clang::StringLiteralParser::Pascal, and clang::PPCallbacks::RenameFile.

Referenced by ReadLineMarkerFlags().

## ◆ isConfigurationPattern()

static bool isConfigurationPattern | ( | Token & | MacroName,
|  | MacroInfo * | MI,
|  | const LangOptions & | LOptions
| ) |  |
| static

Definition at line 2405 of file PPDirectives.cpp.

References clang::MacroInfo::AddTokenToBody(), clang::Preprocessor::AllocateMacroInfo(), clang::Preprocessor::appendDefMacroDirective(), clang::Preprocessor::appendMacroDirective(), clang::Preprocessor::CheckEndOfDirective(), clang::PPCallbacks::CVK_False, clang::PPCallbacks::CVK_NotEvaluated, clang::PPCallbacks::CVK_True, clang::Preprocessor::Diag(), clang::Preprocessor::DiscardUntilEndOfDirective(), clang::PPConditionalInfo::FoundElse, clang::PPConditionalInfo::FoundNonSkip, clang::MacroInfo::getDefinitionLoc(), clang::Preprocessor::getDiagnostics(), clang::Token::getIdentifierInfo(), clang::Token::getKind(), clang::Preprocessor::getLangOpts(), clang::Token::getLocation(), clang::Preprocessor::getMacroDefinition(), clang::Preprocessor::getMacroInfo(), clang::IdentifierInfo::getName(), clang::MacroInfo::getNumTokens(), clang::MacroInfo::getParameterNum(), clang::Preprocessor::getPredefinesFileID(), clang::MacroInfo::getReplacementToken(), clang::Preprocessor::getSourceManager(), clang::DiagnosticsEngine::getSuppressSystemWarnings(), clang::VAOptDefinitionContext::getUnmatchedOpeningParenLoc(), clang::PPConditionalInfo::IfLoc, clang::Token::is(), clang::MacroInfo::isC99Varargs(), clang::MacroInfo::isIdenticalTo(), clang::SourceManager::isInMainFile(), isInvalid(), clang::VAOptDefinitionContext::isInVAOpt(), clang::MacroInfo::isObjectLike(), clang::Token::isOneOf(), clang::IdentifierInfo::isStr(), clang::MacroInfo::isUsed(), clang::VAOptDefinitionContext::isVAOptToken(), clang::MacroInfo::isWarnIfUnused(), clang::Token::LeadingSpace, clang::Preprocessor::LexUnexpandedToken(), clang::Preprocessor::markMacroAsUsed(), clang::MU_Define, clang::MU_Undef, clang::ObjC, clang::Result, clang::VAOptDefinitionContext::sawClosingParen(), clang::VAOptDefinitionContext::sawOpeningParen(), clang::VAOptDefinitionContext::sawVAOptFollowedByOpeningParens(), clang::MacroInfo::setDefinitionEndLoc(), clang::MacroInfo::setHasCommaPasting(), clang::MacroInfo::setIsFunctionLike(), clang::MacroInfo::setIsWarnIfUnused(), clang::Token::setKind(), clang::format::Tok, clang::Preprocessor::VariadicMacroScopeGuard, and clang::PPConditionalInfo::WasSkipping.

## ◆ isForModuleBuilding()

static bool isForModuleBuilding | ( | Module * | M,
|  | StringRef | CurrentModule,
|  | StringRef | ModuleName
| ) |  |
| static

Definition at line 129 of file PPDirectives.cpp.

References clang::Module::getTopLevelModule(), clang::Module::getTopLevelModuleName(), and clang::Module::IsFramework.

Referenced by clang::Preprocessor::checkModuleIsAvailable().

## ◆ isReservedId()

static bool isReservedId | ( | StringRef | Text,
|  | const LangOptions & | Lang
| ) |  |
| static

Checks if the specified identifier is reserved in the specified language.

This function does not check if the identifier is a keyword.

Definition at line 106 of file PPDirectives.cpp.

References clang::isUppercase().

Referenced by shouldWarnOnMacroDef(), and shouldWarnOnMacroUndef().

## ◆ ReadLineMarkerFlags()

static bool ReadLineMarkerFlags | ( | bool & | IsFileEntry,
|  | bool & | IsFileExit,
|  | SrcMgr::CharacteristicKind & | FileKind,
|  | Preprocessor & | PP
| ) |  |
| static

ReadLineMarkerFlags - Parse and validate any flags at the end of a GNU line marker directive.

Definition at line 1226 of file PPDirectives.cpp.

References clang::Preprocessor::appendMacroDirective(), clang::SrcMgr::C_ExternCSystem, clang::SrcMgr::C_System, clang::SrcMgr::C_User, clang::Preprocessor::CheckEndOfDirective(), clang::Preprocessor::Diag(), clang::Preprocessor::DiscardUntilEndOfDirective(), clang::PPCallbacks::EnterFile, clang::PPCallbacks::ExitFile, clang::SourceManager::getDecomposedExpansionLoc(), clang::Token::getIdentifierInfo(), clang::PresumedLoc::getIncludeLoc(), GetLineValue(), clang::Preprocessor::getLocalMacroDirective(), clang::Token::getLocation(), clang::SourceManager::getPresumedLoc(), clang::Preprocessor::getSourceManager(), clang::Preprocessor::getSpelling(), clang::StringLiteralParser::GetString(), clang::StringLiteralParser::hadError, clang::Token::hasUDSuffix(), clang::Token::is(), clang::StringLiteralParser::isAscii(), clang::SourceLocation::isInvalid(), clang::PresumedLoc::isInvalid(), clang::Token::isNot(), clang::Preprocessor::Lex(), clang::MU_Undef, clang::StringLiteralParser::Pascal, clang::PPCallbacks::RenameFile, SM, and clang::format::Tok.

## ◆ shouldWarnOnMacroDef()

static MacroDiag shouldWarnOnMacroDef | ( | Preprocessor & | PP,
|  | IdentifierInfo * | II
| ) |  |
| static

Definition at line 142 of file PPDirectives.cpp.

References clang::Preprocessor::getLangOpts(), clang::IdentifierInfo::getName(), clang::IdentifierInfo::isKeyword(), isReservedId(), MD_KeywordDef, MD_NoWarn, MD_ReservedMacro, and Text.

Referenced by clang::Preprocessor::CheckMacroName().

## ◆ shouldWarnOnMacroUndef()

static MacroDiag shouldWarnOnMacroUndef | ( | Preprocessor & | PP,
|  | IdentifierInfo * | II
| ) |  |
| static

Definition at line 154 of file PPDirectives.cpp.

References clang::Preprocessor::getLangOpts(), clang::IdentifierInfo::getName(), isReservedId(), MD_NoWarn, MD_ReservedMacro, and Text.

Referenced by clang::Preprocessor::CheckMacroName().

## ◆ trySimplifyPath()

static bool trySimplifyPath | ( | SmallVectorImpl< StringRef > & | Components,
|  | StringRef | RealPathName
| ) |  |
| static

Definition at line 1614 of file PPDirectives.cpp.

## ◆ warnByDefaultOnWrongCase()

static bool warnByDefaultOnWrongCase | ( | StringRef | Include | ) |
| static

Definition at line 168 of file PPDirectives.cpp.