Esempio n. 1
0
        public static string iExists(SAR s)
        {
            Symbol symbol;
            Symbol check;
            Symbol defined;
            bool   flag           = false;
            string tempScope      = "";
            string scope          = s.scope;
            string parameterTypes = "";
            int    definedParamCount;

            while (scope != "")
            {
                if (ScopeTable.ContainsKey(scope))
                {
                    for (int i = 0; i < ScopeTable[scope].Count; ++i)
                    {
                        symbol = ScopeTable[scope][i];
                        if (symbol.value.Equals(s.value) && symbol.symid[1] != 'A')
                        {
                            tempScope = scope;
                            if (symbol.parameters.Split(',')[0] != "")
                            {
                                definedParamCount = symbol.parameters.Split(',').Length;
                            }
                            else
                            {
                                definedParamCount = 0;
                            }
                            if (s.dataType == "@")
                            {
                                string type = symbol.data[0].Split(':')[1];
                                if (type.Length < 1 || type[0] != '@')
                                {
                                    continue;
                                }
                                if (type[0] == '@')
                                {
                                    type = type.Substring(1, type.Length - 1);
                                }
                                if (s.value == "i")
                                {
                                    Console.Write(" ");
                                }
                                string   symid = "tArr" + SemanticActions.uniqueCounter++;
                                string[] data  = new string[2];
                                data[0] = "dataType:" + type;
                                data[1] = "accessMod:public";
                                Symbol temp = new Symbol("t", symid, "t" + s.value, "tvar", data);
                                Add(temp);
                                s.dataType = data[0];
                                s.symid    = symid;
                                s.scope    = "t";
                                ICode.AEF(symbol.symid, s.argList[0], temp.symid);
                                return(s.symid);
                            }
                            else if (s.argList.Count != definedParamCount)
                            {
                                for (int j = 0; j < s.argList.Count; ++j)
                                {
                                    parameterTypes += symbolTable[s.argList[s.argList.Count - j - 1]].data[0].Split(':')[1] + ",";
                                }
                                continue;
                            }
                            else
                            {
                                parameterTypes = "";
                                for (int j = 0; j < s.argList.Count; ++j)
                                {
                                    check   = symbolTable[s.argList[j]];//args are in reverse order
                                    defined = symbolTable[symbol.parameters.Split(',')[j]];
                                    if (check.data[0].Split(':')[1] != defined.data[0].Split(':')[1])
                                    {
                                        flag = true;
                                    }
                                    parameterTypes += check.data[0].Split(':')[1] + ",";
                                }
                                if (flag)
                                {
                                    continue;
                                }
                            }
                            s.symid = ScopeTable[scope][i].symid;
                            s.scope = scope;
                            return(s.symid);
                        }
                    }
                }
                if (!scope.Contains("."))
                {
                    if (parameterTypes != null && parameterTypes.Length > 0)
                    {
                        s.value += "(" + parameterTypes.Substring(0, parameterTypes.Length - 1) + ")";
                    }
                    if (tempScope != "")
                    {
                        s.scope = tempScope;
                    }
                    return(null);
                }
                string[] scopes = scope.Split('.');
                scope = scopes[0];
                for (int i = 1; i < scopes.Length - 1; ++i)
                {
                    scope += "." + scopes[i];
                }
            }
            s.value += "(" + parameterTypes.Substring(0, parameterTypes.Length - 1) + ")";
            s.scope  = tempScope;
            return(null);
        }