clang API Documentation

MacroBuilder.h
Go to the documentation of this file.
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 /// \file
00011 /// \brief Defines the clang::MacroBuilder utility class.
00012 ///
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CLANG_BASIC_MACROBUILDER_H
00016 #define LLVM_CLANG_BASIC_MACROBUILDER_H
00017 
00018 #include "clang/Basic/LLVM.h"
00019 #include "llvm/ADT/Twine.h"
00020 #include "llvm/Support/raw_ostream.h"
00021 
00022 namespace clang {
00023 
00024 class MacroBuilder {
00025   raw_ostream &Out;
00026 public:
00027   MacroBuilder(raw_ostream &Output) : Out(Output) {}
00028 
00029   /// Append a \#define line for macro of the form "\#define Name Value\n".
00030   void defineMacro(const Twine &Name, const Twine &Value = "1") {
00031     Out << "#define " << Name << ' ' << Value << '\n';
00032   }
00033 
00034   /// Append a \#undef line for Name.  Name should be of the form XXX
00035   /// and we emit "\#undef XXX".
00036   void undefineMacro(const Twine &Name) {
00037     Out << "#undef " << Name << '\n';
00038   }
00039 
00040   /// Directly append Str and a newline to the underlying buffer.
00041   void append(const Twine &Str) {
00042     Out << Str << '\n';
00043   }
00044 };
00045 
00046 }  // end namespace clang
00047 
00048 #endif