Permalink
Browse files

use pointer for node reference

  • Loading branch information...
1 parent 35cf9e9 commit bd23b42c62b795c3467056b0506c89089fb34521 @haya14busa committed Sep 19, 2016
Showing with 49 additions and 49 deletions.
  1. +19 −19 ast/node.go
  2. +11 −11 ast/walk.go
  3. +2 −2 compiler/compiler.go
  4. +17 −17 go/export.go
View
@@ -57,13 +57,13 @@ func (e *Excmd) Cmd() Cmd { return *e.ExArg.Cmd }
// vimlparser: FUNCTION .ea .body .left .rlist .attr .endfunction
type Function struct {
- Func Pos // position of starting the :function
- ExArg ExArg // Ex command arg
- Body []Statement // function body
- Name Expr // function name
- Params []Ident // parameters
- Attr FuncAttr // function attributes
- EndFunction EndFunction // :endfunction
+ Func Pos // position of starting the :function
+ ExArg ExArg // Ex command arg
+ Body []Statement // function body
+ Name Expr // function name
+ Params []*Ident // parameters
+ Attr FuncAttr // function attributes
+ EndFunction *EndFunction // :endfunction
}
type FuncAttr struct {
@@ -107,9 +107,9 @@ func (f *Return) Cmd() Cmd { return *f.ExArg.Cmd }
// vimlparser: EXCALL .ea .left
type ExCall struct {
- ExCall Pos // position of starting the :call
- ExArg ExArg // Ex command arg
- FuncCall CallExpr // a function call
+ ExCall Pos // position of starting the :call
+ ExArg ExArg // Ex command arg
+ FuncCall *CallExpr // a function call
}
func (f *ExCall) Pos() Pos { return f.ExCall }
@@ -175,9 +175,9 @@ type If struct {
ExArg ExArg // Ex command arg
Body []Statement // body of if statement
Condition Expr // condition
- ElseIf []ElseIf
+ ElseIf []*ElseIf
Else *Else
- EndIf EndIf
+ EndIf *EndIf
}
func (f *If) Pos() Pos { return f.If }
@@ -219,7 +219,7 @@ type While struct {
ExArg ExArg // Ex command arg
Body []Statement // body of while statement
Condition Expr // condition
- EndWhile EndWhile
+ EndWhile *EndWhile
}
func (f *While) Pos() Pos { return f.While }
@@ -251,7 +251,7 @@ type For struct {
Rest Expr // rest of lhs list; or nil
Right Expr // rhs expression.
- EndFor EndFor
+ EndFor *EndFor
}
func (f *For) Pos() Pos { return f.For }
@@ -289,9 +289,9 @@ type Try struct {
Try Pos // position of starting the :try
ExArg ExArg // Ex command arg
Body []Statement // body of try statement
- Catch []Catch
+ Catch []*Catch
Finally *Finally
- EndTry EndTry
+ EndTry *EndTry
}
func (f *Try) Pos() Pos { return f.Try }
@@ -437,7 +437,7 @@ func (c *CallExpr) Pos() Pos { return c.Lparen }
type DotExpr struct {
Left Expr
Dot Pos // position of "."
- Right Ident
+ Right *Ident
}
func (c *DotExpr) Pos() Pos { return c.Dot }
@@ -516,8 +516,8 @@ func (i *Ident) Pos() Pos { return i.NamePos }
// vimlparsr: LAMBDA .rlist .left
// { Params -> Expr }
type LambdaExpr struct {
- Lcurlybrace Pos // position of "{"
- Params []Ident // parameters
+ Lcurlybrace Pos // position of "{"
+ Params []*Ident // parameters
Expr Expr
}
View
@@ -41,7 +41,7 @@ func Walk(v Visitor, node Node) {
Walk(v, n.Name)
walkIdentList(v, n.Params)
walkStmtList(v, n.Body)
- Walk(v, &n.EndFunction)
+ Walk(v, n.EndFunction)
case *EndFunction: // nothing to do
@@ -52,7 +52,7 @@ func Walk(v Visitor, node Node) {
Walk(v, n.Result)
case *ExCall:
- Walk(v, &n.FuncCall)
+ Walk(v, n.FuncCall)
case *Let:
Walk(v, n.Left)
@@ -72,10 +72,10 @@ func Walk(v Visitor, node Node) {
case *If:
Walk(v, n.Condition)
for _, elseif := range n.ElseIf {
- Walk(v, &elseif)
+ Walk(v, elseif)
}
Walk(v, n.Else)
- Walk(v, &n.EndIf)
+ Walk(v, n.EndIf)
case *ElseIf:
Walk(v, n.Condition)
@@ -89,7 +89,7 @@ func Walk(v Visitor, node Node) {
case *While:
Walk(v, n.Condition)
walkStmtList(v, n.Body)
- Walk(v, &n.EndWhile)
+ Walk(v, n.EndWhile)
case *EndWhile: // nothing to do
@@ -99,7 +99,7 @@ func Walk(v Visitor, node Node) {
Walk(v, n.Rest)
Walk(v, n.Right)
walkStmtList(v, n.Body)
- Walk(v, &n.EndFor)
+ Walk(v, n.EndFor)
case *EndFor: // nothing to do
@@ -110,10 +110,10 @@ func Walk(v Visitor, node Node) {
case *Try:
walkStmtList(v, n.Body)
for _, c := range n.Catch {
- Walk(v, &c)
+ Walk(v, c)
}
Walk(v, n.Finally)
- Walk(v, &n.EndTry)
+ Walk(v, n.EndTry)
case *Catch:
walkStmtList(v, n.Body)
@@ -161,7 +161,7 @@ func Walk(v Visitor, node Node) {
case *DotExpr:
Walk(v, n.Left)
- Walk(v, &n.Right)
+ Walk(v, n.Right)
case *BasicLit: // nothing to do
@@ -197,9 +197,9 @@ func Walk(v Visitor, node Node) {
// Helper functions for common node lists. They may be empty.
-func walkIdentList(v Visitor, list []Ident) {
+func walkIdentList(v Visitor, list []*Ident) {
for _, x := range list {
- Walk(v, &x)
+ Walk(v, x)
}
}
@@ -178,7 +178,7 @@ func (c *Compiler) compileReturn(node *ast.Return) {
}
func (c *Compiler) compileExcall(node *ast.ExCall) {
- c.fprintln("(%s %s)", node.Cmd().Name, c.compileExpr(&node.FuncCall))
+ c.fprintln("(%s %s)", node.Cmd().Name, c.compileExpr(node.FuncCall))
}
func (c *Compiler) compileLet(node *ast.Let) {
@@ -396,7 +396,7 @@ func (c *Compiler) compileExpr(node ast.Expr) string {
return fmt.Sprintf("(%s)", name)
case *ast.DotExpr:
l := c.compileExpr(n.Left)
- r := c.compileExpr(&n.Right)
+ r := c.compileExpr(n.Right)
return fmt.Sprintf("(dot %s %s)", l, r)
case *ast.BasicLit:
return n.Value
View
@@ -68,7 +68,7 @@ func newAstNode(n *VimNode, filename string) ast.Node {
Name: newAstNode(n.left, filename),
Params: newIdents(*n, filename),
Attr: attr,
- EndFunction: *newAstNode(n.endfunction, filename).(*ast.EndFunction),
+ EndFunction: newAstNode(n.endfunction, filename).(*ast.EndFunction),
}
case NODE_ENDFUNCTION:
@@ -95,7 +95,7 @@ func newAstNode(n *VimNode, filename string) ast.Node {
return &ast.ExCall{
ExCall: pos,
ExArg: newExArg(*n.ea, filename),
- FuncCall: *newAstNode(n.left, filename).(*ast.CallExpr),
+ FuncCall: newAstNode(n.left, filename).(*ast.CallExpr),
}
case NODE_LET:
@@ -133,13 +133,13 @@ func newAstNode(n *VimNode, filename string) ast.Node {
}
case NODE_IF:
- var elifs []ast.ElseIf
+ var elifs []*ast.ElseIf
if n.elseif != nil {
- elifs = make([]ast.ElseIf, 0, len(n.elseif))
+ elifs = make([]*ast.ElseIf, 0, len(n.elseif))
}
for _, node := range n.elseif {
if node != nil { // conservative
- elifs = append(elifs, *newAstNode(node, filename).(*ast.ElseIf))
+ elifs = append(elifs, newAstNode(node, filename).(*ast.ElseIf))
}
}
var els *ast.Else
@@ -153,7 +153,7 @@ func newAstNode(n *VimNode, filename string) ast.Node {
Condition: newAstNode(n.cond, filename),
ElseIf: elifs,
Else: els,
- EndIf: *newAstNode(n.endif, filename).(*ast.EndIf),
+ EndIf: newAstNode(n.endif, filename).(*ast.EndIf),
}
case NODE_ELSEIF:
@@ -183,7 +183,7 @@ func newAstNode(n *VimNode, filename string) ast.Node {
ExArg: newExArg(*n.ea, filename),
Body: newBody(*n, filename),
Condition: newAstNode(n.cond, filename),
- EndWhile: *newAstNode(n.endwhile, filename).(*ast.EndWhile),
+ EndWhile: newAstNode(n.endwhile, filename).(*ast.EndWhile),
}
case NODE_ENDWHILE:
@@ -201,7 +201,7 @@ func newAstNode(n *VimNode, filename string) ast.Node {
List: newList(*n, filename),
Rest: newAstNode(n.rest, filename),
Right: newAstNode(n.right, filename),
- EndFor: *newAstNode(n.endfor, filename).(*ast.EndFor),
+ EndFor: newAstNode(n.endfor, filename).(*ast.EndFor),
}
case NODE_ENDFOR:
@@ -223,13 +223,13 @@ func newAstNode(n *VimNode, filename string) ast.Node {
}
case NODE_TRY:
- var catches []ast.Catch
+ var catches []*ast.Catch
if n.catch != nil {
- catches = make([]ast.Catch, 0, len(n.catch))
+ catches = make([]*ast.Catch, 0, len(n.catch))
}
for _, node := range n.catch {
if node != nil { // conservative
- catches = append(catches, *newAstNode(node, filename).(*ast.Catch))
+ catches = append(catches, newAstNode(node, filename).(*ast.Catch))
}
}
var finally *ast.Finally
@@ -242,7 +242,7 @@ func newAstNode(n *VimNode, filename string) ast.Node {
Body: newBody(*n, filename),
Catch: catches,
Finally: finally,
- EndTry: *newAstNode(n.endtry, filename).(*ast.EndTry),
+ EndTry: newAstNode(n.endtry, filename).(*ast.EndTry),
}
case NODE_CATCH:
@@ -352,7 +352,7 @@ func newAstNode(n *VimNode, filename string) ast.Node {
return &ast.DotExpr{
Left: newAstNode(n.left, filename),
Dot: pos,
- Right: *newAstNode(n.right, filename).(*ast.Ident),
+ Right: newAstNode(n.right, filename).(*ast.Ident),
}
case NODE_NUMBER:
@@ -514,14 +514,14 @@ func newBody(n VimNode, filename string) []ast.Statement {
return body
}
-func newIdents(n VimNode, filename string) []ast.Ident {
- var idents []ast.Ident
+func newIdents(n VimNode, filename string) []*ast.Ident {
+ var idents []*ast.Ident
if n.rlist != nil {
- idents = make([]ast.Ident, 0, len(n.rlist))
+ idents = make([]*ast.Ident, 0, len(n.rlist))
}
for _, node := range n.rlist {
if node != nil { // conservative
- idents = append(idents, *newAstNode(node, filename).(*ast.Ident))
+ idents = append(idents, newAstNode(node, filename).(*ast.Ident))
}
}
return idents

0 comments on commit bd23b42

Please sign in to comment.