aboutsummaryrefslogtreecommitdiff
path: root/libgcobol/common-defs.h
diff options
context:
space:
mode:
Diffstat (limited to 'libgcobol/common-defs.h')
-rw-r--r--libgcobol/common-defs.h66
1 files changed, 27 insertions, 39 deletions
diff --git a/libgcobol/common-defs.h b/libgcobol/common-defs.h
index e3471c5..a78022a 100644
--- a/libgcobol/common-defs.h
+++ b/libgcobol/common-defs.h
@@ -30,8 +30,9 @@
#ifndef COMMON_DEFS_H_
#define COMMON_DEFS_H_
-#include <stdio.h>
-#include <stdint.h>
+#include <cassert>
+#include <cstdio>
+#include <cstdint>
#include <list>
#define COUNT_OF(X) (sizeof(X) / sizeof(X[0]))
@@ -236,7 +237,7 @@ enum cbl_file_mode_t {
file_mode_output_e = 'w',
file_mode_extend_e = 'a',
file_mode_io_e = '+',
- file_mode_any_e,
+ file_mode_any_e,
};
enum cbl_round_t {
@@ -287,15 +288,15 @@ enum bitop_t {
};
enum file_stmt_t {
- file_stmt_delete_e,
- file_stmt_merge_e,
- file_stmt_read_e,
- file_stmt_rewrite_e,
- file_stmt_sort_e,
- file_stmt_start_e,
- file_stmt_write_e,
+ file_stmt_delete_e,
+ file_stmt_merge_e,
+ file_stmt_read_e,
+ file_stmt_rewrite_e,
+ file_stmt_sort_e,
+ file_stmt_start_e,
+ file_stmt_write_e,
};
-
+
enum file_close_how_t {
file_close_no_how_e = 0x00,
file_close_removal_e = 0x01,
@@ -411,14 +412,14 @@ ec_cmp( ec_type_t raised, ec_type_t ec )
{
if( raised == ec ) return true;
- // If both low bytes are nonzero, we had to match exactly, above.
+ // If both low bytes are nonzero, we had to match exactly, above.
if( (~EC_ALL_E & static_cast<uint32_t>(raised))
&&
(~EC_ALL_E & static_cast<uint32_t>(ec)) ) {
return false;
}
- // Level 1 and 2 have low byte of zero.
+ // Level 1 and 2 have low byte of zero.
// If one low byte is zero, see if they're the same kind.
return 0xFF < ( static_cast<uint32_t>(raised)
&
@@ -458,35 +459,23 @@ struct cbl_enabled_exception_t {
struct cbl_declarative_t {
enum { files_max = 16 };
size_t section; // implies program
- uint32_t global; // See the note below
+ bool global;
ec_type_t type;
uint32_t nfile, files[files_max];
cbl_file_mode_t mode;
-/* The ::global member originally was "bool global". A bool, however, occupies
- only one byte of storage. The structure, in turn, is constructed on
- four-byte boundaries for members, so there were three padding bytes between
- the single byte of global and the ::type member.
-
- When used to create a "blob", where the structure was treated as a stream
- of bytes that were used to create a constructor for an array of bytes,
- valgrind noticed that those three padding bytes were not initialized, and
- generated the appropriate error message. This made it hard to find other
- problems.
-
- Changing the declaration from "bool" to "uint32_t" seems to have eliminated
- the valgrind error without affecting overall performance. */
-
- cbl_declarative_t( cbl_file_mode_t mode = file_mode_none_e )
- : section(0), global(false)
+ explicit cbl_declarative_t( cbl_file_mode_t mode = file_mode_none_e )
+ : section(0)
+ , global(false)
, type(ec_none_e)
, nfile(0)
, mode(mode)
{
std::fill(files, files + COUNT_OF(files), 0);
}
- cbl_declarative_t( ec_type_t type )
- : section(0), global(false)
+ explicit cbl_declarative_t( ec_type_t type )
+ : section(0)
+ , global(false)
, type(type)
, nfile(0)
, mode(file_mode_none_e)
@@ -521,10 +510,9 @@ struct cbl_declarative_t {
std::copy( that.files, that.files + nfile, this->files );
}
}
- constexpr cbl_declarative_t& operator=(const cbl_declarative_t&) = default;
+ cbl_declarative_t& operator=(const cbl_declarative_t&) = default;
std::vector<uint64_t> encode() const;
- void decode( const std::vector<uint64_t>& encoded );
/*
* Sort file names before file modes, and file modes before non-IO.
@@ -547,9 +535,9 @@ struct cbl_declarative_t {
return section < that.section;
}
- // TRUE if there are no files to match, or the provided file is in the list.
- bool match_file( size_t file ) const {
- static const auto pend = files + nfile;
+ // TRUE if there are no files to match, or the provided file is in the list.
+ bool match_file( size_t file ) const {
+ static const uint32_t * pend = files + nfile;
return nfile == 0 || pend != std::find(files, files + nfile, file);
}
@@ -578,11 +566,11 @@ class cbl_enabled_exceptions_t : protected std::set<cbl_enabled_exception_t>
public:
cbl_enabled_exceptions_t() {}
- cbl_enabled_exceptions_t( size_t nec, const cbl_enabled_exception_t *ecs )
+ cbl_enabled_exceptions_t( size_t nec, const cbl_enabled_exception_t *ecs )
: std::set<cbl_enabled_exception_t>(ecs, ecs + nec)
{}
void turn_on_off( bool enabled, bool location, ec_type_t type,
- std::set<size_t> files );
+ const std::set<size_t>& files );
const cbl_enabled_exception_t * match( ec_type_t ec, size_t file = 0 ) const;