mirror of
https://github.com/golang/go
synced 2024-11-13 18:10:24 -07:00
- fixed a bug w/ exports (wrong package info)
- keep track of type alias (type T1 T0) so we can print the proper type name R=r OCL=13688 CL=13688
This commit is contained in:
parent
9fb9e82fa3
commit
0c374e9f89
@ -6,9 +6,14 @@
|
||||
|
||||
package base
|
||||
|
||||
type Foo int
|
||||
|
||||
type Bar *float;
|
||||
|
||||
type Node struct {
|
||||
left, right *Node;
|
||||
val bool
|
||||
val bool;
|
||||
f Foo
|
||||
}
|
||||
|
||||
export Node
|
||||
export Foo, Bar, Node
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
package decls
|
||||
|
||||
import "base"
|
||||
//import "base"
|
||||
import base "base"
|
||||
import base2 "base"
|
||||
|
||||
|
@ -23,7 +23,7 @@ type Exporter struct {
|
||||
|
||||
func (E *Exporter) WriteType(typ *Globals.Type);
|
||||
func (E *Exporter) WriteObject(obj *Globals.Object);
|
||||
func (E *Exporter) WritePackage(pkg *Globals.Package);
|
||||
func (E *Exporter) WritePackage(pno int);
|
||||
|
||||
|
||||
func (E *Exporter) WriteByte(x byte) {
|
||||
@ -132,7 +132,7 @@ func (E *Exporter) WriteObject(obj *Globals.Object) {
|
||||
E.WriteObjectTag(obj.kind);
|
||||
E.WriteString(obj.ident);
|
||||
E.WriteType(obj.typ);
|
||||
E.WritePackage(E.comp.pkgs[obj.pnolev]);
|
||||
E.WritePackage(obj.pnolev);
|
||||
|
||||
switch obj.kind {
|
||||
case Object.CONST:
|
||||
@ -173,12 +173,15 @@ func (E *Exporter) WriteType(typ *Globals.Type) {
|
||||
panic "typ.obj.type() != typ"; // primary type
|
||||
}
|
||||
E.WriteString(typ.obj.ident);
|
||||
E.WritePackage(E.comp.pkgs[typ.obj.pnolev]);
|
||||
E.WritePackage(typ.obj.pnolev);
|
||||
} else {
|
||||
E.WriteString("");
|
||||
}
|
||||
|
||||
switch typ.form {
|
||||
case Type.ALIAS:
|
||||
E.WriteType(typ.elt);
|
||||
|
||||
case Type.ARRAY:
|
||||
E.WriteInt(typ.len_);
|
||||
E.WriteType(typ.elt);
|
||||
@ -207,7 +210,11 @@ func (E *Exporter) WriteType(typ *Globals.Type) {
|
||||
}
|
||||
|
||||
|
||||
func (E *Exporter) WritePackage(pkg *Globals.Package) {
|
||||
func (E *Exporter) WritePackage(pno int) {
|
||||
if pno < 0 {
|
||||
pno = 0;
|
||||
}
|
||||
pkg := E.comp.pkgs[pno];
|
||||
if pkg.ref >= 0 {
|
||||
E.WritePackageTag(pkg.ref); // package already exported
|
||||
return;
|
||||
@ -251,7 +258,7 @@ func (E *Exporter) Export(comp* Globals.Compilation, file_name string) {
|
||||
E.type_ref = Universe.types.len_;
|
||||
|
||||
pkg := comp.pkgs[0];
|
||||
E.WritePackage(pkg);
|
||||
E.WritePackage(0);
|
||||
E.WriteScope(pkg.scope);
|
||||
|
||||
if E.debug {
|
||||
|
@ -200,7 +200,9 @@ func (I *Importer) ReadType() *Globals.Type {
|
||||
I.type_ref++;
|
||||
|
||||
switch (typ.form) {
|
||||
default: fallthrough;
|
||||
case Type.ALIAS:
|
||||
typ.elt = I.ReadType();
|
||||
|
||||
case Type.ARRAY:
|
||||
typ.len_ = I.ReadInt();
|
||||
typ.elt = I.ReadType();
|
||||
|
@ -1633,9 +1633,21 @@ func (P *Parser) ParseTypeSpec(exported bool) {
|
||||
P.Declare(obj);
|
||||
}
|
||||
|
||||
typ := P.TryType(); // nil if we have an explicit forward declaration
|
||||
// If the next token is an identifier and we have a legal program,
|
||||
// it must be a typename. In that case this declaration introduces
|
||||
// an alias type.
|
||||
make_alias := P.tok == Scanner.IDENT;
|
||||
|
||||
// If we have an explicit forward declaration, TryType will not
|
||||
// find a type and return nil.
|
||||
typ := P.TryType();
|
||||
|
||||
if typ != nil {
|
||||
if make_alias {
|
||||
alias := Globals.NewType(Type.ALIAS);
|
||||
alias.elt = typ;
|
||||
typ = alias;
|
||||
}
|
||||
obj.typ = typ;
|
||||
if typ.obj == nil {
|
||||
typ.obj = obj; // primary type object
|
||||
|
@ -199,6 +199,9 @@ func (P *Printer) PrintTypeStruct(typ *Globals.Type) {
|
||||
}
|
||||
P.PrintType(typ);
|
||||
|
||||
case Type.ALIAS:
|
||||
P.PrintType(typ.elt);
|
||||
|
||||
case Type.ARRAY:
|
||||
print "[]";
|
||||
P.PrintType(typ.elt);
|
||||
|
@ -8,7 +8,7 @@ export
|
||||
UNDEF, BAD, NIL,
|
||||
BOOL, UINT, INT, FLOAT, STRING,
|
||||
ANY,
|
||||
ARRAY, STRUCT, INTERFACE, MAP, CHANNEL, FUNCTION, POINTER, REFERENCE
|
||||
ALIAS, ARRAY, STRUCT, INTERFACE, MAP, CHANNEL, FUNCTION, POINTER, REFERENCE
|
||||
|
||||
const /* form */ (
|
||||
// internal types
|
||||
@ -18,7 +18,7 @@ const /* form */ (
|
||||
// 'any' type
|
||||
ANY;
|
||||
// composite types
|
||||
ARRAY; STRUCT; INTERFACE; MAP; CHANNEL; FUNCTION; POINTER; REFERENCE;
|
||||
ALIAS; ARRAY; STRUCT; INTERFACE; MAP; CHANNEL; FUNCTION; POINTER; REFERENCE;
|
||||
)
|
||||
|
||||
|
||||
@ -48,6 +48,7 @@ func FormStr(form int) string {
|
||||
case FLOAT: return "FLOAT";
|
||||
case STRING: return "STRING";
|
||||
case ANY: return "ANY";
|
||||
case ALIAS: return "ALIAS";
|
||||
case ARRAY: return "ARRAY";
|
||||
case STRUCT: return "STRUCT";
|
||||
case INTERFACE: return "INTERFACE";
|
||||
|
@ -79,15 +79,17 @@ func DeclObj(kind int, ident string, typ *Globals.Type) *Globals.Object {
|
||||
}
|
||||
|
||||
|
||||
func DeclAlias(ident string, typ *Globals.Type) *Globals.Type {
|
||||
func DeclType(form int, ident string, size int) *Globals.Type {
|
||||
typ := Globals.NewType(form);
|
||||
typ.size = size;
|
||||
return DeclObj(Object.TYPE, ident, typ).typ;
|
||||
}
|
||||
|
||||
|
||||
func DeclType(form int, ident string, size int) *Globals.Type {
|
||||
typ := Globals.NewType(form);
|
||||
typ.size = size;
|
||||
return DeclAlias(ident, typ);
|
||||
func DeclAlias(ident string, typ *Globals.Type) *Globals.Type {
|
||||
alias := Globals.NewType(Type.ALIAS);
|
||||
alias.elt = typ;
|
||||
return DeclObj(Object.TYPE, ident, alias).typ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,6 +50,8 @@ func VerifyType(typ *Globals.Type) {
|
||||
break;
|
||||
case Type.ANY:
|
||||
break;
|
||||
case Type.ALIAS:
|
||||
break;
|
||||
case Type.ARRAY:
|
||||
break;
|
||||
case Type.STRUCT:
|
||||
|
Loading…
Reference in New Issue
Block a user