Skip to content

Commit

Permalink
cc: cleanup code
Browse files Browse the repository at this point in the history
remove useless macros
rename symbols to be more transparent
  • Loading branch information
jmalak committed Nov 8, 2024
1 parent 9254bfd commit fa7856a
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 56 deletions.
2 changes: 1 addition & 1 deletion bld/cc/c/cdecl1.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ static void CheckParms( void )
if( VarParm( CurFunc ) ) {
typ = ArrayNode( GetType( TYP_CHAR ) );
typ->u.array->dimension = 160;
sym_handle = GetNewSym( &var_parm, 'V', typ, SC_AUTO );
sym_handle = GetNewDotSym( &var_parm, 'V', typ, SC_AUTO );
SymReplace( &var_parm, sym_handle );
prev_parm->sym.handle = sym_handle;
}
Expand Down
8 changes: 4 additions & 4 deletions bld/cc/c/cdinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ static void *DesignatedInit( TYPEPTR typ, TYPEPTR ctyp, void *field )
static bool new_field = true;

if( !CompFlags.extensions_enabled
&& CHECK_STD( < , C99 ) ) {
&& ( CompVars.cstd < STD_C99 ) ) {
return( field );
}

Expand Down Expand Up @@ -1339,7 +1339,7 @@ static void AggregateVarDeclEquals( SYMPTR sym, SYM_HANDLE sym_handle )
SYM_HANDLE sym2_handle;
SYM_ENTRY sym2;

