class MacroExpansionContext

Declaration

class MacroExpansionContext { /* full declaration omitted */ };

Description

MacroExpansionContext tracks the macro expansions processed by the Preprocessor. It means that it can track source locations from a single translation unit. For every macro expansion it can tell you what text will be substituted. It was designed to deal with: - regular macros - macro functions - variadic macros - transitive macro expansions - macro redefinition - unbalanced parenthesis

Declared at: clang/include/clang/Analysis/MacroExpansionContext.h:73

Member Variables

private clang::MacroExpansionContext::ExpansionMap ExpandedTokens
Associates the textual representation of the expanded tokens at the given macro expansion location.
private clang::MacroExpansionContext::ExpansionRangeMap ExpansionRanges
Tracks which source location was the last affected by any macro substitution starting from a given macro expansion location.
private clang::Preprocessor* PP = nullptr
private clang::SourceManager* SM = nullptr
private const clang::LangOptions& LangOpts

Method Overview

Methods

MacroExpansionContext(
    const clang::LangOptions& LangOpts)

Description

Creates a MacroExpansionContext.

Declared at: clang/include/clang/Analysis/MacroExpansionContext.h:78

Parameters

const clang::LangOptions& LangOpts

void dumpExpandedTexts() const

Declared at: clang/include/clang/Analysis/MacroExpansionContext.h:100

void dumpExpandedTextsToStream(
    llvm::raw_ostream& OS) const

Declared at: clang/include/clang/Analysis/MacroExpansionContext.h:98

Parameters

llvm::raw_ostream& OS

void dumpExpansionRanges() const

Declared at: clang/include/clang/Analysis/MacroExpansionContext.h:99

void dumpExpansionRangesToStream(
    llvm::raw_ostream& OS) const

Declared at: clang/include/clang/Analysis/MacroExpansionContext.h:97

Parameters

llvm::raw_ostream& OS

Optional<llvm::StringRef> getExpandedText(
    clang::SourceLocation MacroExpansionLoc) const

Declared at: clang/include/clang/Analysis/MacroExpansionContext.h:89

Parameters

clang::SourceLocation MacroExpansionLoc
Must be the expansion location of a macro.

Returns

The textual representation of the token sequence which was substituted in place of the macro after the preprocessing. If no macro was expanded at that location, returns llvm::None.

Optional<llvm::StringRef> getOriginalText(
    clang::SourceLocation MacroExpansionLoc) const

Declared at: clang/include/clang/Analysis/MacroExpansionContext.h:95

Parameters

clang::SourceLocation MacroExpansionLoc
Must be the expansion location of a macro.

Returns

The text from the original source code which were substituted by the macro expansion chain from the given location. If no macro was expanded at that location, returns llvm::None.

void onTokenLexed(const clang::Token& Tok)

Description

This callback is called by the preprocessor. It stores the textual representation of the expanded token sequence for a macro expansion location.

Declared at: clang/include/clang/Analysis/MacroExpansionContext.h:123

Parameters

const clang::Token& Tok

void registerForPreprocessor(
    clang::Preprocessor& PP)

Description

Register the necessary callbacks to the Preprocessor to record the expansion events and the generated tokens. Must ensure that this object outlives the given Preprocessor.

Declared at: clang/include/clang/Analysis/MacroExpansionContext.h:83

Parameters

clang::Preprocessor& PP