macroprocessor: add @#ifdef
parent
c22022cfb0
commit
2d15137289
|
@ -79,7 +79,7 @@ class MacroDriver;
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%token DEFINE LINE FOR IN IF ELSE ENDIF ECHO_DIR ERROR
|
%token DEFINE LINE FOR IN IF ELSE ENDIF ECHO_DIR ERROR IFDEF
|
||||||
%token LPAREN RPAREN LBRACKET RBRACKET EQUAL EOL
|
%token LPAREN RPAREN LBRACKET RBRACKET EQUAL EOL
|
||||||
|
|
||||||
%token <int_val> INTEGER
|
%token <int_val> INTEGER
|
||||||
|
@ -117,6 +117,8 @@ statement : expr
|
||||||
{ TYPERR_CATCH(driver.init_loop(*$2, $4), @$); delete $2; }
|
{ TYPERR_CATCH(driver.init_loop(*$2, $4), @$); delete $2; }
|
||||||
| IF expr
|
| IF expr
|
||||||
{ TYPERR_CATCH(driver.begin_if($2), @$); }
|
{ TYPERR_CATCH(driver.begin_if($2), @$); }
|
||||||
|
| IFDEF NAME
|
||||||
|
{ TYPERR_CATCH(driver.begin_ifdef(*$2), @$); delete $2; }
|
||||||
| ECHO_DIR expr
|
| ECHO_DIR expr
|
||||||
{ TYPERR_CATCH(driver.echo(@$, $2), @$); }
|
{ TYPERR_CATCH(driver.echo(@$, $2), @$); }
|
||||||
| ERROR expr
|
| ERROR expr
|
||||||
|
|
|
@ -164,6 +164,24 @@ MacroDriver::begin_if(const MacroValue *value) throw (MacroValue::TypeError)
|
||||||
last_if = (bool) ival->value;
|
last_if = (bool) ival->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MacroDriver::begin_ifdef(const string &name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
get_variable(name);
|
||||||
|
const MacroValue *one = new IntMV(*this, 1);
|
||||||
|
begin_if(one);
|
||||||
|
delete one;
|
||||||
|
}
|
||||||
|
catch (UnknownVariable &)
|
||||||
|
{
|
||||||
|
const MacroValue *zero = new IntMV(*this, 0);
|
||||||
|
begin_if(zero);
|
||||||
|
delete zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MacroDriver::echo(const Macro::parser::location_type &l, const MacroValue *value) const throw (MacroValue::TypeError)
|
MacroDriver::echo(const Macro::parser::location_type &l, const MacroValue *value) const throw (MacroValue::TypeError)
|
||||||
{
|
{
|
||||||
|
|
|
@ -208,6 +208,9 @@ public:
|
||||||
//! Begins an @#if statement
|
//! Begins an @#if statement
|
||||||
void begin_if(const MacroValue *value) throw (MacroValue::TypeError);
|
void begin_if(const MacroValue *value) throw (MacroValue::TypeError);
|
||||||
|
|
||||||
|
//! Begins an @#ifdef statement
|
||||||
|
void begin_ifdef(const string &name);
|
||||||
|
|
||||||
//! Executes @#echo directive
|
//! Executes @#echo directive
|
||||||
void echo(const Macro::parser::location_type &l, const MacroValue *value) const throw (MacroValue::TypeError);
|
void echo(const Macro::parser::location_type &l, const MacroValue *value) const throw (MacroValue::TypeError);
|
||||||
|
|
||||||
|
|
|
@ -164,6 +164,8 @@ CONT \\\\
|
||||||
<STMT>for { reading_for_statement = true; return token::FOR; }
|
<STMT>for { reading_for_statement = true; return token::FOR; }
|
||||||
<STMT>endfor { driver.error(*yylloc, "@#endfor is not matched by a @#for statement"); }
|
<STMT>endfor { driver.error(*yylloc, "@#endfor is not matched by a @#for statement"); }
|
||||||
|
|
||||||
|
<STMT>ifdef { reading_if_statement = true; return token::IFDEF; }
|
||||||
|
|
||||||
<STMT>if { reading_if_statement = true; return token::IF; }
|
<STMT>if { reading_if_statement = true; return token::IF; }
|
||||||
<STMT>else { driver.error(*yylloc, "@#else is not matched by an @#if statement"); }
|
<STMT>else { driver.error(*yylloc, "@#else is not matched by an @#if statement"); }
|
||||||
<STMT>endif { driver.error(*yylloc, "@#endif is not matched by an @#if statement"); }
|
<STMT>endif { driver.error(*yylloc, "@#endif is not matched by an @#if statement"); }
|
||||||
|
|
Loading…
Reference in New Issue