Implemented a subset of #if

This commit is contained in:
Pierre Pronchery 2009-08-01 02:11:44 +00:00
parent ec4a31ea90
commit 59d80dffd6
2 changed files with 20 additions and 2 deletions

View File

@ -575,6 +575,7 @@ static int _cpp_callback_dequeue(Parser * parser, Token * token, int c,
switch(cpp->queue_code)
{
case CPP_CODE_META_DEFINE:
case CPP_CODE_META_IF:
case CPP_CODE_META_IFDEF:
case CPP_CODE_META_IFNDEF:
case CPP_CODE_META_INCLUDE:

View File

@ -223,9 +223,26 @@ static int _scan_ifndef(Cpp * cpp, Token ** token)
static int _scan_if(Cpp * cpp, Token ** token)
{
char * str;
char * p;
DEBUG_SCOPE();
/* FIXME check the condition */
if((str = token_get_data(*token)) == NULL)
/* FIXME it's probably an error case instead */
_cpp_scope_push(cpp, CPP_SCOPE_NOTYET);
else if(strcmp(str, "1") == 0)
_cpp_scope_push(cpp, CPP_SCOPE_TAKING);
else if(strncmp(str, "defined(", 8) == 0 &&
(p = strchr(str, ')')) != NULL)
{
*p = '\0';
_cpp_scope_push(cpp, cpp_define_get(cpp, &str[8]) != NULL
? CPP_SCOPE_TAKING : CPP_SCOPE_NOTYET);
}
else
/* FIXME really check the condition */
_cpp_scope_push(cpp, CPP_SCOPE_NOTYET);
free(str);
return 0;
}