Skip to content

Commit 67c2192

Browse files
committed
Add a bunch of build hacks.
1 parent 03644a0 commit 67c2192

5 files changed

+41
-10
lines changed

decl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func ast_decl_class(d ast.Decl) decl_class {
130130
case token.CONST:
131131
return decl_const
132132
case token.TYPE:
133-
if t.Specs[0].(*ast.TypeSpec).Assign != 0 {
133+
if isAliasTypeSpec(t.Specs[0].(*ast.TypeSpec)) {
134134
return decl_type_alias
135135
} else {
136136
return decl_type

package_bin.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,8 @@ func (p *gc_bin_parser) obj(tag int) {
213213
pkg, name := p.qualifiedName()
214214
typ := p.typ("")
215215
p.callback(pkg, &ast.GenDecl{
216-
Tok: token.TYPE,
217-
Specs: []ast.Spec{
218-
&ast.TypeSpec{
219-
Name: ast.NewIdent(name),
220-
Assign: 1, // fake, but gocode only cares if it's there or not
221-
Type: typ,
222-
},
223-
},
216+
Tok: token.TYPE,
217+
Specs: []ast.Spec{typeAliasSpec(name, typ)},
224218
})
225219

226220
case typeTag:

pre_go17.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !go1.7
1+
// +build !go1.7,!go1.8
22

33
package main
44

type_alias_build_hack_18.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// +build !go1.9
2+
3+
package main
4+
5+
import (
6+
"go/ast"
7+
)
8+
9+
func typeAliasSpec(name string, typ ast.Expr) *ast.TypeSpec {
10+
return &ast.TypeSpec{
11+
Name: ast.NewIdent(name),
12+
Type: typ,
13+
}
14+
}
15+
16+
func isAliasTypeSpec(t *ast.TypeSpec) bool {
17+
return false
18+
}

type_alias_build_hack_19.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// +build go1.9
2+
3+
package main
4+
5+
import (
6+
"go/ast"
7+
)
8+
9+
func typeAliasSpec(name string, typ ast.Expr) *ast.TypeSpec {
10+
return &ast.TypeSpec{
11+
Name: ast.NewIdent(name),
12+
Assign: 1,
13+
Type: typ,
14+
}
15+
}
16+
17+
func isAliasTypeSpec(t *ast.TypeSpec) bool {
18+
return t.Assign != 0
19+
}

0 commit comments

Comments
 (0)