public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg) { int index; string tab = new string('\t', this.getAllParentsOf<Interfaces.iCodeBlock>().Count); if (this.encapsulation == Encapsulation.Static || this.IsConstructor) { var fqn = this.Name.FullyQualifiedName; var filePath = Wrapper.Compiler.ProjectFile.OutputFolder + fqn.Replace("::", "\\"); var fileFolderPath = filePath.Substring(0, filePath.LastIndexOf('\\')); if (!Directory.Exists(fileFolderPath)) Directory.CreateDirectory(fileFolderPath); sw = new System.IO.StreamWriter(filePath + ".sqf"); fqn = fqn.Replace("::", "_"); int lIndex = fqn.LastIndexOf('_'); string lPath; string rPath; if (lIndex <= 0) { lPath = "UNCATEGORIZED"; rPath = fqn; Logger.Instance.log(Logger.LogLevel.WARNING, "Function '" + this.Name.FullyQualifiedName + "' at line " + this.Name.Line + " has no namespace"); } else { lPath = fqn.Substring(0, lIndex); rPath = fqn.Substring(lIndex + 1); } cfg.setValue(lPath + '/' + "All" + '/' + rPath + '/' + "file", '"' + filePath.Substring(Wrapper.Compiler.ProjectFile.OutputFolder.Length) + ".sqf" + '"'); cfg.setValue(lPath + '/' + "All" + '/' + rPath + '/' + "preInit", this.Name.OriginalValue == "preInit" ? "1" : "0"); cfg.setValue(lPath + '/' + "All" + '/' + rPath + '/' + "postInit", this.Name.OriginalValue == "postInit" ? "1" : "0"); cfg.setValue(lPath + '/' + "All" + '/' + rPath + '/' + "preStart", this.Name.OriginalValue == "preStart" ? "1" : "0"); cfg.setValue(lPath + '/' + "All" + '/' + rPath + '/' + "recompile", "0"); cfg.setValue(lPath + '/' + "All" + '/' + rPath + '/' + "ext", '"' + ".sqf" + '"'); cfg.setValue(lPath + '/' + "All" + '/' + rPath + '/' + "headerType", "-1"); } sw.WriteLine(tab + "scopeName \"" + Wrapper.Compiler.ScopeNames.function + "\";"); var argList = this.ArgListObjects; if (argList.Count > 0) { sw.Write(tab + "params ["); bool printComma = false; if (this.encapsulation != Encapsulation.Static && !this.IsConstructor) { sw.Write('"' + Wrapper.Compiler.thisVariableName + '"'); printComma = true; } foreach(var it in argList) { if (printComma) sw.Write(", "); if (it is Variable) { sw.Write('"' + ((Variable)it).SqfVariableName + '"'); } else { throw new Exception(); } } sw.WriteLine("];"); } var localVarList = this.getAllChildrenOf<Variable>(false, null, -1, 1); if (localVarList.Count > 0) { if (localVarList.Count == 1) sw.Write(tab + "private "); else sw.Write(tab + "private ["); for (int i = 0; i < localVarList.Count; i++) { var it = localVarList[i]; if (i != 0) { sw.Write(", "); } if (it is Variable) { sw.Write('"' + ((Variable)it).SqfVariableName + '"'); } else { throw new Exception(); } } if (localVarList.Count > 1) sw.Write("]"); sw.WriteLine(";"); } if (this.IsConstructor) { ///////////////////////////////// // OBJECT CONSTRUCTOR PRINTING // ///////////////////////////////// var classObject = this.getFirstOf<oosClass>(); var varList = classObject.AllVariables; var fncList = classObject.AllFunctions; if (varList.Count > 0 || fncList.Count > 0) { sw.Write(tab + "private ["); index = 0; foreach (var it in varList) { if (index > 0) sw.Write(", "); sw.Write("\"" + Wrapper.Compiler.thisVariableName + "var" + it.Name.OriginalValue.Replace("::", "_") + "\""); index++; } foreach (var it in fncList) { if (((Function)it).IsConstructor) continue; if (index > 0) sw.Write(","); sw.Write("\"" + Wrapper.Compiler.thisVariableName + "fnc" + it.Name.OriginalValue.Replace("::", "_") + "\""); index++; } sw.WriteLine("];"); } foreach (var it in varList) { sw.Write(Wrapper.Compiler.thisVariableName + "var" + it.Name.OriginalValue.Replace("::", "_") + " = ["); var val = it.Value; if (val == null) sw.Write("nil"); else val.writeOut(sw, cfg); sw.WriteLine("];"); } foreach (var it in fncList) { if (((Function)it).IsConstructor) continue; sw.WriteLine(Wrapper.Compiler.thisVariableName + "fnc" + it.Name.OriginalValue.Replace("::", "_") + " = {"); it.writeOut(sw, cfg); sw.WriteLine("};"); } sw.Write(tab + Wrapper.Compiler.thisVariableName + " = ["); //Write out parents info var classIdents = classObject.ParentClassesIdents; classIdents.Add(classObject.Name); sw.Write("["); index = 0; foreach (var it in classIdents) { if (index > 0) sw.Write(", "); if (it is Ident) { index++; sw.Write('"' + ((Ident)it).FullyQualifiedName + '"'); } else { throw new Exception("please report to developer, unknown exception happened in function object creation"); } } sw.Write("],["); index = 0; foreach (var it in classIdents) { if (index > 0) sw.Write(","); if (it is Ident) { var refObj = ((Ident)it).ReferencedObject; if (refObj is oosClass) { index++; var cObj = (oosClass)refObj; int index2 = 0; //LookupRegister sw.Write("[["); foreach (var child in cObj.children) { if (index2 > 0) sw.Write(", "); if (child is Function) { if (((Function)child).IsClassFunction && !((Function)child).IsConstructor) sw.Write('"' + ((Function)child).Name.FullyQualifiedName + '"'); else sw.Write("nil"); } else if (child is VirtualFunction) { sw.Write('"' + ((VirtualFunction)child).Name.FullyQualifiedName + '"'); } else if (child is Variable) { if (((Variable)child).IsClassVariable) sw.Write('"' + ((Variable)child).Name.FullyQualifiedName + '"'); else sw.Write("nil"); } else { sw.Write("nil"); } index2++; } sw.Write("], ["); index2 = 0; foreach (var child in cObj.children) { if (index2 > 0) sw.Write(", "); if (child is Function) { if (((Function)child).IsClassFunction && !((Function)child).IsConstructor) sw.Write(Wrapper.Compiler.thisVariableName + "fnc" + ((Function)child).Name.OriginalValue.Replace("::", "_")); else sw.Write("nil"); } else if (child is VirtualFunction) { sw.Write(Wrapper.Compiler.thisVariableName + "var" + ((VirtualFunction)child).Name.OriginalValue.Replace("::", "_")); } else if (child is Variable) { if (((Variable)child).IsClassVariable) sw.Write(Wrapper.Compiler.thisVariableName + "var" + ((Variable)child).Name.OriginalValue.Replace("::", "_")); else sw.Write("nil"); } else { sw.Write("nil"); } index2++; } sw.Write("], ["); sw.Write('"' + ((Ident)it).FullyQualifiedName + '"'); sw.Write("]]"); } else if (refObj is oosInterface) { index++; sw.Write("nil"); } else { throw new Exception("please report to developer, unknown exception happened in function object creation cast refObj"); } } else { throw new Exception("Function has Encapsulation.NA on encapsulation field, please report to developer"); } } sw.Write("], "); //Current active class sw.Write("nil, "); //Reserved for future meta informations sw.Write("[]"); sw.WriteLine("];"); //ToDo: add baseconstructor calls sw.WriteLine("//Actual constructor starts here, we just printed the object till here :)"); } foreach (var it in this.CodeInstructions) { if (it is Ident) sw.Write(tab); it.writeOut(sw, cfg); sw.WriteLine(";"); } if (this.IsConstructor) { sw.Write(tab + Wrapper.Compiler.thisVariableName); } if (this.encapsulation == Encapsulation.Static || this.IsConstructor) { sw.Flush(); sw.Close(); } }