Debian Codegraph @

gcc/cobol/cdfval.h

raw
1 /*
2 * Copyright (c) 2021-2025 Symas Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of the Symas Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _CDF_VAL_H_
33 #define _CDF_VAL_H_
34
35 #include <cassert>
36 #include <cstdint>
37 #include <cstdlib>
38
39 bool scanner_parsing();
40
41 /* cdfval_base_t has no constructor because otherwise:
42 * cobol/cdf.h:172:7: note: ‘YDFSTYPE::YDFSTYPE()’ is implicitly deleted
43 * because the default definition would be ill-formed:
44 * 172 | union YDFSTYPE
45 *
46 * We use the derived type cdfval_t, which can be properly constructed and
47 * operated on, but tell Bison only about its POD base class.
48 */
49 struct YDFLTYPE;
50 struct cdfval_base_t {
51 bool off;
52 const char *string;
53 int64_t number;
54 const cdfval_base_t& operator()( const YDFLTYPE& loc );
55 };
56
57 struct cdf_arg_t {
58 int token;
59 const char *string;
60 };
61
62 extern int yylineno;
63 const char * cobol_filename();
64
65 struct cdfval_t : public cdfval_base_t {
66 int lineno;
67 const char *filename;
68
69 cdfval_t()
70 : lineno(yylineno), filename(cobol_filename())
71 {
72 cdfval_base_t::off = false;
73 cdfval_base_t::string = NULL;
74 cdfval_base_t::number = 0;
75 }
76 cdfval_t( const char value[] ) // cppcheck-suppress noExplicitConstructor
77 : lineno(yylineno), filename(cobol_filename())
78 {
79 cdfval_base_t::off = false;
80 cdfval_base_t::string = value;
81 cdfval_base_t::number = 0;
82 }
83 cdfval_t( long long value ) // cppcheck-suppress noExplicitConstructor
84 : lineno(yylineno), filename(cobol_filename())
85 {
86 cdfval_base_t::off = false;
87 cdfval_base_t::string = NULL;
88 cdfval_base_t::number = value;
89 }
90 cdfval_t( long value ) // cppcheck-suppress noExplicitConstructor
91 : lineno(yylineno), filename(cobol_filename())
92 {
93 cdfval_base_t::off = false;
94 cdfval_base_t::string = NULL;
95 cdfval_base_t::number = value;
96 }
97 cdfval_t( int value ) // cppcheck-suppress noExplicitConstructor
98 : lineno(yylineno), filename(cobol_filename())
99 {
100 cdfval_base_t::off = false;
101 cdfval_base_t::string = NULL;
102 cdfval_base_t::number = value;
103 }
104 explicit cdfval_t( const REAL_VALUE_TYPE& r )
105 : lineno(yylineno), filename(cobol_filename())
106 {
107 cdfval_base_t::off = false;
108 cdfval_base_t::string = NULL;
109 HOST_WIDE_INT value = real_to_integer(&r);
110 cdfval_base_t::number = value;
111 }
112 cdfval_t( const cdfval_base_t& value ) // cppcheck-suppress noExplicitConstructor
113 : lineno(yylineno), filename(cobol_filename())
114 {
115 cdfval_base_t *self(this);
116 *self = value;
117 }
118
119 bool is_numeric() const { return ! (off || string); }
120 int64_t as_number() const { assert(is_numeric()); return number; }
121 };
122
123 const cdfval_t *
124 cdf_value( const char name[] );
125
126 bool
127 cdf_value( const char name[], const cdfval_t& value );
128
129 typedef std::map<std::string, cdfval_t> cdf_values_t;
130
131 cdf_values_t& cdf_dictionary();
132
133 #endif