Skip to content

Commit

Permalink
getting swaps to pass the listener
Browse files Browse the repository at this point in the history
  • Loading branch information
mbellotti committed Mar 14, 2023
1 parent 19099a0 commit 9aa7835
Show file tree
Hide file tree
Showing 5 changed files with 366 additions and 358 deletions.
2 changes: 1 addition & 1 deletion grammar/FaultParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ globalDecl
;

swap
: operand '=' (functionLit | numeric | string_ | bool_ | operandName | prefix | solvable)
: paramCall '=' (functionLit | numeric | string_ | bool_ | operandName | prefix | solvable)
;

componentDecl
Expand Down
15 changes: 12 additions & 3 deletions listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,15 @@ func (l *FaultListener) ExitRunBlock(c *parser.RunBlockContext) {
}
steps := c.AllRunStep()
for i := len(steps) - 1; i >= 0; i-- {
v := steps[i]
ex := l.pop()

if ex.TokenLiteral() == "SWAP" {
i++ //Swaps are the same step as the instance that initializes them
}

switch t := ex.(type) {
case *ast.Instance:
token2 := util.GenerateToken("FUNCTION", "FUNCTION", v.(*parser.RunInitContext).GetStart(), v.(*parser.RunInitContext).GetStop())
token2 := ex.GetToken()

s := &ast.ExpressionStatement{
Token: token2,
Expand All @@ -661,7 +665,7 @@ func (l *FaultListener) ExitRunBlock(c *parser.RunBlockContext) {
case *ast.ParallelFunctions:
sl.Statements = append([]ast.Statement{t}, sl.Statements...)
case ast.Expression:
token2 := util.GenerateToken("FUNCTION", "FUNCTION", v.(*parser.RunInitContext).GetStart(), v.(*parser.RunInitContext).GetStop())
token2 := ex.GetToken()
n := l.packageCallsAsRunSteps(t)

s := &ast.ExpressionStatement{
Expand Down Expand Up @@ -722,6 +726,9 @@ func (l *FaultListener) ExitRunInit(c *parser.RunInitContext) {

token2 := util.GenerateToken("IDENT", "IDENT", c.GetStart(), c.GetStop())

// Check for swaps
swaps := l.getSwaps()

ident := &ast.Identifier{Token: token2}
switch len(txt) {
case 1:
Expand Down Expand Up @@ -756,6 +763,8 @@ func (l *FaultListener) ExitRunInit(c *parser.RunInitContext) {
Name: right,
Order: order,
})

l.pushN(swaps)
}

func (l *FaultListener) ExitRunStepExpr(c *parser.RunStepExprContext) {
Expand Down
6 changes: 3 additions & 3 deletions listener/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func TestThis(t *testing.T) {
func TestClock(t *testing.T) {
test := `spec test1;
def foo = flow{
bar: func{1+clock;},
bar: func{1+now;},
};
`
_, spec := prepTest(test, nil)
Expand Down Expand Up @@ -416,7 +416,7 @@ func TestClockRun(t *testing.T) {
bar: func{1+this;},
};
for 1 run {
clock;
now;
}
`
_, spec := prepTest(test, nil)
Expand Down Expand Up @@ -1654,7 +1654,7 @@ func TestUnknown(t *testing.T) {

}

func TestSysSpec(t *testing.T) {
func TestSwap(t *testing.T) {
test := `system test1;
import "foo.fspec";
Expand Down

0 comments on commit 9aa7835

Please sign in to comment.