From 1b0f18bed125d641dc02caa4cfebcefc3a419de7 Mon Sep 17 00:00:00 2001 From: sbrandt Date: Mon, 19 May 2014 15:54:50 +0000 Subject: Close ticket 1554 git-svn-id: http://svn.cactuscode.org/flesh/trunk@5118 17b73243-c579-4c4c-a9d2-2d5706c11dac --- src/piraha/Call.cc | 116 ++++++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/src/piraha/Call.cc b/src/piraha/Call.cc index a59d287b..f4bfefe7 100644 --- a/src/piraha/Call.cc +++ b/src/piraha/Call.cc @@ -217,6 +217,7 @@ std::ostream& operator<<(std::ostream& o,const smart_ptr& val) { typedef std::map > >::iterator th_iter; typedef std::map >::iterator nm_iter; +std::map > variables; smart_ptr eval_expr(std::string inp); @@ -284,6 +285,10 @@ smart_ptr lookup_var(smart_ptr gr) { ret->type = PIR_REAL; ret->ddata = 4.0*atan2(1.0,1.0); } + nm_iter iter = variables.find(gr->group(0)->substring()); + if(iter != variables.end()) { + ret = iter->second; + } if(!ret.valid()) { std::ostringstream msg; msg << "Unknown variable: " << gr->substring() << std::endl; @@ -859,8 +864,9 @@ 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" + "set_var = \\${name} = \\+?{expr}{-skipeol}\n" "desc = !DESC {quot}\n" - "file = ^( ({desc}|{set}|{active}) )*$"; + "file = ^( ({desc}|{set_var}|{set}|{active}) )*$"; //std::ofstream peg("/tmp/par.peg"); //peg << par_file_src; //peg.close(); @@ -888,61 +894,41 @@ extern "C" int cctk_PirahaParser(const char *buffer,unsigned long buffersize,int set_function("ActiveThorns",active.c_str(),line); for(int i=0;igroupCount();i++) { smart_ptr gr = m2->group(i); - if(gr->getPatternName() != "set") - continue; - smart_ptr par = gr->group("par"); - if(par.valid()) { - // add value->quot->inquot - std::string key; - std::string thorn = par->group("name",0)->substring(); - std::string name = par->group("name",1)->substring(); - key += thorn; - key += "::"; - key += name; - const cParamData *data = CCTK_ParameterData(name.c_str(),thorn.c_str()); - - smart_ptr index = par->group("parindex"); - if(index.valid()) { - key += '['; - smart_ptr vv = meval(index); - if(vv->type != PIR_INT) { - std::ostringstream msg; - std::string par = get_parfile(); - msg << "bad index " << vv << std::endl; - CCTK_Error(index->line(),par.c_str(),thorn.c_str(),msg.str().c_str()); + if(gr->getPatternName() == "set") { + smart_ptr par = gr->group("par"); + if(par.valid()) { + // add value->quot->inquot + std::string key; + std::string thorn = par->group("name",0)->substring(); + std::string name = par->group("name",1)->substring(); + key += thorn; + key += "::"; + key += name; + const cParamData *data = CCTK_ParameterData(name.c_str(),thorn.c_str()); + + smart_ptr index = par->group("parindex"); + if(index.valid()) { + key += '['; + smart_ptr vv = meval(index); + if(vv->type != PIR_INT) { + std::ostringstream msg; + std::string par = get_parfile(); + msg << "bad index " << vv << std::endl; + CCTK_Error(index->line(),par.c_str(),thorn.c_str(),msg.str().c_str()); + } + std::string vvstr = vv->copy(); + key += vvstr; + key += ']'; } - std::string vvstr = vv->copy(); - key += vvstr; - key += ']'; - } - std::string val; - smart_ptr aexpr = gr->group("expr"); - if(aexpr.valid()) { - current_thorn = thorn; - smart_ptr smv = meval(aexpr); - val = smv->copy(); - assert(smv.valid()); - smv->integerize(); - if(data != NULL) { - if(data->type == PARAMETER_REAL) - smv->integerize(); - if(data->type == PARAMETER_BOOLEAN) - smv->booleanize(gr); - check_types(thorn.c_str(),aexpr->line(),smv,data->type); - } - set_function( - key.c_str(), - val.c_str(), - gr->group(0)->line()); - } else { - smart_ptr arr = gr->group("array"); - for(int i=0;igroupCount();i++) { - aexpr = arr->group(i); - std::ostringstream keyi; - keyi << key << '[' << i << ']'; + std::string val; + smart_ptr aexpr = gr->group("expr"); + if(aexpr.valid()) { + current_thorn = thorn; smart_ptr smv = meval(aexpr); val = smv->copy(); + assert(smv.valid()); + smv->integerize(); if(data != NULL) { if(data->type == PARAMETER_REAL) smv->integerize(); @@ -951,11 +937,33 @@ extern "C" int cctk_PirahaParser(const char *buffer,unsigned long buffersize,int check_types(thorn.c_str(),aexpr->line(),smv,data->type); } set_function( - keyi.str().c_str(), + key.c_str(), val.c_str(), - aexpr->line()); + gr->group(0)->line()); + } else { + smart_ptr arr = gr->group("array"); + for(int i=0;igroupCount();i++) { + aexpr = arr->group(i); + std::ostringstream keyi; + keyi << key << '[' << i << ']'; + smart_ptr smv = meval(aexpr); + val = smv->copy(); + if(data != NULL) { + if(data->type == PARAMETER_REAL) + smv->integerize(); + if(data->type == PARAMETER_BOOLEAN) + smv->booleanize(gr); + check_types(thorn.c_str(),aexpr->line(),smv,data->type); + } + set_function( + keyi.str().c_str(), + val.c_str(), + aexpr->line()); + } } } + } else if(gr->getPatternName() == "set_var") { + variables[gr->group(0)->substring()] = meval(gr->group(1)); } } } else { -- cgit v1.2.3