Skip to content
This repository was archived by the owner on Jul 7, 2020. It is now read-only.

Commit a97ff47

Browse files
committed
c2go: more minor bug fixes, notably preserve %% in format strings
Also, reestablish "signal handler".
1 parent a9bc7f2 commit a97ff47

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

Diff for: add/gc/go.y

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ simple_stmt:
449449
if $1.Next != nil {
450450
Yyerror("argument count mismatch: %d = %d", count($1), 1);
451451
} else if ($1.N.Op != ONAME && $1.N.Op != OTYPE && $1.N.Op != ONONAME) || isblank($1.N) {
452-
Yyerror("invalid variable name %nil in type switch", $1.N);
452+
Yyerror("invalid variable name %s in type switch", Nconv($1.N, 0));
453453
} else {
454454
$$.Left = dclname($1.N.Sym);
455455
} // it's a colas, so must not re-use an oldname.

Diff for: c2go.cfg

+61-2
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ diff {
14961496
dumpdepth--
14971497

14981498
default:
1499-
Fatal("unhandled %N mode")
1499+
Fatal("unhandled %%N mode")
15001500
}
15011501

15021502
flag = sf
@@ -2608,8 +2608,14 @@ diff {
26082608
+ Yyerror("%s", msg)
26092609
+}
26102610
+
2611+
+var theparser yyParser
2612+
+var parsing bool
2613+
+
26112614
+func yyparse() {
2612-
+ yyParse(yy{})
2615+
+ theparser = yyNewParser()
2616+
+ parsing = true
2617+
+ theparser.Parse(yy{})
2618+
+ parsing = false
26132619
+}
26142620
+
26152621
-func yylex() int32 {
@@ -3228,3 +3234,56 @@ diff {
32283234
+ gc.Exit(0)
32293235
}
32303236
3237+
diff {
3238+
sep = ""
3239+
- if p[0] != 0 {
3240+
+ if p != "" {
3241+
sep = " "
3242+
}
3243+
}
3244+
3245+
diff {
3246+
if d >= 0 && (flag&obj.FmtSign != 0 /*untyped*/) {
3247+
fp += fmt.Sprintf("+")
3248+
}
3249+
- fp += fmt.Sprintf("%g", d)
3250+
+ fp += fmt.Sprintf("%.6g", d)
3251+
return fp
3252+
}
3253+
3254+
func parserline() int {
3255+
if parsing && theparser.Lookahead() > 0 {
3256+
// parser has one symbol lookahead
3257+
return int(prevlineno)
3258+
}
3259+
return int(lineno)
3260+
}
3261+
3262+
func fault() {
3263+
if nsavederrors+nerrors > 0 {
3264+
// If we've already complained about things
3265+
// in the program, don't bother complaining
3266+
// about a panic too; let the user clean up
3267+
// the code and try again.
3268+
if err := recover(); err != nil {
3269+
errorexit()
3270+
}
3271+
}
3272+
}
3273+
3274+
diff {
3275+
-func fault() {
3276+
+func hidePanic() {
3277+
}
3278+
diff {
3279+
func Main() {
3280+
+ defer hidePanic()
3281+
}
3282+
3283+
diff {
3284+
+ if fmt_ == "%s" && len(args) == 1 && args[0] == "syntax error" {
3285+
+ nsyntaxerrors++
3286+
+ }
3287+
if strings.HasPrefix(fmt_, "syntax error") {
3288+
nsyntaxerrors++
3289+
}

Diff for: printf.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ func fixPrintFormat(curfn *cc.Decl, fx *cc.Expr, args []*cc.Expr) []*cc.Expr {
153153
}
154154
})
155155
}
156-
156+
157157
isGC := strings.Contains(fx.Span.Start.File, "cmd/gc")
158-
isCompiler := isGC || strings.Contains(fx.Span.Start.File, "cmd/6g") || strings.Contains(fx.Span.Start.File, "cmd/8g") || strings.Contains(fx.Span.Start.File, "cmd/5g") || strings.Contains(fx.Span.Start.File, "cmd/9g")
158+
isCompiler := isGC || strings.Contains(fx.Span.Start.File, "cmd/6g") || strings.Contains(fx.Span.Start.File, "cmd/8g") || strings.Contains(fx.Span.Start.File, "cmd/5g") || strings.Contains(fx.Span.Start.File, "cmd/9g")
159159

160160
narg := 0
161161
for j, text := range fx.Texts {
@@ -177,6 +177,7 @@ func fixPrintFormat(curfn *cc.Decl, fx *cc.Expr, args []*cc.Expr) []*cc.Expr {
177177
start = i
178178
i++
179179
if i < len(format) && format[i] == '%' {
180+
buf.WriteByte('%')
180181
buf.WriteByte('%')
181182
start = i + 1
182183
continue
@@ -250,7 +251,7 @@ func fixPrintFormat(curfn *cc.Decl, fx *cc.Expr, args []*cc.Expr) []*cc.Expr {
250251
convert = "uint"
251252
}
252253
}
253-
254+
254255
case 'C': // rune
255256
buf.WriteString(flags)
256257
buf.WriteString("c")

0 commit comments

Comments
 (0)