Skip to content

Commit

Permalink
Update some files
Browse files Browse the repository at this point in the history
  • Loading branch information
itsubaki committed Jan 13, 2025
1 parent 519c716 commit fa3429d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
8 changes: 5 additions & 3 deletions visitor/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ func (v *Visitor) VisitSwitchStatement(ctx *parser.SwitchStatementContext) inter
}

result := v.Visit(item.ExpressionList()).([]interface{})
if result[len(result)-1] == x {
for _, r := range result {
if r != x {
continue
}

enclosed.Visit(item)
return nil
}
Expand Down Expand Up @@ -330,8 +334,6 @@ func (v *Visitor) Modify(u matrix.Matrix, qargs [][]q.Qubit, modifier []parser.I
}

u = Pow(u, p)
default:
return nil, fmt.Errorf("modifier=%s: %w", mod.GetText(), ErrUnexpected)
}
}

Expand Down
25 changes: 25 additions & 0 deletions visitor/visitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,31 @@ func TestVisitor_VisitSwitchStatement(t *testing.T) {
tree: "(program (statementOrScope (statement (classicalDeclarationStatement (scalarType int) a = (declarationExpression (expression 20)) ;))) (statementOrScope (statement (classicalDeclarationStatement (scalarType int) b = (declarationExpression (expression 0)) ;))) (statementOrScope (statement (switchStatement switch ( (expression a) ) { (switchCaseItem case (expressionList (expression 15)) (scope { (statementOrScope (statement (assignmentStatement (indexedIdentifier b) = (expression 15) ;))) })) (switchCaseItem default (scope { (statementOrScope (statement (assignmentStatement (indexedIdentifier b) = (expression - (expression 1)) ;))) })) }))) <EOF>)",
want: "map[a:20 b:-1]",
},
{
text: `
int a = 20;
int b = 0;
switch (a) {
case 1, 2, 3{
b = 15;
}
case 20 {
b = -1;
}
}
`,
tree: "(program (statementOrScope (statement (classicalDeclarationStatement (scalarType int) a = (declarationExpression (expression 20)) ;))) (statementOrScope (statement (classicalDeclarationStatement (scalarType int) b = (declarationExpression (expression 0)) ;))) (statementOrScope (statement (switchStatement switch ( (expression a) ) { (switchCaseItem case (expressionList (expression 1) , (expression 2) , (expression 3)) (scope { (statementOrScope (statement (assignmentStatement (indexedIdentifier b) = (expression 15) ;))) })) (switchCaseItem case (expressionList (expression 20)) (scope { (statementOrScope (statement (assignmentStatement (indexedIdentifier b) = (expression - (expression 1)) ;))) })) }))) <EOF>)",
want: "map[a:20 b:-1]",
},
{
text: `
int a = 20;
int b = 0;
switch (a) { }
`,
tree: "(program (statementOrScope (statement (classicalDeclarationStatement (scalarType int) a = (declarationExpression (expression 20)) ;))) (statementOrScope (statement (classicalDeclarationStatement (scalarType int) b = (declarationExpression (expression 0)) ;))) (statementOrScope (statement (switchStatement switch ( (expression a) ) { }))) <EOF>)",
want: "map[a:20 b:0]",
},
}

for _, c := range cases {
Expand Down

0 comments on commit fa3429d

Please sign in to comment.