public bool Read(Types.ITypedElement variable) { bool retVal = false; foreach (PreCondition preCondition in PreConditions) { if (preCondition.Reads(variable)) { retVal = true; break; } } if (!retVal && Expression != null) { foreach (Variables.IVariable var in Expression.GetVariables()) { if (var == variable) { retVal = true; break; } } } return(retVal); }
/// <summary> /// Indicates whether this preCondition reads the variable /// </summary> /// <param name="variable"></param> /// <returns></returns> public bool Reads(Types.ITypedElement variable) { bool retVal = false; if (ExpressionTree != null) { foreach (Types.ITypedElement el in ExpressionTree.GetVariables()) { if (el == variable) { retVal = true; break; } } if (!retVal) { Interpreter.Call call = ExpressionTree as Interpreter.Call; if (call != null) { retVal = call.Reads(variable); } } } return(retVal); }
/// <summary> /// Applied to all nodes of the tree /// </summary> /// <param name="obj"></param> /// <param name="visitSubNodes"></param> public override void visit(Generated.Namable obj, bool visitSubNodes) { Namable namable = (Namable)obj; if (obj is Types.ITypedElement) { Types.ITypedElement typedElement = obj as Types.ITypedElement; Types.Type type = typedElement.Type; if (type == null) { namable.AddError("Cannot find type " + typedElement.TypeName); } else if (!(typedElement is Parameter) && !(type is Types.StateMachine)) { Types.ITypedElement enclosingTypedElement = Utils.EnclosingFinder <Types.ITypedElement> .find(typedElement); while (enclosingTypedElement != null) { if (enclosingTypedElement.Type == type) { namable.AddError("Recursive types are not allowed for " + type.Name); enclosingTypedElement = null; } else { enclosingTypedElement = Utils.EnclosingFinder <Types.ITypedElement> .find(enclosingTypedElement); } } } } base.visit(obj, visitSubNodes); }
/// <summary> /// Indicates whether this action reads the variable /// </summary> /// <param name="variable"></param> /// <returns></returns> public bool Reads(Types.ITypedElement variable) { if (Statement != null) { return(Statement.Reads(variable)); } return(false); }
/// <summary> /// Provides the statement which modifies the variable /// </summary> /// <param name="variable"></param> /// <returns>null if no statement modifies the element</returns> public Interpreter.Statement.VariableUpdateStatement Modifies(Types.ITypedElement variable) { if (Statement != null) { return(Statement.Modifies(variable)); } return(null); }
/// <summary> /// Provides the statement which modifies the element /// </summary> /// <param name="variable"></param> /// <returns>null if no statement modifies the element</returns> public override VariableUpdateStatement Modifies(Types.ITypedElement variable) { VariableUpdateStatement retVal = null; if (variable == Target) { retVal = this; } return(retVal); }
/// <summary> /// Indicates whether this statement reads the variable /// </summary> /// <param name="variable"></param> /// <returns></returns> public virtual bool Reads(Types.ITypedElement variable) { bool retVal = false; List <Types.ITypedElement> variablesRead = new List <Types.ITypedElement>(); ReadElements(variablesRead); retVal = variablesRead.Contains(variable); return(retVal); }
/// <summary> /// Indicates whether this statement reads the element /// </summary> /// <param name="variable"></param> /// <returns></returns> public override bool Reads(Types.ITypedElement variable) { foreach (Rules.Action action in Actions) { if (action.Reads(variable)) { return(true); } } return(false); }
/// <summary> /// Indicates whether this call may read a given variable /// </summary> /// <param name="variable"></param> /// <returns></returns> public bool Reads(Types.ITypedElement variable) { bool retVal = false; Function function = Called.getStaticCallable() as Function; if (function != null) { retVal = function.Reads(variable); } return(retVal); }
/// <summary> /// Provides the type of this expression /// </summary> /// <param name="context">The interpretation context</param> /// <returns></returns> public override Types.Type GetExpressionType() { Types.Type retVal = Ref as Types.Type; if (retVal == null) { Types.ITypedElement typedElement = Ref as Types.ITypedElement; if (typedElement != null) { retVal = typedElement.Type; } } return(retVal); }
public bool Reads(Types.ITypedElement variable) { bool retVal = false; foreach (Case cas in Cases) { if (cas.Read(variable)) { retVal = true; break; } } return(retVal); }
/// <summary> /// Provides the statement which modifies the variable /// </summary> /// <param name="variable"></param> /// <returns>null if no statement modifies the element</returns> public Interpreter.Statement.VariableUpdateStatement Modifies(Types.ITypedElement variable) { Interpreter.Statement.VariableUpdateStatement retVal = null; foreach (Action action in Actions) { retVal = action.Modifies(variable); if (retVal != null) { return(retVal); } } return(retVal); }
/// <summary> /// Provides the statement which modifies the variable /// </summary> /// <param name="variable"></param> /// <returns>null if no statement modifies the element</returns> public override VariableUpdateStatement Modifies(Types.ITypedElement variable) { VariableUpdateStatement retVal = null; foreach (Rules.Action action in Actions) { retVal = action.Modifies(variable); if (retVal != null) { return(retVal); } } return(retVal); }
/// <summary> /// Checks the expression and appends errors to the root tree node when inconsistencies are found /// </summary> public override void checkExpression() { Types.Structure structureType = Structure.GetExpressionType() as Types.Structure; if (structureType != null) { foreach (KeyValuePair <string, Expression> pair in Associations) { string name = pair.Key; Expression expression = pair.Value; List <Utils.INamable> targets = new List <Utils.INamable>(); structureType.Find(name, targets); if (targets.Count > 0) { expression.checkExpression(); Types.Type type = expression.GetExpressionType(); if (type != null) { foreach (Utils.INamable namable in targets) { Types.ITypedElement element = namable as Types.ITypedElement; if (element != null && element.Type != null) { if (!element.Type.Match(type)) { AddError("Expression " + expression.ToString() + " type (" + type.FullName + ") does not match the target element " + element.Name + " type (" + element.Type.FullName + ")"); } } } } else { AddError("Expression " + expression.ToString() + " type cannot be found"); } } else { Root.AddError("Cannot find " + name + " in structure " + Structure.ToString()); } } } else { AddError("Cannot find structure type " + Structure.ToString()); } }
/// <summary> /// Provides the right sides used by this expression /// </summary> public List <Types.ITypedElement> GetRightSides() { List <Types.ITypedElement> retVal = new List <Types.ITypedElement>(); List <Utils.INamable> tmp = new List <Utils.INamable>(); fill(tmp, Filter.IsRightSide); foreach (Utils.INamable namable in tmp) { Types.ITypedElement element = namable as Types.ITypedElement; if (element != null) { retVal.Add(element); } } return(retVal); }
public override void visit(Generated.PreCondition obj, bool subNodes) { Rules.PreCondition preCondition = obj as Rules.PreCondition; if (preCondition != null) { try { // Check whether the expression is valid Interpreter.Expression expression = checkExpression(preCondition, preCondition.Condition); if (!preCondition.Dictionary.EFSSystem.BoolType.Match(expression.GetExpressionType())) { preCondition.AddError("Expression type should be Boolean"); } Types.ITypedElement element = OverallTypedElementFinder.INSTANCE.findByName(preCondition, preCondition.findVariable()); if (element != null) { if (element.Type is Types.StateMachine) { if (preCondition.findOperator() != null) { if (preCondition.findOperator().CompareTo("==") == 0) { preCondition.AddWarning("Operator == should not be used for state machines"); } else if (preCondition.findOperator().CompareTo("!=") == 0) { preCondition.AddWarning("Operator != should not be used for state machines"); } } } } } catch (Exception exception) { preCondition.AddException(exception); } } base.visit(obj, subNodes); }
/// <summary> /// Indicates whether this rule reads the content of this variable /// </summary> /// <param name="variable"></param> /// <returns></returns> public bool Reads(Types.ITypedElement variable) { foreach (PreCondition precondition in PreConditions) { if (precondition.Reads(variable)) { return(true); } } foreach (Action action in Actions) { if (action.Reads(variable)) { return(true); } } return(false); }
/// <summary> /// Provides the statement which modifies the variable /// </summary> /// <param name="variable"></param> /// <returns>null if no statement modifies the element</returns> public abstract VariableUpdateStatement Modifies(Types.ITypedElement variable);
public override void visit(Generated.RuleCondition obj, bool subNodes) { Rules.RuleCondition ruleCondition = obj as Rules.RuleCondition; if (ruleCondition != null) { try { bool found = false; ruleCondition.Messages.Clear(); foreach (Rules.PreCondition preCondition in ruleCondition.PreConditions) { Interpreter.BinaryExpression expression = checkExpression(preCondition, preCondition.Expression) as Interpreter.BinaryExpression; if (expression != null) { if (expression.IsSimpleEquality()) { Types.ITypedElement variable = expression.Left.Ref as Types.ITypedElement; if (variable != null) { if (variable.Type != null) { // Check that when preconditions are based on a request, // the corresponding action affects the value Request.Disabled to the same variable if (variable.Type.Name.Equals("Request") && expression.Right != null && expression.Right is Interpreter.UnaryExpression) { Values.IValue val2 = expression.Right.Ref as Values.IValue; if (val2 != null && "Response".CompareTo(val2.Name) == 0) { if (ruleCondition != null) { found = false; foreach (Rules.Action action in ruleCondition.Actions) { Variables.IVariable var = OverallVariableFinder.INSTANCE.findByName(action, preCondition.findVariable()); Interpreter.Statement.VariableUpdateStatement update = action.Modifies(var); if (update != null) { Interpreter.UnaryExpression updateExpr = update.Expression as Interpreter.UnaryExpression; if (updateExpr != null) { Values.IValue val3 = updateExpr.Ref as Values.IValue; if (val3 != null && val3.Name.CompareTo("Disabled") == 0) { found = true; break; } } } } if (!found) { preCondition.AddError("Rules where the Pre conditions is based on a Request type variable must assign that variable the value 'Request.Disabled'"); } } } } } // Check that the outgoing variables are not read if (variable.Mode == Generated.acceptor.VariableModeEnumType.aOutgoing) { if (ruleCondition.Reads(variable)) { preCondition.AddError("An outgoing variable cannot be read"); } } // Check that the incoming variables are not modified if (variable.Mode == Generated.acceptor.VariableModeEnumType.aIncoming) { if (ruleCondition.Modifies(variable) != null) { preCondition.AddError("An incoming variable cannot be written"); } } } } } } } catch (Exception exception) { ruleCondition.AddException(exception); } } base.visit(obj, subNodes); }
/// <summary> /// Provides the possible references for this designator (only available during semantic analysis) /// </summary> /// <param name="instance">the instance on which this element should be found.</param> /// <param name="expectation">the expectation on the element found</param> /// <param name="lastElement">Indicates that this element is the last one in a dereference chain</param> /// <returns></returns> public ReturnValue getReferences(INamable instance, Filter.AcceptableChoice expectation, bool lastElement) { ReturnValue retVal = new ReturnValue(this); if (instance == null) { // Special handling for THIS if (Image.CompareTo("THIS") == 0) { INamable currentElem = Root; while (currentElem != null) { Types.Type type = currentElem as Types.Type; if (type != null) { Types.StateMachine stateMachine = type as Types.StateMachine; while (stateMachine != null) { type = stateMachine; stateMachine = stateMachine.EnclosingStateMachine; } retVal.Add(type); return(retVal); } currentElem = enclosing(currentElem); } return(retVal); } // No enclosing instance. Try to first name of a . separated list of names // . First in the enclosing expression InterpreterTreeNode current = this; while (current != null) { ISubDeclarator subDeclarator = current as ISubDeclarator; if (FillBySubdeclarator(subDeclarator, expectation, retVal) > 0) { // If this is the last element in the dereference chain, stop at first match if (lastElement) { return(retVal); } current = null; } else { current = current.Enclosing; } } // . In the predefined elements addReference(EFSSystem.getPredefinedItem(Image), expectation, retVal); if (lastElement && !retVal.IsEmpty) { return(retVal); } // . In the enclosing items, except the enclosing dictionary since dictionaries are handled in a later step INamable currentNamable = Root; while (currentNamable != null) { Utils.ISubDeclarator subDeclarator = currentNamable as Utils.ISubDeclarator; if (subDeclarator != null && !(subDeclarator is Dictionary)) { if (FillBySubdeclarator(subDeclarator, expectation, retVal) > 0 && lastElement) { return(retVal); } } currentNamable = enclosingSubDeclarator(currentNamable); } // . In the dictionaries declared in the system foreach (Dictionary dictionary in EFSSystem.Dictionaries) { if (FillBySubdeclarator(dictionary, expectation, retVal) > 0 && lastElement) { return(retVal); } Types.NameSpace defaultNameSpace = dictionary.findNameSpace("Default"); if (defaultNameSpace != null) { if (FillBySubdeclarator(defaultNameSpace, expectation, retVal) > 0 && lastElement) { return(retVal); } } } } else { // The instance is provided, hence, this is not the first designator in the . separated list of designators if (instance is Types.ITypedElement && !(instance is Constants.State)) { // If the instance is a typed element, dereference it to its corresponding type Types.ITypedElement element = instance as Types.ITypedElement; if (element.Type != EFSSystem.NoType) { instance = element.Type; } } // Find the element in all enclosing sub declarators of the instance while (instance != null) { Utils.ISubDeclarator subDeclarator = instance as Utils.ISubDeclarator; if (FillBySubdeclarator(subDeclarator, expectation, retVal) > 0) { instance = null; } else { if (instance is Dictionary) { instance = enclosingSubDeclarator(instance); } else { instance = null; } } } } return(retVal); }
/// <summary> /// Provides the statement which modifies the variable /// </summary> /// <param name="variable"></param> /// <returns>null if no statement modifies the element</returns> public override VariableUpdateStatement Modifies(Types.ITypedElement variable) { VariableUpdateStatement retVal = null; return(retVal); }