Exemple #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="method"></param>
 /// <returns>CodeEventReferenceExpression</returns>
 public override CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue)
 {
     if (IsStatic)
     {
         if (typeof(ProjectResources).Equals(ObjectType))
         {
             ProjectResources rm = ((LimnorProject)(method.ModuleProject)).GetProjectSingleData <ProjectResources>();
             return(new CodeEventReferenceExpression(new CodeTypeReferenceExpression(rm.HelpClassName), this.MemberName));
         }
         return(new CodeEventReferenceExpression(new CodeTypeReferenceExpression(ObjectType), this.MemberName));
     }
     else
     {
         CodeExpression targetObject;
         if (this.Owner != null)
         {
             targetObject = this.Owner.GetReferenceCode(method, statements, forValue);
         }
         else
         {
             targetObject = this.Holder.GetReferenceCode(method, statements, forValue);
         }
         return(new CodeEventReferenceExpression(OnGetTargetObject(targetObject), this.MemberName));
     }
 }
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            MathNode.Trace("{0}.ExportCode", this.GetType().Name);
            int n = ChildNodeCount;

            CodeExpression[] ps;
            if (n > 0)
            {
                ps = new CodeExpression[n];
                for (int i = 0; i < n; i++)
                {
                    ps[i] = this[i].ExportCode(method);
                }
            }
            else
            {
                ps = new CodeExpression[] { };
            }
            if (_targetObject == null)
            {
                _targetObject = new CodeThisReferenceExpression();
            }
            CodeMethodInvokeExpression e = new CodeMethodInvokeExpression(
                _targetObject, _functionName, ps);

            return(e);
        }
Exemple #3
0
        public override void ExportCodeStatements(IMethodCompile method)
        {
            MathNode.Trace("ExportCodeStatements for {0}", this.GetType());
            //0: start
            //1: end
            //2: function
            //3: dx             IsParam
            //4: sum            IsLocal
            //5: summing index  IsLocal IsParam
            base.ExportCodeStatements(method);
            //assign code expression to all x in the function
            OnPrepareVariable(method);
            MathNodeVariable.DeclareVariable(method.MethodCode.Statements, (IVariable)this[4]);
            CodeVariableReferenceExpression sum = new CodeVariableReferenceExpression(((IVariable)this[4]).CodeVariableName);

            method.MethodCode.Statements.Add(new CodeAssignStatement(sum, new CodePrimitiveExpression(0)));
            CodeExpression         c5  = this.GetParameterCode(method, 5);
            CodeIterationStatement cis = new CodeIterationStatement(
                new CodeVariableDeclarationStatement(this[5].DataType.Type, ((IVariable)this[5]).CodeVariableName,
                                                     new CodePrimitiveExpression(1)),
                new CodeBinaryOperatorExpression(c5, CodeBinaryOperatorType.LessThanOrEqual, new CodePrimitiveExpression(_intervals - 1)),
                new CodeAssignStatement(c5, new CodeBinaryOperatorExpression(c5, CodeBinaryOperatorType.Add, new CodePrimitiveExpression(1))),
                new CodeStatement[] {
                new CodeAssignStatement(sum, new CodeBinaryOperatorExpression(sum, CodeBinaryOperatorType.Add, this.GetParameterCode(method, 2)))
            });

            method.MethodCode.Statements.Add(cis);
            //clear code expression to all x in the function
            this[2].AssignCodeExp(null, ((MathNodeVariable)this[3]).CodeVariableName);
        }
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            this[0].CompileDataType = new RaisDataType(typeof(string));
            CodeExpression e = this[0].ExportCode(method);

            return(new CodeMethodInvokeExpression(e, "Trim"));
        }
