Exemplo n.º 1
0
        public override IPStmt VisitPrintStmt(PParser.PrintStmtContext context)
        {
            string message = context.StringLiteral().GetText();

            message = message.Substring(1, message.Length - 2); // strip beginning / end double quote
            int numNecessaryArgs = TypeCheckingUtils.PrintStmtNumArgs(message);

            if (numNecessaryArgs == -1)
            {
                throw handler.InvalidPrintFormat(context, context.StringLiteral().Symbol);
            }

            List <IPExpr> args = TypeCheckingUtils.VisitRvalueList(context.rvalueList(), exprVisitor).ToList();

            foreach (IPExpr arg in args)
            {
                if (arg is LinearAccessRefExpr)
                {
                    throw handler.PrintStmtLinearArgument(arg.SourceLocation);
                }
            }

            if (args.Count != numNecessaryArgs)
            {
                throw handler.IncorrectArgumentCount(context, args.Count, numNecessaryArgs);
            }

            return(new PrintStmt(context, message, args));
        }
Exemplo n.º 2
0
        public override IPExpr VisitFormatedString([NotNull] PParser.FormatedStringContext context)
        {
            string baseString = context.StringLiteral().GetText();

            baseString = baseString.Substring(1, baseString.Length - 2); // strip beginning / end double quote
            int numNecessaryArgs = TypeCheckingUtils.PrintStmtNumArgs(baseString);

            if (numNecessaryArgs == -1)
            {
                throw handler.InvalidStringExprFormat(context, context.StringLiteral().Symbol);
            }

            List <IPExpr> args = TypeCheckingUtils.VisitRvalueList(context.rvalueList(), this).ToList();

            foreach (IPExpr arg in args)
            {
                if (arg is LinearAccessRefExpr)
                {
                    throw handler.StringAssignStmtLinearArgument(arg.SourceLocation);
                }
            }

            if (args.Count != numNecessaryArgs)
            {
                throw handler.IncorrectArgumentCount(context, args.Count, numNecessaryArgs);
            }

            return(new StringExpr(context, baseString, args));
        }
Exemplo n.º 3
0
        public override IPStmt VisitStringAssignStmt(PParser.StringAssignStmtContext context)
        {
            IPExpr variable   = exprVisitor.Visit(context.lvalue());
            string baseString = context.StringLiteral().GetText();

            baseString = baseString.Substring(1, baseString.Length - 2); // strip beginning / end double quote
            int numNecessaryArgs = TypeCheckingUtils.PrintStmtNumArgs(baseString);

            if (numNecessaryArgs == -1)
            {
                throw handler.InvalidStringAssignFormat(context, context.StringLiteral().Symbol);
            }

            List <IPExpr> args = TypeCheckingUtils.VisitRvalueList(context.rvalueList(), exprVisitor).ToList();

            foreach (IPExpr arg in args)
            {
                if (arg is LinearAccessRefExpr)
                {
                    throw handler.StringAssignStmtLinearArgument(arg.SourceLocation);
                }
            }

            if (args.Count != numNecessaryArgs)
            {
                throw handler.IncorrectArgumentCount(context, args.Count, numNecessaryArgs);
            }

            if (variable.Type != PrimitiveType.String)
            {
                throw handler.TypeMismatch(context, variable.Type, PrimitiveType.String);
            }

            return(new StringAssignStmt(context, variable, baseString, args));
        }