int asCRestore::Restore() { // Before starting the load, make sure that // any existing resources have been freed module->InternalReset(); unsigned long i, count; asCScriptFunction* func; // Read enums READ_NUM(count); module->enumTypes.Allocate(count, 0); for( i = 0; i < count; i++ ) { asCObjectType *ot = asNEW(asCObjectType)(engine); ReadObjectTypeDeclaration(ot, false); engine->classTypes.PushLast(ot); module->enumTypes.PushLast(ot); ot->AddRef(); ReadObjectTypeDeclaration(ot, true); } // structTypes[] // First restore the structure names, then the properties READ_NUM(count); module->classTypes.Allocate(count, 0); for( i = 0; i < count; ++i ) { asCObjectType *ot = asNEW(asCObjectType)(engine); ReadObjectTypeDeclaration(ot, false); engine->classTypes.PushLast(ot); module->classTypes.PushLast(ot); ot->AddRef(); // Add script classes to the GC if( (ot->GetFlags() & asOBJ_SCRIPT_OBJECT) && ot->GetSize() > 0 ) engine->gc.AddScriptObjectToGC(ot, &engine->objectTypeBehaviours); } // Read interface methods for( i = 0; i < module->classTypes.GetLength(); i++ ) { if( module->classTypes[i]->IsInterface() ) ReadObjectTypeDeclaration(module->classTypes[i], true); } module->ResolveInterfaceIds(); // Read class methods, properties, and behaviours for( i = 0; i < module->classTypes.GetLength(); ++i ) { if( !module->classTypes[i]->IsInterface() ) ReadObjectTypeDeclaration(module->classTypes[i], true); } // Read typedefs READ_NUM(count); module->typeDefs.Allocate(count, 0); for( i = 0; i < count; i++ ) { asCObjectType *ot = asNEW(asCObjectType)(engine); ReadObjectTypeDeclaration(ot, false); engine->classTypes.PushLast(ot); module->typeDefs.PushLast(ot); ot->AddRef(); ReadObjectTypeDeclaration(ot, true); } // scriptGlobals[] READ_NUM(count); module->scriptGlobals.Allocate(count, 0); for( i = 0; i < count; ++i ) { ReadGlobalProperty(); } // scriptFunctions[] READ_NUM(count); for( i = 0; i < count; ++i ) { func = ReadFunction(); } // globalFunctions[] READ_NUM(count); for( i = 0; i < count; ++i ) { func = ReadFunction(false, false); module->globalFunctions.PushLast(func); func->AddRef(); } // bindInformations[] READ_NUM(count); module->bindInformations.SetLength(count); for(i=0;i<count;++i) { sBindInfo *info = asNEW(sBindInfo); info->importedFunctionSignature = ReadFunction(false, false); info->importedFunctionSignature->id = int(FUNC_IMPORTED + engine->importedFunctions.GetLength()); engine->importedFunctions.PushLast(info); ReadString(&info->importFromModule); info->boundFunctionId = -1; module->bindInformations[i] = info; } // usedTypes[] READ_NUM(count); usedTypes.Allocate(count, 0); for( i = 0; i < count; ++i ) { asCObjectType *ot = ReadObjectType(); usedTypes.PushLast(ot); } // usedTypeIds[] ReadUsedTypeIds(); // usedFunctions[] ReadUsedFunctions(); // usedGlobalProperties[] ReadUsedGlobalProps(); // usedStringConstants[] ReadUsedStringConstants(); for( i = 0; i < module->scriptFunctions.GetLength(); i++ ) TranslateFunction(module->scriptFunctions[i]); for( i = 0; i < module->scriptGlobals.GetLength(); i++ ) if( module->scriptGlobals[i]->initFunc ) TranslateFunction(module->scriptGlobals[i]->initFunc); // Init system functions properly engine->PrepareEngine(); // Add references for all functions for( i = 0; i < module->scriptFunctions.GetLength(); i++ ) module->scriptFunctions[i]->AddReferences(); for( i = 0; i < module->scriptGlobals.GetLength(); i++ ) if( module->scriptGlobals[i]->initFunc ) module->scriptGlobals[i]->initFunc->AddReferences(); module->CallInit(); return 0; }
int asCRestore::Restore() { // Before starting the load, make sure that // any existing resources have been freed module->InternalReset(); unsigned long i, count; asCScriptFunction* func; asCString *cstr; // Read enums READ_NUM(count); module->enumTypes.Allocate(count, 0); for( i = 0; i < count; i++ ) { asCObjectType *ot = asNEW(asCObjectType)(engine); ReadObjectTypeDeclaration(ot, false); engine->classTypes.PushLast(ot); module->enumTypes.PushLast(ot); ot->AddRef(); ReadObjectTypeDeclaration(ot, true); } // structTypes[] // First restore the structure names, then the properties READ_NUM(count); module->classTypes.Allocate(count, 0); for( i = 0; i < count; ++i ) { asCObjectType *ot = asNEW(asCObjectType)(engine); ReadObjectTypeDeclaration(ot, false); engine->classTypes.PushLast(ot); module->classTypes.PushLast(ot); ot->AddRef(); } // Read interface methods for( i = 0; i < module->classTypes.GetLength(); i++ ) { if( module->classTypes[i]->IsInterface() ) ReadObjectTypeDeclaration(module->classTypes[i], true); } module->ResolveInterfaceIds(); // Read class methods, properties, and behaviours for( i = 0; i < module->classTypes.GetLength(); ++i ) { if( !module->classTypes[i]->IsInterface() ) ReadObjectTypeDeclaration(module->classTypes[i], true); } // Read typedefs READ_NUM(count); module->typeDefs.Allocate(count, 0); for( i = 0; i < count; i++ ) { asCObjectType *ot = asNEW(asCObjectType)(engine); ReadObjectTypeDeclaration(ot, false); engine->classTypes.PushLast(ot); module->typeDefs.PushLast(ot); ot->AddRef(); ReadObjectTypeDeclaration(ot, true); } // scriptGlobals[] READ_NUM(count); module->scriptGlobals.Allocate(count, 0); for( i = 0; i < count; ++i ) { ReadGlobalProperty(); } // globalVarPointers[] ReadGlobalVarPointers(); // scriptFunctions[] READ_NUM(count); for( i = 0; i < count; ++i ) { func = ReadFunction(); } // globalFunctions[] READ_NUM(count); for( i = 0; i < count; ++i ) { func = ReadFunction(false, false); module->globalFunctions.PushLast(func); } // initFunction READ_NUM(count); if( count ) { module->initFunction = ReadFunction(false, true); } // stringConstants[] READ_NUM(count); module->stringConstants.Allocate(count, 0); for( i = 0; i < count; ++i ) { cstr = asNEW(asCString)(); ReadString(cstr); module->stringConstants.PushLast(cstr); } // importedFunctions[] and bindInformations[] READ_NUM(count); module->importedFunctions.Allocate(count, 0); module->bindInformations.SetLength(count); for(i=0;i<count;++i) { func = ReadFunction(false, false); module->importedFunctions.PushLast(func); sBindInfo *info = asNEW(sBindInfo); ReadString(&info->importFromModule); info->importedFunction = -1; module->bindInformations[i] = info; } // usedTypes[] READ_NUM(count); usedTypes.Allocate(count, 0); for( i = 0; i < count; ++i ) { asCObjectType *ot = ReadObjectType(); usedTypes.PushLast(ot); } // usedTypeIds[] ReadUsedTypeIds(); // usedFunctions[] ReadUsedFunctions(); // usedGlobalProperties[] ReadUsedGlobalProps(); // TODO: global: The module won't have a globalVarPointers anymore, instead each script // function has its own array so this should be moved into TranslateFunction // Translate the module->globalVarPointers for( i = 0; i < module->globalVarPointers.GetLength(); i++ ) { module->globalVarPointers[i] = usedGlobalProperties[(int)(size_t)module->globalVarPointers[i]]; } if( module->initFunction ) TranslateFunction(module->initFunction); for( i = 0; i < module->scriptFunctions.GetLength(); i++ ) TranslateFunction(module->scriptFunctions[i]); // Fake building module->isBuildWithoutErrors = true; // Init system functions properly engine->PrepareEngine(); // Add references for all functions if( module->initFunction ) module->initFunction->AddReferences(); for( i = 0; i < module->scriptFunctions.GetLength(); i++ ) { module->scriptFunctions[i]->AddReferences(); } module->CallInit(); return 0; }