Skip to content

Commit 7a5b132

Browse files
committed
symtable: correct package name and stop panic's escaping the package
1 parent 21129d0 commit 7a5b132

File tree

5 files changed

+38
-44
lines changed

5 files changed

+38
-44
lines changed

symtable/make_symtable_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def main():
292292
path = "symtable_data_test.go"
293293
out = ["""// Test data generated by make_symtable_test.py - do not edit
294294
295-
package compile
295+
package symtable
296296
297297
import (
298298
"github.com/ncw/gpython/py"

symtable/stringer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// generated by stringer -type=Scope,BlockType -output stringer.go; DO NOT EDIT
22

3-
package compile
3+
package symtable
44

55
import "fmt"
66

symtable/symtable.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// st.ste_opt_lineno,
88
// st.ste_opt_col_offset)
99

10-
package compile
10+
package symtable
1111

1212
import (
1313
"fmt"
@@ -117,14 +117,19 @@ type SymTable struct {
117117
}
118118

119119
// Make a new top symbol table from the ast supplied
120-
func NewSymTable(Ast ast.Ast) *SymTable {
121-
st := newSymTable(ModuleBlock, "top", nil)
120+
func NewSymTable(Ast ast.Ast) (st *SymTable, err error) {
121+
defer func() {
122+
if r := recover(); r != nil {
123+
err = py.MakeException(r)
124+
}
125+
}()
126+
st = newSymTable(ModuleBlock, "top", nil)
122127
st.Unoptimized = optTopLevel
123128
// Parse into the symbol table
124129
st.Parse(Ast)
125130
// Analyze the symbolt table
126131
st.Analyze()
127-
return st
132+
return st, nil
128133
}
129134

130135
// Make a new symbol table from the ast supplied of the given type

symtable/symtable_data_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test data generated by make_symtable_test.py - do not edit
22

3-
package compile
3+
package symtable
44

55
import (
66
"github.com/ncw/gpython/py"

symtable/symtable_test.go

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package compile
1+
package symtable
22

33
//go:generate ./make_symtable_test.py
44

@@ -131,45 +131,34 @@ func EqSymTable(t *testing.T, name string, a, b *SymTable) {
131131
func TestSymTable(t *testing.T) {
132132
for _, test := range symtableTestData {
133133
var symtab *SymTable
134-
func() {
135-
defer func() {
136-
if r := recover(); r != nil {
137-
if test.exceptionType == nil {
138-
t.Errorf("%s: Got exception %v when not expecting one", test.in, r)
139-
return
140-
}
141-
exc, ok := r.(*py.Exception)
142-
if !ok {
143-
t.Errorf("%s: Got non python exception %T %v", test.in, r, r)
144-
return
145-
}
146-
if exc.Type() != test.exceptionType {
147-
t.Errorf("%s: want exception type %v got %v", test.in, test.exceptionType, exc.Type())
148-
return
149-
}
150-
if exc.Type() != test.exceptionType {
151-
t.Errorf("%s: want exception type %v got %v", test.in, test.exceptionType, exc.Type())
152-
return
153-
}
154-
msg := string(exc.Args.(py.Tuple)[0].(py.String))
155-
if msg != test.errString {
156-
t.Errorf("%s: want exception text %q got %q", test.in, test.errString, msg)
157-
}
158-
134+
Ast, err := parser.ParseString(test.in, test.mode)
135+
if err != nil {
136+
t.Fatalf("Unexpected parse error: %v", err)
137+
}
138+
symtab, err = NewSymTable(Ast)
139+
if err != nil {
140+
if test.exceptionType == nil {
141+
t.Errorf("%s: Got exception %v when not expecting one", test.in, err)
142+
} else if exc, ok := err.(*py.Exception); !ok {
143+
t.Errorf("%s: Got non python exception %T %v", test.in, err, err)
144+
} else if exc.Type() != test.exceptionType {
145+
t.Errorf("%s: want exception type %v got %v", test.in, test.exceptionType, exc.Type())
146+
} else if exc.Type() != test.exceptionType {
147+
t.Errorf("%s: want exception type %v got %v", test.in, test.exceptionType, exc.Type())
148+
} else {
149+
msg := string(exc.Args.(py.Tuple)[0].(py.String))
150+
if msg != test.errString {
151+
t.Errorf("%s: want exception text %q got %q", test.in, test.errString, msg)
159152
}
160-
}()
161-
Ast, err := parser.ParseString(test.in, test.mode)
162-
if err != nil {
163-
panic(err) // FIXME error handling!
164-
}
165-
symtab = NewSymTable(Ast)
166-
}()
167-
if test.out == nil {
168-
if symtab != nil {
169-
t.Errorf("%s: Expecting nil *py.Code but got %T", test.in, symtab)
170153
}
171154
} else {
172-
EqSymTable(t, test.in, test.out, symtab)
155+
if test.exceptionType != nil {
156+
t.Errorf("%s: Didn't get exception %v", test.in, err)
157+
} else if test.out == nil && symtab != nil {
158+
t.Errorf("%s: Expecting nil *SymbolTab but got %T", test.in, symtab)
159+
} else {
160+
EqSymTable(t, test.in, test.out, symtab)
161+
}
173162
}
174163
}
175164
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy