X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=gmqcc.h;h=38aba65aaa2b0edcd9d4934003188f3b0dc99d42;hp=a6b5b1ff54ccb06e6a395b680fb1364ed6b07f5b;hb=aabefd1bfe0c5b08bea9341c1394cfa8b96d754d;hpb=0a00807e57ee1c84b3c0e8105c3e735bfebd7965 diff --git a/gmqcc.h b/gmqcc.h index a6b5b1f..38aba65 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -1,26 +1,3 @@ -/* - * Copyright (C) 2012, 2013, 2014, 2015 - * Dale Weiler - * Wolfgang Bumiller - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ #ifndef GMQCC_HDR #define GMQCC_HDR #include @@ -186,23 +163,9 @@ char *stat_mem_strdup(const char *, bool); #define mem_d(PTRN) free((void*)PTRN) #define mem_r(PTRN, SIZE) realloc((void*)PTRN, SIZE) -/* TODO: rename to mem variations */ #define util_strdup(SRC) stat_mem_strdup((char*)(SRC), false) #define util_strdupe(SRC) stat_mem_strdup((char*)(SRC), true) -/* util.c */ - -/* - * Microsoft implements against the spec versions of ctype.h. Which - * means what ever the current set locale is will render the actual - * results of say isalpha('A') wrong for what ever retarded locale - * is used. Simalerly these are also implemented inefficently on - * some toolchains and end up becoming actual library calls. Perhaps - * this is why tools like yacc provide their own? Regardless implementing - * these as functions is equally as silly, the call overhead is not - * justified when this could happen on every character from an input - * stream. We provide our own as macros for absolute inlinability. - */ #define util_isalpha(a) ((((unsigned)(a)|32)-'a') < 26) #define util_isdigit(a) (((unsigned)(a)-'0') < 10) #define util_islower(a) (((unsigned)(a)-'a') < 26) @@ -279,36 +242,6 @@ typedef struct hash_table_s { struct hash_node_t **table; } hash_table_t, *ht; -/* - * hashtable implementation: - * - * Note: - * This was designed for pointers: you manage the life of the object yourself - * if you do use this for non-pointers please be warned that the object may not - * be valid if the duration of it exceeds (i.e on stack). So you need to allocate - * yourself, or put those in global scope to ensure duration is for the whole - * runtime. - * - * util_htnew(size) -- to make a new hashtable - * util_htset(table, key, value, sizeof(value)) -- to set something in the table - * util_htget(table, key) -- to get something from the table - * util_htdel(table) -- to delete the table - * - * example of use: - * - * ht foo = util_htnew(1024); - * int data = 100; - * char *test = "hello world\n"; - * util_htset(foo, "foo", (void*)&data); - * util_gtset(foo, "bar", (void*)test); - * - * printf("foo: %d, bar %s", - * *((int *)util_htget(foo, "foo")), - * ((char*)util_htget(foo, "bar")) - * ); - * - * util_htdel(foo); - */ hash_table_t *util_htnew (size_t size); void util_htrem(hash_table_t *ht, void (*callback)(void *data)); void util_htset(hash_table_t *ht, const char *key, void *value); @@ -401,34 +334,16 @@ typedef struct { #define OFS_PARM6 (OFS_PARM5 +3) #define OFS_PARM7 (OFS_PARM6 +3) +typedef union { + int16_t s1; + uint16_t u1; +} operand_t; + typedef struct { uint16_t opcode; - - /* operand 1 */ - union { - int16_t s1; /* signed */ - uint16_t u1; /* unsigned */ - } o1; - /* operand 2 */ - union { - int16_t s1; /* signed */ - uint16_t u1; /* unsigned */ - } o2; - /* operand 3 */ - union { - int16_t s1; /* signed */ - uint16_t u1; /* unsigned */ - } o3; - - /* - * This is the same as the structure in darkplaces - * { - * unsigned short op; - * short a,b,c; - * } - * But this one is more sane to work with, and the - * type sizes are guranteed. - */ + operand_t o1; + operand_t o2; + operand_t o3; } prog_section_statement_t; typedef struct { @@ -581,7 +496,7 @@ typedef float qcfloat_t; typedef int32_t qcint_t; typedef uint32_t qcuint_t; -typedef struct { +struct code_t { prog_section_statement_t *statements; int *linenums; int *columnnums; @@ -594,17 +509,17 @@ typedef struct { uint32_t entfields; ht string_cache; qcint_t string_cached_empty; -} code_t; +}; /* * A shallow copy of a lex_file to remember where which ast node * came from. */ -typedef struct { +struct lex_ctx_t { const char *file; size_t line; size_t column; -} lex_ctx_t; +}; /* * code_write -- writes out the compiled file @@ -789,27 +704,27 @@ const char* prog_getstring (qc_program_t *prog, qcint_t str); prog_section_def_t* prog_entfield (qc_program_t *prog, qcint_t off); prog_section_def_t* prog_getdef (qc_program_t *prog, qcint_t off); qcany_t* prog_getedict (qc_program_t *prog, qcint_t e); -qcint_t prog_tempstring(qc_program_t *prog, const char *_str); +qcint_t prog_tempstring(qc_program_t *prog, const char *_str); /* parser.c */ -struct parser_s; -struct parser_s *parser_create (void); -bool parser_compile_file (struct parser_s *parser, const char *); -bool parser_compile_string(struct parser_s *parser, const char *, const char *, size_t); -bool parser_finish (struct parser_s *parser, const char *); -void parser_cleanup (struct parser_s *parser); +struct parser_t; +parser_t *parser_create(void); +bool parser_compile_file(parser_t *parser, const char *); +bool parser_compile_string(parser_t *parser, const char *, const char *, size_t); +bool parser_finish(parser_t *parser, const char *); +void parser_cleanup(parser_t *parser); /* ftepp.c */ -struct ftepp_s; -struct ftepp_s *ftepp_create (void); -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); -void ftepp_finish (struct ftepp_s *ftepp); -const char *ftepp_get (struct ftepp_s *ftepp); -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); +struct ftepp_t; +ftepp_t *ftepp_create (void); +bool ftepp_preprocess_file (ftepp_t *ftepp, const char *filename); +bool ftepp_preprocess_string(ftepp_t *ftepp, const char *name, const char *str); +void ftepp_finish(ftepp_t *ftepp); +const char *ftepp_get(ftepp_t *ftepp); +void ftepp_flush(ftepp_t *ftepp); +void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name); +void ftepp_add_macro(ftepp_t *ftepp, const char *name, const char *value); /* main.c */