]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.cc] cmd/internal/gc: reconvert to pick up bug fixes
authorRuss Cox <rsc@golang.org>
Mon, 23 Feb 2015 19:02:27 +0000 (14:02 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 23 Feb 2015 19:56:18 +0000 (19:56 +0000)
Convert using rsc.io/c2go rev a97ff47.

Notable changes:
- %% in format string now correctly preserved
- reintroduce "signal handler" to hide internal faults
  after errors have been printed

Change-Id: Ic5a94f1c3a8015a9054e21c8969b52d964a36c45
Reviewed-on: https://go-review.googlesource.com/5633
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/internal/gc/const.go
src/cmd/internal/gc/fmt.go
src/cmd/internal/gc/go.y
src/cmd/internal/gc/lex.go
src/cmd/internal/gc/mparith1.go
src/cmd/internal/gc/subr.go
src/cmd/internal/gc/y.go

index f9bd5571b4c65817d25ef5ef27dc792f66b151af..49d3bcc56874bf563dd4fd14d28789af39511667 100644 (file)
@@ -788,7 +788,7 @@ func evconst(n *Node) {
        // which is not quite an ideal error.
        case OMOD<<16 | CTFLT:
                if n.Diag == 0 {
-                       Yyerror("illegal constant expression: floating-point % operation")
+                       Yyerror("illegal constant expression: floating-point %% operation")
                        n.Diag = 1
                }
 
index 43e5d551375facd18cf0dcc66db21a462af8e479..b155f7857459a658a56adf7994983adbcada9a31 100644 (file)
@@ -1899,7 +1899,7 @@ func Nconv(n *Node, flag int) string {
                dumpdepth--
 
        default:
-               Fatal("unhandled %N mode")
+               Fatal("unhandled %%N mode")
        }
 
        flag = sf
index 90384499fd268cee513e9ee7b112f9fc76a9c675..53aec54e4a18e5919d9c85b25a2790391022a824 100644 (file)
@@ -449,7 +449,7 @@ simple_stmt:
                        if $1.Next != nil {
                                Yyerror("argument count mismatch: %d = %d", count($1), 1);
                        } else if ($1.N.Op != ONAME && $1.N.Op != OTYPE && $1.N.Op != ONONAME) || isblank($1.N) {
-                               Yyerror("invalid variable name %nil in type switch", $1.N);
+                               Yyerror("invalid variable name %s in type switch", Nconv($1.N, 0));
                        } else {
                                $$.Left = dclname($1.N.Sym);
                        }  // it's a colas, so must not re-use an oldname.
index 555a8fddd650bcbb0c043fe1911e7539e61b12b7..26f2eff13a073051803b89f0293c19f7e3b4e570 100644 (file)
@@ -75,15 +75,16 @@ func usage() {
        Exit(2)
 }
 
-func fault(s int) {
-       // If we've already complained about things
-       // in the program, don't bother complaining
-       // about the seg fault too; let the user clean up
-       // the code and try again.
+func hidePanic() {
        if nsavederrors+nerrors > 0 {
-               errorexit()
+               // If we've already complained about things
+               // in the program, don't bother complaining
+               // about a panic too; let the user clean up
+               // the code and try again.
+               if err := recover(); err != nil {
+                       errorexit()
+               }
        }
-       Fatal("fault")
 }
 
 func doversion() {
@@ -95,7 +96,7 @@ func doversion() {
                p = ""
        }
        sep = ""
-       if p[0] != 0 {
+       if p != "" {
                sep = " "
        }
        fmt.Printf("%cg version %s%s%s\n", Thearch.Thechar, obj.Getgoversion(), sep, p)
@@ -103,6 +104,7 @@ func doversion() {
 }
 
 func Main() {
+       defer hidePanic()
        var l *NodeList
        var p string
 
@@ -1834,8 +1836,14 @@ func (yy) Error(msg string) {
        Yyerror("%s", msg)
 }
 
+var theparser yyParser
+var parsing bool
+
 func yyparse() {
-       yyParse(yy{})
+       theparser = yyNewParser()
+       parsing = true
+       theparser.Parse(yy{})
+       parsing = false
 }
 
 func yylex(yylval *yySymType) int32 {
index 45f16d969cc96278b5464359c16e90f5f6f44707..14b8620ad490a3daca45039111179f52c46c1c35 100644 (file)
@@ -638,7 +638,7 @@ func Fconv(fvp *Mpflt, flag int) string {
                        if d >= 0 && (flag&obj.FmtSign != 0 /*untyped*/) {
                                fp += fmt.Sprintf("+")
                        }
-                       fp += fmt.Sprintf("%g", d)
+                       fp += fmt.Sprintf("%.6g", d)
                        return fp
                }
 
index c8e613ce263582cde6be7337fab89353ea62907b..dba7dc338fec01414bb1309d2fc32d133404156b 100644 (file)
@@ -36,7 +36,8 @@ func errorexit() {
 }
 
 func parserline() int {
-       if yychar_subr != 0 && yychar_subr != -2 { // parser has one symbol lookahead
+       if parsing && theparser.Lookahead() > 0 {
+               // parser has one symbol lookahead
                return int(prevlineno)
        }
        return int(lineno)
@@ -135,6 +136,9 @@ var yyerror_lastsyntax int
 func Yyerror(fmt_ string, args ...interface{}) {
        var i int
 
+       if fmt_ == "%s" && len(args) == 1 && args[0] == "syntax error" {
+               nsyntaxerrors++
+       }
        if strings.HasPrefix(fmt_, "syntax error") {
                nsyntaxerrors++
 
index 5b79856981169a2f3331eabc2122715b5ea345be..b05fe8f34e2c5a057cf4042edeabbfaf6d53f625 100644 (file)
@@ -1467,7 +1467,7 @@ yydefault:
                                if yyDollar[1].list.Next != nil {
                                        Yyerror("argument count mismatch: %d = %d", count(yyDollar[1].list), 1)
                                } else if (yyDollar[1].list.N.Op != ONAME && yyDollar[1].list.N.Op != OTYPE && yyDollar[1].list.N.Op != ONONAME) || isblank(yyDollar[1].list.N) {
-                                       Yyerror("invalid variable name %nil in type switch", yyDollar[1].list.N)
+                                       Yyerror("invalid variable name %s in type switch", Nconv(yyDollar[1].list.N, 0))
                                } else {
                                        yyVAL.node.Left = dclname(yyDollar[1].list.N.Sym)
                                } // it's a colas, so must not re-use an oldname.