class MacroCallReconstructor

Declaration

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

Description

Converts a sequence of UnwrappedLines containing expanded macros into a single UnwrappedLine containing the macro calls. This UnwrappedLine may be broken into child lines, in a way that best conveys the structure of the expanded code. In the simplest case, a spelled UnwrappedLine contains one macro, and after expanding it we have one expanded UnwrappedLine. In general, macro expansions can span UnwrappedLines, and multiple macros can contribute tokens to the same line. We keep consuming expanded lines until: * all expansions that started have finished (we're not chopping any macros in half) * *and* we've reached the end of a *spelled* unwrapped line. A single UnwrappedLine represents this chunk of code. After this point, the state of the spelled/expanded stream is "in sync" (both at the start of an UnwrappedLine, with no macros open), so the Unexpander can be thrown away and parsing can continue. Given a mapping from the macro name identifier token in the macro call to the tokens of the macro call, for example: CLASSA -> CLASSA({public: void x();}) When getting the formatted lines of the expansion via the \c addLine method (each '->' specifies a call to \c addLine ): -> class A { -> public: -> void x(); -> }; Creates the tree of unwrapped lines containing the macro call tokens so that the macro call tokens fit the semantic structure of the expanded formatted lines: -> CLASSA({ -> public: -> void x(); -> })

Declared at: clang/lib/Format/Macros.h:172

Member Variables

private clang::format::MacroCallReconstructor:: ReconstructorState State = Start
private clang::format::MacroCallReconstructor:: ReconstructedLine Result
private llvm::SmallVector<ReconstructedLine*> ActiveReconstructedLines
private llvm::DenseMap<FormatToken*, FormatToken*> SpelledParentToReconstructedParent
private llvm::SmallVector<Expansion> ActiveExpansions
private llvm::SmallVector<MacroCallState> MacroCallStructure
private const unsigned int Level
private const llvm::DenseMap< FormatToken*, std::unique_ptr<UnwrappedLine>>& IdToReconstructed

Method Overview

  • public MacroCallReconstructor(unsigned int Level, const llvm::DenseMap<FormatToken *, std::unique_ptr<UnwrappedLine>> & ActiveExpansions)
  • private void add(clang::format::FormatToken * Token, clang::format::FormatToken * ExpandedParent, bool First)
  • public void addLine(const clang::format::UnwrappedLine & Line)
  • private void appendToken(clang::format::FormatToken * Token, clang::format::MacroCallReconstructor::ReconstructedLine * L = nullptr)
  • private clang::format::UnwrappedLine createUnwrappedLine(const clang::format::MacroCallReconstructor::ReconstructedLine & Line, int Level)
  • private clang::format::MacroCallReconstructor::ReconstructedLine * currentLine()
  • private void debug(const clang::format::MacroCallReconstructor::ReconstructedLine & Line, int Level)
  • private void debugParentMap() const
  • private void endReconstruction(clang::format::FormatToken * Token)
  • private void finalize()
  • public bool finished() const
  • private clang::format::FormatToken * getParentInResult(clang::format::FormatToken * Parent)
  • private clang::format::MacroCallReconstructor::ReconstructedLine & parentLine()
  • private void prepareParent(clang::format::FormatToken * ExpandedParent, bool First)
  • private bool processNextReconstructed()
  • private void reconstruct(clang::format::FormatToken * Token)
  • private bool reconstructActiveCallUntil(clang::format::FormatToken * Token)
  • private void startReconstruction(clang::format::FormatToken * Token)
  • public clang::format::UnwrappedLine takeResult() &&

Methods

MacroCallReconstructor(
    unsigned int Level,
    const llvm::DenseMap<
        FormatToken*,
        std::unique_ptr<UnwrappedLine>>&
        ActiveExpansions)

Description

Create an Reconstructor whose resulting \p UnwrappedLine will start at\p Level, using the map from name identifier token to the corresponding tokens of the spelled macro call.

Declared at: clang/lib/Format/Macros.h:177

Parameters

unsigned int Level
const llvm::DenseMap< FormatToken*, std::unique_ptr<UnwrappedLine>>& ActiveExpansions

void add(
    clang::format::FormatToken* Token,
    clang::format::FormatToken* ExpandedParent,
    bool First)

Declared at: clang/lib/Format/Macros.h:227

Parameters

clang::format::FormatToken* Token
clang::format::FormatToken* ExpandedParent
bool First

void addLine(
    const clang::format::UnwrappedLine& Line)

Description

For the given \p Line, match all occurences of tokens expanded from a macro to unwrapped lines in the spelled macro call so that the resulting tree of unwrapped lines best resembles the structure of unwrapped lines passed in via \c addLine.

Declared at: clang/lib/Format/Macros.h:186

Parameters

const clang::format::UnwrappedLine& Line

void appendToken(
    clang::format::FormatToken* Token,
    clang::format::MacroCallReconstructor::
        ReconstructedLine* L = nullptr)

Declared at: clang/lib/Format/Macros.h:239

Parameters

clang::format::FormatToken* Token
clang::format::MacroCallReconstructor:: ReconstructedLine* L = nullptr

clang::format::UnwrappedLine createUnwrappedLine(
    const clang::format::MacroCallReconstructor::
        ReconstructedLine& Line,
    int Level)

Declared at: clang/lib/Format/Macros.h:240

Parameters

const clang::format::MacroCallReconstructor:: ReconstructedLine& Line
int Level

clang::format::MacroCallReconstructor::
    ReconstructedLine*
    currentLine()

Declared at: clang/lib/Format/Macros.h:243

void debug(
    const clang::format::MacroCallReconstructor::
        ReconstructedLine& Line,
    int Level)

Declared at: clang/lib/Format/Macros.h:241

Parameters

const clang::format::MacroCallReconstructor:: ReconstructedLine& Line
int Level

void debugParentMap() const

Declared at: clang/lib/Format/Macros.h:244

void endReconstruction(
    clang::format::FormatToken* Token)

Declared at: clang/lib/Format/Macros.h:233

Parameters

clang::format::FormatToken* Token

void finalize()

Declared at: clang/lib/Format/Macros.h:235

bool finished() const

Description

Check whether at the current state there is no open macro expansion that needs to be processed to finish an macro call. Only when \c finished() is true, \c takeResult() can be called to retrieve the resulting \c UnwrappedLine. If there are multiple subsequent macro calls within an unwrapped line in the spelled token stream, the calling code may also continue to call\c addLine() when \c finished() is true.

Declared at: clang/lib/Format/Macros.h:195

clang::format::FormatToken* getParentInResult(
    clang::format::FormatToken* Parent)

Declared at: clang/lib/Format/Macros.h:229

Parameters

clang::format::FormatToken* Parent

clang::format::MacroCallReconstructor::
    ReconstructedLine&
    parentLine()

Declared at: clang/lib/Format/Macros.h:242

void prepareParent(
    clang::format::FormatToken* ExpandedParent,
    bool First)

Declared at: clang/lib/Format/Macros.h:228

Parameters

clang::format::FormatToken* ExpandedParent
bool First

bool processNextReconstructed()

Declared at: clang/lib/Format/Macros.h:234

void reconstruct(
    clang::format::FormatToken* Token)

Declared at: clang/lib/Format/Macros.h:230

Parameters

clang::format::FormatToken* Token

bool reconstructActiveCallUntil(
    clang::format::FormatToken* Token)

Declared at: clang/lib/Format/Macros.h:232

Parameters

clang::format::FormatToken* Token

void startReconstruction(
    clang::format::FormatToken* Token)

Declared at: clang/lib/Format/Macros.h:231

Parameters

clang::format::FormatToken* Token

clang::format::UnwrappedLine takeResult() &&

Description

Retrieve the formatted \c UnwrappedLine containing the orginal macro calls, formatted according to the expanded token stream received via \c addLine(). Generally, this line tries to have the same structure as the expanded, formatted unwrapped lines handed in via \c addLine(), with the exception that for multiple top-level lines, each subsequent line will be the child of the last token in its predecessor. This representation is chosen because it is a precondition to the formatter that we get what looks like a single statement in a single \c UnwrappedLine (i.e. matching parens). If a token in a macro argument is a child of a token in the expansion, the parent will be the corresponding token in the macro call. For example: #define C(a, b) class C { a b C(int x;, int y;) would expand to class C { int x; int y; where in a formatted line "int x;" and "int y;" would both be new separate lines. In the result, "int x;" will be a child of the opening parenthesis in "C(" and "int y;" will be a child of the "," token: C ( \ - int x; , \ - int y; )

Declared at: clang/lib/Format/Macros.h:224