simplerule::simplerule(ste * enclosures, expr * condition, ste * locals, stmt * body, int priority) :rule(), name(name), enclosures(enclosures), condition(condition), locals(locals), body(body), condname(NULL), rulename(NULL), priority(priority) { if (condition != NULL && body != NULL) { Error.CondError(condition->has_side_effects(), "Rule Condition must not have side effects."); if (args->pmurphik) { Error.CondError(!type_equal(condition->gettype(), realtype), "Condition for probabilistic rule must be a real expression."); if (condition->hasvalue() && ((condition->getrvalue() < 0) || (condition->getrvalue() > 1))) Error.Error("Real condition for rule must be >=0 and <=1."); } else Error.CondError(!type_equal(condition->gettype(), booltype), "Condition for rule must be a boolean expression."); } NextSimpleRule = SimpleRuleList; SimpleRuleList = this; size = CountSize(enclosures); // Rearrange enclosures so that the ones that are NOT // mentioned in the condition go first rearrange_enclosures(); }
simplerule::simplerule(ste *enclosures, expr *condition, ste *locals, stmt *body, bool unfair, int priority) :rule(), name( name ), enclosures(enclosures), condition(condition), locals(locals), body(body), condname(NULL), rulename(NULL), unfair(unfair), priority(priority) { if ( condition != NULL && body != NULL ) { Error.CondError(condition->has_side_effects(), "Rule Condition must not have side effects."); Error.CondError(!type_equal(condition->gettype(), booltype), "Condition for rule must be a boolean expression."); } NextSimpleRule = SimpleRuleList; SimpleRuleList = this; size = CountSize(enclosures); // Rearrange enclosures so that the ones that are NOT // mentioned in the condition go first rearrange_enclosures(); }
int simplerule::CountSize(ste * enclosures) { int ret; if (enclosures != NULL && (enclosures->getvalue()->getclass() == decl::Quant || enclosures->getvalue()->getclass() == decl::Alias || enclosures->getvalue()->getclass() == decl::Choose)) { ret = CountSize(enclosures->getnext()); if (enclosures->getvalue()->getclass() == decl::Quant || enclosures->getvalue()->getclass() == decl::Choose) return ret * enclosures->getvalue()->gettype()->getsize(); else return ret; } else return 1; }