[cfe-commits] r39178 - in /cfe/cfe/trunk: AST/SemaType.cpp AST/Type.cpp Parse/ParseDecl.cpp Sema/SemaType.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Type.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:40:38 PDT 2007
Author: sabre
Date: Wed Jul 11 11:40:37 2007
New Revision: 39178
URL: http://llvm.org/viewvc/llvm-project?rev=39178&view=rev
Log:
rearrange the type printing code so that we can do the horrible C "inside out"
thing properly. This allows us to print types like:
int (*A)[restrict static 4][6];
properly, in addition to representing them properly. :)
Modified:
cfe/cfe/trunk/AST/SemaType.cpp
cfe/cfe/trunk/AST/Type.cpp
cfe/cfe/trunk/Parse/ParseDecl.cpp
cfe/cfe/trunk/Sema/SemaType.cpp
cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/cfe/trunk/include/clang/AST/Type.h
Modified: cfe/cfe/trunk/AST/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaType.cpp?rev=39178&r1=39177&r2=39178&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaType.cpp (original)
+++ cfe/cfe/trunk/AST/SemaType.cpp Wed Jul 11 11:40:37 2007
@@ -87,14 +87,15 @@
// Apply const/volatile/restrict qualifiers to T.
T = T.getQualifiedType(D.getDeclSpec().TypeQualifiers);
- // Walk the DeclTypeInfo, building the recursive type as we go.
+ // Walk the DeclTypeInfo, building the recursive type as we go. DeclTypeInfos
+ // are ordered from the identifier out, which is opposite of what we want :).
for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
const DeclaratorTypeInfo &DeclType = D.getTypeObject(e-i-1);
switch (DeclType.Kind) {
default: assert(0 && "Unknown decltype!");
case DeclaratorTypeInfo::Pointer:
T = Context.getPointerType(T);
-
+
// Apply the pointer typequals to the pointer object.
T = T.getQualifiedType(DeclType.Ptr.TypeQuals);
break;
Modified: cfe/cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Type.cpp?rev=39178&r1=39177&r2=39178&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Type.cpp (original)
+++ cfe/cfe/trunk/AST/Type.cpp Wed Jul 11 11:40:37 2007
@@ -24,8 +24,8 @@
//===----------------------------------------------------------------------===//
void TypeRef::dump() const {
- std::string R;
- AppendToString(R);
+ std::string R = "foo";
+ getAsString(R);
std::cerr << R << "\n";
}
@@ -40,32 +40,45 @@
S += (NonePrinted+" restrict"), NonePrinted = false;
}
-void TypeRef::AppendToString(std::string &S) const {
+void TypeRef::getAsString(std::string &S) const {
if (isNull()) {
S += "NULL TYPE\n";
return;
}
- getTypePtr()->AppendToString(S);
-
// Print qualifiers as appropriate.
if (unsigned TQ = getQualifiers()) {
- S += ' ';
- AppendTypeQualList(S, TQ);
+ std::string TQS;
+ AppendTypeQualList(TQS, TQ);
+ S = TQS + ' ' + S;
}
+
+ getTypePtr()->getAsString(S);
}
-void BuiltinType::AppendToString(std::string &S) const {
- S += Name;
+void BuiltinType::getAsString(std::string &S) const {
+ if (S.empty()) {
+ S = Name;
+ } else {
+ // Prefix the basic type, e.g. 'int X'.
+ S = ' ' + S;
+ S = Name + S;
+ }
}
-void PointerType::AppendToString(std::string &S) const {
- PointeeType.AppendToString(S);
- S += '*';
+void PointerType::getAsString(std::string &S) const {
+ S = '*' + S;
+
+ // Handle things like 'int (*A)[4];' correctly.
+ // FIXME: this should include vectors.
+ if (isa<ArrayType>(PointeeType.getTypePtr()))
+ S = '(' + S + ')';
+
+
+ PointeeType.getAsString(S);
}
-void ArrayType::AppendToString(std::string &S) const {
- ElementType.AppendToString(S);
+void ArrayType::getAsString(std::string &S) const {
S += '[';
if (IndexTypeQuals) {
@@ -79,4 +92,6 @@
S += '*';
S += ']';
+
+ ElementType.getAsString(S);
}
Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=39178&r1=39177&r2=39178&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:40:37 2007
@@ -785,7 +785,7 @@
// Recursively parse the declarator.
ParseDeclaratorInternal(D);
-
+
// Remember that we parsed a pointer type, and remember the type-quals.
D.AddTypeInfo(DeclaratorTypeInfo::getPointer(DS.TypeQualifiers, Loc));
}
Modified: cfe/cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaType.cpp?rev=39178&r1=39177&r2=39178&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaType.cpp Wed Jul 11 11:40:37 2007
@@ -87,14 +87,15 @@
// Apply const/volatile/restrict qualifiers to T.
T = T.getQualifiedType(D.getDeclSpec().TypeQualifiers);
- // Walk the DeclTypeInfo, building the recursive type as we go.
+ // Walk the DeclTypeInfo, building the recursive type as we go. DeclTypeInfos
+ // are ordered from the identifier out, which is opposite of what we want :).
for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
const DeclaratorTypeInfo &DeclType = D.getTypeObject(e-i-1);
switch (DeclType.Kind) {
default: assert(0 && "Unknown decltype!");
case DeclaratorTypeInfo::Pointer:
T = Context.getPointerType(T);
-
+
// Apply the pointer typequals to the pointer object.
T = T.getQualifiedType(DeclType.Ptr.TypeQuals);
break;
Modified: cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=39178&r1=39177&r2=39178&view=diff
==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:40:37 2007
@@ -16,6 +16,7 @@
DE1733000B068B700080B521 /* ASTContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE1732FF0B068B700080B521 /* ASTContext.cpp */; };
DE17336E0B068DC20080B521 /* DeclSpec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE17336D0B068DC20080B521 /* DeclSpec.cpp */; };
DE1733700B068DC60080B521 /* DeclSpec.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE17336F0B068DC60080B521 /* DeclSpec.h */; };
+ DE1737A90B0847BC0080B521 /* SemaType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE1737A80B0847BC0080B521 /* SemaType.cpp */; };
DE1F22030A7D852A00FBF588 /* Parser.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE1F22020A7D852A00FBF588 /* Parser.h */; };
DE2E60610B04461800F3FAFE /* SemaExpr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE2E60600B04461800F3FAFE /* SemaExpr.cpp */; };
DE344AB80AE5DF6D00DBC861 /* HeaderSearch.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE344AB70AE5DF6D00DBC861 /* HeaderSearch.h */; };
@@ -147,6 +148,7 @@
DE1732FF0B068B700080B521 /* ASTContext.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ASTContext.cpp; path = AST/ASTContext.cpp; sourceTree = "<group>"; };
DE17336D0B068DC20080B521 /* DeclSpec.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = DeclSpec.cpp; path = Parse/DeclSpec.cpp; sourceTree = "<group>"; };
DE17336F0B068DC60080B521 /* DeclSpec.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DeclSpec.h; path = clang/Parse/DeclSpec.h; sourceTree = "<group>"; };
+ DE1737A80B0847BC0080B521 /* SemaType.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = SemaType.cpp; path = AST/SemaType.cpp; sourceTree = "<group>"; };
DE1F22020A7D852A00FBF588 /* Parser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Parser.h; path = clang/Parse/Parser.h; sourceTree = "<group>"; };
DE2E60600B04461800F3FAFE /* SemaExpr.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = SemaExpr.cpp; path = AST/SemaExpr.cpp; sourceTree = "<group>"; };
DE344AB70AE5DF6D00DBC861 /* HeaderSearch.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = HeaderSearch.h; sourceTree = "<group>"; };
@@ -336,6 +338,7 @@
DE34633F0B02F0F800DBC861 /* SemaDecl.cpp */,
DE2E60600B04461800F3FAFE /* SemaExpr.cpp */,
DE75ED180B0446470020CF81 /* SemaStmt.cpp */,
+ DE1737A80B0847BC0080B521 /* SemaType.cpp */,
DE34621C0AFEB19B00DBC861 /* StmtPrinter.cpp */,
DE345C560AFC69E800DBC861 /* StmtVisitor.cpp */,
);
@@ -499,6 +502,7 @@
DE75EDF10B06880E0020CF81 /* Type.cpp in Sources */,
DE1733000B068B700080B521 /* ASTContext.cpp in Sources */,
DE17336E0B068DC20080B521 /* DeclSpec.cpp in Sources */,
+ DE1737A90B0847BC0080B521 /* SemaType.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
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=39178&r1=39177&r2=39178&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Type.h Wed Jul 11 11:40:37 2007
@@ -105,7 +105,7 @@
/// appropriate type qualifiers on it.
inline TypeRef getCanonicalType() const;
- void AppendToString(std::string &S) const;
+ void getAsString(std::string &S) const;
void dump() const;
};
@@ -157,7 +157,7 @@
bool isCanonical() const { return CanonicalType == this; }
Type *getCanonicalType() const { return CanonicalType; }
- virtual void AppendToString(std::string &S) const = 0;
+ virtual void getAsString(std::string &InnerString) const = 0;
static bool classof(const Type *) { return true; }
};
@@ -169,8 +169,7 @@
public:
BuiltinType(const char *name) : Type(Builtin, 0), Name(name) {}
- virtual void AppendToString(std::string &S) const;
-
+ virtual void getAsString(std::string &InnerString) const;
static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
static bool classof(const BuiltinType *) { return true; }
@@ -188,7 +187,7 @@
TypeRef getPointeeType() const { return PointeeType; }
- virtual void AppendToString(std::string &S) const;
+ virtual void getAsString(std::string &InnerString) const;
static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
static bool classof(const PointerType *) { return true; }
@@ -226,7 +225,7 @@
ArraySizeModifier getSizeModifier() const { return SizeModifier; }
unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
- virtual void AppendToString(std::string &S) const;
+ virtual void getAsString(std::string &InnerString) 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