/// <summary>
 /// Processes the child of the current reader position into a child of this object.
 /// </summary>
 /// <param name="reader">The XML reader</param>
 protected override void ReadXmlChild(XmlReader reader) {
     if(XmlInitializerName == reader.Name) {
         Initializer = XmlSerialization.ReadChildExpression(reader);
     } else {
         base.ReadXmlChild(reader);
     }
 }
Example #2
0
 /// <summary>
 /// Processes the child of the current reader position into a child of this object.
 /// </summary>
 /// <param name="reader">The XML reader</param>
 protected override void ReadXmlChild(XmlReader reader) {
     if(XmlLockExpressionName == reader.Name) {
         LockExpression = XmlSerialization.ReadChildExpression(reader);
     } else {
         base.ReadXmlChild(reader);
     }
 }
Example #3
0
 /// <summary>
 /// Processes the child of the current reader position into a child of this object.
 /// </summary>
 /// <param name="reader">The XML reader</param>
 protected override void ReadXmlChild(XmlReader reader) {
     if(XmlImportedNamespaceName == reader.Name) {
         ImportedNamespace = XmlSerialization.ReadChildExpression(reader);
     } else {
         base.ReadXmlChild(reader);
     }
 }
        /// <summary>
        /// Analyze the expression and return NameUse it belongs
        /// </summary>
        /// <param name="exp"></param>
        /// <param name="IsFieldUpdate"></param>
        /// <returns></returns>
        private NameUse GetNameUseOrObj(Expression exp, out bool IsFieldUpdate)
        {
            if(!exp.Components.Any()) {
                IsFieldUpdate = false;
                return exp as NameUse;
            }
            var compList = exp.Components.ToList();
            //check if it contains sub assignment expression
            if(compList.Count > 2) {
                UpdateByExpToTheEnd(compList, 0);

                IsFieldUpdate = false;
                for(int curPos = 0; curPos < compList.Count; curPos += 2) {
                    if(curPos + 1 < compList.Count) {
                        var expOp = compList.ElementAt(curPos + 1) as OperatorUse;
                        if(expOp != null) {
                            if(IsNameInclusionOp(expOp)) {
                                //Has connection op (Check one matching by assuming the inputs are syntax correct.)
                                IsFieldUpdate = true;
                            }
                        }
                    }

                    NameUse nu = compList.ElementAt(curPos) as NameUse;
                    if(nu != null && nu.Name != "this" && nu.Name != "base") {

                        return nu;
                    }
                }
                return null;

                //if(compList.First() is NameUse) {
                //    //Has connection op (Check one matching by assuming the inputs are syntax correct.)
                //    var expOp = compList.ElementAt(1) as OperatorUse;
                //    if(expOp != null) {
                //        foreach(var op in NameInclusionOperators) {
                //            if(op.Equals(expOp.Text)) {
                //                IsFieldUpdate = true;
                //                // check non static field
                //                var field = compList.Last() as NameUse;
                //                if(field != null && !field.GetType().IsSubclassOf(typeof(NameUse))) {
                //                    VariableDeclaration vd = field.FindMatches().FirstOrDefault() as VariableDeclaration;

                //                    //if(vd != 0 && vd.) {

                //                    //}
                //                }
                //            }
                //        }
                //    }
                //}
                //return compList.First() as NameUse;
            }
            IsFieldUpdate = false;
            return null;
        }
        /// <summary>
        /// update info based on the expression
        /// </summary>
        /// <param name="exp"></param>
        public void UpdateByExpression(Expression exp)
        {
            if(exp is VariableDeclaration) {
                //variable declaration expression
                var vdExp = (VariableDeclaration)exp;
                VariableInfo vi = new VariableInfo(vdExp);
                VariablesInfo.Add(vi);

                //update if it contains assignment
                if(vdExp.Initializer != null) {
                    var subExps = new List<Expression>();
                    if(vdExp.Initializer.Components.Count == 0) {
                        subExps.Add(vdExp.Initializer);
                    } else {
                        subExps = vdExp.Initializer.Components.ToList();
                    }
                    UpdateAssignmentExpRightHand(subExps, 0, vi, false);
                    //TO DO: ex. = new school()
                }
            } else if(exp is MethodCall) {
                //Method call expression
                var mcExp = (MethodCall)exp;
                UpdateMethodCall(mcExp);

            } else {
                    //Update the expression
                    var subExps = exp.Components.ToList();

                    int curPos = 0;

                    // Checks keyword new
                    if(subExps.Count > 0) {
                        var oUse = subExps.ElementAt(0) as OperatorUse;
                        if(oUse != null && oUse.Text == "new") {
                            if(InReturnStmt > 0) {
                                IsReturnNewObj = true;
                            }
                            curPos++;
                        }
                    }
                    UpdateByExpToTheEnd(subExps, curPos);
            }
        }
Example #6
0
 /// <summary>
 /// Adds the given argument to the Arguments collection.
 /// </summary>
 /// <param name="arg">The argument to add.</param>
 public void AddArgument(Expression arg) {
     if(arg == null) { throw new ArgumentNullException("arg"); }
     arg.ParentExpression = this;
     arg.ParentStatement = this.ParentStatement;
     argumentList.Add(arg);
 }
Example #7
0
 /// <summary>
 /// Adds the given Expression to the Components collection. Nothing will be done if <paramref name="component"/> is null.
 /// </summary>
 /// <param name="component">The component to add.</param>
 public virtual void AddComponent(Expression component) {
     if(null != component) {
         component.ParentExpression = this;
         componentsList.Add(component);
     }
 }
        //This method is used to return the value of an expression. For example, a "MethodCall" expression would return "FunctionCall" for rebuild a string.
        public string GetExpCont(Expression exp, List<string[]> variables)
        {
            string teststring = "";

            if (exp is MethodCall) return "FunctionCall";

            if (exp is LiteralUse)
            {
                LiteralUse expl = (LiteralUse)exp;
                teststring = TakeQuotOff(expl.Text);
                return teststring;
            }

            if (exp is VariableUse)
            {
                teststring = GetVariableCont(exp.ToString(), variables);
                if (teststring == "") teststring = exp.ToString();
                return teststring;
            }

            return "codeexpression";
        }
 //When we know an expression is a "MethodCall", we check it's arguments and handle the case like argument is m.call(string1 + string2). String1 plus string2 might be a invocation.
 public string handleFunctionCall(Expression exp, List<string[]> variables)
 {
     string returnResult = "FunctionCall";
     MethodCall mc = (MethodCall)exp;
     if (mc.Arguments.Count == 0) return returnResult;
     var arg = mc.Arguments[0];
     if (arg.Components.Count == 0) return returnResult;
     var exps = arg.Components;
     string callPara = "";
     for (int i = 0; i < exps.Count; i++)
     {
         var texp = exps.ElementAt(i);
         if (texp is LiteralUse || texp is VariableUse)
         {
             callPara += GetExpCont(texp, variables);
             continue;
         }
         if ((texp is OperatorUse) && texp.ToString() == "+" && i + 1 < exps.Count)
         {
             i = i + 1;
             callPara += GetExpCont(exps.ElementAt(i), variables);
             continue;
         }
     }
     UpdateVariable("argument", variables, callPara);
     return returnResult;
 }