]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - gmqcc.h
ast and ir testers - to use: compile into gmqcc and execut the functions in main()
[xonotic/gmqcc.git] / gmqcc.h
diff --git a/gmqcc.h b/gmqcc.h
index cbe195a77a0dd61504b3dca6f978897011439ab8..6da465b42e741533fb18ce58509c16ef75114582 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
 #else
 #   define GMQCC_WARN
 #endif
+/*
+ * This is a hack to silent clang regarding empty
+ * body if statements.
+ */
+#define GMQCC_SUPRESS_EMPTY_BODY do { } while (0)
 
 /*
  * stdint.h and inttypes.h -less subset
@@ -167,8 +172,9 @@ enum {
 int       lex_token  (lex_file *);
 void      lex_reset  (lex_file *);
 void      lex_close  (lex_file *);
-lex_file *lex_include(lex_file *, char *);
-lex_file *lex_open   (FILE *);
+void      lex_parse  (lex_file *);
+lex_file *lex_include(lex_file *, const char *);
+void      lex_init   (const char *, lex_file **);
 
 //===================================================================
 //========================== error.c ================================
@@ -208,8 +214,8 @@ void  util_meminfo       ();
 bool  util_strupper      (const char *);
 bool  util_strdigit      (const char *);
 char *util_strdup        (const char *);
-char *util_strrq         (char *);
-char *util_strrnl        (char *);
+char *util_strrq         (const char *);
+char *util_strrnl        (const char *);
 char *util_strsws        (const char *);
 char *util_strchp        (const char *, const char *);
 void  util_debug         (const char *, const char *, ...);
@@ -227,6 +233,8 @@ uint32_t util_crc32(const char *, int, register const short);
 #endif
 
 /* Builds vector type (usefull for inside structures) */
+#define VECTOR_SNAP(X,Y) X ## Y
+#define VECTOR_FILL(X,Y) VECTOR_SNAP(X,Y)
 #define VECTOR_TYPE(T,N)                                        \
     T*     N##_data      = NULL;                                \
     long   N##_elements  = 0;                                   \
@@ -257,7 +265,8 @@ uint32_t util_crc32(const char *, int, register const short);
         elements--;                                             \
         while (N##_add(*++elements) != -1 && len--);            \
         return N##_elements;                                    \
-    }
+    }                                                           \
+    typedef char VECTOR_FILL(extra_semicolon_,__COUNTER__)
 /* Builds a full vector inspot */
 #define VECTOR_MAKE(T,N) \
     VECTOR_TYPE(T,N);    \
@@ -303,17 +312,17 @@ typedef struct {
     union {
         int16_t  s1; /* signed   */
         uint16_t u1; /* unsigned */
-    };
+    } o1;
     /* operand 2 */
     union {
         int16_t  s2; /* signed   */
         uint16_t u2; /* unsigned */
-    };
+    } o2;
     /* operand 3 */
     union {
         int16_t  s3; /* signed   */
         uint16_t u3; /* unsigned */
-    };
+    } o3;
     
     /*
      * This is the same as the structure in darkplaces
@@ -572,12 +581,12 @@ extern int  opts_compiler;
 //======================================================================
 #define MEM_VECTOR_PROTO(Towner, Tmem, mem)                   \
     bool GMQCC_WARN Towner##_##mem##_add(Towner*, Tmem);      \
-    bool GMQCC_WARN Towner##_##mem##_remove(Towner*, size_t);
+    bool GMQCC_WARN Towner##_##mem##_remove(Towner*, size_t)
 
 #define MEM_VECTOR_PROTO_ALL(Towner, Tmem, mem)                    \
-    MEM_VECTOR_PROTO(Towner, Tmem, mem)                            \
+    MEM_VECTOR_PROTO(Towner, Tmem, mem);                           \
     bool GMQCC_WARN Towner##_##mem##_find(Towner*, Tmem, size_t*); \
-    void Towner##_##mem##_clear(Towner*);
+    void Towner##_##mem##_clear(Towner*)
 
 #define MEM_VECTOR_MAKE(Twhat, name) \
     Twhat  *name;                    \
@@ -651,17 +660,17 @@ void Tself##_##mem##_clear(Tself *self) \
 {                                       \
     if (!self->mem)                     \
         return;                         \
-    free((void*) self->mem);            \
+    mem_d((void*) self->mem);           \
     self->mem = NULL;                   \
     self->mem##_count = 0;              \
     self->mem##_alloc = 0;              \
 }
 
-#define MEM_VECTOR_CLEAR(owner, mem) \
-    if ((owner)->mem)                \
-        free((void*)((owner)->mem)); \
-    (owner)->mem = NULL;             \
-    (owner)->mem##_count = 0;        \
+#define MEM_VECTOR_CLEAR(owner, mem)  \
+    if ((owner)->mem)                 \
+        mem_d((void*)((owner)->mem)); \
+    (owner)->mem = NULL;              \
+    (owner)->mem##_count = 0;         \
     (owner)->mem##_alloc = 0
 
 #define MEM_VECTOR_INIT(owner, mem) \
@@ -688,14 +697,14 @@ enum store_types {
 
 typedef struct {
     float x, y, z;
-} vector_t;
+} vector;
 
 /*
  * A shallow copy of a lex_file to remember where which ast node
  * came from.
  */
-typedef struct lex_ctx {
+typedef struct {
     const char *file;
-    size_t     line;
-} lex_ctx_t;
+    size_t      line;
+} lex_ctx;
 #endif