sym2_handle = MakeNewSym( &sym2, 'X', sym->sym_type, SC_STATIC );
sym2_handle = MakeNewDotSym( &sym2, 'X', sym->sym_type, SC_STATIC );
sym2.flags |= SYM_INITIALIZED;
CompFlags.initializing_data = true;
StaticInit( &sym2, sym2_handle );
Expand Down Expand Up @@ -1525,7 +1525,7 @@ static void InitArrayVar( SYMPTR sym, SYM_HANDLE sym_handle, TYPEPTR typ )
*/
NextToken();
if( CharArray( typ->object ) ) {
sym2_handle = MakeNewSym( &sym2, 'X', typ, SC_STATIC );
sym2_handle = MakeNewDotSym( &sym2, 'X', typ, SC_STATIC );
sym2.flags |= SYM_INITIALIZED;
if( sym2.u.var.segid == SEG_NULL ) {
SetFarHuge( &sym2, false );
Expand All @@ -1538,7 +1538,7 @@ static void InitArrayVar( SYMPTR sym, SYM_HANDLE sym_handle, TYPEPTR typ )
AssignAggregate( VarLeaf( sym, sym_handle ),
VarLeaf( &sym2, sym2_handle ), typ );
} else if( WCharArray( typ->object ) ) {
sym2_handle = MakeNewSym( &sym2, 'X', typ, SC_STATIC );
sym2_handle = MakeNewDotSym( &sym2, 'X', typ, SC_STATIC );
sym2.flags |= SYM_INITIALIZED;
if( sym2.u.var.segid == SEG_NULL ) {
SetFarHuge( &sym2, false );
Expand Down
2 changes: 1 addition & 1 deletion bld/cc/c/cenum.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ TYPEPTR EnumDecl( type_modifiers flags )
U64Add( &n, &Inc, &n );
MustRecog( T_COMMA );
if( !CompFlags.extensions_enabled
&& CHECK_STD( < , C99 )
&& ( CompVars.cstd < STD_C99 )
&& ( CurToken == T_RIGHT_BRACE )) {
ExpectIdentifier();
}
Expand Down
4 changes: 2 additions & 2 deletions bld/cc/c/cexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2358,7 +2358,7 @@ static TREEPTR DummyFuncName( void )
SYM_ENTRY sym;

typ = FuncNode( GetType( TYP_INT ), FLAG_NONE, NULL );
sym_handle = MakeNewSym( &sym, 'F', typ, SC_AUTO );
sym_handle = MakeNewDotSym( &sym, 'F', typ, SC_AUTO );
sym.flags |= SYM_FUNCTION;
sym.mods = FLAG_NONE;
SymReplace( &sym, sym_handle );
Expand Down Expand Up @@ -2415,7 +2415,7 @@ static TREEPTR StartFunc( TREEPTR tree, TYPEPTR **plistptr )
if( tree->op.opr == OPR_POINTS ) { /* need to recover decl flags */
decl_flags = typ->u.fn.decl_flags;
}
sym_handle = MakeNewSym( &sym, 'F', orig_typ, SC_AUTO );
sym_handle = MakeNewDotSym( &sym, 'F', orig_typ, SC_AUTO );
sym.flags |= SYM_FUNCTION;
sym.mods = decl_flags;
SymReplace( &sym, sym_handle );
Expand Down
2 changes: 1 addition & 1 deletion bld/cc/c/cmac1.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ TOKEN SpecialMacro( MEPTR mentry )
ConstType = TYP_INT;
return( T_CONSTANT );
case MACRO_STDC_VERSION:
if( CHECK_STD( < , C99 ) ) {
if( CompVars.cstd < STD_C99 ) {
WriteBufferString( "199409L" );
Constant = 199409;
} else {
Expand Down
3 changes: 2 additions & 1 deletion bld/cc/c/cmac2.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,8 @@ static void CError( void )

static void CWarning( void )
{
if( CompFlags.extensions_enabled || CHECK_STD( >= , C23 ) ) {
if( CompFlags.extensions_enabled
|| ( CompVars.cstd >= STD_C23 ) ) {
get_arg_message();
/*
* Force #error output to be reported, even with preprocessor
Expand Down
4 changes: 2 additions & 2 deletions bld/cc/c/cmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2002-2023 The Open Watcom Contributors. All Rights Reserved.
* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -292,7 +292,7 @@ void InitModInfo( void )
WngLevel = WLEVEL_DEFAULT;

PreProcChar = '#';
SET_STD( C89 );
CompVars.cstd = STD_C89;

CompFlags.check_syntax = false;
CompFlags.signed_char = false;
Expand Down
2 changes: 1 addition & 1 deletion bld/cc/c/coptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ static void AnalyseAnyTargetOptions( OPT_STORAGE *data )
}
switch( data->cstd ) {
case OPT_ENUM_cstd_za99:
SET_STD( C99 );
CompVars.cstd = STD_C99;
break;
case OPT_ENUM_cstd_zastd:
if( data->zastd_value != STD_NONE )
Expand Down
7 changes: 4 additions & 3 deletions bld/cc/c/cscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ TOKEN KwLookup( const char *buf, size_t len )
/*
* look up id in keyword table
*/
if( CHECK_STD( < , C99 ) ) {
if( CompVars.cstd < STD_C99 ) {
switch( token ) {
case T__BOOL:
case T_INLINE:
Expand Down Expand Up @@ -460,7 +460,8 @@ static TOKEN doScanPPNumber( void )
|| c == '.' ) {
WriteBufferChar( c );
} else if( ( prevc == 'e' || prevc == 'E'
|| CHECK_STD( > , C89 ) && ( prevc == 'p' || prevc == 'P' ) )
|| ( CompVars.cstd > STD_C89 )
&& ( prevc == 'p' || prevc == 'P' ) )
&& ( c == '+' || c == '-' ) ) {
WriteBufferChar( c );
if( CompFlags.extensions_enabled ) {
Expand Down Expand Up @@ -678,7 +679,7 @@ static TOKEN doScanNum( void )
c = WriteBufferCharNextChar( c );
}

if( CHECK_STD( > , C89 ) ) {
if( CompVars.cstd > STD_C89 ) {
if( c == '.'
|| c == 'p'
|| c == 'P' ) {
Expand Down
18 changes: 9 additions & 9 deletions bld/cc/c/cstmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ static SYM_HANDLE GetLocalVarDecls( void )
if( symlist != SYM_NULL ) {
symhandle = CurFunc->u.func.locals;
/*
* symhandle will be non-zero if MakeNewSym was called while
* symhandle will be non-zero if MakeNewDotSym was called while
* parsing the declaration list.
*/
if( symhandle != SYM_NULL ) { // if some temporaries were created
Expand Down Expand Up @@ -703,11 +703,11 @@ static void ForStmt( void )

NextToken();
MustRecog( T_LEFT_PAREN );
if( CHECK_STD( > , C89 ) ) {
if( CompVars.cstd > STD_C99 ) {
PushBlock(); // 'for' opens new scope
}
if( CurToken != T_SEMI_COLON ) {
if( CHECK_STD( > , C89 ) ) {
if( CompVars.cstd > STD_C89 ) {
TREEPTR tree;

tree = LeafNode( OPR_NEWBLOCK );
Expand Down Expand Up @@ -897,7 +897,7 @@ static SYM_HANDLE DummyTrySymbol( void )
SYM_ENTRY sym;
SYM_HANDLE sym_handle;

sym_handle = MakeNewSym( &sym, 'T', GetType( TYP_VOID ), SC_STATIC );
sym_handle = MakeNewDotSym( &sym, 'T', GetType( TYP_VOID ), SC_STATIC );
SymReplace( &sym, sym_handle );
return( sym_handle );
}
Expand Down Expand Up @@ -1092,7 +1092,7 @@ static void EndOfStmt( void )
EndForStmt();
--LoopDepth;
DropBreakLabel();
if( CHECK_STD( > , C89 ) ) {
if( CompVars.cstd > STD_C89 ) {
EndBlock(); /* Terminate the scope introduced by 'for' */
PopBlock();
}
Expand Down Expand Up @@ -1252,15 +1252,15 @@ void Statement( void )
if( GrabLabels() == 0 ) {
GetLocalVarDecls();
}
func_result_handle = MakeNewSym( &sym, 'R', CurFunc->sym_type->object, SC_AUTO );
func_result_handle = MakeNewDotSym( &sym, 'R', CurFunc->sym_type->object, SC_AUTO );
sym.flags |= SYM_FUNC_RETURN_VAR;
SymReplace( &sym, func_result_handle );
for( ;; ) {
CompFlags.pending_dead_code = false;
if( GrabLabels() == 0 && declaration_allowed && IsDeclarator( CurToken ) ) {
GetLocalVarDecls();
}
if( CHECK_STD( > , C89 ) ) {
if( CompVars.cstd > STD_C89 ) {
declaration_allowed = true;
}
skip_to_next_token = false;
Expand Down Expand Up @@ -1405,7 +1405,7 @@ void Statement( void )
case T_DOUBLE:
case T_SIGNED:
case T_UNSIGNED:
if( CHECK_STD( < , C99 ) ) {
if( CompVars.cstd < STD_C99 ) {
CErr1( ERR_MISSING_RIGHT_BRACE );
} else {
CErr1( ERR_UNEXPECTED_DECLARATION );
Expand Down Expand Up @@ -1440,7 +1440,7 @@ void Statement( void )
}
}
/* C99 has special semantics for return value of main() */
if( CHECK_STD( > , C89 ) && strcmp( CurFunc->name, "main" ) == 0 ) {
if( ( CompVars.cstd > STD_C89 ) && strcmp( CurFunc->name, "main" ) == 0 ) {
if( !return_at_outer_level ) {
FixupC99MainReturn( func_result_handle, &return_info );
return_at_outer_level = true;
Expand Down
6 changes: 3 additions & 3 deletions bld/cc/c/csym.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ SYM_HANDLE SymAddL0( id_hash_idx hash, SYMPTR new_sym )
}


static SYM_HANDLE GetNewSym( SYMPTR sym, char id, TYPEPTR typ, stg_classes stg_class )
static SYM_HANDLE GetNewDotSym( SYMPTR sym, char id, TYPEPTR typ, stg_classes stg_class )
{
char name[3];
SYM_HANDLE sym_handle;
Expand All @@ -513,11 +513,11 @@ static SYM_HANDLE GetNewSym( SYMPTR sym, char id, TYPEPTR typ, stg_classes stg_c
}


SYM_HANDLE MakeNewSym( SYMPTR sym, char id, TYPEPTR typ, stg_classes stg_class )
SYM_HANDLE MakeNewDotSym( SYMPTR sym, char id, TYPEPTR typ, stg_classes stg_class )
{
SYM_HANDLE sym_handle;

sym_handle = GetNewSym( sym, id, typ, stg_class );
sym_handle = GetNewDotSym( sym, id, typ, stg_class );
if( SymLevel != 0 ) {
sym->handle = CurFunc->u.func.locals;
CurFunc->u.func.locals = sym_handle;
Expand Down
6 changes: 4 additions & 2 deletions bld/cc/c/ctype.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ type_modifiers TypeQualifier( void )
default:
return( flags );
}
if( (flags & bit) && CHECK_STD( < , C99 ) )
if( (flags & bit)
&& ( CompVars.cstd < STD_C99 ) )
CErr1( ERR_REPEATED_MODIFIER );
flags |= bit;
NextToken();
Expand Down Expand Up @@ -1353,7 +1354,8 @@ static void CheckBitfieldType( TYPEPTR typ )
}
switch( typ->decl_type ) {
case TYP_BOOL:
if( !CompFlags.extensions_enabled && CHECK_STD( < , C99 ) ) {
if( !CompFlags.extensions_enabled
&& ( CompVars.cstd < STD_C99 ) ) {
break;
}
/* fall through */
Expand Down
Loading

0 comments on commit fa7856a

Please sign in to comment.