예제 #1
0
        public DataTypePointer GetConcreteType(Type typeParameter)
        {
            if (ClassType != null)
            {
                DataTypePointer dp = _type.GetConcreteType(typeParameter);
                if (dp != null)
                {
                    return(dp);
                }
            }
            IGenericTypePointer igp = null;
            IObjectPointer      op  = Owner;

            while (op != null)
            {
                igp = op as IGenericTypePointer;
                if (igp != null)
                {
                    break;
                }
                op = op.Owner;
            }
            if (igp != null)
            {
                return(igp.GetConcreteType(typeParameter));
            }
            return(null);
        }
        public IList <DataTypePointer> GetGenericTypes()
        {
            IGenericTypePointer gtp = _methodPointer as IGenericTypePointer;

            if (gtp != null)
            {
                return(gtp.GetGenericTypes());
            }
            return(null);
        }
        public CodeTypeReference GetCodeTypeReference()
        {
            IGenericTypePointer gtp = _methodPointer as IGenericTypePointer;

            if (gtp != null)
            {
                return(gtp.GetCodeTypeReference());
            }
            return(null);
        }
        public DataTypePointer GetConcreteType(Type typeParameter)
        {
            IGenericTypePointer gtp = _methodPointer as IGenericTypePointer;

            if (gtp != null)
            {
                return(gtp.GetConcreteType(typeParameter));
            }
            return(null);
        }
        public DataTypePointer[] GetConcreteTypes()
        {
            IGenericTypePointer gtp = _methodPointer as IGenericTypePointer;

            if (gtp != null)
            {
                return(gtp.GetConcreteTypes());
            }
            return(null);
        }
        /// <summary>
        /// returns corresponding concrete types for generic arguments
        /// 1. method parameters
        /// 2. method return type
        /// 3. owner type arguments
        /// different sections may overlap, duplications may exist
        /// </summary>
        /// <returns></returns>
        public DataTypePointer[] GetConcreteTypes()
        {
            List <DataTypePointer> l = new List <DataTypePointer>();

            if (_paramTypes != null && _paramTypes.Length > 0)
            {
                for (int i = 0; i < _paramTypes.Length; i++)
                {
                    if (_paramTypes[i].IsGenericParameter || _paramTypes[i].IsGenericType)
                    {
                        DataTypePointer dp = GetConcreteType(_paramTypes[i]);
                        if (dp != null)
                        {
                            l.Add(dp);
                        }
                    }
                }
            }
            if (_concreteReturnType != null)
            {
                l.Add(_concreteReturnType);
            }
            IGenericTypePointer igp = this.Owner as IGenericTypePointer;

            if (igp != null)
            {
                DataTypePointer[] dps = igp.GetConcreteTypes();
                if (dps != null && dps.Length > 0)
                {
                    DataTypePointer[] ps = new DataTypePointer[l.Count + dps.Length];
                    l.CopyTo(ps, 0);
                    dps.CopyTo(ps, l.Count);
                    return(ps);
                }
            }
            return(l.ToArray());
        }
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            MathNode.Trace("{0}.ExportCode", this.GetType().Name);
            if (_methodPointer == null)
            {
                MathNode.Trace("Warning: method pointer is null");
                return(null);
            }
            bool isWeb = false;

            if (_methodPointer.Owner != null && _methodPointer.Owner.RootPointer != null)
            {
                isWeb = _methodPointer.Owner.RootPointer.IsWebPage;
            }
            if (isWeb && _methodPointer.RunAt == EnumWebRunAt.Client)
            {
                CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression(
                    new CodeVariableReferenceExpression("clientRequest"), "GetStringValue", new CodePrimitiveExpression(DataPassingCodeName));
                return(cmie);
            }
            if (method == null)
            {
                throw new DesignerException("Calling {0}.ExportCode with null method", this.GetType().Name);
            }
            if (method.MethodCode == null)
            {
                throw new DesignerException("Calling {0}.ExportCode with null method.MethodCode", this.GetType().Name);
            }
            CodeStatementCollection supprtStatements = method.MethodCode.Statements;
            int n = ChildNodeCount;

            CodeExpression[] ps;
            if (n > 0)
            {
                IList <IParameter> pList = _methodPointer.MethodPointed.MethodParameterTypes;;

                //_methodPointer.MethodPointed.
                ps = new CodeExpression[n];
                for (int i = 0; i < n; i++)
                {
                    this[i].CompileDataType = new RaisDataType(pList[i].ParameterLibType);
                    if (typeof(string).Equals(pList[i].ParameterLibType))
                    {
                        if (this[i].Parent != null)
                        {
                            MathNodeMethodPointer mmp = this[i].Parent as MathNodeMethodPointer;
                            if (mmp != null && mmp.Method != null && mmp.Method.Owner != null)
                            {
                                if (typeof(DateTime).Equals(mmp.Method.Owner.ObjectType))
                                {
                                    if (this[i].ActualCompiledType != null && typeof(CultureInfo).Equals(this[i].ActualCompiledType.LibType))
                                    {
                                        this[i].CompileDataType = this[i].ActualCompiledType;
                                    }
                                }
                            }
                        }
                    }
                    ps[i] = this[i].ExportCode(method);
                }
            }
            else
            {
                ps = new CodeExpression[] { };
            }
            _methodPointer.SetParameterExpressions(ps);
            CodeExpression ce = _methodPointer.GetReferenceCode(method, supprtStatements, true);

            if (_methodPointer.ReturnBaseType != null && this.CompileDataType != null && this.CompileDataType.Type != null)
            {
                DataTypePointer     targetType = new DataTypePointer(this.CompileDataType.Type);
                DataTypePointer     sourceType = new DataTypePointer(_methodPointer.ReturnBaseType);
                IGenericTypePointer igp        = _methodPointer as IGenericTypePointer;
                if (igp != null)
                {
                    if (targetType.IsGenericType || targetType.IsGenericParameter)
                    {
                        DataTypePointer dtp = igp.GetConcreteType(targetType.BaseClassType);
                        if (dtp != null)
                        {
                            targetType = dtp;
                        }
                    }
                    if (sourceType.IsGenericType || sourceType.IsGenericParameter)
                    {
                        DataTypePointer dtp = igp.GetConcreteType(sourceType.BaseClassType);
                        if (dtp != null)
                        {
                            sourceType = dtp;
                        }
                    }
                }
                if (!targetType.IsAssignableFrom(sourceType))
                {
                    ce = CompilerUtil.GetTypeConversion(targetType, ce, sourceType, supprtStatements);
                }
            }
            return(ce);
        }
