mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-03 14:18:07 +02:00
slang/pp: Use a dictionary for the remaining string literals.
This commit is contained in:
parent
0ddf41d34d
commit
ce8f486156
7 changed files with 95 additions and 54 deletions
|
|
@ -52,5 +52,32 @@ sl_pp_dict_init(struct sl_pp_context *context)
|
|||
ADD_NAME(context, warn);
|
||||
ADD_NAME(context, disable);
|
||||
|
||||
ADD_NAME(context, defined);
|
||||
|
||||
ADD_NAME_STR(context, ___LINE__, "__LINE__");
|
||||
ADD_NAME_STR(context, ___FILE__, "__FILE__");
|
||||
ADD_NAME(context, __VERSION__);
|
||||
|
||||
ADD_NAME(context, optimize);
|
||||
ADD_NAME(context, debug);
|
||||
|
||||
ADD_NAME(context, off);
|
||||
ADD_NAME(context, on);
|
||||
|
||||
ADD_NAME(context, define);
|
||||
ADD_NAME(context, elif);
|
||||
ADD_NAME_STR(context, _else, "else");
|
||||
ADD_NAME(context, endif);
|
||||
ADD_NAME(context, error);
|
||||
ADD_NAME(context, extension);
|
||||
ADD_NAME_STR(context, _if, "if");
|
||||
ADD_NAME(context, ifdef);
|
||||
ADD_NAME(context, ifndef);
|
||||
ADD_NAME(context, line);
|
||||
ADD_NAME(context, pragma);
|
||||
ADD_NAME(context, undef);
|
||||
|
||||
ADD_NAME(context, version);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,33 @@ struct sl_pp_dict {
|
|||
int enable;
|
||||
int warn;
|
||||
int disable;
|
||||
|
||||
int defined;
|
||||
|
||||
int ___LINE__;
|
||||
int ___FILE__;
|
||||
int __VERSION__;
|
||||
|
||||
int optimize;
|
||||
int debug;
|
||||
|
||||
int off;
|
||||
int on;
|
||||
|
||||
int define;
|
||||
int elif;
|
||||
int _else;
|
||||
int endif;
|
||||
int error;
|
||||
int extension;
|
||||
int _if;
|
||||
int ifdef;
|
||||
int ifndef;
|
||||
int line;
|
||||
int pragma;
|
||||
int undef;
|
||||
|
||||
int version;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -136,20 +136,16 @@ _parse_if(struct sl_pp_context *context,
|
|||
break;
|
||||
|
||||
case SL_PP_IDENTIFIER:
|
||||
{
|
||||
const char *id = sl_pp_context_cstr(context, input[i].data.identifier);
|
||||
|
||||
if (!strcmp(id, "defined")) {
|
||||
i++;
|
||||
if (_parse_defined(context, input, &i, &state)) {
|
||||
free(state.out);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (sl_pp_macro_expand(context, input, &i, NULL, &state, 0)) {
|
||||
free(state.out);
|
||||
return -1;
|
||||
}
|
||||
if (input[i].data.identifier == context->dict.defined) {
|
||||
i++;
|
||||
if (_parse_defined(context, input, &i, &state)) {
|
||||
free(state.out);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (sl_pp_macro_expand(context, input, &i, NULL, &state, 0)) {
|
||||
free(state.out);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@ sl_pp_macro_expand(struct sl_pp_context *context,
|
|||
int mute)
|
||||
{
|
||||
int macro_name;
|
||||
const char *macro_str;
|
||||
struct sl_pp_macro *macro = NULL;
|
||||
struct sl_pp_macro *actual_arg = NULL;
|
||||
unsigned int j;
|
||||
|
|
@ -135,23 +134,22 @@ sl_pp_macro_expand(struct sl_pp_context *context,
|
|||
}
|
||||
|
||||
macro_name = input[*pi].data.identifier;
|
||||
macro_str = sl_pp_context_cstr(context, macro_name);
|
||||
|
||||
if (!strcmp(macro_str, "__LINE__")) {
|
||||
if (macro_name == context->dict.___LINE__) {
|
||||
if (!mute && _out_number(context, state, context->line)) {
|
||||
return -1;
|
||||
}
|
||||
(*pi)++;
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(macro_str, "__FILE__")) {
|
||||
if (macro_name == context->dict.___FILE__) {
|
||||
if (!mute && _out_number(context, state, context->file)) {
|
||||
return -1;
|
||||
}
|
||||
(*pi)++;
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(macro_str, "__VERSION__")) {
|
||||
if (macro_name == context->dict.__VERSION__) {
|
||||
if (!mute && _out_number(context, state, 110)) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,21 +36,21 @@ sl_pp_process_pragma(struct sl_pp_context *context,
|
|||
unsigned int last,
|
||||
struct sl_pp_process_state *state)
|
||||
{
|
||||
const char *pragma_name = NULL;
|
||||
int pragma_name = -1;
|
||||
struct sl_pp_token_info out;
|
||||
const char *arg_name = NULL;
|
||||
int arg_name = -1;
|
||||
|
||||
if (first < last && input[first].token == SL_PP_IDENTIFIER) {
|
||||
pragma_name = sl_pp_context_cstr(context, input[first].data.identifier);
|
||||
pragma_name = input[first].data.identifier;
|
||||
first++;
|
||||
}
|
||||
if (!pragma_name) {
|
||||
if (pragma_name == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(pragma_name, "optimize")) {
|
||||
if (pragma_name == context->dict.optimize) {
|
||||
out.token = SL_PP_PRAGMA_OPTIMIZE;
|
||||
} else if (!strcmp(pragma_name, "debug")) {
|
||||
} else if (pragma_name == context->dict.debug) {
|
||||
out.token = SL_PP_PRAGMA_DEBUG;
|
||||
} else {
|
||||
return 0;
|
||||
|
|
@ -71,16 +71,16 @@ sl_pp_process_pragma(struct sl_pp_context *context,
|
|||
}
|
||||
|
||||
if (first < last && input[first].token == SL_PP_IDENTIFIER) {
|
||||
arg_name = sl_pp_context_cstr(context, input[first].data.identifier);
|
||||
arg_name = input[first].data.identifier;
|
||||
first++;
|
||||
}
|
||||
if (!arg_name) {
|
||||
if (arg_name == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(arg_name, "off")) {
|
||||
if (arg_name == context->dict.off) {
|
||||
out.data.pragma = 0;
|
||||
} else if (!strcmp(arg_name, "on")) {
|
||||
} else if (arg_name == context->dict.on) {
|
||||
out.data.pragma = 1;
|
||||
} else {
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -100,14 +100,14 @@ sl_pp_process(struct sl_pp_context *context,
|
|||
switch (input[i].token) {
|
||||
case SL_PP_IDENTIFIER:
|
||||
{
|
||||
const char *name;
|
||||
int name;
|
||||
int found_eol = 0;
|
||||
unsigned int first;
|
||||
unsigned int last;
|
||||
struct sl_pp_token_info endof;
|
||||
|
||||
/* Directive name. */
|
||||
name = sl_pp_context_cstr(context, input[i].data.identifier);
|
||||
name = input[i].data.identifier;
|
||||
i++;
|
||||
skip_whitespace(input, &i);
|
||||
|
||||
|
|
@ -136,51 +136,51 @@ sl_pp_process(struct sl_pp_context *context,
|
|||
|
||||
last = i - 1;
|
||||
|
||||
if (!strcmp(name, "if")) {
|
||||
if (name == context->dict._if) {
|
||||
if (sl_pp_process_if(context, input, first, last)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!strcmp(name, "ifdef")) {
|
||||
} else if (name == context->dict.ifdef) {
|
||||
if (sl_pp_process_ifdef(context, input, first, last)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!strcmp(name, "ifndef")) {
|
||||
} else if (name == context->dict.ifndef) {
|
||||
if (sl_pp_process_ifndef(context, input, first, last)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!strcmp(name, "elif")) {
|
||||
} else if (name == context->dict.elif) {
|
||||
if (sl_pp_process_elif(context, input, first, last)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!strcmp(name, "else")) {
|
||||
} else if (name == context->dict._else) {
|
||||
if (sl_pp_process_else(context, input, first, last)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!strcmp(name, "endif")) {
|
||||
} else if (name == context->dict.endif) {
|
||||
if (sl_pp_process_endif(context, input, first, last)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (context->if_value) {
|
||||
if (!strcmp(name, "define")) {
|
||||
if (name == context->dict.define) {
|
||||
if (sl_pp_process_define(context, input, first, last)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!strcmp(name, "error")) {
|
||||
} else if (name == context->dict.error) {
|
||||
sl_pp_process_error(context, input, first, last);
|
||||
return -1;
|
||||
} else if (!strcmp(name, "extension")) {
|
||||
} else if (name == context->dict.extension) {
|
||||
if (sl_pp_process_extension(context, input, first, last, &state)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!strcmp(name, "line")) {
|
||||
} else if (name == context->dict.line) {
|
||||
if (sl_pp_process_line(context, input, first, last, &state)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!strcmp(name, "pragma")) {
|
||||
} else if (name == context->dict.pragma) {
|
||||
if (sl_pp_process_pragma(context, input, first, last, &state)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!strcmp(name, "undef")) {
|
||||
} else if (name == context->dict.undef) {
|
||||
if (sl_pp_process_undef(context, input, first, last)) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,18 +79,11 @@ sl_pp_version(struct sl_pp_context *context,
|
|||
break;
|
||||
|
||||
case SL_PP_IDENTIFIER:
|
||||
{
|
||||
const char *id = sl_pp_context_cstr(context, input[i].data.identifier);
|
||||
|
||||
if (!id) {
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(id, "version")) {
|
||||
return 0;
|
||||
}
|
||||
i++;
|
||||
found_version = 1;
|
||||
if (input[i].data.identifier != context->dict.version) {
|
||||
return 0;
|
||||
}
|
||||
i++;
|
||||
found_version = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue