clang
15.0.0git
|
#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"
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... | |
Namespaces | |
llvm | |
YAML serialization mapping. | |
clang | |
clang::format | |
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 (
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.