예제 #1
0
        public override IPExpr VisitChooseExpr(PParser.ChooseExprContext context)
        {
            // if choose is without an argument then its a choose boolean
            if (context.expr() == null)
            {
                return(new ChooseExpr(context, null, PrimitiveType.Bool));
            }

            IPExpr        subExpr     = Visit(context.expr());
            PLanguageType subExprType = subExpr.Type;

            switch (subExprType.Canonicalize())
            {
            case SequenceType seqType:
                return(new ChooseExpr(context, subExpr, seqType.ElementType));

            case SetType setType:
                return(new ChooseExpr(context, subExpr, setType.ElementType));

            case PrimitiveType primType when primType.IsSameTypeAs(PrimitiveType.Int):
                return(new ChooseExpr(context, subExpr, PrimitiveType.Int));

            default:
                throw handler.IllegalChooseSubExprType(context, subExprType);
            }
        }
 public Exception IllegalChooseSubExprType(PParser.ChooseExprContext context, PLanguageType subExprType)
 {
     return(IssueError(context, $"choose expects a parameter of type int (max value) or a seq or a set, got a parameter of type {subExprType}"));
 }