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>
// 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
}
dumpdepth--
default:
- Fatal("unhandled %N mode")
+ Fatal("unhandled %%N mode")
}
flag = sf
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.
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() {
p = ""
}
sep = ""
- if p[0] != 0 {
+ if p != "" {
sep = " "
}
fmt.Printf("%cg version %s%s%s\n", Thearch.Thechar, obj.Getgoversion(), sep, p)
}
func Main() {
+ defer hidePanic()
var l *NodeList
var p 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 {
if d >= 0 && (flag&obj.FmtSign != 0 /*untyped*/) {
fp += fmt.Sprintf("+")
}
- fp += fmt.Sprintf("%g", d)
+ fp += fmt.Sprintf("%.6g", d)
return fp
}
}
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)
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++
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.