mirror of
https://github.com/golang/go
synced 2024-11-26 13:58:48 -07:00
- moved struct Compilation into globals.go, adjusted deps
- bail out after > 10 errors - fixed send/recv statements SVN=127890
This commit is contained in:
parent
9e2d185040
commit
85303f2715
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -425,6 +425,10 @@ func (S *Scanner) Error(pos int, msg string) {
|
||||
S.nerrors++;
|
||||
S.errpos = pos;
|
||||
}
|
||||
|
||||
if S.nerrors >= 10 {
|
||||
sys.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user