aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/gc/main.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2020-11-16 11:08:38 -0500
committerRuss Cox <rsc@golang.org>2020-11-24 15:07:09 +0000
commit357c576878137c8840b702c64167470f1669f064 (patch)
tree8f5231b32b44f1e53dbaab0f8759743ccc4e3ccd /src/cmd/compile/internal/gc/main.go
parent5fd949e4bd18ec2068e614c17be0a74969dc13b8 (diff)
downloadgo-357c576878137c8840b702c64167470f1669f064.tar.gz
go-357c576878137c8840b702c64167470f1669f064.zip
[dev.regabi] cmd/compile: clean up error API
Prepare for factoring the error API out of this package by cleaning it up. The doc comments use the intended new names, which will be introduced in the next CL. Change-Id: Ie4c8d4262422da32a9a9f750fda42c225b6b42a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/272248 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/gc/main.go')
-rw-r--r--src/cmd/compile/internal/gc/main.go44
1 files changed, 11 insertions, 33 deletions
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go
index d1b4161277..89dbca0cf1 100644
--- a/src/cmd/compile/internal/gc/main.go
+++ b/src/cmd/compile/internal/gc/main.go
@@ -119,7 +119,7 @@ func usage() {
}
func hidePanic() {
- if Debug_panic == 0 && nsavederrors+nerrors > 0 {
+ if Debug_panic == 0 && Errors() > 0 {
// If we've already complained about things
// in the program, don't bother complaining
// about a panic too; let the user clean up
@@ -567,7 +567,6 @@ func Main(archInit func(*Arch)) {
initUniverse()
dclcontext = PEXTERN
- nerrors = 0
autogeneratedPos = makePos(src.NewFileBase("<autogenerated>", "<autogenerated>"), 1, 0)
@@ -625,10 +624,10 @@ func Main(archInit func(*Arch)) {
if n.Op == ODCLFUNC {
Curfn = n
decldepth = 1
- saveerrors()
+ errorsBefore := Errors()
typecheckslice(Curfn.Nbody.Slice(), ctxStmt)
checkreturn(Curfn)
- if nerrors != 0 {
+ if Errors() > errorsBefore {
Curfn.Nbody.Set(nil) // type errors; do not compile
}
// Now that we've checked whether n terminates,
@@ -641,11 +640,9 @@ func Main(archInit func(*Arch)) {
// check past phase 9 isn't sufficient, as we may exit with other errors
// before then, thus skipping map key errors.
checkMapKeys()
- timings.AddEvent(fcount, "funcs")
+ ExitIfErrors()
- if nsavederrors+nerrors != 0 {
- errorexit()
- }
+ timings.AddEvent(fcount, "funcs")
fninit(xtop)
@@ -660,12 +657,8 @@ func Main(archInit func(*Arch)) {
}
}
capturevarscomplete = true
-
Curfn = nil
-
- if nsavederrors+nerrors != 0 {
- errorexit()
- }
+ ExitIfErrors()
// Phase 5: Inlining
timings.Start("fe", "inlining")
@@ -674,14 +667,10 @@ func Main(archInit func(*Arch)) {
// otherwise lazily when used or re-exported.
for _, n := range importlist {
if n.Func.Inl != nil {
- saveerrors()
typecheckinl(n)
}
}
-
- if nsavederrors+nerrors != 0 {
- errorexit()
- }
+ ExitIfErrors()
}
if Debug.l != 0 {
@@ -793,10 +782,7 @@ func Main(archInit func(*Arch)) {
// Check the map keys again, since we typechecked the external
// declarations.
checkMapKeys()
-
- if nerrors+nsavederrors != 0 {
- errorexit()
- }
+ ExitIfErrors()
// Write object data to disk.
timings.Start("be", "dumpobj")
@@ -827,10 +813,7 @@ func Main(archInit func(*Arch)) {
}
logopt.FlushLoggedOpts(Ctxt, myimportpath)
-
- if nerrors+nsavederrors != 0 {
- errorexit()
- }
+ ExitIfErrors()
flusherrors()
timings.Stop()
@@ -1011,11 +994,6 @@ func readSymABIs(file, myimportpath string) {
}
}
-func saveerrors() {
- nsavederrors += nerrors
- nerrors = 0
-}
-
func arsize(b *bufio.Reader, name string) int {
var buf [ArhdrSize]byte
if _, err := io.ReadFull(b, buf[:]); err != nil {
@@ -1396,7 +1374,7 @@ func clearImports() {
// leave s->block set to cause redeclaration
// errors if a conflicting top-level name is
// introduced by a different file.
- if !n.Name.Used() && nsyntaxerrors == 0 {
+ if !n.Name.Used() && SyntaxErrors() == 0 {
unused = append(unused, importedPkg{n.Pos, n.Name.Pkg.Path, s.Name})
}
s.Def = nil
@@ -1405,7 +1383,7 @@ func clearImports() {
if IsAlias(s) {
// throw away top-level name left over
// from previous import . "x"
- if n.Name != nil && n.Name.Pack != nil && !n.Name.Pack.Name.Used() && nsyntaxerrors == 0 {
+ if n.Name != nil && n.Name.Pack != nil && !n.Name.Pack.Name.Used() && SyntaxErrors() == 0 {
unused = append(unused, importedPkg{n.Name.Pack.Pos, n.Name.Pack.Name.Pkg.Path, ""})
n.Name.Pack.Name.SetUsed(true)
}