]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - gmqcc.h
Starting point of 0.3.0
[xonotic/gmqcc.git] / gmqcc.h
diff --git a/gmqcc.h b/gmqcc.h
index ad185a05c6e5fda2f00d40a93544a8017b0edbf0..0031227457eded092b0b4d25d7e5793b5d45d464 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
  */
 #ifdef _MSC_VER
 #   pragma warning(disable : 4244 ) /* conversion from 'int' to 'float', possible loss of data */
-#   pragma warning(disable : 4018 ) /* signed/unsigned mismatch                                */
 #endif /*! _MSC_VER */
 
 #define GMQCC_VERSION_MAJOR 0
-#define GMQCC_VERSION_MINOR 2
-#define GMQCC_VERSION_PATCH 9
+#define GMQCC_VERSION_MINOR 3
+#define GMQCC_VERSION_PATCH 0
 #define GMQCC_VERSION_BUILD(J,N,P) (((J)<<16)|((N)<<8)|(P))
 #define GMQCC_VERSION \
     GMQCC_VERSION_BUILD(GMQCC_VERSION_MAJOR, GMQCC_VERSION_MINOR, GMQCC_VERSION_PATCH)
 #define GMQCC_VERSION_TYPE_DEVEL
 
 /* Full version string in case we need it */
-#ifdef GMQCC_GITINFO
-#    define GMQCC_DEV_VERSION_STRING "git build: " GMQCC_GITINFO "\n"
-#elif defined(GMQCC_VERSION_TYPE_DEVEL)
-#    define GMQCC_DEV_VERSION_STRING "development build\n"
+#ifdef GMQCC_VERSION_TYPE_DEVEL
+#    ifdef GMQCC_GITINFO
+#        define GMQCC_DEV_VERSION_STRING "git build: " GMQCC_GITINFO "\n"
+#    elif defined(GMQCC_VERSION_TYPE_DEVEL)
+#        define GMQCC_DEV_VERSION_STRING "development build\n"
+#    else
+#        define GMQCC_DEV_VERSION_STRING
+#    endif /*! GMQCC_GITINGO */
 #else
 #    define GMQCC_DEV_VERSION_STRING
-#endif /*! GMQCC_GITINGO */
+#endif
 
 #define GMQCC_STRINGIFY(x) #x
 #define GMQCC_IND_STRING(x) GMQCC_STRINGIFY(x)
@@ -168,17 +171,6 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
     typedef __int64          int64_t;
 #endif /*! _MSC_VER */
 
-/*
- *windows makes these prefixed because they're C99
- * TODO: utility versions that are type-safe and not
- * just plain textual subsitution.
- */
-#ifdef _MSC_VER
-#    define snprintf(X, Y, Z, ...) _snprintf(X, Y, Z, __VA_ARGS__)
-    /* strtof doesn't exist -> strtod does though :) */
-#    define strtof(X, Y)          (float)(strtod(X, Y))
-#endif /*! _MSC_VER */
-
 /*
  * Very roboust way at determining endianess at compile time: this handles
  * almost every possible situation.  Otherwise a runtime check has to be
@@ -275,7 +267,7 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
         unsigned short     d_reclen;
         unsigned short     d_namlen;
         char               d_name[FILENAME_MAX];
-    }
+    };
 
     typedef struct {
         struct _finddata_t dd_dta;
@@ -284,6 +276,14 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
         int                dd_stat;
         char               dd_name[1];
     } DIR;
+    /*
+     * Visual studio also lacks S_ISDIR for sys/stat.h, so we emulate this as well
+     * which is not hard at all.
+     */
+#    ifdef S_ISDIR
+#        undef  S_ISDIR
+#    endif /*! S_ISDIR */
+#   define S_ISDIR(X) ((X)&_S_IFDIR)
 #else
 #   include <dirent.h>
 #endif /*! _WIN32 && !defined(__MINGW32__) */
@@ -313,8 +313,18 @@ uint16_t util_crc16(uint16_t crc, const char *data, size_t len);
 void     util_seed(uint32_t);
 uint32_t util_rand();
 
-int util_vasprintf(char **ret, const char *fmt, va_list);
-int util_asprintf (char **ret, const char *fmt, ...);
+/*
+ * String functions (formatting, copying, concatenating, errors). These are wrapped
+ * to use the MSVC _safe_ versions when using MSVC, plus some implementations of
+ * these are non-conformant or don't exist such as asprintf and snprintf, which are
+ * not supported in C90, but do exist in C99.
+ */
+int         util_vasprintf(char **ret, const char *fmt, va_list);
+int         util_asprintf (char **ret, const char *fmt, ...);
+int         util_snprintf (char *src,  size_t bytes, const char *format, ...);
+char       *util_strcat   (char *dest, const char *src);
+char       *util_strncpy  (char *dest, const char *src, size_t num);
+const char *util_strerror (int num);
 
 
 #ifdef NOTRACK
@@ -355,7 +365,7 @@ void _util_vec_grow(void **a, size_t i, size_t s);
 )
 
 /* exposed interface */
