mirror of
https://github.com/golang/go
synced 2024-11-23 00:00:07 -07:00
cmd/gc: qualified embedded fields with owner package.
R=rsc CC=golang-dev https://golang.org/cl/14188044
This commit is contained in:
parent
4d7c63558c
commit
8d6bc666fb
@ -1021,7 +1021,7 @@ tointerface(NodeList *l)
|
||||
}
|
||||
|
||||
Node*
|
||||
embedded(Sym *s)
|
||||
embedded(Sym *s, Pkg *pkg)
|
||||
{
|
||||
Node *n;
|
||||
char *name;
|
||||
@ -1038,9 +1038,9 @@ embedded(Sym *s)
|
||||
|
||||
if(exportname(name))
|
||||
n = newname(lookup(name));
|
||||
else if(s->pkg == builtinpkg && importpkg != nil)
|
||||
// The name of embedded builtins during imports belongs to importpkg.
|
||||
n = newname(pkglookup(name, importpkg));
|
||||
else if(s->pkg == builtinpkg)
|
||||
// The name of embedded builtins belongs to pkg.
|
||||
n = newname(pkglookup(name, pkg));
|
||||
else
|
||||
n = newname(pkglookup(name, s->pkg));
|
||||
n = nod(ODCLFIELD, n, oldname(s));
|
||||
|
@ -754,6 +754,9 @@ typefmt(Fmt *fp, Type *t)
|
||||
//if(t->funarg)
|
||||
// fmtstrcpy(fp, "_ ");
|
||||
//else
|
||||
if(t->embedded && s->pkg != nil && s->pkg->path->len > 0)
|
||||
fmtprint(fp, "@\"%Z\".? ", s->pkg->path);
|
||||
else
|
||||
fmtstrcpy(fp, "? ");
|
||||
}
|
||||
}
|
||||
|
@ -1080,7 +1080,7 @@ NodeList* constiter(NodeList *vl, Node *t, NodeList *cl);
|
||||
Node* dclname(Sym *s);
|
||||
void declare(Node *n, int ctxt);
|
||||
void dumpdcl(char *st);
|
||||
Node* embedded(Sym *s);
|
||||
Node* embedded(Sym *s, Pkg *pkg);
|
||||
Node* fakethis(void);
|
||||
void funcbody(Node *n);
|
||||
void funccompile(Node *n, int isclosure);
|
||||
|
@ -1126,6 +1126,19 @@ hidden_importsym:
|
||||
}
|
||||
$$ = pkglookup($4->name, p);
|
||||
}
|
||||
| '@' LLITERAL '.' '?'
|
||||
{
|
||||
Pkg *p;
|
||||
|
||||
if($2.u.sval->len == 0)
|
||||
p = importpkg;
|
||||
else {
|
||||
if(isbadimport($2.u.sval))
|
||||
errorexit();
|
||||
p = mkpkg($2.u.sval);
|
||||
}
|
||||
$$ = pkglookup("?", p);
|
||||
}
|
||||
|
||||
name:
|
||||
sym %prec NotParen
|
||||
@ -1536,7 +1549,7 @@ structdcl:
|
||||
n = $2;
|
||||
if(n->op == OIND)
|
||||
n = n->left;
|
||||
n = embedded(n->sym);
|
||||
n = embedded(n->sym, importpkg);
|
||||
n->right = $2;
|
||||
n->val = $3;
|
||||
$$ = list1(n);
|
||||
@ -1607,7 +1620,7 @@ packname:
|
||||
embed:
|
||||
packname
|
||||
{
|
||||
$$ = embedded($1);
|
||||
$$ = embedded($1, localpkg);
|
||||
}
|
||||
|
||||
interfacedcl:
|
||||
@ -2061,15 +2074,19 @@ hidden_structdcl:
|
||||
sym hidden_type oliteral
|
||||
{
|
||||
Sym *s;
|
||||
Pkg *p;
|
||||
|
||||
if($1 != S) {
|
||||
if($1 != S && strcmp($1->name, "?") != 0) {
|
||||
$$ = nod(ODCLFIELD, newname($1), typenod($2));
|
||||
$$->val = $3;
|
||||
} else {
|
||||
s = $2->sym;
|
||||
if(s == S && isptr[$2->etype])
|
||||
s = $2->type->sym;
|
||||
$$ = embedded(s);
|
||||
p = importpkg;
|
||||
if($1 != S)
|
||||
p = $1->pkg;
|
||||
$$ = embedded(s, p);
|
||||
$$->right = typenod($2);
|
||||
$$->val = $3;
|
||||
}
|
||||
|
3476
src/cmd/gc/y.tab.c
3476
src/cmd/gc/y.tab.c
File diff suppressed because it is too large
Load Diff
@ -1,24 +1,21 @@
|
||||
/* A Bison parser, made by GNU Bison 2.3. */
|
||||
/* A Bison parser, made by GNU Bison 2.5. */
|
||||
|
||||
/* Skeleton interface for Bison's Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA. */
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* As a special exception, you may create a larger work that contains
|
||||
part or all of the Bison parser skeleton and distribute that work
|
||||
@ -29,10 +26,11 @@
|
||||
special exception, which will cause the skeleton and the resulting
|
||||
Bison output files to be licensed under the GNU General Public
|
||||
License without this special exception.
|
||||
|
||||
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
|
||||
/* Tokens. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
@ -146,22 +144,28 @@
|
||||
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef union YYSTYPE
|
||||
#line 28 "go.y"
|
||||
{
|
||||
|
||||
/* Line 2068 of yacc.c */
|
||||
#line 28 "go.y"
|
||||
|
||||
Node* node;
|
||||
NodeList* list;
|
||||
Type* type;
|
||||
Sym* sym;
|
||||
struct Val val;
|
||||
int i;
|
||||
}
|
||||
/* Line 1529 of yacc.c. */
|
||||
#line 160 "y.tab.h"
|
||||
YYSTYPE;
|
||||
|
||||
|
||||
|
||||
/* Line 2068 of yacc.c */
|
||||
#line 163 "y.tab.h"
|
||||
} YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
#endif
|
||||
|
||||
extern YYSTYPE yylval;
|
||||
|
||||
|
||||
|
@ -14,28 +14,28 @@ static struct {
|
||||
// is converted by bisonerrors into the yystate and yychar caused
|
||||
// by that token list.
|
||||
|
||||
221, ',',
|
||||
222, ',',
|
||||
"unexpected comma during import block",
|
||||
|
||||
32, ';',
|
||||
"missing import path; require quoted string",
|
||||
|
||||
377, ';',
|
||||
378, ';',
|
||||
"missing { after if clause",
|
||||
|
||||
398, ';',
|
||||
399, ';',
|
||||
"missing { after switch clause",
|
||||
|
||||
237, ';',
|
||||
238, ';',
|
||||
"missing { after for clause",
|
||||
|
||||
475, LBODY,
|
||||
476, LBODY,
|
||||
"missing { after for clause",
|
||||
|
||||
22, '{',
|
||||
"unexpected semicolon or newline before {",
|
||||
|
||||
144, ';',
|
||||
145, ';',
|
||||
"unexpected semicolon or newline in type declaration",
|
||||
|
||||
37, '}',
|
||||
@ -47,33 +47,33 @@ static struct {
|
||||
37, ',',
|
||||
"unexpected comma in channel type",
|
||||
|
||||
438, LELSE,
|
||||
439, LELSE,
|
||||
"unexpected semicolon or newline before else",
|
||||
|
||||
257, ',',
|
||||
258, ',',
|
||||
"name list not allowed in interface type",
|
||||
|
||||
237, LVAR,
|
||||
238, LVAR,
|
||||
"var declaration not allowed in for initializer",
|
||||
|
||||
65, '{',
|
||||
"unexpected { at end of statement",
|
||||
|
||||
376, '{',
|
||||
377, '{',
|
||||
"unexpected { at end of statement",
|
||||
|
||||
125, ';',
|
||||
126, ';',
|
||||
"argument to go/defer must be function call",
|
||||
|
||||
425, ';',
|
||||
426, ';',
|
||||
"need trailing comma before newline in composite literal",
|
||||
|
||||
436, ';',
|
||||
437, ';',
|
||||
"need trailing comma before newline in composite literal",
|
||||
|
||||
112, LNAME,
|
||||
113, LNAME,
|
||||
"nested func not allowed",
|
||||
|
||||
644, ';',
|
||||
645, ';',
|
||||
"else must be followed by if or statement block"
|
||||
};
|
||||
|
7
test/fixedbugs/issue6513.dir/a.go
Normal file
7
test/fixedbugs/issue6513.dir/a.go
Normal file
@ -0,0 +1,7 @@
|
||||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package a
|
||||
|
||||
type T struct{ int }
|
9
test/fixedbugs/issue6513.dir/b.go
Normal file
9
test/fixedbugs/issue6513.dir/b.go
Normal file
@ -0,0 +1,9 @@
|
||||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package b
|
||||
|
||||
import "./a"
|
||||
|
||||
type U struct{ a.T }
|
16
test/fixedbugs/issue6513.dir/main.go
Normal file
16
test/fixedbugs/issue6513.dir/main.go
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"./a"
|
||||
"./b"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var t a.T
|
||||
var u b.U
|
||||
_, _ = t, u
|
||||
}
|
10
test/fixedbugs/issue6513.go
Normal file
10
test/fixedbugs/issue6513.go
Normal file
@ -0,0 +1,10 @@
|
||||
// compiledir
|
||||
|
||||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Issue 6513: embedded builtins may get incorrect qualified
|
||||
// field name during import.
|
||||
|
||||
package ignored
|
Loading…
Reference in New Issue
Block a user