GRIB-394:grib_filter further fixes required because of mixed types in IF statement

This commit is contained in:
Shahram Najm 2013-08-14 16:06:12 +01:00
parent cabc6994b0
commit 40fa5272df
3 changed files with 214 additions and 191 deletions

View File

@ -11,7 +11,7 @@
#include <stdarg.h>
#include "grib_api_internal.h"
int grib_expression_native_type(grib_handle* h,grib_expression* g)
int grib_expression_native_type(grib_handle* h,grib_expression* g)
{
grib_expression_class *c = g->cclass;
while(c)
@ -26,7 +26,7 @@
}
int grib_expression_evaluate_long(grib_handle* h,grib_expression* g,long* result)
int grib_expression_evaluate_long(grib_handle* h,grib_expression* g,long* result)
{
grib_expression_class *c = g->cclass;
while(c)
@ -38,7 +38,7 @@
return GRIB_INVALID_TYPE;
}
int grib_expression_evaluate_double(grib_handle* h,grib_expression* g,double* result)
int grib_expression_evaluate_double(grib_handle* h,grib_expression* g,double* result)
{
grib_expression_class *c = g->cclass;
while(c)
@ -50,7 +50,7 @@
return GRIB_INVALID_TYPE;
}
const char* grib_expression_evaluate_string(grib_handle* h,grib_expression* g,char* buf, size_t* size, int *err)
const char* grib_expression_evaluate_string(grib_handle* h,grib_expression* g,char* buf, size_t* size, int *err)
{
grib_expression_class *c = g->cclass;
while(c)
@ -65,7 +65,7 @@
return 0;
}
const char* grib_expression_get_name(grib_expression* g)
const char* grib_expression_get_name(grib_expression* g)
{
grib_expression_class *c = g->cclass;
while(c)
@ -79,7 +79,7 @@
return 0;
}
void grib_expression_print(grib_context* ctx,grib_expression* g,grib_handle* f)
void grib_expression_print(grib_context* ctx,grib_expression* g,grib_handle* f)
{
grib_expression_class *c = g->cclass;
while(c)
@ -92,10 +92,9 @@
c = c->super ? *(c->super) : NULL;
}
Assert(1==0);
}
void grib_expression_compile(grib_expression* g,grib_compiler* f)
void grib_expression_compile(grib_expression* g,grib_compiler* f)
{
grib_expression_class *c = g->cclass;
if(!c->compile)
@ -116,7 +115,7 @@
}
void grib_expression_free(grib_context* ctx,grib_expression* g)
void grib_expression_free(grib_context* ctx,grib_expression* g)
{
grib_expression_class *c = g->cclass;
while(c)
@ -129,7 +128,7 @@
}
void grib_expression_add_dependency(grib_expression* e, grib_accessor* observer)
void grib_expression_add_dependency(grib_expression* e, grib_accessor* observer)
{
grib_expression_class *c = e->cclass;
while(c)
@ -213,7 +212,7 @@ void grib_arguments_print(grib_context* c,grib_arguments* g,grib_handle* f)
}
}
const char *grib_arguments_get_name(grib_handle *h, grib_arguments *args, int n)
const char *grib_arguments_get_name(grib_handle *h, grib_arguments *args, int n)
{
grib_expression *e = NULL;
while(args && n-->0) {args = args->next;}
@ -224,8 +223,7 @@ void grib_arguments_print(grib_context* c,grib_arguments* g,grib_handle* f)
return e ? grib_expression_get_name(e) : NULL;
}
const char* grib_arguments_get_string(grib_handle* h,grib_arguments* args,int n)
const char* grib_arguments_get_string(grib_handle* h,grib_arguments* args,int n)
{
grib_expression *e = NULL;
int ret=0;
@ -237,7 +235,7 @@ void grib_arguments_print(grib_context* c,grib_arguments* g,grib_handle* f)
return grib_expression_evaluate_string(h,e,NULL,NULL,&ret);
}
long grib_arguments_get_long(grib_handle* h,grib_arguments* args,int n)
long grib_arguments_get_long(grib_handle* h,grib_arguments* args,int n)
{
int ret=0;
long lres=0;
@ -249,10 +247,9 @@ void grib_arguments_print(grib_context* c,grib_arguments* g,grib_handle* f)
e = args->expression;
ret = grib_expression_evaluate_long(h,e,&lres);
return lres;
}
double grib_arguments_get_double(grib_handle* h,grib_arguments* args,int n)
double grib_arguments_get_double(grib_handle* h,grib_arguments* args,int n)
{
int ret=0;
double dres=0.0;
@ -268,7 +265,7 @@ void grib_arguments_print(grib_context* c,grib_arguments* g,grib_handle* f)
}
grib_expression* grib_arguments_get_expression(grib_handle* h,grib_arguments* args,int n)
grib_expression* grib_arguments_get_expression(grib_handle* h,grib_arguments* args,int n)
{
while(args && n-->0) {args = args->next;}
@ -276,7 +273,3 @@ void grib_arguments_print(grib_context* c,grib_arguments* g,grib_handle* f)
return args->expression;
}

View File

@ -103,6 +103,21 @@ static int evaluate_long(grib_expression *g,grib_handle* h,long* lres)
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;
@ -121,6 +136,21 @@ static int evaluate_double(grib_expression *g,grib_handle* h,double* dres)
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_dbl 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_double(h,e->left,&v1);
if (ret != GRIB_SUCCESS) return ret;
@ -191,5 +221,5 @@ static int native_type(grib_expression* g,grib_handle *h)
{
return GRIB_TYPE_DOUBLE;
}
return e->double_func ? GRIB_TYPE_LONG : GRIB_TYPE_DOUBLE;
return e->long_func ? GRIB_TYPE_LONG : GRIB_TYPE_DOUBLE;
}

View File

@ -161,5 +161,5 @@ static void compile(grib_expression* g,grib_compiler* c)
static int native_type(grib_expression* g,grib_handle *h)
{
grib_expression_unop* e = (grib_expression_unop*)g;
return e->double_func ? GRIB_TYPE_DOUBLE : GRIB_TYPE_LONG;
return e->long_func ? GRIB_TYPE_LONG : GRIB_TYPE_DOUBLE;
}