diff options
Diffstat (limited to 'usr/gri')
| -rw-r--r-- | usr/gri/gosrc/ast.go | 6 | ||||
| -rw-r--r-- | usr/gri/gosrc/compilation.go | 6 | ||||
| -rwxr-xr-x | usr/gri/gosrc/decls.go | 2 | ||||
| -rw-r--r-- | usr/gri/gosrc/globals.go | 16 | ||||
| -rw-r--r-- | usr/gri/gosrc/go.go | 14 | ||||
| -rw-r--r-- | usr/gri/gosrc/parser.go | 364 | ||||
| -rw-r--r-- | usr/gri/gosrc/scanner.go | 82 | ||||
| -rw-r--r-- | usr/gri/gosrc/test_scanner.go | 4 | ||||
| -rw-r--r-- | usr/gri/gosrc/verifier.go | 20 | ||||
| -rw-r--r-- | usr/gri/pretty/ast.go | 16 | ||||
| -rw-r--r-- | usr/gri/pretty/compilation.go | 30 | ||||
| -rw-r--r-- | usr/gri/pretty/globals.go | 18 | ||||
| -rw-r--r-- | usr/gri/pretty/parser.go | 224 | ||||
| -rw-r--r-- | usr/gri/pretty/scanner.go | 82 | ||||
| -rw-r--r-- | usr/gri/pretty/selftest2.go | 2 |
15 files changed, 443 insertions, 443 deletions
diff --git a/usr/gri/gosrc/ast.go b/usr/gri/gosrc/ast.go index c37c902e5a..b1d495ba77 100644 --- a/usr/gri/gosrc/ast.go +++ b/usr/gri/gosrc/ast.go @@ -33,7 +33,7 @@ func (x *Literal) typ() *Globals.Type { export func NewLiteral(pos int, typ *Globals.Type) *Literal { - x := new(Literal); + x := new(*Literal); x.pos_ = pos; x.typ_ = typ; return x; @@ -63,7 +63,7 @@ func (x *Object) typ() *Globals.Type { export func NewObject(pos int, obj* Globals.Object) *Object { - x := new(Object); + x := new(*Object); x.pos_ = pos; x.obj = obj; return x; @@ -88,7 +88,7 @@ func (x *Selector) typ() *Globals.Type { export func NewSelector(pos int, typ *Globals.Type) *Selector { - x := new(Selector); + x := new(*Selector); x.pos_ = pos; x.typ_ = typ; return x; diff --git a/usr/gri/gosrc/compilation.go b/usr/gri/gosrc/compilation.go index 595c4f1080..e72aa46545 100644 --- a/usr/gri/gosrc/compilation.go +++ b/usr/gri/gosrc/compilation.go @@ -93,16 +93,16 @@ export func Compile(comp *Globals.Compilation, src_file string) { print(src_file, "\n"); } - scanner := new(Scanner.Scanner); + scanner := new(*Scanner.Scanner); scanner.Open(src_file, src); - var tstream *chan *Scanner.Token; + var tstream chan *Scanner.Token; if comp.flags.token_chan { tstream = new(chan *Scanner.Token, 100); go scanner.Server(tstream); } - parser := new(Parser.Parser); + parser := new(*Parser.Parser); parser.Open(comp, scanner, tstream); parser.ParseProgram(); diff --git a/usr/gri/gosrc/decls.go b/usr/gri/gosrc/decls.go index b923fd1b8f..58b995a5b4 100755 --- a/usr/gri/gosrc/decls.go +++ b/usr/gri/gosrc/decls.go @@ -52,7 +52,7 @@ type T8 chan <- *T6 type T9 struct { p *T9; - q [] *map [int] *T9; + q [] map [int] *T9; f *(x, y *T9) *T9; } diff --git a/usr/gri/gosrc/globals.go b/usr/gri/gosrc/globals.go index e971a1462d..809e01f5fc 100644 --- a/usr/gri/gosrc/globals.go +++ b/usr/gri/gosrc/globals.go @@ -59,7 +59,7 @@ export type List struct { export type Scope struct { parent *Scope; entries *List; - // entries *map[string] *Object; // doesn't work properly + // entries map[string] *Object; // doesn't work properly } @@ -129,7 +129,7 @@ type Elem struct { export var Universe_void_t *Type // initialized by Universe to Universe.void_t export func NewObject(pos, kind int, ident string) *Object { - obj := new(Object); + obj := new(*Object); obj.exported = false; obj.pos = pos; obj.kind = kind; @@ -141,7 +141,7 @@ export func NewObject(pos, kind int, ident string) *Object { export func NewType(form int) *Type { - typ := new(Type); + typ := new(*Type); typ.ref = -1; // not yet exported typ.form = form; return typ; @@ -149,7 +149,7 @@ export func NewType(form int) *Type { export func NewPackage(file_name string, obj *Object, scope *Scope) *Package { - pkg := new(Package); + pkg := new(*Package); pkg.ref = -1; // not yet exported pkg.file_name = file_name; pkg.key = "<the package key>"; // empty key means package forward declaration @@ -160,12 +160,12 @@ export func NewPackage(file_name string, obj *Object, scope *Scope) *Package { export func NewList() *List { - return new(List); + return new(*List); } export func NewScope(parent *Scope) *Scope { - scope := new(Scope); + scope := new(*Scope); scope.parent = parent; scope.entries = NewList(); return scope; @@ -176,7 +176,7 @@ export func NewScope(parent *Scope) *Scope { // Object methods func (obj *Object) Copy() *Object { - copy := new(Object); + copy := new(*Object); copy.exported = obj.exported; copy.pos = obj.pos; copy.kind = obj.kind; @@ -211,7 +211,7 @@ func (L *List) Clear() { func (L *List) Add() *Elem { L.len_++; - e := new(Elem); + e := new(*Elem); if L.first == nil { L.first = e; } else { diff --git a/usr/gri/gosrc/go.go b/usr/gri/gosrc/go.go index b4e7bcb6ab..537c327932 100644 --- a/usr/gri/gosrc/go.go +++ b/usr/gri/gosrc/go.go @@ -42,14 +42,14 @@ func Next() string { func main() { arg := Next(); - + if arg == "" { PrintHelp(); return; } // collect flags and files - flags := new(Globals.Flags); + flags := new(*Globals.Flags); files := Globals.NewList(); for arg != "" { switch arg { @@ -81,20 +81,20 @@ func main() { } arg = Next(); } - + // setup environment - env := new(Globals.Environment); + env := new(*Globals.Environment); env.Import = &Compilation.Import; env.Export = &Compilation.Export; env.Compile = &Compilation.Compile; - + // compile files for p := files.first; p != nil; p = p.next { // setup compilation - comp := new(Globals.Compilation); + comp := new(*Globals.Compilation); comp.flags = flags; comp.env = env; - + // compile Compilation.Compile(comp, p.str); } diff --git a/usr/gri/gosrc/parser.go b/usr/gri/gosrc/parser.go index f908dc78e8..06a51b63e9 100644 --- a/usr/gri/gosrc/parser.go +++ b/usr/gri/gosrc/parser.go @@ -20,8 +20,8 @@ export type Parser struct { verbose bool; indent uint; S *Scanner.Scanner; - C *chan *Scanner.Token; - + C chan *Scanner.Token; + // Token tok int; // one token look-ahead pos int; // token source position @@ -77,7 +77,7 @@ func (P *Parser) Next() { } -func (P *Parser) Open(comp *Globals.Compilation, S *Scanner.Scanner, C *chan *Scanner.Token) { +func (P *Parser) Open(comp *Globals.Compilation, S *Scanner.Scanner, C chan *Scanner.Token) { P.comp = comp; P.semantic_checks = comp.flags.ast; P.verbose = comp.flags.verbosity > 2; @@ -228,7 +228,7 @@ func (P *Parser) DeclareFunc(pos int, ident string, typ *Globals.Type) *Globals. obj = Globals.NewObject(-1, Object.FUNC, ident); obj.typ = typ; // TODO do we need to set the primary type? probably... - return obj; + return obj; } // We have a matching forward declaration. Use it. @@ -262,7 +262,7 @@ func (P *Parser) ParseIdent(allow_keyword bool) (pos int, ident string) { } else { P.Expect(Scanner.IDENT); // use Expect() error handling } - + P.Ecart(); return pos, ident; } @@ -270,11 +270,11 @@ func (P *Parser) ParseIdent(allow_keyword bool) (pos int, ident string) { func (P *Parser) ParseIdentDecl(kind int) *Globals.Object { P.Trace("IdentDecl"); - + pos, ident := P.ParseIdent(kind == Object.FIELD); obj := Globals.NewObject(pos, kind, ident); P.Declare(obj); - + P.Ecart(); return obj; } @@ -282,14 +282,14 @@ func (P *Parser) ParseIdentDecl(kind int) *Globals.Object { func (P *Parser) ParseIdentDeclList(kind int) *Globals.List { P.Trace("IdentDeclList"); - + list := Globals.NewList(); list.AddObj(P.ParseIdentDecl(kind)); for P.tok == Scanner.COMMA { P.Next(); list.AddObj(P.ParseIdentDecl(kind)); } - + P.Ecart(); return list; } @@ -312,7 +312,7 @@ func (P *Parser) ParseQualifiedIdent(pos int, ident string) *Globals.Object { if pos < 0 { pos, ident = P.ParseIdent(false); } - + if P.semantic_checks { obj := P.Lookup(ident); if obj == nil { @@ -336,10 +336,10 @@ func (P *Parser) ParseQualifiedIdent(pos int, ident string) *Globals.Object { obj = Globals.NewObject(pos, Object.BAD, ident); } } - + P.Ecart(); return obj; - + } else { if P.tok == Scanner.PERIOD { P.Next(); @@ -348,7 +348,7 @@ func (P *Parser) ParseQualifiedIdent(pos int, ident string) *Globals.Object { P.Ecart(); return nil; } - + panic("UNREACHABLE"); } @@ -358,13 +358,13 @@ func (P *Parser) ParseQualifiedIdent(pos int, ident string) *Globals.Object { func (P *Parser) ParseType() *Globals.Type { P.Trace("Type"); - + typ := P.TryType(); if typ == nil { P.Error(P.pos, "type expected"); typ = Universe.bad_t; } - + P.Ecart(); return typ; } @@ -372,10 +372,10 @@ func (P *Parser) ParseType() *Globals.Type { func (P *Parser) ParseVarType() *Globals.Type { P.Trace("VarType"); - + pos := P.pos; typ := P.ParseType(); - + if P.semantic_checks { switch typ.form { case Type.ARRAY: @@ -384,13 +384,13 @@ func (P *Parser) ParseVarType() *Globals.Type { } // open arrays must be pointers fallthrough; - + case Type.MAP, Type.CHANNEL, Type.FUNCTION: P.Error(pos, "must be pointer to this type"); typ = Universe.bad_t; } } - + P.Ecart(); return typ; } @@ -398,7 +398,7 @@ func (P *Parser) ParseVarType() *Globals.Type { func (P *Parser) ParseTypeName() *Globals.Type { P.Trace("TypeName"); - + if P.semantic_checks { pos := P.pos; obj := P.ParseQualifiedIdent(-1, ""); @@ -414,14 +414,14 @@ func (P *Parser) ParseTypeName() *Globals.Type { P.Ecart(); return Universe.bad_t; } - + panic("UNREACHABLE"); } func (P *Parser) ParseArrayType() *Globals.Type { P.Trace("ArrayType"); - + P.Expect(Scanner.LBRACK); typ := Globals.NewType(Type.ARRAY); if P.tok != Scanner.RBRACK { @@ -431,14 +431,14 @@ func (P *Parser) ParseArrayType() *Globals.Type { P.Expect(Scanner.RBRACK); typ.elt = P.ParseVarType(); - P.Ecart(); + P.Ecart(); return typ; } func (P *Parser) ParseChannelType() *Globals.Type { P.Trace("ChannelType"); - + typ := Globals.NewType(Type.CHANNEL); if P.tok == Scanner.CHAN { P.Next(); @@ -455,53 +455,53 @@ func (P *Parser) ParseChannelType() *Globals.Type { } typ.elt = P.ParseVarType(); - P.Ecart(); + P.Ecart(); return typ; } func (P *Parser) ParseVarDeclList(kind int) { P.Trace("VarDeclList"); - + list := P.ParseIdentDeclList(kind); typ := P.ParseVarType(); for p := list.first; p != nil; p = p.next { p.obj.typ = typ; // TODO should use/have set_type() } - + P.Ecart(); } func (P *Parser) ParseParameterList() { P.Trace("ParameterList"); - + P.ParseVarDeclList(Object.VAR); for P.tok == Scanner.COMMA { P.Next(); P.ParseVarDeclList(Object.VAR); } - + P.Ecart(); } func (P *Parser) ParseParameters() { P.Trace("Parameters"); - + P.Expect(Scanner.LPAREN); if P.tok != Scanner.RPAREN { P.ParseParameterList(); } P.Expect(Scanner.RPAREN); - + P.Ecart(); } func (P *Parser) TryResult() bool { P.Trace("Result (try)"); - + res := false; if P.tok == Scanner.LPAREN { // TODO: here we allow empty returns - should proably fix this @@ -511,7 +511,7 @@ func (P *Parser) TryResult() bool { res = P.TryType() != nil; } P.Ecart(); - + return res; } @@ -527,15 +527,15 @@ func (P *Parser) TryResult() bool { func (P *Parser) ParseAnonymousSignature() *Globals.Type { P.Trace("AnonymousSignature"); - + P.OpenScope(); P.level--; sig := P.top_scope; p0 := 0; - + recv_pos := P.pos; P.ParseParameters(); - + if P.tok == Scanner.PERIOD { p0 = sig.entries.len_; if P.semantic_checks && p0 != 1 { @@ -546,12 +546,12 @@ func (P *Parser) ParseAnonymousSignature() *Globals.Type { P.Next(); P.ParseParameters(); } - + r0 := sig.entries.len_; P.TryResult(); P.level++; P.CloseScope(); - + P.Ecart(); return MakeFunctionType(sig, p0, r0, true); } @@ -568,7 +568,7 @@ func (P *Parser) ParseAnonymousSignature() *Globals.Type { func (P *Parser) ParseNamedSignature() (pos int, ident string, typ *Globals.Type) { P.Trace("NamedSignature"); - + P.OpenScope(); P.level--; sig := P.top_scope; @@ -585,16 +585,16 @@ func (P *Parser) ParseNamedSignature() (pos int, ident string, typ *Globals.Type // TODO do something useful here } } - + pos, ident = P.ParseIdent(true); P.ParseParameters(); - + r0 := sig.entries.len_; P.TryResult(); P.level++; P.CloseScope(); - + P.Ecart(); return pos, ident, MakeFunctionType(sig, p0, r0, true); } @@ -602,9 +602,9 @@ func (P *Parser) ParseNamedSignature() (pos int, ident string, typ *Globals.Type func (P *Parser) ParseFunctionType() *Globals.Type { P.Trace("FunctionType"); - + typ := P.ParseAnonymousSignature(); - + P.Ecart(); return typ; } @@ -612,36 +612,36 @@ func (P *Parser) ParseFunctionType() *Globals.Type { func (P *Parser) ParseMethodDecl(recv_typ *Globals.Type) { P.Trace("MethodDecl"); - + pos, ident := P.ParseIdent(true); P.OpenScope(); P.level--; sig := P.top_scope; - + // dummy receiver (give it a name so it won't conflict with unnamed result) recv := Globals.NewObject(pos, Object.VAR, ".recv"); recv.typ = recv_typ; sig.Insert(recv); - + P.ParseParameters(); - + r0 := sig.entries.len_; P.TryResult(); P.level++; P.CloseScope(); P.Optional(Scanner.SEMICOLON); - + obj := Globals.NewObject(pos, Object.FUNC, ident); obj.typ = MakeFunctionType(sig, 1, r0, true); P.Declare(obj); - + P.Ecart(); } func (P *Parser) ParseInterfaceType() *Globals.Type { P.Trace("InterfaceType"); - + P.Expect(Scanner.INTERFACE); P.Expect(Scanner.LBRACE); P.OpenScope(); @@ -654,7 +654,7 @@ func (P *Parser) ParseInterfaceType() *Globals.Type { P.level++; P.CloseScope(); P.Expect(Scanner.RBRACE); - + P.Ecart(); return typ; } @@ -662,7 +662,7 @@ func (P *Parser) ParseInterfaceType() *Globals.Type { func (P *Parser) ParseMapType() *Globals.Type { P.Trace("MapType"); - + P.Expect(Scanner.MAP); P.Expect(Scanner.LBRACK); typ := Globals.NewType(Type.MAP); @@ -670,14 +670,14 @@ func (P *Parser) ParseMapType() *Globals.Type { P.Expect(Scanner.RBRACK); typ.elt = P.ParseVarType(); P.Ecart(); - + return typ; } func (P *Parser) ParseStructType() *Globals.Type { P.Trace("StructType"); - + P.Expect(Scanner.STRUCT); P.Expect(Scanner.LBRACE); P.OpenScope(); @@ -694,7 +694,7 @@ func (P *Parser) ParseStructType() *Globals.Type { P.level++; P.CloseScope(); P.Expect(Scanner.RBRACE); - + P.Ecart(); return typ; } @@ -702,10 +702,10 @@ func (P *Parser) ParseStructType() *Globals.Type { func (P *Parser) ParsePointerType() *Globals.Type { P.Trace("PointerType"); - + P.Expect(Scanner.MUL); typ := Globals.NewType(Type.POINTER); - + var elt *Globals.Type; if P.semantic_checks { if P.tok == Scanner.STRING && !P.comp.flags.sixg { @@ -727,7 +727,7 @@ func (P *Parser) ParsePointerType() *Globals.Type { // TODO introduce dummy package so we can continue safely } } - + P.Next(); // consume package name P.Expect(Scanner.PERIOD); pos, ident := P.ParseIdent(false); @@ -747,11 +747,11 @@ func (P *Parser) ParsePointerType() *Globals.Type { } elt = obj.typ; } - + } else if P.tok == Scanner.IDENT { if P.Lookup(P.val) == nil { // implicit type forward declaration - // create a named forward type + // create a named forward type pos, ident := P.ParseIdent(false); obj := Globals.NewObject(pos, Object.TYPE, ident); elt = Globals.NewType(Type.FORWARD); @@ -760,7 +760,7 @@ func (P *Parser) ParsePointerType() *Globals.Type { // remember the current scope - resolving the forward // type must find a matching declaration in this or a less nested scope elt.scope = P.top_scope; - + } else { // type name // (ParseType() (via TryType()) checks for forward types and complains, @@ -774,17 +774,17 @@ func (P *Parser) ParsePointerType() *Globals.Type { if elt.form == Type.FORWARD { P.forward_types.AddTyp(typ); } - + } else { elt = P.ParseType(); } - + } else { elt = P.ParseType(); } typ.elt = elt; - + P.Ecart(); return typ; } @@ -793,7 +793,7 @@ func (P *Parser) ParsePointerType() *Globals.Type { // Returns nil if no type was found. func (P *Parser) TryType() *Globals.Type { P.Trace("Type (try)"); - + pos := P.pos; var typ *Globals.Type = nil; switch P.tok { @@ -840,7 +840,7 @@ func (P *Parser) ParseStatementList() { func (P *Parser) ParseBlock(sig *Globals.Scope) { P.Trace("Block"); - + P.Expect(Scanner.LBRACE); P.OpenScope(); if sig != nil { @@ -860,7 +860,7 @@ func (P *Parser) ParseBlock(sig *Globals.Scope) { } P.CloseScope(); P.Expect(Scanner.RBRACE); - + P.Ecart(); } @@ -870,23 +870,23 @@ func (P *Parser) ParseBlock(sig *Globals.Scope) { func (P *Parser) ParseExpressionList(list *Globals.List) { P.Trace("ExpressionList"); - + list.AddExpr(P.ParseExpression()); for P.tok == Scanner.COMMA { P.Next(); list.AddExpr(P.ParseExpression()); } - + P.Ecart(); } func (P *Parser) ParseNewExpressionList() *Globals.List { P.Trace("NewExpressionList"); - + list := Globals.NewList(); P.ParseExpressionList(list); - + P.Ecart(); return list; } @@ -894,7 +894,7 @@ func (P *Parser) ParseNewExpressionList() *Globals.List { func (P *Parser) ParseNew() Globals.Expr { P.Trace("New"); - + P.Expect(Scanner.NEW); P.Expect(Scanner.LPAREN); P.ParseType(); @@ -904,7 +904,7 @@ func (P *Parser) ParseNew() Globals.Expr { P.ParseExpressionList(args) } P.Expect(Scanner.RPAREN); - + P.Ecart(); return nil; } @@ -912,11 +912,11 @@ func (P *Parser) ParseNew() Globals.Expr { func (P *Parser) ParseFunctionLit() Globals.Expr { P.Trace("FunctionLit"); - + P.Expect(Scanner.FUNC); typ := P.ParseFunctionType(); P.ParseBlock(typ.scope); - + P.Ecart(); return nil; } @@ -928,7 +928,7 @@ func (P *Parser) ParseExpressionPair(list *Globals.List) { list.AddExpr(P.ParseExpression()); P.Expect(Scanner.COLON); list.AddExpr(P.ParseExpression()); - + P.Ecart(); } @@ -940,14 +940,14 @@ func (P *Parser) ParseExpressionPairList(list *Globals.List) { for (P.tok == Scanner.COMMA) { P.ParseExpressionPair(list); } - + P.Ecart(); } func (P *Parser) ParseCompositeLit(typ *Globals.Type) Globals.Expr { P.Trace("CompositeLit"); - + P.Expect(Scanner.LBRACE); // TODO: should allow trailing ',' list := Globals.NewList(); @@ -999,16 +999,16 @@ func (P *Parser) ParseOperand(pos int, ident string) Globals.Expr { } } else { - + switch P.tok { case Scanner.IDENT: panic("UNREACHABLE"); - + case Scanner.LPAREN: P.Next(); res = P.ParseExpression(); P.Expect(Scanner.RPAREN); - + case Scanner.INT: x := AST.NewLiteral(P.pos, Universe.int_t); x.i = 42; // TODO set the right value @@ -1030,7 +1030,7 @@ func (P *Parser) ParseOperand(pos int, ident string) Globals.Expr { case Scanner.NIL: P.Next(); res = AST.Nil; - + case Scanner.IOTA: x := AST.NewLiteral(P.pos, Universe.int_t); x.i = 42; // TODO set the right value @@ -1044,13 +1044,13 @@ func (P *Parser) ParseOperand(pos int, ident string) Globals.Expr { case Scanner.FALSE: P.Next(); res = AST.False; - + case Scanner.FUNC: res = P.ParseFunctionLit(); - + case Scanner.NEW: res = P.ParseNew(); - + default: typ := P.TryType(); if typ != nil { @@ -1060,7 +1060,7 @@ func (P *Parser) ParseOperand(pos int, ident string) Globals.Expr { P.Next(); // make progress } } - + } P.Ecart(); @@ -1073,10 +1073,10 @@ func (P *Parser) ParseSelectorOrTypeAssertion(x Globals.Expr) Globals.Expr { period_pos := P.pos; P.Expect(Scanner.PERIOD); - + if P.tok >= Scanner.IDENT { ident_pos, ident := P.ParseIdent(true); - + if P.semantic_checks { switch typ := x.typ(); typ.form { case Type.BAD: @@ -1086,7 +1086,7 @@ func (P *Parser) ParseSelectorOrTypeAssertion(x Globals.Expr) Globals.Expr { obj := typ.scope.Lookup(ident); if obj != nil { x = AST.NewSelector(x.pos(), obj.typ); - + } else { P.Error(ident_pos, `no field/method "` + ident + `"`); x = AST.Bad; @@ -1096,17 +1096,17 @@ func (P *Parser) ParseSelectorOrTypeAssertion(x Globals.Expr) Globals.Expr { x = AST.Bad; } } - + } else { P.Expect(Scanner.LPAREN); P.ParseType(); P.Expect(Scanner.RPAREN); - + if P.semantic_checks { panic("UNIMPLEMENTED"); } } - + P.Ecart(); return x; } @@ -1114,7 +1114,7 @@ func (P *Parser) ParseSelectorOrTypeAssertion(x Globals.Expr) Globals.Expr { func (P *Parser) ParseIndexOrSlice(x Globals.Expr) Globals.Expr { P.Trace("IndexOrSlice"); - + pos := P.pos; P.Expect(Scanner.LBRACK); i1 := P.ParseExpression(); @@ -1124,7 +1124,7 @@ func (P *Parser) ParseIndexOrSlice(x Globals.Expr) Globals.Expr { i2 := P.ParseExpression(); } P.Expect(Scanner.RBRACK); - + if P.semantic_checks { switch typ := x.typ(); typ.form { case Type.BAD: @@ -1132,24 +1132,24 @@ func (P *Parser) ParseIndexOrSlice(x Globals.Expr) Globals.Expr { break; case Type.STRING, Type.ARRAY: panic("UNIMPLEMENTED"); - + case Type.MAP: if Type.Equal(typ.aux, i1.typ()) { // x = AST.NewSubscript(x, i1); panic("UNIMPLEMENTED"); - + } else { P.Error(x.pos(), "map key type mismatch"); x = AST.Bad; } - + default: P.Error(pos, `"[]" not applicable`); x = AST.Bad; } - + } - + P.Ecart(); return x; } @@ -1168,7 +1168,7 @@ func (P *Parser) ParseCall(x Globals.Expr) Globals.Expr { if P.semantic_checks { panic("UNIMPLEMENTED"); } - + P.Ecart(); return x; } @@ -1176,7 +1176,7 @@ func (P *Parser) ParseCall(x Globals.Expr) Globals.Expr { func (P *Parser) ParsePrimaryExpr(pos int, ident string) Globals.Expr { P.Trace("PrimaryExpr"); - + x := P.ParseOperand(pos, ident); for { switch P.tok { @@ -1203,7 +1203,7 @@ func (P *Parser) ParsePrimaryExprList() *Globals.List { P.Next(); list.AddExpr(P.ParsePrimaryExpr(-1, "")); } - + P.Ecart(); return list; } @@ -1211,7 +1211,7 @@ func (P *Parser) ParsePrimaryExprList() *Globals.List { func (P *Parser) ParseUnaryExpr() Globals.Expr { P.Trace("UnaryExpr"); - + switch P.tok { case Scanner.ADD: fallthrough; case Scanner.SUB: fallthrough; @@ -1226,7 +1226,7 @@ func (P *Parser) ParseUnaryExpr() Globals.Expr { return nil; // TODO fix this } P.ParsePrimaryExpr(-1, ""); - + P.Ecart(); return nil; // TODO fix this } @@ -1254,7 +1254,7 @@ func Precedence(tok int) int { func (P *Parser) ParseBinaryExpr(pos int, ident string, prec1 int) Globals.Expr { P.Trace("BinaryExpr"); - + var x Globals.Expr; if pos >= 0 { x = P.ParsePrimaryExpr(pos, ident); @@ -1263,7 +1263,7 @@ func (P *Parser) ParseBinaryExpr(pos int, ident string, prec1 int) Globals.Expr } for prec := Precedence(P.tok); prec >= prec1; prec-- { for Precedence(P.tok) == prec { - e := new(AST.BinaryExpr); + e := new(*AST.BinaryExpr); e.typ_ = Universe.bad_t; // TODO fix this e.op = P.tok; // TODO should we use tokens or separate operator constants? e.x = x; @@ -1272,7 +1272,7 @@ func (P *Parser) ParseBinaryExpr(pos int, ident string, prec1 int) Globals.Expr x = e; } } - + P.Ecart(); return x; } @@ -1284,9 +1284,9 @@ func (P *Parser) ParseBinaryExpr(pos int, ident string, prec1 int) Globals.Expr func (P *Parser) ParseIdentExpression(pos int, ident string) Globals.Expr { P.Trace("IdentExpression"); indent := P.indent; - + x := P.ParseBinaryExpr(pos, ident, 1); - + if indent != P.indent { panic("imbalanced tracing code (Expression)"); } @@ -1297,7 +1297,7 @@ func (P *Parser) ParseIdentExpression(pos int, ident string) Globals.Expr { func (P *Parser) ParseExpression() Globals.Expr { P.Trace("Expression"); - + x := P.ParseIdentExpression(-1, ""); P.Ecart(); @@ -1326,7 +1326,7 @@ func (P *Parser) ConvertToExprList(pos_list, ident_list, expr_list *Globals.List func (P *Parser) ParseIdentOrExpr(pos_list, ident_list, expr_list *Globals.List) { P.Trace("IdentOrExpr"); - + pos_list.AddInt(P.pos); pos, ident := -1, ""; just_ident := false; @@ -1360,21 +1360,21 @@ func (P *Parser) ParseIdentOrExpr(pos_list, ident_list, expr_list *Globals.List) P.ParseIdentExpression(pos, ident); expr_list.AddInt(0); // TODO fix this - add correct expression } - + P.Ecart(); } func (P *Parser) ParseIdentOrExprList() (pos_list, ident_list, expr_list *Globals.List) { P.Trace("IdentOrExprList"); - + pos_list, ident_list, expr_list = Globals.NewList(), Globals.NewList(), Globals.NewList(); P.ParseIdentOrExpr(pos_list, ident_list, expr_list); for P.tok == Scanner.COMMA { P.Next(); P.ParseIdentOrExpr(pos_list, ident_list, expr_list); } - + P.Ecart(); return pos_list, ident_list, expr_list; } @@ -1382,7 +1382,7 @@ func (P *Parser) ParseIdentOrExprList() (pos_list, ident_list, expr_list *Global func (P *Parser) ParseSimpleStat() { P.Trace("SimpleStat"); - + // If we see an identifier, we don't know if it's part of a // label declaration, (multiple) variable declaration, assignment, // or simply an expression, without looking ahead. @@ -1393,7 +1393,7 @@ func (P *Parser) ParseSimpleStat() { // a non-empty list of identifiers or a non-empty list of expressions // (but not both). pos_list, ident_list, expr_list := P.ParseIdentOrExprList(); - + switch P.tok { case Scanner.COLON: // label declaration @@ -1401,7 +1401,7 @@ func (P *Parser) ParseSimpleStat() { P.Error(P.pos, "illegal label declaration"); } P.Next(); - + case Scanner.DEFINE: // variable declaration if P.semantic_checks && ident_list.len_ == 0 { @@ -1421,7 +1421,7 @@ func (P *Parser) ParseSimpleStat() { // TODO set correct types } } - + case Scanner.ASSIGN: fallthrough; case Scanner.ADD_ASSIGN: fallthrough; case Scanner.SUB_ASSIGN: fallthrough; @@ -1440,7 +1440,7 @@ func (P *Parser) ParseSimpleStat() { if P.semantic_checks && val_list.len_ != expr_list.len_ { P.Error(pos, "number of expressions does not match number of variables"); } - + default: P.ConvertToExprList(pos_list, ident_list, expr_list); if P.semantic_checks && expr_list.len_ != 1 { @@ -1450,49 +1450,49 @@ func (P *Parser) ParseSimpleStat() { P.Next(); } } - + P.Ecart(); } func (P *Parser) ParseGoStat() { P.Trace("GoStat"); - + P.Expect(Scanner.GO); P.ParseExpression(); - + P.Ecart(); } func (P *Parser) ParseReturnStat() { P.Trace("ReturnStat"); - + P.Expect(Scanner.RETURN); res := Globals.NewList(); if P.tok != Scanner.SEMICOLON && P.tok != Scanner.RBRACE { P.ParseExpressionList(res); } - + P.Ecart(); } func (P *Parser) ParseControlFlowStat(tok int) { P.Trace("ControlFlowStat"); - + P.Expect(tok); if P.tok == Scanner.IDENT { P.ParseIdent(false); } - + P.Ecart(); } func (P *Parser) ParseIfStat() *AST.IfStat { P.Trace("IfStat"); - + P.Expect(Scanner.IF); P.OpenScope(); if P.tok != Scanner.LBRACE { @@ -1517,7 +1517,7 @@ func (P *Parser) ParseIfStat() *AST.IfStat { } } P.CloseScope(); - + P.Ecart(); return nil; } @@ -1525,7 +1525,7 @@ func (P *Parser) ParseIfStat() *AST.IfStat { func (P *Parser) ParseForStat() { P.Trace("ForStat"); - + P.Expect(Scanner.FOR); P.OpenScope(); if P.tok != Scanner.LBRACE { @@ -1545,14 +1545,14 @@ func (P *Parser) ParseForStat() { } P.ParseBlock(nil); P.CloseScope(); - + P.Ecart(); } func (P *Parser) ParseCase() { P.Trace("Case"); - + if P.tok == Scanner.CASE { P.Next(); list := Globals.NewList(); @@ -1561,14 +1561,14 @@ func (P *Parser) ParseCase() { P.Expect(Scanner.DEFAULT); } P.Expect(Scanner.COLON); - + P.Ecart(); } func (P *Parser) ParseCaseClause() { P.Trace("CaseClause"); - + P.ParseCase(); if P.tok != Scanner.FALLTHROUGH && P.tok != Scanner.RBRACE { P.ParseStatementList(); @@ -1578,14 +1578,14 @@ func (P *Parser) ParseCaseClause() { P.Next(); P.Optional(Scanner.SEMICOLON); } - + P.Ecart(); } func (P *Parser) ParseSwitchStat() { P.Trace("SwitchStat"); - + P.Expect(Scanner.SWITCH); P.OpenScope(); if P.tok != Scanner.LBRACE { @@ -1605,14 +1605,14 @@ func (P *Parser) ParseSwitchStat() { } P.Expect(Scanner.RBRACE); P.CloseScope(); - + P.Ecart(); } func (P *Parser) ParseCommCase() { P.Trace("CommCase"); - + if P.tok == Scanner.CASE { P.Next(); if P.tok == Scanner.GTR { @@ -1634,47 +1634,47 @@ func (P *Parser) ParseCommCase() { P.Expect(Scanner.DEFAULT); } P.Expect(Scanner.COLON); - + P.Ecart(); } func (P *Parser) ParseCommClause() { P.Trace("CommClause"); - + P.ParseCommCase(); if P.tok != Scanner.CASE && P.tok != Scanner.DEFAULT && P.tok != Scanner.RBRACE { P.ParseStatementList(); P.Optional(Scanner.SEMICOLON); } - + P.Ecart(); } func (P *Parser) ParseRangeStat() { P.Trace("RangeStat"); - + P.Expect(Scanner.RANGE); P.ParseIdentList(); P.Expect(Scanner.DEFINE); P.ParseExpression(); P.ParseBlock(nil); - + P.Ecart(); } func (P *Parser) ParseSelectStat() { P.Trace("SelectStat"); - + P.Expect(Scanner.SELECT); P.Expect(Scanner.LBRACE); for P.tok != Scanner.RBRACE && P.tok != Scanner.EOF { P.ParseCommClause(); } P.Next(); - + P.Ecart(); } @@ -1730,7 +1730,7 @@ func (P *Parser) TryStatement() bool { func (P *Parser) ParseImportSpec() { P.Trace("ImportSpec"); - + var obj *Globals.Object = nil; if P.tok == Scanner.PERIOD { P.Error(P.pos, `"import ." not yet handled properly`); @@ -1738,7 +1738,7 @@ func (P *Parser) ParseImportSpec() { } else if P.tok == Scanner.IDENT { obj = P.ParseIdentDecl(Object.PACKAGE); } - + if P.semantic_checks && P.tok == Scanner.STRING { // TODO eventually the scanner should strip the quotes pkg_name := P.val[1 : len(P.val) - 1]; // strip quotes @@ -1760,14 +1760,14 @@ func (P *Parser) ParseImportSpec() { } else { P.Expect(Scanner.STRING); // use Expect() error handling } - + P.Ecart(); } func (P *Parser) ParseConstSpec(exported bool) { P.Trace("ConstSpec"); - + list := P.ParseIdentDeclList(Object.CONST); typ := P.TryType(); if typ != nil { @@ -1775,18 +1775,18 @@ func (P *Parser) ParseConstSpec(exported bool) { p.obj.typ = typ; } } - + if P.tok == Scanner.ASSIGN { P.Next(); P.ParseNewExpressionList(); } - + if exported { for p := list.first; p != nil; p = p.next { p.obj.exported = true; } } - + P.Ecart(); } @@ -1795,10 +1795,10 @@ func (P *Parser) ParseTypeSpec(exported bool) { P.Trace("TypeSpec"); var typ *Globals.Type; - + pos, ident := P.ParseIdent(false); obj := P.Lookup(ident); - + if !P.comp.flags.sixg && obj != nil { if obj.typ.form == Type.FORWARD { // imported forward-declared type @@ -1808,7 +1808,7 @@ func (P *Parser) ParseTypeSpec(exported bool) { } else { panic("bar"); } - + } else { // Immediately after declaration of the type name, the type is // considered forward-declared. It may be referred to from inside @@ -1843,7 +1843,7 @@ func (P *Parser) ParseTypeSpec(exported bool) { if typ.obj == nil { typ.obj = obj; // primary type object } - + // if the type is exported, for now we export all fields // of structs and interfaces by default // TODO this needs to change eventually @@ -1853,14 +1853,14 @@ func (P *Parser) ParseTypeSpec(exported bool) { p.obj.exported = true; } } - + P.Ecart(); } func (P *Parser) ParseVarSpec(exported bool) { P.Trace("VarSpec"); - + list := P.ParseIdentDeclList(Object.VAR); if P.tok == Scanner.ASSIGN { P.Next(); @@ -1875,13 +1875,13 @@ func (P *Parser) ParseVarSpec(exported bool) { P.ParseNewExpressionList(); } } - + if exported { for p := list.first; p != nil; p = p.next { p.obj.exported = true; } } - + P.Ecart(); } @@ -1900,7 +1900,7 @@ func (P *Parser) ParseSpec(exported bool, keyword int) { func (P *Parser) ParseDecl(exported bool, keyword int) { P.Trace("Decl"); - + P.Expect(keyword); if P.tok == Scanner.LPAREN { P.Next(); @@ -1915,14 +1915,14 @@ func (P *Parser) ParseDecl(exported bool, keyword int) { } else { P.ParseSpec(exported, keyword); } - + P.Ecart(); } func (P *Parser) ParseFuncDecl(exported bool) { P.Trace("FuncDecl"); - + P.Expect(Scanner.FUNC); pos, ident, typ := P.ParseNamedSignature(); obj := P.DeclareFunc(pos, ident, typ); // need obj later for statements @@ -1933,14 +1933,14 @@ func (P *Parser) ParseFuncDecl(exported bool) { } else { P.ParseBlock(typ.scope); } - + P.Ecart(); } func (P *Parser) ParseExportDecl() { P.Trace("ExportDecl"); - + // TODO This is deprecated syntax and should go away eventually. // (Also at the moment the syntax is everything goes...) //P.Expect(Scanner.EXPORT); @@ -1948,7 +1948,7 @@ func (P *Parser) ParseExportDecl() { if !P.comp.flags.sixg { P.Error(P.pos, "deprecated export syntax (use -6g to enable)"); } - + has_paren := false; if P.tok == Scanner.LPAREN { P.Next(); @@ -1962,7 +1962,7 @@ func (P *Parser) ParseExportDecl() { if has_paren { P.Expect(Scanner.RPAREN) } - + P.Ecart(); } @@ -1970,7 +1970,7 @@ func (P *Parser) ParseExportDecl() { func (P *Parser) ParseDeclaration() { P.Trace("Declaration"); indent := P.indent; - + exported := false; if P.tok == Scanner.EXPORT { if P.level == 0 { @@ -1980,7 +1980,7 @@ func (P *Parser) ParseDeclaration() { } P.Next(); } - + switch P.tok { case Scanner.CONST, Scanner.TYPE, Scanner.VAR: P.ParseDecl(exported, P.tok); @@ -2000,7 +2000,7 @@ func (P *Parser) ParseDeclaration() { P.Next(); // make progress } } - + if indent != P.indent { panic("imbalanced tracing code (Declaration)"); } @@ -2015,18 +2015,18 @@ func (P *Parser) ResolveForwardTypes() { if !P.semantic_checks { return; } - + for p := P.forward_types.first; p != nil; p = p.next { typ := p.typ; if typ.form != Type.POINTER { panic("unresolved types should be pointers only"); } - + elt := typ.elt; if typ.elt.form != Type.FORWARD { panic("unresolved pointer should point to forward type"); } - + obj := elt.obj; if obj.typ == elt { // actual forward declaration (as opposed to forward types introduced @@ -2047,7 +2047,7 @@ func (P *Parser) ResolveForwardTypes() { // update the pointer type typ.elt = obj.typ; - + // TODO as long as we don't *use* a forward type, we are ok // => consider not reporting this as an error // (in a real forward declaration, the corresponding objects are not in a scope @@ -2063,7 +2063,7 @@ func (P *Parser) MarkExports() { if !P.semantic_checks { return; } - + scope := P.top_scope; for p := P.exports.first; p != nil; p = p.next { obj := scope.Lookup(p.str); @@ -2090,17 +2090,17 @@ func (P *Parser) MarkExports() { func (P *Parser) ParseProgram() { P.Trace("Program"); - + P.OpenScope(); P.Expect(Scanner.PACKAGE); obj := P.ParseIdentDecl(Object.PACKAGE); P.Optional(Scanner.SEMICOLON); - + { P.OpenScope(); if P.level != 0 { panic("incorrect scope level"); } - + P.comp.Insert(Globals.NewPackage(P.S.filename, obj, P.top_scope)); if P.comp.pkg_ref != 1 { panic("should have exactly one package now"); @@ -2110,21 +2110,21 @@ func (P *Parser) ParseProgram() { P.ParseDecl(false, Scanner.IMPORT); P.Optional(Scanner.SEMICOLON); } - + for P.tok != Scanner.EOF { P.ParseDeclaration(); P.Optional(Scanner.SEMICOLON); } - + P.ResolveForwardTypes(); P.MarkExports(); - + if P.level != 0 { panic("incorrect scope level"); } P.CloseScope(); } - + P.CloseScope(); P.Ecart(); } diff --git a/usr/gri/gosrc/scanner.go b/usr/gri/gosrc/scanner.go index bfb8e3c360..a1e18ba35c 100644 --- a/usr/gri/gosrc/scanner.go +++ b/usr/gri/gosrc/scanner.go @@ -26,24 +26,24 @@ export const ( RBRACK; LBRACE; RBRACE; - + ASSIGN; DEFINE; - + INC; DEC; NOT; - + AND; OR; XOR; - + ADD; SUB; MUL; QUO; REM; - + EQL; NEQ; LSS; @@ -53,7 +53,7 @@ export const ( SHL; SHR; - + ARROW; ADD_ASSIGN; @@ -65,13 +65,13 @@ export const ( AND_ASSIGN; OR_ASSIGN; XOR_ASSIGN; - + SHL_ASSIGN; SHR_ASSIGN; LAND; LOR; - + // IDENT must be immediately before keywords IDENT; @@ -111,7 +111,7 @@ export const ( ) -var Keywords *map [string] int; +var Keywords map [string] int; var VerboseMsgs bool; // error message customization @@ -137,7 +137,7 @@ export func TokenName(tok int) string { case ASSIGN: return "="; case DEFINE: return ":="; - + case INC: return "++"; case DEC: return "--"; case NOT: return "!"; @@ -145,13 +145,13 @@ export func TokenName(tok int) string { case AND: return "&"; case OR: return "|"; case XOR: return "^"; - + case ADD: return "+"; case SUB: return "-"; case MUL: return "*"; case QUO: return "/"; case REM: return "%"; - + case EQL: return "=="; case NEQ: return "!="; case LSS: return "<"; @@ -161,7 +161,7 @@ export func TokenName(tok int) string { case SHL: return "<<"; case SHR: return ">>"; - + case ARROW: return "<-"; case ADD_ASSIGN: return "+="; @@ -213,18 +213,18 @@ export func TokenName(tok int) string { case TYPE: return "type"; case VAR: return "var"; } - + return "???"; } func init() { Keywords = new(map [string] int); - + for i := KEYWORDS_BEG; i <= KEYWORDS_END; i++ { Keywords[TokenName(i)] = i; } - + // Provide column information in error messages for gri only... VerboseMsgs = Platform.USER == "gri"; } @@ -258,7 +258,7 @@ export type Scanner struct { filename string; // error reporting only nerrors int; // number of errors errpos int; // last error position - + src string; // scanned source pos int; // current reading position ch int; // one char look-ahead @@ -296,7 +296,7 @@ func (S *Scanner) Next() { src := S.src; lim := len(src); pos := S.pos; - + // 1-byte sequence // 0000-007F => T1 if pos >= lim { @@ -371,7 +371,7 @@ bad: func (S *Scanner) LineCol(pos int) (line, col int) { line = 1; lpos := 0; - + src := S.src; if pos > len(src) { pos = len(src); @@ -383,7 +383,7 @@ func (S *Scanner) LineCol(pos int) (line, col int) { lpos = i; } } - + return line, pos - lpos; } @@ -409,7 +409,7 @@ func (S *Scanner) Error(pos int, msg string) { S.nerrors++; S.errpos = pos; } - + if S.nerrors >= 10 { sys.exit(1); } @@ -420,7 +420,7 @@ func (S *Scanner) Open(filename, src string) { S.filename = filename; S.nerrors = 0; S.errpos = 0; - + S.src = src; S.pos = 0; S.Next(); @@ -467,7 +467,7 @@ func (S *Scanner) SkipComment() { for S.ch != '\n' && S.ch >= 0 { S.Next(); } - + } else { /* comment */ pos := S.chpos - 1; @@ -491,13 +491,13 @@ func (S *Scanner) ScanIdentifier() (tok int, val string) { S.Next(); } val = S.src[pos : S.chpos]; - + var present bool; tok, present = Keywords[val]; if !present { tok = IDENT; } - + return tok, val; } @@ -512,14 +512,14 @@ func (S *Scanner) ScanMantissa(base int) { func (S *Scanner) ScanNumber(seen_decimal_point bool) (tok int, val string) { pos := S.chpos; tok = INT; - + if seen_decimal_point { tok = FLOAT; pos--; // '.' is one byte S.ScanMantissa(10); goto exponent; } - + if S.ch == '0' { // int or float S.Next(); @@ -539,18 +539,18 @@ func (S *Scanner) ScanNumber(seen_decimal_point bool) (tok int, val string) { } goto exit; } - + mantissa: // decimal int or float S.ScanMantissa(10); - + if S.ch == '.' { // float tok = FLOAT; S.Next(); S.ScanMantissa(10) } - + exponent: if S.ch == 'e' || S.ch == 'E' { // float @@ -561,7 +561,7 @@ exponent: } S.ScanMantissa(10); } - + exit: return tok, S.src[pos : S.chpos]; } @@ -580,22 +580,22 @@ func (S *Scanner) ScanDigits(n int, base int) { func (S *Scanner) ScanEscape() string { // TODO: fix this routine - + ch := S.ch; pos := S.chpos; S.Next(); switch (ch) { case 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', '\'', '"': return string(ch); - + case '0', '1', '2', '3', '4', '5', '6', '7': S.ScanDigits(3 - 1, 8); // 1 char already read return ""; // TODO fix this - + case 'x': S.ScanDigits(2, 16); return ""; // TODO fix this - + case 'u': S.ScanDigits(4, 16); return ""; // TODO fix this @@ -642,7 +642,7 @@ func (S *Scanner) ScanString() string { S.ScanEscape(); } } - + S.Next(); return S.src[pos : S.chpos]; } @@ -707,11 +707,11 @@ func (S *Scanner) Select4(tok0, tok1, ch2, tok2, tok3 int) int { func (S *Scanner) Scan() (tok, pos int, val string) { S.SkipWhitespace(); - + ch := S.ch; tok = ILLEGAL; pos = S.chpos; - + switch { case is_letter(ch): tok, val = S.ScanIdentifier(); case digit_val(ch) < 10: tok, val = S.ScanNumber(false); @@ -767,7 +767,7 @@ func (S *Scanner) Scan() (tok, pos int, val string) { tok = ILLEGAL; } } - + return tok, pos, val; } @@ -779,9 +779,9 @@ export type Token struct { } -func (S *Scanner) Server(c *chan *Token) { +func (S *Scanner) Server(c chan *Token) { for { - t := new(Token); + t := new(*Token); t.tok, t.pos, t.val = S.Scan(); c <- t; if t.tok == EOF { diff --git a/usr/gri/gosrc/test_scanner.go b/usr/gri/gosrc/test_scanner.go index ffdc0b56fc..b43810a856 100644 --- a/usr/gri/gosrc/test_scanner.go +++ b/usr/gri/gosrc/test_scanner.go @@ -8,7 +8,7 @@ import Scanner "scanner" func Scan1(filename, src string) { - S := new(Scanner.Scanner); + S := new(*Scanner.Scanner); S.Open(filename, src); for { tok, pos, val := S.Scan(); @@ -25,7 +25,7 @@ func Scan1(filename, src string) { func Scan2(filename, src string) { - S := new(Scanner.Scanner); + S := new(*Scanner.Scanner); S.Open(filename, src); c := new(chan *Scanner.Token, 32); go S.Server(c); diff --git a/usr/gri/gosrc/verifier.go b/usr/gri/gosrc/verifier.go index 9fc2290b94..9c1405e6ef 100644 --- a/usr/gri/gosrc/verifier.go +++ b/usr/gri/gosrc/verifier.go @@ -23,11 +23,11 @@ func Error(msg string) { type Verifier struct { comp *Globals.Compilation; - + // various sets for marking the graph (and thus avoid cycles) - objs *map[*Globals.Object] bool; - typs *map[*Globals.Type] bool; - pkgs *map[*Globals.Package] bool; + objs map[*Globals.Object] bool; + typs map[*Globals.Type] bool; + pkgs map[*Globals.Package] bool; } @@ -39,11 +39,11 @@ func (V *Verifier) VerifyType(typ *Globals.Type) { return; // already verified } V.typs[typ] = true; - + if typ.obj != nil { V.VerifyObject(typ.obj, 0); } - + switch typ.form { case Type.VOID: break; // TODO for now - remove eventually @@ -95,10 +95,10 @@ func (V *Verifier) VerifyObject(obj *Globals.Object, pnolev int) { return; // already verified } V.objs[obj] = true; - + // all objects have a non-nil type V.VerifyType(obj.typ); - + switch obj.kind { case Object.CONST: break; @@ -130,7 +130,7 @@ func (V *Verifier) VerifyPackage(pkg *Globals.Package, pno int) { return; // already verified } V.pkgs[pkg] = true; - + V.VerifyObject(pkg.obj, pno); V.VerifyScope(pkg.scope); } @@ -158,6 +158,6 @@ func (V *Verifier) Verify(comp *Globals.Compilation) { export func Verify(comp *Globals.Compilation) { - V := new(Verifier); + V := new(*Verifier); V.Verify(comp); } diff --git a/usr/gri/pretty/ast.go b/usr/gri/pretty/ast.go index 5969c8fb16..3c3c039ec1 100644 --- a/usr/gri/pretty/ast.go +++ b/usr/gri/pretty/ast.go @@ -56,14 +56,14 @@ export func NewExpr(pos, tok int, x, y *Expr) *Expr { if x != nil && x.tok == Scanner.TYPE || y != nil && y.tok == Scanner.TYPE { panic("no type expression allowed"); } - e := new(Expr); + e := new(*Expr); e.pos, e.tok, e.x, e.y = pos, tok, x, y; return e; } export func NewLit(pos, tok int, s string) *Expr { - e := new(Expr); + e := new(*Expr); e.pos, e.tok, e.s = pos, tok, s; return e; } @@ -112,7 +112,7 @@ func (t *Type) nfields() int { export func NewType(pos, tok int) *Type { - t := new(Type); + t := new(*Type); t.pos, t.tok = pos, tok; return t; } @@ -120,7 +120,7 @@ export func NewType(pos, tok int) *Type { // requires complete Type type export func NewTypeExpr(t *Type) *Expr { - e := new(Expr); + e := new(*Expr); e.pos, e.tok, e.t = t.pos, Scanner.TYPE, t; return e; } @@ -142,7 +142,7 @@ export type Stat struct { export func NewStat(pos, tok int) *Stat { - s := new(Stat); + s := new(*Stat); s.pos, s.tok = pos, tok; return s; } @@ -167,7 +167,7 @@ export type Decl struct { export func NewDecl(pos, tok int, exported bool) *Decl { - d := new(Decl); + d := new(*Decl); d.pos, d.tok, d.exported = pos, tok, exported; return d; } @@ -186,7 +186,7 @@ export type Comment struct { export func NewComment(pos int, text string) *Comment { - c := new(Comment); + c := new(*Comment); c.pos, c.text = pos, text; return c; } @@ -201,7 +201,7 @@ export type Program struct { export func NewProgram(pos int) *Program { - p := new(Program); + p := new(*Program); p.pos = pos; return p; } diff --git a/usr/gri/pretty/compilation.go b/usr/gri/pretty/compilation.go index 82b6618da3..3168354870 100644 --- a/usr/gri/pretty/compilation.go +++ b/usr/gri/pretty/compilation.go @@ -54,7 +54,7 @@ func (h *ErrorHandler) Init(filename, src string, columns bool) { func (h *ErrorHandler) LineCol(pos int) (line, col int) { line = 1; lpos := 0; - + src := h.src; if pos > len(src) { pos = len(src); @@ -66,7 +66,7 @@ func (h *ErrorHandler) LineCol(pos int) (line, col int) { lpos = i; } } - + return line, pos - lpos; } @@ -82,7 +82,7 @@ func (h *ErrorHandler) ErrorMsg(pos int, msg string) { } } print(" ", msg, "\n"); - + h.nerrors++; h.errpos = pos; @@ -100,10 +100,10 @@ func (h *ErrorHandler) Error(pos int, msg string) { if delta < 0 { delta = -delta; } - + if delta > errdist || h.nerrors == 0 /* always report first error */ { h.ErrorMsg(pos, msg); - } + } } @@ -118,14 +118,14 @@ export func Compile(src_file string, flags *Flags) (*AST.Program, int) { print("cannot open ", src_file, "\n"); return nil, 1; } - + var err ErrorHandler; err.Init(src_file, src, flags.columns); var scanner Scanner.Scanner; scanner.Init(&err, src, true, flags.testmode); - var tstream *<-chan *Scanner.Token; + var tstream <-chan *Scanner.Token; if flags.tokenchan { tstream = scanner.TokenStream(); } @@ -134,11 +134,11 @@ export func Compile(src_file string, flags *Flags) (*AST.Program, int) { parser.Open(flags.verbose, flags.sixg, flags.deps, &scanner, tstream); prog := parser.ParseProgram(); - + if err.nerrors == 0 { TypeChecker.CheckProgram(prog); } - + return prog, err.nerrors; } @@ -153,27 +153,27 @@ func FileExists(name string) bool { } -func AddDeps(globalset *map [string] bool, wset *array.Array, src_file string, flags *Flags) { +func AddDeps(globalset map [string] bool, wset *array.Array, src_file string, flags *Flags) { dummy, found := globalset[src_file]; if !found { globalset[src_file] = true; - + prog, nerrors := Compile(src_file, flags); if nerrors > 0 { return; } - + nimports := prog.decls.Len(); if nimports > 0 { print(src_file, ".6:\t"); - + localset := new(map [string] bool); for i := 0; i < nimports; i++ { decl := prog.decls.At(i).(*AST.Decl); assert(decl.tok == Scanner.IMPORT && decl.val.tok == Scanner.STRING); src := decl.val.s; src = src[1 : len(src) - 1]; // strip "'s - + // ignore files when they are seen a 2nd time dummy, found := localset[src]; if !found { @@ -184,7 +184,7 @@ func AddDeps(globalset *map [string] bool, wset *array.Array, src_file string, f } else if FileExists(Platform.GOROOT + "/pkg/" + src + ".6") || FileExists(Platform.GOROOT + "/pkg/" + src + ".a") { - + } else { // TODO should collect these and print later //print("missing file: ", src, "\n"); diff --git a/usr/gri/pretty/globals.go b/usr/gri/pretty/globals.go index d1dc47cb0b..e51bfb14d0 100644 --- a/usr/gri/pretty/globals.go +++ b/usr/gri/pretty/globals.go @@ -57,7 +57,7 @@ export type Package struct { export type Scope struct { parent *Scope; - entries *map[string] *Object; + entries map[string] *Object; } @@ -72,15 +72,15 @@ export type Environment struct { export type OldCompilation struct { // environment env *Environment; - + // TODO rethink the need for this here src_file string; src string; - + // Error handling nerrors int; // number of errors reported errpos int; // last error position - + // TODO use open arrays eventually pkg_list [256] *Package; // pkg_list[0] is the current package pkg_ref int; @@ -119,7 +119,7 @@ export type Elem struct { export var Universe_void_typ *Type // initialized by Universe to Universe.void_typ export func NewObject(pos, kind int, ident string) *Object { - obj := new(Object); + obj := new(*Object); obj.exported = false; obj.pos = pos; obj.kind = kind; @@ -131,7 +131,7 @@ export func NewObject(pos, kind int, ident string) *Object { export func NewType(form int) *Type { - typ := new(Type); + typ := new(*Type); typ.ref = -1; // not yet exported typ.form = form; return typ; @@ -139,7 +139,7 @@ export func NewType(form int) *Type { export func NewPackage(file_name string, obj *Object, scope *Scope) *Package { - pkg := new(Package); + pkg := new(*Package); pkg.ref = -1; // not yet exported pkg.file_name = file_name; pkg.key = "<the package key>"; // empty key means package forward declaration @@ -150,7 +150,7 @@ export func NewPackage(file_name string, obj *Object, scope *Scope) *Package { export func NewScope(parent *Scope) *Scope { - scope := new(Scope); + scope := new(*Scope); scope.parent = parent; scope.entries = new(map[string]*Object, 8); return scope; @@ -161,7 +161,7 @@ export func NewScope(parent *Scope) *Scope { // Object methods func (obj *Object) Copy() *Object { - copy := new(Object); + copy := new(*Object); copy.exported = obj.exported; copy.pos = obj.pos; copy.kind = obj.kind; diff --git a/usr/gri/pretty/parser.go b/usr/gri/pretty/parser.go index f9fcf0630d..b773d8e233 100644 --- a/usr/gri/pretty/parser.go +++ b/usr/gri/pretty/parser.go @@ -13,17 +13,17 @@ export type Parser struct { // Tracing/debugging verbose, sixg, deps bool; indent uint; - + // Scanner scanner *Scanner.Scanner; - tokchan *<-chan *Scanner.Token; + tokchan <-chan *Scanner.Token; comments *array.Array; - + // Scanner.Token pos int; // token source position tok int; // one token look-ahead val string; // token value (for IDENT, NUMBER, STRING only) - + // Non-syntactic parser control opt_semi bool; // true if semicolon is optional @@ -69,7 +69,7 @@ func (P *Parser) Next0() { P.tok, P.pos, P.val = t.tok, t.pos, t.val; } P.opt_semi = false; - + if P.verbose { P.PrintIndent(); print("[", P.pos, "] ", Scanner.TokenString(P.tok), "\n"); @@ -84,16 +84,16 @@ func (P *Parser) Next() { } -func (P *Parser) Open(verbose, sixg, deps bool, scanner *Scanner.Scanner, tokchan *<-chan *Scanner.Token) { +func (P *Parser) Open(verbose, sixg, deps bool, scanner *Scanner.Scanner, tokchan <-chan *Scanner.Token) { P.verbose = verbose; P.sixg = sixg; P.deps = deps; P.indent = 0; - + P.scanner = scanner; P.tokchan = tokchan; P.comments = array.New(0); - + P.Next(); P.expr_lev = 0; P.scope_lev = 0; @@ -182,7 +182,7 @@ func (P *Parser) ParseIdent() *AST.Expr { } else { P.Expect(Scanner.IDENT); // use Expect() error handling } - + P.Ecart(); return x; } @@ -214,13 +214,13 @@ func (P *Parser) ParseIdentList() *AST.Expr { func (P *Parser) ParseType() *AST.Type { P.Trace("Type"); - + t := P.TryType(); if t == nil { P.Error(P.pos, "type expected"); t = AST.BadType; } - + P.Ecart(); return t; } @@ -228,9 +228,9 @@ func (P *Parser) ParseType() *AST.Type { func (P *Parser) ParseVarType() *AST.Type { P.Trace("VarType"); - + typ := P.ParseType(); - + P.Ecart(); return typ; } @@ -246,7 +246,7 @@ func (P *Parser) ParseQualifiedIdent() *AST.Expr { y := P.ParseIdent(); x = P.NewExpr(pos, Scanner.PERIOD, x, y); } - + P.Ecart(); return x; } @@ -254,7 +254,7 @@ func (P *Parser) ParseQualifiedIdent() *AST.Expr { func (P *Parser) ParseTypeName() *AST.Type { P.Trace("TypeName"); - + t := AST.NewType(P.pos, P.tok); t.expr = P.ParseQualifiedIdent(); @@ -265,7 +265,7 @@ func (P *Parser) ParseTypeName() *AST.Type { func (P *Parser) ParseArrayType() *AST.Type { P.Trace("ArrayType"); - + t := AST.NewType(P.pos, Scanner.LBRACK); P.Expect(Scanner.LBRACK); if P.tok != Scanner.RBRACK { @@ -281,7 +281,7 @@ func (P *Parser) ParseArrayType() *AST.Type { func (P *Parser) ParseChannelType() *AST.Type { P.Trace("ChannelType"); - + t := AST.NewType(P.pos, Scanner.CHAN); t.mode = AST.FULL; if P.tok == Scanner.CHAN { @@ -340,13 +340,13 @@ func (P *Parser) ParseVarDeclList(list *array.Array, ellipsis_ok bool) { typ = AST.NewType(P.pos, Scanner.ELLIPSIS); P.Next(); } - + if ellipsis_ok /* param list */ && i0 > 0 && typ == nil { // not the first parameter section; we must have a type P.Error(P.pos, "type expected"); typ = AST.BadType; } - + // convert the list into a list of (type) expressions if typ != nil { // all list entries must be identifiers @@ -371,21 +371,21 @@ func (P *Parser) ParseVarDeclList(list *array.Array, ellipsis_ok bool) { list.Set(i, AST.NewTypeExpr(t)); } } - + P.Ecart(); } func (P *Parser) ParseParameterList(ellipsis_ok bool) *array.Array { P.Trace("ParameterList"); - + list := array.New(0); P.ParseVarDeclList(list, ellipsis_ok); for P.tok == Scanner.COMMA { P.Next(); P.ParseVarDeclList(list, ellipsis_ok); } - + P.Ecart(); return list; } @@ -393,7 +393,7 @@ func (P *Parser) ParseParameterList(ellipsis_ok bool) *array.Array { func (P *Parser) ParseParameters(ellipsis_ok bool) *AST.Type { P.Trace("Parameters"); - + t := AST.NewType(P.pos, Scanner.STRUCT); P.Expect(Scanner.LPAREN); if P.tok != Scanner.RPAREN { @@ -401,7 +401,7 @@ func (P *Parser) ParseParameters(ellipsis_ok bool) *AST.Type { } t.end = P.pos; P.Expect(Scanner.RPAREN); - + P.Ecart(); return t; } @@ -425,7 +425,7 @@ func (P *Parser) ParseResultList() { func (P *Parser) ParseResult() *AST.Type { P.Trace("Result"); - + var t *AST.Type; if P.tok == Scanner.LPAREN { t = P.ParseParameters(false); @@ -452,12 +452,12 @@ func (P *Parser) ParseResult() *AST.Type { func (P *Parser) ParseFunctionType() *AST.Type { P.Trace("FunctionType"); - + t := AST.NewType(P.pos, Scanner.LPAREN); t.list = P.ParseParameters(true).list; // TODO find better solution t.end = P.pos; t.elt = P.ParseResult(); - + P.Ecart(); return t; } @@ -465,7 +465,7 @@ func (P *Parser) ParseFunctionType() *AST.Type { func (P *Parser) ParseMethodSpec(list *array.Array) { P.Trace("MethodDecl"); - + list.Push(P.ParseIdentList()); t := AST.BadType; if P.sixg { @@ -474,14 +474,14 @@ func (P *Parser) ParseMethodSpec(list *array.Array) { t = P.ParseFunctionType(); } list.Push(AST.NewTypeExpr(t)); - + P.Ecart(); } func (P *Parser) ParseInterfaceType() *AST.Type { P.Trace("InterfaceType"); - + t := AST.NewType(P.pos, Scanner.INTERFACE); P.Expect(Scanner.INTERFACE); if P.tok == Scanner.LBRACE { @@ -504,14 +504,14 @@ func (P *Parser) ParseInterfaceType() *AST.Type { func (P *Parser) ParseMapType() *AST.Type { P.Trace("MapType"); - + t := AST.NewType(P.pos, Scanner.MAP); P.Expect(Scanner.MAP); P.Expect(Scanner.LBRACK); t.key = P.ParseVarType(); P.Expect(Scanner.RBRACK); t.elt = P.ParseVarType(); - + P.Ecart(); return t; } @@ -551,11 +551,11 @@ func (P *Parser) ParseStructType() *AST.Type { func (P *Parser) ParsePointerType() *AST.Type { P.Trace("PointerType"); - + t := AST.NewType(P.pos, Scanner.MUL); P.Expect(Scanner.MUL); t.elt = P.ParseType(); - + P.Ecart(); return t; } @@ -563,7 +563,7 @@ func (P *Parser) ParsePointerType() *AST.Type { func (P *Parser) TryType() *AST.Type { P.Trace("Type (try)"); - + t := AST.BadType; switch P.tok { case Scanner.IDENT: t = P.ParseTypeName(); @@ -587,7 +587,7 @@ func (P *Parser) TryType() *AST.Type { func (P *Parser) ParseStatementList() *array.Array { P.Trace("StatementList"); - + list := array.New(0); for P.tok != Scanner.CASE && P.tok != Scanner.DEFAULT && P.tok != Scanner.RBRACE && P.tok != Scanner.EOF { s := P.ParseStatement(); @@ -603,7 +603,7 @@ func (P *Parser) ParseStatementList() *array.Array { break; } } - + // Try to provide a good error message if P.tok != Scanner.CASE && P.tok != Scanner.DEFAULT && P.tok != Scanner.RBRACE && P.tok != Scanner.EOF { P.Error(P.pos, "expected end of statement list (semicolon missing?)"); @@ -616,13 +616,13 @@ func (P *Parser) ParseStatementList() *array.Array { func (P *Parser) ParseBlock() (slist *array.Array, end int) { P.Trace("Block"); - + P.Expect(Scanner.LBRACE); slist = P.ParseStatementList(); end = P.pos; P.Expect(Scanner.RBRACE); P.opt_semi = true; - + P.Ecart(); return slist, end; } @@ -654,7 +654,7 @@ func (P *Parser) ParseExpressionList() *AST.Expr { func (P *Parser) ParseFunctionLit() *AST.Expr { P.Trace("FunctionLit"); - + x := AST.NewLit(P.pos, Scanner.FUNC, ""); P.Expect(Scanner.FUNC); x.t = P.ParseFunctionType(); @@ -663,7 +663,7 @@ func (P *Parser) ParseFunctionLit() *AST.Expr { x.block, x.end = P.ParseBlock(); P.scope_lev--; P.expr_lev--; - + P.Ecart(); return x; } @@ -672,7 +672,7 @@ func (P *Parser) ParseFunctionLit() *AST.Expr { /* func (P *Parser) ParseNewCall() *AST.Expr { P.Trace("NewCall"); - + x := AST.NewExpr(P.pos, Scanner.NEW, nil, nil); P.Next(); P.Expect(Scanner.LPAREN); @@ -684,7 +684,7 @@ func (P *Parser) ParseNewCall() *AST.Expr { } P.expr_lev--; P.Expect(Scanner.RPAREN); - + P.Ecart(); return x; } @@ -698,9 +698,9 @@ func (P *Parser) ParseOperand() *AST.Expr { switch P.tok { case Scanner.IDENT: x = P.ParseIdent(); - + case Scanner.LPAREN: - // TODO we could have a function type here as in: new(*()) + // TODO we could have a function type here as in: new(**()) // (currently not working) P.Next(); P.expr_lev++; @@ -745,16 +745,16 @@ func (P *Parser) ParseSelectorOrTypeGuard(x *AST.Expr) *AST.Expr { x = P.NewExpr(P.pos, Scanner.PERIOD, x, nil); P.Expect(Scanner.PERIOD); - + if P.tok == Scanner.IDENT { x.y = P.ParseIdent(); - + } else { P.Expect(Scanner.LPAREN); x.t = P.ParseType(); P.Expect(Scanner.RPAREN); } - + P.Ecart(); return x; } @@ -762,14 +762,14 @@ func (P *Parser) ParseSelectorOrTypeGuard(x *AST.Expr) *AST.Expr { func (P *Parser) ParseIndex(x *AST.Expr) *AST.Expr { P.Trace("IndexOrSlice"); - + pos := P.pos; P.Expect(Scanner.LBRACK); P.expr_lev++; i := P.ParseExpression(0); P.expr_lev--; P.Expect(Scanner.RBRACK); - + P.Ecart(); return P.NewExpr(pos, Scanner.LBRACK, x, i); } @@ -786,7 +786,7 @@ func (P *Parser) ParseCall(x0 *AST.Expr) *AST.Expr { P.expr_lev++; var t *AST.Type; if x0.tok == Scanner.IDENT && x0.s == "new" { - // heuristic: assume it's a new(T, ...) call, try to parse a type + // heuristic: assume it's a new(*T, ...) call, try to parse a type t = P.TryType(); } if t != nil { @@ -808,7 +808,7 @@ func (P *Parser) ParseCall(x0 *AST.Expr) *AST.Expr { P.expr_lev--; } P.Expect(Scanner.RPAREN); - + P.Ecart(); return x; } @@ -819,13 +819,13 @@ func (P *Parser) ParseCompositeElements() *AST.Expr { if P.tok == Scanner.COMMA { pos := P.pos; P.Next(); - + // first element determines mode singles := true; if x.tok == Scanner.COLON { singles = false; } - + for first := true; P.tok != Scanner.RBRACE && P.tok != Scanner.EOF; { y := P.ParseExpression(0); @@ -838,13 +838,13 @@ func (P *Parser) ParseCompositeElements() *AST.Expr { P.Error(y.pos, "key:value pair expected; found single value"); } } - + if first { x = P.NewExpr(pos, Scanner.COMMA, x, y); } else { x.y = P.NewExpr(pos, Scanner.COMMA, x.y, y); } - + if P.tok == Scanner.COMMA { pos = P.pos; P.Next(); @@ -860,7 +860,7 @@ func (P *Parser) ParseCompositeElements() *AST.Expr { func (P *Parser) ParseCompositeLit(t *AST.Type) *AST.Expr { P.Trace("CompositeLit"); - + x := P.NewExpr(P.pos, Scanner.LBRACE, nil, nil); x.t = t; P.Expect(Scanner.LBRACE); @@ -868,7 +868,7 @@ func (P *Parser) ParseCompositeLit(t *AST.Type) *AST.Expr { x.y = P.ParseCompositeElements(); } P.Expect(Scanner.RBRACE); - + P.Ecart(); return x; } @@ -876,7 +876,7 @@ func (P *Parser) ParseCompositeLit(t *AST.Type) *AST.Expr { func (P *Parser) ParsePrimaryExpr() *AST.Expr { P.Trace("PrimaryExpr"); - + x := P.ParseOperand(); for { switch P.tok { @@ -899,7 +899,7 @@ func (P *Parser) ParsePrimaryExpr() *AST.Expr { default: goto exit; } } - + exit: P.Ecart(); return x; @@ -908,7 +908,7 @@ exit: func (P *Parser) ParseUnaryExpr() *AST.Expr { P.Trace("UnaryExpr"); - + x := AST.BadExpr; switch P.tok { case Scanner.ADD, Scanner.SUB, Scanner.MUL, Scanner.NOT, Scanner.XOR, Scanner.ARROW, Scanner.AND: @@ -923,11 +923,11 @@ func (P *Parser) ParseUnaryExpr() *AST.Expr { } else { x = P.NewExpr(pos, tok, nil, y); } - + default: x = P.ParsePrimaryExpr(); } - + P.Ecart(); return x; } @@ -935,7 +935,7 @@ func (P *Parser) ParseUnaryExpr() *AST.Expr { func (P *Parser) ParseBinaryExpr(prec1 int) *AST.Expr { P.Trace("BinaryExpr"); - + x := P.ParseUnaryExpr(); for prec := Scanner.Precedence(P.tok); prec >= prec1; prec-- { for Scanner.Precedence(P.tok) == prec { @@ -945,7 +945,7 @@ func (P *Parser) ParseBinaryExpr(prec1 int) *AST.Expr { x = P.NewExpr(pos, tok, x, y); } } - + P.Ecart(); return x; } @@ -973,10 +973,10 @@ func (P *Parser) ParseExpression(prec int) *AST.Expr { func (P *Parser) ParseSimpleStat(range_ok bool) *AST.Stat { P.Trace("SimpleStat"); - + s := AST.BadStat; x := P.ParseExpressionList(); - + is_range := false; if range_ok && P.tok == Scanner.COLON { pos := P.pos; @@ -989,7 +989,7 @@ func (P *Parser) ParseSimpleStat(range_ok bool) *AST.Stat { P.Error(pos, "expected initialization, found ':'"); } } - + switch P.tok { case Scanner.COLON: // label declaration @@ -1052,7 +1052,7 @@ func (P *Parser) ParseSimpleStat(range_ok bool) *AST.Stat { P.Error(x.pos, "only one expression allowed"); } } - + P.Ecart(); return s; } @@ -1060,11 +1060,11 @@ func (P *Parser) ParseSimpleStat(range_ok bool) *AST.Stat { func (P *Parser) ParseGoStat() *AST.Stat { P.Trace("GoStat"); - + s := AST.NewStat(P.pos, Scanner.GO); P.Expect(Scanner.GO); s.expr = P.ParseExpression(1); - + P.Ecart(); return s; } @@ -1072,13 +1072,13 @@ func (P *Parser) ParseGoStat() *AST.Stat { func (P *Parser) ParseReturnStat() *AST.Stat { P.Trace("ReturnStat"); - + s := AST.NewStat(P.pos, Scanner.RETURN); P.Expect(Scanner.RETURN); if P.tok != Scanner.SEMICOLON && P.tok != Scanner.RBRACE { s.expr = P.ParseExpressionList(); } - + P.Ecart(); return s; } @@ -1086,13 +1086,13 @@ func (P *Parser) ParseReturnStat() *AST.Stat { func (P *Parser) ParseControlFlowStat(tok int) *AST.Stat { P.Trace("ControlFlowStat"); - + s := AST.NewStat(P.pos, tok); P.Expect(tok); if tok != Scanner.FALLTHROUGH && P.tok == Scanner.IDENT { s.expr = P.ParseIdent(); } - + P.Ecart(); return s; } @@ -1100,7 +1100,7 @@ func (P *Parser) ParseControlFlowStat(tok int) *AST.Stat { func (P *Parser) ParseControlClause(keyword int) *AST.Stat { P.Trace("ControlClause"); - + s := AST.NewStat(P.pos, keyword); P.Expect(keyword); if P.tok != Scanner.LBRACE { @@ -1163,7 +1163,7 @@ func (P *Parser) ParseIfStat() *AST.Stat { } s.post = s1; } - + P.Ecart(); return s; } @@ -1171,10 +1171,10 @@ func (P *Parser) ParseIfStat() *AST.Stat { func (P *Parser) ParseForStat() *AST.Stat { P.Trace("ForStat"); - + s := P.ParseControlClause(Scanner.FOR); s.block, s.end = P.ParseBlock(); - + P.Ecart(); return s; } @@ -1182,7 +1182,7 @@ func (P *Parser) ParseForStat() *AST.Stat { func (P *Parser) ParseCase() *AST.Stat { P.Trace("Case"); - + s := AST.NewStat(P.pos, P.tok); if P.tok == Scanner.CASE { P.Next(); @@ -1191,7 +1191,7 @@ func (P *Parser) ParseCase() *AST.Stat { P.Expect(Scanner.DEFAULT); } P.Expect(Scanner.COLON); - + P.Ecart(); return s; } @@ -1204,7 +1204,7 @@ func (P *Parser) ParseCaseClause() *AST.Stat { if P.tok != Scanner.CASE && P.tok != Scanner.DEFAULT && P.tok != Scanner.RBRACE { s.block = P.ParseStatementList(); } - + P.Ecart(); return s; } @@ -1212,7 +1212,7 @@ func (P *Parser) ParseCaseClause() *AST.Stat { func (P *Parser) ParseSwitchStat() *AST.Stat { P.Trace("SwitchStat"); - + s := P.ParseControlClause(Scanner.SWITCH); s.block = array.New(0); P.Expect(Scanner.LBRACE); @@ -1258,12 +1258,12 @@ func (P *Parser) ParseCommCase() *AST.Stat { func (P *Parser) ParseCommClause() *AST.Stat { P.Trace("CommClause"); - + s := P.ParseCommCase(); if P.tok != Scanner.CASE && P.tok != Scanner.DEFAULT && P.tok != Scanner.RBRACE { s.block = P.ParseStatementList(); } - + P.Ecart(); return s; } @@ -1271,7 +1271,7 @@ func (P *Parser) ParseCommClause() *AST.Stat { func (P *Parser) ParseSelectStat() *AST.Stat { P.Trace("SelectStat"); - + s := AST.NewStat(P.pos, Scanner.SELECT); s.block = array.New(0); P.Expect(Scanner.SELECT); @@ -1281,7 +1281,7 @@ func (P *Parser) ParseSelectStat() *AST.Stat { } P.Expect(Scanner.RBRACE); P.opt_semi = true; - + P.Ecart(); return s; } @@ -1289,14 +1289,14 @@ func (P *Parser) ParseSelectStat() *AST.Stat { func (P *Parser) ParseRangeStat() *AST.Stat { P.Trace("RangeStat"); - + s := AST.NewStat(P.pos, Scanner.RANGE); P.Expect(Scanner.RANGE); P.ParseIdentList(); P.Expect(Scanner.DEFINE); s.expr = P.ParseExpression(1); s.block, s.end = P.ParseBlock(); - + P.Ecart(); return s; } @@ -1358,7 +1358,7 @@ func (P *Parser) ParseStatement() *AST.Stat { func (P *Parser) ParseImportSpec(pos int) *AST.Decl { P.Trace("ImportSpec"); - + d := AST.NewDecl(pos, Scanner.IMPORT, false); if P.tok == Scanner.PERIOD { P.Error(P.pos, `"import ." not yet handled properly`); @@ -1366,7 +1366,7 @@ func (P *Parser) ParseImportSpec(pos int) *AST.Decl { } else if P.tok == Scanner.IDENT { d.ident = P.ParseIdent(); } - + if P.tok == Scanner.STRING { // TODO eventually the scanner should strip the quotes d.val = AST.NewLit(P.pos, Scanner.STRING, P.val); @@ -1374,7 +1374,7 @@ func (P *Parser) ParseImportSpec(pos int) *AST.Decl { } else { P.Expect(Scanner.STRING); // use Expect() error handling } - + P.Ecart(); return d; } @@ -1382,7 +1382,7 @@ func (P *Parser) ParseImportSpec(pos int) *AST.Decl { func (P *Parser) ParseConstSpec(exported bool, pos int) *AST.Decl { P.Trace("ConstSpec"); - + d := AST.NewDecl(pos, Scanner.CONST, exported); d.ident = P.ParseIdentList(); d.typ = P.TryType(); @@ -1390,7 +1390,7 @@ func (P *Parser) ParseConstSpec(exported bool, pos int) *AST.Decl { P.Next(); d.val = P.ParseExpressionList(); } - + P.Ecart(); return d; } @@ -1403,7 +1403,7 @@ func (P *Parser) ParseTypeSpec(exported bool, pos int) *AST.Decl { d.ident = P.ParseIdent(); d.typ = P.ParseType(); P.opt_semi = true; - + P.Ecart(); return d; } @@ -1411,7 +1411,7 @@ func (P *Parser) ParseTypeSpec(exported bool, pos int) *AST.Decl { func (P *Parser) ParseVarSpec(exported bool, pos int) *AST.Decl { P.Trace("VarSpec"); - + d := AST.NewDecl(pos, Scanner.VAR, exported); d.ident = P.ParseIdentList(); if P.tok == Scanner.ASSIGN { @@ -1424,7 +1424,7 @@ func (P *Parser) ParseVarSpec(exported bool, pos int) *AST.Decl { d.val = P.ParseExpressionList(); } } - + P.Ecart(); return d; } @@ -1445,7 +1445,7 @@ func (P *Parser) ParseSpec(exported bool, pos int, keyword int) *AST.Decl { func (P *Parser) ParseDecl(exported bool, keyword int) *AST.Decl { P.Trace("Decl"); - + d := AST.BadDecl; pos := P.pos; P.Expect(keyword); @@ -1464,11 +1464,11 @@ func (P *Parser) ParseDecl(exported bool, keyword int) *AST.Decl { d.end = P.pos; P.Expect(Scanner.RPAREN); P.opt_semi = true; - + } else { d = P.ParseSpec(exported, pos, keyword); } - + P.Ecart(); return d; } @@ -1485,10 +1485,10 @@ func (P *Parser) ParseDecl(exported bool, keyword int) *AST.Decl { func (P *Parser) ParseFunctionDecl(exported bool) *AST.Decl { P.Trace("FunctionDecl"); - + d := AST.NewDecl(P.pos, Scanner.FUNC, exported); P.Expect(Scanner.FUNC); - + var recv *AST.Type; if P.tok == Scanner.LPAREN { pos := P.pos; @@ -1497,7 +1497,7 @@ func (P *Parser) ParseFunctionDecl(exported bool) *AST.Decl { P.Error(pos, "must have exactly one receiver"); } } - + d.ident = P.ParseIdent(); d.typ = P.ParseFunctionType(); d.typ.key = recv; @@ -1507,7 +1507,7 @@ func (P *Parser) ParseFunctionDecl(exported bool) *AST.Decl { d.list, d.end = P.ParseBlock(); P.scope_lev--; } - + P.Ecart(); return d; } @@ -1515,7 +1515,7 @@ func (P *Parser) ParseFunctionDecl(exported bool) *AST.Decl { func (P *Parser) ParseExportDecl() *AST.Decl { P.Trace("ExportDecl"); - + d := AST.NewDecl(P.pos, Scanner.EXPORT, false); d.ident = P.ParseIdentList(); @@ -1527,7 +1527,7 @@ func (P *Parser) ParseExportDecl() *AST.Decl { func (P *Parser) ParseDeclaration() *AST.Decl { P.Trace("Declaration"); indent := P.indent; - + d := AST.BadDecl; exported := false; // TODO don't use bool flag for export @@ -1539,7 +1539,7 @@ func (P *Parser) ParseDeclaration() *AST.Decl { } P.Next(); } - + switch P.tok { case Scanner.CONST, Scanner.TYPE, Scanner.VAR: d = P.ParseDecl(exported, P.tok); @@ -1573,26 +1573,26 @@ func (P *Parser) ParseDeclaration() *AST.Decl { func (P *Parser) ParseProgram() *AST.Program { P.Trace("Program"); - + p := AST.NewProgram(P.pos); P.Expect(Scanner.PACKAGE); p.ident = P.ParseIdent(); - + p.decls = array.New(0); for P.tok == Scanner.IMPORT { p.decls.Push(P.ParseDecl(false, Scanner.IMPORT)); P.OptSemicolon(); } - + if !P.deps { for P.tok != Scanner.EOF { p.decls.Push(P.ParseDeclaration()); P.OptSemicolon(); } } - + p.comments = P.comments; - + P.Ecart(); return p; } diff --git a/usr/gri/pretty/scanner.go b/usr/gri/pretty/scanner.go index 917acad382..e77ade39ee 100644 --- a/usr/gri/pretty/scanner.go +++ b/usr/gri/pretty/scanner.go @@ -24,13 +24,13 @@ export const ( MUL; QUO; REM; - + AND; OR; XOR; SHL; SHR; - + ADD_ASSIGN; SUB_ASSIGN; MUL_ASSIGN; @@ -48,7 +48,7 @@ export const ( ARROW; INC; DEC; - + EQL; NEQ; LSS; @@ -60,14 +60,14 @@ export const ( DEFINE; NOT; ELLIPSIS; - + LPAREN; RPAREN; LBRACK; RBRACK; LBRACE; RBRACE; - + COMMA; SEMICOLON; COLON; @@ -80,32 +80,32 @@ export const ( CHAN; CONST; CONTINUE; - + DEFAULT; ELSE; EXPORT; FALLTHROUGH; FOR; - + FUNC; GO; GOTO; IF; IMPORT; - + INTERFACE; MAP; PACKAGE; RANGE; RETURN; - + SELECT; STRUCT; SWITCH; TYPE; VAR; KEYWORDS_END; - + // AST use only EXPRSTAT; ) @@ -114,7 +114,7 @@ export const ( export func TokenString(tok int) string { switch tok { case ILLEGAL: return "ILLEGAL"; - + case IDENT: return "IDENT"; case INT: return "INT"; case FLOAT: return "FLOAT"; @@ -128,13 +128,13 @@ export func TokenString(tok int) string { case MUL: return "*"; case QUO: return "/"; case REM: return "%"; - + case AND: return "&"; case OR: return "|"; case XOR: return "^"; case SHL: return "<<"; case SHR: return ">>"; - + case ADD_ASSIGN: return "+="; case SUB_ASSIGN: return "-="; case MUL_ASSIGN: return "+="; @@ -206,10 +206,10 @@ export func TokenString(tok int) string { case SWITCH: return "switch"; case TYPE: return "type"; case VAR: return "var"; - + case EXPRSTAT: return "EXPRSTAT"; } - + return "token(" + Utils.IntToString(tok, 10) + ")"; } @@ -242,7 +242,7 @@ export func Precedence(tok int) int { } -var Keywords *map [string] int; +var Keywords map [string] int; func init() { @@ -325,7 +325,7 @@ func (S *Scanner) Error(pos int, msg string) { S.testpos = -1; return; } - + S.err.Error(pos, msg); } @@ -397,7 +397,7 @@ func (S *Scanner) SkipWhitespace() { func (S *Scanner) ScanComment() string { // first '/' already consumed pos := S.chpos - 1; - + if S.ch == '/' { //-style comment S.Next(); @@ -410,7 +410,7 @@ func (S *Scanner) ScanComment() string { goto exit; } } - + } else { /*-style comment */ S.Expect('*'); @@ -423,7 +423,7 @@ func (S *Scanner) ScanComment() string { } } } - + S.Error(pos, "comment not terminated"); exit: @@ -443,7 +443,7 @@ exit: oldpos = S.testpos; S.ExpectNoErrors(); } - + if 0 <= oldpos && oldpos <= len(S.src) { // the previous error was not found S.Error(oldpos, "ERROR not found"); // TODO this should call ErrorMsg @@ -460,13 +460,13 @@ func (S *Scanner) ScanIdentifier() (tok int, val string) { S.Next(); } val = S.src[pos : S.chpos]; - + var present bool; tok, present = Keywords[val]; if !present { tok = IDENT; } - + return tok, val; } @@ -481,14 +481,14 @@ func (S *Scanner) ScanMantissa(base int) { func (S *Scanner) ScanNumber(seen_decimal_point bool) (tok int, val string) { pos := S.chpos; tok = INT; - + if seen_decimal_point { tok = FLOAT; pos--; // '.' is one byte S.ScanMantissa(10); goto exponent; } - + if S.ch == '0' { // int or float S.Next(); @@ -508,18 +508,18 @@ func (S *Scanner) ScanNumber(seen_decimal_point bool) (tok int, val string) { } goto exit; } - + mantissa: // decimal int or float S.ScanMantissa(10); - + if S.ch == '.' { // float tok = FLOAT; S.Next(); S.ScanMantissa(10) } - + exponent: if S.ch == 'e' || S.ch == 'E' { // float @@ -530,7 +530,7 @@ exponent: } S.ScanMantissa(10); } - + exit: return tok, S.src[pos : S.chpos]; } @@ -549,22 +549,22 @@ func (S *Scanner) ScanDigits(n int, base int) { func (S *Scanner) ScanEscape(quote int) string { // TODO: fix this routine - + ch := S.ch; pos := S.chpos; S.Next(); switch ch { case 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\': return string(ch); - + case '0', '1', '2', '3', '4', '5', '6', '7': S.ScanDigits(3 - 1, 8); // 1 char already read return ""; // TODO fix this - + case 'x': S.ScanDigits(2, 16); return ""; // TODO fix this - + case 'u': S.ScanDigits(4, 16); return ""; // TODO fix this @@ -580,7 +580,7 @@ func (S *Scanner) ScanEscape(quote int) string { } S.Error(pos, "illegal char escape"); } - + return ""; // TODO fix this } @@ -615,7 +615,7 @@ func (S *Scanner) ScanString() string { S.ScanEscape('"'); } } - + S.Next(); return S.src[pos : S.chpos]; } @@ -680,9 +680,9 @@ func (S *Scanner) Select4(tok0, tok1, ch2, tok2, tok3 int) int { func (S *Scanner) Scan() (pos, tok int, val string) { L: S.SkipWhitespace(); - + pos, tok = S.chpos, ILLEGAL; - + switch ch := S.ch; { case is_letter(ch): tok, val = S.ScanIdentifier(); case digit_val(ch) < 10: tok, val = S.ScanNumber(false); @@ -746,7 +746,7 @@ L: S.SkipWhitespace(); tok = ILLEGAL; } } - + return pos, tok, val; } @@ -758,11 +758,11 @@ export type Token struct { } -func (S *Scanner) TokenStream() *<-chan *Token { +func (S *Scanner) TokenStream() <-chan *Token { ch := new(chan *Token, 100); - go func(S *Scanner, ch *chan <- *Token) { + go func(S *Scanner, ch chan <- *Token) { for { - t := new(Token); + t := new(*Token); t.pos, t.tok, t.val = S.Scan(); ch <- t; if t.tok == EOF { diff --git a/usr/gri/pretty/selftest2.go b/usr/gri/pretty/selftest2.go index 3e07ba799b..af449ed1ac 100644 --- a/usr/gri/pretty/selftest2.go +++ b/usr/gri/pretty/selftest2.go @@ -73,7 +73,7 @@ func f2(tag int) { } -func f3(a *[]int, m *map[string] int) { +func f3(a *[]int, m map[string] int) { println("A1"); for i := range a { println(i); |
