コード例 #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));
        }
コード例 #2
0
        public override IPStmt VisitPrintStmt(PParser.PrintStmtContext context)
        {
            IPExpr message = exprVisitor.Visit(context.message);

            if (!message.Type.IsSameTypeAs(PrimitiveType.String))
            {
                throw handler.TypeMismatch(context.message, message.Type, PrimitiveType.String);
            }
            return(new PrintStmt(context, message));
        }
コード例 #3
0
ファイル: StatementVisitor.cs プロジェクト: zhaowei19920524/P
        public override IPStmt VisitPrintStmt(PParser.PrintStmtContext context)
        {
            string message          = context.StringLiteral().GetText();
            int    numNecessaryArgs = (from Match match in Regex.Matches(message, @"(?:{{|}}|{(\d+)}|[^{}]+|{|})")
                                       where match.Groups[1].Success
                                       select int.Parse(match.Groups[1].Value) + 1)
                                      .Concat(new[] { 0 })
                                      .Max();

            var args = (from arg in context.rvalueList()?.rvalue() ?? Enumerable.Empty <PParser.RvalueContext>() select exprVisitor.Visit(arg)).ToList();

            if (args.Count != numNecessaryArgs)
            {
                throw handler.IncorrectArgumentCount((ParserRuleContext)context.rvalueList() ?? context,
                                                     args.Count,
                                                     numNecessaryArgs);
            }
            return(new PrintStmt(context, message, args));
        }
コード例 #4
0
 public Exception InvalidPrintFormat(PParser.PrintStmtContext context, IToken symbol)
 {
     return(IssueError(context,
                       symbol,
                       "Print format placeholders must contain only digits. Escape braces by doubling them."));
 }
コード例 #5
0
 public override object VisitPrintStmt(PParser.PrintStmtContext context)
 {
     return(null);
 }