clang API Documentation
00001 //===--- MacroBuilder.h - CPP Macro building utility ------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the MacroBuilder utility class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_BASIC_MACROBUILDER_H 00015 #define LLVM_CLANG_BASIC_MACROBUILDER_H 00016 00017 #include "llvm/ADT/Twine.h" 00018 #include "llvm/Support/raw_ostream.h" 00019 00020 namespace clang { 00021 00022 class MacroBuilder { 00023 raw_ostream &Out; 00024 public: 00025 MacroBuilder(raw_ostream &Output) : Out(Output) {} 00026 00027 /// Append a #define line for macro of the form "#define Name Value\n". 00028 void defineMacro(const Twine &Name, const Twine &Value = "1") { 00029 Out << "#define " << Name << ' ' << Value << '\n'; 00030 } 00031 00032 /// Append a #undef line for Name. Name should be of the form XXX 00033 /// and we emit "#undef XXX". 00034 void undefineMacro(const Twine &Name) { 00035 Out << "#undef " << Name << '\n'; 00036 } 00037 00038 /// Directly append Str and a newline to the underlying buffer. 00039 void append(const Twine &Str) { 00040 Out << Str << '\n'; 00041 } 00042 }; 00043 00044 } // end namespace clang 00045 00046 #endif