[llvm-commits] [bug_122] CVS: llvm/include/llvm/PrintableItem.h
LLVM
llvm at cs.uiuc.edu
Sun May 16 18:57:01 PDT 2004
Changes in directory llvm/include/llvm:
PrintableItem.h added (r1.1.2.1)
---
Log message:
Added this abstract base class to encapsulate the print(std::ostream&) and
dump() methods common to Types and Values. Can be used elsewhere to obtain
an object for which "call OBJ->dump()" in the debugger will print out the
object.
---
Diffs of the changes: (+66 -0)
Index: llvm/include/llvm/PrintableItem.h
diff -c /dev/null llvm/include/llvm/PrintableItem.h:1.1.2.1
*** /dev/null Sun May 16 18:57:53 2004
--- llvm/include/llvm/PrintableItem.h Sun May 16 18:57:43 2004
***************
*** 0 ****
--- 1,66 ----
+ //===-- llvm/NamedItem.h - Definition of the Value class --------*- C++ -*-===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This file defines the common base class for Type and Value. It provides some
+ // basic, common functionality that both Type and Value use.
+ //
+ //===----------------------------------------------------------------------===//
+
+ #ifndef LLVM_PRINTABLEITEM_H
+ #define LLVM_PRINTABLEITEM_H
+
+ #include <iostream>
+
+ namespace llvm {
+
+ //===----------------------------------------------------------------------===//
+ // PrintableItem Class
+ //===----------------------------------------------------------------------===//
+
+ /// A base class endowing its subclasses with the ability to be printed on
+ /// an iostream and dumped in the debugger.
+ struct PrintableItem {
+
+ public:
+ /// We have nothing to destruct but we declare the virtual destructor here
+ /// because PrintableItem is the super class of many other classes.
+ virtual ~PrintableItem();
+
+ /// This method is overridden by subclasses to dump the contents
+ /// of the named item. It is intended to support debugging and
+ /// is callable in GDB with "call NI->dump()".
+ /// @brief Dump the named item to stderr.
+ void dump() const;
+
+ /// Implement operator<< on PrintableItem
+ virtual void print(std::ostream &O) const = 0;
+
+ };
+
+ /// An ostream inserter for a pointer to any PrintableItem subclass.
+ inline std::ostream &operator<<(std::ostream &OS, const PrintableItem *NI) {
+ if (NI == 0)
+ OS << "<null> value!\n";
+ else
+ NI->print(OS);
+ return OS;
+ }
+
+ /// An ostream inserter for a reference to any PrintableItem subclass.
+ inline std::ostream &operator<<(std::ostream &OS, const PrintableItem &NI) {
+ NI.print(OS);
+ return OS;
+ }
+
+ } // End llvm namespace
+
+ // vim: sw=2
+
+ #endif
+
More information about the llvm-commits
mailing list