+ *I = NewType; // Update to point to new, more refined type.
+}
+
+
+
+// parseTypeConstants - We have to use this wierd code to handle recursive
+// types. We know that recursive types will only reference the current slab of
+// values in the type plane, but they can forward reference types before they
+// have been read. For example, Type #0 might be '{ Ty#1 }' and Type #1 might
+// be 'Ty#0*'. When reading Type #0, type number one doesn't exist. To fix
+// this ugly problem, we pesimistically insert an opaque type for each type we
+// are about to read. This means that forward references will resolve to
+// something and when we reread the type later, we can replace the opaque type
+// with a new resolved concrete type.
+//
+bool BytecodeParser::parseTypeConstants(const uchar *&Buf, const uchar *EndBuf,
+ TypeValuesListTy &Tab,
+ unsigned NumEntries) {
+ assert(Tab.size() == 0 && "I think table should always be empty here!"
+ "This should simplify later code");
+
+ // Record the base, starting level that we will begin with.
+ unsigned BaseLevel = Tab.size();
+
+ // Insert a bunch of opaque types to be resolved later...
+ for (unsigned i = 0; i < NumEntries; i++)
+ Tab.push_back(PATypeHandle<Type>(OpaqueType::get(), this));
+
+ // Loop through reading all of the types. Forward types will make use of the
+ // opaque types just inserted.
+ //
+ for (unsigned i = 0; i < NumEntries; i++) {
+ const Type *NewTy = parseTypeConstant(Buf, EndBuf);
+ if (NewTy == 0) return failure(true);
+ BCR_TRACE(4, "Read Type Constant: '" << NewTy << "'\n");
+
+ // Don't insertValue the new type... instead we want to replace the opaque
+ // type with the new concrete value...
+ //
+
+ // Refine the abstract type to the new type. This causes all uses of the
+ // abstract type to use the newty. This also will cause the opaque type
+ // to be deleted...
+ //
+ // FIXME when types are not const
+ const_cast<DerivedType*>(Tab[i+BaseLevel]->castDerivedTypeAsserting())->refineAbstractTypeTo(NewTy);
+
+ // This should have replace the old opaque type with the new type in the
+ // value table...
+ assert(Tab[i+BaseLevel] == NewTy && "refineAbstractType didn't work!");
+ }
+
+ BCR_TRACE(5, "Resulting types:\n");
+ for (unsigned i = 0; i < NumEntries; i++) {
+ BCR_TRACE(5, Tab[i+BaseLevel]->castTypeAsserting() << "\n");
+ }