-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_ast.go
97 lines (77 loc) · 1.72 KB
/
print_ast.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"awesomeProject/ir"
"container/list"
"fmt"
"go/ast"
"go/printer"
"go/token"
"os"
//"reflect"
"go/parser"
)
func ololo() {
// Create a new list and put some numbers in it.
l := list.New()
e4 := l.PushBack(4)
e1 := l.PushFront(1)
l.InsertBefore(3, e4)
l.InsertAfter(2, e1)
// Iterate through list and print its contents.
for e := l.Front(); e != nil; e = e.Next() {
fmt.Println(e.Value)
}
}
//const np token.Pos = 0
//goland:noinspection GoUnhandledErrorResult
func main7() {
println("----")
op2 := ir.Operator{
Name: "fn",
Dialect: "go",
Blocks: nil,
ReturnNames: nil,
Attributes: nil,
}
label := &ir.Label{
Name: "^bb0",
ParamValues: nil,
ParamTypes: nil,
}
bb0 := ir.Block{
Label: label,
Items: []ir.Operator{op2, op2},
}
op := ir.Operator{
Name: "fn",
Dialect: "go",
Blocks: []ir.Block{bb0},
ReturnNames: []ir.SimpleName{"%078"},
Attributes: nil,
}
op.RenderTo(os.Stdout, " ")
return
// OLD version https://github.com/obask/homoiconic-go/blob/master/result.go
filePath := "./hello.go"
//filePath := "/Users/baskakov/IdeaProjects/homoiconic-go/assets/types.go"
fset := token.NewFileSet()
code, err := parser.ParseFile(fset, filePath, nil, 0)
if err != nil {
panic(err)
}
//ast.Print(fset, code)
if err := printer.Fprint(os.Stdout, fset, code); err != nil {
panic(err)
}
//p := &sexpr.SExpr{}
//p.Sprint(reflect.ValueOf(code))
println("---------")
//_ = ast.Fprint(os.Stdout, fset, code, ast.NotNilFilter)
Fprint(os.Stdout, fset, code, ast.NotNilFilter)
tmp := &ast.BasicLit{
ValuePos: 0,
Kind: token.STRING,
Value: "\"hello world\"",
}
printer.Fprint(os.Stdout, fset, tmp)
}