diff options
author | Austin Clements <aclements@csail.mit.edu> | 2009-08-27 11:21:52 -0700 |
---|---|---|
committer | Austin Clements <aclements@csail.mit.edu> | 2009-08-27 11:21:52 -0700 |
commit | 2a03786e02ffb7c728423f6471076e7769f9efef (patch) | |
tree | 684f202d8c590d14b188507a7ee1e9a08a930127 /usr/austin/eval/expr.go | |
parent | e0347fcfd827558d7b7a15995d61a17cb080b11d (diff) | |
download | golang-2a03786e02ffb7c728423f6471076e7769f9efef.tar.gz |
Make the statement compiler not use the AST visitor.
In the process, I made error handling in the statement
compiler much saner. Instead of separately tracking various
error flags with weird relations, I just track if any error
messages have been produced.
R=rsc
APPROVED=rsc
DELTA=308 (98 added, 135 deleted, 75 changed)
OCL=33870
CL=33961
Diffstat (limited to 'usr/austin/eval/expr.go')
-rw-r--r-- | usr/austin/eval/expr.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/usr/austin/eval/expr.go b/usr/austin/eval/expr.go index 3ec0854e0..43ec54781 100644 --- a/usr/austin/eval/expr.go +++ b/usr/austin/eval/expr.go @@ -615,6 +615,7 @@ func (a *exprCompiler) compile(x ast.Expr) *expr { // Remaining expressions case *ast.BadExpr: // Error already reported by parser + a.silentErrors++; return nil; case *ast.BinaryExpr: @@ -740,6 +741,7 @@ func (a *exprInfo) compileIdent(b *block, constant bool, name string) *expr { func (a *exprInfo) compileVariable(level int, v *Variable) *expr { if v.Type == nil { // Placeholder definition from an earlier error + a.silentErrors++; return nil; } expr := a.newExpr(v.Type, "variable"); @@ -1614,7 +1616,12 @@ func (a *compiler) compileArrayLen(b *block, expr ast.Expr) (int64, bool) { func (a *compiler) compileExpr(b *block, constant bool, expr ast.Expr) *expr { ec := &exprCompiler{a, b, constant}; - return ec.compile(expr); + nerr := a.numError(); + e := ec.compile(expr); + if e == nil && nerr == a.numError() { + log.Crashf("expression compilation failed without reporting errors"); + } + return e; } // extractEffect separates out any effects that the expression may @@ -1698,7 +1705,7 @@ func (expr *Expr) Eval(f *Frame) Value { func CompileExpr(scope *Scope, expr ast.Expr) (*Expr, os.Error) { errors := scanner.NewErrorVector(); - cc := &compiler{errors}; + cc := &compiler{errors, 0, 0}; ec := cc.compileExpr(scope.block, false, expr); if ec == nil { |