コード例 #1
0
 public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
 {
     foreach (var it in this.children)
     {
         it.writeOut(sw, cfg);
     }
 }
コード例 #2
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            //ToDo: Fix the wrong private of the forArg1 variable from inside of the loop to parent codeblock
            string tab = new string('\t', this.Parent.getAllParentsOf <Interfaces.iCodeBlock>().Count);

            if (this.forArg1 != null)
            {
                this.forArg1.writeOut(sw, cfg);
                sw.WriteLine(";");
            }
            sw.Write(tab + "while {");
            if (this.forArg2 != null)
            {
                this.forArg2.writeOut(sw, cfg);
            }
            else
            {
                sw.Write("true");
            }
            sw.WriteLine("} do");
            sw.WriteLine(tab + "{");
            HelperClasses.PrintCodeHelpers.printPrivateArray(this, tab, sw, cfg, 0);
            if (this.getAllChildrenOf <Break>(true).Count > 0)
            {
                sw.WriteLine(tab + '\t' + "scopeName \"" + this.BreakScope + "\";");
            }
            HelperClasses.PrintCodeHelpers.printCodeLines(this.CodeInstructions, tab, sw, cfg);
            if (this.forArg3 != null)
            {
                this.forArg3.writeOut(sw, cfg);
            }
            sw.WriteLine(";");
            sw.Write(tab + "}");
        }
コード例 #3
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string tab      = new string('\t', this.Parent.getAllParentsOf <Interfaces.iCodeBlock>().Count);
            var    caseList = this.Cases;

            if (caseList.Count == 0)
            {
                sw.WriteLine(tab + "default {");
            }
            else
            {
                foreach (var it in caseList)
                {
                    sw.Write(tab + "case ");
                    it.writeOut(sw, cfg);
                    sw.Write(":");
                }
                sw.WriteLine("{");
            }
            HelperClasses.PrintCodeHelpers.printPrivateArray(this, tab, sw, cfg);
            HelperClasses.PrintCodeHelpers.printCodeLines(this.CodeInstructions.GetRange(0, this.CodeInstructions.Count - 1), tab, sw, cfg);
            var lastInstruction = CodeInstructions.Last();

            if (!(lastInstruction is Break))
            {
                lastInstruction.writeOut(sw, cfg);
                sw.WriteLine(";");
            }
            sw.Write(tab + "}");
        }
コード例 #4
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string tab       = new string('\t', this.getAllParentsOf <Interfaces.iCodeBlock>().Count);
            var    breakable = this.getFirstOf <Interfaces.iBreakable>();

            sw.Write(tab + "breakOut \"" + breakable.BreakScope + "\"");
        }
コード例 #5
0
 public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
 {
     sw.Write("((");
     this.LIdent.writeOut(sw, cfg);
     sw.Write(" select 0) find (");
     sw.Write('"' + this.RIdent.LastIdent.FullyQualifiedName + '"');
     sw.Write(") != -1)");
 }
コード例 #6
0
        public override void writeOut(StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string tab = this.Parent is Interfaces.iCodeBlock ? new string('\t', this.getAllParentsOf <Interfaces.iCodeBlock>().Count) : "";

            var lArgs = this.LArgs;
            var rArgs = this.RArgs;

            sw.Write(tab);
            if (lArgs.Count > 0)
            {
                if (lArgs.Count == 1)
                {
                    sw.Write("(");
                    lArgs[0].writeOut(sw, cfg);
                    sw.Write(") ");
                }
                else
                {
                    sw.Write("[");
                    int index = 0;
                    foreach (var it in lArgs)
                    {
                        if (index > 0)
                        {
                            sw.Write(", ");
                        }
                        index++;
                        it.writeOut(sw, cfg);
                    }
                    sw.Write("] ");
                }
            }
            sw.Write(this.Name.OriginalValue);
            if (rArgs.Count > 0)
            {
                if (rArgs.Count == 1)
                {
                    sw.Write(" (");
                    rArgs[0].writeOut(sw, cfg);
                    sw.Write(")");
                }
                else
                {
                    sw.Write(" [");
                    int index = 0;
                    foreach (var it in rArgs)
                    {
                        if (index > 0)
                        {
                            sw.Write(", ");
                        }
                        index++;
                        it.writeOut(sw, cfg);
                    }
                    sw.Write("]");
                }
            }
        }
