parse.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,171 行 · 第 1/2 页
C
1,171 行
*/
static void handle_F( OPT_STORAGE *cmdOpts, int x )
/*************************************************/
{
static int hasBeenCalled;
OPT_STRING * p;
x = x;
if( hasBeenCalled ) {
Warning( "Overriding /F%s with /F%s", cmdOpts->F_value->data,
cmdOpts->F_value->next->data );
p = cmdOpts->F_value->next;
FreeMem( cmdOpts->F_value );
cmdOpts->F_value = p;
} else {
hasBeenCalled = 1;
}
}
/*
* Warn when the previous /Fe value is overridden.
*/
static void handle_Fe( OPT_STORAGE *cmdOpts, int x )
/**************************************************/
{
static int hasBeenCalled;
OPT_STRING * p;
x = x;
if( hasBeenCalled ) {
Warning( "Overriding /Fe%s with /Fe%s", cmdOpts->Fe_value->data,
cmdOpts->Fe_value->next->data );
p = cmdOpts->Fe_value->next;
FreeMem( cmdOpts->Fe_value );
cmdOpts->Fe_value = p;
} else {
hasBeenCalled = 1;
}
}
/*
* Warn when the previous /Fp value is overridden.
*/
static void handle_Fp( OPT_STORAGE *cmdOpts, int x )
/**************************************************/
{
static int hasBeenCalled;
OPT_STRING * p;
x = x;
if( hasBeenCalled ) {
Warning( "Overriding /Fp%s with /Fp%s", cmdOpts->Fp_value->data,
cmdOpts->Fp_value->next->data );
p = cmdOpts->Fp_value->next;
FreeMem( cmdOpts->Fp_value );
cmdOpts->Fp_value = p;
} else {
hasBeenCalled = 1;
}
}
/*
* Warn when the previous /FR value is overridden.
*/
static void handle_FR( OPT_STORAGE *cmdOpts, int x )
/**************************************************/
{
static int hasBeenCalled;
OPT_STRING * p;
x = x;
if( hasBeenCalled ) {
Warning( "Overriding /FR%s with /FR%s", cmdOpts->FR_value->data,
cmdOpts->FR_value->next->data );
p = cmdOpts->FR_value->next;
FreeMem( cmdOpts->FR_value );
cmdOpts->FR_value = p;
} else {
Warning( "Browsing information will be output to .mbr file(s)" );
hasBeenCalled = 1;
}
}
/*
* Suppress warning messages.
*/
static void handle_nowwarn( OPT_STORAGE *cmdOpts, int x )
/*******************************************************/
{
x = x;
cmdOpts = cmdOpts;
DisableWarnings( 1 );
}
/*
* Warn when one of /Ob0, /Ob1, and /Ob2 overrides another.
*/
static void handle_inlining_level( OPT_STORAGE *cmdOpts, int x )
/**************************************************************/
{
static int hasBeenCalled;
static int prevValue;
x = x;
if( hasBeenCalled ) {
if( prevValue != cmdOpts->Ob_value ) {
Warning( "Overriding /Ob%d with /Ob%d", prevValue,
cmdOpts->Ob_value );
}
} else {
hasBeenCalled = 1;
}
prevValue = cmdOpts->Ob_value;
}
/*
* Warn when one of /O1, /O2, and /Ox overrides another. Note that, for
* MS compatability, no warning is issued when one of /O2 and /Ox overrides
* the other.
*/
static void handle_opt_level( OPT_STORAGE *cmdOpts, int x )
/*********************************************************/
{
static int hasBeenCalled;
static int prevValue;
x = x;
if( hasBeenCalled ) {
if( prevValue == OPT_opt_level_O1 ) {
if( cmdOpts->opt_level == OPT_opt_level_O2 ) {
Warning( "Overriding /O1 with /O2" );
} else if( cmdOpts->opt_level == OPT_opt_level_Ox ) {
Warning( "Overriding /O1 with /Ox" );
}
} else if( prevValue == OPT_opt_level_O2 ) {
if( cmdOpts->opt_level == OPT_opt_level_O1 ) {
Warning( "Overriding /O2 with /O1" );
}
} else if( prevValue == OPT_opt_level_Ox ) {
if( cmdOpts->opt_level == OPT_opt_level_O1 ) {
Warning( "Overriding /Ox with /O1" );
}
} else if( prevValue == OPT_opt_level_Od ) {
if( cmdOpts->opt_level == OPT_opt_level_O1 ) {
Warning( "Overriding /Od with /O1" );
} else if( cmdOpts->opt_level == OPT_opt_level_O2 ) {
Warning( "Overriding /Od with /O2" );
} else if( cmdOpts->opt_level == OPT_opt_level_Ox ) {
Warning( "Overriding /Od with /Ox" );
}
}
} else {
hasBeenCalled = 1;
}
prevValue = cmdOpts->opt_level;
}
/*
* Warn when one of /Os and /Ot overrides the other.
*/
static void handle_opt_size_time( OPT_STORAGE *cmdOpts, int x )
/*************************************************************/
{
static int hasBeenCalled;
static int prevValue;
x = x;
if( hasBeenCalled ) {
if( prevValue == OPT_opt_size_time_Os ) {
if( cmdOpts->opt_size_time == OPT_opt_size_time_Ot ) {
Warning( "Overriding /Os with /Ot" );
}
} else if( prevValue == OPT_opt_size_time_Ot ) {
if( cmdOpts->opt_size_time == OPT_opt_size_time_Os ) {
Warning( "Overriding /Ot with /Os" );
}
}
} else {
hasBeenCalled = 1;
}
prevValue = cmdOpts->opt_size_time;
}
/*
* Warn when one of /Ge and /Gs overrides the other.
*/
static void handle_stack_probes( OPT_STORAGE *cmdOpts, int x )
/************************************************************/
{
static int hasBeenCalled;
static int prevValue;
x = x;
if( cmdOpts->Gs_value != NULL ) {
Warning( "Ignoring unsupported parameter '%s' to /Gs",
cmdOpts->Gs_value->data );
OPT_CLEAN_STRING( &(cmdOpts->Gs_value) );
}
if( hasBeenCalled ) {
if( prevValue == OPT_stack_probes_Ge ) {
if( cmdOpts->stack_probes == OPT_stack_probes_Gs ) {
Warning( "Overriding /Ge with /Gs" );
}
} else if( prevValue == OPT_stack_probes_Gs ) {
if( cmdOpts->stack_probes == OPT_stack_probes_Ge ) {
Warning( "Overriding /Gs with /Ge" );
}
}
} else {
hasBeenCalled = 1;
}
prevValue = cmdOpts->stack_probes;
}
/*
* Warn when one of /MD, /ML, and /MT overrides another.
*/
static void handle_threads_linking( OPT_STORAGE *cmdOpts, int x )
/***************************************************************/
{
static int hasBeenCalled;
static int prevValue;
char oldType, newType;
x = x;
if( hasBeenCalled ) {
if( prevValue != cmdOpts->threads_linking ) {
switch( prevValue ) { /* what's the old type? */
case OPT_threads_linking_MD:
oldType = 'D';
break;
case OPT_threads_linking_ML:
oldType = 'L';
break;
case OPT_threads_linking_MT:
oldType = 'T';
break;
default:
Zoinks();
}
switch( cmdOpts->threads_linking ) { /* what's the new type? */
case OPT_threads_linking_MD:
newType = 'D';
break;
case OPT_threads_linking_ML:
newType = 'L';
break;
case OPT_threads_linking_MT:
newType = 'T';
break;
default:
Zoinks();
}
Warning( "Overriding /M%c with /M%c", oldType, newType );
}
} else {
hasBeenCalled = 1;
}
prevValue = cmdOpts->threads_linking;
}
/*
* Warn when one of /w and /W overrides the other.
*/
static void handle_warn_level( OPT_STORAGE *cmdOpts, int x )
/**********************************************************/
{
static int hasBeenCalled;
static int prevType;
static int prevLevel;
x = x;
if( hasBeenCalled ) {
if( prevType == OPT_warn_level_w ) {
if( cmdOpts->warn_level == OPT_warn_level_W ) {
if( cmdOpts->W_value != 0 ) {
Warning( "Overriding /w with /W%d", cmdOpts->W_value );
}
}
} else if( prevType == OPT_warn_level_W ) {
if( cmdOpts->warn_level == OPT_warn_level_w ) {
if( prevLevel != 0 ) {
Warning( "Overriding /W%d with /w", prevLevel );
}
} else if( cmdOpts->warn_level == OPT_warn_level_W ) {
if( cmdOpts->W_value != prevLevel ) {
Warning( "Overriding /W%d with /W%d", prevLevel,
cmdOpts->W_value );
}
}
}
} else {
hasBeenCalled = 1;
}
prevType = cmdOpts->warn_level;
if( prevType == OPT_warn_level_W ) {
prevLevel = cmdOpts->W_value;
} else {
prevLevel = 0;
}
}
/*
* Ensure that /Yc has no filename parameter.
*/
static void handle_precomp_headers( OPT_STORAGE *cmdOpts, int x )
/***************************************************************/
{
x = x;
if( cmdOpts->precomp_headers == OPT_precomp_headers_Yc ) {
if( cmdOpts->Yc_value != NULL ) {
Warning( "Ignoring unsupported parameter '%s' to /Yc",
cmdOpts->Yc_value->data );
OPT_CLEAN_STRING( &(cmdOpts->Yc_value) );
}
} else if( cmdOpts->precomp_headers == OPT_precomp_headers_Yu ) {
if( cmdOpts->Yu_value != NULL ) {
Warning( "Ignoring unsupported parameter '%s' to /Yu",
cmdOpts->Yu_value->data );
OPT_CLEAN_STRING( &(cmdOpts->Yu_value) );
}
} else if( cmdOpts->precomp_headers == OPT_precomp_headers_YX ) {
if( cmdOpts->YX_value != NULL ) {
Warning( "Ignoring unsupported parameter '%s' to /YX",
cmdOpts->YX_value->data );
OPT_CLEAN_STRING( &(cmdOpts->YX_value) );
}
}
}
/*
* Handle options which can be either /option- to disable or /option to
* enable. Option-specific information is passed as parameters. Returns
* non-zero if the option should be enabled or zero if it should be disabled.
*/
static int handle_on_off_option( int *hasBeenCalled, char *optName, int isOn )
/****************************************************************************/
{
int rc = isOn;
if( *hasBeenCalled ) {
/*** Warn when one of /option and /option- overrides the other ***/
if( isOn ) {
if( GetCharContext() == '-' ) {
Warning( "Overriding /%s with /%s-", optName, optName );
rc = 0;
} else {
UngetCharContext();
}
} else {
if( GetCharContext() != '-' ) {
Warning( "Overriding /%s- with /%s", optName, optName );
rc = 1;
} else {
UngetCharContext();
}
}
} else {
/*** Handle /option- for the first time ***/
*hasBeenCalled = 1;
if( GetCharContext() == '-' ) {
rc = 0;
} else {
UngetCharContext();
}
}
return( rc );
}
/*
* Parse the /GX and /GX- options.
*/
static void handle_GX( OPT_STORAGE *cmdOpts, int x )
/**************************************************/
{
static int hasBeenCalled;
x = x;
if( handle_on_off_option( &hasBeenCalled, "GX", cmdOpts->GX ) ) {
cmdOpts->GX = 1;
} else {
cmdOpts->GX = 0;
}
}
/*
* Parse the /Op and /Op- options.
*/
static void handle_Op( OPT_STORAGE *cmdOpts, int x )
/**************************************************/
{
static int hasBeenCalled;
x = x;
if( handle_on_off_option( &hasBeenCalled, "Op", cmdOpts->Op ) ) {
cmdOpts->Op = 1;
} else {
cmdOpts->Op = 0;
}
}
/*
* Parse the /Oy and /Oy- options.
*/
static void handle_Oy( OPT_STORAGE *cmdOpts, int x )
/**************************************************/
{
static int hasBeenCalled;
x = x;
if( handle_on_off_option( &hasBeenCalled, "Oy", cmdOpts->Oy ) ) {
cmdOpts->Oy = 1;
} else {
cmdOpts->Oy = 0;
}
}
/*
* Return the next character and advance to the next one.
*/
static int OPT_GET_LOWER( void )
/******************************/
{
return( GetCharContext() );
}
/*
* If the next character is ch, it is consumed and a non-zero value
* is returned; otherwise, it is not consumed and zero is returned.
*/
static int OPT_RECOG( int ch )
/**********************************/
{
return( CmdScanRecogCharExact( ch ) );
}
/*
* If the next character is ch (in either uppercase or lowercase form), it
* is consumed and a non-zero value is returned; otherwise, it is not
* consumed and zero is returned.
*/
static int OPT_RECOG_LOWER( int ch )
/**********************************/
{
return( CmdScanRecogChar( ch ) );
}
/*
* Back up one character.
*/
static void OPT_UNGET( void )
/***************************/
{
UngetCharContext();
}
/*
* Scan an optional filename. No leading whitespace is permitted.
*/
static int OPT_GET_FILE_OPT( OPT_STRING **p )
/*******************************************/
{
char * filename;
filename = CmdScanFileName();
if( filename != NULL ) {
add_string( p, filename );
} else {
OPT_CLEAN_STRING( p );
}
return( 1 );
}
/*
* Scan a pathname. No leading whitespace is permitted.
*/
static int OPT_GET_PATH( OPT_STRING **p )
/***************************************/
{
char * filename;
filename = CmdScanFileName();
if( filename != NULL ) {
add_string( p, filename );
} else {
OPT_CLEAN_STRING( p );
}
return( 1 );
}
/*
* Scan a number. No leading whitespace is permitted.
*/
static int OPT_GET_NUMBER( unsigned *p )
/**************************************/
{
unsigned value;
if( CmdScanNumber( &value ) ) {
*p = value;
return( 1 );
} else {
return( 0 );
}
}
/*
* Scan an optional number. No leading whitespace is permitted.
*/
static int OPT_GET_NUMBER_DEFAULT( unsigned *p, unsigned value )
/**************************************************************/
{
char ch;
*p = value;
ch = GetCharContext();
UngetCharContext();
if( isdigit( ch ) ) {
if( CmdScanNumber( &value ) ) {
*p = value;
return( 1 );
} else {
return( 0 );
}
}
return( 1 );
}
/*
* Is this the end of an option chain?
*/
static int OPT_END( void )
/************************/
{
char ch;
ch = GetCharContext();
if( ch == '\0' ) return( 1 );
UngetCharContext();
if( isspace( ch ) ) return( 1 );
if( ch == '/' ) return( 1 );
if( ch == '-' ) return( 1 );
if( ch == '\@' ) return( 1 );
if( ch == '"' ) return( 1 );
if( ch == '\'' ) return( 1 );
return( 0 );
}
/* Include after all static functions were declared */
#if defined(__TARGET_386__)
#include "optp386c.gh"
#elif defined(__TARGET_AXP__)
#include "optpaxpc.gh"
#elif defined(__TARGET_PPC__)
#include "optpppcc.gh"
#else
#error Unrecognized CPU type
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?