Debian Codegraph @

gcc/cobol/exceptg.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 #ifndef _EXCEPTL_H_
31 #define _EXCEPTL_H_
32
33 /* This file contains exception processing declarations needed by the gcc/cobol
34 compilation. It's not included in the libgcobol compilation. */
35
36 extern const char * ec_type_str( ec_type_t type );
37 extern ec_disposition_t ec_type_disposition( ec_type_t type );
38
39 extern void declarative_runtime_match( const std::list<cbl_declarative_t>& declaratives,
40 cbl_label_t *lave );
41
42 static inline ec_disposition_t
43 ec_implemented( ec_disposition_t disposition ) {
44 return ec_disposition_t( size_t(disposition) & ~0x80 );
45 }
46
47 // >>TURN arguments
48 class exception_turn_t;
49 bool apply_cdf_turn( const exception_turn_t& turn );
50
51 class exception_turn_t {
52 friend bool apply_cdf_turn( const exception_turn_t& turn );
53 typedef std::list<size_t> filelist_t;
54 typedef std::map<ec_type_t, filelist_t> ec_filemap_t;
55 ec_filemap_t exceptions;
56 bool enabled, location;
57 public:
58
59 exception_turn_t() : enabled(false), location(false) {};
60
61 explicit exception_turn_t( ec_type_t ec, bool enabled = true )
62 : enabled(enabled), location(false)
63 {
64 add_exception(ec);
65 }
66
67 bool enable( bool enabled ) {
68 return this->enabled = enabled;
69 }
70 bool enable( bool enabled, bool location ) {
71 this->location = location;
72 return this->enabled = enabled;
73 }
74
75 const ec_filemap_t& exception_files() const { return exceptions; }
76
77 bool add_exception( ec_type_t type, const filelist_t& files = filelist_t() ) {
78 ec_disposition_t disposition = ec_type_disposition(type);
79 if( disposition != ec_implemented(disposition) ) {
80 cbl_unimplementedw("CDF: exception '%s'", ec_type_str(type));
81 }
82 auto elem = exceptions.find(type);
83 if( elem != exceptions.end() ) return false; // cannot add twice
84
85 exceptions[type] = files;
86 return true;
87 }
88
89 void clear() {
90 for( auto& ex : exceptions ) {
91 ex.second.clear();
92 }
93 exceptions.clear();
94 enabled = location = false;
95 }
96
97 };
98
99 #endif
100
101
102