38 _ Node = SelectorExpr{}
40 _ Node = KeyValueExpr{}
49 _ Node = CompositeLit{}
52 _ Node = TypeSwitchStmt{}
53 _ Node = TypeAssertExpr{}
55 _ Node = InterfaceType{}
66 type Function struct {
70 type Token token.Token
75 type Ellipsis struct {
79 type IncDecStmt struct {
84 type BranchStmt struct {
89 type InterfaceType struct {
93 type TypeSpec struct {
98 type TypeAssertExpr struct {
103 type TypeSwitchStmt struct {
109 type SwitchStmt struct {
115 type EmptyStmt struct {
118 type CompositeLit struct {
123 type CommClause struct {
128 type CaseClause struct {
133 type CallExpr struct {
136 // XXX handle ellipsis
139 // TODO(dh): add a ChanDir node, and a way of instantiating it.
141 type ChanType struct {
146 type FuncDecl struct {
153 type FuncLit struct {
158 type FuncType struct {
163 type KeyValueExpr struct {
168 type StructType struct {
172 type SelectorExpr struct {
194 type ImportSpec struct {
199 type SelectStmt struct {
203 type ArrayType struct {
208 type DeferStmt struct {
212 type MapType struct {
217 type ReturnStmt struct {
221 type SliceExpr struct {
228 type StarExpr struct {
232 type UnaryExpr struct {
237 type SendStmt struct {
242 type Binding struct {
247 type RangeStmt struct {
255 type AssignStmt struct {
261 type IndexExpr struct {
266 type Node interface {
279 type Builtin struct {
287 type ValueSpec struct {
298 type GenDecl struct {
303 type BasicLit struct {
308 type BinaryExpr struct {
314 type ForStmt struct {
329 func stringify(n Node) string {
330 v := reflect.ValueOf(n)
332 parts = append(parts, v.Type().Name())
333 for i := 0; i < v.NumField(); i++ {
334 parts = append(parts, fmt.Sprintf("%s", v.Field(i)))
336 return "(" + strings.Join(parts, " ") + ")"
339 func (stmt AssignStmt) String() string { return stringify(stmt) }
340 func (expr IndexExpr) String() string { return stringify(expr) }
341 func (id Ident) String() string { return stringify(id) }
342 func (spec ValueSpec) String() string { return stringify(spec) }
343 func (decl GenDecl) String() string { return stringify(decl) }
344 func (lit BasicLit) String() string { return stringify(lit) }
345 func (expr BinaryExpr) String() string { return stringify(expr) }
346 func (stmt ForStmt) String() string { return stringify(stmt) }
347 func (stmt RangeStmt) String() string { return stringify(stmt) }
348 func (typ ArrayType) String() string { return stringify(typ) }
349 func (stmt DeferStmt) String() string { return stringify(stmt) }
350 func (typ MapType) String() string { return stringify(typ) }
351 func (stmt ReturnStmt) String() string { return stringify(stmt) }
352 func (expr SliceExpr) String() string { return stringify(expr) }
353 func (expr StarExpr) String() string { return stringify(expr) }
354 func (expr UnaryExpr) String() string { return stringify(expr) }
355 func (stmt SendStmt) String() string { return stringify(stmt) }
356 func (spec ImportSpec) String() string { return stringify(spec) }
357 func (stmt SelectStmt) String() string { return stringify(stmt) }
358 func (stmt IfStmt) String() string { return stringify(stmt) }
359 func (stmt IncDecStmt) String() string { return stringify(stmt) }
360 func (stmt GoStmt) String() string { return stringify(stmt) }
361 func (field Field) String() string { return stringify(field) }
362 func (expr SelectorExpr) String() string { return stringify(expr) }
363 func (typ StructType) String() string { return stringify(typ) }
364 func (expr KeyValueExpr) String() string { return stringify(expr) }
365 func (typ FuncType) String() string { return stringify(typ) }
366 func (lit FuncLit) String() string { return stringify(lit) }
367 func (decl FuncDecl) String() string { return stringify(decl) }
368 func (stmt BranchStmt) String() string { return stringify(stmt) }
369 func (expr CallExpr) String() string { return stringify(expr) }
370 func (clause CaseClause) String() string { return stringify(clause) }
371 func (typ ChanType) String() string { return stringify(typ) }
372 func (clause CommClause) String() string { return stringify(clause) }
373 func (lit CompositeLit) String() string { return stringify(lit) }
374 func (stmt EmptyStmt) String() string { return stringify(stmt) }
375 func (typ InterfaceType) String() string { return stringify(typ) }
376 func (stmt SwitchStmt) String() string { return stringify(stmt) }
377 func (expr TypeAssertExpr) String() string { return stringify(expr) }
378 func (spec TypeSpec) String() string { return stringify(spec) }
379 func (stmt TypeSwitchStmt) String() string { return stringify(stmt) }
380 func (nil Nil) String() string { return "nil" }
381 func (builtin Builtin) String() string { return stringify(builtin) }
382 func (obj Object) String() string { return stringify(obj) }
383 func (fn Function) String() string { return stringify(fn) }
384 func (el Ellipsis) String() string { return stringify(el) }
385 func (not Not) String() string { return stringify(not) }
387 func (or Or) String() string {
389 for _, node := range or.Nodes {
397 func isProperList(l List) bool {
398 if l.Head == nil && l.Tail == nil {
401 switch tail := l.Tail.(type) {
405 return isProperList(tail)
411 func (l List) String() string {
412 if l.Head == nil && l.Tail == nil {
417 // pretty-print the list
420 objs = append(objs, l.Head.String())
423 return fmt.Sprintf("[%s]", strings.Join(objs, " "))
426 return fmt.Sprintf("%s:%s", l.Head, l.Tail)
429 func (bind Binding) String() string {
430 if bind.Node == nil {
433 return fmt.Sprintf("%s@%s", bind.Name, bind.Node)
436 func (s String) String() string { return fmt.Sprintf("%q", string(s)) }
438 func (tok Token) String() string {
439 return fmt.Sprintf("%q", strings.ToUpper(token.Token(tok).String()))
442 func (Any) String() string { return "_" }
444 func (AssignStmt) isNode() {}
445 func (IndexExpr) isNode() {}
446 func (Ident) isNode() {}
447 func (ValueSpec) isNode() {}
448 func (GenDecl) isNode() {}
449 func (BasicLit) isNode() {}
450 func (BinaryExpr) isNode() {}
451 func (ForStmt) isNode() {}
452 func (RangeStmt) isNode() {}
453 func (ArrayType) isNode() {}
454 func (DeferStmt) isNode() {}
455 func (MapType) isNode() {}
456 func (ReturnStmt) isNode() {}
457 func (SliceExpr) isNode() {}
458 func (StarExpr) isNode() {}
459 func (UnaryExpr) isNode() {}
460 func (SendStmt) isNode() {}
461 func (ImportSpec) isNode() {}
462 func (SelectStmt) isNode() {}
463 func (IfStmt) isNode() {}
464 func (IncDecStmt) isNode() {}
465 func (GoStmt) isNode() {}
466 func (Field) isNode() {}
467 func (SelectorExpr) isNode() {}
468 func (StructType) isNode() {}
469 func (KeyValueExpr) isNode() {}
470 func (FuncType) isNode() {}
471 func (FuncLit) isNode() {}
472 func (FuncDecl) isNode() {}
473 func (BranchStmt) isNode() {}
474 func (CallExpr) isNode() {}
475 func (CaseClause) isNode() {}
476 func (ChanType) isNode() {}
477 func (CommClause) isNode() {}
478 func (CompositeLit) isNode() {}
479 func (EmptyStmt) isNode() {}
480 func (InterfaceType) isNode() {}
481 func (SwitchStmt) isNode() {}
482 func (TypeAssertExpr) isNode() {}
483 func (TypeSpec) isNode() {}
484 func (TypeSwitchStmt) isNode() {}
485 func (Nil) isNode() {}
486 func (Builtin) isNode() {}
487 func (Object) isNode() {}
488 func (Function) isNode() {}
489 func (Ellipsis) isNode() {}
490 func (Or) isNode() {}
491 func (List) isNode() {}
492 func (String) isNode() {}
493 func (Token) isNode() {}
494 func (Any) isNode() {}
495 func (Binding) isNode() {}
496 func (Not) isNode() {}