]> Cypherpunks repositories - gostls13.git/commitdiff
- simplified handling of primary types (types w/ names which must
authorRobert Griesemer <gri@golang.org>
Fri, 1 Aug 2008 21:50:18 +0000 (14:50 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 1 Aug 2008 21:50:18 +0000 (14:50 -0700)
  be canonicalized upon import)
- missed some exports

R=r
OCL=13733
CL=13733

usr/gri/gosrc/export.go
usr/gri/gosrc/import.go
usr/gri/gosrc/object.go
usr/gri/gosrc/parser.go

index 466296030e83ff51c307ca3b9c35ee5497a6a4e5..e127ad62667c6e071d8699f3bdf8e5ee5114be90 100755 (executable)
@@ -120,37 +120,37 @@ func (E *Exporter) WriteScope(scope *Globals.Scope, export_all bool) {
 
 func (E *Exporter) WriteObject(obj *Globals.Object) {
        if obj == nil {
-               E.WriteObjectTag(Object.EOS);
+               E.WriteObjectTag(Object.END);
                return;
        }
 
-       if obj.kind == Object.TYPE && obj.typ.obj == obj {
-               // primary type object - handled entirely by WriteType()
-               E.WriteObjectTag(Object.PTYPE);
+       E.WriteObjectTag(obj.kind);
+       if obj.kind == Object.TYPE {
+               // named types are always primary types
+               // and handled entirely by WriteType()
+               if obj.typ.obj != obj {
+                       panic "inconsistent primary type"
+               }
                E.WriteType(obj.typ);
+               return;
+       }
 
-       } else {
-               E.WriteObjectTag(obj.kind);
-               E.WriteString(obj.ident);
-               E.WriteType(obj.typ);
-               E.WritePackage(obj.pnolev);
-
-               switch obj.kind {
-               case Object.CONST:
-                       E.WriteInt(0);  // should be the correct value
-
-               case Object.TYPE:
-                       // nothing to do
-                       
-               case Object.VAR:
-                       E.WriteInt(0);  // should be the correct address/offset
-                       
-               case Object.FUNC:
-                       E.WriteInt(0);  // should be the correct address/offset
-                       
-               default:
-                       panic "UNREACHABLE";
-               }
+       E.WriteString(obj.ident);
+       E.WriteType(obj.typ);
+       E.WritePackage(obj.pnolev);
+
+       switch obj.kind {
+       case Object.CONST:
+               E.WriteInt(0);  // should be the correct value
+
+       case Object.VAR:
+               E.WriteInt(0);  // should be the correct address/offset
+               
+       case Object.FUNC:
+               E.WriteInt(0);  // should be the correct address/offset
+               
+       default:
+               panic "UNREACHABLE";
        }
 }
 
index 5f086fdcf6e31e3fa4bf4ec3cfd37d954fa1b8c7..334fcefd279390b6cafc0aa84e5c18ab61f4d366 100755 (executable)
@@ -136,43 +136,40 @@ func (I *Importer) ReadScope() *Globals.Scope {
 
 func (I *Importer) ReadObject() *Globals.Object {
        tag := I.ReadObjectTag();
-       if tag == Object.EOS {
+       if tag == Object.END {
                return nil;
        }
        
-       if tag == Object.PTYPE {
-               // primary type object - handled entirely by ReadType()
+       if tag == Object.TYPE {
+               // named types are always primary types
+               // and handled entirely by ReadType()
                typ := I.ReadType();
                if typ.obj.typ != typ {
-                       panic "incorrect primary type";
+                       panic "inconsistent primary type";
                }
                return typ.obj;
+       }
+       
+       ident := I.ReadString();
+       obj := Globals.NewObject(0, tag, ident);
+       obj.typ = I.ReadType();
+       obj.pnolev = I.ReadPackage().obj.pnolev;
 
-       } else {
-               ident := I.ReadString();
-               obj := Globals.NewObject(0, tag, ident);
-               obj.typ = I.ReadType();
-               obj.pnolev = I.ReadPackage().obj.pnolev;
-
-               switch (tag) {
-               case Object.CONST:
-                       I.ReadInt();  // should set the value field
-
-               case Object.TYPE:
-                       // nothing to do
-                       
-               case Object.VAR:
-                       I.ReadInt();  // should set the address/offset field
-
-               case Object.FUNC:
-                       I.ReadInt();  // should set the address/offset field
-                       
-               default:
-                       panic "UNREACHABLE";
-               }
+       switch (tag) {
+       case Object.CONST:
+               I.ReadInt();  // should set the value field
 
-               return obj;
+       case Object.VAR:
+               I.ReadInt();  // should set the address/offset field
+
+       case Object.FUNC:
+               I.ReadInt();  // should set the address/offset field
+               
+       default:
+               panic "UNREACHABLE";
        }
+
+       return obj;
 }
 
 
index aab80cc57eda2862240b716ac17417cdc47fdce7..aacbe8d5195ff50e3024d6c759a6802d5b991ed9 100755 (executable)
@@ -7,12 +7,11 @@ package Object
 import Globals "globals"
 
 
-export BAD, CONST, TYPE, VAR, FUNC, PACKAGE, LABEL, PTYPE, EOS
+export BAD, CONST, TYPE, VAR, FUNC, PACKAGE, LABEL, END
 const /* kind */ (
        BAD = iota;  // error handling
        CONST; TYPE; VAR; FUNC; PACKAGE; LABEL;
-       PTYPE;  // primary type (import/export only)
-       EOS;  // end of scope (import/export only)
+       END;  // end of scope (import/export only)
 )
 
 
@@ -31,8 +30,7 @@ func KindStr(kind int) string {
        case FUNC: return "FUNC";
        case PACKAGE: return "PACKAGE";
        case LABEL: return "LABEL";
-       case PTYPE: return "PTYPE";
-       case EOS: return "EOS";
+       case END: return "END";
        }
        return "<unknown Object kind>";
 }
index 02081d3a4475914975d962b69c2589b060a88434..d7e7fa0688511a857ee8713f44c4f269b9a59251 100644 (file)
@@ -1649,15 +1649,21 @@ func (P *Parser) ParseConstSpec(exported bool) {
        typ := P.TryType();
        if typ != nil {
                for p := list.first; p != nil; p = p.next {
-                       p.obj.exported = exported;
-                       p.obj.typ = typ;  // TODO should use/have set_type()!
+                       p.obj.typ = typ;
                }
        }
+       
        if P.tok == Scanner.ASSIGN {
                P.Next();
                P.ParseExpressionList();
        }
        
+       if exported {
+               for p := list.first; p != nil; p = p.next {
+                       p.obj.exported = true;
+               }
+       }
+       
        P.Ecart();
 }
 
@@ -1725,6 +1731,12 @@ func (P *Parser) ParseVarSpec(exported bool) {
                }
        }
        
+       if exported {
+               for p := list.first; p != nil; p = p.next {
+                       p.obj.exported = true;
+               }
+       }
+       
        P.Ecart();
 }