From: Chandler Carruth Date: Wed, 20 Jan 2010 06:13:02 +0000 (+0000) Subject: Move the MacroBuilder utilitiy to its own header. Update references. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=103b71c37a3c3a3da7128c1d0232a89b1e8d0d90;p=clang Move the MacroBuilder utilitiy to its own header. Update references. Comments and/or improvements to the documentation are welcome. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93982 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/MacroBuilder.h b/include/clang/Basic/MacroBuilder.h new file mode 100644 index 0000000000..e46f424835 --- /dev/null +++ b/include/clang/Basic/MacroBuilder.h @@ -0,0 +1,46 @@ +//===--- MacroBuilder.h - CPP Macro building utilitiy -----------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the MacroBuilder utility class. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_BASIC_MACROBUILDER_H +#define LLVM_CLANG_BASIC_MACROBUILDER_H + +#include "llvm/ADT/Twine.h" +#include "llvm/Support/raw_ostream.h" + +namespace clang { + +class MacroBuilder { + llvm::raw_ostream &Out; +public: + MacroBuilder(llvm::raw_ostream &Output) : Out(Output) {} + + /// Append a #define line for macro of the form "#define Name Value\n". + void defineMacro(const llvm::Twine &Name, const llvm::Twine &Value = "1") { + Out << "#define " << Name << ' ' << Value << '\n'; + } + + /// Append a #undef line for Name. Name should be of the form XXX + /// and we emit "#undef XXX". + void undefineMacro(const llvm::Twine &Name) { + Out << "#undef " << Name << '\n'; + } + + /// Directly append Str and a newline to the underlying buffer. + void append(const llvm::Twine &Str) { + Out << Str << '\n'; + } +}; + +} // end namespace clang + +#endif diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index 45c3b9732b..97e0495bfb 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -17,8 +17,6 @@ // FIXME: Daniel isn't smart enough to use a prototype for this. #include "llvm/ADT/StringMap.h" #include "llvm/ADT/Triple.h" -#include "llvm/ADT/Twine.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/System/DataTypes.h" #include #include @@ -32,34 +30,13 @@ class StringRef; namespace clang { class Diagnostic; class LangOptions; +class MacroBuilder; class SourceLocation; class SourceManager; class TargetOptions; namespace Builtin { struct Info; } -class MacroBuilder { - llvm::raw_ostream &Out; -public: - MacroBuilder(llvm::raw_ostream &Output) : Out(Output) {} - - /// Append a #define line for macro of the form "#define Name Value\n". - void defineMacro(const llvm::Twine &Name, const llvm::Twine &Value = "1") { - Out << "#define " << Name << ' ' << Value << '\n'; - } - - /// Append a #undef line for Name. Name should be of the form XXX - /// and we emit "#undef XXX". - void undefineMacro(const llvm::Twine &Name) { - Out << "#undef " << Name << '\n'; - } - - /// Directly append Str and a newline to the underlying buffer. - void append(const llvm::Twine &Str) { - Out << Str << '\n'; - } -}; - /// TargetInfo - This class exposes information about the current target. /// class TargetInfo { diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index a015ec3110..ea076ae0bb 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -16,6 +16,7 @@ #include "clang/Basic/Builtins.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/LangOptions.h" +#include "clang/Basic/MacroBuilder.h" #include "clang/Basic/TargetBuiltins.h" #include "clang/Basic/TargetOptions.h" #include "llvm/ADT/APFloat.h" diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index f2eb4e642b..32363eed20 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/Frontend/Utils.h" +#include "clang/Basic/MacroBuilder.h" #include "clang/Basic/TargetInfo.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/FrontendOptions.h"