From 85303f271529213a19729a35d50ee18f8580f9af Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 17 Jul 2008 15:11:46 -0700 Subject: [PATCH] - moved struct Compilation into globals.go, adjusted deps - bail out after > 10 errors - fixed send/recv statements SVN=127890 --- usr/gri/gosrc/compilation.go | 47 +++------------------------------ usr/gri/gosrc/globals.go | 50 +++++++++++++++++++++++++++++++++--- usr/gri/gosrc/parser.go | 4 +-- usr/gri/gosrc/scanner.go | 4 +++ 4 files changed, 56 insertions(+), 49 deletions(-) diff --git a/usr/gri/gosrc/compilation.go b/usr/gri/gosrc/compilation.go index 3e602b9e40c..062c963e06d 100644 --- a/usr/gri/gosrc/compilation.go +++ b/usr/gri/gosrc/compilation.go @@ -13,47 +13,6 @@ import Parser "parser" import Export "export" -export Compilation -type Compilation struct { - src_name string; - pkg *Globals.Object; - imports [256] *Globals.Package; // TODO need open arrays - nimports int; -} - - -func (C *Compilation) Lookup(file_name string) *Globals.Package { - for i := 0; i < C.nimports; i++ { - pkg := C.imports[i]; - if pkg.file_name == file_name { - return pkg; - } - } - return nil; -} - - -func (C *Compilation) Insert(pkg *Globals.Package) { - if C.Lookup(pkg.file_name) != nil { - panic "package already inserted"; - } - pkg.pno = C.nimports; - C.imports[C.nimports] = pkg; - C.nimports++; -} - - -func (C *Compilation) InsertImport(pkg *Globals.Package) *Globals.Package { - p := C.Lookup(pkg.file_name); - if (p == nil) { - // no primary package found - C.Insert(pkg); - p = pkg; - } - return p; -} - - func BaseName(s string) string { // TODO this is not correct for non-ASCII strings! i := len(s); @@ -76,12 +35,12 @@ func FixExt(s string) string { } -func (C *Compilation) Import(pkg_name string) (pno int) { +func Import(C *Globals.Compilation, pkg_name string) (pno int) { panic "UNIMPLEMENTED"; } -func (C *Compilation) Export() { +func Export(C *Globals.Compilation) { file_name := FixExt(BaseName(C.src_name)); // strip src dir Export.Export(file_name/*, C */); } @@ -89,7 +48,7 @@ func (C *Compilation) Export() { export Compile func Compile(src_name string, verbose int) { - comp := new(Compilation); + comp := new(Globals.Compilation); comp.src_name = src_name; comp.pkg = nil; comp.nimports = 0; diff --git a/usr/gri/gosrc/globals.go b/usr/gri/gosrc/globals.go index 83d3a8fb3f9..c86289b7ada 100644 --- a/usr/gri/gosrc/globals.go +++ b/usr/gri/gosrc/globals.go @@ -6,9 +6,9 @@ package Globals // The following types should really be in their respective files -// (object.go, type.go, scope.go, package.go) but they refer to each -// other and we don't know how to handle forward-declared pointers -// across packages yet. +// (object.go, type.go, scope.go, package.go, compilation.go) but +// they refer to each other and we don't know how to handle forward +// declared pointers across packages yet. // ---------------------------------------------------------------------------- @@ -75,6 +75,15 @@ type Package struct { } +export Compilation +type Compilation struct { + src_name string; + pkg *Object; + imports [256] *Package; // TODO need open arrays + nimports int; +} + + // ---------------------------------------------------------------------------- // Creation @@ -226,3 +235,38 @@ func (scope *Scope) Print() { } print "\n}\n"; } + + +// ---------------------------------------------------------------------------- +// Compilation methods + +func (C *Compilation) Lookup(file_name string) *Package { + for i := 0; i < C.nimports; i++ { + pkg := C.imports[i]; + if pkg.file_name == file_name { + return pkg; + } + } + return nil; +} + + +func (C *Compilation) Insert(pkg *Package) { + if C.Lookup(pkg.file_name) != nil { + panic "package already inserted"; + } + pkg.pno = C.nimports; + C.imports[C.nimports] = pkg; + C.nimports++; +} + + +func (C *Compilation) InsertImport(pkg *Package) *Package { + p := C.Lookup(pkg.file_name); + if (p == nil) { + // no primary package found + C.Insert(pkg); + p = pkg; + } + return p; +} diff --git a/usr/gri/gosrc/parser.go b/usr/gri/gosrc/parser.go index f93567a2c63..e99279ba4af 100644 --- a/usr/gri/gosrc/parser.go +++ b/usr/gri/gosrc/parser.go @@ -1004,8 +1004,8 @@ func (P *Parser) TryStatement() bool { case Scanner.FUNC: // for now we do not allow local function declarations fallthrough; - case Scanner.LSS: fallthrough; - case Scanner.GTR: + case Scanner.SEND: fallthrough; + case Scanner.RECV: P.ParseSimpleStat(); // send or receive case Scanner.IDENT: switch P.ident { diff --git a/usr/gri/gosrc/scanner.go b/usr/gri/gosrc/scanner.go index a5c63e20f94..5ef8081da61 100644 --- a/usr/gri/gosrc/scanner.go +++ b/usr/gri/gosrc/scanner.go @@ -425,6 +425,10 @@ func (S *Scanner) Error(pos int, msg string) { S.nerrors++; S.errpos = pos; } + + if S.nerrors >= 10 { + sys.exit(1); + } }