github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/config/lang/ast/call.go (about)

     1  package ast
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  // Call represents a function call.
     9  type Call struct {
    10  	Func string
    11  	Args []Node
    12  	Posx Pos
    13  }
    14  
    15  func (n *Call) Accept(v Visitor) Node {
    16  	for i, a := range n.Args {
    17  		n.Args[i] = a.Accept(v)
    18  	}
    19  
    20  	return v(n)
    21  }
    22  
    23  func (n *Call) Pos() Pos {
    24  	return n.Posx
    25  }
    26  
    27  func (n *Call) String() string {
    28  	args := make([]string, len(n.Args))
    29  	for i, arg := range n.Args {
    30  		args[i] = fmt.Sprintf("%s", arg)
    31  	}
    32  
    33  	return fmt.Sprintf("Call(%s, %s)", n.Func, strings.Join(args, ", "))
    34  }
    35  
    36  func (n *Call) Type(s Scope) (Type, error) {
    37  	f, ok := s.LookupFunc(n.Func)
    38  	if !ok {
    39  		return TypeInvalid, fmt.Errorf("unknown function: %s", n.Func)
    40  	}
    41  
    42  	return f.ReturnType, nil
    43  }
    44  
    45  func (n *Call) GoString() string {
    46  	return fmt.Sprintf("*%#v", *n)
    47  }