clang 19.0.0git
Classes | Enumerations | Functions
PPDirectives.cpp File Reference

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

#include "clang/Basic/CharInfo.h"
#include "clang/Basic/DirectoryEntry.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/HeaderSearchOptions.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/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/AlignOf.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SaveAndRestore.h"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <new>
#include <optional>
#include <string>
#include <utility>

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...
 
enum  PPElifDiag { PED_Elif , PED_Elifdef , PED_Elifndef }
 Enumerates possible select values for the pp_err_elif_after_else and pp_err_elif_without_if diagnostics. More...
 

Functions

static bool isFeatureTestMacro (StringRef MacroName)
 
static bool isLanguageDefinedBuiltin (const SourceManager &SourceMgr, const MacroInfo *MI, const StringRef MacroName)
 
static MacroDiag shouldWarnOnMacroDef (Preprocessor &PP, IdentifierInfo *II)
 
static MacroDiag shouldWarnOnMacroUndef (Preprocessor &PP, IdentifierInfo *II)
 
static bool warnByDefaultOnWrongCase (StringRef Include)
 
static std::optional< StringRef > findSimilarStr (StringRef LHS, const std::vector< StringRef > &Candidates)
 Find a similar string in Candidates.
 
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.
 
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.
 
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.
 
static bool trySimplifyPath (SmallVectorImpl< StringRef > &Components, StringRef RealPathName, llvm::sys::path::Style Separator)
 
static bool isConfigurationPattern (Token &MacroName, MacroInfo *MI, const LangOptions &LOptions)
 
static bool isObjCProtectedMacro (const IdentifierInfo *II)
 

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 100 of file PPDirectives.cpp.

◆ PPElifDiag

enum PPElifDiag

Enumerates possible select values for the pp_err_elif_after_else and pp_err_elif_without_if diagnostics.

Enumerator
PED_Elif 
PED_Elifdef 
PED_Elifndef 

Definition at line 108 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 1820 of file PPDirectives.cpp.

References clang::Preprocessor::Diag(), clang::Token::getIdentifierInfo(), and clang::IdentifierInfo::getPPKeywordID().

◆ findSimilarStr()

static std::optional< StringRef > findSimilarStr ( StringRef  LHS,
const std::vector< StringRef > &  Candidates 
)
static

Find a similar string in Candidates.

Parameters
LHSa string for a similar string in Candidates
Candidatesthe candidates to find a similar string.
Returns
a similar string if exists. If no similar string exists, returns std::nullopt.

Definition at line 287 of file PPDirectives.cpp.

References clang::C.

◆ 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 1339 of file PPDirectives.cpp.

References clang::Preprocessor::AdvanceToTokenCharacter(), clang::Preprocessor::Diag(), clang::Preprocessor::DiscardUntilEndOfDirective(), clang::Token::getLength(), clang::Token::getLocation(), clang::Preprocessor::getSpelling(), clang::Invalid, clang::isDigit(), and clang::Token::isNot().

Referenced by ReadLineMarkerFlags().

◆ isConfigurationPattern()

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

◆ isFeatureTestMacro()

static bool isFeatureTestMacro ( StringRef  MacroName)
static

Definition at line 114 of file PPDirectives.cpp.

Referenced by shouldWarnOnMacroDef().

◆ isLanguageDefinedBuiltin()

static bool isLanguageDefinedBuiltin ( const SourceManager SourceMgr,
const MacroInfo MI,
const StringRef  MacroName 
)
static

◆ isObjCProtectedMacro()

static bool isObjCProtectedMacro ( const IdentifierInfo II)
static

Definition at line 3060 of file PPDirectives.cpp.

References clang::IdentifierInfo::isStr().

◆ ReadLineMarkerFlags()

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

◆ shouldWarnOnMacroDef()

static MacroDiag shouldWarnOnMacroDef ( Preprocessor PP,
IdentifierInfo II 
)
static

◆ shouldWarnOnMacroUndef()

static MacroDiag shouldWarnOnMacroUndef ( Preprocessor PP,
IdentifierInfo II 
)
static

◆ trySimplifyPath()

static bool trySimplifyPath ( SmallVectorImpl< StringRef > &  Components,
StringRef  RealPathName,
llvm::sys::path::Style  Separator 
)
static

Definition at line 1860 of file PPDirectives.cpp.

◆ warnByDefaultOnWrongCase()

static bool warnByDefaultOnWrongCase ( StringRef  Include)
static

Definition at line 204 of file PPDirectives.cpp.