Made ErrorList struct opaque to callers.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 09 Nov 2010 05:05:41 -0500
changeset 945 f00ea3986db8
parent 944 9f9fa9650772
child 946 16fec3a3f687
Made ErrorList struct opaque to callers.
mojoshader.c
mojoshader_assembler.c
mojoshader_common.c
mojoshader_compiler.c
mojoshader_internal.h
mojoshader_preprocessor.c
--- a/mojoshader.c	Tue Nov 09 05:00:03 2010 -0500
+++ b/mojoshader.c	Tue Nov 09 05:05:41 2010 -0500
@@ -7359,7 +7359,7 @@
     if (!isfail(ctx))
         samplers = build_samplers(ctx);
 
-    const int error_count = ctx->errors->count;
+    const int error_count = errorlist_count(ctx->errors);
     errors = errorlist_flatten(ctx->errors);
 
     if (!isfail(ctx))
--- a/mojoshader_assembler.c	Tue Nov 09 05:00:03 2010 -0500
+++ b/mojoshader_assembler.c	Tue Nov 09 05:05:41 2010 -0500
@@ -1515,7 +1515,7 @@
     retval->free = (ctx->free == MOJOSHADER_internal_free) ? NULL : ctx->free;
     retval->malloc_data = ctx->malloc_data;
 
-    retval->error_count = ctx->errors->count;
+    retval->error_count = errorlist_count(ctx->errors);
     retval->errors = errorlist_flatten(ctx->errors);
     if (ctx->out_of_memory)
     {
--- a/mojoshader_common.c	Tue Nov 09 05:00:03 2010 -0500
+++ b/mojoshader_common.c	Tue Nov 09 05:05:41 2010 -0500
@@ -390,6 +390,23 @@
 } // stringcache_destroy
 
 
+// We chain errors as a linked list with a head/tail for easy appending.
+//  These get flattened before passing to the application.
+typedef struct ErrorItem
+{
+    MOJOSHADER_error error;
+    struct ErrorItem *next;
+} ErrorItem;
+
+struct ErrorList
+{
+    ErrorItem head;
+    ErrorItem *tail;
+    int count;
+    MOJOSHADER_malloc m;
+    MOJOSHADER_free f;
+    void *d;
+};
 
 ErrorList *errorlist_create(MOJOSHADER_malloc m, MOJOSHADER_free f, void *d)
 {
@@ -483,6 +500,12 @@
 } // errorlist_add_va
 
 
+int errorlist_count(ErrorList *list)
+{
+    return list->count;
+} // errorlist_count
+
+
 MOJOSHADER_error *errorlist_flatten(ErrorList *list)
 {
     if (list->count == 0)
--- a/mojoshader_compiler.c	Tue Nov 09 05:00:03 2010 -0500
+++ b/mojoshader_compiler.c	Tue Nov 09 05:05:41 2010 -0500
@@ -2368,7 +2368,7 @@
     retval->malloc = (ctx->malloc == MOJOSHADER_internal_malloc) ? NULL : ctx->malloc;
     retval->free = (ctx->free == MOJOSHADER_internal_free) ? NULL : ctx->free;
     retval->malloc_data = ctx->malloc_data;
-    retval->error_count = ctx->errors->count;
+    retval->error_count = errorlist_count(ctx->errors);
     retval->errors = errorlist_flatten(ctx->errors);
 
     if (ctx->out_of_memory)
@@ -2403,7 +2403,7 @@
         retval->ast = ctx->ast;
     } // if
 
-    retval->error_count = ctx->errors->count;
+    retval->error_count = errorlist_count(ctx->errors);
     retval->errors = errorlist_flatten(ctx->errors);
     if (ctx->out_of_memory)
     {
@@ -2462,9 +2462,9 @@
     retval->free = (ctx->free == MOJOSHADER_internal_free) ? NULL : ctx->free;
     retval->malloc_data = ctx->malloc_data;
     retval->source_profile = ctx->source_profile;
-    retval->error_count = ctx->errors->count;
+    retval->error_count = errorlist_count(ctx->errors);
     retval->errors = errorlist_flatten(ctx->errors);
-    retval->warning_count = ctx->warnings->count;
+    retval->warning_count = errorlist_count(ctx->warnings);
     retval->warnings = errorlist_flatten(ctx->warnings);
 
     if (ctx->out_of_memory)  // in case something failed up there.
@@ -2503,9 +2503,9 @@
         // !!! FIXME: build symbols and symbol_count here.
     } // if
 
-    retval->error_count = ctx->errors->count;
+    retval->error_count = errorlist_count(ctx->errors);
     retval->errors = errorlist_flatten(ctx->errors);
-    retval->warning_count = ctx->warnings->count;
+    retval->warning_count = errorlist_count(ctx->warnings);
     retval->warnings = errorlist_flatten(ctx->warnings);
 
     if (ctx->out_of_memory)  // in case something failed up there.
--- a/mojoshader_internal.h	Tue Nov 09 05:00:03 2010 -0500
+++ b/mojoshader_internal.h	Tue Nov 09 05:05:41 2010 -0500
@@ -194,24 +194,9 @@
 void stringcache_destroy(StringCache *cache);
 
 
-// We chain errors as a linked list with a head/tail for easy appending.
-//  These get flattened before passing to the application.
-typedef struct ErrorItem
-{
-    MOJOSHADER_error error;
-    struct ErrorItem *next;
-} ErrorItem;
+// Error lists...
 
-typedef struct ErrorList
-{
-    ErrorItem head;
-    ErrorItem *tail;
-    int count;
-    MOJOSHADER_malloc m;
-    MOJOSHADER_free f;
-    void *d;
-} ErrorList;
-
+typedef struct ErrorList ErrorList;
 ErrorList *errorlist_create(MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
 int errorlist_add(ErrorList *list, const char *fname,
                       const int errpos, const char *str);
@@ -219,6 +204,7 @@
                       const int errpos, const char *fmt, ...) ISPRINTF(4,5);
 int errorlist_add_va(ErrorList *list, const char *_fname,
                      const int errpos, const char *fmt, va_list va);
+int errorlist_count(ErrorList *list);
 MOJOSHADER_error *errorlist_flatten(ErrorList *list); // resets the list!
 void errorlist_destroy(ErrorList *list);
 
--- a/mojoshader_preprocessor.c	Tue Nov 09 05:00:03 2010 -0500
+++ b/mojoshader_preprocessor.c	Tue Nov 09 05:05:41 2010 -0500
@@ -2319,9 +2319,10 @@
     } // if
 
     memset(retval, '\0', sizeof (*retval));
-    if (errors->count > 0)
+    const int errcount = errorlist_count(errors);
+    if (errcount > 0)
     {
-        retval->error_count = errors->count;
+        retval->error_count = errcount;
         retval->errors = errorlist_flatten(errors);
         if (retval->errors == NULL)
         {