]> Cypherpunks repositories - gostls13.git/commitdiff
- enabling tracking of declarations
authorRobert Griesemer <gri@golang.org>
Wed, 7 Jan 2009 21:58:56 +0000 (13:58 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 7 Jan 2009 21:58:56 +0000 (13:58 -0800)
- removed dead code
- snapshot before making a lareger structural change

R=r
OCL=22226
CL=22226

usr/gri/pretty/ast.go
usr/gri/pretty/globals.go
usr/gri/pretty/parser.go
usr/gri/pretty/test.sh
usr/gri/pretty/typechecker.go

index 5969c8fb16d4cb2380667f25845662143b7d594b..5e40a61cc93a33acf826991b2d912531e47dbbe2 100644 (file)
@@ -11,7 +11,7 @@ import (
 
 
 type (
-       Any interface {};
+       Object struct;
        Type struct;
        Expr struct;
        Stat struct;
@@ -23,7 +23,29 @@ type (
 // All nodes have a source position and and token.
 
 export type Node struct {
-       pos, tok int;
+       pos int;  // source position (< 0 => unknown position)
+       tok int;  // identifying token
+}
+
+
+// ----------------------------------------------------------------------------
+// Objects represent declared language objects, such as a const, type, var;
+// but also anonymous objects such as type and other literals.
+
+export type Object struct {
+       Node;
+       lit string;  // identifiers and literals
+       typ *Type;
+       val *Expr;
+}
+
+
+export func NewObject(pos, tok int, lit string) *Object {
+       obj := new(Object);
+       obj.pos, obj.tok = pos, tok;
+       obj.lit = lit;
+       obj.typ = nil;  // Universe::void_typ
+       return obj;
 }
 
 
@@ -33,6 +55,8 @@ export type Node struct {
 export type Expr struct {
        Node;
        x, y *Expr;  // binary (x, y) and unary (y) expressions
+       obj *Object;
+       
        // TODO find a more space efficient way to hold these
        s string;  // identifiers and literals
        t *Type;  // type expressions, function literal types
index ffabfde1df5980dfe73a18e0ae29f27da094eed3..25a8702f15be1b0ba38883d4f7f33799c4f697eb 100644 (file)
@@ -15,7 +15,6 @@ package Globals
 
 type Type struct
 type Scope struct
-type Elem struct
 type OldCompilation struct
 
 // Object represents a language object, such as a constant, variable, type,
@@ -100,19 +99,6 @@ export type Stat interface {
 }
 
 
-// TODO This is hideous! We need to have a decent way to do lists.
-// Ideally open arrays that allow '+'.
-
-export type Elem struct {
-       next *Elem;
-       val int;
-       str string;
-       obj *Object;
-       typ *Type;
-       expr Expr
-}
-
-
 // ----------------------------------------------------------------------------
 // Creation
 
index 4bd8e193c23089a53a604ae22394517d2dd260e1..0bca27867d675370e7842ced5ee2e13035f66314 100644 (file)
@@ -703,7 +703,7 @@ func (P *Parser) ParseOperand() *AST.Expr {
                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++;
@@ -723,11 +723,6 @@ func (P *Parser) ParseOperand() *AST.Expr {
        case Scanner.FUNC:
                x = P.ParseFunctionLit();
 
-       /*
-       case Scanner.NEW:
-               x = P.ParseNewCall();
-       */
-
        default:
                t := P.TryType();
                if t != nil {
index 9fe43ba46f3d4c9f1e72861317fbf70b37aa1e67..b248616ff3e1a22e9af75a9139162494c6eb93a3 100755 (executable)
@@ -25,8 +25,8 @@ apply1() {
        # these files don't pass the idempotency test yet
        log.go | type.go | types_amd64_darwin.go | \
        \
-       selftest1.go | func3.go | bug014.go | bug029.go | bug032.go | bug050.go | \
-       bug068.go | bug088.go | bug083.go | bug106.go | bug125.go ) ;;  # skip - files contain syntax errors
+       method1.go | selftest1.go | func3.go | bug014.go | bug029.go | bug032.go | bug050.go | \
+       bug068.go | bug088.go | bug083.go | bug106.go | bug125.go | bug126.go ) ;;  # skip - files contain errors
        * ) $1 $2; count ;;
        esac
 }
index b7d796257f9c0f57832392bad32c1ee0a9d4478e..4b0c6e48a02c9ff623e07d02a9ef9095b2dd4a77 100644 (file)
@@ -163,7 +163,14 @@ func (s *State) CheckDeclaration(d *AST.Decl) {
                                // method
                                // TODO
                        } else {
-                               s.DeclareIdent(d.ident, d.tok, d.typ);
+                               // functions may be forward-declared
+                               obj := s.Lookup(d.ident.s);
+                               if obj != nil {
+                                 // TODO check if proper forward-declaration
+                                 
+                               } else {
+                                       s.DeclareIdent(d.ident, d.tok, d.typ);
+                               }
                        }
 
                default:
@@ -190,8 +197,6 @@ func (s *State) CheckProgram(p *AST.Program) {
 // ----------------------------------------------------------------------------
 
 export func CheckProgram(err Scanner.ErrorHandler, p *AST.Program) {
-       return;  // DISABLED FOR NOW
-       
        var s State;
        s.Init(err);
        s.CheckProgram(p);