compiler: export the type "any" as a builtin
Otherwise we can't tell the difference between builtin type "any" and a locally defined type "any". This will require updates to the gccgo export data parsers in the main Go repo and the x/tools repo. These updates are https://go.dev/cl/537195 and https://go.dev/cl/537215. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536715
This commit is contained in:
parent
fbb569315a
commit
e52d31804a
5 changed files with 21 additions and 16 deletions
|
@ -1,4 +1,4 @@
|
||||||
ddf3758e4a45ca2816fb68f3e4224501a3c4c438
|
7ab229670f7dad1d79f33929f9a4f8e6e4a71526
|
||||||
|
|
||||||
The first line of this file holds the git revision number of the last
|
The first line of this file holds the git revision number of the last
|
||||||
merge done from the gofrontend repository.
|
merge done from the gofrontend repository.
|
||||||
|
|
|
@ -1661,6 +1661,7 @@ Export::register_builtin_types(Gogo* gogo)
|
||||||
this->register_builtin_type(gogo, "error", BUILTIN_ERROR);
|
this->register_builtin_type(gogo, "error", BUILTIN_ERROR);
|
||||||
this->register_builtin_type(gogo, "byte", BUILTIN_BYTE);
|
this->register_builtin_type(gogo, "byte", BUILTIN_BYTE);
|
||||||
this->register_builtin_type(gogo, "rune", BUILTIN_RUNE);
|
this->register_builtin_type(gogo, "rune", BUILTIN_RUNE);
|
||||||
|
this->register_builtin_type(gogo, "any", BUILTIN_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register one builtin type in the export table.
|
// Register one builtin type in the export table.
|
||||||
|
|
|
@ -51,8 +51,9 @@ enum Builtin_code
|
||||||
BUILTIN_ERROR = -19,
|
BUILTIN_ERROR = -19,
|
||||||
BUILTIN_BYTE = -20,
|
BUILTIN_BYTE = -20,
|
||||||
BUILTIN_RUNE = -21,
|
BUILTIN_RUNE = -21,
|
||||||
|
BUILTIN_ANY = -22,
|
||||||
|
|
||||||
SMALLEST_BUILTIN_CODE = -21
|
SMALLEST_BUILTIN_CODE = -22
|
||||||
};
|
};
|
||||||
|
|
||||||
// Export data version number. New export data is written with the
|
// Export data version number. New export data is written with the
|
||||||
|
|
|
@ -1408,6 +1408,7 @@ Import::register_builtin_types(Gogo* gogo)
|
||||||
this->register_builtin_type(gogo, "error", BUILTIN_ERROR);
|
this->register_builtin_type(gogo, "error", BUILTIN_ERROR);
|
||||||
this->register_builtin_type(gogo, "byte", BUILTIN_BYTE);
|
this->register_builtin_type(gogo, "byte", BUILTIN_BYTE);
|
||||||
this->register_builtin_type(gogo, "rune", BUILTIN_RUNE);
|
this->register_builtin_type(gogo, "rune", BUILTIN_RUNE);
|
||||||
|
this->register_builtin_type(gogo, "any", BUILTIN_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register a single builtin type.
|
// Register a single builtin type.
|
||||||
|
|
|
@ -187,7 +187,6 @@ func (p *parser) parseQualifiedNameStr(unquotedName string) (pkgpath, name strin
|
||||||
// getPkg returns the package for a given path. If the package is
|
// getPkg returns the package for a given path. If the package is
|
||||||
// not found but we have a package name, create the package and
|
// not found but we have a package name, create the package and
|
||||||
// add it to the p.imports map.
|
// add it to the p.imports map.
|
||||||
//
|
|
||||||
func (p *parser) getPkg(pkgpath, name string) *types.Package {
|
func (p *parser) getPkg(pkgpath, name string) *types.Package {
|
||||||
// package unsafe is not in the imports map - handle explicitly
|
// package unsafe is not in the imports map - handle explicitly
|
||||||
if pkgpath == "unsafe" {
|
if pkgpath == "unsafe" {
|
||||||
|
@ -904,6 +903,7 @@ const (
|
||||||
gccgoBuiltinERROR = 19
|
gccgoBuiltinERROR = 19
|
||||||
gccgoBuiltinBYTE = 20
|
gccgoBuiltinBYTE = 20
|
||||||
gccgoBuiltinRUNE = 21
|
gccgoBuiltinRUNE = 21
|
||||||
|
gccgoBuiltinANY = 22
|
||||||
)
|
)
|
||||||
|
|
||||||
func lookupBuiltinType(typ int) types.Type {
|
func lookupBuiltinType(typ int) types.Type {
|
||||||
|
@ -928,13 +928,13 @@ func lookupBuiltinType(typ int) types.Type {
|
||||||
gccgoBuiltinERROR: types.Universe.Lookup("error").Type(),
|
gccgoBuiltinERROR: types.Universe.Lookup("error").Type(),
|
||||||
gccgoBuiltinBYTE: types.Universe.Lookup("byte").Type(),
|
gccgoBuiltinBYTE: types.Universe.Lookup("byte").Type(),
|
||||||
gccgoBuiltinRUNE: types.Universe.Lookup("rune").Type(),
|
gccgoBuiltinRUNE: types.Universe.Lookup("rune").Type(),
|
||||||
|
gccgoBuiltinANY: types.Universe.Lookup("any").Type(),
|
||||||
}[typ]
|
}[typ]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type = "<" "type" ( "-" int | int [ TypeSpec ] ) ">" .
|
// Type = "<" "type" ( "-" int | int [ TypeSpec ] ) ">" .
|
||||||
//
|
//
|
||||||
// parseType updates the type map to t for all type numbers n.
|
// parseType updates the type map to t for all type numbers n.
|
||||||
//
|
|
||||||
func (p *parser) parseType(pkg *types.Package, n ...any) types.Type {
|
func (p *parser) parseType(pkg *types.Package, n ...any) types.Type {
|
||||||
p.expect('<')
|
p.expect('<')
|
||||||
t, _ := p.parseTypeAfterAngle(pkg, n...)
|
t, _ := p.parseTypeAfterAngle(pkg, n...)
|
||||||
|
@ -1117,9 +1117,10 @@ func (p *parser) maybeCreatePackage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitDataDirective = ( "v1" | "v2" | "v3" ) ";" |
|
// InitDataDirective = ( "v1" | "v2" | "v3" ) ";" |
|
||||||
// "priority" int ";" |
|
//
|
||||||
// "init" { PackageInit } ";" |
|
// "priority" int ";" |
|
||||||
// "checksum" unquotedString ";" .
|
// "init" { PackageInit } ";" |
|
||||||
|
// "checksum" unquotedString ";" .
|
||||||
func (p *parser) parseInitDataDirective() {
|
func (p *parser) parseInitDataDirective() {
|
||||||
if p.tok != scanner.Ident {
|
if p.tok != scanner.Ident {
|
||||||
// unexpected token kind; panic
|
// unexpected token kind; panic
|
||||||
|
@ -1170,15 +1171,16 @@ func (p *parser) parseInitDataDirective() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Directive = InitDataDirective |
|
// Directive = InitDataDirective |
|
||||||
// "package" unquotedString [ unquotedString ] [ unquotedString ] ";" |
|
//
|
||||||
// "pkgpath" unquotedString ";" |
|
// "package" unquotedString [ unquotedString ] [ unquotedString ] ";" |
|
||||||
// "prefix" unquotedString ";" |
|
// "pkgpath" unquotedString ";" |
|
||||||
// "import" unquotedString unquotedString string ";" |
|
// "prefix" unquotedString ";" |
|
||||||
// "indirectimport" unquotedString unquotedstring ";" |
|
// "import" unquotedString unquotedString string ";" |
|
||||||
// "func" Func ";" |
|
// "indirectimport" unquotedString unquotedstring ";" |
|
||||||
// "type" Type ";" |
|
// "func" Func ";" |
|
||||||
// "var" Var ";" |
|
// "type" Type ";" |
|
||||||
// "const" Const ";" .
|
// "var" Var ";" |
|
||||||
|
// "const" Const ";" .
|
||||||
func (p *parser) parseDirective() {
|
func (p *parser) parseDirective() {
|
||||||
if p.tok != scanner.Ident {
|
if p.tok != scanner.Ident {
|
||||||
// unexpected token kind; panic
|
// unexpected token kind; panic
|
||||||
|
|
Loading…
Add table
Reference in a new issue