clang  13.0.0git
Classes | Namespaces
Macros.h File Reference
#include <string>
#include <unordered_map>
#include <vector>
#include "Encoding.h"
#include "FormatToken.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
Include dependency graph for Macros.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


class  clang::format::MacroExpander
 Takes a set of macro definitions as strings and allows expanding calls to those macros. More...



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 MacroUnexpander matches the spelled token stream into unwrapped lines that best resemble the structure of the expanded unwrapped lines.

When formatting, clang-format 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.