-#define vec_meta(A)       (((vector_t*)(A)) - 1)
+#define vec_meta(A)       (((vector_t*)((void*)A)) - 1)
 #define vec_free(A)       ((void)((A) ? (mem_d((void*)vec_meta(A)), (A) = NULL) : 0))
 #define vec_push(A,V)     (GMQCC_VEC_WILLGROW((A),1), (A)[vec_meta(A)->used++] = (V))
 #define vec_size(A)       ((A) ? vec_meta(A)->used : 0)
@@ -494,9 +504,9 @@ enum {
 #define CV_VAR   -1
 #define CV_WRONG  0x8000 /* magic number to help parsing */
 
-extern const char *type_name        [TYPE_COUNT];
-extern uint16_t    type_store_instr [TYPE_COUNT];
-extern uint16_t    field_store_instr[TYPE_COUNT];
+extern const char    *type_name        [TYPE_COUNT];
+extern const uint16_t type_store_instr [TYPE_COUNT];
+extern const uint16_t field_store_instr[TYPE_COUNT];
 
 /*
  * could use type_store_instr + INSTR_STOREP_F - INSTR_STORE_F
@@ -504,10 +514,10 @@ extern uint16_t    field_store_instr[TYPE_COUNT];
  * instruction set, the old ones are left untouched, thus the _I instructions
  * are at a seperate place.
  */
-extern uint16_t type_storep_instr[TYPE_COUNT];
-extern uint16_t type_eq_instr    [TYPE_COUNT];
-extern uint16_t type_ne_instr    [TYPE_COUNT];
-extern uint16_t type_not_instr   [TYPE_COUNT];
+extern const uint16_t type_storep_instr[TYPE_COUNT];
+extern const uint16_t type_eq_instr    [TYPE_COUNT];
+extern const uint16_t type_ne_instr    [TYPE_COUNT];
+extern const uint16_t type_not_instr   [TYPE_COUNT];
 
 typedef struct {
     uint32_t offset;      /* Offset in file of where data begins  */
@@ -697,32 +707,38 @@ enum {
     VINSTR_NRCALL
 };
 
-/* TODO: cleanup this mess */
-extern prog_section_statement *code_statements;
-extern int                    *code_linenums;
-extern prog_section_def       *code_defs;
-extern prog_section_field     *code_fields;
-extern prog_section_function  *code_functions;
-extern int                    *code_globals;
-extern char                   *code_chars;
-extern uint16_t code_crc;
-
 /* uhh? */
 typedef float   qcfloat;
 typedef int32_t qcint;
 
+typedef struct {
+    prog_section_statement *statements;
+    int                    *linenums;
+    prog_section_def       *defs;
+    prog_section_field     *fields;
+    prog_section_function  *functions;
+    int                    *globals;
+    char                   *chars;
+    uint16_t                crc;
+    uint32_t                entfields;
+    ht                      string_cache;
+    qcint                   string_cached_empty;
+} code_t;
+
 /*
- * code_write -- writes out the compiled file
- * code_init  -- prepares the code file
+ * code_write          -- writes out the compiled file
+ * code_init           -- prepares the code file
+ * code_genstrin       -- generates string for code
+ * code_alloc_field    -- allocated a field
+ * code_push_statement -- keeps statements and linenumbers together
+ * code_pop_statement  -- keeps statements and linenumbers together 
  */
-bool     code_write       (const char *filename, const char *lno);
-void     code_init        ();
-uint32_t code_genstring   (const char *string);
-qcint    code_alloc_field (size_t qcsize);
-
-/* this function is used to keep statements and linenumbers together */
-void     code_push_statement(prog_section_statement *stmt, int linenum);
-void     code_pop_statement();
+bool      code_write         (code_t *, const char *filename, const char *lno);
+code_t   *code_init          (void);
+uint32_t  code_genstring     (code_t *, const char *string);
+qcint     code_alloc_field   (code_t *, size_t qcsize);
+void      code_push_statement(code_t *, prog_section_statement *stmt, int linenum);
+void      code_pop_statement (code_t *);
 
 /*
  * A shallow copy of a lex_file to remember where which ast node
@@ -996,20 +1012,7 @@ void             parser_cleanup       (struct parser_s *parser);
 /*===================================================================*/
 /*====================== ftepp.c commandline ========================*/
 /*===================================================================*/
-struct lex_file_s;
 struct ftepp_s;
-
-typedef struct {
-    const char  *name;
-    char      *(*func)(struct lex_file_s *);
-} ftepp_predef_t;
-
-/*
- * line, file, counter, counter_last, random, random_last, date, time
- * increment when items are added
- */
-#define FTEPP_PREDEF_COUNT 8
-
 struct ftepp_s *ftepp_create           ();
 bool            ftepp_preprocess_file  (struct ftepp_s *ftepp, const char *filename);
 bool            ftepp_preprocess_string(struct ftepp_s *ftepp, const char *name, const char *str);
@@ -1019,8 +1022,6 @@ void            ftepp_flush            (struct ftepp_s *ftepp);
 void            ftepp_add_define       (struct ftepp_s *ftepp, const char *source, const char *name);
 void            ftepp_add_macro        (struct ftepp_s *ftepp, const char *name,   const char *value);
 
-extern const ftepp_predef_t ftepp_predefs[FTEPP_PREDEF_COUNT];
-
 /*===================================================================*/
 /*======================= main.c commandline ========================*/
 /*===================================================================*/