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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8332 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2003-09-02 21:56:34 +00:00
parent 2a4a4b54ad
commit bc4846d76c

View File

@@ -385,37 +385,38 @@ OpaqueType::OpaqueType() : DerivedType(OpaqueTyID) {
// Derived Type setDerivedTypeProperties Function // Derived Type setDerivedTypeProperties Function
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// getTypeProps - This is a recursive function that walks a type hierarchy // isTypeAbstract - This is a recursive function that walks a type hierarchy
// calculating the description for a type and whether or not it is abstract or // calculating whether or not a type is abstract. Worst case it will have to do
// recursive. Worst case it will have to do a lot of traversing if you have // a lot of traversing if you have some whacko opaque types, but in most cases,
// some whacko opaque types, but in most cases, it will do some simple stuff // it will do some simple stuff when it hits non-abstract types that aren't
// when it hits non-abstract types that aren't recursive. // recursive.
// //
static void getTypeProps(const Type *Ty, std::vector<const Type *> &TypeStack, bool Type::isTypeAbstract() {
bool &isAbstract) { if (!isAbstract()) // Base case for the recursion
if (!Ty->isAbstract()) // Base case for the recursion return false; // Primitive = leaf type
return; // Primitive = leaf type
if (isa<OpaqueType>(Ty)) { // Base case for the recursion if (isa<OpaqueType>(this)) // Base case for the recursion
isAbstract = true; // This whole type is abstract! return true; // This whole type is abstract!
return; // Opaque = leaf type
}
// Check to see if the Type is already on the stack... // We have to guard against recursion. To do this, we temporarily mark this
for (unsigned Slot = 0; Slot != TypeStack.size(); ++Slot) // type as concrete, so that if we get back to here recursively we will think
if (TypeStack[Slot] == Ty) // Scan for type // it's not abstract, and thus not scan it again.
return; // is a recursive check. setAbstract(false);
// Recursive case: derived type... // Scan all of the sub-types. If any of them are abstract, than so is this
TypeStack.push_back(Ty); // Add us to the stack.. // 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(); // Nothing looks abstract here...
I != E; ++I) { return false;
getTypeProps(*I, TypeStack, isAbstract);
if (isAbstract) break;
}
TypeStack.pop_back(); // Remove self from stack...
} }
@@ -423,12 +424,8 @@ static void getTypeProps(const Type *Ty, std::vector<const Type *> &TypeStack,
// setting for a type. The getTypeProps function does all the dirty work. // setting for a type. The getTypeProps function does all the dirty work.
// //
void DerivedType::setDerivedTypeProperties() { void DerivedType::setDerivedTypeProperties() {
std::vector<const Type *> TypeStack;
bool isAbstract = false;
setAbstract(true); setAbstract(true);
getTypeProps(this, TypeStack, isAbstract); setAbstract(isTypeAbstract());
setAbstract(isAbstract);
} }