1 // go-diagnostics.h -- interface to diagnostic reporting -*- C++ -*-
3 // Copyright 2016 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 #ifndef GO_DIAGNOSTICS_H
8 #define GO_DIAGNOSTICS_H
10 #include "go-linemap.h"
12 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
13 #define GO_ATTRIBUTE_GCC_DIAG(m, n) __attribute__ ((__format__ (__gcc_tdiag__, m, n))) __attribute__ ((__nonnull__ (m)))
15 #define GO_ATTRIBUTE_GCC_DIAG(m, n)
18 // These declarations define the interface through which the frontend
19 // reports errors and warnings. These functions accept printf-like
20 // format specifiers (e.g. %d, %f, %s, etc), with the following additional
23 // 1. 'q' qualifier may be applied to a specifier to add quoting, e.g.
24 // %qd produces a quoted decimal output, %qs a quoted string output.
25 // [This extension is supported only with single-character format
28 // 2. %m specifier outputs value of "strerror(errno)" at time of call.
30 // 3. %< outputs an opening quote, %> a closing quote.
32 // All other format specifiers are as defined by 'sprintf'. The final resulting
33 // message is then sent to the back end via go_be_error_at/go_be_warning_at.
35 extern void go_error_at(const Location
, const char* fmt
, ...)
36 GO_ATTRIBUTE_GCC_DIAG(2,3);
37 extern void go_warning_at(const Location
, int opt
, const char* fmt
, ...)
38 GO_ATTRIBUTE_GCC_DIAG(3,4);
39 extern void go_fatal_error(const Location
, const char* fmt
, ...)
40 GO_ATTRIBUTE_GCC_DIAG(2,3);
41 extern void go_inform(const Location
, const char* fmt
, ...)
42 GO_ATTRIBUTE_GCC_DIAG(2,3);
44 // These interfaces provide a way for the front end to ask for
45 // the open/close quote characters it should use when formatting
46 // diagnostics (warnings, errors).
47 extern const char* go_open_quote();
48 extern const char* go_close_quote();
50 // These interfaces are used by utilities above to pass warnings and
51 // errors (once format specifiers have been expanded) to the back end,
52 // and to determine quoting style. Avoid calling these routines directly;
53 // instead use the equivalent routines above. The back end is required to
54 // implement these routines.
56 extern void go_be_error_at(const Location
, const std::string
& errmsg
);
57 extern void go_be_warning_at(const Location
, int opt
,
58 const std::string
& warningmsg
);
59 extern void go_be_fatal_error(const Location
, const std::string
& errmsg
);
60 extern void go_be_inform(const Location
, const std::string
& infomsg
);
61 extern void go_be_get_quotechars(const char** open_quote
,
62 const char** close_quote
);
64 #endif // !defined(GO_DIAGNOSTICS_H)