[cfe-commits] r39449 - in /cfe/cfe/trunk: AST/Sema.cpp AST/SemaExpr.cpp AST/SemaType.cpp AST/StmtPrinter.cpp AST/Type.cpp Driver/clang.cpp Sema/Sema.cpp Sema/SemaExpr.cpp Sema/SemaType.cpp include/clang/AST/Type.h

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:44:33 PDT 2007


Author: clattner
Date: Wed Jul 11 11:44:33 2007
New Revision: 39449

URL: http://llvm.org/viewvc/llvm-project?rev=39449&view=rev
Log:
Rename type::getAsString to getAsStringInternal.  Add a new
QualType::getAsString() that returns a string, which is much easier
for clients to use.  Convert clients to use it.

Modified:
    cfe/cfe/trunk/AST/Sema.cpp
    cfe/cfe/trunk/AST/SemaExpr.cpp
    cfe/cfe/trunk/AST/SemaType.cpp
    cfe/cfe/trunk/AST/StmtPrinter.cpp
    cfe/cfe/trunk/AST/Type.cpp
    cfe/cfe/trunk/Driver/clang.cpp
    cfe/cfe/trunk/Sema/Sema.cpp
    cfe/cfe/trunk/Sema/SemaExpr.cpp
    cfe/cfe/trunk/Sema/SemaType.cpp
    cfe/cfe/trunk/include/clang/AST/Type.h

Modified: cfe/cfe/trunk/AST/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.cpp?rev=39449&r1=39448&r2=39449&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:44:33 2007
@@ -45,8 +45,7 @@
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, QualType t) {
-  std::string Name;
-  t.getAsString(Name);
+  std::string Name = t.getAsString();
   PP.getDiagnostics().Report(Loc, DiagID, &Name, 1);
   return true;
 }

Modified: cfe/cfe/trunk/AST/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaExpr.cpp?rev=39449&r1=39448&r2=39449&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/AST/SemaExpr.cpp Wed Jul 11 11:44:33 2007
@@ -179,10 +179,9 @@
   else if (exprType->isVoidType())
     Diag(OpLoc, diag::ext_sizeof_void_type, isSizeof ? "sizeof" : "__alignof");
   else if (exprType->isIncompleteType()) {
-    std::string TypeName;
-    exprType->getAsString(TypeName);
     Diag(OpLoc, isSizeof ? diag::err_sizeof_incomplete_type : 
-                           diag::err_alignof_incomplete_type, TypeName);
+                           diag::err_alignof_incomplete_type,
+         exprType.getAsString());
     return QualType(); // error
   }
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.

Modified: cfe/cfe/trunk/AST/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaType.cpp?rev=39449&r1=39448&r2=39449&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaType.cpp (original)
+++ cfe/cfe/trunk/AST/SemaType.cpp Wed Jul 11 11:44:33 2007
@@ -136,10 +136,8 @@
       // C99 6.7.5.2p1: If the element type is an incomplete or function type, 
       // reject it (e.g. void ary[7], struct foo ary[7], void ary[7]())
       if (T->isIncompleteType()) { 
-        std::string Name;
-        T->getAsString(Name);
         Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_incomplete_type,
-             Name);
+             T.getAsString());
         return QualType();
       } else if (isa<FunctionType>(CanonicalT)) {
         Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_functions,
@@ -149,9 +147,8 @@
         // If the element type is a struct or union that contains a variadic
         // array, reject it: C99 6.7.2.1p2.
         if (EltTy->getDecl()->hasFlexibleArrayMember()) {
-          std::string Name;
-          T->getAsString(Name);
-          Diag(DeclType.Loc, diag::err_flexible_array_in_array, Name);
+          Diag(DeclType.Loc, diag::err_flexible_array_in_array,
+               T.getAsString());
           return QualType();
         }
       }

Modified: cfe/cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/StmtPrinter.cpp?rev=39449&r1=39448&r2=39449&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/cfe/trunk/AST/StmtPrinter.cpp Wed Jul 11 11:44:33 2007
@@ -263,10 +263,7 @@
 }
 void StmtPrinter::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
   OS << (Node->isSizeOf() ? "sizeof(" : "__alignof(");
-  
-  std::string TypeStr;
-  Node->getArgumentType().getAsString(TypeStr);
-  OS << TypeStr << ")";
+  OS << Node->getArgumentType().getAsString() << ")";
 }
 void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
   PrintExpr(Node->getBase());
@@ -293,10 +290,7 @@
   OS << "member";
 }
 void StmtPrinter::VisitCastExpr(CastExpr *Node) {
-  OS << "(";
-  std::string TypeStr;
-  Node->getDestType().getAsString(TypeStr);
-  OS << TypeStr << ")";
+  OS << "(" << Node->getDestType().getAsString() << ")";
   PrintExpr(Node->getSubExpr());
 }
 void StmtPrinter::VisitCXXCastExpr(CXXCastExpr *Node) {
@@ -310,9 +304,7 @@
   case CXXCastExpr::StaticCast:      OS << "static_cast<";      break;
   }
 
-  std::string TypeStr;
-  Node->getDestType().getAsString(TypeStr);
-  OS << TypeStr << ">(";
+  OS << Node->getDestType().getAsString() << ">(";
   PrintExpr(Node->getSubExpr());
   OS << ")";
 }

Modified: cfe/cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Type.cpp?rev=39449&r1=39448&r2=39449&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Type.cpp (original)
+++ cfe/cfe/trunk/AST/Type.cpp Wed Jul 11 11:44:33 2007
@@ -373,7 +373,7 @@
 
 void QualType::dump(const char *msg) const {
   std::string R = "foo";
-  getAsString(R);
+  getAsStringInternal(R);
   if (msg)
     std::cerr << msg << ": " << R << "\n";
   else
@@ -391,7 +391,7 @@
     S += (NonePrinted+" restrict"), NonePrinted = false;
 }
 
