[cfe-commits] r81065 - in /cfe/trunk: 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

John McCall rjmccall at apple.com
Fri Sep 4 23:31:48 PDT 2009


Author: rjmccall
Date: Sat Sep  5 01:31:47 2009
New Revision: 81065

URL: http://llvm.org/viewvc/llvm-project?rev=81065&view=rev
Log:
Start emitting ElaboratedTypes in C++ mode.  Support the effort in various
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.


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

Modified: cfe/trunk/include/clang/AST/PrettyPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/PrettyPrinter.h?rev=81065&r1=81064&r2=81065&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/PrettyPrinter.h (original)
+++ cfe/trunk/include/clang/AST/PrettyPrinter.h Sat Sep  5 01:31:47 2009
@@ -36,8 +36,8 @@
   /// \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 @@
   /// 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

Modified: cfe/trunk/lib/AST/NestedNameSpecifier.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/NestedNameSpecifier.cpp?rev=81065&r1=81064&r2=81065&view=diff

==============================================================================
--- cfe/trunk/lib/AST/NestedNameSpecifier.cpp (original)
+++ cfe/trunk/lib/AST/NestedNameSpecifier.cpp Sat Sep  5 01:31:47 2009
@@ -143,6 +143,7 @@
 
     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

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

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Sat Sep  5 01:31:47 2009
@@ -143,6 +143,8 @@
 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 @@
   std::string TypeStr;
   PrintingPolicy InnerPolicy(Policy);
   InnerPolicy.SuppressTagKind = true;
+  InnerPolicy.SuppressScope = true;
   NamedType.getAsStringInternal(TypeStr, InnerPolicy);
 
   MyString += TypeStr;
@@ -1715,7 +1718,7 @@
     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 @@
         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;
 }

Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=81065&r1=81064&r2=81065&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Sat Sep  5 01:31:47 2009
@@ -581,6 +581,9 @@
   } 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

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sat Sep  5 01:31:47 2009
@@ -52,6 +52,10 @@
         // 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() &&

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=81065&r1=81064&r2=81065&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Sep  5 01:31:47 2009
@@ -3893,7 +3893,7 @@
                                            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

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sat Sep  5 01:31:47 2009
@@ -195,6 +195,13 @@
            "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;





More information about the cfe-commits mailing list