github.com/alexanius/gollvm12@v0.0.0-20230419200121-b152358b84f3/gofrontend/go/go-diagnostics.h (about)

     1  // go-diagnostics.h -- interface to diagnostic reporting   -*- C++ -*-
     2  
     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.
     6  
     7  #ifndef GO_DIAGNOSTICS_H
     8  #define GO_DIAGNOSTICS_H
     9  
    10  #include "go-linemap.h"
    11  
    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)))
    14  #else
    15  #define GO_ATTRIBUTE_GCC_DIAG(m,  n)
    16  #endif
    17  
    18  #if __GNUC__ >= 3
    19  #define GO_ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) __attribute__ ((__nonnull__ (m)))
    20  #else
    21  #define GO_ATTRIBUTE_PRINTF(m, n)
    22  #endif
    23  
    24  // These declarations define the interface through which the frontend
    25  // reports errors and warnings. These functions accept printf-like
    26  // format specifiers (e.g. %d, %f, %s, etc), with the following additional
    27  // extensions:
    28  //
    29  //  1.  'q' qualifier may be applied to a specifier to add quoting, e.g.
    30  //      %qd produces a quoted decimal output, %qs a quoted string output.
    31  //      [This extension is supported only with single-character format
    32  //      specifiers].
    33  //
    34  //  2.  %m specifier outputs value of "strerror(errno)" at time of call.
    35  //
    36  //  3.  %< outputs an opening quote, %> a closing quote.
    37  //
    38  // All other format specifiers are as defined by 'sprintf'. The final resulting
    39  // message is then sent to the back end via go_be_error_at/go_be_warning_at.
    40  
    41  extern void go_error_at(const Location, const char* fmt, ...)
    42      GO_ATTRIBUTE_GCC_DIAG(2,3);
    43  extern void go_warning_at(const Location, int opt, const char* fmt, ...)
    44      GO_ATTRIBUTE_GCC_DIAG(3,4);
    45  extern void go_fatal_error(const Location, const char* fmt, ...)
    46      GO_ATTRIBUTE_GCC_DIAG(2,3);
    47  extern void go_inform(const Location, const char* fmt, ...)
    48      GO_ATTRIBUTE_GCC_DIAG(2,3);
    49  
    50  // go_debug is used to report a debugging message at a location.  This
    51  // uses standard printf formatting.
    52  
    53  extern void go_debug(const Location, const char* fmt, ...)
    54    GO_ATTRIBUTE_PRINTF(2, 3);
    55  
    56  // These interfaces provide a way for the front end to ask for
    57  // the open/close quote characters it should use when formatting
    58  // diagnostics (warnings, errors).
    59  extern const char* go_open_quote();
    60  extern const char* go_close_quote();
    61  
    62  // These interfaces are used by utilities above to pass warnings and
    63  // errors (once format specifiers have been expanded) to the back end,
    64  // and to determine quoting style. Avoid calling these routines directly;
    65  // instead use the equivalent routines above. The back end is required to
    66  // implement these routines.
    67  
    68  extern void go_be_error_at(const Location, const std::string& errmsg);
    69  extern void go_be_warning_at(const Location, int opt,
    70                               const std::string& warningmsg);
    71  extern void go_be_fatal_error(const Location, const std::string& errmsg);
    72  extern void go_be_inform(const Location, const std::string& infomsg);
    73  extern void go_be_get_quotechars(const char** open_quote,
    74                                   const char** close_quote);
    75  
    76  #endif // !defined(GO_DIAGNOSTICS_H)