-
Notifications
You must be signed in to change notification settings - Fork 0
/
stmts.go
46 lines (36 loc) · 864 Bytes
/
stmts.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
40
41
42
43
44
45
46
package bstar
import (
"fmt"
"github.com/Nv7-Github/bsharp/ir"
"github.com/Nv7-Github/bsharp/types"
)
func (b *BStar) buildNode(node ir.Node) (Node, error) {
switch n := node.(type) {
case *ir.CallNode:
return b.buildCall(n)
case *ir.Const:
if n.Type().Equal(types.STRING) {
return constNode(fmt.Sprintf("%q", n.Value)), nil
}
return constNode(n.Value), nil
case *ir.BlockNode:
return b.buildBlock(n)
case *ir.CastNode:
return b.addCast(n)
case *ir.FnCallNode:
return b.buildFnCall(n)
case *ir.ExtensionCall:
switch n.Name {
case "ARGS":
ind, err := b.buildNode(n.Args[0])
if err != nil {
return nil, err
}
return blockNode(true, constNode("ARGS"), ind), nil
default:
return nil, n.Pos().Error("unknown extension call: %s", n.Name)
}
default:
return nil, n.Pos().Error("unknown node: %T", n)
}
}