Skip to content

Commit

Permalink
add prefix character to message number for C and C++ compilers
Browse files Browse the repository at this point in the history
'C' prefix character is used for C compiler messages
'P' prefix character is used for C++ compiler messages
Each compiler ignores messages for the other compiler
  • Loading branch information
jmalak committed Dec 13, 2023
1 parent 35dba55 commit 57dee74
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 26 deletions.
26 changes: 22 additions & 4 deletions bld/cc/c/coptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1305,8 +1305,26 @@ static void Set_WO( void ) { CompFlags.using_overlays = true; }
static void Set_WPX( void ) { Check_global_prototype = true; }
static void Set_WX( void ) { WngLevel = WLEVEL_WX; }
static void SetWarningLevel( void ) { WngLevel = OptValue; if( WngLevel > WLEVEL_MAX ) WngLevel = WLEVEL_MAX; }
static void Set_WCD( void ) { WarnEnableDisable( false, OptValue ); }
static void Set_WCE( void ) { WarnEnableDisable( true, OptValue ); }
static void Set_WCD( void )
{
char *p;
unsigned num;

p = CopyOfParm();
GetMsgNum( p, &num );
CMemFree( p );
WarnEnableDisable( false, num );
}
static void Set_WCE( void )
{
char *p;
unsigned num;

p = CopyOfParm();
GetMsgNum( p, &num );
CMemFree( p );
WarnEnableDisable( true, num );
}

#if _CPU == 386
static void Set_XGV( void ) { TargetSwitches |= CGSW_X86_INDEXED_GLOBALS; }
Expand Down Expand Up @@ -1798,8 +1816,8 @@ static struct option const CFE_Options[] = {
{ "tp=$", 0, Set_TP },
{ "u$", 0, Set_U },
{ "v", 0, Set_V },
{ "wcd=#", 0, Set_WCD },
{ "wce=#", 0, Set_WCE },
{ "wcd=$", 0, Set_WCD },
{ "wce=$", 0, Set_WCE },
{ "we", 0, Set_WE },
{ "wo", 0, Set_WO },
{ "wpx", 0, Set_WPX },
Expand Down
52 changes: 46 additions & 6 deletions bld/cc/c/cpragma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,13 +1034,51 @@ static void changeStatus( bool enabled, int msg_index )
}
}

bool GetMsgNum( const char *str, msg_codes *val )
/***********************************************/
{
/*
* skip, C++ compiler messages, prefixed by 'P' character
*/
if( tolower( *(unsigned char *)str ) == 'p' ) {
*val = 0;
return( true );
}
/*
* process C compiler messages, prefixed by 'C' character
* or old messages without prefix which can be C or C++ message
* it is for backward compatibility
*/
if( tolower( *(unsigned char *)str ) == 'c' )
str++;
if( isdigit( *(unsigned char *)str ) ) {
*val = atol( str );
return( true );
}
return( false );
}

static bool getMessageNum( msg_codes *val )
/*****************************************/
{
if( CurToken == T_CONSTANT ) {
*val = Constant;
return( true );
} else if( CurToken == T_ID ) {
return( GetMsgNum( Buffer, val ) );
}
return( false );
}

