]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ftepp.c
Fold for div op
[xonotic/gmqcc.git] / ftepp.c
diff --git a/ftepp.c b/ftepp.c
index 723ec6afff3d3ebe82eab43c1b5c51207d1473f4..3f45bc22d8b6d120eccfd3d7bf5f7acee3b513fb 100644 (file)
--- a/ftepp.c
+++ b/ftepp.c
@@ -41,7 +41,7 @@ typedef struct {
     char *value;
     /* a copy from the lexer */
     union {
-        vector v;
+        vec3_t v;
         int    i;
         double f;
         int    t; /* type */
@@ -49,7 +49,7 @@ typedef struct {
 } pptoken;
 
 typedef struct {
-    lex_ctx ctx;
+    lex_ctx_t ctx;
 
     char   *name;
     char  **params;
@@ -132,14 +132,14 @@ static char *ftepp_predef_time(lex_file *context) {
 /* __LINE__ */
 static char *ftepp_predef_line(lex_file *context) {
     char   *value;
-    util_asprintf(&value, "%d", (int)context->ctx.line);
+    util_asprintf(&value, "%d", (int)context->line);
     return value;
 }
 /* __FILE__ */
 static char *ftepp_predef_file(lex_file *context) {
-    size_t  length = strlen(context->ctx.file) + 3; /* two quotes and a terminator */
+    size_t  length = strlen(context->name) + 3; /* two quotes and a terminator */
     char   *value  = (char*)mem_a(length);
-    util_snprintf(value, length, "\"%s\"", context->ctx.file);
+    util_snprintf(value, length, "\"%s\"", context->name);
 
     return value;
 }
@@ -183,7 +183,7 @@ static char *ftepp_predef_timestamp(lex_file *context) {
     char       *find;
     char       *value;
     size_t      size;
-    if (stat(context->ctx.file, &finfo))
+    if (stat(context->name, &finfo))
         return util_strdup("\"<failed to determine timestamp>\"");
 
     /*
@@ -239,14 +239,14 @@ static GMQCC_INLINE char *(*ftepp_predef(const char *name))(lex_file *context) {
 #define ftepp_tokval(f) ((f)->lex->tok.value)
 #define ftepp_ctx(f)    ((f)->lex->tok.ctx)
 
-static void ftepp_errorat(ftepp_t *ftepp, lex_ctx *ctx, const char *fmt, ...)
+static void ftepp_errorat(ftepp_t *ftepp, lex_ctx_t ctx, const char *fmt, ...)
 {
     va_list ap;
 
     ftepp->errors++;
 
     va_start(ap, fmt);
-    con_cvprintmsg((void*)ctx, LVL_ERROR, "error", fmt, ap);
+    con_cvprintmsg(ctx, LVL_ERROR, "error", fmt, ap);
     va_end(ap);
 }
 
@@ -257,7 +257,7 @@ static void ftepp_error(ftepp_t *ftepp, const char *fmt, ...)
     ftepp->errors++;
 
     va_start(ap, fmt);
-    con_cvprintmsg((void*)&ftepp->lex->tok.ctx, LVL_ERROR, "error", fmt, ap);
+    con_cvprintmsg(ftepp->lex->tok.ctx, LVL_ERROR, "error", fmt, ap);
     va_end(ap);
 }
 
@@ -267,7 +267,7 @@ static bool GMQCC_WARN ftepp_warn(ftepp_t *ftepp, int warntype, const char *fmt,
     va_list ap;
 
     va_start(ap, fmt);
-    r = vcompile_warning(*(ftepp->lex->tok.ctx), warntype, fmt, ap);
+    r = vcompile_warning(ftepp->lex->tok.ctx, warntype, fmt, ap);
     va_end(ap);
     return r;
 }
@@ -293,7 +293,7 @@ static GMQCC_INLINE void pptoken_delete(pptoken *self)
     mem_d(self);
 }
 
-static ppmacro *ppmacro_new(lex_ctx ctx, const char *name)
+static ppmacro *ppmacro_new(lex_ctx_t ctx, const char *name)
 {
     ppmacro *macro = (ppmacro*)mem_a(sizeof(ppmacro));
 
@@ -524,7 +524,7 @@ static bool ftepp_define_body(ftepp_t *ftepp, ppmacro *macro)
 static bool ftepp_define(ftepp_t *ftepp)
 {
     ppmacro *macro = NULL;
-    size_t l = ftepp_ctx(ftepp)->line;
+    size_t l = ftepp_ctx(ftepp).line;
 
     (void)ftepp_next(ftepp);
     if (!ftepp_skipspace(ftepp))
@@ -540,7 +540,7 @@ static bool ftepp_define(ftepp_t *ftepp)
                     return false;
                 ftepp_macro_delete(ftepp, ftepp_tokval(ftepp));
             }
-            macro = ppmacro_new(*ftepp_ctx(ftepp), ftepp_tokval(ftepp));
+            macro = ppmacro_new(ftepp_ctx(ftepp), ftepp_tokval(ftepp));
             break;
         default:
             ftepp_error(ftepp, "expected macro name");
@@ -573,7 +573,7 @@ static bool ftepp_define(ftepp_t *ftepp)
         ppmacro_delete(macro);
     }
 
-    for (; l < ftepp_ctx(ftepp)->line; ++l)
+    for (; l < ftepp_ctx(ftepp).line; ++l)
         ftepp_out(ftepp, "\n", true);
     return true;
 }
@@ -840,16 +840,16 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param
     /*
     printf("__________\n%s\n=========\n", ftepp->output_string);
     */
-    inlex = lex_open_string(ftepp->output_string, vec_size(ftepp->output_string)-1, ftepp->lex->ctx.file);
+    inlex = lex_open_string(ftepp->output_string, vec_size(ftepp->output_string)-1, ftepp->lex->name);
     if (!inlex) {
         ftepp_error(ftepp, "internal error: failed to instantiate lexer");
         retval = false;
         goto cleanup;
     }
 
-    inlex->sline    = ftepp->lex->sline;
-    inlex->ctx.line = ftepp->lex->ctx.line;
-    ftepp->lex      = inlex;
+    inlex->line  = ftepp->lex->line;
+    inlex->sline = ftepp->lex->sline;
+    ftepp->lex   = inlex;
 
     old_inmacro     = ftepp->in_macro;
     ftepp->in_macro = true;
@@ -1406,7 +1406,7 @@ static void ftepp_directive_message(ftepp_t *ftepp) {
         }
         vec_push(message, '\0');
         if (ftepp->output_on)
-            con_cprintmsg(&ftepp->lex->tok.ctx, LVL_MSG, "message", message);
+            con_cprintmsg(ftepp->lex->tok.ctx, LVL_MSG, "message", message);
         vec_free(message);
         return;
     }
@@ -1415,7 +1415,7 @@ static void ftepp_directive_message(ftepp_t *ftepp) {
         return;
 
     unescape     (ftepp_tokval(ftepp), ftepp_tokval(ftepp));
-    con_cprintmsg(&ftepp->lex->tok.ctx, LVL_MSG, "message",  ftepp_tokval(ftepp));
+    con_cprintmsg(ftepp->lex->tok.ctx, LVL_MSG, "message",  ftepp_tokval(ftepp));
 }
 
 /**
@@ -1427,7 +1427,7 @@ static bool ftepp_include(ftepp_t *ftepp)
 {
     lex_file *old_lexer = ftepp->lex;
     lex_file *inlex;
-    lex_ctx  ctx;
+    lex_ctx_t ctx;
     char     lineno[128];
     char     *filename;
     char     *old_includename;
@@ -1446,7 +1446,7 @@ static bool ftepp_include(ftepp_t *ftepp)
         return true;
     }
 
-    ctx = *ftepp_ctx(ftepp);
+    ctx = ftepp_ctx(ftepp);
 
     unescape(ftepp_tokval(ftepp), ftepp_tokval(ftepp));
 
@@ -1517,7 +1517,7 @@ static bool ftepp_hash(ftepp_t *ftepp)
     ppcondition cond;
     ppcondition *pc;
 
-    lex_ctx *ctx = ftepp_ctx(ftepp);
+    lex_ctx_t ctx = ftepp_ctx(ftepp);
 
     if (!ftepp_skipspace(ftepp))
         return false;
@@ -1878,7 +1878,7 @@ ftepp_t *ftepp_create()
 void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name)
 {
     ppmacro *macro;
-    lex_ctx ctx = { "__builtin__", 0, 0 };
+    lex_ctx_t ctx = { "__builtin__", 0, 0 };
     ctx.file = source;
     macro = ppmacro_new(ctx, name);
     /*vec_push(ftepp->macros, macro);*/