Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:50

0001 //===--- MacroBuilder.h - CPP Macro building utility ------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// \file
0010 /// Defines the clang::MacroBuilder utility class.
0011 ///
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CLANG_BASIC_MACROBUILDER_H
0015 #define LLVM_CLANG_BASIC_MACROBUILDER_H
0016 
0017 #include "clang/Basic/LLVM.h"
0018 #include "llvm/ADT/Twine.h"
0019 #include "llvm/Support/raw_ostream.h"
0020 
0021 namespace clang {
0022 
0023 class MacroBuilder {
0024   raw_ostream &Out;
0025 public:
0026   MacroBuilder(raw_ostream &Output) : Out(Output) {}
0027 
0028   /// Append a \#define line for macro of the form "\#define Name Value\n".
0029   /// If DeprecationMsg is provided, also append a pragma to deprecate the
0030   /// defined macro.
0031   void defineMacro(const Twine &Name, const Twine &Value = "1",
0032                    Twine DeprecationMsg = "") {
0033     Out << "#define " << Name << ' ' << Value << '\n';
0034     if (!DeprecationMsg.isTriviallyEmpty())
0035       Out << "#pragma clang deprecated(" << Name << ", \"" << DeprecationMsg
0036           << "\")\n";
0037   }
0038 
0039   /// Append a \#undef line for Name.  Name should be of the form XXX
0040   /// and we emit "\#undef XXX".
0041   void undefineMacro(const Twine &Name) {
0042     Out << "#undef " << Name << '\n';
0043   }
0044 
0045   /// Directly append Str and a newline to the underlying buffer.
0046   void append(const Twine &Str) {
0047     Out << Str << '\n';
0048   }
0049 };
0050 
0051 }  // end namespace clang
0052 
0053 #endif