コード例 #7
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string tab = new string('\t', this.getAllParentsOf <Interfaces.iCodeBlock>().Count);

            sw.Write(tab + "throw ");
            foreach (var it in this.children)
            {
                it.writeOut(sw, cfg);
            }
        }
コード例 #8
0
 public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
 {
     sw.Write("((");
     sw.Write(oosClass.GlobalClassRegisterVariable.SqfVariableName);
     sw.Write(" select (");
     this.LIdent.writeOut(sw, cfg);
     sw.Write(" select 0)) find (");
     sw.Write('"' + this.RIdent.LastIdent.FullyQualifiedName + '"');
     sw.Write(") != -1)");
 }
コード例 #9
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string tab = new string('\t', this.getAllParentsOf <Interfaces.iCodeBlock>().Count);

            sw.Write(tab);
            foreach (var it in this.children)
            {
                it.writeOut(sw, cfg);
            }
            sw.Write(" breakOut \"" + Wrapper.Compiler.ScopeNames.function + "\"");
        }
コード例 #10
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string tab = new string('\t', this.Parent.getAllParentsOf <Interfaces.iCodeBlock>().Count);

            sw.Write(tab + "switch (");
            this.expression.writeOut(sw, cfg);
            sw.WriteLine(") do");
            sw.WriteLine(tab + "{");
            HelperClasses.PrintCodeHelpers.printCodeLines(this.CodeInstructions, tab, sw, cfg);
            sw.Write(tab + "}");
        }
コード例 #11
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string tab = new string('\t', this.Parent.getAllParentsOf <Interfaces.iCodeBlock>().Count);

            sw.Write(tab + "while {");
            this.expression.writeOut(sw, cfg);
            sw.WriteLine("} do");
            sw.WriteLine(tab + "{");
            var varList = this.getAllChildrenOf <Variable>();

            if (varList.Count > 0)
            {
                if (varList.Count == 1)
                {
                    sw.Write(tab + '\t' + "private ");
                }
                else
                {
                    sw.Write(tab + '\t' + "private [");
                }

                for (int i = 0; i < varList.Count; i++)
                {
                    var it = varList[i];
                    if (i != 0)
                    {
                        sw.Write(", ");
                    }
                    if (it is Variable)
                    {
                        sw.Write('"' + ((Variable)it).SqfVariableName + '"');
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                if (varList.Count > 1)
                {
                    sw.Write("]");
                }
                sw.WriteLine(";");
            }
            if (this.getAllChildrenOf <Break>(true).Count > 0)
            {
                sw.WriteLine(tab + '\t' + "scopeName \"" + this.BreakScope + "\";");
            }
            HelperClasses.PrintCodeHelpers.printCodeLines(this.CodeInstructions, tab, sw, cfg);
            sw.Write(tab + "}");
        }
コード例 #12
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            //ToDo: do the actual casting stuff
            string tab = this.Parent is Interfaces.iCodeBlock ? new string('\t', this.getAllParentsOf <Interfaces.iCodeBlock>().Count) : "";

            if (this.children.Count != 1 || !(this.children[0] is Ident))
            {
                throw new Exception();
            }
            Ident ident = (Ident)this.children[0];

            switch (ident.LastIdent.ReferencedType.varType)
            {
            case VarType.Object:
                ident.writeOut(sw, cfg);
                break;

            case VarType.Bool:
                switch (this.ReferencedType.varType)
                {
                case VarType.Scalar:
                    sw.Write("parseNumber ");
                    ident.writeOut(sw, cfg);
                    break;

                default:
                    ident.writeOut(sw, cfg);
                    break;
                }
                break;

            case VarType.Scalar:
                switch (this.ReferencedType.varType)
                {
                case VarType.Bool:
                    sw.Write("if(");
                    ident.writeOut(sw, cfg);
                    sw.Write(" > 0) then {true} else {false}");
                    break;

                default:
                    ident.writeOut(sw, cfg);
                    break;
                }
                break;

            default:
                throw new Exception();
            }
        }
コード例 #13
0
 public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
 {
     foreach (var it in ClassContent)
     {
         if (it is Interfaces.iFunction && ((Interfaces.iFunction)it).IsVirtual)
         {
             continue;
         }
         if (it is Variable)
         {
             continue;
         }
         it.writeOut(sw, cfg);
     }
 }
コード例 #14
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string tab = new string('\t', this.Parent.getAllParentsOf <Interfaces.iCodeBlock>().Count);

            sw.WriteLine(tab + "try");
            sw.WriteLine(tab + "{");
            HelperClasses.PrintCodeHelpers.printPrivateArray(this, tab, sw, cfg, 1);
            HelperClasses.PrintCodeHelpers.printCodeLines(this.TryInstructions, tab, sw, cfg);
            sw.WriteLine(tab + "}");
            sw.WriteLine(tab + "catch");
            sw.WriteLine(tab + "{");
            HelperClasses.PrintCodeHelpers.printPrivateArray(this, tab, sw, cfg, 2);
            this.variable.writeOut(sw, cfg);
            sw.WriteLine(" = _exception;");
            HelperClasses.PrintCodeHelpers.printCodeLines(this.CatchInstructions, tab, sw, cfg);
            sw.Write(tab + "}");
        }
コード例 #15
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            sw.Write("[");
            bool flag = false;

            foreach (var it in this.children)
            {
                if (flag)
                {
                    sw.Write(", ");
                }
                else
                {
                    flag = true;
                }
                it.writeOut(sw, cfg);
            }
            sw.Write("]");
        }
コード例 #16
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string tab = new string('\t', this.getAllParentsOf <Interfaces.iCodeBlock>().Count);

            sw.Write(tab);
            if (((Variable)this.Name.LastIdent.ReferencedObject).encapsulation == Encapsulation.NA || ((Variable)this.Name.LastIdent.ReferencedObject).encapsulation == Encapsulation.Static)
            {
                this.Name.writeOut(sw, cfg);
                sw.Write(" = ");
                this.assign.writeOut(sw, cfg);
            }
            else
            {
                this.Name.writeOut(sw, cfg);
                sw.Write(" set [" + ((Variable)this.Name.LastIdent.ReferencedObject).SqfVariableName + ", ");
                this.assign.writeOut(sw, cfg);
                sw.Write("]");
            }
        }
コード例 #17
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string tab = new string('\t', this.Parent.getAllParentsOf <Interfaces.iCodeBlock>().Count);

            sw.Write(tab + "if(");
            this.expression.writeOut(sw, cfg);
            sw.WriteLine(") then");
            sw.WriteLine(tab + "{");
            HelperClasses.PrintCodeHelpers.printPrivateArray(this, tab, sw, cfg, 1);
            HelperClasses.PrintCodeHelpers.printCodeLines(this.IfInstructions, tab, sw, cfg);
            sw.Write(tab + "}");
            if (this.ElseInstructions.Count > 0)
            {
                sw.WriteLine("\n" + tab + "else");
                sw.WriteLine(tab + "{");
                HelperClasses.PrintCodeHelpers.printPrivateArray(this, tab, sw, cfg, 2);
                HelperClasses.PrintCodeHelpers.printCodeLines(this.ElseInstructions, tab, sw, cfg);
                sw.Write(tab + "}");
            }
        }
コード例 #18
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            if (sw == null)
            {
                return;
            }
            var assignList = this.getAllChildrenOf <VariableAssignment>();

            if (assignList.Count == 0)
            {
                return;
            }
            string tab = new string('\t', this.getAllParentsOf <Interfaces.iCodeBlock>().Count);

            sw.Write(tab + this.SqfVariableName);
            if (assignList.Count > 0)
            {
                sw.Write(" = ");
                assignList[0].writeOut(sw, cfg);
            }
        }
コード例 #19
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string tab = new string('\t', this.Parent.getAllParentsOf <Interfaces.iCodeBlock>().Count);

            if ((Variable.LastIdent.ReferencedType.IsObject && Variable.LastIdent.ReferencedType.ident.LastIdent.ReferencedObject.isType("::array")) || (Variable is Interfaces.iHasType && ((Interfaces.iHasType)Variable).ReferencedType.IsArray))
            {
                sw.WriteLine(tab + '{');
                HelperClasses.PrintCodeHelpers.printPrivateArray(this, tab, sw, cfg);
                if (this.getAllChildrenOf <Break>(true).Count > 0)
                {
                    sw.WriteLine(tab + '\t' + "scopeName \"" + this.BreakScope + "\";");
                }
                sw.WriteLine(tab + '\t' + Itterator.SqfVariableName + " = _x;");
                HelperClasses.PrintCodeHelpers.printCodeLines(this.CodeInstructions, tab, sw, cfg);
                sw.Write(tab + "} foreach ");
                Variable.writeOut(sw, cfg);
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #20
0
 public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
 {
     throw new NotImplementedException();
 }
コード例 #21
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            if (this.negate)
            {
                sw.Write('!');
            }
            if (this.negate || this.hasBrackets || this.expressionOperators.Count > 0)
            {
                sw.Write('(');
            }
            int i = 0;

            if (!(this.expressionObjects[0] is Expression || this.expressionObjects[0] is Value))
            {
                sw.Write('(');
                this.expressionObjects[0].writeOut(sw, cfg);
                sw.Write(')');
            }
            else
            {
                this.expressionObjects[0].writeOut(sw, cfg);
            }
            foreach (var op in this.expressionOperators)
            {
                var lArg = this.expressionObjects[i];
                var rArg = this.expressionObjects[++i];
                if (op == "==")
                {
                    if (!(rArg is Expression || rArg is Value))
                    {
                        sw.Write(" isEqualTo (");
                        rArg.writeOut(sw, cfg);
                        sw.Write(')');
                    }
                    else
                    {
                        sw.Write(' ' + "isEqualTo" + ' ');
                        rArg.writeOut(sw, cfg);
                    }
                }
                else if (op == "&&" || op == "||")
                {
                    sw.Write(' ' + op + " {");
                    rArg.writeOut(sw, cfg);
                    sw.Write('}');
                }
                else
                {
                    if (!(rArg is Expression || rArg is Value))
                    {
                        sw.Write(' ' + op + " (");
                        rArg.writeOut(sw, cfg);
                        sw.Write(')');
                    }
                    else
                    {
                        sw.Write(' ' + op + ' ');
                        rArg.writeOut(sw, cfg);
                    }
                }
            }
            if (this.negate || this.hasBrackets || this.expressionOperators.Count > 0)
            {
                sw.Write(')');
            }
        }
