clang 20.0.0git
Classes | Namespaces
Macros.h File Reference

This file contains the main building blocks of macro support in clang-format. More...

#include <list>
#include "FormatToken.h"
#include "llvm/ADT/DenseMap.h"

Go to the source code of this file.

Classes

class  clang::format::MacroExpander
 Takes a set of macro definitions as strings and allows expanding calls to those macros. More...
 
class  clang::format::MacroCallReconstructor
 Converts a sequence of UnwrappedLines containing expanded macros into a single UnwrappedLine containing the macro calls. More...
 

Namespaces

namespace  clang
 The JSON file list parser is used to communicate input to InstallAPI.
 
namespace  clang::format
 

Detailed Description

This file contains the main building blocks of macro support in clang-format.

In order to not violate the requirement that clang-format can format files in isolation, clang-format's macro support uses expansions users provide as part of clang-format's style configuration.

Macro definitions are of the form "MACRO(p1, p2)=p1 + p2", but only support one level of expansion (

See also
MacroExpander for a full description of what is supported).

As part of parsing, clang-format uses the MacroExpander to expand the spelled token streams into expanded token streams when it encounters a macro call. The UnwrappedLineParser continues to parse UnwrappedLines from the expanded token stream. After the expanded unwrapped lines are parsed, the MacroCallReconstructor matches the spelled token stream into unwrapped lines that best resemble the structure of the expanded unwrapped lines. These reconstructed unwrapped lines are aliasing the tokens in the expanded token stream, so that token annotations will be reused when formatting the spelled macro calls.

When formatting, clang-format annotates and formats the expanded unwrapped lines first, determining the token types. Next, it formats the spelled unwrapped lines, keeping the token types fixed, while allowing other formatting decisions to change.

Definition in file Macros.h.