static void warnChangeLevel( unsigned level, msg_codes msgnum )
/**************************************************************
* CHANGE WARNING LEVEL FOR A MESSAGE
*/
{
unsigned msg_index;

if( msgnum == 0 )
return;
msg_index = GetMsgIndex( msgnum );
if( IS_MSGIDX_INVALID( msg_index ) ) {
CWarn2( ERR_PRAG_WARNING_BAD_MESSAGE, msgnum );
Expand Down Expand Up @@ -1085,6 +1123,8 @@ void WarnEnableDisable( bool enabled, msg_codes msgnum )
{
unsigned msg_index;

if( msgnum == 0 )
return;
msg_index = GetMsgIndex( msgnum );
if( IS_MSGIDX_INVALID( msg_index ) ) {
CWarn2( ERR_PRAG_WARNING_BAD_MESSAGE, msgnum );
Expand Down Expand Up @@ -1116,7 +1156,7 @@ static bool pragWarning( void )
* "level==0" implies warning will be treated as an error
*/
{
unsigned msgnum; // - message number
msg_codes msgnum; // - message number
unsigned level; // - new level
bool change_all; // - true ==> change all levels
bool ignore;
Expand All @@ -1128,9 +1168,7 @@ static bool pragWarning( void )
NextToken();
if( CurToken == T_TIMES ) {
change_all = true;
} else if( CurToken == T_CONSTANT ) {
msgnum = Constant;
} else {
} else if( !getMessageNum( &msgnum ) ) {
/*
* ignore; MS or other vendor's #pragma
*/
Expand Down Expand Up @@ -1165,12 +1203,14 @@ static void pragEnableDisableMessage( bool enabled )
* disable/enable display of selected message number
*/
{
msg_codes msgnum;

PPCTL_ENABLE_MACROS();
PPNextToken();
if( ExpectingToken( T_LEFT_PAREN ) ) {
PPNextToken();
while( CurToken == T_CONSTANT ) {
WarnEnableDisable( enabled, Constant );
while( getMessageNum( &msgnum ) ) {
WarnEnableDisable( enabled, msgnum );
PPNextToken();
if( CurToken == T_COMMA ) {
PPNextToken();
Expand Down
8 changes: 6 additions & 2 deletions bld/cc/gml/options.gml
Original file line number Diff line number Diff line change
Expand Up @@ -993,16 +993,20 @@
:usage. set warning level number
:jusage. 警告レベル番号を設定します

:cmt.
:cmt. wcd and wce uses list of values which are 'C' prefix and a C compiler
:cmt. message number without any prefix
:cmt.
:option. wcd
:target. any
:number.
:id.
:multiple.
:usage. disable warning message <num>
:jusage. 警告制御: 警告メッセージ<num>を禁止します

:option. wce
:target. any
:number.
:id.
:multiple.
:usage. enable warning message <num>
:jusage. 警告制御: 警告メッセージ <num> の表示をします
Expand Down
1 change: 1 addition & 0 deletions bld/cc/h/cvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ extern void CreateAux( const char * );
extern void CreateAuxInlineFunc( bool too_many_bytes );
extern void SetCurrInfo( const char * );
extern void XferPragInfo( const char *, const char * );
extern bool GetMsgNum( const char *str, msg_codes *val );
extern void WarnEnableDisable( bool enabled, msg_codes msgnum );
extern void AddLibraryName( const char *, char );
extern void AddExtRefN( const char * );
Expand Down
24 changes: 16 additions & 8 deletions bld/plusplus/c/cmdlnany.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,20 @@ static bool debugOptionAfterOptOption( OPT_STORAGE *data )
return( false );
}

static void setMessageStatus( OPT_STRING *s, bool state )
{
unsigned num;

while( s != NULL ) {
if( GetMsgNum( s->data, &num ) ) {
WarnEnableDisable( state, num );
} else {
CErr2( ERR_PRAG_WARNING_BAD_MESSAGE, 0 );
}
s = s->next;
}
}

static void analyseAnyTargetOptions( OPT_STORAGE *data )
{
// quickly do the quiet option so the banner can be printed
Expand Down Expand Up @@ -1022,16 +1036,10 @@ static void analyseAnyTargetOptions( OPT_STORAGE *data )
CompFlags.dump_prototypes = true;
}
if( data->wcd ) {
OPT_NUMBER *n;
for( n = data->wcd_value; n != NULL; n = n->next ) {
WarnEnableDisable( false, n->number );
}
setMessageStatus( data->wcd_value, false );
}
if( data->wce ) {
OPT_NUMBER *n;
for( n = data->wce_value; n != NULL; n = n->next ) {
WarnEnableDisable( true, n->number );
}
setMessageStatus( data->wce_value, true );
}
if( data->we ) {
CompFlags.warnings_cause_bad_exit = true;
Expand Down
55 changes: 53 additions & 2 deletions bld/plusplus/c/cpragma.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,57 @@ static void fini // MODULE COMPLETION

INITDEFN( pragma_extref, init, fini );

bool GetMsgNum( const char *str, unsigned *val )
{
if( tolower( *(unsigned char *)str ) == 'c' ) {
/*
* skip C compiler messages, prefixed by 'C' character
*/
*val = 0;
return( true );
}
/*
* process C++ compiler messages, prefixed by 'P' character
* or old messages, may be C or C+++ message
*/
if( tolower( *(unsigned char *)str ) == 'p' )
str++;
if( isdigit( *(unsigned char *)str ) ) {
*val = atol( str );
return( true );
}
return( false );
}

static bool getMessageNum( unsigned *val )
{
if( CurToken == T_CONSTANT ) {
*val = U32Fetch( Constant64 );
return( true );
} else if( CurToken == T_ID ) {
return( GetMsgNum( Buffer, val ) );
}
return( false );
}

static bool grabMessageNum( unsigned *val )
{
if( getMessageNum( val ) ) {
NextToken();
return( true );
}
if( CurToken == T_LEFT_PAREN ) {
NextToken();
if( getMessageNum( val ) ) {
NextToken();
MustRecog( T_RIGHT_PAREN );
return( true );
}
}
NextToken();
return( false );
}

static bool grabNum( unsigned *val )
{
if( CurToken == T_CONSTANT ) {
Expand Down Expand Up @@ -513,7 +564,7 @@ static void pragEnableMessage( // ENABLE WARNING MESSAGE
NextToken();
MustRecog( T_LEFT_PAREN );
for( ;; ) {
if( !grabNum( &msgnum ) ) {
if( !grabMessageNum( &msgnum ) ) {
CErr1( ERR_PRAG_ENABLE_MESSAGE );
error_occurred = true;
}
Expand Down Expand Up @@ -548,7 +599,7 @@ static void pragDisableMessage( // DISABLE WARNING MESSAGE
NextToken();
MustRecog( T_LEFT_PAREN );
for( ;; ) {
if( !grabNum( &msgnum ) ) {
if( !grabMessageNum( &msgnum ) ) {
CErr1( ERR_PRAG_DISABLE_MESSAGE );
error_occurred = true;
}
Expand Down
6 changes: 5 additions & 1 deletion bld/plusplus/c/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved.
* Copyright (c) 2002-2023 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -879,6 +879,8 @@ void WarnEnableDisable( // ENABLE/DISABLE A MESSAGE
bool enabled, // - new status
MSG_NUM msgnum ) // - message number
{
if( msgnum == 0 )
return;
if( msgnum >= ARRAY_SIZE( msg_level ) ) {
CErr2( ERR_PRAG_WARNING_BAD_MESSAGE, msgnum );
return;
Expand All @@ -901,6 +903,8 @@ void WarnChangeLevel( // CHANGE WARNING LEVEL FOR A MESSAGE
unsigned level, // - new level
MSG_NUM msgnum ) // - message number
{
if( msgnum == 0 )
return;
if( msgnum >= ARRAY_SIZE( msg_level ) ) {
CErr2( ERR_PRAG_WARNING_BAD_MESSAGE, msgnum );
return;
Expand Down
8 changes: 6 additions & 2 deletions bld/plusplus/gml/options.gml
Original file line number Diff line number Diff line change
Expand Up @@ -1079,16 +1079,20 @@
:usage. set warning level number
:jusage. 警告レベル番号を設定します

:cmt.
:cmt. wcd and wce uses list of values which are 'P' prefix and C++ compiler
:cmt. message number without any prefix
:cmt.
:option. wcd
:target. any
:number.
:id.
:multiple.
:usage. disable warning message <num>
:jusage. 警告制御: 警告メッセージ<num>を禁止します

:option. wce
:target. any
:number.
:id.
:multiple.
:usage. enable warning message <num>
:jusage. 警告制御: 警告メッセージ <num> の表示をします
Expand Down
6 changes: 5 additions & 1 deletion bld/plusplus/h/pragdefn.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved.
* Copyright (c) 2002-2023 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -195,6 +195,10 @@ void AsmSysPCHWriteCode( // write code sequence to PCH
void AsmSysPCHReadCode( // read code sequence from PCH
AUX_INFO *info ) // - code sequence
;
bool GetMsgNum( // decode C++ message number from string
const char *str, // - input string
unsigned *val ) // - output message number
;
const char *SkipUnderscorePrefix(
const char *str )
;
Expand Down

0 comments on commit 57dee74

Please sign in to comment.