Exemple #5
0
 /// <summary>
 /// find linked node and use that node's code.
 /// if not found then use default value
 /// </summary>
 /// <returns></returns>
 public override System.CodeDom.CodeExpression ExportCode(IMethodCompile method)
 {
     MathNode.Trace("{0}.ExportCode", this.GetType().Name);
     if (this.InPort != null)
     {
         if (this.InPort.LinkedPortID != 0)
         {
             MathExpItem mathParent = root.ContainerMathItem;
             if (mathParent == null)
             {
                 throw new MathException(XmlSerialization.FormatString("ExportCode for Default value: Linked port ID {0}. MathNodeRoot missing container.", this.InPort.LinkedPortID));
             }
             if (mathParent.Parent == null)
             {
                 throw new MathException(XmlSerialization.FormatString("ExportCode for Default value: Linked port ID {0}. MathExpItem missing container.", this.InPort.LinkedPortID));
             }
             MathExpItem item = mathParent.Parent.GetItemByID(this.InPort.LinkedPortID);
             if (item == null)
             {
                 throw new MathException(XmlSerialization.FormatString("ExportCode for Default value: Linked port ID {0} does not point to a valid port", this.InPort.LinkedPortID));
             }
             return(item.ReturnCodeExpression(method));
         }
     }
     return(ValueTypeUtil.GetDefaultValueByType(this.DataType.Type));
 }
        /// <summary>
        /// generate local variables and code to do the calculation of the math.
        /// the calculation result is assigned to the variable this[4]
        /// </summary>
        /// <returns></returns>
        public override void ExportCodeStatements(IMethodCompile method)
        {
            MathNode.Trace("ExportCodeStatements for {0}", this.GetType());
            //0:function
            //1:index
            //2:begin
            //3:end
            //4:sum
            OnPrepareVariable(method);
            CodeVariableReferenceExpression  sum = new CodeVariableReferenceExpression(((IVariable)this[4]).CodeVariableName);
            CodeVariableDeclarationStatement p;

            if (((IVariable)this[4]).VariableType.Type.IsValueType)
            {
                p = new CodeVariableDeclarationStatement(((IVariable)this[4]).VariableType.Type, ((IVariable)this[4]).CodeVariableName);
            }
            else
            {
                p = new CodeVariableDeclarationStatement(((IVariable)this[4]).VariableType.Type, ((IVariable)this[4]).CodeVariableName,
                                                         ValueTypeUtil.GetDefaultCodeByType(((IVariable)this[4]).VariableType.Type));
            }
            method.MethodCode.Statements.Add(p);
            CodeExpression         idx = this[1].ExportCode(method);
            CodeIterationStatement cis = new CodeIterationStatement(
                new CodeVariableDeclarationStatement(this[1].DataType.Type, ((IVariable)this[1]).CodeVariableName,
                                                     this[2].ExportCode(method)),
                new CodeBinaryOperatorExpression(idx, CodeBinaryOperatorType.LessThanOrEqual, this[3].ExportCode(method)),
                new CodeAssignStatement(idx, new CodeBinaryOperatorExpression(idx, CodeBinaryOperatorType.Add, new CodePrimitiveExpression(1))),
                new CodeStatement[] {
                new CodeAssignStatement(sum, new CodeBinaryOperatorExpression(sum, CodeBinaryOperatorType.Add, this[0].ExportCode(method)))
            });

            method.MethodCode.Statements.Add(cis);
        }
Exemple #7
0
        public override void ExportCodeStatements(IMethodCompile method)
        {
            RaisDataType targetType = this[0].DataType;
            RaisDataType sourceType = this[1].DataType;
            Type         target     = targetType.Type;
            Type         source     = sourceType.Type;

            if (target.Equals(source))
            {
                MathNode.Trace("MathNodeAssign, code 1: same type:{0}", target);
                method.MethodCode.Statements.Add(new CodeAssignStatement(this[0].ExportCode(method), this[1].ExportCode(method)));
            }
            else
            {
                MathNode.Trace("MathNodeAssign");
                CodeExpression code = RaisDataType.GetConversionCode(sourceType, this[1].ExportCode(method), targetType, method.MethodCode.Statements);
                if (code != null)
                {
                    method.MethodCode.Statements.Add(new CodeAssignStatement(this[0].ExportCode(method), code));
                }
                else
                {
                    if (!target.Equals(typeof(void)))
                    {
                    }
                }
            }
        }
Exemple #8
0
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            MathNode.Trace("{0}.ExportCode", this.GetType().Name);
            int n = ChildNodeCount;

            CodeExpression[] ps;
            if (n > 0)
            {
                ps = new CodeExpression[n];
                for (int i = 0; i < n; i++)
                {
                    this[i].CompileDataType = new RaisDataType(typeof(int));
                    ps[i] = this[i].ExportCode(method);
                }
            }
            else
            {
                ps = new CodeExpression[] { };
            }
            CodeExpression[] cp = new CodeExpression[1];
            cp[0] = new CodeMethodInvokeExpression(new CodeMethodInvokeExpression(
                                                       new CodeTypeReferenceExpression(typeof(Guid)), "NewGuid", new CodeExpression[] { }
                                                       ), "GetHashCode", new CodeExpression[] { });
            CodeMethodInvokeExpression e = new CodeMethodInvokeExpression(
                new CodeObjectCreateExpression(typeof(Random), cp), "Next", ps);

            return(e);
        }
