[llvm-commits] CVS: llvm/lib/VMCore/Type.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue Sep 2 16:57:01 PDT 2003
Changes in directory llvm/lib/VMCore:
Type.cpp updated: 1.55 -> 1.56
---
Log message:
Removal of explicit stack, which requires the method to be a member (so it can
call setAbstract). Now that we just compute abstractness we can also return
the computed value by value instead of as an argument.
---
Diffs of the changes:
Index: llvm/lib/VMCore/Type.cpp
diff -u llvm/lib/VMCore/Type.cpp:1.55 llvm/lib/VMCore/Type.cpp:1.56
--- llvm/lib/VMCore/Type.cpp:1.55 Tue Sep 2 16:41:05 2003
+++ llvm/lib/VMCore/Type.cpp Tue Sep 2 16:56:34 2003
@@ -385,37 +385,38 @@
// Derived Type setDerivedTypeProperties Function
//===----------------------------------------------------------------------===//
-// getTypeProps - This is a recursive function that walks a type hierarchy
-// calculating the description for a type and whether or not it is abstract or
-// recursive. Worst case it will have to do a lot of traversing if you have
-// some whacko opaque types, but in most cases, it will do some simple stuff
-// when it hits non-abstract types that aren't recursive.
+// isTypeAbstract - This is a recursive function that walks a type hierarchy
+// calculating whether or not a type is abstract. Worst case it will have to do
+// a lot of traversing if you have some whacko opaque types, but in most cases,
+// it will do some simple stuff when it hits non-abstract types that aren't
+// recursive.
//
-static void getTypeProps(const Type *Ty, std::vector<const Type *> &TypeStack,
- bool &isAbstract) {
- if (!Ty->isAbstract()) // Base case for the recursion
- return; // Primitive = leaf type
+bool Type::isTypeAbstract() {
+ if (!isAbstract()) // Base case for the recursion
+ return false; // Primitive = leaf type
- if (isa<OpaqueType>(Ty)) { // Base case for the recursion
- isAbstract = true; // This whole type is abstract!
- return; // Opaque = leaf type
- }
+ if (isa<OpaqueType>(this)) // Base case for the recursion
+ return true; // This whole type is abstract!
- // Check to see if the Type is already on the stack...
- for (unsigned Slot = 0; Slot != TypeStack.size(); ++Slot)
- if (TypeStack[Slot] == Ty) // Scan for type
- return; // is a recursive check.
-
- // Recursive case: derived type...
- TypeStack.push_back(Ty); // Add us to the stack..
+ // We have to guard against recursion. To do this, we temporarily mark this
+ // type as concrete, so that if we get back to here recursively we will think
+ // it's not abstract, and thus not scan it again.
+ setAbstract(false);
+
+ // Scan all of the sub-types. If any of them are abstract, than so is this
+ // one!
+ for (Type::subtype_iterator I = subtype_begin(), E = subtype_end();
+ I != E; ++I)
+ if (const_cast<Type*>(*I)->isTypeAbstract()) {
+ setAbstract(true);
+ return true;
+ }
+
+ // Restore the abstract bit.
+ setAbstract(true);
- for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
- I != E; ++I) {
- getTypeProps(*I, TypeStack, isAbstract);
- if (isAbstract) break;
- }
-
- TypeStack.pop_back(); // Remove self from stack...
+ // Nothing looks abstract here...
+ return false;
}
@@ -423,12 +424,8 @@
// setting for a type. The getTypeProps function does all the dirty work.
//
void DerivedType::setDerivedTypeProperties() {
- std::vector<const Type *> TypeStack;
- bool isAbstract = false;
-
setAbstract(true);
- getTypeProps(this, TypeStack, isAbstract);
- setAbstract(isAbstract);
+ setAbstract(isTypeAbstract());
}
More information about the llvm-commits
mailing list