public void GenerateBindingList(List <TypeBindingInfo> orderedTypes) { this.cs.enabled = (typeBindingFlags & TypeBindingFlags.BindingCode) != 0; this.tsDeclare.enabled = (typeBindingFlags & TypeBindingFlags.TypeDefinition) != 0; using (new PlatformCodeGen(this, TypeBindingFlags.Default)) { using (new TopLevelCodeGen(this, CodeGenerator.NameOfBindingList)) { using (new NamespaceCodeGen(this, typeof(Values).Namespace)) { using (new PreservedCodeGen(this)) { using (new PlainClassCodeGen(this, typeof(Values).Name)) { using (new PreservedCodeGen(this)) { this.cs.AppendLine("public const uint CodeGenVersion = {0};", ScriptEngine.VERSION); } using (new PreservedCodeGen(this)) { using (var method = new PlainMethodCodeGen(this, "private static void BindAll(TypeRegister register)")) { var editorTypes = new List <TypeBindingInfo>(); foreach (var type in orderedTypes) { if (type.genBindingCode) { if (type.isEditorRuntime) { editorTypes.Add(type); } else { method.AddStatement("{0}.{1}.Bind(register);", this.bindingManager.prefs.ns, type.csBindingName); } } } using (new EditorOnlyCodeGen(this)) { foreach (var editorType in editorTypes) { method.AddStatement("{0}.{1}.Bind(register);", this.bindingManager.prefs.ns, editorType.csBindingName); } } method.AddStatement("{0}.{1}.Bind(register);", this.bindingManager.prefs.ns, CodeGenerator.NameOfDelegates); } } } } } } } }
public void GenerateBindingList(List <TypeBindingInfo> orderedTypes) { this.cs.enabled = (typeBindingFlags & TypeBindingFlags.BindingCode) != 0; this.tsDeclare.enabled = (typeBindingFlags & TypeBindingFlags.TypeDefinition) != 0; using (new CSDebugCodeGen(this)) { using (new CSPlatformCodeGen(this, TypeBindingFlags.Default)) { using (new CSTopLevelCodeGen(this, CodeGenerator.NameOfBindingList)) { using (new CSNamespaceCodeGen(this, typeof(Values).Namespace)) { using (new PreservedCodeGen(this)) { using (new PlainClassCodeGen(this, typeof(Values).Name)) { using (new PreservedCodeGen(this)) { this.cs.AppendLine("public const uint CodeGenVersion = {0};", ScriptEngine.VERSION); } using (new PreservedCodeGen(this)) { using (var method = new PlainMethodCodeGen(this, "private static void BindAll(ScriptRuntime runtime)")) { var modules = from t in orderedTypes where t.genBindingCode orderby t.tsTypeNaming.jsDepth group t by t.tsTypeNaming.jsModule; foreach (var module in modules) { var moduleName = string.IsNullOrEmpty(module.Key) ? this.bindingManager.prefs.defaultJSModule : module.Key; if (module.Count() > 0) { var runtimeVarName = "rt"; var moduleVarName = "module"; this.cs.AppendLine($"runtime.AddStaticModuleProxy(\"{moduleName}\", ({runtimeVarName}, {moduleVarName}) => "); using (this.cs.TailCallCodeBlockScope()) { var editorTypesMap = new Dictionary <string, List <TypeBindingInfo> >(); foreach (var type in module) { if (type.requiredDefines.Count != 0) { var defs = string.Join(" && ", from def in type.requiredDefines select def); List <TypeBindingInfo> list; if (!editorTypesMap.TryGetValue(defs, out list)) { editorTypesMap[defs] = list = new List <TypeBindingInfo>(); } list.Add(type); } else { method.AddModuleEntry(runtimeVarName, moduleVarName, type); } } foreach (var editorTypes in editorTypesMap) { using (new EditorOnlyCodeGen(this, editorTypes.Key)) { foreach (var type in editorTypes.Value) { method.AddModuleEntry(runtimeVarName, moduleVarName, type); } } } } } } method.AddStatement("{0}.{1}.Bind(runtime);", this.bindingManager.prefs.ns, CodeGenerator.NameOfDelegates); } // func: BindAll } // 'preserved' attribute for func: BindAll } // class } // preserved } // cs-namespace } // toplevel } // platform } // debug }