xref: /aosp_15_r20/external/clang/include/clang/Basic/MacroBuilder.h (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li //===--- MacroBuilder.h - CPP Macro building utility ------------*- C++ -*-===//
2*67e74705SXin Li //
3*67e74705SXin Li //                     The LLVM Compiler Infrastructure
4*67e74705SXin Li //
5*67e74705SXin Li // This file is distributed under the University of Illinois Open Source
6*67e74705SXin Li // License. See LICENSE.TXT for details.
7*67e74705SXin Li //
8*67e74705SXin Li //===----------------------------------------------------------------------===//
9*67e74705SXin Li ///
10*67e74705SXin Li /// \file
11*67e74705SXin Li /// \brief Defines the clang::MacroBuilder utility class.
12*67e74705SXin Li ///
13*67e74705SXin Li //===----------------------------------------------------------------------===//
14*67e74705SXin Li 
15*67e74705SXin Li #ifndef LLVM_CLANG_BASIC_MACROBUILDER_H
16*67e74705SXin Li #define LLVM_CLANG_BASIC_MACROBUILDER_H
17*67e74705SXin Li 
18*67e74705SXin Li #include "clang/Basic/LLVM.h"
19*67e74705SXin Li #include "llvm/ADT/Twine.h"
20*67e74705SXin Li #include "llvm/Support/raw_ostream.h"
21*67e74705SXin Li 
22*67e74705SXin Li namespace clang {
23*67e74705SXin Li 
24*67e74705SXin Li class MacroBuilder {
25*67e74705SXin Li   raw_ostream &Out;
26*67e74705SXin Li public:
MacroBuilder(raw_ostream & Output)27*67e74705SXin Li   MacroBuilder(raw_ostream &Output) : Out(Output) {}
28*67e74705SXin Li 
29*67e74705SXin Li   /// Append a \#define line for macro of the form "\#define Name Value\n".
30*67e74705SXin Li   void defineMacro(const Twine &Name, const Twine &Value = "1") {
31*67e74705SXin Li     Out << "#define " << Name << ' ' << Value << '\n';
32*67e74705SXin Li   }
33*67e74705SXin Li 
34*67e74705SXin Li   /// Append a \#undef line for Name.  Name should be of the form XXX
35*67e74705SXin Li   /// and we emit "\#undef XXX".
undefineMacro(const Twine & Name)36*67e74705SXin Li   void undefineMacro(const Twine &Name) {
37*67e74705SXin Li     Out << "#undef " << Name << '\n';
38*67e74705SXin Li   }
39*67e74705SXin Li 
40*67e74705SXin Li   /// Directly append Str and a newline to the underlying buffer.
append(const Twine & Str)41*67e74705SXin Li   void append(const Twine &Str) {
42*67e74705SXin Li     Out << Str << '\n';
43*67e74705SXin Li   }
44*67e74705SXin Li };
45*67e74705SXin Li 
46*67e74705SXin Li }  // end namespace clang
47*67e74705SXin Li 
48*67e74705SXin Li #endif
49