From 11afccd963ba93a4b537b524e59d5f7cf95fa8ae Mon Sep 17 00:00:00 2001 From: "James K. Lowden" <jklowden@symas.com> Date: Mon, 16 Dec 2024 18:07:15 -0500 Subject: [PATCH] rework ast_first_statement --- gcc/cobol/parse.y | 23 +++++++++++++---------- gcc/cobol/parse_ante.h | 29 ++++++++++++++++++----------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index ac9645efadc2..a1cdbc3c091f 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -2856,7 +2856,8 @@ level_name: LEVEL ctx_name YYERROR; } struct cbl_field_t field = { 0, - FldInvalid, FldInvalid, 0, 0, 0, $1, nonarray, yylineno, "", + FldInvalid, FldInvalid, 0, 0, 0, capacity_cast($1), + nonarray, yylineno, "", 0, cbl_field_t::linkage_t(), { 0,0,0,0, NULL, NULL, { NULL }, { NULL } }, NULL }; if( !namcpy(field.name, $2) ) YYERROR; @@ -2880,7 +2881,8 @@ level_name: LEVEL ctx_name YYERROR; } struct cbl_field_t field = { 0, - FldInvalid, FldInvalid, 0, 0, 0, $1, nonarray, yylineno, "", + FldInvalid, FldInvalid, 0, 0, 0, capacity_cast($1), + nonarray, yylineno, "", 0, {}, { 0,0,0,0, NULL, NULL, { NULL }, { NULL } }, NULL }; $$ = field_add(&field); @@ -2913,8 +2915,9 @@ const_value: cce_expr value78: literalism { - cbl_field_data_t data = { .capacity = strlen($1.data), - .initial = $1.data }; + cbl_field_data_t + data = { .capacity = capacity_cast(strlen($1.data)), + .initial = $1.data }; $$ = new cbl_field_data_t(data); } | const_value @@ -4321,10 +4324,7 @@ sentences: sentence { ast_first_statement(@1.first_line); symbol_temporaries_free(); } - | section_name { - location_set(@1); - ast_first_statement(@1.first_line); - } + | section_name | paragraph_name[para] '.' { location_set(@para); @@ -4332,12 +4332,15 @@ sentences: sentence { if( !label ) { YYERROR; } - ast_first_statement(@1.first_line); ast_enter_paragraph(label); current.new_paragraph(label); apply_declaratives(); } - | sentences sentence { symbol_temporaries_free(); } + | sentences sentence + { // sentences might not be sentence + ast_first_statement(@2.first_line); + symbol_temporaries_free(); + } | sentences section_name | sentences paragraph_name[para] '.' { diff --git a/gcc/cobol/parse_ante.h b/gcc/cobol/parse_ante.h index 351fac44810e..f7fce3fe07b8 100644 --- a/gcc/cobol/parse_ante.h +++ b/gcc/cobol/parse_ante.h @@ -158,20 +158,27 @@ yyerrorvl( int line, const char *filename, const char fmt[], ... ) { va_end(ap); } +static uint32_t +capacity_cast( size_t size ) { + uint32_t len = static_cast<uint32_t>(size); + assert(len == size); + return len; +} + const char * consistent_encoding_check( const char input[] ) { - cbl_field_t faux = { - .type = FldAlphanumeric, - .data = { .capacity = strlen(input), .initial = input } - }; + cbl_field_t faux = { + .type = FldAlphanumeric, + .data = { .capacity = capacity_cast(strlen(input)), .initial = input } + }; - auto s = faux.internalize(); - if( !s ) { - yyerrorv("inconsistent string literal encoding for '%s'", input); - } else { - if( s != input ) return s; - } - return NULL; + auto s = faux.internalize(); + if( !s ) { + yyerrorv("inconsistent string literal encoding for '%s'", input); + } else { + if( s != input ) return s; + } + return NULL; } class external_message { -- GitLab