Exemple #9
0
        public override System.CodeDom.CodeExpression ExportCode(IMethodCompile method)
        {
            int n = Branches;

            MathNode.Trace("{0}.ExportCode: reference to variable '{1}'", this.GetType().Name, ((IVariable)this[n + 1]).CodeVariableName);
            return(new CodeVariableReferenceExpression(((IVariable)this[n + 1]).CodeVariableName));
        }
Exemple #10
0
        public CodeStatement[] ExportStatements(ILimnorCodeCompiler compiler, IMethodCompile methodToCompile)
        {
            List <CodeStatement> ss = new List <CodeStatement>();

            //TBD: create statements for _list
            return(ss.ToArray());
        }
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            CodeStatementCollection supprtStatements = method.MethodCode.Statements;

            if (_passin != null)
            {
                MathNode.Trace("MathNodeVariable.ExportCode returns _passin");
                return(_passin);
            }
            CodeExpression code = this.MathExpression.GetMappedCode(this, method, supprtStatements, true);

            if (code != null)
            {
                return(code);
            }
            //if this variable links to a method parameter then the code is a reference to that parameter
            if (this.InPort != null)
            {
                MathExpItem item = this.root.RootContainer.GetItemByID(this.InPort.LinkedPortID);
                if (item != null)
                {
                    MathNode.Trace("variable:{0} linked to MathExpItem: {1}", this.TraceInfo, item.MathExpression.TraceInfo);
                    return(item.ReturnCodeExpression(method));
                }
            }
            if (!NoAutoDeclare)
            {
                DeclareVariable(supprtStatements, this);
            }
            MathNode.Trace("MathNodeVariable.ExportCode returns variable reference to {0}", this.CodeVariableName);
            return(new CodeVariableReferenceExpression(this.CodeVariableName));
        }
Exemple #12
0
 protected void Arguements(IMethodCompile method, List <CodeExpression> args)
 {
     if (this[0] is MathNodeStringAdd)
     {
         List <CodeExpression> left = new List <CodeExpression>();
         ((MathNodeStringAdd)this[0]).Arguements(method, left);
         args.AddRange(left);
     }
     else
     {
         this[0].CompileDataType = new RaisDataType(typeof(object));
         args.Add(this[0].ExportCode(method));
     }
     if (this[1] is MathNodeStringAdd)
     {
         List <CodeExpression> right = new List <CodeExpression>();
         ((MathNodeStringAdd)this[1]).Arguements(method, right);
         args.AddRange(right);
     }
     else
     {
         this[1].CompileDataType = new RaisDataType(typeof(object));
         args.Add(this[1].ExportCode(method));
     }
 }
Exemple #13
0
 public override CodeExpression ExportCode(IMethodCompile method)
 {
     if (string.IsNullOrEmpty(FieldName))
     {
         throw new DesignerException("Using action input but the previous action does not have an output. Change the math expression to not use action input");
     }
     return(new CodeVariableReferenceExpression(FieldName));
 }
Exemple #14
0
 public CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue)
 {
     if (string.IsNullOrEmpty(CodeName))
     {
         return(null);
     }
     return(new CodeVariableReferenceExpression(CodeName));
 }
 public override CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue)
 {
     if (Project != null && Project.ProjectType == EnumProjectType.WebAppAspx)
     {
         return(CompilerUtil.GetWebRequestValue(this.DataPassingCodeName));
     }
     return(new CodeVariableReferenceExpression(CodeName));
 }
Exemple #16
0
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            MathNode.Trace("{0}.ExportCode", this.GetType().Name);
            CodeExpression e1 = this[0].ExportCode(method);
            CodeExpression e2 = this[1].ExportCode(method);

            return(new CodeBinaryOperatorExpression(e1, operaterType, e2));
        }
 public CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue)
 {
     if (_methodPointer != null)
     {
         return(_methodPointer.GetReferenceCode(method, statements, forValue));
     }
     return(null);
 }
 public CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue)
 {
     if (_exp != null)
     {
         return(_exp.ReturnCodeExpression(method));
     }
     return(null);
 }
 public CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue)
 {
     if (forValue)
     {
         return(new CodeTypeOfExpression(ClassType));
     }
     return(new CodeTypeReferenceExpression(ClassType));
 }
