[cfe-commits] r39177 - in /cfe/cfe/trunk: AST/Type.cpp include/clang/AST/Type.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:40:37 PDT 2007
Author: sabre
Date: Wed Jul 11 11:40:36 2007
New Revision: 39177
URL: http://llvm.org/viewvc/llvm-project?rev=39177&view=rev
Log:
change print methods to render into a string, which is more useful for diagnostics
and for handling precedence of types more accurately
Modified:
cfe/cfe/trunk/AST/Type.cpp
cfe/cfe/trunk/include/clang/AST/Type.h
Modified: cfe/cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Type.cpp?rev=39177&r1=39176&r2=39177&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Type.cpp (original)
+++ cfe/cfe/trunk/AST/Type.cpp Wed Jul 11 11:40:36 2007
@@ -24,58 +24,59 @@
//===----------------------------------------------------------------------===//
void TypeRef::dump() const {
- print(std::cerr);
- std::cerr << "\n";
+ std::string R;
+ AppendToString(R);
+ std::cerr << R << "\n";
}
-static void PrintTypeQualList(std::ostream &OS, unsigned TypeQuals) {
+static void AppendTypeQualList(std::string &S, unsigned TypeQuals) {
// Note: funkiness to ensure we get a space only between quals.
bool NonePrinted = true;
if (TypeQuals & TypeRef::Const)
- OS << "const", NonePrinted = false;
+ S += "const", NonePrinted = false;
if (TypeQuals & TypeRef::Volatile)
- OS << (NonePrinted+" volatile"), NonePrinted = false;
+ S += (NonePrinted+" volatile"), NonePrinted = false;
if (TypeQuals & TypeRef::Restrict)
- OS << (NonePrinted+" restrict"), NonePrinted = false;
- }
+ S += (NonePrinted+" restrict"), NonePrinted = false;
+}
-void TypeRef::print(std::ostream &OS) const {
+void TypeRef::AppendToString(std::string &S) const {
if (isNull()) {
- OS << "NULL TYPE\n";
+ S += "NULL TYPE\n";
return;
}
- getTypePtr()->print(OS);
+ getTypePtr()->AppendToString(S);
// Print qualifiers as appropriate.
if (unsigned TQ = getQualifiers()) {
- OS << " ";
- PrintTypeQualList(OS, TQ);
+ S += ' ';
+ AppendTypeQualList(S, TQ);
}
}
-void BuiltinType::print(std::ostream &OS) const {
- OS << Name;
+void BuiltinType::AppendToString(std::string &S) const {
+ S += Name;
}
-void PointerType::print(std::ostream &OS) const {
- PointeeType.print(OS);
- OS << "*";
+void PointerType::AppendToString(std::string &S) const {
+ PointeeType.AppendToString(S);
+ S += '*';
}
-void ArrayType::print(std::ostream &OS) const {
- ElementType.print(OS);
- OS << "[";
+void ArrayType::AppendToString(std::string &S) const {
+ ElementType.AppendToString(S);
+ S += '[';
if (IndexTypeQuals) {
- PrintTypeQualList(OS, IndexTypeQuals);
- OS << " ";
+ AppendTypeQualList(S, IndexTypeQuals);
+ S += ' ';
}
if (SizeModifier == Static)
- OS << "static";
+ S += "static";
else if (SizeModifier == Star)
- OS << "*";
+ S += '*';
- OS << "]";
+ S += ']';
}
Modified: cfe/cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Type.h?rev=39177&r1=39176&r2=39177&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Type.h Wed Jul 11 11:40:36 2007
@@ -17,7 +17,7 @@
#include "llvm/Support/Casting.h"
#include "llvm/Support/DataTypes.h"
#include <cassert>
-#include <iosfwd>
+#include <string>
namespace llvm {
namespace clang {
@@ -105,7 +105,7 @@
/// appropriate type qualifiers on it.
inline TypeRef getCanonicalType() const;
- void print(std::ostream &OS) const;
+ void AppendToString(std::string &S) const;
void dump() const;
};
@@ -157,7 +157,7 @@
bool isCanonical() const { return CanonicalType == this; }
Type *getCanonicalType() const { return CanonicalType; }
- virtual void print(std::ostream &OS) const = 0;
+ virtual void AppendToString(std::string &S) const = 0;
static bool classof(const Type *) { return true; }
};
@@ -169,7 +169,7 @@
public:
BuiltinType(const char *name) : Type(Builtin, 0), Name(name) {}
- virtual void print(std::ostream &OS) const;
+ virtual void AppendToString(std::string &S) const;
static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
@@ -188,7 +188,7 @@
TypeRef getPointeeType() const { return PointeeType; }
- virtual void print(std::ostream &OS) const;
+ virtual void AppendToString(std::string &S) const;
static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
static bool classof(const PointerType *) { return true; }
@@ -226,7 +226,7 @@
ArraySizeModifier getSizeModifier() const { return SizeModifier; }
unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
- virtual void print(std::ostream &OS) const;
+ virtual void AppendToString(std::string &S) const;
static bool classof(const Type *T) { return T->getTypeClass() == Array; }
static bool classof(const ArrayType *) { return true; }
More information about the cfe-commits
mailing list