clang 20.0.0git
MacroBuilder.h
Go to the documentation of this file.
1//===--- MacroBuilder.h - CPP Macro building utility ------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// Defines the clang::MacroBuilder utility class.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_BASIC_MACROBUILDER_H
15#define LLVM_CLANG_BASIC_MACROBUILDER_H
16
17#include "clang/Basic/LLVM.h"
18#include "llvm/ADT/Twine.h"
19#include "llvm/Support/raw_ostream.h"
20
21namespace clang {
22
24 raw_ostream &Out;
25public:
26 MacroBuilder(raw_ostream &Output) : Out(Output) {}
27
28 /// Append a \#define line for macro of the form "\#define Name Value\n".
29 /// If DeprecationMsg is provided, also append a pragma to deprecate the
30 /// defined macro.
31 void defineMacro(const Twine &Name, const Twine &Value = "1",
32 Twine DeprecationMsg = "") {
33 Out << "#define " << Name << ' ' << Value << '\n';
34 if (!DeprecationMsg.isTriviallyEmpty())
35 Out << "#pragma clang deprecated(" << Name << ", \"" << DeprecationMsg
36 << "\")\n";
37 }
38
39 /// Append a \#undef line for Name. Name should be of the form XXX
40 /// and we emit "\#undef XXX".
41 void undefineMacro(const Twine &Name) {
42 Out << "#undef " << Name << '\n';
43 }
44
45 /// Directly append Str and a newline to the underlying buffer.
46 void append(const Twine &Str) {
47 Out << Str << '\n';
48 }
49};
50
51} // end namespace clang
52
53#endif
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
MacroBuilder(raw_ostream &Output)
Definition: MacroBuilder.h:26
void undefineMacro(const Twine &Name)
Append a #undef line for Name.
Definition: MacroBuilder.h:41
void defineMacro(const Twine &Name, const Twine &Value="1", Twine DeprecationMsg="")
Append a #define line for macro of the form "\#define Name Value\n".
Definition: MacroBuilder.h:31
void append(const Twine &Str)
Directly append Str and a newline to the underlying buffer.
Definition: MacroBuilder.h:46
The JSON file list parser is used to communicate input to InstallAPI.