static void dump(grib_action* act, FILE* f, int lvl) { grib_action_if* a = (grib_action_if*)act; int i = 0; for (i=0;i<lvl;i++) grib_context_print(act->context,f," "); printf("if(%s) { ",act->name); grib_expression_print(act->context,a->expression,0); printf("\n"); if(a->block_true){ /* grib_context_print(act->context,f,"IF \t TODO \n"); TODO */ grib_dump_action_branch(f,a->block_true,lvl+1); } if(a->block_false){ printf("}\n"); for (i=0;i<lvl;i++) grib_context_print(act->context,f," "); printf("else(%s) { ",act->name); grib_expression_print(act->context,a->expression,0); /* grib_context_print(act->context,f,"ELSE \n" );*/ grib_dump_action_branch(f,a->block_false,lvl+1); } for (i=0;i<lvl;i++) grib_context_print(act->context,f," "); printf("}\n"); }
static void print(grib_context* c,grib_expression* g,grib_handle* f) { grib_expression_binop* e = (grib_expression_binop*)g; printf("binop("); grib_expression_print(c,e->left,f); printf(","); grib_expression_print(c,e->right,f); printf(")"); }
static void print(grib_context* c,grib_expression* g,grib_handle* f) { grib_expression_string_compare* e = (grib_expression_string_compare*)g; printf("string_compare("); grib_expression_print(c,e->left,f); printf(","); grib_expression_print(c,e->right,f); printf(")"); }
static int evaluate_long(grib_expression *g,grib_handle* h,long* lres) { long v1=0; long v2=0; int ret; grib_expression_binop* e = (grib_expression_binop*)g; #if 0 /* DEBUGGING */ { int typeLeft, typeRight; const char* nameLeft; const char* nameRight; typeLeft = grib_expression_native_type(h, e->left); typeRight = grib_expression_native_type(h, e->right); nameLeft = grib_expression_get_name(e->left); nameRight= grib_expression_get_name(e->right); printf("eval_long nameLeft=%s (type=%d), nameRight=%s (type=%d)\n",nameLeft,typeLeft, nameRight,typeRight); grib_expression_print(h->context, g, h); printf("\n"); } #endif ret = grib_expression_evaluate_long(h,e->left,&v1); if (ret != GRIB_SUCCESS) return ret; ret = grib_expression_evaluate_long(h,e->right,&v2); if (ret != GRIB_SUCCESS) return ret; *lres=e->long_func(v1,v2); return GRIB_SUCCESS; }
static void print(grib_context* c,grib_expression* g,grib_handle* f) { grib_expression_unop* e = (grib_expression_unop*)g; printf("unop("); grib_expression_print(c,e->exp,f); printf(")"); }
static int create_accessor( grib_section* p, grib_action* act, grib_loader *h) { grib_action_if* a = (grib_action_if*)act; grib_action* next = NULL; int ret = 0; long lres=0; grib_accessor* as = NULL; grib_section* gs = NULL; as = grib_accessor_factory(p, act,0,NULL); if(!as)return GRIB_INTERNAL_ERROR; gs = as->sub_section; grib_push_accessor(as,p->block); if ((ret=grib_expression_evaluate_long(p->h,a->expression,&lres)) != GRIB_SUCCESS) return ret; if(lres) next = a->block_true; else next = a->block_false; if(p->h->context->debug > 1) { printf("EVALUATE create_accessor_handle "); grib_expression_print(p->h->context,a->expression,p->h); printf(" [%s][_if%p]\n", (next == a->block_true ? "true":"false"), (void*)a); /*grib_dump_action_branch(stdout,next,5);*/ } gs->branch = next; grib_dependency_observe_expression(as,a->expression); while(next){ ret = grib_create_accessor(gs, next, h); if(ret != GRIB_SUCCESS) return ret; next= next->next; } return GRIB_SUCCESS; }