diff options
| author | Robert Griesemer <gri@golang.org> | 2016-11-04 15:48:39 -0700 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2016-11-04 23:44:15 +0000 |
| commit | 8e970536dfe0b8ce74bfd0e83ae608c4a012d3c6 (patch) | |
| tree | 213f5f7549f2f46dd14de38cdb54c01d0b193e19 /src | |
| parent | dd1e7b3be0f64438e58f956bfb989608c7fa61bc (diff) | |
| download | go-8e970536dfe0b8ce74bfd0e83ae608c4a012d3c6.tar.xz | |
cmd/compile: revert user-visible changes related to aliases
Reason: Decision to back out current alias implementation.
Leaving import/export related code in place for now.
For #16339.
TBR=mdempsky
Change-Id: Ib0897cab2c1c3dc8a541f2efb9893271b0b0efe2
Reviewed-on: https://go-review.googlesource.com/32757
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/compile/internal/gc/noder.go | 97 | ||||
| -rw-r--r-- | src/go/internal/gcimporter/testdata/exports.go | 23 |
2 files changed, 1 insertions, 119 deletions
diff --git a/src/cmd/compile/internal/gc/noder.go b/src/cmd/compile/internal/gc/noder.go index 10bd09e72f..0189242d18 100644 --- a/src/cmd/compile/internal/gc/noder.go +++ b/src/cmd/compile/internal/gc/noder.go @@ -61,9 +61,6 @@ func (p *noder) decls(decls []syntax.Decl) (l []*Node) { case *syntax.ImportDecl: p.importDecl(decl) - case *syntax.AliasDecl: - p.aliasDecl(decl) - case *syntax.VarDecl: l = append(l, p.varDecl(decl)...) @@ -150,100 +147,6 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) { my.Block = 1 // at top level } -func (p *noder) aliasDecl(decl *syntax.AliasDecl) { - // Because alias declarations must refer to imported entities - // which are already set up, we can do all checks right here. - // We won't know anything about entities that have not been - // declared yet, but since they cannot have been imported, we - // know there's an error and we don't care about the details. - - // The original entity must be denoted by a qualified identifier. - // (The parser doesn't make this restriction to be more error- - // tolerant.) - qident, ok := decl.Orig.(*syntax.SelectorExpr) - if !ok { - // TODO(gri) This prints a dot-imported object with qualification - // (confusing error). Fix this. - yyerror("invalid alias: %v is not a package-qualified identifier", p.expr(decl.Orig)) - return - } - - pkg := p.expr(qident.X) - if pkg.Op != OPACK { - yyerror("invalid alias: %v is not a package", pkg) - return - } - pkg.Used = true - - // Resolve original entity - orig := oldname(restrictlookup(qident.Sel.Value, pkg.Name.Pkg)) - if orig.Sym.Flags&SymAlias != 0 { - Fatalf("original %v marked as alias", orig.Sym) - } - - // An alias declaration must not refer to package unsafe. - if orig.Sym.Pkg == unsafepkg { - yyerror("invalid alias: %v refers to package unsafe (%v)", decl.Name.Value, orig) - return - } - - // The aliased entity must be from a matching constant, type, variable, - // or function declaration, respectively. - var what string - switch decl.Tok { - case syntax.Const: - if orig.Op != OLITERAL { - what = "constant" - } - case syntax.Type: - if orig.Op != OTYPE { - what = "type" - } - case syntax.Var: - if orig.Op != ONAME || orig.Class != PEXTERN { - what = "variable" - } - case syntax.Func: - if orig.Op != ONAME || orig.Class != PFUNC { - what = "function" - } - default: - Fatalf("unexpected token: %s", decl.Tok) - } - if what != "" { - yyerror("invalid alias: %v is not a %s", orig, what) - return - } - - // handle special cases - switch decl.Name.Value { - case "_": - return // don't declare blank aliases - case "init": - yyerror("cannot declare init - must be non-alias function declaration") - return - } - - // declare alias - // (this is similar to handling dot imports) - asym := p.name(decl.Name) - if asym.Def != nil { - redeclare(asym, "in alias declaration") - return - } - asym.Flags |= SymAlias - asym.Def = orig - asym.Block = block - asym.Lastlineno = lineno - - if exportname(asym.Name) { - // TODO(gri) newname(asym) is only needed to satisfy exportsym - // (and indirectly, exportlist). We should be able to just - // collect the Syms, eventually. - exportsym(newname(asym)) - } -} - func (p *noder) varDecl(decl *syntax.VarDecl) []*Node { names := p.declNames(decl.NameList) diff --git a/src/go/internal/gcimporter/testdata/exports.go b/src/go/internal/gcimporter/testdata/exports.go index 0033f3027b..9a0273ba20 100644 --- a/src/go/internal/gcimporter/testdata/exports.go +++ b/src/go/internal/gcimporter/testdata/exports.go @@ -7,11 +7,7 @@ package exports -import ( - "go/ast" - "go/build" - "math" -) +import "go/ast" // Issue 3682: Correctly read dotted identifiers from export data. const init1 = 0 @@ -29,10 +25,6 @@ const ( C7 = `bar\n` ) -const ( - C8 => math.Pi -) - type ( T1 int T2 [10]int @@ -81,21 +73,12 @@ type ( T28 func(T28) T28 ) -type ( - T29 => ast.File - T30 => build.Context -) - var ( V0 int V1 = -991.0 V2 float32 = 1.2 ) -var ( - V3 => build.Default -) - func F1() {} func F2(x int) {} func F3() int { return 0 } @@ -103,7 +86,3 @@ func F4() float32 { return 0 } func F5(a, b, c int, u, v, w struct{ x, y T1 }, more ...interface{}) (p, q, r chan<- T10) func (p *T1) M1() - -func F6 => math.Sin -func F7 => ast.IsExported -func F8 => build.Import |
