changeset 3495:174e9c75bb24 trunk

Miscellaneous code cleanups; Support "(empty)?" expression.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 05 Sep 2007 03:29:19 +0300
parents 7d1dee4f660a
children 1590c8f4ffa9
files src/audacious/tuple_compiler.c
diffstat 1 files changed, 21 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/tuple_compiler.c	Wed Sep 05 03:28:30 2007 +0300
+++ b/src/audacious/tuple_compiler.c	Wed Sep 05 03:29:19 2007 +0300
@@ -25,7 +25,7 @@
  * - implement handling of external expressions
  * - error handling issues?
  * - evaluation context: how local variables should REALLY work?
- * - global context needed (?)
+ *   currently there is just a single context, is a "global" context needed?
  */
 
 #include "config.h"
@@ -412,6 +412,19 @@
           case '(': c++;
             if (!strncmp(c, "empty)?", 7)) {
               c += 7;
+              literal = FALSE;
+              if (tc_get_item(&c, tmps1, MAX_STR, ':', &literal, "tag", item)) {
+                c++;
+                tmp = tuple_evalnode_new();
+                tmp->opcode = OP_EXISTS;
+                if ((tmp->var[0] = tc_get_variable(ctx, tmps1, VAR_FIELD)) < 0) {
+                  tuple_error("Invalid variable '%s' in '%s'.\n", tmps1, expr);
+                  goto ret_error;
+                }
+                tmp->children = tuple_compiler_pass1(level, ctx, &c);
+                tuple_evalnode_insert(&res, tmp);
+              } else
+                goto ret_error;
             } else
               goto ext_expression;
             break;
@@ -499,7 +512,6 @@
 static TupleEvalNode *tuple_compiler_pass2(gboolean *changed, TupleEvalContext *ctx, TupleEvalNode *expr)
 {
   TupleEvalNode *curr = expr, *res = NULL;
-  *changed = FALSE;
   assert(ctx != NULL);
   assert(expr != NULL);
   
@@ -660,11 +672,13 @@
             case OP_LTEQ:       result = (resulti <= 0); break;
             case OP_GT:         result = (resulti >  0); break;
             case OP_GTEQ:       result = (resulti >= 0); break;
-            default: result = FALSE;
+            default:		result = FALSE;
           }
             
           if (result && !tuple_formatter_eval_do(ctx, curr->children, tuple, res, resmax, reslen))
             return FALSE;
+        } else {
+          /* FIXME?! Warn that types are not same? */
         }
         break;
       
@@ -673,7 +687,7 @@
 
         if (tf_get_fieldref(var0, tuple)) {
 
-        switch (var0->fieldref->type) {
+          switch (var0->fieldref->type) {
           case TUPLE_INT:
             result = (var0->fieldref->value.integer == 0);
             break;
@@ -692,14 +706,12 @@
 
           default:
             result = TRUE;
-        }
+          }
         } else
           result = TRUE;
         
-        if (result) {
-          if (!tuple_formatter_eval_do(ctx, curr->children, tuple, res, resmax, reslen))
-            return FALSE;
-        }
+        if (result && !tuple_formatter_eval_do(ctx, curr->children, tuple, res, resmax, reslen))
+          return FALSE;
         break;
       
       default: