glsl/pp: Differentiate between integer and floating-point number tokens.

This commit is contained in:
Michal Krol
2009-09-22 12:51:08 +02:00
parent bb32b0908f
commit 0481e85af7
8 changed files with 39 additions and 22 deletions
+6 -2
View File
@@ -239,8 +239,12 @@ sl_pp_process_error(struct sl_pp_context *context,
s = sl_pp_context_cstr(context, input[i].data.identifier);
break;
case SL_PP_NUMBER:
s = sl_pp_context_cstr(context, input[i].data.number);
case SL_PP_UINT:
s = sl_pp_context_cstr(context, input[i].data._uint);
break;
case SL_PP_FLOAT:
s = sl_pp_context_cstr(context, input[i].data._float);
break;
case SL_PP_OTHER:
+2 -2
View File
@@ -42,8 +42,8 @@ static int
_parse_primary(struct parse_context *ctx,
int *result)
{
if (ctx->input->token == SL_PP_NUMBER) {
*result = atoi(sl_pp_context_cstr(ctx->context, ctx->input->data.number));
if (ctx->input->token == SL_PP_UINT) {
*result = atoi(sl_pp_context_cstr(ctx->context, ctx->input->data._uint));
ctx->input++;
} else {
if (ctx->input->token != SL_PP_LPAREN) {
+4 -4
View File
@@ -81,13 +81,13 @@ _parse_defined(struct sl_pp_context *context,
(*pi)++;
}
result.token = SL_PP_NUMBER;
result.token = SL_PP_UINT;
if (defined) {
result.data.number = sl_pp_context_add_unique_str(context, "1");
result.data._uint = sl_pp_context_add_unique_str(context, "1");
} else {
result.data.number = sl_pp_context_add_unique_str(context, "0");
result.data._uint = sl_pp_context_add_unique_str(context, "0");
}
if (result.data.number == -1) {
if (result.data._uint == -1) {
return -1;
}
+4 -4
View File
@@ -67,8 +67,8 @@ sl_pp_process_line(struct sl_pp_context *context,
}
}
if (state.out_len > 0 && state.out[0].token == SL_PP_NUMBER) {
line_number = state.out[0].data.number;
if (state.out_len > 0 && state.out[0].token == SL_PP_UINT) {
line_number = state.out[0].data._uint;
} else {
strcpy(context->error_msg, "expected a number after `#line'");
free(state.out);
@@ -76,8 +76,8 @@ sl_pp_process_line(struct sl_pp_context *context,
}
if (state.out_len > 1) {
if (state.out[1].token == SL_PP_NUMBER) {
file_number = state.out[1].data.number;
if (state.out[1].token == SL_PP_UINT) {
file_number = state.out[1].data._uint;
} else {
strcpy(context->error_msg, "expected a number after line number");
free(state.out);
+2 -2
View File
@@ -105,8 +105,8 @@ _out_number(struct sl_pp_context *context,
sprintf(buf, "%u", number);
ti.token = SL_PP_NUMBER;
ti.data.number = sl_pp_context_add_unique_str(context, buf);
ti.token = SL_PP_UINT;
ti.data._uint = sl_pp_context_add_unique_str(context, buf);
if (sl_pp_process_out(state, &ti)) {
strcpy(context->error_msg, "out of memory");
return -1;
+15 -4
View File
@@ -271,6 +271,7 @@ _tokenise_number(struct sl_pp_context *context,
{
const char *input = *pinput;
unsigned int eaten;
unsigned int is_float = 0;
char number[256]; /* XXX: Remove this artifical limit. */
eaten = _parse_float(input);
@@ -282,6 +283,8 @@ _tokenise_number(struct sl_pp_context *context,
eaten = _parse_dec(input);
}
}
} else {
is_float = 1;
}
if (!eaten || _is_identifier_char(input[eaten])) {
@@ -297,10 +300,18 @@ _tokenise_number(struct sl_pp_context *context,
memcpy(number, input, eaten);
number[eaten] = '\0';
info->token = SL_PP_NUMBER;
info->data.number = sl_pp_context_add_unique_str(context, number);
if (info->data.number == -1) {
return -1;
if (is_float) {
info->token = SL_PP_FLOAT;
info->data._float = sl_pp_context_add_unique_str(context, number);
if (info->data._float == -1) {
return -1;
}
} else {
info->token = SL_PP_UINT;
info->data._uint = sl_pp_context_add_unique_str(context, number);
if (info->data._uint == -1) {
return -1;
}
}
*pinput = input + eaten;
+4 -2
View File
@@ -82,7 +82,8 @@ enum sl_pp_token {
SL_PP_IDENTIFIER,
SL_PP_NUMBER,
SL_PP_UINT,
SL_PP_FLOAT,
SL_PP_OTHER,
@@ -102,7 +103,8 @@ enum sl_pp_token {
union sl_pp_token_data {
int identifier;
int number;
int _uint;
int _float;
char other;
int pragma;
int extension;
+2 -2
View File
@@ -99,8 +99,8 @@ sl_pp_version(struct sl_pp_context *context,
i++;
break;
case SL_PP_NUMBER:
*version = atoi(sl_pp_context_cstr(context, input[i].data.number));
case SL_PP_UINT:
*version = atoi(sl_pp_context_cstr(context, input[i].data._uint));
i++;
found_number = 1;
break;