コード例 #22
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            if (this.IsExternal)
            {
                return;
            }
            if (this.IsInline)
            {
                if (cfg == null)
                {
                    cfg = new SqfConfigObjects.SqfConfigFile("inline");
                }
                else
                {
                    return;
                }
            }


            int    index;
            string tab = new string('\t', this.getAllParentsOf <Interfaces.iCodeBlock>().Count);

            if (this.IsVirtual || this.IsInline)
            {
                tab += '\t';
            }
            if (!this.IsVirtual)
            {
                var fqn = this.Name.FullyQualifiedName;

                var filePath       = Wrapper.Compiler.ProjectFile.OutputFolder + fqn.Replace("::", "\\") + this.SqfSuffix;
                var fileFolderPath = filePath.Substring(0, filePath.LastIndexOf('\\'));
                if (!Directory.Exists(fileFolderPath))
                {
                    Directory.CreateDirectory(fileFolderPath);
                }
                if (sw == null)
                {
                    sw = new System.IO.StreamWriter(filePath + ".sqf");
                }

                int lIndex = fqn.LastIndexOf("::") - fqn.Count(c => c == ':') / 2 + 1;
                fqn = fqn.Replace("::", "_") + this.SqfSuffix;
                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 || this.encapsulation != Encapsulation.Static)
            {
                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 + '"');
                        printComma = true;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                sw.WriteLine("];");
            }
            #region constructor printing
            if (this.IsConstructor)
            {
                /////////////////////////////////
                // OBJECT CONSTRUCTOR PRINTING //
                /////////////////////////////////
                var classObject = this.getFirstOf <oosClass>();
                var objects     = classObject.AllObjects;
                if (objects.Count > 0)
                {
                    sw.Write(tab + "private [");
                    index = 0;
                    foreach (var it in objects)
                    {
                        if (it is Interfaces.iFunction && !((Interfaces.iFunction)it).IsVirtual)
                        {
                            continue;
                        }
                        if (!(it is Variable) || ((Variable)it).Value != null)
                        {
                            if (index > 0)
                            {
                                sw.Write(", ");
                            }
                            sw.Write("\"" + Wrapper.Compiler.thisVariableName + (it is Function ? "fnc" : "var") + ((Interfaces.iName)it).Name.OriginalValue.Replace("::", "_") + (it is Function ? this.SqfSuffix : "") + "\"");
                            index++;
                        }
                    }
                    sw.WriteLine("];");
                }
                foreach (var it in objects)
                {
                    if (it == this)
                    {
                        continue;
                    }
                    if (it is Interfaces.iFunction && !((Interfaces.iFunction)it).IsVirtual)
                    {
                        continue;
                    }
                    if (it is Function)
                    {
                        sw.Write(tab + Wrapper.Compiler.thisVariableName + (it is Function ? "fnc" : "var") + ((Interfaces.iName)it).Name.OriginalValue.Replace("::", "_") + (it is Function ? this.SqfSuffix + " = {\r\n" : " = "));
                        it.writeOut(sw, cfg);
                        sw.WriteLine(tab + "};");
                    }
                    else
                    {
                        var val = ((Variable)it).Value;
                        if (val != null)
                        {
                            sw.Write(tab + Wrapper.Compiler.thisVariableName + (it is Function ? "fnc" : "var") + ((Interfaces.iName)it).Name.OriginalValue.Replace("::", "_") + (it is Function ? this.SqfSuffix + " = {\r\n" : " = "));
                            val.writeOut(sw, cfg);
                            sw.WriteLine(";");
                        }
                    }
                }
                sw.Write(tab + Wrapper.Compiler.thisVariableName + " = [");


                var classIdents = classObject.ParentClassesIdents;
                classIdents.Add(classObject.Name);

                //Representing classes (InstanceOf reference)
                sw.Write("[");
                index = 0;
                foreach (var it in classIdents)
                {
                    if (index > 0)
                    {
                        sw.Write(", ");
                    }
                    if (it is Ident)
                    {
                        index++;
                        sw.Write('"' + ((Interfaces.iClass)((Ident)it).ReferencedObject).Name.FullyQualifiedName + '"');
                    }
                    else
                    {
                        throw new Exception("please report to developer, unknown exception happened in function object creation");
                    }
                }
                sw.Write("], [");
                //Lookup register
                index = 0;
                foreach (var child in objects)
                {
                    if (child is Interfaces.iFunction && !((Interfaces.iFunction)child).IsVirtual)
                    {
                        continue;
                    }
                    if (child is Variable)
                    {
                        var variable = (Variable)child;
                        if (variable.IsClassVariable)
                        {
                            if (index > 0)
                            {
                                sw.Write(", ");
                            }
                            sw.Write('"' + ((Variable)child).Name.OriginalValue + '"');
                            index++;
                        }
                    }
                    else if (child is Interfaces.iFunction)
                    {
                        if (index > 0)
                        {
                            sw.Write(", ");
                        }
                        var fnc = (Interfaces.iFunction)child;
                        sw.Write('"' + ((Interfaces.iFunction)child).Name.OriginalValue + '"');
                        index++;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                sw.Write("]");
                foreach (var child in objects)
                {
                    if (child is Interfaces.iFunction)
                    {
                        var fnc = (Interfaces.iFunction)child;
                        if (fnc.IsVirtual)
                        {
                            if (index > 0)
                            {
                                sw.Write(", ");
                            }
                            sw.Write(Wrapper.Compiler.thisVariableName + "fnc" + ((Function)child).Name.OriginalValue.Replace("::", "_") + this.SqfSuffix);
                            index++;
                        }
                    }
                    else if (child is Variable)
                    {
                        var variable = (Variable)child;
                        if (variable.IsClassVariable)
                        {
                            sw.Write(", ");
                            if (variable.Value == null)
                            {
                                sw.Write("nil");
                            }
                            else
                            {
                                sw.Write(Wrapper.Compiler.thisVariableName + "var" + ((Variable)child).Name.OriginalValue.Replace("::", "_"));
                            }
                        }
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                sw.WriteLine("];");
                //ToDo: add baseconstructor calls
            }
            #endregion
            Logger.Instance.log(Logger.LogLevel.DEBUG, "Printing out function '" + this.Name.FullyQualifiedName + this.SqfSuffix + "'s body");
            HelperClasses.PrintCodeHelpers.printPrivateArray(this, tab, sw, cfg);
            HelperClasses.PrintCodeHelpers.printCodeLines(this.CodeInstructions, tab, sw, cfg);
            if (this.IsConstructor)
            {
                sw.Write(tab + Wrapper.Compiler.thisVariableName);
            }
            if (!this.IsVirtual)
            {
                sw.Flush();
                if (!this.IsInline)
                {
                    sw.Close();
                }
            }
        }
コード例 #23
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string variableName = this.Name.WriteOutValue;

            if (this.ReferencedObject is Interfaces.iFunction)
            {
                Interfaces.iFunction fnc = (Interfaces.iFunction) this.ReferencedObject;
                bool flag = false;
                if (fnc is NativeInstruction)
                {
                    var           nIns       = (NativeInstruction)fnc;
                    List <string> stringList = new List <string>();
                    if (!string.IsNullOrEmpty(variableName))
                    {
                        stringList.Add(variableName);
                    }
                    foreach (var it in this.children)
                    {
                        using (MemoryStream memStream = new MemoryStream())
                        {
                            StreamWriter memStreamWriter = new StreamWriter(memStream);
                            it.writeOut(memStreamWriter, cfg);
                            memStreamWriter.Flush();
                            memStream.Seek(0, SeekOrigin.Begin);
                            stringList.Add(new StreamReader(memStream).ReadToEnd());
                        }
                    }
                    sw.Write(nIns.getCode(stringList.ToArray()));
                }
                else
                {
                    if (fnc.FunctionEncapsulation == Encapsulation.Static || fnc.IsConstructor)
                    {
                        sw.Write('[');
                    }
                    else
                    {
                        sw.Write('[' + variableName);
                        flag = true;
                    }
                    foreach (var it in this.children)
                    {
                        if (flag)
                        {
                            sw.Write(", ");
                        }
                        else
                        {
                            flag = true;
                        }
                        it.writeOut(sw, cfg);
                    }
                    if (fnc is Function)
                    {
                        if (fnc.IsVirtual)
                        {
                            sw.Write(']' + (!fnc.IsAsync ? " call (" : " spawn (") + '(' + variableName + ')' + ((Function)fnc).SqfVariableName + ')');
                        }
                        else
                        {
                            sw.Write(']' + (!fnc.IsAsync ? " call " : " spawn ") + ((Function)fnc).SqfVariableName);
                        }
                        if (((Function)fnc).IsThrowing && this.getFirstOf <TryCatch>() == null)
                        {
                            Ident ident = this.getFirstOf <Ident>();
                            Logger.Instance.log(Logger.LogLevel.WARNING, "Function '" + fnc.Name.FullyQualifiedName + "' is throwing but not catched. line " + ident.Line + ", pos " + ident.Pos + ", file '" + ident.File + '\'');
                        }
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #24
0
 public abstract void writeOut(StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg);
コード例 #25
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            if (this.Parent is Ident)
            {
                var parentIdent = (Ident)this.Parent;
                if (parentIdent.ReferencedObject is Variable)
                {
                    var  variable    = (Variable)parentIdent.ReferencedObject;
                    bool printSelect = true;
                    if (variable.ReferencedType.IsObject)
                    {
                        if (variable.ReferencedType.ident.ReferencedObject is Interfaces.iClass)
                        {
                            var c   = (Interfaces.iClass)variable.ReferencedType.ident.ReferencedObject;
                            var fnc = c.getOperatorFunction(OverridableOperator.ArrayAccess);
                            if (fnc != null)
                            {
                                printSelect = false;
                                string variableName = ((Ident)this.Parent).WriteOutValue;
                                #region Copied from FunctionCall

                                bool flag = false;
                                if (fnc is NativeInstruction)
                                {
                                    var           nIns       = (NativeInstruction)fnc;
                                    List <string> stringList = new List <string>();
                                    stringList.Add(variableName);
                                    foreach (var it in this.children)
                                    {
                                        using (MemoryStream memStream = new MemoryStream())
                                        {
                                            StreamWriter memStreamWriter = new StreamWriter(memStream);
                                            it.writeOut(memStreamWriter, cfg);
                                            memStreamWriter.Flush();
                                            memStream.Seek(0, SeekOrigin.Begin);
                                            stringList.Add(new StreamReader(memStream).ReadToEnd());
                                        }
                                    }
                                    sw.Write(nIns.getCode(stringList.ToArray()));
                                }
                                else
                                {
                                    if (fnc.FunctionEncapsulation == Encapsulation.Static || fnc.IsConstructor)
                                    {
                                        sw.Write('[');
                                    }
                                    else
                                    {
                                        sw.Write('[' + variableName);
                                        flag = true;
                                    }
                                    foreach (var it in this.children)
                                    {
                                        if (flag)
                                        {
                                            sw.Write(", ");
                                        }
                                        else
                                        {
                                            flag = true;
                                        }
                                        it.writeOut(sw, cfg);
                                    }
                                    if (fnc is Function)
                                    {
                                        if (fnc.FunctionEncapsulation == Encapsulation.Static || fnc.IsConstructor)
                                        {
                                            sw.Write(']' + " call " + ((Function)fnc).SqfVariableName);
                                        }
                                        else
                                        {
                                            sw.Write(']' + " call " + '(' + variableName + ')' + ((Function)fnc).SqfVariableName);
                                        }
                                    }
                                    else
                                    {
                                        throw new Exception();
                                    }
                                }
                                #endregion
                            }
                        }
                    }
                    if (printSelect)
                    {
                        bool flag = false;
                        if (this.getFirstOf <FunctionCall>(false, typeof(Ident)) != null)
                        {
                            flag = true;
                        }
                        //if(((Ident)this.Parent).HasCallWrapper)
                        //{
                        sw.Write((flag ? "(" : "") + ((Ident)this.Parent).WriteOutValue);
                        //}
                        sw.Write(" select ");
                        foreach (var it in this.children)
                        {
                            it.writeOut(sw, cfg);
                        }
                        if (flag)
                        {
                            sw.Write(')');
                        }
                    }
                }
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #26
0
 public static void printCodeLines(List <pBaseLangObject> instructions, string tab, System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
 {
     foreach (var it in instructions)
     {
         if (it is Ident)
         {
             sw.Write(tab + '\t');
         }
         if (it is Variable && ((Variable)it).getAllChildrenOf <VariableAssignment>().Count == 0)
         {
             continue;
         }
         it.writeOut(sw, cfg);
         sw.WriteLine(";");
     }
 }
コード例 #27
0
        public static void printPrivateArray(pBaseLangObject obj, string tab, System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg, int scopeIndex = -1)
        {
            var varList     = obj.getAllChildrenOf <Variable>(false, null, -1, scopeIndex);
            var forLoopList = obj.getAllChildrenOf <For>(false, null, -1, scopeIndex);

            foreach (var it in forLoopList)
            {
                if (it.forArg1 != null && it.forArg1 is Variable)
                {
                    varList.Add((Variable)it.forArg1);
                }
            }
            if (varList.Count > 0)
            {
                if (varList.Count == 1)
                {
                    sw.Write(tab + '\t' + "private ");
                }
                else
                {
                    sw.Write(tab + '\t' + "private [");
                }

                for (int i = 0; i < varList.Count; i++)
                {
                    var it = varList[i];
                    if (i != 0)
                    {
                        sw.Write(", ");
                    }
                    if (it is Variable)
                    {
                        sw.Write('"' + ((Variable)it).SqfVariableName + '"');
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                if (varList.Count > 1)
                {
                    sw.Write("]");
                }
                sw.WriteLine(";");
            }
        }
コード例 #28
0
ファイル: Ident.cs プロジェクト: X39/ObjectOrientedScripting
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            bool assignToTmp = this.HasCallWrapper;
            bool callWrapper = !(this.Parent is Ident && ((Ident)this.Parent).Type != IdenType.NamespaceAccess) && assignToTmp;

            if (callWrapper)
            {
                sw.Write("[] call {private \"___tmp___\"; ");
                if (this.ReferencedObject is Variable)
                {
                    sw.Write("___tmp___ = (" + ((Variable)this.ReferencedObject).SqfVariableName + ");");
                }
                else
                {
                    sw.Write("___tmp___ = (" + this.WriteOutValue + ");");
                }
            }


            if (this.IsSimpleIdentifier && this.children.Count == 0)
            {
                if (this.ReferencedObject is Variable)
                {
                    Variable variable = (Variable)this.ReferencedObject;
                    sw.Write(variable.SqfVariableName);
                }
                else if (this.ReferencedObject is oosClass && this.IsSelfReference)
                {
                    sw.Write(Wrapper.Compiler.thisVariableName);
                }
                else if (this.ReferencedObject is Function)
                {
                    var fnc = (Function)this.ReferencedObject;
                    sw.Write(fnc.SqfVariableName);
                }
                else
                {
                    throw new Exception();
                }
            }
            else if (this.children.Count == 0)
            {
                sw.Write(this.WriteOutValue);
            }
            else
            {
                foreach (var it in this.children)
                {
                    var ms  = new MemoryStream();
                    var sw2 = new StreamWriter(ms);
                    if (it is Ident)
                    {
                        continue;
                    }
                    it.writeOut(sw2, cfg);
                    sw2.Flush();
                    ms.Seek(0, SeekOrigin.Begin);
                    string output = new StreamReader(ms).ReadToEnd();
                    ms.Close();
                    if (assignToTmp)
                    {
                        if (output != "___tmp___")
                        {
                            sw.Write(" ___tmp___ = (");
                            sw.Write(output);
                            sw.Write(");");
                        }
                    }
                    else
                    {
                        sw.Write(output);
                    }
                }
                foreach (var it in this.children)
                {
                    if (it is Ident)
                    {
                        it.writeOut(sw, cfg);
                    }
                }
            }

            if (callWrapper)
            {
                if (this.LastIdent.ReferencedType.varType == VarType.Void)
                {
                    sw.Write('}');
                }
                else
                {
                    sw.Write(" ___tmp___}");
                }
            }
        }
コード例 #29
0
 public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
 {
 }
コード例 #30
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            if (this.Parent is Ident || this.Parent is AssignContainer)
            {
                Ident  parent  = this.Parent is AssignContainer ? ((AssignContainer)this.Parent).Name.NextWorkerIdent : (Ident)this.Parent;
                string varName = '(' + parent.WriteOutValue + ')';
                switch (this.Operation)
                {
                case AssignmentCharacters.PlusOne:
                    sw.Write(varName + " + 1");
                    break;

                case AssignmentCharacters.MinusOne:
                    sw.Write(varName + " - 1");
                    break;

                case AssignmentCharacters.AdditionAssign:
                    sw.Write(varName + " + (");
                    foreach (var it in this.children)
                    {
                        it.writeOut(sw, cfg);
                    }
                    sw.Write(")");
                    break;

                case AssignmentCharacters.SubstractionAssign:
                    sw.Write(varName + " - (");
                    foreach (var it in this.children)
                    {
                        it.writeOut(sw, cfg);
                    }
                    sw.Write(")");
                    break;

                case AssignmentCharacters.MultiplicationAssign:
                    sw.Write(varName + " * (");
                    foreach (var it in this.children)
                    {
                        it.writeOut(sw, cfg);
                    }
                    sw.Write(")");
                    break;

                case AssignmentCharacters.DivisionAssign:
                    sw.Write(varName + " / (");
                    foreach (var it in this.children)
                    {
                        it.writeOut(sw, cfg);
                    }
                    sw.Write(")");
                    break;

                default:
                    foreach (var it in this.children)
                    {
                        it.writeOut(sw, cfg);
                    }
                    break;
                }
            }
            else if (this.Parent is Variable)
            {
                foreach (var it in this.children)
                {
                    it.writeOut(sw, cfg);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }