Ejemplo n.º 1
0
        private List <IPStmt> SimplifyStatement(IPStmt statement)
        {
            Antlr4.Runtime.ParserRuleContext location = statement?.SourceLocation;
            switch (statement)
            {
            case null:
                throw new ArgumentNullException(nameof(statement));

            case AnnounceStmt announceStmt:
                (IExprTerm annEvt, List <IPStmt> annEvtDeps)         = SimplifyExpression(announceStmt.PEvent);
                (IExprTerm annPayload, List <IPStmt> annPayloadDeps) = announceStmt.Payload == null
                        ? (null, new List <IPStmt>())
                        : SimplifyExpression(announceStmt.Payload);
                return(annEvtDeps.Concat(annPayloadDeps)
                       .Concat(new[]
                {
                    new AnnounceStmt(location, annEvt, annPayload)
                })
                       .ToList());

            case AssertStmt assertStmt:
                (IExprTerm assertExpr, List <IPStmt> assertDeps)   = SimplifyExpression(assertStmt.Assertion);
                (IExprTerm messageExpr, List <IPStmt> messageDeps) = SimplifyExpression(assertStmt.Message);

                return(assertDeps.Concat(messageDeps).Concat(new[]
                {
                    new AssertStmt(location, assertExpr, messageExpr)
                })
                       .ToList());

            case AssignStmt assignStmt:
                (IPExpr assignLV, List <IPStmt> assignLVDeps)    = SimplifyLvalue(assignStmt.Location);
                (IExprTerm assignRV, List <IPStmt> assignRVDeps) = SimplifyRvalue(assignStmt.Value);
                IPStmt assignment;
                // If temporary returned, then automatically move.
                if (assignRV is VariableAccessExpr variableRef &&
                    variableRef.Variable.Role.HasFlag(VariableRole.Temp))
                {
                    assignment = new MoveAssignStmt(location, assignLV, variableRef.Variable);
                }
                else
                {
                    assignment = new AssignStmt(location, assignLV, new CloneExpr(assignRV));
                }

                return(assignLVDeps.Concat(assignRVDeps).Concat(new[] { assignment }).ToList());
Ejemplo n.º 2
0
 public Exception MovedField(MoveAssignStmt moveAssignStmt)
 {
     return(IssueError(moveAssignStmt.SourceLocation, $"attempted to move field {moveAssignStmt.FromVariable}"));
 }