public override string VisitQFunctionCall([NotNull] QPILE_converterV2Parser.QFunctionCallContext context)
        {
            if (context.CREATE_MAP() != null)
            {
                return("{}");
            }

            if (context.SET_VALUE() != null)
            {
                var name  = Visit(context.children[2]);
                var key   = context.children[4].GetText();
                var value = Visit(context.children[6]);
                return("setValue(" + name + ", " + key + ", " + value + ")" + "\n"
                       + GenerateSet_ValueFunction());
            }

            if (context.GET_INFO_PARAM() != null)
            {
                var str = context.children[2].GetText();
                return("getInfoParam" + " (" + str + ")");
            }

            if (context.SUBSTR() != null)
            {
                string str;
                if (context.STRING_SYMBOLS() != null)
                {
                    str = context.children[2].GetText();
                }
                else
                {
                    str = Visit(context.children[2]);
                }
                var index  = Visit(context.children[4]);
                var length = Visit(context.children[6]);
                return("string.sub" + "(" + str + ", " + index + ", " + index + " + " + length + ")");
            }

            return(base.VisitQFunctionCall(context));
        }
Exemplo n.º 2
0
        public override string VisitQFunctionCall([NotNull] QPILE_converterV2Parser.QFunctionCallContext context)
        {
            if (context.CREATE_MAP() != null)
            {
                return("{}");
            }

            if (context.SET_VALUE() != null)
            {
                var name  = Visit(context.children[2]);
                var key   = context.children[4].GetText();
                var value = Visit(context.children[6]);
                return("setValue(" + name + ", " + key + ", " + value + ")" + "\n"
                       + GenerateSet_ValueFunction());
            }

            if (context.GET_INFO_PARAM() != null)
            {
                var str = context.children[2].GetText();
                return("getInfoParam" + " (" + str + ")");
            }

            if (context.GET_COLLECTION_COUNT() != null)
            {
                var str = context.children[2].GetText();
                return("#" + str + "+1");
            }

            if (context.GET_VALUE() != null)
            {
                var str1 = context.children[2].GetText();
                var str2 = context.children[4].GetText();
                return(str1 + "[" + str2 + "]");
            }

            if (context.GET_ITEM() != null)
            {
                var str1 = context.children[2].GetText();
                var str2 = context.children[4].GetText();
                return("getItem(" + str1 + "," + str2 + ")");
            }

            if (context.GET_NUMBER_OF() != null)
            {
                var str1 = context.children[2].GetText();
                return("getNumberOf(" + str1 + ")");
            }

            if (context.REMOVE_COLLECTION_ITEM() != null)
            {
                var    str1 = context.children[2].GetText();
                var    str2 = context.children[4].GetText();
                string res  = "";
                res += "collectionName1 = {}\n    a=0\n    for j=0, #collectionName do\n        if j == index then\n            a=1\n";
                res += "        else\n            collectionName1[j-a]=collectionName[j]\n    end\n";
                if (methods.Contains(res) == false)
                {
                    methods += "function RemoveCollectionItem(collectionName,index)\n    " + res + "end;\n";
                }
                return("RemoveCollectionItem(" + str1 + "," + str2 + ")");
            }

            if (context.INSERT_COLLECTION_ITEM() != null)
            {
                var    str1 = context.children[2].GetText();
                var    str2 = context.children[4].GetText();
                var    str3 = context.children[6].GetText();
                string res  = "";
                res += "collectionName1 = {}\n    a=0\n    for j=0, #collectionName do\n        if j == index then\n            a=1;\n";
                res += "            collectionName1[j]=value\n        end\n        collectionName1[j+a]=collectionName[j]\n    end\n    return collectionName1\n";
                if (methods.Contains(res) == false)
                {
                    methods += "function InsertCollectionItem(collectionName,index,value)\n    " + res + "end;\n";
                }
                return("InsertCollectionItem(" + str1 + "," + str2 + "," + str3 + ")");
            }

            if (context.GET_COLLECTION_ITEM() != null)
            {
                var str1 = context.children[2].GetText();
                var str2 = context.children[4].GetText();
                return(str1 + "[" + str2 + "]");
            }

            if (context.SET_COLLECTION_ITEM() != null)
            {
                var    str1 = context.children[2].GetText();
                var    str2 = context.children[4].GetText();
                var    str3 = context.children[6].GetText();
                string res  = "";
                res += "collectionName1 = {}\n    for j = 0,#collectionName do\n        if j == index then\n            collectionName1[j]=value\n";
                res += "        else\n            collectionName1[j]=collectionName[j]\n        end\n    end\n    return collectionName1\n";
                if (methods.Contains(res) == false)
                {
                    methods += "function SetCollectionItem(collectionName,index,value)\n    " + res + "end;\n";
                }
                return("SetCollectionItem(" + str1 + "," + str2 + "," + str3 + ")");
            }

            if (context.CREATE_COLLECTION() != null)
            {
                return("{}");
            }

            if (context.SUBSTR() != null)
            {
                string str;
                if (context.STRING_SYMBOLS() != null)
                {
                    str = context.children[2].GetText();
                }
                else
                {
                    str = Visit(context.children[2]);
                }
                var index  = Visit(context.children[4]);
                var length = Visit(context.children[6]);
                return("string.sub" + "(" + str + ", " + index + ", " + index + " + " + length + ")");
            }

            return(base.VisitQFunctionCall(context));
        }