1 //===- CodeExpander.h - Expand variables in a string ----------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 /// \file Expand the variables in a string.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_UTILS_TABLEGEN_CODEEXPANDER_H
14 #define LLVM_UTILS_TABLEGEN_CODEEXPANDER_H
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/SMLoc.h"
24 /// Emit the given code with all '${foo}' placeholders expanded to their
27 /// It's an error to use an undefined expansion and expansion-like output that
28 /// needs to be emitted verbatim can be escaped as '\${foo}'
30 /// The emitted code can be given a custom indent to enable both indentation by
31 /// an arbitrary amount of whitespace and emission of the code as a comment.
34 const CodeExpansions
&Expansions
;
35 const ArrayRef
<SMLoc
> &Loc
;
40 CodeExpander(StringRef Code
, const CodeExpansions
&Expansions
,
41 const ArrayRef
<SMLoc
> &Loc
, bool ShowExpansions
,
42 StringRef Indent
= " ")
43 : Code(Code
), Expansions(Expansions
), Loc(Loc
),
44 ShowExpansions(ShowExpansions
), Indent(Indent
) {}
46 void emit(raw_ostream
&OS
) const;
49 inline raw_ostream
&operator<<(raw_ostream
&OS
, const CodeExpander
&Expander
) {
53 } // end namespace llvm
55 #endif // ifndef LLVM_UTILS_TABLEGEN_CODEEXPANDER_H