-void QualType::getAsString(std::string &S) const {
+void QualType::getAsStringInternal(std::string &S) const {
   if (isNull()) {
     S += "NULL TYPE\n";
     return;
@@ -404,10 +404,10 @@
     S = TQS + ' ' + S;
   }
 
-  getTypePtr()->getAsString(S);
+  getTypePtr()->getAsStringInternal(S);
 }
 
-void BuiltinType::getAsString(std::string &S) const {
+void BuiltinType::getAsStringInternal(std::string &S) const {
   if (S.empty()) {
     S = getName();
   } else {
@@ -417,7 +417,7 @@
   }
 }
 
-void PointerType::getAsString(std::string &S) const {
+void PointerType::getAsStringInternal(std::string &S) const {
   S = '*' + S;
   
   // Handle things like 'int (*A)[4];' correctly.
@@ -425,10 +425,10 @@
   if (isa<ArrayType>(PointeeType.getTypePtr()))
     S = '(' + S + ')';
   
-  PointeeType.getAsString(S);
+  PointeeType.getAsStringInternal(S);
 }
 
-void ArrayType::getAsString(std::string &S) const {
+void ArrayType::getAsStringInternal(std::string &S) const {
   S += '[';
   
   if (IndexTypeQuals) {
@@ -443,19 +443,19 @@
   
   S += ']';
   
-  ElementType.getAsString(S);
+  ElementType.getAsStringInternal(S);
 }
 
-void FunctionTypeNoProto::getAsString(std::string &S) const {
+void FunctionTypeNoProto::getAsStringInternal(std::string &S) const {
   // If needed for precedence reasons, wrap the inner part in grouping parens.
   if (!S.empty())
     S = "(" + S + ")";
   
   S += "()";
-  getResultType().getAsString(S);
+  getResultType().getAsStringInternal(S);
 }
 
-void FunctionTypeProto::getAsString(std::string &S) const {
+void FunctionTypeProto::getAsStringInternal(std::string &S) const {
   // If needed for precedence reasons, wrap the inner part in grouping parens.
   if (!S.empty())
     S = "(" + S + ")";
@@ -464,7 +464,7 @@
   std::string Tmp;
   for (unsigned i = 0, e = getNumArgs(); i != e; ++i) {
     if (i) S += ", ";
-    getArgType(i).getAsString(Tmp);
+    getArgType(i).getAsStringInternal(Tmp);
     S += Tmp;
     Tmp.clear();
   }
@@ -479,17 +479,17 @@
   }
   
   S += ")";
-  getResultType().getAsString(S);
+  getResultType().getAsStringInternal(S);
 }
 
 
-void TypedefType::getAsString(std::string &InnerString) const {
+void TypedefType::getAsStringInternal(std::string &InnerString) const {
   if (!InnerString.empty())    // Prefix the basic type, e.g. 'typedefname X'.
     InnerString = ' ' + InnerString;
   InnerString = getDecl()->getIdentifier()->getName() + InnerString;
 }
 
-void TagType::getAsString(std::string &InnerString) const {
+void TagType::getAsStringInternal(std::string &InnerString) const {
   if (!InnerString.empty())    // Prefix the basic type, e.g. 'typedefname X'.
     InnerString = ' ' + InnerString;
   

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39449&r1=39448&r2=39449&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:44:33 2007
@@ -857,7 +857,7 @@
       std::string ParamStr;
       if (HasBody) ParamStr = FD->getParamDecl(i)->getName();
       
-      FT->getArgType(i).getAsString(ParamStr);
+      FT->getArgType(i).getAsStringInternal(ParamStr);
       Proto += ParamStr;
     }
     
@@ -870,7 +870,7 @@
     assert(isa<FunctionTypeNoProto>(AFT));
     Proto += "()";
   }
-  AFT->getResultType().getAsString(Proto);
+  AFT->getResultType().getAsStringInternal(Proto);
 
   std::cerr << "\n" << Proto;
   
@@ -885,7 +885,7 @@
 
 static void PrintTypeDefDecl(TypedefDecl *TD) {
   std::string S = TD->getName();
-  TD->getUnderlyingType().getAsString(S);
+  TD->getUnderlyingType().getAsStringInternal(S);
   std::cerr << "typedef " << S << ";\n";
 }
 

Modified: cfe/cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.cpp?rev=39449&r1=39448&r2=39449&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:44:33 2007
@@ -45,8 +45,7 @@
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, QualType t) {
-  std::string Name;
-  t.getAsString(Name);
+  std::string Name = t.getAsString();
   PP.getDiagnostics().Report(Loc, DiagID, &Name, 1);
   return true;
 }

Modified: cfe/cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaExpr.cpp?rev=39449&r1=39448&r2=39449&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:44:33 2007
@@ -179,10 +179,9 @@
   else if (exprType->isVoidType())
     Diag(OpLoc, diag::ext_sizeof_void_type, isSizeof ? "sizeof" : "__alignof");
   else if (exprType->isIncompleteType()) {
-    std::string TypeName;
-    exprType->getAsString(TypeName);
     Diag(OpLoc, isSizeof ? diag::err_sizeof_incomplete_type : 
-                           diag::err_alignof_incomplete_type, TypeName);
+                           diag::err_alignof_incomplete_type,
+         exprType.getAsString());
     return QualType(); // error
   }
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.

Modified: cfe/cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaType.cpp?rev=39449&r1=39448&r2=39449&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaType.cpp Wed Jul 11 11:44:33 2007
@@ -136,10 +136,8 @@
       // C99 6.7.5.2p1: If the element type is an incomplete or function type, 
       // reject it (e.g. void ary[7], struct foo ary[7], void ary[7]())
       if (T->isIncompleteType()) { 
-        std::string Name;
-        T->getAsString(Name);
         Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_incomplete_type,
-             Name);
+             T.getAsString());
         return QualType();
       } else if (isa<FunctionType>(CanonicalT)) {
         Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_functions,
@@ -149,9 +147,8 @@
         // If the element type is a struct or union that contains a variadic
         // array, reject it: C99 6.7.2.1p2.
         if (EltTy->getDecl()->hasFlexibleArrayMember()) {
-          std::string Name;
-          T->getAsString(Name);
-          Diag(DeclType.Loc, diag::err_flexible_array_in_array, Name);
+          Diag(DeclType.Loc, diag::err_flexible_array_in_array,
+               T.getAsString());
           return QualType();
         }
       }

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=39449&r1=39448&r2=39449&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Type.h Wed Jul 11 11:44:33 2007
@@ -112,12 +112,20 @@
   bool operator!=(const QualType &RHS) const {
     return ThePtr != RHS.ThePtr;
   }
-  void getAsString(std::string &S) const;
+  std::string getAsString() const {
+    std::string S;
+    getAsStringInternal(S);
+    return S;
+  }
+  void getAsStringInternal(std::string &Str) const;
+  
   void dump(const char *s = 0) const;
 
   /// getCanonicalType - Return the canonical version of this type, with the
   /// appropriate type qualifiers on it.
   inline QualType getCanonicalType() const;
+  
+private:
 };
 
 } // end clang.
@@ -237,7 +245,7 @@
   QualType getCanonicalTypeInternal() const { return CanonicalType; }
   friend class QualType;
 public:
-  virtual void getAsString(std::string &InnerString) const = 0;
+  virtual void getAsStringInternal(std::string &InnerString) const = 0;
   
   static bool classof(const Type *) { return true; }
 };
