예제 #1
0
 public override Expression ClearConstant(Dictionary <string, Expression> constMapping)
 {
     if (Argument2 != null)
     {
         return(new PrimitiveApplication(Operator, Argument1.ClearConstant(constMapping), Argument2.ClearConstant(constMapping)));
     }
     else
     {
         return(new PrimitiveApplication(Operator, Argument1.ClearConstant(constMapping)));
     }
 }
예제 #2
0
        public IndexedExpression ClearConstant(Dictionary <string, Expression> constMapping)
        {
            Expression newExpression = Expression.ClearConstant(constMapping);

            List <ParallelDefinition> newDefinitions = new List <ParallelDefinition>(Definitions.Count);

            foreach (ParallelDefinition definition in Definitions)
            {
                newDefinitions.Add(definition.ClearConstant(constMapping));
            }

            return(new IndexedExpression(Operator, newDefinitions, newExpression));
        }
        public override Expression ClearConstant(Dictionary <string, Expression> constMapping)
        {
            Expression[] newArgs = new Expression[Arguments.Length];

            for (int i = 0; i < Arguments.Length; i++)
            {
                newArgs[i] = Arguments[i].ClearConstant(constMapping);
            }

            return(new ClassMethodCallInstance(Variable.ClearConstant(constMapping), MethodName, newArgs));
        }
예제 #4
0
파일: If.cs 프로젝트: vu111293/pat-design
 public override Expression ClearConstant(Dictionary <string, Expression> constMapping)
 {
     return(new If(Condition.ClearConstant(constMapping), ThenPart.ClearConstant(constMapping), ElsePart == null ? null : ElsePart.ClearConstant(constMapping)));
 }
예제 #5
0
파일: While.cs 프로젝트: fangld/EDGolog
 public override Expression ClearConstant(Dictionary <string, Expression> constMapping)
 {
     return(new While(Test.ClearConstant(constMapping), Body.ClearConstant(constMapping)));
 }
예제 #6
0
 public override Expression ClearConstant(Dictionary <string, Expression> constMapping)
 {
     return(new ClassProperty(Variable.ClearConstant(constMapping), PropertyName));
 }
 public override Expression ClearConstant(Dictionary <string, Expression> constMapping)
 {
     return(new ClassPropertyAssignment(ClassProperty.ClearConstant(constMapping) as ClassProperty, RightHandExpression.ClearConstant(constMapping)));
 }
예제 #8
0
 public override Expression ClearConstant(Dictionary <string, Expression> constMapping)
 {
     return(new Sequence(FirstPart.ClearConstant(constMapping), SecondPart.ClearConstant(constMapping)));
 }
예제 #9
0
 public override Expression ClearConstant(Dictionary <string, Expression> constMapping)
 {
     return(new LetDefinition(Variable, RightHandExpression.ClearConstant(constMapping)));
 }
예제 #10
0
 public override Expression ClearConstant(Dictionary <string, Expression> constMapping)
 {
     return(new Assignment((constMapping.ContainsKey(LeftHandSide)? constMapping[LeftHandSide].ExpressionID: LeftHandSide), RightHandSide.ClearConstant(constMapping)));
 }
예제 #11
0
 public override Expression ClearConstant(Dictionary <string, Expression> constMapping)
 {
     return(new PropertyAssignment(RecordExpression.ClearConstant(constMapping),
                                   PropertyExpression.ClearConstant(constMapping),
                                   RightHandExpression.ClearConstant(constMapping)));
 }
예제 #12
0
        public static void UpdateClockBounds(Expression expression, Dictionary<string, Expression> constantDB, int oldCeiling, int oldFloor, out int ceiling, out int floor)
        {
            try
            {
                if (constantDB.Count > 0)
                {
                    expression = expression.ClearConstant(constantDB);
                }

                if (!expression.HasVar)
                {
                    ExpressionValue rhv = EvaluatorDenotational.Evaluate(expression, null);

                    if (rhv is IntConstant)
                    {
                        IntConstant v = rhv as IntConstant;
                        ceiling = Math.Max(v.Value, oldCeiling);
                        floor = Math.Min(v.Value, oldFloor);

                        return;
                    }
                }
            }
            catch (Exception ex)
            {

            }

            ceiling = oldCeiling;
            floor = oldFloor;
        }
