mojoshader_compiler.c
changeset 839 40e990813f41
parent 838 37e901d1b7bf
child 842 1ea7f51250fb
--- a/mojoshader_compiler.c	Sat Feb 20 20:31:00 2010 -0500
+++ b/mojoshader_compiler.c	Sat Feb 20 21:50:48 2010 -0500
@@ -1399,23 +1399,6 @@
 #include "mojoshader_parser_hlsl.h"
 
 
-static void free_string_cache(Context *ctx)
-{
-    size_t i;
-    for (i = 0; i < STATICARRAYLEN(ctx->string_hashtable); i++)
-    {
-        StringBucket *bucket = ctx->string_hashtable[i];
-        ctx->string_hashtable[i] = NULL;
-        while (bucket)
-        {
-            StringBucket *next = bucket->next;
-            Free(ctx, bucket->string);
-            Free(ctx, bucket);
-            bucket = next;
-        } // while
-    } // for
-} // free_string_cache
-
 static inline int64 strtoi64(const char *str, unsigned int len)
 {
     int64 retval = 0;
@@ -1764,6 +1747,32 @@
     return 0;
 } // convert_to_lemon_token
 
+static void free_string_cache(Context *ctx)
+{
+    size_t i;
+    for (i = 0; i < STATICARRAYLEN(ctx->string_hashtable); i++)
+    {
+        StringBucket *bucket = ctx->string_hashtable[i];
+        ctx->string_hashtable[i] = NULL;
+        while (bucket)
+        {
+            StringBucket *next = bucket->next;
+            Free(ctx, bucket->string);
+            Free(ctx, bucket);
+            bucket = next;
+        } // while
+    } // for
+} // free_string_cache
+
+static void destroy_context(Context *ctx)
+{
+    if (ctx->preprocessor != NULL)
+        preprocessor_end(ctx->preprocessor);
+    // !!! FIXME: free ctx->errors
+    // !!! FIXME: free ctx->usertypes
+    delete_compilation_unit(ctx, ctx->ast);
+    free_string_cache(ctx);
+} // destroy_context
 
 void MOJOSHADER_compile(const char *filename,
                         const char *source, unsigned int sourcelen,
@@ -1791,6 +1800,8 @@
                                            include_open, include_close,
                                            defines, define_count, 0, m, f, d);
 
+    // !!! FIXME: check if (ctx.preprocessor == NULL)...
+
     void *pParser = ParseHLSLAlloc(m, d);
 
     #if DEBUG_COMPILER_PARSER
@@ -1825,8 +1836,7 @@
     } while ((!ctx.isfail) && (tokenval != TOKEN_EOI));
 
     ParseHLSLFree(pParser, f, d);
-    // !!! FIXME: destruct (ctx) here.
-    free_string_cache(&ctx);
+    destroy_context(&ctx);
 } // MOJOSHADER_compile
 
 // end of mojoshader_compiler.c ...