summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichal Krol <[email protected]>2009-09-22 12:51:08 +0200
committerMichal Krol <[email protected]>2009-09-22 12:51:08 +0200
commit0481e85af7195e13c30580afba233a80feeee740 (patch)
tree6c9d69005a67424d41b6a1a04c9ab1dee087b796 /src
parentbb32b0908ff0d3a99758abd46356676fc1ec2369 (diff)
glsl/pp: Differentiate between integer and floating-point number tokens.
Diffstat (limited to 'src')
-rw-r--r--src/glsl/pp/sl_pp_error.c8
-rw-r--r--src/glsl/pp/sl_pp_expression.c4
-rw-r--r--src/glsl/pp/sl_pp_if.c8
-rw-r--r--src/glsl/pp/sl_pp_line.c8
-rw-r--r--src/glsl/pp/sl_pp_macro.c4
-rw-r--r--src/glsl/pp/sl_pp_token.c19
-rw-r--r--src/glsl/pp/sl_pp_token.h6
-rw-r--r--src/glsl/pp/sl_pp_version.c4
8 files changed, 39 insertions, 22 deletions
diff --git a/src/glsl/pp/sl_pp_error.c b/src/glsl/pp/sl_pp_error.c
index d42568d23dc..e591f4beef9 100644
--- a/src/glsl/pp/sl_pp_error.c
+++ b/src/glsl/pp/sl_pp_error.c
@@ -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:
diff --git a/src/glsl/pp/sl_pp_expression.c b/src/glsl/pp/sl_pp_expression.c
index 6b2329ed1a7..5093ef6cc9d 100644
--- a/src/glsl/pp/sl_pp_expression.c
+++ b/src/glsl/pp/sl_pp_expression.c
@@ -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) {
diff --git a/src/glsl/pp/sl_pp_if.c b/src/glsl/pp/sl_pp_if.c
index cf1c746d5f6..5fa27fcf053 100644
--- a/src/glsl/pp/sl_pp_if.c
+++ b/src/glsl/pp/sl_pp_if.c
@@ -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;
}
diff --git a/src/glsl/pp/sl_pp_line.c b/src/glsl/pp/sl_pp_line.c
index cab0262686c..e8f751003ac 100644
--- a/src/glsl/pp/sl_pp_line.c
+++ b/src/glsl/pp/sl_pp_line.c
@@ -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);
diff --git a/src/glsl/pp/sl_pp_macro.c b/src/glsl/pp/sl_pp_macro.c
index 878b22ed9c3..3956ba3b574 100644
--- a/src/glsl/pp/sl_pp_macro.c
+++ b/src/glsl/pp/sl_pp_macro.c
@@ -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;
diff --git a/src/glsl/pp/sl_pp_token.c b/src/glsl/pp/sl_pp_token.c
index 3a7ffe7db15..99a32a6e671 100644
--- a/src/glsl/pp/sl_pp_token.c
+++ b/src/glsl/pp/sl_pp_token.c
@@ -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;
diff --git a/src/glsl/pp/sl_pp_token.h b/src/glsl/pp/sl_pp_token.h
index 4131be6bdad..2a7b79ea3f7 100644
--- a/src/glsl/pp/sl_pp_token.h
+++ b/src/glsl/pp/sl_pp_token.h
@@ -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;
diff --git a/src/glsl/pp/sl_pp_version.c b/src/glsl/pp/sl_pp_version.c
index 825967d4c10..adf3017bf21 100644
--- a/src/glsl/pp/sl_pp_version.c
+++ b/src/glsl/pp/sl_pp_version.c
@@ -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;