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