From aabefd1bfe0c5b08bea9341c1394cfa8b96d754d Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Wed, 14 Jan 2015 23:56:52 -0500 Subject: [PATCH] Use C++ naming for structures --- conout.cpp | 4 ++-- exec.cpp | 4 ++-- fold.cpp | 8 ++++---- ftepp.cpp | 52 +++++++++++++++++++++++----------------------------- gmqcc.h | 40 ++++++++++++++++++++-------------------- ir.cpp | 4 ++-- ir.h | 36 ++++++++++++++++++------------------ lexer.h | 27 +++++++++++---------------- main.cpp | 4 ++-- parser.h | 38 +++++++++++++++++++------------------- 10 files changed, 103 insertions(+), 114 deletions(-) diff --git a/conout.cpp b/conout.cpp index 9d0659b..98c4289 100644 --- a/conout.cpp +++ b/conout.cpp @@ -5,12 +5,12 @@ #define GMQCC_IS_STDERR(X) ((X) == stderr) #define GMQCC_IS_DEFINE(X) (GMQCC_IS_STDERR(X) || GMQCC_IS_STDOUT(X)) -typedef struct { +struct con_t { FILE *handle_err; FILE *handle_out; int color_err; int color_out; -} con_t; +}; static con_t console; diff --git a/exec.cpp b/exec.cpp index 8ec97e4..5b1fe23 100644 --- a/exec.cpp +++ b/exec.cpp @@ -633,10 +633,10 @@ const char *type_name[TYPE_COUNT] = { "noexpr" }; -typedef struct { +struct qcvm_parameter { int vtype; const char *value; -} qcvm_parameter; +}; static qcvm_parameter *main_params = NULL; diff --git a/fold.cpp b/fold.cpp index 64b20d9..a2d6339 100644 --- a/fold.cpp +++ b/fold.cpp @@ -25,20 +25,20 @@ */ typedef uint32_t sfloat_t; -typedef union { +union sfloat_cast_t { qcfloat_t f; sfloat_t s; -} sfloat_cast_t; +}; /* Exception flags */ -typedef enum { +enum sfloat_exceptionflags_t { SFLOAT_NOEXCEPT = 0, SFLOAT_INVALID = 1, SFLOAT_DIVBYZERO = 4, SFLOAT_OVERFLOW = 8, SFLOAT_UNDERFLOW = 16, SFLOAT_INEXACT = 32 -} sfloat_exceptionflags_t; +}; /* Rounding modes */ typedef enum { diff --git a/ftepp.cpp b/ftepp.cpp index 1c80d9e..2cfe4cb 100644 --- a/ftepp.cpp +++ b/ftepp.cpp @@ -7,54 +7,48 @@ #define HT_MACROS 1024 -typedef struct { +struct ppcondition { bool on; bool was_on; bool had_else; -} ppcondition; +}; -typedef struct { - int token; +struct pptoken { + int token; char *value; /* a copy from the lexer */ union { vec3_t v; - int i; + int i; double f; - int t; /* type */ + int t; /* type */ } constval; -} pptoken; +}; -typedef struct { +struct ppmacro { lex_ctx_t ctx; - - char *name; - char **params; + char *name; + char **params; /* yes we need an extra flag since `#define FOO x` is not the same as `#define FOO() x` */ - bool has_params; - bool variadic; - + bool has_params; + bool variadic; pptoken **output; -} ppmacro; +}; -typedef struct ftepp_s { - lex_file *lex; - int token; +struct ftepp_t { + lex_file *lex; + int token; unsigned int errors; - - bool output_on; + bool output_on; ppcondition *conditions; - /*ppmacro **macros;*/ - ht macros; /* hashtable */ - char *output_string; - - char *itemname; - char *includename; - bool in_macro; - + ht macros; /* hashtable */ + char *output_string; + char *itemname; + char *includename; + bool in_macro; uint32_t predef_countval; uint32_t predef_randval; -} ftepp_t; +}; /* __DATE__ */ static char *ftepp_predef_date(ftepp_t *context) { diff --git a/gmqcc.h b/gmqcc.h index 07cdddd..38aba65 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -496,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; @@ -509,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 @@ -704,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 */ diff --git a/ir.cpp b/ir.cpp index 8c3d234..5920361 100644 --- a/ir.cpp +++ b/ir.cpp @@ -199,7 +199,7 @@ static void ir_gen_extparam (ir_builder *ir); static bool ir_builder_set_name(ir_builder *self, const char *name); -static ir_function* ir_function_new(struct ir_builder_s *owner, int returntype); +static ir_function* ir_function_new(ir_builder *owner, int returntype); static bool ir_function_set_name(ir_function*, const char *name); static void ir_function_delete(ir_function*); static void ir_function_dump(ir_function*, char *ind, int (*oprintf)(const char*,...)); @@ -207,7 +207,7 @@ static void ir_function_dump(ir_function*, char *ind, int (*oprintf)( static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx_t, const char *label, int op, ir_value *a, ir_value *b, int outype); static void ir_block_delete(ir_block*); -static ir_block* ir_block_new(struct ir_function_s *owner, const char *label); +static ir_block* ir_block_new(ir_function *owner, const char *label); static bool GMQCC_WARN ir_block_create_store(ir_block*, lex_ctx_t, ir_value *target, ir_value *what); static bool ir_block_set_label(ir_block*, const char *label); static void ir_block_dump(ir_block*, char *ind, int (*oprintf)(const char*,...)); diff --git a/ir.h b/ir.h index a767a0d..7f4106e 100644 --- a/ir.h +++ b/ir.h @@ -8,11 +8,11 @@ */ typedef uint8_t ir_flag_t; -typedef struct ir_value_s ir_value; -typedef struct ir_instr_s ir_instr; -typedef struct ir_block_s ir_block; -typedef struct ir_function_s ir_function; -typedef struct ir_builder_s ir_builder; +struct ir_value; +struct ir_instr; +struct ir_block; +struct ir_function; +struct ir_builder; typedef struct { /* both inclusive */ @@ -35,7 +35,7 @@ enum { IR_FLAG_MASK_NO_LOCAL_TEMPS = (IR_FLAG_HAS_ARRAYS | IR_FLAG_HAS_UNINITIALIZED) }; -struct ir_value_s { +struct ir_value { char *name; int vtype; int store; @@ -98,32 +98,32 @@ bool ir_value_lives(ir_value*, size_t); void ir_value_dump_life(const ir_value *self, int (*oprintf)(const char*,...)); /* PHI data */ -typedef struct ir_phi_entry_s { +struct ir_phi_entry_t { ir_value *value; ir_block *from; -} ir_phi_entry_t; +}; /* instruction */ -struct ir_instr_s { - int opcode; - lex_ctx_t context; - ir_value* (_ops[3]); - ir_block* (bops[2]); +struct ir_instr { + int opcode; + lex_ctx_t context; + ir_value *(_ops[3]); + ir_block *(bops[2]); ir_phi_entry_t *phi; - ir_value **params; + ir_value **params; /* For the temp-allocation */ size_t eid; /* For IFs */ - bool likely; + bool likely; ir_block *owner; }; /* block */ -struct ir_block_s { +struct ir_block { char *label; lex_ctx_t context; bool final; /* once a jump is added we're done */ @@ -177,7 +177,7 @@ bool GMQCC_WARN ir_block_create_jump(ir_block*, lex_ctx_t, ir_block *to); bool GMQCC_WARN ir_block_create_goto(ir_block*, lex_ctx_t, ir_block *to); /* function */ -struct ir_function_s { +struct ir_function { char *name; int outtype; int *params; @@ -229,7 +229,7 @@ ir_block* ir_function_create_block(lex_ctx_t ctx, ir_function*, const char #define IR_HT_SIZE 1024 #define IR_MAX_VINSTR_TEMPS 1 -struct ir_builder_s { +struct ir_builder { char *name; ir_function **functions; ir_value **globals; diff --git a/lexer.h b/lexer.h index 73749dbf..dc180f0 100644 --- a/lexer.h +++ b/lexer.h @@ -2,20 +2,15 @@ #define GMQCC_LEXER_HDR #include "gmqcc.h" -typedef struct token_s token; - -struct token_s { +struct token { int ttype; - char *value; - union { - vec3_t v; - int i; + vec3_t v; + int i; qcfloat_t f; - int t; /* type */ + int t; /* type */ } constval; - lex_ctx_t ctx; }; @@ -66,12 +61,12 @@ enum { TOKEN_FATAL /* internal error, eg out of memory */ }; -typedef struct { +struct frame_macro { char *name; - int value; -} frame_macro; + int value; +}; -typedef struct lex_file_s { +struct lex_file { FILE *file; const char *open_string; size_t open_string_length; @@ -101,7 +96,7 @@ typedef struct lex_file_s { char *modelname; size_t push_line; -} lex_file; +}; lex_file* lex_open (const char *file); lex_file* lex_open_string(const char *str, size_t len, const char *name); @@ -121,7 +116,7 @@ enum { #define OP_SUFFIX 1 #define OP_PREFIX 2 -typedef struct { +struct oper_info { const char *op; unsigned int operands; unsigned int id; @@ -129,7 +124,7 @@ typedef struct { signed int prec; unsigned int flags; bool folds; -} oper_info; +}; /* * Explicit uint8_t casts since the left operand of shift operator cannot diff --git a/main.cpp b/main.cpp index ac715d5..c0868f8 100644 --- a/main.cpp +++ b/main.cpp @@ -520,8 +520,8 @@ int main(int argc, char **argv) { bool operators_free = false; bool progs_src = false; FILE *outfile = NULL; - struct parser_s *parser = NULL; - struct ftepp_s *ftepp = NULL; + parser_t *parser = NULL; + ftepp_t *ftepp = NULL; app_name = argv[0]; con_init (); diff --git a/parser.h b/parser.h index 43ebe6f..7f07bdf 100644 --- a/parser.h +++ b/parser.h @@ -4,26 +4,26 @@ #include "lexer.h" #include "ast.h" -typedef struct intrin_s intrin_t; -typedef struct parser_s parser_t; - -typedef struct { - struct parser_s *parser; - ast_value **imm_float; /* vector */ - ast_value **imm_vector; /* vector */ - ast_value **imm_string; /* vector */ - hash_table_t *imm_string_untranslate; /* map */ - hash_table_t *imm_string_dotranslate; /* map */ -} fold_t; - -typedef struct { +struct parser_t; +struct intrin_t; + +struct fold_t { + parser_t *parser; + ast_value **imm_float; /* vector */ + ast_value **imm_vector; /* vector */ + ast_value **imm_string; /* vector */ + hash_table_t *imm_string_untranslate; /* map */ + hash_table_t *imm_string_dotranslate; /* map */ +}; + +struct intrin_func_t { ast_expression *(*intrin)(intrin_t *); - const char *name; - const char *alias; - size_t args; -} intrin_func_t; + const char *name; + const char *alias; + size_t args; +}; -struct intrin_s { +struct intrin_t { intrin_func_t *intrinsics; /* vector */ ast_expression **generated; /* vector */ parser_t *parser; @@ -32,7 +32,7 @@ struct intrin_s { #define parser_ctx(p) ((p)->lex->tok.ctx) -struct parser_s { +struct parser_t { lex_file *lex; int tok; -- 2.39.2