void FLuaScriptCodeGenerator::ExportClass(UClass* Class, const FString& SourceHeaderFilename, const FString& GeneratedHeaderFilename, bool bHasChanged) { if (!CanExportClass(Class)) { return; } UE_LOG(LogScriptGenerator, Log, TEXT("Exporting class %s"), *Class->GetName()); ExportedClasses.Add(Class->GetFName()); LuaExportedClasses.Add(Class); AllSourceClassHeaders.Add(SourceHeaderFilename); const FString ClassGlueFilename = GetScriptHeaderForClass(Class); AllScriptHeaders.Add(ClassGlueFilename); const FString ClassNameCPP = GetClassNameCPP(Class); FString GeneratedGlue(TEXT("#pragma once\r\n\r\n")); // Export all functions for (TFieldIterator<UFunction> FuncIt(Class /*, EFieldIteratorFlags::ExcludeSuper*/); FuncIt; ++FuncIt) { UFunction* Function = *FuncIt; if (CanExportFunction(ClassNameCPP, Class, Function)) { GeneratedGlue += ExportFunction(ClassNameCPP, Class, Function); } } // Export properties that are owned by this class int32 PropertyIndex = 0; for (TFieldIterator<UProperty> PropertyIt(Class /*, EFieldIteratorFlags::ExcludeSuper*/); PropertyIt; ++PropertyIt, ++PropertyIndex) { UProperty* Property = *PropertyIt; if (CanExportProperty(ClassNameCPP, Class, Property)) { UE_LOG(LogScriptGenerator, Log, TEXT(" %s %s"), *Property->GetClass()->GetName(), *Property->GetName()); GeneratedGlue += ExportProperty(ClassNameCPP, Class, Property, PropertyIndex); } } GeneratedGlue += ExportAdditionalClassGlue(ClassNameCPP, Class); SaveHeaderIfChanged(ClassGlueFilename, GeneratedGlue); }
void JSBTypeScript::ExportModuleClasses(const String& moduleName) { JSBModule* module = JSBindings::Instance()->GetModuleByName(moduleName); if (!module->classes_.Size()) return; source_ += "\n"; for (unsigned i = 0; i < module->classes_.Size(); i++) { JSBClass* klass = module->classes_.At(i); source_ += " export class " + klass->GetName(); if (klass->GetBaseClass()) source_ += " extends " + klass->GetBaseClass()->GetName(); source_ += " {\n\n"; Vector<String> propertyNames; klass->GetPropertyNames(propertyNames); for (unsigned j = 0; j < propertyNames.Size(); j++) { JSBProperty* prop = klass->GetProperty(propertyNames[j]); JSBFunctionType* ftype = NULL; if (prop->getter_ && !prop->getter_->Skip()) { ftype = prop->getter_->returnType_; } else if (prop->setter_ && !prop->setter_->Skip()) ftype = prop->setter_->parameters_[0]; if (!ftype) continue; String scriptType = GetScriptType(ftype); String scriptName = propertyNames[j]; scriptName[0] = tolower(scriptName[0]); source_ += " " + scriptName + ": " + scriptType + ";\n"; } if (propertyNames.Size()) source_ += "\n"; JSBFunction* constructor = klass->GetConstructor(); if (constructor) { ExportFunction(constructor); source_ += "\n"; } for (unsigned j = 0; j < klass->GetFunctionCount(); j++) { JSBFunction* func = klass->GetFunction(j); if (func->isConstructor_ || func->isDestructor_ || func->Skip()) continue; ExportFunction(func); } source_ += "\n }\n\n"; } source_ += "\n"; }
void JSBHaxe::ExportModuleClasses(JSBModule* module) { Vector<SharedPtr<JSBClass>> classes = module->GetClasses(); if (!classes.Size()) return; source_ += "\n"; for (unsigned i = 0; i < classes.Size(); i++) { JSBClass* klass = classes.At(i); if (klass->IsNumberArray()) { source_ += "typedef " + klass->GetName() + " = Array<Float>;\n"; continue; } source_ += "@:native(\"Atomic." + klass->GetName() + "\")\n"; source_ += "extern class " + klass->GetName(); JSBClass* base = klass->GetBaseClass(); if (base) { source_ += " extends " + base->GetName(); } source_ += " {\n\n"; Vector<String> propertyNames; klass->GetPropertyNames(propertyNames); for (unsigned j = 0; j < propertyNames.Size(); j++) { JSBProperty* prop = klass->GetProperty(propertyNames[j]); JSBFunctionType* ftype = NULL; if (prop->getter_ && !prop->getter_->Skip()) { ftype = prop->getter_->GetReturnType(); } else if (prop->setter_ && !prop->setter_->Skip()) ftype = prop->setter_->GetParameters()[0]; if (!ftype) continue; String scriptType = GetScriptType(ftype); String scriptName = prop->GetCasePropertyName(); if (!checkV(klass, scriptName, scriptType)) { //rename haxe reserved words if (scriptName == "override") { scriptName = "overide"; } if (scriptName == "dynamic") { scriptName = "dynamik"; } source_ += " var " + scriptName + ": " + scriptType + ";\n"; } } if (propertyNames.Size()) source_ += "\n"; JSBFunction* constructor = klass->GetConstructor(); if (constructor) { ExportFunction(constructor); source_ += "\n"; } PODVector<JSBFunction*>& functions = klass->GetFunctions(); for (unsigned j = 0; j < functions.Size(); j++) { JSBFunction* func = functions[j]; if (func->IsConstructor() || func->IsDestructor() || func->Skip()) continue; ExportFunction(func); } for (unsigned j = 0; j < klass->GetNumHaxeDecl(); j++) { source_ += " " + klass->GetHaxeDecl(j) + "\n"; } source_ += "\n}\n\n"; } source_ += "\n"; }
void JSBTypeScript::ExportModuleClasses(JSBModule* module) { Vector<SharedPtr<JSBClass>> classes = module->GetClasses(); if (!classes.Size()) return; source_ += "\n"; for (unsigned i = 0; i < classes.Size(); i++) { JSBClass* klass = classes.At(i); source_ += " export class " + klass->GetName(); JSBClass* base = klass->GetBaseClass(); if (base) { if (klass->GetPackage() != base->GetPackage()) { source_ += " extends " + base->GetPackage()->GetName() + "." + base->GetName(); } else { source_ += " extends " + base->GetName(); } } source_ += " {\n\n"; Vector<String> propertyNames; klass->GetPropertyNames(propertyNames); for (unsigned j = 0; j < propertyNames.Size(); j++) { JSBProperty* prop = klass->GetProperty(propertyNames[j]); JSBFunctionType* ftype = NULL; if (prop->getter_ && !prop->getter_->Skip()) { ftype = prop->getter_->GetReturnType(); } else if (prop->setter_ && !prop->setter_->Skip()) ftype = prop->setter_->GetParameters()[0]; if (!ftype) continue; String scriptType = GetScriptType(ftype); String scriptName = prop->GetCasePropertyName(); source_ += " " + scriptName + ": " + scriptType + ";\n"; } if (propertyNames.Size()) source_ += "\n"; JSBFunction* constructor = klass->GetConstructor(); if (constructor) { ExportFunction(constructor); source_ += "\n"; } PODVector<JSBFunction*>& functions = klass->GetFunctions(); for (unsigned j = 0; j < functions.Size(); j++) { JSBFunction* func = functions[j]; if (func->IsConstructor() || func->IsDestructor() || func->Skip()) continue; ExportFunction(func); } for (unsigned j = 0; j < klass->GetNumTypeScriptDecl(); j++) { source_ += " " + klass->GetTypeScriptDecl(j) + "\n"; } source_ += "\n }\n\n"; } source_ += "\n"; }
returnValue DiscreteTimeExport::setup( ) { int useOMP; get(CG_USE_OPENMP, useOMP); ExportStruct structWspace; structWspace = useOMP ? ACADO_LOCAL : ACADO_WORKSPACE; // non equidistant integration grids not implemented for NARX integrators if( !equidistant ) return ACADOERROR( RET_INVALID_OPTION ); String fileName( "integrator.c" ); int printLevel; get( PRINTLEVEL,printLevel ); if ( (PrintLevel)printLevel >= HIGH ) acadoPrintf( "--> Preparing to export %s... ",fileName.getName() ); ExportIndex run( "run" ); ExportIndex i( "i" ); ExportIndex j( "j" ); ExportIndex k( "k" ); ExportIndex tmp_index("tmp_index"); uint diffsDim = NX*(NX+NU); uint inputDim = NX*(NX+NU+1) + NU + NP; // setup INTEGRATE function rk_index = ExportVariable( "rk_index", 1, 1, INT, ACADO_LOCAL, BT_TRUE ); rk_eta = ExportVariable( "rk_eta", 1, inputDim, REAL ); if( equidistantControlGrid() ) { integrate = ExportFunction( "integrate", rk_eta, reset_int ); } else { integrate = ExportFunction( "integrate", rk_eta, reset_int, rk_index ); } integrate.setReturnValue( error_code ); integrate.addIndex( run ); integrate.addIndex( i ); integrate.addIndex( j ); integrate.addIndex( k ); integrate.addIndex( tmp_index ); rhs_in = ExportVariable( "x", inputDim-diffsDim, 1, REAL, ACADO_LOCAL ); rhs_out = ExportVariable( "f", NX, 1, REAL, ACADO_LOCAL ); fullRhs = ExportFunction( "full_rhs", rhs_in, rhs_out ); rk_xxx = ExportVariable( "rk_xxx", 1, inputDim-diffsDim, REAL, structWspace ); if( grid.getNumIntervals() > 1 || !equidistantControlGrid() ) { rk_diffsPrev1 = ExportVariable( "rk_diffsPrev1", NX1, NX1+NU, REAL, structWspace ); rk_diffsPrev2 = ExportVariable( "rk_diffsPrev2", NX2, NX1+NX2+NU, REAL, structWspace ); } rk_diffsNew1 = ExportVariable( "rk_diffsNew1", NX1, NX1+NU, REAL, structWspace ); rk_diffsNew2 = ExportVariable( "rk_diffsNew2", NX2, NX1+NX2+NU, REAL, structWspace ); ExportVariable numInt( "numInts", 1, 1, INT ); if( !equidistantControlGrid() ) { ExportVariable numStepsV( "numSteps", numSteps, STATIC_CONST_INT ); integrate.addStatement( String( "int " ) << numInt.getName() << " = " << numStepsV.getName() << "[" << rk_index.getName() << "];\n" ); } integrate.addStatement( rk_xxx.getCols( NX,inputDim-diffsDim ) == rk_eta.getCols( NX+diffsDim,inputDim ) ); integrate.addLinebreak( ); // integrator loop: ExportForLoop tmpLoop( run, 0, grid.getNumIntervals() ); ExportStatementBlock *loop; if( equidistantControlGrid() ) { loop = &tmpLoop; } else { loop = &integrate; loop->addStatement( String("for(") << run.getName() << " = 0; " << run.getName() << " < " << numInt.getName() << "; " << run.getName() << "++ ) {\n" ); } loop->addStatement( rk_xxx.getCols( 0,NX ) == rk_eta.getCols( 0,NX ) ); if( grid.getNumIntervals() > 1 || !equidistantControlGrid() ) { // Set rk_diffsPrev: loop->addStatement( String("if( run > 0 ) {\n") ); if( NX1 > 0 ) { ExportForLoop loopTemp1( i,0,NX1 ); loopTemp1.addStatement( rk_diffsPrev1.getSubMatrix( i,i+1,0,NX1 ) == rk_eta.getCols( i*NX+NX+NXA,i*NX+NX+NXA+NX1 ) ); if( NU > 0 ) loopTemp1.addStatement( rk_diffsPrev1.getSubMatrix( i,i+1,NX1,NX1+NU ) == rk_eta.getCols( i*NU+(NX+NXA)*(NX+1),i*NU+(NX+NXA)*(NX+1)+NU ) ); loop->addStatement( loopTemp1 ); } if( NX2 > 0 ) { ExportForLoop loopTemp2( i,0,NX2 ); loopTemp2.addStatement( rk_diffsPrev2.getSubMatrix( i,i+1,0,NX1+NX2 ) == rk_eta.getCols( i*NX+NX+NXA+NX1*NX,i*NX+NX+NXA+NX1*NX+NX1+NX2 ) ); if( NU > 0 ) loopTemp2.addStatement( rk_diffsPrev2.getSubMatrix( i,i+1,NX1+NX2,NX1+NX2+NU ) == rk_eta.getCols( i*NU+(NX+NXA)*(NX+1)+NX1*NU,i*NU+(NX+NXA)*(NX+1)+NX1*NU+NU ) ); loop->addStatement( loopTemp2 ); } loop->addStatement( String("}\n") ); } // evaluate states: if( NX1 > 0 ) { loop->addFunctionCall( lin_input.getName(), rk_xxx, rk_eta.getAddress(0,0) ); } if( NX2 > 0 ) { loop->addFunctionCall( getNameRHS(), rk_xxx, rk_eta.getAddress(0,NX1) ); } // evaluate sensitivities: if( NX1 > 0 ) { for( uint i1 = 0; i1 < NX1; i1++ ) { for( uint i2 = 0; i2 < NX1; i2++ ) { loop->addStatement( rk_diffsNew1.getSubMatrix(i1,i1+1,i2,i2+1) == A11(i1,i2) ); } for( uint i2 = 0; i2 < NU; i2++ ) { loop->addStatement( rk_diffsNew1.getSubMatrix(i1,i1+1,NX1+i2,NX1+i2+1) == B11(i1,i2) ); } } } if( NX2 > 0 ) { loop->addFunctionCall( getNameDiffsRHS(), rk_xxx, rk_diffsNew2.getAddress(0,0) ); } // computation of the sensitivities using chain rule: if( grid.getNumIntervals() > 1 || !equidistantControlGrid() ) { loop->addStatement( String( "if( run == 0 ) {\n" ) ); } // PART 1 updateInputSystem(loop, i, j, tmp_index); // PART 2 updateImplicitSystem(loop, i, j, tmp_index); if( grid.getNumIntervals() > 1 || !equidistantControlGrid() ) { loop->addStatement( String( "}\n" ) ); loop->addStatement( String( "else {\n" ) ); // PART 1 propagateInputSystem(loop, i, j, k, tmp_index); // PART 2 propagateImplicitSystem(loop, i, j, k, tmp_index); loop->addStatement( String( "}\n" ) ); } // end of the integrator loop. if( !equidistantControlGrid() ) { loop->addStatement( "}\n" ); } else { integrate.addStatement( *loop ); } // PART 1 if( NX1 > 0 ) { Matrix zeroR = zeros(1, NX2); ExportForLoop loop1( i,0,NX1 ); loop1.addStatement( rk_eta.getCols( i*NX+NX+NXA+NX1,i*NX+NX+NXA+NX ) == zeroR ); integrate.addStatement( loop1 ); } if ( (PrintLevel)printLevel >= HIGH ) acadoPrintf( "done.\n" ); return SUCCESSFUL_RETURN; }