Make {Type,}ExprString methods, not functions.

This commit is contained in:
Nigel Tao committed 2017-05-12 10:59:10 +10:00
1 parent e10ddeb248
commit d8d17b66c0
3 files changed
+15 -20

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file.
package ast
import (
t "github.com/google/puffs/lang/token"
)
// String returns a string form of the Expr n.
func (n *Expr) String(m *t.IDMap) string {
if n == nil {
return ""
}
if n.ID0() == 0 {
return m.ByID(n.ID1())
}
return "Expr.String.TODO"
}
// String returns a string form of the TypeExpr n.
func (n *TypeExpr) String(m *t.IDMap) string {
if n != nil {
s := ""
switch n.PackageOrDecorator() {
case 0:
s = m.ByID(n.Name())
case t.IDPtr:
return "ptr " + n.Inner().String(m)
case t.IDOpenBracket:
return "[" + n.ArrayLength().String(m) + "] " + n.Inner().String(m)
default:
s = m.ByID(n.PackageOrDecorator()) + "." + m.ByID(n.Name())
}
if n.InclMin() == nil && n.ExclMax() == nil {
return s
}
return s + "[" + n.InclMin().String(m) + ":" + n.ExclMax().String(m) + "]"
}
return "!invalid_type!"
}