forked from elliotchance/c2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goto.go
39 lines (32 loc) · 819 Bytes
/
goto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// This file contains functions for transpiling goto/label statements.
package transpiler
import (
goast "go/ast"
"go/token"
"github.com/elliotchance/c2go/ast"
"github.com/elliotchance/c2go/program"
"github.com/elliotchance/c2go/util"
)
func transpileLabelStmt(n *ast.LabelStmt, p *program.Program) (*goast.LabeledStmt, error) {
var stmt goast.Stmt
if len(n.Children()) > 0 {
var err error
stmt, _, _, err = transpileToStmt(n.Children()[0], p)
if err != nil {
return nil, err
}
}
if stmt == nil {
stmt = &goast.EmptyStmt{}
}
return &goast.LabeledStmt{
Label: util.NewIdent(n.Name),
Stmt: stmt,
}, nil
}
func transpileGotoStmt(n *ast.GotoStmt, p *program.Program) (*goast.BranchStmt, error) {
return &goast.BranchStmt{
Label: util.NewIdent(n.Name),
Tok: token.GOTO,
}, nil
}