@@ -261,7 +269,7 @@
   Kind getKind() const { return TypeKind; }
   const char *getName() const;
   
-  virtual void getAsString(std::string &InnerString) const;
+  virtual void getAsStringInternal(std::string &InnerString) const;
   
   static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
   static bool classof(const BuiltinType *) { return true; }
@@ -279,7 +287,7 @@
     
   QualType getPointeeType() const { return PointeeType; }
   
-  virtual void getAsString(std::string &InnerString) const;
+  virtual void getAsStringInternal(std::string &InnerString) const;
   
   
   void Profile(FoldingSetNodeID &ID) {
@@ -329,7 +337,7 @@
   unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
   Expr *getSize() const { return SizeExpr; }
   
-  virtual void getAsString(std::string &InnerString) const;
+  virtual void getAsStringInternal(std::string &InnerString) const;
   
   void Profile(FoldingSetNodeID &ID) {
     Profile(ID, getSizeModifier(), getIndexTypeQualifier(), getElementType(),
@@ -383,7 +391,7 @@
 public:
   // No additional state past what FunctionType provides.
   
-  virtual void getAsString(std::string &InnerString) const;
+  virtual void getAsStringInternal(std::string &InnerString) const;
 
   void Profile(FoldingSetNodeID &ID) {
     Profile(ID, getResultType());
@@ -427,7 +435,7 @@
     
   bool isVariadic() const { return getSubClassData(); }
   
-  virtual void getAsString(std::string &InnerString) const;
+  virtual void getAsStringInternal(std::string &InnerString) const;
 
   static bool classof(const Type *T) {
     return T->getTypeClass() == FunctionProto;
@@ -450,7 +458,7 @@
   
   TypedefDecl *getDecl() const { return Decl; }
     
-  virtual void getAsString(std::string &InnerString) const;
+  virtual void getAsStringInternal(std::string &InnerString) const;
 
   static bool classof(const Type *T) { return T->getTypeClass() == TypeName; }
   static bool classof(const TypedefType *) { return true; }
@@ -465,7 +473,7 @@
     
   TagDecl *getDecl() const { return Decl; }
   
-  virtual void getAsString(std::string &InnerString) const;
+  virtual void getAsStringInternal(std::string &InnerString) const;
   
   static bool classof(const Type *T) { return T->getTypeClass() == Tagged; }
   static bool classof(const TagType *) { return true; }





More information about the cfe-commits mailing list