Ejemplo n.º 1
0
Archivo: VTable.cpp Proyecto: bsdf/trx
    VTable* VTable::newParameterizedVTable(Traits* param_traits, Stringp fullname)
    {
        Toplevel* toplevel = this->toplevel();
        AvmCore* core = toplevel->core();
        Namespacep traitsNs = this->traits->ns();

        GCRef<builtinClassManifest> builtinClasses = toplevel->builtinClasses();
        GCRef<ObjectVectorClass> vectorobj_cls = builtinClasses->get_Vector_objectClass();
        GCRef<ScopeChain> vectorobj_cscope = vectorobj_cls->vtable->init->scope();
        GCRef<ScopeChain> vectorobj_iscope = vectorobj_cls->ivtable()->init->scope();
        VTable* objVecVTable = vectorobj_cls->vtable;
        AbcEnv* objVecAbcEnv = vectorobj_cscope->abcEnv();
        Toplevel* objVecToplevel = objVecVTable->toplevel();
        VTable* objVecIVTable = objVecVTable->ivtable;

        // these cases should all be filtered out by the caller;
        // we only want to handle Vector<SomeObject> here
        AvmAssert(param_traits != NULL &&
                    param_traits != toplevel->intClass()->vtable->traits->itraits &&
                    param_traits != toplevel->uintClass()->vtable->traits->itraits &&
                    param_traits != toplevel->numberClass()->vtable->traits->itraits);

        PoolObject* traitsPool = this->traits->pool;

        Stringp classname = core->internString(fullname->appendLatin1("$"));
        Traits* ctraits = core->domainMgr()->findTraitsInPoolByNameAndNS(traitsPool, classname, traitsNs);
        Traits* itraits;
        if (!ctraits)
        {
            // important: base the new ctraits on objVecVTable->traits, *not* this->traits;
            // we want the result to be based off ObjectVectorClass, not VectorClass
            // (otherwise sizeofInstance would be too small and we'd be crashy)
            ctraits = objVecVTable->traits->newParameterizedCTraits(classname, traitsNs);
            ctraits->verifyBindings(toplevel);

            itraits = traitsPool->resolveParameterizedType(toplevel, this->ivtable->traits, param_traits);
            ctraits->itraits = itraits;
        }
        else
        {
            itraits = ctraits->itraits;
        }

        AvmAssert(itraits != NULL);

        VTable* class_ivtable = builtinClasses->get_ClassClass()->ivtable();

        VTable* cvtab = core->newVTable(ctraits, class_ivtable, objVecToplevel);
        ScopeChain* cvtab_cscope = vectorobj_cscope->cloneWithNewVTable(core->GetGC(), cvtab, objVecAbcEnv);

        VTable* ivtab = core->newVTable(itraits, objVecIVTable, objVecToplevel);
        ScopeChain* ivtab_iscope = vectorobj_iscope->cloneWithNewVTable(core->GetGC(), ivtab, objVecAbcEnv);
        cvtab->ivtable = ivtab;
        ivtab->init = objVecIVTable->init;

        cvtab->resolveSignatures(cvtab_cscope);
        ivtab->resolveSignatures(ivtab_iscope);

        return cvtab;
    }
Ejemplo n.º 2
0
    ClassClosure *SamplerScript::getType(Toplevel* ss_toplevel, SamplerObjectType sot, const void *ptr)
    {
        Toplevel* tl;

        switch (sotGetKind(sot))
        {
            case kSOT_String:
            {
                // toplevel can be null here if there was no CodeContext active
                // when the sample was taken (ie, string was allocated from C++ code).
                // in that case, use the TL from the SamplerScript itself... it isn't
                // technically the right one to use, but is adequate for our purposes here
                // (it will return a stringClass or namespaceClass that will be valid
                // for the sampler)
                tl = sotGetToplevel(sot);
                if (!tl) tl = ss_toplevel;
                return tl->stringClass();
            }
            case kSOT_Namespace:
            {
                tl = sotGetToplevel(sot);
                if (!tl) tl = ss_toplevel;
                return tl->namespaceClass();
            }
            default:
                AvmAssert(0);
            case kSOT_Object:
                break;
        }

        VTable* vt = sotGetVTable(sot);
        tl = vt->toplevel();
        AvmCore* core = tl->core();

        ClassClosure *type;
        ScriptObject* obj = (ScriptObject*)ptr;
        if (obj && AvmCore::istype(obj->atom(), core->traits.class_itraits))
        {
            type = tl->classClass();
        }
        else if (obj && AvmCore::istype(obj->atom(), core->traits.function_itraits))
        {
            type = tl->functionClass();
        }
        else if (obj && obj->traits()->isActivationTraits())
        {
            type = tl->objectClass;
        }
        else
        {
            // fallback answer
            type = tl->objectClass;

            // note that note all types will have an init method,
            // so those types may get reported as "objectClass" rather
            // than something more specific. However, it's not clear
            // that the Sampler ever really cared about reporting those
            // objects well in the first place (eg activation or catch objects),
            // so it doesn't seem we're a lot worse off than before.
            ScopeChain* sc = NULL;
            if (vt->init)
                sc = vt->init->scope();

            if (sc && sc->getSize() <= 1)
            {
                if(sc->getSize() == 1)
                    type = tl->classClass();
            }
            else if (sc)
            {
                Atom ccAtom = sc->getScope(sc->getSize()-1);
                if(AvmCore::isObject(ccAtom))
                {
                    type = (ClassClosure*) AvmCore::atomToScriptObject(ccAtom);
                    if(!AvmCore::istype(type->atom(), core->traits.class_itraits))
                    {
                        // obj is a ClassClosure
                        type = tl->classClass();
                    }
                }
            }
        }
        AvmAssert(AvmCore::istype(type->atom(), core->traits.class_itraits));
        return type;
    }