Beispiel #1
0
        public virtual bool CanStoreValue(ExecContext context, ITypeDef valueType)
        {
            //if (valueType is TypeDef) {
            //	return null == (valueType as TypeDef).IsNull();
            //}
            if (valueType.IsNull())
            {
                return(true);
            }

            TypeDef_Function funcValueType = valueType as TypeDef_Function;

            if (null == funcValueType)
            {
                return(false);
            }

            if (!retType.Equals(IntrinsicTypeDefs.VOID) && !retType.CanStoreValue(context, funcValueType.retType))
            {
                return(false);
            }

            if (null != classType)
            {
                if (null == funcValueType.classType || !classType.CanStoreValue(context, funcValueType.classType))
                {
                    return(false);
                }
                // This is the point of isStatic in this class. This is saying, "I can save a reference to a class member function only if it is static."
            }
            else if (null != funcValueType.classType && !funcValueType.isStaticMember)
            {
                return(false);
            }

            // Mismatch if other's max args exceeds our max args.
            if (argTypes.Count > funcValueType.argTypes.Count)
            {
                return(false);
            }

            // Mismatch if we have fewer min args than they do.
            // (Meaning we could be called with fewer arguments than they have default values for.)
            if (minArgs < funcValueType.minArgs)
            {
                return(false);
            }

            // Make sure that for every argument WE have, THEIR argument's type matches.
            for (int ii = 0; ii < argTypes.Count; ++ii)
            {
                if (!funcValueType.argTypes[ii].CanStoreValue(context, argTypes[ii]))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        // D B A
        // G E B A
        // This is specifically for the conditional operator.
        //   typeof(true?D:G) is B
        public ITypeDef GetMostCommonType(ITypeDef typeA, ITypeDef typeB)
        {
            bool aIsClass = typeA is TypeDef_Class;

            if (aIsClass)
            {
                bool bIsClass = typeB is TypeDef_Class;
                if (bIsClass)
                {
                    TypeDef_Class classTypeA = typeA as TypeDef_Class;
                    TypeDef_Class classTypeB = typeB as TypeDef_Class;
                    return(GetMostCommonType(classTypeA, classTypeB));
                }
            }

            // If they aren't both classes then they must be equal or they
            // have no commonality.
            if (typeA.Equals(typeB))
            {
                return(typeA);
            }

            return(null);
        }