public IOPrintNode CreateIOPrintNodeForAssertNode(AssertNode assertNode) { assertNode.IOPrintNode = new IOPrintNode(assertNode.Expression.Token); assertNode.IOPrintNode.AddExpression(new StringValueNode(StringFormatter.formatFailedAssertion(assertNode))); return(assertNode.IOPrintNode); }
public AssertNode CreateAssertNode(StatementsNode statementsNode, Token t) { AssertNode assertNode = new AssertNode(t); statementsNode.Statement = assertNode; return(assertNode); }
/// <summary> /// Checks the static semantic constraints of an AssertNode. /// </summary> /// <returns>An ISemanticCheckValue.</returns> /// <param name="node">Node.</param> public ISemanticCheckValue VisitAssertNode(AssertNode node) { // get the evaluation of this node IProperty evaluation = node.Accept(this.typeChecker).asProperty(); // check that the evaluation is a boolean value if (!checkPropertyType(evaluation, TokenType.BOOL_VAL)) { analyzer.notifyError(new IllegalTypeError(node)); } return(voidProperty); }
/// <summary> /// Visits the assert node. /// </summary> /// <returns>An ISemanticCheckValue.</returns> /// <param name="node">Node.</param> public ISemanticCheckValue VisitAssertNode(AssertNode node) { // Evaluate the expression and if the result is false, execute the IOPrintNode // to inform the user about the failed assertion. // Note that this does not halt the execution! IProperty evaluation = node.Accept(this.evaluator).asProperty(); if (!evaluation.asBoolean()) { node.IOPrintNode.Accept(this); } return(voidProperty); }
/// <summary> /// Parses an assert statement into an AssertNode /// </summary> /// <returns>The next token.</returns> /// <param name="token">Token.</param> /// <param name="statementsNode">A StatementsNode.</param> private Token ParseAssert(Token token, StatementsNode statementsNode) { try { Token next = scanner.getNextToken(token); match(next, TokenType.PARENTHESIS_LEFT); // create the AssertNode AssertNode assertNode = nodeBuilder.CreateAssertNode(statementsNode, token); // parse the expression to assert when executed next = ParseExpression(scanner.getNextToken(next), assertNode); match(next, TokenType.PARENTHESIS_RIGHT); // create an IOPrinterNode to print a message in case of a failed assertion nodeBuilder.CreateIOPrintNodeForAssertNode(assertNode); return(scanner.getNextToken(next)); } catch (UnexpectedTokenException ex) { return(FastForwardToStatementEnd(ex)); } }
/// <summary> /// Visits the assert node. /// </summary> /// <returns>An ISemanticCheckValue.</returns> /// <param name="node">Node.</param> public ISemanticCheckValue VisitAssertNode(AssertNode node) { // evaluate the expression and return it return(node.Expression.Accept(this)); }
public static string formatFailedAssertion(AssertNode assertNode) { return(line(StringFormattingConstants.ASSERTION_FAILED + assertNode.Expression.ToString())); }
/// <summary> /// Visits the assert node. /// </summary> /// <returns>An ISemanticCheckValue.</returns> /// <param name="node">Node.</param> public ISemanticCheckValue VisitAssertNode(AssertNode node) { // return the evaluation of the node's expression return(getEvaluation(node.Expression)); }