return true;
case OPT_M:
- cobol_set_pp_option('M');
+ cobol_set_pp_option('M');
return true;
case OPT_fstatic_call:
wsclear(cobol_default_byte);
return true;
- case OPT_fflex_debug:
+ case OPT_fflex_debug: // cppcheck-suppress syntaxError // The need for this is a mystery
yy_flex_debug = 1;
cobol_set_debugging( true, yy_debug == 1, cobol_trace_debug == 1 );
return true;
+
case OPT_fyacc_debug:
yy_debug = 1;
cobol_set_debugging(yy_flex_debug == 1,
true,
cobol_trace_debug == 1 );
return true;
+
case OPT_ftrace_debug:
cobol_set_debugging( yy_flex_debug == 1, yy_debug == 1, true );
return true;
case OPT_fsyntax_only:
mode_syntax_only(identification_div_e);
break;
+
case OPT_preprocess:
if( ! preprocess_filter_add(arg) ) {
cbl_errx( "could not execute preprocessor %s", arg);
}
return true;
+
case OPT_include:
if( ! include_file_add(arg) ) {
cbl_errx( "could not include %s", arg);
} );
return true;
}
-};
+}
return;
}
int i = 1;
- for( auto& elem : *this ) {
+ for( auto& elem : *this ) { // cppcheck-suppress constVariableReference
dbgmsg("cbl_enabled_exceptions_t: %2d {%s, %s, %lu}",
i++,
elem.location? "with location" : " no location",
// cl_decoded_option
size_t new_option_count = new_opt.size();
- struct cl_decoded_option *new_options = XNEWVEC (struct cl_decoded_option, new_option_count);
+ struct cl_decoded_option *new_options = XNEWVEC (struct cl_decoded_option,
+ new_option_count);
for(size_t i=0; i<new_option_count; i++)
{
#ifdef NOISY
verbose = true;
#endif
- if( verbose && new_options != original_options )
+ if( verbose && new_options != original_options ) // cppcheck-suppress knownConditionTrueFalse
{
fprintf(stderr, _("Driving: (" HOST_SIZE_T_PRINT_DEC ")\n"),
(fmt_size_t)new_option_count);
ELSE
ENDIF
- cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() );
+ const cbl_enabled_exceptions_t&
+ enabled_exceptions( cdf_enabled_exceptions() );
for(size_t i=0; i<ninputs; i++)
{
// the compiler when a source code module makes that mistake.
static std::unordered_set<std::string> names_we_have_seen;
-// This vector is used to process the function_decls at the point we leave
+// This vector is used to process the function_decls at the point we leave
// the file.
static std::vector<tree> finalized_function_decls;
static char *
gg_unique_in_function(const char *var_name, gg_variable_scope_t vs_scope)
{
- char *retval = (char *)xmalloc(strlen(var_name)+32);
+ char *retval = static_cast<char *>(xmalloc(strlen(var_name)+32));
if( (vs_scope == vs_stack || vs_scope == vs_static) )
{
sprintf(retval, "%s." HOST_SIZE_T_PRINT_DEC, var_name,
break;
}
DECL_INITIAL(var_decl) = initial_value;
- if( unique_name )
- {
- free(unique_name);
- }
+ free(unique_name);
return var_decl;
}
}
return retval;
}
-
+
tree
gg_build_fn_decl(const char *funcname, tree fndecl_type)
{
tree function_decl;
-
+
std::string key = function_decl_key(funcname, fndecl_type);
std::unordered_map<std::string, tree>::const_iterator it =
map_of_function_decls.find(key);
}
va_end(params);
+ char ach[32];
std::unordered_set<std::string>::const_iterator it =
names_we_have_seen.find(funcname);
if( it != names_we_have_seen.end() )
{
static int bum_counter = 1;
// We have seen this name before. Replace it with something unique:
- char ach[32];
sprintf(ach, "..no_dupes.%d", bum_counter++);
funcname = ach;
}
if( !arithmetic_label->structs.arith_error )
{
arithmetic_label->structs.arith_error
- = (cbl_arith_error_t *)xmalloc(sizeof(struct cbl_arith_error_t) );
+ = static_cast<cbl_arith_error_t *>
+ (xmalloc(sizeof(struct cbl_arith_error_t)));
// Set up the address pairs for this clause
gg_create_goto_pair(&arithmetic_label->structs.arith_error->over.go_to,
&arithmetic_label->structs.arith_error->over.label);
if( !compute_label->structs.compute_error )
{
compute_label->structs.compute_error
- = (cbl_compute_error_t *)
- xmalloc(sizeof(struct cbl_compute_error_t) );
+ = static_cast<cbl_compute_error_t *>
+ (xmalloc(sizeof(struct cbl_compute_error_t)));
compute_label->structs.compute_error->compute_error_code
= gg_define_int(0);
}
{
TRACE1_HEADER
TRACE1_TEXT_ABC("calling ", operation, "")
- TRACE1_END
for(size_t ii=0; ii<nA; ii++)
{
TRACE1_INDENT
build_int_cst_type(SIZE_T, ii));
TRACE1_REFER("", B[ii], "");
}
- TRACE1_END
}
// We need to split up cbl_num_result_t into two arrays, one for the refer_t
{
for(size_t ii=0; ii<nC; ii++)
{
- break; // Breaks on ADD 1 SUB2 GIVING SUB4 both PIC S9(3) COMP
TRACE1_INDENT
gg_fprintf( trace_handle,
1, "result: C[%ld]: ",
// We now either divide into C[n] or assign dividend/divisor to C[n]:
for(size_t i=0; i<nC; i++ )
{
- tree dest_type = tree_type_from_size(C[i].refer.field->data.capacity, 0);
- tree dest_addr = gg_add(member(C[i].refer.field->var_decl_node, "data"),
+ tree dest_type =
+ tree_type_from_size(C[i].refer.field->data.capacity, 0);
+ tree dest_addr = gg_add(member( C[i].refer.field->var_decl_node,
+ "data"),
refer_offset(C[i].refer));
tree ptr = gg_cast(build_pointer_type(dest_type), dest_addr);
if( nB )
}
// This is where we handle any remainder, keeping in mind that for
- // nB != 0, the actual dividend is in the value we have named "divisor".
- //
- // And, yes, I hate comments like that, too.
+ // nB != 0, the actual dividend is in the value we have named
+ // "divisor".
// We calculate the remainder by calculating
// dividend minus quotient * divisor
if( remainder.field )
{
- tree dest_addr = gg_add(member(remainder.field->var_decl_node, "data"),
- refer_offset(remainder));
+ dest_addr = gg_add( member(remainder.field->var_decl_node, "data"),
+ refer_offset(remainder));
dest_type = tree_type_from_size(remainder.field->data.capacity, 0);
ptr = gg_cast(build_pointer_type(dest_type), dest_addr);
tree reflen, // LONG returned value
cbl_refer_t &refer)
{
- cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() );
+ const cbl_enabled_exceptions_t&
+ enabled_exceptions( cdf_enabled_exceptions() );
if( !enabled_exceptions.match(ec_bound_ref_mod_e) )
{
declarative with a RESUME NEXT STATEMENT, or before the default_condition
processing can do a controlled exit.
*/
- cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() );
+ const cbl_enabled_exceptions_t&
+ enabled_exceptions( cdf_enabled_exceptions() );
cbl_field_t *depending_on;
depending_on = cbl_field_of(symbol_at(odo->occurs.depending_on));
return;
}
- // Bounds checking is enabled, so we test the DEPENDING ON value to be between
- // the lower and upper OCCURS limits:
+ // Bounds checking is enabled, so we test the DEPENDING ON value to be
+ // between the lower and upper OCCURS limits:
get_integer_value(retval,
depending_on,
NULL,
{
// This needs to evaluate to an integer
set_exception_code(ec_bound_odo_e);
- gg_assign(retval, build_int_cst_type(TREE_TYPE(retval), odo->occurs.bounds.lower));
+ gg_assign(retval, build_int_cst_type( TREE_TYPE(retval),
+ odo->occurs.bounds.lower));
gg_assign(var_decl_rdigits, integer_zero_node);
}
ELSE
ENDIF
- IF( retval, gt_op, build_int_cst_type(TREE_TYPE(retval), odo->occurs.bounds.upper) )
+ IF( retval, gt_op, build_int_cst_type(TREE_TYPE(retval),
+ odo->occurs.bounds.upper) )
{
set_exception_code(ec_bound_odo_e);
- gg_assign(retval, build_int_cst_type(TREE_TYPE(retval), odo->occurs.bounds.lower));
+ gg_assign(retval, build_int_cst_type( TREE_TYPE(retval),
+ odo->occurs.bounds.lower));
}
ELSE
{
- IF( retval, lt_op, build_int_cst_type(TREE_TYPE(retval), odo->occurs.bounds.lower) )
+ IF( retval, lt_op, build_int_cst_type(TREE_TYPE(retval),
+ odo->occurs.bounds.lower) )
{
set_exception_code(ec_bound_odo_e);
- gg_assign(retval, build_int_cst_type(TREE_TYPE(retval), odo->occurs.bounds.lower));
+ gg_assign(retval, build_int_cst_type( TREE_TYPE(retval),
+ odo->occurs.bounds.lower));
}
ELSE
ENDIF
// We have a refer.
// At the very least, we have an constant offset
int all_flags = 0;
- int all_flag_bit = 1;
if( refer.nsubscript() )
{
// Establish the field_t pointer for walking up through our ancestors:
cbl_field_t *parent = refer.field;
+ int all_flag_bit = 1;
// Note the backwards test, because refer->nsubscript is an unsigned value
for(size_t i=refer.nsubscript()-1; i<refer.nsubscript(); i-- )
{
}
else
{
- cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() );
+ const cbl_enabled_exceptions_t&
+ enabled_exceptions( cdf_enabled_exceptions() );
if( !enabled_exceptions.match(ec_bound_subscript_e) )
{
// With no exception testing, just pick up the value
}
ELSE
{
- IF( subscript, lt_op, gg_cast(TREE_TYPE(subscript), integer_one_node) )
+ IF( subscript, lt_op, gg_cast(TREE_TYPE(subscript),
+ integer_one_node) )
{
// The subscript is too small
set_exception_code(ec_bound_subscript_e);
- gg_assign(subscript, build_int_cst_type(TREE_TYPE(subscript), 1));
+ gg_assign(subscript, build_int_cst_type(TREE_TYPE(subscript),
+ 1));
}
ELSE
{
IF( subscript,
ge_op,
- build_int_cst_type(TREE_TYPE(subscript), parent->occurs.ntimes()) )
+ build_int_cst_type( TREE_TYPE(subscript),
+ parent->occurs.ntimes()) )
{
// The subscript is too large
set_exception_code(ec_bound_subscript_e);
- gg_assign(subscript, build_int_cst_type(TREE_TYPE(subscript), 1));
+ gg_assign(subscript, build_int_cst_type(TREE_TYPE(subscript),
+ 1));
}
ELSE
{
all_flag_bit <<= 1;
- // Although we strictly don't need to look at the ODO value at this point,
- // we do want it checked for the purposes of ec-bound-odo
+ // Although we strictly don't need to look at the ODO value at this
+ // point, we do want it checked for the purposes of ec-bound-odo
- cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() );
+ const cbl_enabled_exceptions_t&
+ enabled_exceptions( cdf_enabled_exceptions() );
if( enabled_exceptions.match(ec_bound_odo_e) )
{
if( parent->occurs.depending_on )
{
- static tree value64 = gg_define_variable(LONG, ".._gdos_value64", vs_file_static);
+ static tree value64 = gg_define_variable( LONG,
+ ".._gdos_value64",
+ vs_file_static);
cbl_field_t *odo = symbol_find_odo(parent);
get_depending_on_value_from_odo(value64, odo);
}
break;
}
- case FldAlphanumeric:
- {
-
- }
-
-
default:
{
- fprintf(stderr, "%s(): We know not how to"
- " get a binary value from %s\n",
- __func__,
- cbl_field_type_str(field->type) );
+ char *err = xasprintf("%s(): We know not how to"
+ " get a binary value from %s\n",
+ __func__,
+ cbl_field_type_str(field->type) );
+ cbl_internal_error("%s", err);
abort();
- break;
+ // break; // break not needed after abort();
}
}
}
bool
-process_this_exception(ec_type_t ec)
+process_this_exception(const ec_type_t ec)
{
- cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() );
+ const cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() );
bool retval;
if( enabled_exceptions.match(ec) || !skip_exception_processing )
{
tree value,
int rhs_rdigits,
bool check_for_error,
- tree &size_error)
+ const tree &size_error)
{
if( check_for_error )
{
}
bool
-refer_is_clean(cbl_refer_t &refer)
+refer_is_clean(const cbl_refer_t &refer)
{
if( !refer.field || refer.field->type == FldLiteralN )
{
static
tree // size_t
-refer_fill_depends(cbl_refer_t &refer)
+refer_fill_depends(const cbl_refer_t &refer)
{
REFER("");
// This returns a positive number which is the amount a depends-limited
int line,
int from_raise_statement=0);
#define set_exception_code(ec) set_exception_code_func(ec, __LINE__)
-bool process_this_exception(ec_type_t ec);
+bool process_this_exception(const ec_type_t ec);
#define CHECK_FOR_FRACTIONAL_DIGITS true
void get_integer_value(tree value, // This is always a LONG
cbl_field_t *field,
tree value,
int rhs_rdigits,
bool check_for_error,
- tree &size_error);
+ const tree &size_error);
tree build_array_of_size_t( size_t N,
const size_t *values);
void parser_display_internal_field(tree file_descriptor,
bool advance=DISPLAY_NO_ADVANCE);
char *get_literal_string(cbl_field_t *field);
-bool refer_is_clean(cbl_refer_t &refer);
+bool refer_is_clean(const cbl_refer_t &refer);
tree refer_offset(cbl_refer_t &refer,
int *pflags=NULL);
std::swap(*mfile.eol, eol); // see implementation for excuses
bool ok = regex_search(p, const_cast<const char *>(mfile.eol), cm, re);
std::swap(*mfile.eol, eol);
-
+
if( ok ) {
gcc_assert(cm.size() > 1);
bool push = TOUPPER(cm[1].first[1]) == 'U';
std::swap(*mfile.eol, eol); // see implementation for excuses
bool ok = regex_search(p, const_cast<const char *>(mfile.eol), cm, re);
std::swap(*mfile.eol, eol);
-
+
if( ok ) {
gcc_assert(cm.size() > 1);
switch( cm[3].length() ) {
dbgmsg( "%s:%d: %s format set, on line " HOST_SIZE_T_PRINT_UNSIGNED,
__func__, __LINE__,
- cdf_source_format().description(),
+ cdf_source_format().description(),
(fmt_size_t)mfile.lineno() );
char *bol = cdf_source_format().is_fixed()? mfile.cur : const_cast<char*>(cm[0].first);
gcc_assert(cm[0].second <= mfile.eol);
gcc_assert(mfile.cur <= cm.first && cm.second <= mfile.eodata);
auto nline = std::count(cm.first, cm.second, '\n');
if( nline ) {
- gcc_assert(loc.first_line < nline);
+ gcc_assert(nline < loc.first_line);
loc.first_line -= nline;
auto p = static_cast<const char*>(memrchr(cm.first, '\n', cm.length()));
loc.last_column = (cm.second) - p;
for( auto p = mfile.cur; p < next; *output.pos++ = *p++ ) {
static bool at_bol = false;
if( at_bol ) {
- auto nonblank = std::find_if( p, next,
+ auto nonblank_l = std::find_if( p, next,
[]( char ch ) {
return !isblank(ch); } );
- if( nonblank + 1 < next ) {
- if( *nonblank == '\r' ) nonblank++; // Windows
- if( *nonblank == '\n' ) {
- p = nonblank;
+ if( nonblank_l + 1 < next ) {
+ if( *nonblank_l == '\r' ) nonblank_l++; // Windows
+ if( *nonblank_l == '\n' ) {
+ p = nonblank_l;
continue;
}
}
// Process any files supplied by the -include command-line option.
for( auto name : included_files ) {
- int input;
if( -1 == (input = open(name, O_RDONLY)) ) {
yyerrorvl(1, "", "cannot open -include file %s", name);
continue;
*/
static const char *
valid_sequence_area( const char *data, const char *eodata ) {
-
+
for( const char *p = data;
(p = std::find_if(p, eodata, is_p)) != eodata;
p++ )
}
}
}
- return nullptr;
+ return nullptr;
}
/*
} current( mfile.data );
/*
- * Infer source code format.
+ * Infer source code format.
*/
if( cdf_source_format().inference_pending() ) {
const char *bol = valid_sequence_area(mfile.data, mfile.eodata);
struct { unsigned long ante, post; } lineno = {
gb4(mfile.lineno()), gb4(mfile.lineno() + segment.after.nlines())
};
- char *directive = lineno.ante == lineno.post?
+ const char *directive = lineno.ante == lineno.post?
nullptr : xasprintf("\n#line %lu \"%s\"\n",
lineno.ante, cobol_filename());
- if( directive )
+ if( directive )
output.push_back( span_t(strlen(directive), directive) );
output.push_back( span_t(mfile.cur, segment.before.p) );
output.push_back( span_t(segment.after.p, segment.after.pend ) );
- if( directive )
+ if( directive )
output.push_back( span_t(strlen(directive), directive) );
mfile.cur = const_cast<char*>(segment.before.pend);
return span_t(output, eout);
}
const char * has_nul() const {
- auto p = std::find(this->p, pend, '\0');
- return p != pend? p : NULL;
+ auto p_l = std::find(this->p, pend, '\0');
+ return p_l != pend? p_l : NULL;
}
bool at_eol() const {
(fmt_size_t)nline, (fmt_size_t)rescan.size());
if( nline ) {
gcc_assert( yylloc.first_line + nline <= yylloc.last_line );
- yylloc.last_line =- int(nline);
+ yylloc.last_line -= int(nline);
+ gcc_assert( yylloc.first_line <= yylloc.last_line );
char *p = static_cast<char*>(memrchr(rescan.p, '\n', rescan.size()));
yylloc.last_column = rescan.pend - ++p;
return;
}
return strcasecmp(key.name, elem.name);
}
- break;
+ // break; // This break not needed if all options do a return.
case SymSpecial:
return special_pair_cmp(k->elem.special, e->elem.special)? 0 : 1;
- break;
+ // break; // This break not needed after return.
case SymAlphabet:
return strcasecmp(k->elem.alphabet.name, e->elem.alphabet.name);
- break;
+ // break; // This break not needed after return.
case SymFile:
// If the key is global, so must be the found element.
if( (cbl_file_of(k)->attr & global_e) == global_e &&
return 1;
}
return strcasecmp(k->elem.file.name, e->elem.file.name);
- break;
+ // break; // This break not needed after return.
}
assert(k->type == SymField);
struct symbol_elem_t *
symbol_alphabet( size_t program, const char name[] )
{
- cbl_alphabet_t alphabet(YYLTYPE(), custom_encoding_e);
+ cbl_alphabet_t alphabet(YYLTYPE(), custom_encoding_e); // cppcheck-suppress syntaxError
assert(strlen(name) < sizeof alphabet.name);
strcpy(alphabet.name, name);
if( e->program != group->program ) return isym;
if( e->type == SymLabel ) return isym; // end of data division
if( e->type == SymField ) {
- const auto f = cbl_field_of(e);
+ const cbl_field_t * f = cbl_field_of(e);
if( f->level == LEVEL77 || f->level == 66 ) return isym;
if( f->level == 1 && f->parent != igroup ) {
return isym;
// If an 01 record exists for the FD/SD, use its capacity as the
// default_record capacity.
if( p != symbols_end() ) {
- const auto record = cbl_field_of(p);
+ const cbl_field_t * record = cbl_field_of(p);
assert(record->level == 1);
e = calculate_capacity(p);
auto record_size = std::max(record->data.memsize,
// If group has a parent that is a record area, expand it, too.
if( 0 < group->parent ) {
- auto redefined = symbol_redefines(group);
+ redefined = symbol_redefines(group);
if( redefined && is_record_area(redefined) ) {
if( redefined->data.capacity < group->data.memsize ) {
redefined->data.capacity = group->data.memsize;
const char *sep = "";
char *out = NULL;
- for( auto attr : attrs ) {
+ for( auto attr_l : attrs ) {
char *part = out;
- if( has_attr(attr) ) {
+ if( has_attr(attr_l) ) {
int erc = asprintf(&out, "%s%s%s",
- part? part : "", sep, cbl_field_attr_str(attr));
+ part? part : "", sep, cbl_field_attr_str(attr_l));
if( -1 == erc ) return part;
free(part);
sep = ", ";
bool size_invalid = field->data.memsize > 0 && symbol_redefines(field);
if( size_invalid ) { // redefine of record area is ok
- const auto redefined = symbol_redefines(field);
+ const cbl_field_t * redefined = symbol_redefines(field);
size_invalid = ! is_record_area(redefined);
}
if( !field->is_valid() || size_invalid )
}
// Verify REDEFINing field has no ODO components
- const auto parent = symbol_redefines(field);
+ const cbl_field_t * parent = symbol_redefines(field);
if( parent && !is_record_area(parent) && is_variable_length(field) ) {
ERROR_FIELD(field, "line %d: REDEFINES field %s cannot be variable length",
field->line, field->name);
auto e = symbols_end() - 1;
assert( symbols_begin() < e );
if( e->type == SymField ) {
- const auto f = cbl_field_of(e);
+ const cbl_field_t * f = cbl_field_of(e);
if( f == field ) return e;
}
if( is_numeric(parent->usage) && parent->data.capacity > 0 ) {
field->type = parent->usage;
field->data = parent->data;
- field->data = 0;
+ field->data = 0; // cppcheck-suppress redundantAssignment
+ // // cppcheck doesn't understand multiple overloaded operator=
field->data.initial = NULL;
}
}
new_temporary_impl( enum cbl_field_type_t type, const cbl_name_t name = nullptr )
{
extern int yylineno;
- static int nstack, nliteral;
static const struct cbl_field_t empty_alpha = {
0, FldAlphanumeric, FldInvalid,
intermediate_e, 0, 0, 0, nonarray, 0, "",
f->line = yylineno;
if( is_literal(type) ) {
+ static int nliteral = 0;
snprintf(f->name, sizeof(f->name), "_literal%d",++nliteral);
} else {
+ static int nstack = 0;
snprintf(f->name, sizeof(f->name), "_stack%d",++nstack);
}
bool
symbol_label_section_exists( size_t eval_label_index ) {
auto eval = symbols_begin(eval_label_index);
+ /* cppcheck warns that the following statement depends on the order of
+ evaluation of side effects. Since this isn't my code, and since I don't
+ think the warning can be eliminated without rewriting it, I am just
+ supprressing it.
+ -- Bob Dubner, 2025-07-14 */
+ // cppcheck-suppress unknownEvaluationOrder
bool has_section = std::any_of( ++eval, symbols_end(),
[program = eval->program]( const auto& sym ) {
if( program == sym.program && sym.type == SymLabel ) {
if( e->type != SymLabel ) continue;
if( e->elem.label.type != LblProgram ) continue;
- const auto prog = cbl_label_of(e);
+ const cbl_label_t * prog = cbl_label_of(e);
if( program == symbol_index(e) && !prog->recursive ) continue;
if( (self->parent == prog->parent && prog->common) ||
size_t n = COUNT_OF(file_status_fields);
const file_status_field_t *fs, key { status };
- fs = (file_status_field_t*)lfind( &key, file_status_fields,
- &n, sizeof(*fs), cbl_file_status_cmp );
-
+ fs = static_cast<file_status_field_t*>(lfind( &key,
+ file_status_fields,
+ &n,
+ sizeof(*fs),
+ cbl_file_status_cmp ));
return fs? (long)fs->status : -1;
}
static bool
is_data_field( symbol_elem_t& e ) {
if( e.type != SymField ) return false;
- const auto f = cbl_field_of(&e);
+ const cbl_field_t *f = cbl_field_of(&e);
if( f->name[0] == '\0' ) return false;
if( is_filler(f) ) return false;
for( auto& elem : symbol_map2 ) {
auto& fields( elem.second );
fields.remove_if( []( auto isym ) {
- const auto f = cbl_field_of(symbol_at(isym));
+ const cbl_field_t *f = cbl_field_of(symbol_at(isym));
return f->type == FldInvalid;
} );
if( fields.empty() ) empties.insert(elem.first);
if( p != item.second.end() ) {
// Preserve symbol's index at front of ancestor list.
symbol_map_t::mapped_type shorter(1 + ancestors->size());
- auto p = shorter.begin();
- *p = item.second.front();
- shorter.insert( ++p, ancestors->begin(), ancestors->end() );
+ auto p_l = shorter.begin();
+ *p_l = item.second.front();
+ shorter.insert( ++p_l, ancestors->begin(), ancestors->end() );
return make_pair(item.first, shorter);
}
}
size_t program;
static size_t prog_of( size_t program ) {
- const auto L = cbl_label_of(symbol_at(program));
+ const cbl_label_t *L = cbl_label_of(symbol_at(program));
return L->parent;
}
auto plist = symbol_map2.find(key);
if( plist != symbol_map2.end() ) {
for( auto candidate : plist->second ) {
- const auto e = symbol_at(candidate);
+ const symbol_elem_t *e = symbol_at(candidate);
if( name_has_names( e, names, local ) ) {
fields.push_back( symbol_index(e) );
}
get_current_dir_name ()
{
/* Use libiberty's allocator here. */
- char *buf = (char *) xmalloc (PATH_MAX);
+ char *buf = static_cast<char *>(xmalloc (PATH_MAX));
return getcwd (buf, PATH_MAX);
}
#endif
/*
* For printing messages, usually the size of the thing is some kind of string
* length, and doesn't really need a size_t. For message formatting, use a
- * simple unsigned long, and warn if that's no good. "gb4" here stands for
+ * simple unsigned long, and warn if that's no good. "gb4" here stands for
* "4 Gigabytes".
*/
unsigned long
}
return input;
}
-
+
/*
* Most CDF Directives -- those that have state -- can be pushed and popped.
* This class maintains stacks of them, with each stack having a "default
* PAGE
* PROPAGATE
* REF-MOD-ZERO-LENGTH
- *
- * >>PUSH ALL calls the class's push() method.
- * >>POP ALL calls the class's pop() method.
+ *
+ * >>PUSH ALL calls the class's push() method.
+ * >>POP ALL calls the class's pop() method.
*/
class cdf_directives_t
{
template <typename T>
- class cdf_stack_t : private std::stack<T> {
+ class cdf_stack_t : private std::stack<T> { // cppcheck-suppress noConstructor
T default_value;
const T& top() const { return std::stack<T>::top(); }
bool empty() const { return std::stack<T>::empty(); }
public:
void value( const T& value ) {
- T& output( empty()? default_value : std::stack<T>::top() );
+ T& output( empty()? default_value : std::stack<T>::top() ); // cppcheck-suppress constVariableReference
output = value;
dbgmsg("cdf_directives_t::%s: %s", __func__, str(output).c_str());
}
}
void pop() {
if( empty() ) {
- error_msg(YYLTYPE(), "CDF stack empty");
+ error_msg(YYLTYPE(), "CDF stack empty"); // cppcheck-suppress syntaxError
return;
}
default_value = top();
static std::string str(cbl_enabled_exceptions_t) {
return "<enabled_exceptions>";
}
-
};
public:
cdf_directives_t() {
call_convention.value() = cbl_call_cobol_e;
}
-
+
void push() {
call_convention.push();
cobol_words.push();
// 8 or more, we need do no further testing because we assume
// everything fits.
if( data.capacity < 8 ) {
- const auto p = strchr(data.initial, symbol_decimal_point());
+ const char *p = strchr(data.initial, symbol_decimal_point());
if( p && atoll(p+1) != 0 ) {
error_msg(loc, "integer type %s VALUE '%s' "
"requires integer VALUE",
pdim++;
return ! occurs.subscript_ok(r.field);
} );
- isub = psub - r.subscripts.begin();
+ isub = psub - r.subscripts.begin();
return psub == r.subscripts.end()? NULL : dims[isub];
}
const char *
cbl_refer_t::str() const {
- static char subscripts[64];
- sprintf(subscripts, "(%u of " HOST_SIZE_T_PRINT_UNSIGNED " dimensions)",
+ static char subscripts_l[64];
+ sprintf(subscripts_l, "(%u of " HOST_SIZE_T_PRINT_UNSIGNED " dimensions)",
nsubscript(), (fmt_size_t)dimensions(field));
char *output = xasprintf("%s %s %s",
field? field_str(field) : "(none)",
- 0 < dimensions(field)? subscripts : "",
+ 0 < dimensions(field)? subscripts_l : "",
is_refmod_reference()? "(refmod)" : "" );
return output;
}
{ regex_t(), 'd', "^(" DATE_FMT_B "|" DATE_FMT_E ")$" },
{ regex_t(), 't', "^(" TIME_FMT_B "|" TIME_FMT_E ")$" },
};
- int erc, cflags = REG_EXTENDED | REG_ICASE, eflags=0;
+ int cflags = REG_EXTENDED | REG_ICASE, eflags=0;
regmatch_t m[5];
char result = 0;
if( ! compiled ) {
for( auto& fmt : fmts ) {
+ int erc;
if( (erc = regcomp(&fmt.reg, fmt.pattern, cflags)) != 0 ) {
char msg[80];
regerror(erc, &fmt.reg, msg, sizeof(msg));
friend void cobol_set_pp_option(int opt);
bool option_m;
std::set<std::string> all_names;
-
+
const char *
no_wd( const char *wd, const char *name ) {
int i;
public:
unique_stack() : option_m(false) {}
-
+
bool push( const value_type& value ) {
auto ok = std::none_of( c.cbegin(), c.cend(),
[value]( const auto& that ) {
const input_file_t& peek( size_t n ) const {
gcc_assert( n < size() );
return c.at(size() - ++n);
- }
-
+ }
+
void option( int opt ) { // capture other preprocessor options eventually
assert(opt == 'M');
option_m = true;
std::string input( top().name );
printf( "%s: ", input.c_str() );
for( const auto& name : all_names ) {
- if( name != input )
+ if( name != input )
printf( "\\\n\t%s ", name.c_str() );
}
printf("\n");
assert(opt == 'M');
input_filenames.option_m = true;
}
-
+
/*
* Maintain a stack of input filenames. Ensure the files are unique (by
* inode), to prevent copybook cycles. Before pushing a new name, Record the
* to enforce uniqueness, and the scanner to maintain line numbers.
*/
bool cobol_filename( const char *name, ino_t inode ) {
- const line_map *lines = NULL;
+ //const line_map *lines = NULL;
if( inode == 0 ) {
auto p = old_filenames.find(name);
if( p == old_filenames.end() ) {
}
cbl_errx( "logic error: missing inode for %s", name);
}
- inode = p->second;
- assert(inode != 0);
+ else {
+ inode = p->second;
+ assert(inode != 0);
+ }
}
linemap_add(line_table, LC_ENTER, sysp, name, 1);
input_filename_vestige = name;
input_filenames.pop();
if( input_filenames.empty() ) return;
- auto& input = input_filenames.top();
+ const auto& input = input_filenames.top();
linemap_add(line_table, LC_LEAVE, sysp, NULL, 0);
}
template <typename LOC>
static void
gcc_location_set_impl( const LOC& loc ) {
- // Set the position to the first line & column in the location.
+ // Set the position to the first line & column in the location.
token_location = linemap_line_start( line_table, loc.first_line, 80 );
token_location = linemap_position_for_column( line_table, loc.first_column);
location_dump(__func__, __LINE__, "parser", loc);
va_list ap;
va_start (ap, gmsgid);
rich_location richloc (line_table, token_location);
- bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_zero,
- gmsgid, &ap, DK_ERROR);
+ /*bool ret =*/ global_dc->diagnostic_impl (&richloc, nullptr, option_zero,
+ gmsgid, &ap, DK_ERROR);
va_end (ap);
}
auto_diagnostic_group d;
va_list ap;
va_start (ap, gmsgid);
- auto ret = emit_diagnostic_valist( DK_ERROR, token_location,
- option_zero, gmsgid, &ap );
+ /*auto ret = */emit_diagnostic_valist( DK_ERROR, token_location,
+ option_zero, gmsgid, &ap );
va_end (ap);
}
va_list ap;
va_start (ap, gmsgid);
rich_location richloc (line_table, token_location);
- bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_zero,
- gmsgid, &ap, DK_ERROR);
+ /*bool ret =*/ global_dc->diagnostic_impl ( &richloc,
+ nullptr,
+ option_zero,
+ gmsgid,
+ &ap, DK_ERROR);
va_end (ap);
global_dc->end_group();
}
va_end(ap);
}
-/*
- * analogs to err(3) and errx(3).
+/*
+ * analogs to err(3) and errx(3).
*/
#pragma GCC diagnostic push
"VOLATILE",
"XML",
"END-START",
-
+
// ISO 2023 keywords
"ACCEPT",
"ACCESS",