]> granicus.if.org Git - clang/commitdiff
add getAsComplexType() for consistency
authorChris Lattner <sabre@nondot.org>
Tue, 21 Aug 2007 16:54:08 +0000 (16:54 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 21 Aug 2007 16:54:08 +0000 (16:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41229 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Type.cpp
include/clang/AST/Type.h

index dca9404dc96a3ea19fb288046cc85e1171cb5c3e..65ba90a75d9c69b038a7f6efbe74891492ef1425 100644 (file)
@@ -71,6 +71,10 @@ bool Type::isUnionType() const {
   return false;
 }
 
+bool Type::isComplexType() const {
+  return isa<ComplexType>(CanonicalType);
+}
+
 const FunctionType *Type::getAsFunctionType() const {
   // If this is directly a function type, return it.
   if (const FunctionType *FTy = dyn_cast<FunctionType>(this))
@@ -161,8 +165,17 @@ const RecordType *Type::getAsUnionType() const {
   return 0;
 }
 
-bool Type::isComplexType() const {
-  return isa<ComplexType>(CanonicalType);
+const ComplexType *Type::getAsComplexType() const {
+  // Are we directly a complex type?
+  if (const ComplexType *CTy = dyn_cast<ComplexType>(this))
+    return CTy;
+  
+  // If this is a typedef for a complex type, strip the typedef off without
+  // losing all typedef information.
+  if (isa<ComplexType>(CanonicalType))
+    return cast<ComplexType>(cast<TypedefType>(this)->LookThroughTypedefs());
+  
+  return 0;
 }
 
 const VectorType *Type::getAsVectorType() const {
index 5b22a4249403007b65bafeff15ba466acab5c1e2..de5e48ee2ccdb81b70c64d8f01c732fcaf624ccf 100644 (file)
@@ -37,6 +37,7 @@ namespace clang {
   class VectorType;
   class ArrayType;
   class RecordType;
+  class ComplexType;
   class TagType;
   class FunctionType;
   class OCUVectorType;
@@ -269,6 +270,7 @@ public:
   const RecordType *getAsStructureType() const;   
   const RecordType *getAsUnionType() const;
   const VectorType *getAsVectorType() const; // GCC vector type.
+  const ComplexType *getAsComplexType() const;
   const OCUVectorType *getAsOCUVectorType() const; // OCU vector type.
   
   /// More type predicates useful for type checking/promotion