Skip to content

Commit

Permalink
use pointer for node reference
Browse files Browse the repository at this point in the history
  • Loading branch information
haya14busa committed Sep 19, 2016
1 parent 35cf9e9 commit bd23b42
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 49 deletions.
38 changes: 19 additions & 19 deletions ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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
}

Expand Down
22 changes: 11 additions & 11 deletions ast/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
34 changes: 17 additions & 17 deletions go/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bd23b42

Please sign in to comment.