Beispiel #1
0
        public bool DoesTypeDeepMatch(List <StackValue> formalParameters, Core core)
        {
            if (formalParameters.Count != FormalParams.Length)
            {
                return(false);
            }

            for (int i = 0; i < FormalParams.Length; i++)
            {
                if (FormalParams[i].IsIndexable != ArrayUtils.IsArray(formalParameters[i]))
                {
                    return(false);
                }

                if (FormalParams[i].IsIndexable && ArrayUtils.IsArray(formalParameters[i]))
                {
                    if (FormalParams[i].rank != ArrayUtils.GetMaxRankForArray(formalParameters[i], core) &&
                        FormalParams[i].rank != DSASM.Constants.kArbitraryRank)
                    {
                        return(false);
                    }


                    Type typ = FormalParams[i];
                    Dictionary <ClassNode, int> arrayTypes = ArrayUtils.GetTypeStatisticsForArray(formalParameters[i], core);

                    ClassNode cn = null;

                    if (arrayTypes.Count == 0)
                    {
                        //This was an empty array
                        Validity.Assert(cn == null, "If it was an empty array, there shouldn't be a type node");
                        cn = core.ClassTable.ClassNodes[(int)PrimitiveType.kTypeNull];
                    }
                    else if (arrayTypes.Count == 1)
                    {
                        //UGLY, get the key out of the array types, of which there is only one
                        foreach (ClassNode key in arrayTypes.Keys)
                        {
                            cn = key;
                        }
                    }
                    else if (arrayTypes.Count > 1)
                    {
                        ClassNode commonBaseType = ArrayUtils.GetGreatestCommonSubclassForArray(formalParameters[i], core);

                        if (commonBaseType == null)
                        {
                            throw new ProtoCore.Exceptions.ReplicationCaseNotCurrentlySupported("Array with no common superclass not yet supported: {0C644179-14F5-4172-8EF8-A2F3739901B2}");
                        }

                        cn = commonBaseType; //From now on perform tests on the commmon base type
                    }


                    ClassNode argTypeNode = core.ClassTable.ClassNodes[typ.UID];

                    //cn now represents the class node of the argument
                    //argTypeNode represents the class node of the argument

                    int coersionScore = cn.GetCoercionScore(core.ClassTable.ClassNodes.IndexOf(argTypeNode));

                    //TODO(Jun)This is worrying test

                    //Disable var as exact match, otherwise resolution between double and var will fail
                    if (cn != argTypeNode && cn != core.ClassTable.ClassNodes[(int)PrimitiveType.kTypeNull] && argTypeNode != core.ClassTable.ClassNodes[(int)PrimitiveType.kTypeVar])
                    {
                        return(false);
                    }

                    //if (coersionScore != (int)ProcedureDistance.kExactMatchScore)
                    //    return false;

                    continue;
                }

                if (FormalParams[i].UID != (int)formalParameters[i].metaData.type)
                {
                    return(false);
                }
            }
            return(true);
        }