@@ -1,6 +1,6 @@ | |||
/* | |||
* Mesa 3-D graphics library | |||
* Version: 6.5 | |||
* Version: 6.6 | |||
* | |||
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved. | |||
* | |||
@@ -1918,10 +1918,11 @@ static GLboolean | |||
compile_with_grammar (grammar id, const char *source, slang_code_unit *unit, slang_unit_type type, | |||
slang_info_log *infolog, slang_code_unit *builtin) | |||
{ | |||
byte *prod; | |||
byte *prod; | |||
GLuint size, start, version; | |||
slang_string preprocessed; | |||
/* retrieve version */ | |||
/* First retrieve the version number. */ | |||
if (!_slang_preprocess_version (source, &version, &start, infolog)) | |||
return GL_FALSE; | |||
@@ -1930,22 +1931,31 @@ compile_with_grammar (grammar id, const char *source, slang_code_unit *unit, sla | |||
return GL_FALSE; | |||
} | |||
/* check the syntax and generate its binary representation */ | |||
if (!grammar_fast_check (id, (const byte *) source + start, &prod, &size, 65536)) | |||
{ | |||
char buf[1024]; | |||
unsigned int pos; | |||
grammar_get_last_error ( (unsigned char*) buf, 1024, (int*) &pos); | |||
/* Now preprocess the source string. */ | |||
slang_string_init (&preprocessed); | |||
if (!_slang_preprocess_directives (&preprocessed, &source[start], infolog)) { | |||
slang_string_free (&preprocessed); | |||
slang_info_log_error (infolog, "failed to preprocess the source."); | |||
return GL_FALSE; | |||
} | |||
/* Finally check the syntax and generate its binary representation. */ | |||
if (!grammar_fast_check (id, (const byte *) (slang_string_cstr (&preprocessed)), &prod, &size, 65536)) { | |||
char buf[1024]; | |||
GLint pos; | |||
slang_string_free (&preprocessed); | |||
grammar_get_last_error ((byte *) (buf), sizeof (buf), &pos); | |||
slang_info_log_error (infolog, buf); | |||
return GL_FALSE; | |||
} | |||
} | |||
slang_string_free (&preprocessed); | |||
/* syntax is okay - translate it to internal representation */ | |||
/* Syntax is okay - translate it to internal representation. */ | |||
if (!compile_binary (prod, unit, type, infolog, builtin, &builtin[SLANG_BUILTIN_TOTAL - 1])) { | |||
grammar_alloc_free (prod); | |||
return GL_FALSE; | |||
} | |||
grammar_alloc_free (prod); | |||
return GL_TRUE; | |||
} |
@@ -1,6 +1,6 @@ | |||
/* | |||
* Mesa 3-D graphics library | |||
* Version: 6.5 | |||
* Version: 6.6 | |||
* | |||
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved. | |||
* | |||
@@ -34,6 +34,9 @@ extern "C" { | |||
GLboolean | |||
_slang_preprocess_version (const char *, GLuint *, GLuint *, slang_info_log *); | |||
GLboolean | |||
_slang_preprocess_directives (slang_string *output, const char *input, slang_info_log *); | |||
#ifdef __cplusplus | |||
} | |||
#endif |
@@ -1,6 +1,6 @@ | |||
/* | |||
* Mesa 3-D graphics library | |||
* Version: 6.5 | |||
* Version: 6.6 | |||
* | |||
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved. | |||
* | |||
@@ -36,6 +36,99 @@ char *slang_string_concat (char *dst, const char *src) | |||
return _mesa_strcpy (dst + _mesa_strlen (dst), src); | |||
} | |||
/* slang_string */ | |||
GLvoid | |||
slang_string_init (slang_string *self) | |||
{ | |||
self->data = NULL; | |||
self->capacity = 0; | |||
self->length = 0; | |||
self->fail = GL_FALSE; | |||
} | |||
GLvoid | |||
slang_string_free (slang_string *self) | |||
{ | |||
if (self->data != NULL) | |||
_mesa_free (self->data); | |||
} | |||
GLvoid | |||
slang_string_reset (slang_string *self) | |||
{ | |||
self->length = 0; | |||
self->fail = GL_FALSE; | |||
} | |||
static GLboolean | |||
grow (slang_string *self, GLuint size) | |||
{ | |||
if (self->fail) | |||
return GL_FALSE; | |||
if (size > self->capacity) { | |||
/* do not overflow 32-bit range */ | |||
assert (size < 0x80000000); | |||
self->data = (char *) (_mesa_realloc (self->data, self->capacity, size * 2)); | |||
self->capacity = size * 2; | |||
if (self->data == NULL) { | |||
self->capacity = 0; | |||
self->fail = GL_TRUE; | |||
return GL_FALSE; | |||
} | |||
} | |||
return GL_TRUE; | |||
} | |||
GLvoid | |||
slang_string_push (slang_string *self, const slang_string *str) | |||
{ | |||
if (str->fail) { | |||
self->fail = GL_TRUE; | |||
return; | |||
} | |||
if (grow (self, self->length + str->length)) { | |||
_mesa_memcpy (&self->data[self->length], str->data, str->length); | |||
self->length += str->length; | |||
} | |||
} | |||
GLvoid | |||
slang_string_pushc (slang_string *self, const char c) | |||
{ | |||
if (grow (self, self->length + 1)) { | |||
self->data[self->length] = c; | |||
self->length++; | |||
} | |||
} | |||
GLvoid | |||
slang_string_pushs (slang_string *self, const char *cstr, GLuint len) | |||
{ | |||
if (grow (self, self->length + len)) { | |||
_mesa_memcpy (&self->data[self->length], cstr, len); | |||
self->length += len; | |||
} | |||
} | |||
GLvoid | |||
slang_string_pushi (slang_string *self, GLint i) | |||
{ | |||
char buffer[12]; | |||
_mesa_sprintf (buffer, "%d", i); | |||
slang_string_pushs (self, buffer, strlen (buffer)); | |||
} | |||
const char * | |||
slang_string_cstr (slang_string *self) | |||
{ | |||
if (grow (self, self->length + 1)) | |||
self->data[self->length] = '\0'; | |||
return self->data; | |||
} | |||
/* slang_atom_pool */ | |||
void slang_atom_pool_construct (slang_atom_pool *pool) |
@@ -1,6 +1,6 @@ | |||
/* | |||
* Mesa 3-D graphics library | |||
* Version: 6.5 | |||
* Version: 6.6 | |||
* | |||
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved. | |||
* | |||
@@ -44,6 +44,42 @@ extern "C" { | |||
char *slang_string_concat (char *, const char *); | |||
/* slang_string */ | |||
typedef struct | |||
{ | |||
char *data; | |||
GLuint length; | |||
GLuint capacity; | |||
GLboolean fail; | |||
} slang_string; | |||
GLvoid | |||
slang_string_init (slang_string *); | |||
GLvoid | |||
slang_string_free (slang_string *); | |||
GLvoid | |||
slang_string_reset (slang_string *); | |||
GLvoid | |||
slang_string_push (slang_string *, const slang_string *); | |||
GLvoid | |||
slang_string_pushc (slang_string *, const char); | |||
GLvoid | |||
slang_string_pushs (slang_string *, const char *, GLuint); | |||
GLvoid | |||
slang_string_pushi (slang_string *, GLint); | |||
const char * | |||
slang_string_cstr (slang_string *); | |||
/* slang_atom */ | |||
typedef GLvoid *slang_atom; | |||
#define SLANG_ATOM_NULL ((slang_atom) 0) |