]> granicus.if.org Git - clang/commitdiff
Start emitting ElaboratedTypes in C++ mode. Support the effort in various
authorJohn McCall <rjmccall@apple.com>
Sat, 5 Sep 2009 06:31:47 +0000 (06:31 +0000)
committerJohn McCall <rjmccall@apple.com>
Sat, 5 Sep 2009 06:31:47 +0000 (06:31 +0000)
ways:  remove elab types during desugaring, enhance pretty-printing to allow
tags to be suppressed without suppressing scopes, look through elab types
when associating a typedef name with an anonymous record type.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81065 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/PrettyPrinter.h
lib/AST/NestedNameSpecifier.cpp
lib/AST/Type.cpp
lib/CodeGen/Mangle.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaType.cpp

index 0a13d3fd4e0047fcf9c261ad9d1e2a6dc92cf168..bc4c82f2be62b99360f4d55a33a81bdebd165915 100644 (file)
@@ -36,8 +36,8 @@ struct PrintingPolicy {
   /// \brief Create a default printing policy for C.
   PrintingPolicy(const LangOptions &LO) 
     : Indentation(2), LangOpts(LO), SuppressSpecifiers(false),
-      SuppressTag(false), SuppressTagKind(false), Dump(false),
-      ConstantArraySizeAsWritten(false) { }
+      SuppressTag(false), SuppressTagKind(false), SuppressScope(false),
+      Dump(false), ConstantArraySizeAsWritten(false) { }
 
   /// \brief The number of spaces to use to indent each line.
   unsigned Indentation : 8;
@@ -75,6 +75,9 @@ struct PrintingPolicy {
   /// kind of tag, e.g., "struct", "union", "enum".
   bool SuppressTagKind : 1;
 
+  /// \brief Suppresses printing of scope specifiers.
+  bool SuppressScope : 1;
+
   /// \brief True when we are "dumping" rather than "pretty-printing",
   /// where dumping involves printing the internal details of the AST
   /// and pretty-printing involves printing something similar to
index 0c24c89b2917d7858f74df9b7c5cc2623df1c7e1..24fb75242042788131545d7c616864b82d723fef 100644 (file)
@@ -143,6 +143,7 @@ NestedNameSpecifier::print(llvm::raw_ostream &OS,
 
     PrintingPolicy InnerPolicy(Policy);
     InnerPolicy.SuppressTagKind = true;
+    InnerPolicy.SuppressScope = true;
     
     // Nested-name-specifiers are intended to contain minimally-qualified
     // types. An actual QualifiedNameType will not occur, since we'll store
index f4dad13f41605a1d8a25ff3c87ac3a20ad2df40b..9bcfb2ad8fd590f8ed4d802b0b77db18df11f9f3 100644 (file)
@@ -143,6 +143,8 @@ QualType QualType::getDesugaredType(bool ForDisplay) const {
 QualType Type::getDesugaredType(bool ForDisplay) const {
   if (const TypedefType *TDT = dyn_cast<TypedefType>(this))
     return TDT->LookThroughTypedefs().getDesugaredType();
+  if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(this))
+    return ET->getUnderlyingType().getDesugaredType();
   if (const TypeOfExprType *TOE = dyn_cast<TypeOfExprType>(this))
     return TOE->getUnderlyingExpr()->getType().getDesugaredType();
   if (const TypeOfType *TOT = dyn_cast<TypeOfType>(this))
@@ -1575,6 +1577,7 @@ void QualifiedNameType::getAsStringInternal(std::string &InnerString, const Prin
   std::string TypeStr;
   PrintingPolicy InnerPolicy(Policy);
   InnerPolicy.SuppressTagKind = true;
+  InnerPolicy.SuppressScope = true;
   NamedType.getAsStringInternal(TypeStr, InnerPolicy);
 
   MyString += TypeStr;
@@ -1715,7 +1718,7 @@ void TagType::getAsStringInternal(std::string &InnerString, const PrintingPolicy
     InnerString = TemplateArgsStr + InnerString;
   }
 
-  if (Kind) {
+  if (!Policy.SuppressScope) {
     // Compute the full nested-name-specifier for this type. In C,
     // this will always be empty.
     std::string ContextStr;
@@ -1745,7 +1748,10 @@ void TagType::getAsStringInternal(std::string &InnerString, const PrintingPolicy
         ContextStr = MyPart + "::" + ContextStr;
     }
 
-    InnerString = std::string(Kind) + " " + ContextStr + ID + InnerString;
+    if (Kind)
+      InnerString = std::string(Kind) + ' ' + ContextStr + ID + InnerString;
+    else
+      InnerString = ContextStr + ID + InnerString;
   } else
     InnerString = ID + InnerString;
 }
index b293560ec90fa44fbdd8062536ba92c18a3a1bec..29b4c8a837787e27afa1e0607d4a6e713457c7d0 100644 (file)
@@ -581,6 +581,9 @@ void CXXNameMangler::mangleType(QualType T) {
   } else if (const ObjCInterfaceType *IT = 
              dyn_cast<ObjCInterfaceType>(T.getTypePtr())) {
     mangleType(IT);
+  } else if (const ElaboratedType *ET =
+             dyn_cast<ElaboratedType>(T.getTypePtr())) {
+    mangleType(ET->getUnderlyingType());
   }
   // FIXME:  ::= G <type>   # imaginary (C 2000)
   // FIXME:  ::= U <source-name> <type>     # vendor extended type qualifier
index 755cc22d52b5928de5cd3063b78e8d82ee44a1fa..b41902c15fb4327ef3e2e48f5cfd12c4c749570b 100644 (file)
@@ -52,6 +52,10 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val,
         // If the desugared type is a vector type, we don't want to expand it,
         // it will turn into an attribute mess. People want their "vec4".
         !isa<VectorType>(DesugaredTy) &&
+
+        // Don't aka just because we saw an elaborated type.
+        (!isa<ElaboratedType>(Ty) ||
+         cast<ElaboratedType>(Ty)->getUnderlyingType() != DesugaredTy) &&
       
         // Don't desugar magic Objective-C types.
         Ty.getUnqualifiedType() != Context.getObjCIdType() &&
index e929b5f0d6d05a058a269b9c0a3f8c9627635644..9809ea55014f5b03ab0e46e40beaa18d1608a3ed 100644 (file)
@@ -3893,7 +3893,7 @@ TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T) {
                                            D.getIdentifier(), 
                                            T);
   
-  if (TagType *TT = dyn_cast<TagType>(T)) {
+  if (const TagType *TT = T->getAs<TagType>()) {
     TagDecl *TD = TT->getDecl();
     
     // If the TagDecl that the TypedefDecl points to is an anonymous decl
index 80cdcd5464e7c48e35e96cd95ff3e6a493bd1e73..b6db829de6d4fe317b186627b4cf0a07585103ed 100644 (file)
@@ -195,6 +195,13 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS,
            "Can't handle qualifiers on typedef names yet!");
     // TypeQuals handled by caller.
     Result = Context.getTypeDeclType(cast<TypeDecl>(D));
+
+    // In C++, make an ElaboratedType.
+    if (getLangOptions().CPlusPlus) {
+      TagDecl::TagKind Tag
+        = TagDecl::getTagKindForTypeSpec(DS.getTypeSpecType());
+      Result = Context.getElaboratedType(Result, Tag);
+    }
     
     if (D->isInvalidDecl())
       isInvalid = true;