From f2ca497038efc19e24d32554b589419cf3a687f9 Mon Sep 17 00:00:00 2001 From: sbrandt Date: Mon, 6 May 2013 20:27:24 +0000 Subject: Closing tickets #1290, #1328, #1324 git-svn-id: http://svn.cactuscode.org/flesh/trunk@5002 17b73243-c579-4c4c-a9d2-2d5706c11dac --- src/main/Parameters.c | 23 +++++++++----- src/piraha/Call.cc | 87 +++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 79 insertions(+), 31 deletions(-) diff --git a/src/main/Parameters.c b/src/main/Parameters.c index 09b3c8b8..01017d38 100644 --- a/src/main/Parameters.c +++ b/src/main/Parameters.c @@ -868,6 +868,15 @@ char *CCTK_ParameterValString (const char *param_name, const char *thorn) return (retval); } +const int slen(const char *s) { + int n = 0; + while(*s != '\0') { + s++; + n++; + } + return n; +} + /*@@ @routine CCTK_PARAMETERVALSTRING @date Thu Jan 21 2000 @@ -910,7 +919,7 @@ void CCTK_FCALL CCTK_FNAME (CCTK_ParameterValString) c_string = CCTK_ParameterValString (param, thorn); if (c_string) { - *nchars = c_strlen = strlen (c_string); + *nchars = c_strlen = slen (c_string); if (c_strlen > (size_t) cctk_strlen3) { CCTK_VWarn (1, __LINE__, __FILE__, "Cactus", @@ -1081,8 +1090,8 @@ int CCTK_ParameterWalk (int first, prefix = CCTK_ThornImplementation (prefix); } - *pfullname = malloc (strlen (prefix) + - strlen (startpoint->props->name) + 3); + *pfullname = malloc (slen (prefix) + + slen (startpoint->props->name) + 3); if(*pfullname) { sprintf (*pfullname, "%s::%s", @@ -2299,7 +2308,7 @@ static int ParameterSetReal (t_param *param, const char *value) * to do the actual conversion) only groks [eE]. */ temp = strdup (value); - for (unsigned int p = 0; p < strlen (temp); p++) + for (unsigned int p = 0; p < slen (temp); p++) { if (temp[p] == 'E' || temp[p] == 'd' || temp[p] == 'D') { @@ -2490,7 +2499,7 @@ static void GetBaseName(const char *name, char **basename, int *array_index) } else { - baselen = strlen(name); + baselen = slen(name); *array_index = -1; } @@ -2533,7 +2542,7 @@ static char *ArrayParamName(const char *basename,int array_index) char *retval; /* Assume the string representation of an integer is no greater than 40 chars */ - retval = (char *)malloc(strlen(basename)+2+40+1); + retval = (char *)malloc(slen(basename)+2+40+1); if(retval) { @@ -2742,7 +2751,7 @@ static int SetVarEvaluator(int nvars, const char * const *vars, uExpressionValue * to do the actual conversion) only groks [eE]. */ temp = strdup (vars[i]); - for (unsigned int p = 0; p < strlen (temp); p++) + for (unsigned int p = 0; p < slen (temp); p++) { if (temp[p] == 'E' || temp[p] == 'd' || temp[p] == 'D') { diff --git a/src/piraha/Call.cc b/src/piraha/Call.cc index 3f507b93..5c3b5757 100644 --- a/src/piraha/Call.cc +++ b/src/piraha/Call.cc @@ -10,6 +10,7 @@ #include #include #include +#include namespace piraha { @@ -208,7 +209,6 @@ std::ostream& operator<<(std::ostream& o,const smart_ptr& val) { return o; } -std::map > > values; typedef std::map > >::iterator th_iter; typedef std::map >::iterator nm_iter; @@ -216,21 +216,47 @@ smart_ptr eval_expr(std::string inp); // If the value was already defined in this parameter file, look // it up in the map. Otherwise, get it from Cactus. -smart_ptr find_val(std::string thorn,std::string name) { - smart_ptr ret; - th_iter th = values.find(thorn); - if(th != values.end()) { - nm_iter nm = th->second.find(name); - if(nm != th->second.end()) { - ret = nm->second; - return ret; - } - } - const cParamData *data = CCTK_ParameterData(name.c_str(),thorn.c_str()); - if(data != NULL) { - std::string expr = data->defval; - ret = eval_expr(expr); - } +smart_ptr find_val(smart_ptr gr,std::string thorn,std::string name) { + smart_ptr ret = new Value(gr); + int type; + const void *result; + result = CCTK_ParameterGet(name.c_str(),thorn.c_str(),&type); + if(result == NULL) { + std::ostringstream msg; + msg << "Undefined or inaccessible variable: " << thorn << "::" << name << std::endl; + std::string par = get_parfile(); + CCTK_Error(gr->line(),par.c_str(),current_thorn.c_str(),msg.str().c_str()); + } + + switch(type) { + case PARAMETER_REAL: + ret->type = PIR_REAL; + ret->ddata = *(const CCTK_REAL*)result; + break; + case PARAMETER_INT: + ret->type = PIR_INT; + ret->idata = *(const CCTK_INT*)result; + break; + case PARAMETER_BOOLEAN: + ret->type = PIR_BOOL; + ret->idata = *(const CCTK_INT*)result; + break; + case PARAMETER_STRING: + case PARAMETER_SENTENCE: + case PARAMETER_KEYWORD: + { + ret->type = PIR_STRING; + const char *s = *(const char **)result; + ret->sdata += s; + } + break; + default: + std::ostringstream msg; + msg << "Unexpected type result from ParameterGet=" << type << std::endl; + std::string par = get_parfile(); + CCTK_Error(gr->line(),par.c_str(),current_thorn.c_str(),msg.str().c_str()); + } + //std::cout << "Piraha: GET: " << thorn << "::" << name << "=" << ret << std::endl; return ret; } @@ -425,11 +451,11 @@ smart_ptr meval(smart_ptr gr) { o << name << "[" << index->idata << "]"; o << std::flush; std::string keyi = o.str(); - ret = find_val(thorn,keyi); + ret = find_val(gr,thorn,keyi); return ret; } } else { - ret = find_val(thorn,name); + ret = find_val(gr,thorn,name); return ret; } std::ostringstream msg; @@ -573,9 +599,11 @@ smart_ptr meval(smart_ptr gr) { ret->sdata = v1->sdata + v2->sdata; } else { std::ostringstream msg; + ret->sdata = v1->sdata + addop + v2->sdata; msg << "Unknown add operator: " << addop << std::endl; + msg << "Interpreting as literal string with value '" << ret->sdata << "'" << std::endl; std::string par = get_parfile(); - CCTK_Error(gr->line(),par.c_str(),current_thorn.c_str(),msg.str().c_str()); + CCTK_Warn(1,gr->line(),par.c_str(),current_thorn.c_str(),msg.str().c_str()); } } else if(v1->intOrDouble() && v2->intOrDouble()) { ret->type = PIR_REAL; @@ -643,6 +671,14 @@ smart_ptr meval(smart_ptr gr) { std::string par = get_parfile(); CCTK_Error(gr->line(),par.c_str(),current_thorn.c_str(),msg.str().c_str()); } + } else if(v1->type == PIR_STRING && v2->type == PIR_STRING) { + std::ostringstream msg; + ret->type = PIR_STRING; + ret->sdata = v1->sdata + mulop + v2->sdata; + msg << "Unknown operation: " << v1->type << " " << mulop << v2->type << std::endl; + msg << "Interpreting as literal string with value '" << ret->sdata << "'" << std::endl; + std::string par = get_parfile(); + CCTK_Warn(1,gr->line(),par.c_str(),current_thorn.c_str(),msg.str().c_str()); } else { std::ostringstream msg; msg << "Unknown operation: " << v1->type << " " << mulop << v2->type << std::endl; @@ -722,7 +758,7 @@ extern "C" int cctk_PirahaParser(const char *buffer,unsigned long buffersize,int "# Note that / occurs in some par files. It is my\n" "# feeling that this should require quote marks.\n" - "name = [@a-zA-Z_][@/a-zA-Z0-9_-]*\n" + "name = [a-zA-Z][a-zA-Z0-9_]*\n" "dname = [0-9][a-zA-Z_]{2,}\n" "inquot = ({var}|\\\\.|[^\\\\\"])*\n" "fname = \\.?/[-\\./0-9a-zA-Z_]+\n" @@ -757,7 +793,11 @@ extern "C" int cctk_PirahaParser(const char *buffer,unsigned long buffersize,int "parindex = \\[ {expr} \\]\n" "active = (?i:ActiveThorns)\n" "set = ({active} = ({quot}|{name})|{par}( {index}|) = ({array}|\\+?{expr})){-skipeol}\n" - "file = ^( !DESC {quot}|)( ({set}|{active}) )*$"; + "desc = !DESC {quot}\n" + "file = ^( ({desc}|{set}|{active}) )*$"; + //std::ofstream peg("/tmp/par.peg"); + //peg << par_file_src; + //peg.close(); compileFile(par_file_grammar,par_file_src,strlen(par_file_src)); @@ -813,7 +853,6 @@ extern "C" int cctk_PirahaParser(const char *buffer,unsigned long buffersize,int smart_ptr smv = meval(aexpr); val = smv->copy(); assert(smv.valid()); - values[thorn][key] = smv; smv->integerize(); if(data != NULL) { if(data->type == PARAMETER_REAL) @@ -834,7 +873,6 @@ extern "C" int cctk_PirahaParser(const char *buffer,unsigned long buffersize,int keyi << key << '[' << i << ']'; smart_ptr smv = meval(aexpr); val = smv->copy(); - values[thorn][keyi.str()] = smv; if(data != NULL) { if(data->type == PARAMETER_REAL) smv->integerize(); @@ -851,9 +889,10 @@ extern "C" int cctk_PirahaParser(const char *buffer,unsigned long buffersize,int } } } else { + // TODO: Fix this std::cout << "ERROR IN PARAMETER FILE:" << std::endl; m2->showError(); - return 1; + return 1; } return 0; } -- cgit v1.2.3