Commit c6eb85ae authored by Robert Griesemer's avatar Robert Griesemer

- simplified handling of primary types (types w/ names which must

  be canonicalized upon import)
- missed some exports

R=r
OCL=13733
CL=13733
parent 0abbb8c7
...@@ -120,37 +120,37 @@ func (E *Exporter) WriteScope(scope *Globals.Scope, export_all bool) { ...@@ -120,37 +120,37 @@ func (E *Exporter) WriteScope(scope *Globals.Scope, export_all bool) {
func (E *Exporter) WriteObject(obj *Globals.Object) { func (E *Exporter) WriteObject(obj *Globals.Object) {
if obj == nil { if obj == nil {
E.WriteObjectTag(Object.EOS); E.WriteObjectTag(Object.END);
return; return;
} }
if obj.kind == Object.TYPE && obj.typ.obj == obj { E.WriteObjectTag(obj.kind);
// primary type object - handled entirely by WriteType() if obj.kind == Object.TYPE {
E.WriteObjectTag(Object.PTYPE); // named types are always primary types
// and handled entirely by WriteType()
if obj.typ.obj != obj {
panic "inconsistent primary type"
}
E.WriteType(obj.typ); E.WriteType(obj.typ);
return;
}
} else { E.WriteString(obj.ident);
E.WriteObjectTag(obj.kind); E.WriteType(obj.typ);
E.WriteString(obj.ident); E.WritePackage(obj.pnolev);
E.WriteType(obj.typ);
E.WritePackage(obj.pnolev); switch obj.kind {
case Object.CONST:
switch obj.kind { E.WriteInt(0); // should be the correct value
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.TYPE:
// nothing to do case Object.FUNC:
E.WriteInt(0); // should be the correct address/offset
case Object.VAR:
E.WriteInt(0); // should be the correct address/offset default:
panic "UNREACHABLE";
case Object.FUNC:
E.WriteInt(0); // should be the correct address/offset
default:
panic "UNREACHABLE";
}
} }
} }
......
...@@ -136,43 +136,40 @@ func (I *Importer) ReadScope() *Globals.Scope { ...@@ -136,43 +136,40 @@ func (I *Importer) ReadScope() *Globals.Scope {
func (I *Importer) ReadObject() *Globals.Object { func (I *Importer) ReadObject() *Globals.Object {
tag := I.ReadObjectTag(); tag := I.ReadObjectTag();
if tag == Object.EOS { if tag == Object.END {
return nil; return nil;
} }
if tag == Object.PTYPE { if tag == Object.TYPE {
// primary type object - handled entirely by ReadType() // named types are always primary types
// and handled entirely by ReadType()
typ := I.ReadType(); typ := I.ReadType();
if typ.obj.typ != typ { if typ.obj.typ != typ {
panic "incorrect primary type"; panic "inconsistent primary type";
} }
return typ.obj; return typ.obj;
}
ident := I.ReadString();
obj := Globals.NewObject(0, tag, ident);
obj.typ = I.ReadType();
obj.pnolev = I.ReadPackage().obj.pnolev;
} else { switch (tag) {
ident := I.ReadString(); case Object.CONST:
obj := Globals.NewObject(0, tag, ident); I.ReadInt(); // should set the value field
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";
}
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;
} }
......
...@@ -7,12 +7,11 @@ package Object ...@@ -7,12 +7,11 @@ package Object
import Globals "globals" import Globals "globals"
export BAD, CONST, TYPE, VAR, FUNC, PACKAGE, LABEL, PTYPE, EOS export BAD, CONST, TYPE, VAR, FUNC, PACKAGE, LABEL, END
const /* kind */ ( const /* kind */ (
BAD = iota; // error handling BAD = iota; // error handling
CONST; TYPE; VAR; FUNC; PACKAGE; LABEL; CONST; TYPE; VAR; FUNC; PACKAGE; LABEL;
PTYPE; // primary type (import/export only) END; // end of scope (import/export only)
EOS; // end of scope (import/export only)
) )
...@@ -31,8 +30,7 @@ func KindStr(kind int) string { ...@@ -31,8 +30,7 @@ func KindStr(kind int) string {
case FUNC: return "FUNC"; case FUNC: return "FUNC";
case PACKAGE: return "PACKAGE"; case PACKAGE: return "PACKAGE";
case LABEL: return "LABEL"; case LABEL: return "LABEL";
case PTYPE: return "PTYPE"; case END: return "END";
case EOS: return "EOS";
} }
return "<unknown Object kind>"; return "<unknown Object kind>";
} }
...@@ -1649,15 +1649,21 @@ func (P *Parser) ParseConstSpec(exported bool) { ...@@ -1649,15 +1649,21 @@ func (P *Parser) ParseConstSpec(exported bool) {
typ := P.TryType(); typ := P.TryType();
if typ != nil { if typ != nil {
for p := list.first; p != nil; p = p.next { for p := list.first; p != nil; p = p.next {
p.obj.exported = exported; p.obj.typ = typ;
p.obj.typ = typ; // TODO should use/have set_type()!
} }
} }
if P.tok == Scanner.ASSIGN { if P.tok == Scanner.ASSIGN {
P.Next(); P.Next();
P.ParseExpressionList(); P.ParseExpressionList();
} }
if exported {
for p := list.first; p != nil; p = p.next {
p.obj.exported = true;
}
}
P.Ecart(); P.Ecart();
} }
...@@ -1725,6 +1731,12 @@ func (P *Parser) ParseVarSpec(exported bool) { ...@@ -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(); P.Ecart();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment