Recognizing the #elif and #undef directives
This commit is contained in:
parent
50237ec133
commit
cd86a3c031
|
@ -33,6 +33,7 @@ typedef enum _CppCode
|
||||||
CPP_CODE_COMMA = 0,
|
CPP_CODE_COMMA = 0,
|
||||||
CPP_CODE_DQUOTE,
|
CPP_CODE_DQUOTE,
|
||||||
CPP_CODE_META_DEFINE,
|
CPP_CODE_META_DEFINE,
|
||||||
|
CPP_CODE_META_ELIF,
|
||||||
CPP_CODE_META_ELSE,
|
CPP_CODE_META_ELSE,
|
||||||
CPP_CODE_META_ENDIF,
|
CPP_CODE_META_ENDIF,
|
||||||
CPP_CODE_META_ERROR,
|
CPP_CODE_META_ERROR,
|
||||||
|
@ -41,6 +42,7 @@ typedef enum _CppCode
|
||||||
CPP_CODE_META_IFNDEF,
|
CPP_CODE_META_IFNDEF,
|
||||||
CPP_CODE_META_INCLUDE,
|
CPP_CODE_META_INCLUDE,
|
||||||
CPP_CODE_META_PRAGMA,
|
CPP_CODE_META_PRAGMA,
|
||||||
|
CPP_CODE_META_UNDEF,
|
||||||
CPP_CODE_META_WARNING,
|
CPP_CODE_META_WARNING,
|
||||||
CPP_CODE_OPERATOR_AEQUALS,
|
CPP_CODE_OPERATOR_AEQUALS,
|
||||||
CPP_CODE_OPERATOR_AMPERSAND,
|
CPP_CODE_OPERATOR_AMPERSAND,
|
||||||
|
@ -98,7 +100,7 @@ void cpp_delete(Cpp * cpp);
|
||||||
char const * cpp_get_filename(Cpp * cpp);
|
char const * cpp_get_filename(Cpp * cpp);
|
||||||
|
|
||||||
/* useful */
|
/* useful */
|
||||||
int cpp_add_path(Cpp * cpp, char const * path);
|
int cpp_path_add(Cpp * cpp, char const * path);
|
||||||
|
|
||||||
int cpp_scan(Cpp * cpp, Token ** token);
|
int cpp_scan(Cpp * cpp, Token ** token);
|
||||||
|
|
||||||
|
|
30
src/cpp.c
30
src/cpp.c
|
@ -62,6 +62,7 @@ struct _Cpp
|
||||||
typedef enum _CppDirective
|
typedef enum _CppDirective
|
||||||
{
|
{
|
||||||
CPP_DIRECTIVE_DEFINE = 0,
|
CPP_DIRECTIVE_DEFINE = 0,
|
||||||
|
CPP_DIRECTIVE_ELIF,
|
||||||
CPP_DIRECTIVE_ELSE,
|
CPP_DIRECTIVE_ELSE,
|
||||||
CPP_DIRECTIVE_ENDIF,
|
CPP_DIRECTIVE_ENDIF,
|
||||||
CPP_DIRECTIVE_ERROR,
|
CPP_DIRECTIVE_ERROR,
|
||||||
|
@ -70,6 +71,7 @@ typedef enum _CppDirective
|
||||||
CPP_DIRECTIVE_IFNDEF,
|
CPP_DIRECTIVE_IFNDEF,
|
||||||
CPP_DIRECTIVE_INCLUDE,
|
CPP_DIRECTIVE_INCLUDE,
|
||||||
CPP_DIRECTIVE_PRAGMA,
|
CPP_DIRECTIVE_PRAGMA,
|
||||||
|
CPP_DIRECTIVE_UNDEF,
|
||||||
CPP_DIRECTIVE_WARNING
|
CPP_DIRECTIVE_WARNING
|
||||||
} CppDirective;
|
} CppDirective;
|
||||||
#define CPP_DIRECTIVE_LAST CPP_DIRECTIVE_WARNING
|
#define CPP_DIRECTIVE_LAST CPP_DIRECTIVE_WARNING
|
||||||
|
@ -122,8 +124,8 @@ static const size_t _cpp_operators_cnt = sizeof(_cpp_operators)
|
||||||
static const size_t _cpp_directives_cnt = CPP_DIRECTIVE_COUNT;
|
static const size_t _cpp_directives_cnt = CPP_DIRECTIVE_COUNT;
|
||||||
static const char * _cpp_directives[CPP_DIRECTIVE_COUNT] =
|
static const char * _cpp_directives[CPP_DIRECTIVE_COUNT] =
|
||||||
{
|
{
|
||||||
"define", "else", "endif", "error", "if", "ifdef", "ifndef", "include",
|
"define", "elif", "else", "endif", "error", "if", "ifdef", "ifndef",
|
||||||
"pragma", "warning"
|
"include", "pragma", "undef", "warning"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -433,6 +435,10 @@ static int _cpp_callback_directive(Parser * parser, Token * token, int c,
|
||||||
/* FIXME implement */
|
/* FIXME implement */
|
||||||
token_set_code(token, CPP_CODE_META_DEFINE);
|
token_set_code(token, CPP_CODE_META_DEFINE);
|
||||||
break;
|
break;
|
||||||
|
case CPP_DIRECTIVE_ELIF:
|
||||||
|
/* FIXME implement */
|
||||||
|
token_set_code(token, CPP_CODE_META_ELIF);
|
||||||
|
break;
|
||||||
case CPP_DIRECTIVE_ELSE:
|
case CPP_DIRECTIVE_ELSE:
|
||||||
/* FIXME implement */
|
/* FIXME implement */
|
||||||
token_set_code(token, CPP_CODE_META_ELSE);
|
token_set_code(token, CPP_CODE_META_ELSE);
|
||||||
|
@ -463,6 +469,10 @@ static int _cpp_callback_directive(Parser * parser, Token * token, int c,
|
||||||
/* FIXME implement */
|
/* FIXME implement */
|
||||||
token_set_code(token, CPP_CODE_META_PRAGMA);
|
token_set_code(token, CPP_CODE_META_PRAGMA);
|
||||||
break;
|
break;
|
||||||
|
case CPP_DIRECTIVE_UNDEF:
|
||||||
|
/* FIXME implement */
|
||||||
|
token_set_code(token, CPP_CODE_META_UNDEF);
|
||||||
|
break;
|
||||||
case CPP_DIRECTIVE_WARNING:
|
case CPP_DIRECTIVE_WARNING:
|
||||||
_directive_warning(cpp, token, str);
|
_directive_warning(cpp, token, str);
|
||||||
break;
|
break;
|
||||||
|
@ -495,6 +505,7 @@ static int _directive_include(Cpp * cpp, Token * token, char const * str)
|
||||||
{
|
{
|
||||||
char * path;
|
char * path;
|
||||||
Cpp ** p;
|
Cpp ** p;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
if((path = _include_path(cpp, token, str)) == NULL)
|
if((path = _include_path(cpp, token, str)) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -505,6 +516,15 @@ static int _directive_include(Cpp * cpp, Token * token, char const * str)
|
||||||
free(path);
|
free(path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
for(i = 0; i < cpp->paths_cnt; i++)
|
||||||
|
if(cpp_path_add(cpp->subparser, cpp->paths[i]) != 0)
|
||||||
|
break;
|
||||||
|
if(i != cpp->paths_cnt)
|
||||||
|
{
|
||||||
|
cpp_delete(cpp->subparser);
|
||||||
|
cpp->subparser = NULL;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,7 +769,7 @@ Cpp * cpp_new(char const * filename, int filters)
|
||||||
cpp->paths_cnt = 0;
|
cpp->paths_cnt = 0;
|
||||||
if((p = strdup(filename)) != NULL)
|
if((p = strdup(filename)) != NULL)
|
||||||
{
|
{
|
||||||
cpp_add_path(cpp, dirname(p)); /* FIXME inclusion order */
|
cpp_path_add(cpp, dirname(p)); /* FIXME inclusion order */
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
if(cpp->parser == NULL || cpp->paths_cnt != 1)
|
if(cpp->parser == NULL || cpp->paths_cnt != 1)
|
||||||
|
@ -794,8 +814,8 @@ char const * cpp_get_filename(Cpp * cpp)
|
||||||
|
|
||||||
|
|
||||||
/* useful */
|
/* useful */
|
||||||
/* cpp_add_path */
|
/* cpp_path_add */
|
||||||
int cpp_add_path(Cpp * cpp, char const * path)
|
int cpp_path_add(Cpp * cpp, char const * path)
|
||||||
{
|
{
|
||||||
char ** p;
|
char ** p;
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ static int _cpp_do(Prefs * prefs, FILE * fp, char const * filename)
|
||||||
? CPP_FILTER_TRIGRAPH : 0)) == NULL)
|
? CPP_FILTER_TRIGRAPH : 0)) == NULL)
|
||||||
return _cpp_error();
|
return _cpp_error();
|
||||||
for(i = 0; i < prefs->paths_cnt; i++)
|
for(i = 0; i < prefs->paths_cnt; i++)
|
||||||
if(cpp_add_path(cpp, prefs->paths[i]) != 0)
|
if(cpp_path_add(cpp, prefs->paths[i]) != 0)
|
||||||
break;
|
break;
|
||||||
if(i != prefs->paths_cnt)
|
if(i != prefs->paths_cnt)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user