Commit bf855f5a authored by Robert Griesemer's avatar Robert Griesemer

- allow for embeded types in fields, and parameter lists w/o parameter names

- temporary work-around for 6g bug

R=r
OCL=16052
CL=16052
parent 75a03a5b
...@@ -220,7 +220,7 @@ export type Decl interface { ...@@ -220,7 +220,7 @@ export type Decl interface {
export type VarDeclList struct { export type VarDeclList struct {
idents *List; idents *List; // possibly nil
typ Type; typ Type;
} }
......
...@@ -152,22 +152,25 @@ func (P *Parser) ParseIdentList() *AST.List { ...@@ -152,22 +152,25 @@ func (P *Parser) ParseIdentList() *AST.List {
} }
func (P *Parser) ParseQualifiedIdent() AST.Expr { func (P *Parser) ParseQualifiedIdent(ident *AST.Ident) AST.Expr {
P.Trace("QualifiedIdent"); P.Trace("QualifiedIdent");
var x AST.Expr = P.ParseIdent(); if ident == nil {
if P.tok == Scanner.PERIOD { ident = P.ParseIdent();
}
var qident AST.Expr = ident;
for P.tok == Scanner.PERIOD {
pos := P.pos; pos := P.pos;
P.Next(); P.Next();
y := P.ParseIdent(); y := P.ParseIdent();
z := new(AST.Selector); z := new(AST.Selector);
z.pos, z.x, z.field = pos, x, y.val; z.pos, z.x, z.field = pos, qident, y.val;
x = z; qident = z;
} }
P.Ecart(); P.Ecart();
return x; return qident;
} }
...@@ -200,7 +203,7 @@ func (P *Parser) ParseVarType() AST.Type { ...@@ -200,7 +203,7 @@ func (P *Parser) ParseVarType() AST.Type {
func (P *Parser) ParseTypeName() AST.Type { func (P *Parser) ParseTypeName() AST.Type {
P.Trace("TypeName"); P.Trace("TypeName");
typ := P.ParseQualifiedIdent(); typ := P.ParseQualifiedIdent(nil);
P.Ecart(); P.Ecart();
return typ; return typ;
...@@ -256,8 +259,26 @@ func (P *Parser) ParseVarDeclList() *AST.VarDeclList { ...@@ -256,8 +259,26 @@ func (P *Parser) ParseVarDeclList() *AST.VarDeclList {
P.Trace("VarDeclList"); P.Trace("VarDeclList");
vars := new(AST.VarDeclList); vars := new(AST.VarDeclList);
vars.idents = P.ParseIdentList(); if P.tok == Scanner.IDENT {
vars.typ = P.ParseVarType(); vars.idents = P.ParseIdentList();
typ, ok := P.TryType();
if ok {
vars.typ = typ;
} else {
// we had an anonymous var, and the ident may be it's typename
// or the package name of a qualified identifier representing
// the typename
if vars.idents.len() == 1 {
vars.typ = P.ParseQualifiedIdent(vars.idents.at(0));
vars.idents = nil;
} else {
P.Error(P.pos, "type expected");
vars.typ = AST.NIL;
}
}
} else {
vars.typ = P.ParseVarType();
}
P.Ecart(); P.Ecart();
return vars; return vars;
...@@ -987,7 +1008,11 @@ func (P *Parser) ParseControlClause(keyword int) *AST.ControlClause { ...@@ -987,7 +1008,11 @@ func (P *Parser) ParseControlClause(keyword int) *AST.ControlClause {
} }
} }
} else { } else {
ctrl.expr, ctrl.has_expr = ctrl.init, ctrl.has_init; //ctrl.expr, ctrl.has_expr = ctrl.init, ctrl.has_init;
ctrl.expr = ctrl.init;
ctrl.has_expr = ctrl.has_init;
ctrl.init, ctrl.has_init = AST.NIL, false; ctrl.init, ctrl.has_init = AST.NIL, false;
} }
} }
......
...@@ -182,8 +182,10 @@ func (P *Printer) DoVarDecl(x *AST.VarDecl) { ...@@ -182,8 +182,10 @@ func (P *Printer) DoVarDecl(x *AST.VarDecl) {
func (P *Printer) DoVarDeclList(x *AST.VarDeclList) { func (P *Printer) DoVarDeclList(x *AST.VarDeclList) {
P.PrintList(x.idents); if x.idents != nil {
P.String(" "); P.PrintList(x.idents);
P.String(" ");
}
P.Print(x.typ); P.Print(x.typ);
} }
......
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