github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/base/print.go (about) 1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package base 6 7 import ( 8 "github.com/shogo82148/std/internal/types/errors" 9 10 "github.com/shogo82148/std/cmd/internal/src" 11 ) 12 13 // Pos is the current source position being processed, 14 // printed by Errorf, ErrorfLang, Fatalf, and Warnf. 15 var Pos src.XPos 16 17 // Errors returns the number of errors reported. 18 func Errors() int 19 20 // SyntaxErrors returns the number of syntax errors reported. 21 func SyntaxErrors() int 22 23 // FmtPos formats pos as a file:line string. 24 func FmtPos(pos src.XPos) string 25 26 // FlushErrors sorts errors seen so far by line number, prints them to stdout, 27 // and empties the errors array. 28 func FlushErrors() 29 30 // Errorf reports a formatted error at the current line. 31 func Errorf(format string, args ...interface{}) 32 33 // ErrorfAt reports a formatted error message at pos. 34 func ErrorfAt(pos src.XPos, code errors.Code, format string, args ...interface{}) 35 36 // UpdateErrorDot is a clumsy hack that rewrites the last error, 37 // if it was "LINE: undefined: NAME", to be "LINE: undefined: NAME in EXPR". 38 // It is used to give better error messages for dot (selector) expressions. 39 func UpdateErrorDot(line string, name, expr string) 40 41 // Warn reports a formatted warning at the current line. 42 // In general the Go compiler does NOT generate warnings, 43 // so this should be used only when the user has opted in 44 // to additional output by setting a particular flag. 45 func Warn(format string, args ...interface{}) 46 47 // WarnfAt reports a formatted warning at pos. 48 // In general the Go compiler does NOT generate warnings, 49 // so this should be used only when the user has opted in 50 // to additional output by setting a particular flag. 51 func WarnfAt(pos src.XPos, format string, args ...interface{}) 52 53 // Fatalf reports a fatal error - an internal problem - at the current line and exits. 54 // If other errors have already been printed, then Fatalf just quietly exits. 55 // (The internal problem may have been caused by incomplete information 56 // after the already-reported errors, so best to let users fix those and 57 // try again without being bothered about a spurious internal error.) 58 // 59 // But if no errors have been printed, or if -d panic has been specified, 60 // Fatalf prints the error as an "internal compiler error". In a released build, 61 // it prints an error asking to file a bug report. In development builds, it 62 // prints a stack trace. 63 // 64 // If -h has been specified, Fatalf panics to force the usual runtime info dump. 65 func Fatalf(format string, args ...interface{}) 66 67 // FatalfAt reports a fatal error - an internal problem - at pos and exits. 68 // If other errors have already been printed, then FatalfAt just quietly exits. 69 // (The internal problem may have been caused by incomplete information 70 // after the already-reported errors, so best to let users fix those and 71 // try again without being bothered about a spurious internal error.) 72 // 73 // But if no errors have been printed, or if -d panic has been specified, 74 // FatalfAt prints the error as an "internal compiler error". In a released build, 75 // it prints an error asking to file a bug report. In development builds, it 76 // prints a stack trace. 77 // 78 // If -h has been specified, FatalfAt panics to force the usual runtime info dump. 79 func FatalfAt(pos src.XPos, format string, args ...interface{}) 80 81 // Assert reports "assertion failed" with Fatalf, unless b is true. 82 func Assert(b bool) 83 84 // Assertf reports a fatal error with Fatalf, unless b is true. 85 func Assertf(b bool, format string, args ...interface{}) 86 87 // AssertfAt reports a fatal error with FatalfAt, unless b is true. 88 func AssertfAt(b bool, pos src.XPos, format string, args ...interface{}) 89 90 // ErrorExit handles an error-status exit. 91 // It flushes any pending errors, removes the output file, and exits. 92 func ErrorExit() 93 94 // ExitIfErrors calls ErrorExit if any errors have been reported. 95 func ExitIfErrors() 96 97 var AutogeneratedPos src.XPos