예제 #13
0
        public static void TestIsIntExpression(Expression p, IToken ID1, string expression, Valuation valuation, Dictionary<string, Expression> ConstantDatabase)
        {
            if (ConstantDatabase.Count > 0)
            {
                p = p.ClearConstant(ConstantDatabase);
            }

            if (p is PrimitiveApplication)
            {
                string Operator = (p as PrimitiveApplication).Operator;
                if (Operator == "||" || Operator == "&&" || Operator == "==" || Operator == "!=" || Operator == ">" ||
                    Operator == "<" || Operator == "!" || Operator == ">=" || Operator == "<=")
                {
                    throw new ParsingException(string.Format(Resources.The_expression__0__must_be_an_integer_expression_,  p + " " + expression), ID1);
                }
                //else
                //{
                //    //recursive test the component inside
                //    TestIsIntExpression((p as PrimitiveApplication).Argument1, ID1, expression, valuation, ConstantDatabase);
                //    if ((p as PrimitiveApplication).Argument2 != null)
                //    {
                //        TestIsIntExpression((p as PrimitiveApplication).Argument2, ID1, expression, valuation, ConstantDatabase);
                //    }
                //}
            }
            else if (p is Variable)
            {
                if (valuation != null && valuation.Variables != null && valuation.Variables.ContainsKey(p.ExpressionID) && !(valuation.Variables[p.ExpressionID] is IntConstant))
                {
                    throw new ParsingException(string.Format(Resources.The_variable__0__must_be_an_integer_variable_, p + " " + expression), ID1);
                }
            }
            else if (p is StaticMethodCall)
            {
                StaticMethodCall call = p as StaticMethodCall;
                switch (call.MethodName)
                {
                    case Common.Classes.Ultility.Constants.ccount:
                    case Common.Classes.Ultility.Constants.csize:
                        return;
                }

                string key = call.MethodName + call.Arguments.Length;

                if (Utilities.CSharpMethods.ContainsKey(key))
                {
                    if (Utilities.CSharpMethods[key].ReturnType.Name == "Int32")
                    {
                        return;
                    }
                }
                else
                {
                    throw new ParsingException(string.Format("The call {0} is not defined.", call.MethodName), ID1);
                }

                throw new ParsingException(string.Format(Resources.The_static_method_call__0__must_return_an_integer_value_, ID1.Text), ID1);

            }
            else if (p is ClassMethodCall)
            {
                ClassMethodCall call = p as ClassMethodCall;
                if (valuation.Variables.ContainsKey(call.Variable))
                {
                    MethodInfo methodInfo = valuation.Variables[call.Variable].GetType().GetMethod(call.MethodName);
                    if (methodInfo != null)
                    {
                        if (methodInfo.ReturnType.Name == "Int32")
                        {
                            return;
                        }
                    }
                }
                else
                {
                    throw new ParsingException(string.Format("The call {0} may not be defined for variable {1}.", call.MethodName, call.Variable), ID1);
                }

                throw new ParsingException(string.Format(Resources.The_method_call__0__must_return_an_integer_value_, p), ID1);

            }
            else if (p is Assignment)
            {
                Assignment assign = p as Assignment;
                TestIsIntExpression(assign.RightHandSide,ID1, expression, valuation, ConstantDatabase);
            }
            else if (p is PropertyAssignment)
            {
                PropertyAssignment assign = p as PropertyAssignment;
                TestIsIntExpression(assign.RightHandExpression, ID1, expression, valuation, ConstantDatabase);
            }
            else if (!(p is IntConstant) && !(p is ClassMethodCall) && !(p is If) && !(p is While) )
            {
                throw new ParsingException(string.Format(Resources.The_expression__0__must_be_an_integer_expression_,  p + " " + expression), ID1);
            }
        }
예제 #14
0
        public static IntConstant EvaluateIntExpression(Expression exp, IToken token, Dictionary<string, Expression> constantDB)
        {
            try
            {
                if (constantDB.Count > 0)
                {
                    exp = exp.ClearConstant(constantDB);
                }

                if (exp.HasVar)
                {
                    List<string> vars = exp.GetVars();
                    throw new ParsingException(string.Format(Resources.Variables___0___can_not_be_used_in_this_expression_, Classes.Ultility.Ultility.PPStringList(vars)) + exp, token);
                }

                ExpressionValue rhv = EvaluatorDenotational.Evaluate(exp, null);

                if (rhv is IntConstant)
                {
                   return rhv as IntConstant;
                }
                else
                {
                    throw new ParsingException(Resources.The_expression_should_return_an_integer_value_, token);
                }
            }
            catch (Exception ex)
            {
                throw new ParsingException(ex.Message, token);
            }
        }
예제 #15
0
        //public static void CheckParameterVarUsedInMathExpression(Expression e1, Dictionary<string, string> ParameterVariables, IToken token)
        //{
        //    if (e1 is Variable)
        //    {
        //        string name = ((Variable) e1).VarName;
        //        if (ParameterVariables.ContainsKey(name))
        //        {
        //            throw new ParsingException("Can not use parameter variable " + name + " in math expression!", token);
        //        }
        //    }
        //}
        public static void CheckTimedExpressionWithGlobalVariable(Expression e1, IToken token, Dictionary<string, Expression> ConstantDatabase, List<IToken> GlobalVarNames)
        {
            if (ConstantDatabase.Count > 0)
            {
                e1 = e1.ClearConstant(ConstantDatabase);
            }

            List<string> evars = e1.GetVars();
            if (evars.Count >= 1)
            {
                foreach (string evar in evars)
                {
                    foreach (IToken gvar in GlobalVarNames)
                    {
                        if (gvar.Text == evar)
                        {
                            throw new ParsingException("Global variable (" + evar + ") cannot be used in timed process!", token);
                        }
                    }

                }
            }
        }