예제 #8
0
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            CodeExpression ce;

            if (_valuePointer != null)
            {
                bool isWeb = false;
                if (_valuePointer.RootPointer != null)
                {
                    isWeb = _valuePointer.RootPointer.IsWebPage;
                }
                if (!IsField() && isWeb && this.IsWebClientValue())
                {
                    //this is a client property, use clientRequest.GetStringValue(DataPassingCodeName)
                    CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression(
                        new CodeVariableReferenceExpression("clientRequest"), "GetStringValue", new CodePrimitiveExpression(DataPassingCodeName));
                    ce = cmie;
                }
                else
                {
                    ce = _valuePointer.GetReferenceCode(method, method.MethodCode.Statements, _forValue);
                }
                ActualCompiledType = new MathExp.RaisTypes.RaisDataType(_valuePointer.ObjectType);
                if (CompileDataType != null)
                {
                    if (CompileDataType.Type != null && _valuePointer.ObjectType != null)
                    {
                        DataTypePointer     targetType = new DataTypePointer(CompileDataType.Type);
                        DataTypePointer     sourceType = new DataTypePointer(_valuePointer.ObjectType);
                        IGenericTypePointer igp        = _valuePointer as IGenericTypePointer;
                        if (igp != null)
                        {
                            if (targetType.IsGenericType || targetType.IsGenericParameter)
                            {
                                DataTypePointer dtp = igp.GetConcreteType(targetType.BaseClassType);
                                if (dtp != null)
                                {
                                    targetType = dtp;
                                }
                            }
                            if (sourceType.IsGenericType || sourceType.IsGenericParameter)
                            {
                                DataTypePointer dtp = igp.GetConcreteType(sourceType.BaseClassType);
                                if (dtp != null)
                                {
                                    sourceType = dtp;
                                }
                            }
                        }
                        if (!targetType.IsAssignableFrom(sourceType))
                        {
                            ce = CompilerUtil.GetTypeConversion(targetType, ce, sourceType, method.MethodCode.Statements);
                            ActualCompiledType = new MathExp.RaisTypes.RaisDataType(targetType.BaseClassType);
                        }
                    }
                }
            }
            else
            {
                ce = new CodeArgumentReferenceExpression(CodeName);
            }
            return(ce);
        }
        public void ResolveGenericParameters(LimnorProject project)
        {
            MethodBase mb = MethodDef;

            if (mb != null)
            {
                if (_concreteReturnType == null && _returnType != null && (_returnType.IsGenericParameter || _returnType.IsGenericType))
                {
                    IGenericTypePointer igp = this.Owner as IGenericTypePointer;
                    if (igp != null)
                    {
                        _concreteReturnType = igp.GetConcreteType(_returnType);
                    }
                }
                if (TypeParameters == null && mb.ContainsGenericParameters && !(mb is ConstructorInfo))
                {
                    _genericParams = mb.GetGenericArguments();
                    if (_genericParams != null && _genericParams.Length > 0)
                    {
                        DlgSelectTypeParameters dlg = new DlgSelectTypeParameters();
                        dlg.LoadData(mb, project);
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            TypeParameters = dlg._holder.Results;
                        }

                        if (TypeParameters == null)
                        {
                            TypeParameters = new DataTypePointer[_genericParams.Length];
                            for (int i = 0; i < _genericParams.Length; i++)
                            {
                                TypeParameters[i] = new DataTypePointer(typeof(object));
                            }
                        }
                        if (_concreteReturnType == null && _returnType != null && (_returnType.IsGenericParameter || _returnType.IsGenericType))
                        {
                            if (_returnType.IsGenericType)
                            {
                                _concreteReturnType = new DataTypePointer(_returnType);
                                Type[] tcs = _returnType.GetGenericArguments();
                                if (tcs != null && tcs.Length > 0)
                                {
                                    _concreteReturnType.TypeParameters = new DataTypePointer[tcs.Length];
                                    for (int i = 0; i < tcs.Length; i++)
                                    {
                                        for (int k = 0; k < _genericParams.Length; k++)
                                        {
                                            if (_genericParams[k].Equals(tcs[i]))
                                            {
                                                _concreteReturnType.TypeParameters[i] = TypeParameters[k];
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            else if (_returnType.IsGenericParameter)
                            {
                                for (int i = 0; i < _genericParams.Length; i++)
                                {
                                    if (_returnType.Equals(_genericParams[i]))
                                    {
                                        _concreteReturnType = TypeParameters[i];
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// each generic type is defined by a DataTypePointer with its BaseClassType being the generic parameter and its _concretTypeForTypeParameter being the concrete type
        /// </summary>
        /// <returns></returns>
        public IList <DataTypePointer> GetGenericTypes()
        {
            List <DataTypePointer> l = new List <DataTypePointer>();

            if (_paramTypes != null && _paramTypes.Length > 0)
            {
                for (int i = 0; i < _paramTypes.Length; i++)
                {
                    if (_paramTypes[i] != null && (_paramTypes[i].IsGenericParameter || _paramTypes[i].IsGenericType))
                    {
                        DataTypePointer dp = new DataTypePointer(_paramTypes[i]);
                        DataTypePointer cp = GetConcreteType(_paramTypes[i]);
                        if (cp != null)
                        {
                            dp.SetConcreteType(cp);
                            l.Add(dp);
                        }
                    }
                }
            }
            if (_returnType != null && _concreteReturnType != null)
            {
                bool found = false;
                foreach (DataTypePointer p in l)
                {
                    if (_returnType.Equals(p.BaseClassType))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    DataTypePointer dp = new DataTypePointer(_returnType);
                    dp.SetConcreteType(_concreteReturnType);
                    l.Add(dp);
                }
            }
            if (TypeParameters != null && TypeParameters.Length > 0)
            {
                if (_genericParams != null && _genericParams.Length == TypeParameters.Length)
                {
                    for (int i = 0; i < _genericParams.Length; i++)
                    {
                        bool found = false;
                        foreach (DataTypePointer p in l)
                        {
                            if (_genericParams[i].Equals(p.BaseClassType))
                            {
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            DataTypePointer dp = new DataTypePointer(_genericParams[i]);
                            dp.SetConcreteType(TypeParameters[i]);
                            l.Add(dp);
                        }
                    }
                }
            }
            IGenericTypePointer igp = this.Owner as IGenericTypePointer;

            if (igp != null)
            {
                IList <DataTypePointer> ls = igp.GetGenericTypes();
                if (ls != null && ls.Count > 0)
                {
                    foreach (DataTypePointer p0 in ls)
                    {
                        bool found = false;
                        foreach (DataTypePointer p in l)
                        {
                            if (p0.Equals(p.BaseClassType))
                            {
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            l.Add(p0);
                        }
                    }
                }
            }
            return(l);
        }
 /// <summary>
 /// returns corresponding concrete type for the given generic argument or generic parameter
 /// </summary>
 /// <param name="typeParameter"></param>
 /// <returns></returns>
 public virtual DataTypePointer GetConcreteType(Type typeParameter)
 {
     if (typeParameter != null)
     {
         IObjectPointer op;
         if (TypeParameters != null)
         {
             if (typeParameter.IsGenericParameter || typeParameter.IsGenericType)
             {
                 MethodBase mb = MethodDef;
                 if (mb != null)
                 {
                     if (mb.ContainsGenericParameters)
                     {
                         Type[] tcs = mb.GetGenericArguments();
                         if (tcs != null && tcs.Length > 0)
                         {
                             for (int i = 0; i < tcs.Length; i++)
                             {
                                 if (tcs[i].Equals(typeParameter))
                                 {
                                     if (i < TypeParameters.Length)
                                     {
                                         return(TypeParameters[i]);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             op = this.Owner;
             IGenericTypePointer igp = null;
             while (op != null)
             {
                 igp = op as IGenericTypePointer;
                 if (igp != null)
                 {
                     break;
                 }
                 op = op.Owner;
             }
             if (igp != null)
             {
                 return(igp.GetConcreteType(typeParameter));
             }
         }
         LocalVariable lv = null;
         op = this.Owner;
         while (op != null)
         {
             lv = op as LocalVariable;
             if (lv != null)
             {
                 break;
             }
             op = op.Owner;
         }
         if (lv != null)
         {
             return(lv.GetConcreteType(typeParameter));
         }
     }
     return(null);
 }