Example #1
0
        public override IPStmt VisitAssertStmt(PParser.AssertStmtContext context)
        {
            IPExpr assertion = exprVisitor.Visit(context.expr());

            if (!PrimitiveType.Bool.IsSameTypeAs(assertion.Type))
            {
                throw handler.TypeMismatch(context.expr(), assertion.Type, PrimitiveType.Bool);
            }
            string message = context.StringLiteral()?.GetText() ?? "";

            return(new AssertStmt(context, assertion, message));
        }
Example #2
0
        public override IPStmt VisitAssertStmt(PParser.AssertStmtContext context)
        {
            var assertion = exprVisitor.Visit(context.expr());

            if (!PrimitiveType.Bool.IsSameTypeAs(assertion.Type))
            {
                throw handler.TypeMismatch(context.expr(), assertion.Type, PrimitiveType.Bool);
            }

            var message = context.StringLiteral()?.GetText() ?? "";

            if (message.StartsWith("\""))
            {
                message = message.Substring(1, message.Length - 2);
            }
            return(new AssertStmt(context, assertion, message));
        }