Debian Codegraph @

gcc/cobol/cbldiag.h

raw
1 /*
2 * Copyright (c) 2021-2025 Symas Corporation
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of the Symas Corporation nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifdef _CBLDIAG_H
32 #pragma message __FILE__ " included twice"
33 #else
34 #define _CBLDIAG_H
35
36 #if GCOBOL_GETENV
37 #define gcobol_getenv(x) getenv(x)
38 #else
39 #define gcobol_getenv(x) ((char *)nullptr)
40 #endif
41
42 const char * cobol_filename();
43
44 /*
45 * These are user-facing messages. They go through the gcc
46 * diagnostic framework and use text that can be localized.
47 */
48 void yyerror( const char fmt[], ... ) ATTRIBUTE_GCOBOL_DIAG(1, 2);
49 bool yywarn( const char fmt[], ... ) ATTRIBUTE_GCOBOL_DIAG(1, 2);
50
51 /* Location type. Borrowed from parse.h as generated by Bison. */
52 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
53 typedef struct YYLTYPE YYLTYPE;
54 struct YYLTYPE
55 {
56 int first_line;
57 int first_column;
58 int last_line;
59 int last_column;
60 };
61 # define YYLTYPE_IS_DECLARED 1
62 # define YYLTYPE_IS_TRIVIAL 1
63
64 const YYLTYPE& cobol_location();
65 #endif
66
67 #if ! defined YDFLTYPE && ! defined YDFLTYPE_IS_DECLARED
68 typedef struct YDFLTYPE YDFLTYPE;
69 struct YDFLTYPE
70 {
71 int first_line;
72 int first_column;
73 int last_line;
74 int last_column;
75 };
76 # define YDFLTYPE_IS_DECLARED 1
77 # define YDFLTYPE_IS_TRIVIAL 1
78
79 #endif
80
81 // Diagnostic format specifiers are documented in gcc/pretty-print.cc
82 // an error at a location, called from the parser for semantic errors
83 void error_msg( const YYLTYPE& loc, const char gmsgid[], ... )
84 ATTRIBUTE_GCOBOL_DIAG(2, 3);
85
86 bool
87 warn_msg( const YYLTYPE& loc, const char gmsgid[], ... )
88 ATTRIBUTE_GCOBOL_DIAG(2, 3);
89
90 // an error that uses token_location, not yylloc
91 void error_msg_direct( const char gmsgid[], ... )
92 ATTRIBUTE_GCOBOL_DIAG(1, 2);
93
94 void dialect_error( const YYLTYPE& loc, const char term[], const char dialect[] );
95
96
97 // for CDF and other warnings that refer back to an earlier line
98 // (not in diagnostic framework yet)
99 void yyerrorvl( int line, const char *filename, const char fmt[], ... )
100 ATTRIBUTE_PRINTF_3;
101
102 void cbl_unimplementedw(const char *gmsgid, ...) ATTRIBUTE_GCOBOL_DIAG(1, 2); // warning
103 void cbl_unimplemented(const char *gmsgid, ...) ATTRIBUTE_GCOBOL_DIAG(1, 2); // error
104 void cbl_unimplemented_at( const YYLTYPE& loc, const char *gmsgid, ... )
105 ATTRIBUTE_GCOBOL_DIAG(2, 3);
106
107 /*
108 * dbgmsg produce messages not intended for the user. They cannot be localized
109 * and fwrite directly to standard error. dbgmsg is activated by -fflex-debug
110 * or -fyacc-debug.
111 */
112 void dbgmsg( const char fmt[], ... ) ATTRIBUTE_PRINTF_1;
113
114 void gcc_location_set( const YYLTYPE& loc );
115
116 void gcc_location_dump();
117
118 // tree.h defines yy_flex_debug as a macro because options.h
119 #if ! defined(yy_flex_debug)
120 template <typename LOC>
121 static void
122 location_dump( const char func[], int line, const char tag[], const LOC& loc) {
123 extern int yy_flex_debug; // cppcheck-suppress shadowVariable
124 if( yy_flex_debug ) {
125 const char *detail = gcobol_getenv("update_location");
126 if( detail ) {
127 fprintf(stderr, "%s:%d: %s location (%d,%d) to (%d,%d)\n",
128 func, line, tag,
129 loc.first_line, loc.first_column, loc.last_line, loc.last_column);
130 if( *detail == '2' ) gcc_location_dump();
131 }
132 }
133 }
134 #endif // defined(yy_flex_debug)
135
136 #endif