diff options
author | John McCall <rjmccall@apple.com> | 2009-09-05 06:31:47 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2009-09-05 06:31:47 +0000 |
commit | 2191b20bfb31fc0e22a158f6b4204cd0b7dbd0fd (patch) | |
tree | f83185278453f6702e0ebee829f34e2cd58b6a4f | |
parent | a2f4ec0df645fc249d2945beef9653f03b175417 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81065 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/PrettyPrinter.h | 7 | ||||
-rw-r--r-- | lib/AST/NestedNameSpecifier.cpp | 1 | ||||
-rw-r--r-- | lib/AST/Type.cpp | 10 | ||||
-rw-r--r-- | lib/CodeGen/Mangle.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/Sema.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaType.cpp | 7 |
7 files changed, 29 insertions, 5 deletions
diff --git a/include/clang/AST/PrettyPrinter.h b/include/clang/AST/PrettyPrinter.h index 0a13d3fd4e..bc4c82f2be 100644 --- a/include/clang/AST/PrettyPrinter.h +++ b/include/clang/AST/PrettyPrinter.h @@ -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 diff --git a/lib/AST/NestedNameSpecifier.cpp b/lib/AST/NestedNameSpecifier.cpp index 0c24c89b29..24fb752420 100644 --- a/lib/AST/NestedNameSpecifier.cpp +++ b/lib/AST/NestedNameSpecifier.cpp @@ -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 diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index f4dad13f41..9bcfb2ad8f 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -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; } diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index b293560ec9..29b4c8a837 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/lib/CodeGen/Mangle.cpp @@ -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 diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 755cc22d52..b41902c15f 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -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() && diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e929b5f0d6..9809ea5501 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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 diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 80cdcd5464..b6db829de6 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -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; |