[cfe-commits] r57951 - in /cfe/trunk: include/clang/AST/Type.h lib/Sema/Sema.h lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp

Douglas Gregor doug.gregor at gmail.com
Tue Oct 21 21:14:45 PDT 2008


Author: dgregor
Date: Tue Oct 21 23:14:44 2008
New Revision: 57951

URL: http://llvm.org/viewvc/llvm-project?rev=57951&view=rev
Log:
Move Sema::GetNonReferenceType to QualType::getNonReferenceType and make it inline

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

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

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Oct 21 23:14:44 2008
@@ -158,28 +158,11 @@
     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 @@
   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<TypedefType>(this);
 }

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=57951&r1=57950&r2=57951&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Oct 21 23:14:44 2008
@@ -259,7 +259,6 @@
   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);
 

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Oct 21 23:14:44 2008
@@ -450,7 +450,7 @@
   }
   // 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,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Oct 21 23:14:44 2008
@@ -500,23 +500,6 @@
   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) {





More information about the cfe-commits mailing list