Exemple #20
0
 public CodeExpression GetReferenceCode(IMethodCompile method)
 {
     if (_prop != null)
     {
         return(_prop.GetReferenceCode(method));
     }
     return(null);
 }
 public CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue)
 {
     if (Event != null)
     {
         Event.SetCompileHolder(_holder);
         return(Event.GetReferenceCode(method, statements, forValue));
     }
     return(null);
 }
        /// <summary>
        /// indices for accessing array item
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="method"></param>
        /// <returns></returns>
        public override CodeExpression[] GetIndexCodes(MethodInfoPointer owner, IMethodCompile method, UInt32 branchId)
        {
            ParameterInfo[]        ps = owner.Info;
            SubMethodParameterInfo p  = (SubMethodParameterInfo)ps[0];

            CodeExpression[] pss = new CodeExpression[1];
            pss[0] = new CodeVariableReferenceExpression(codeName2(p.CodeName, branchId));
            return(pss);
        }
Exemple #23
0
 public override CodeExpression ExportCode(IMethodCompile method)
 {
     MathNode.Trace("{0}.ExportCode", this.GetType().Name);
     if (this.StringLength <= 0)
     {
         this.StringLength = 10;
     }
     return(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(WinUtil)), "GetRandomString", new CodePrimitiveExpression(this.StringLength)));
 }
 public CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue)
 {
     tryDeseirialize();
     if (_parameter == null)
     {
         return(null);
     }
     return(_parameter.GetReferenceCode(method, statements, forValue));
 }
Exemple #25
0
 public override CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue)
 {
     if (IsLibType)
     {
         return(new CodeTypeOfExpression(this.BaseClassType));
     }
     else
     {
         return(new CodeTypeOfExpression(this.TypeString));
     }
 }
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            MathNode.Trace("{0}.ExportCode", this.GetType().Name);
            CodeExpression e = this[0].ExportCode(method);

            if (!this[0].DataType.Type.Equals(typeof(bool)))
            {
                e = new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression(typeof(Convert)), "ToBoolean", new CodeExpression[] { e });
            }
            return(new CodeBinaryOperatorExpression(e, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(false)));
        }
 public CodeExpression ExportCode(IMethodCompile method)
 {
     if (_hasData && _exp != null)
     {
         MathNodeNumber mn = _exp[1] as MathNodeNumber;
         if (mn == null || !mn.IsPlaceHolder)
         {
             return(_exp.ExportCode(method));
         }
     }
     return(null);
 }
        public override CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue)
        {
            CodeExpression propOwner;

            propOwner = this.Owner.GetReferenceCode(method, statements, forValue);
            if (string.IsNullOrEmpty(MemberName))
            {
                throw new DesignerException("name is null at {0}.GetReferenceCode", this.GetType());
            }
            CodeCastExpression ce = new CodeCastExpression(_interfaceType, propOwner);

            return(new CodePropertyReferenceExpression(ce, MemberName));
        }
Exemple #29
0
        protected override void OnPrepareVariable(IMethodCompile method)
        {
            MathNode.Trace("OnPrepareVariable for {0}", this.GetType());
            CodeExpression cp = new CodeBinaryOperatorExpression(this.GetParameterCode(method, 0), CodeBinaryOperatorType.Add,
                                                                 new CodeBinaryOperatorExpression(this.GetParameterCode(method, 5), CodeBinaryOperatorType.Multiply,
                                                                                                  new CodeBinaryOperatorExpression(
                                                                                                      new CodeBinaryOperatorExpression(this.GetParameterCode(method, 1), CodeBinaryOperatorType.Subtract, this.GetParameterCode(method, 0)), CodeBinaryOperatorType.Divide,
                                                                                                      new CodePrimitiveExpression(_intervals))));

            //this[3] is the x, this[2] is the function
            //for all x in the function, the code expression is cp
            this[2].AssignCodeExp(cp, ((MathNodeVariable)this[3]).CodeVariableName);
        }
Exemple #30
0
 /// <summary>
 /// get a CodeExpression representing T[i]?
 /// </summary>
 /// <param name="methodCompile"></param>
 /// <param name="statements"></param>
 /// <param name="method"></param>
 /// <param name="forValue"></param>
 /// <returns></returns>
 public CodeExpression GetReferenceCode(IMethodCompile methodCompile, CodeStatementCollection statements, MethodPointer method, CodeExpression[] ps, bool forValue)
 {
     if (string.Compare(method.MethodName, "Get", StringComparison.Ordinal) == 0)
     {
         CodeExpression ce = new CodeArrayIndexerExpression(GetReferenceCode(methodCompile, statements, forValue), ps);
         return(ce);
     }
     else if (string.Compare(method.MethodName, "Set", StringComparison.Ordinal) == 0)
     {
         CodeExpression ce = new CodeArrayIndexerExpression(GetReferenceCode(methodCompile, statements, forValue), ps[0]);
         return(ce);
     }
     return(null);
 }