]> Cypherpunks repositories - gostls13.git/commitdiff
- fixed a bug w/ exports (wrong package info)
authorRobert Griesemer <gri@golang.org>
Thu, 31 Jul 2008 17:47:10 +0000 (10:47 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 31 Jul 2008 17:47:10 +0000 (10:47 -0700)
- keep track of type alias (type T1 T0) so we can print the proper type name

R=r
OCL=13688
CL=13688

usr/gri/gosrc/base.go
usr/gri/gosrc/decls.go
usr/gri/gosrc/export.go
usr/gri/gosrc/import.go
usr/gri/gosrc/parser.go
usr/gri/gosrc/printer.go
usr/gri/gosrc/type.go
usr/gri/gosrc/universe.go
usr/gri/gosrc/verifier.go

index 44ea1cd542c92079dd626dbcbe1ac2636a578d88..0fb95a75e52858fc7f28286e6feb2eacfc80a3a6 100755 (executable)
@@ -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
index 37b261e3bda68c24b06273550432c5137995b0dd..5570d0a0e7e2f2d8d21f31d1a54220718409e82e 100755 (executable)
@@ -6,7 +6,7 @@
 
 package decls
 
-import "base"
+//import "base"
 import base "base"
 import base2 "base"
 
index 441e68a61153a7481972c7d677edc84f6ec91ba4..9d480fc50ce9d9b1d8421d6b946bf94c109a22c9 100755 (executable)
@@ -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 {
index 66c6e2f91bc26939716fc08b71e351456cf3aa38..79ffec1022fa2322aa29bc7c000c4477d544b2d7 100755 (executable)
@@ -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();
index 45b529dd51eb58bb9235e55c07e387874f05cae1..726b8124578a0d6df2bcef74e990bda147778ec0 100644 (file)
@@ -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
index d2dafd4ecfa769e706dd60bd9c5fee7f61a003f8..4fc5d1f53848e7abcfb58abca8a6f4c954a8e41b 100755 (executable)
@@ -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);
index ea0877990ecd8e66bff1d19d0a94b30f09fba08d..ff7ddcbf286e362197ef527c4ee930b9c72e716e 100644 (file)
@@ -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";
index f0c7c396aff005888235b8759da6ab7cb23cbbe6..76f403d066ab3777ea97e466806f97ccfce9ea3d 100755 (executable)
@@ -79,15 +79,17 @@ func DeclObj(kind int, ident string, typ *Globals.Type) *Globals.Object {
 }
 
 
-func DeclAlias(ident string, typ *Globals.Type) *Globals.Type {
-       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);
+  return DeclObj(Object.TYPE, ident, typ).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;
 }
 
 
index 3ec700b25e4dbc350eff20896f09738b3034c7f9..08fedc26948aec92fca8ff939469925c64d58585 100644 (file)
@@ -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: