diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 07eae4427a..85635709e0 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -158,28 +158,11 @@ public: return QualType(getTypePtr(), TQs|getCVRQualifiers()); } - inline QualType getUnqualifiedType() const; + QualType getUnqualifiedType() const; + bool isMoreQualifiedThan(QualType Other) const; + bool isAtLeastAsQualifiedAs(QualType Other) const; + QualType getNonReferenceType() const; - /// isMoreQualifiedThan - Determine whether this type is more - /// qualified than the Other type. For example, "const volatile int" - /// is more qualified than "const int", "volatile int", and - /// "int". However, it is not more qualified than "const volatile - /// int". - bool isMoreQualifiedThan(QualType Other) const { - unsigned MyQuals = this->getCVRQualifiers(); - unsigned OtherQuals = Other.getCVRQualifiers(); - return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; - } - - /// isAtLeastAsQualifiedAs - Determine whether this type is at last - /// as qualified as the Other type. For example, "const volatile - /// int" is at least as qualified as "const int", "volatile int", - /// "int", and "const volatile int". - bool isAtLeastAsQualifiedAs(QualType Other) const { - unsigned MyQuals = this->getCVRQualifiers(); - unsigned OtherQuals = Other.getCVRQualifiers(); - return (MyQuals | OtherQuals) == MyQuals; - } /// operator==/!= - Indicate whether the specified types and qualifiers are /// identical. @@ -1370,6 +1353,45 @@ inline unsigned QualType::getAddressSpace() const { return 0; } +/// isMoreQualifiedThan - Determine whether this type is more +/// qualified than the Other type. For example, "const volatile int" +/// is more qualified than "const int", "volatile int", and +/// "int". However, it is not more qualified than "const volatile +/// int". +inline bool QualType::isMoreQualifiedThan(QualType Other) const { + // FIXME: Handle address spaces + unsigned MyQuals = this->getCVRQualifiers(); + unsigned OtherQuals = Other.getCVRQualifiers(); + return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; +} + +/// isAtLeastAsQualifiedAs - Determine whether this type is at last +/// as qualified as the Other type. For example, "const volatile +/// int" is at least as qualified as "const int", "volatile int", +/// "int", and "const volatile int". +inline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { + // FIXME: Handle address spaces + unsigned MyQuals = this->getCVRQualifiers(); + unsigned OtherQuals = Other.getCVRQualifiers(); + return (MyQuals | OtherQuals) == MyQuals; +} + +/// getNonReferenceType - If Type is a reference type (e.g., const +/// int&), returns the type that the reference refers to ("const +/// int"). Otherwise, returns the type itself. This routine is used +/// throughout Sema to implement C++ 5p6: +/// +/// If an expression initially has the type "reference to T" (8.3.2, +/// 8.5.3), the type is adjusted to "T" prior to any further +/// analysis, the expression designates the object or function +/// denoted by the reference, and the expression is an lvalue. +inline QualType QualType::getNonReferenceType() const { + if (const ReferenceType *RefType = (*this)->getAsReferenceType()) + return RefType->getPointeeType(); + else + return *this; +} + inline const TypedefType* Type::getAsTypedefType() const { return dyn_cast(this); } diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index d53e200ba9..2508d1ac9f 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -259,7 +259,6 @@ public: QualType ConvertDeclSpecToType(const DeclSpec &DS); void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL); QualType GetTypeForDeclarator(Declarator &D, Scope *S); - QualType GetNonReferenceType(QualType Type); QualType ObjCGetTypeForMethodDefinition(DeclTy *D); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 3ead4308d2..9292017d67 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -450,7 +450,7 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc, } // If this reference is not in a block or if the referenced variable is // within the block, create a normal DeclRefExpr. - return new DeclRefExpr(VD, GetNonReferenceType(VD->getType()), Loc); + return new DeclRefExpr(VD, VD->getType().getNonReferenceType(), Loc); } Sema::ExprResult Sema::ActOnPredefinedExpr(SourceLocation Loc, diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 942d7063a1..f1edabfa7e 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -500,23 +500,6 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) { return T; } -/// GetNonReferenceType - If Type is a reference type (e.g., const -/// int&), returns the type that the reference refers to ("const -/// int"). Otherwise, returns the type itself. This routine is used -/// throughout to implement C++ 5p6: -/// -/// If an expression initially has the type "reference to T" (8.3.2, -/// 8.5.3), the type is adjusted to "T" prior to any further -/// analysis, the expression designates the object or function -/// denoted by the reference, and the expression is an lvalue. -QualType Sema::GetNonReferenceType(QualType Type) -{ - if (const ReferenceType *RefType = Type->getAsReferenceType()) - return RefType->getPointeeType(); - else - return Type; -} - /// ObjCGetTypeForMethodDefinition - Builds the type for a method definition /// declarator QualType Sema::ObjCGetTypeForMethodDefinition(DeclTy *D) {