def printRef(h): header = h class RefCreator: def __init__(self,t,ev=None,m=None): self.t = t self.ev = ev self.m = m def print1(self,f): if header: print "extern", print "template struct Create<"+f+","+self.t+">;" def __call__(self,r,f): if r.properties["ev"]==self.ev and objdb.getCPModule(r)==self.m: self.print1(f) def varArg(ev): if ev not in ["Casper::BoolSet","Casper::IntSet"]: return None return "CP::Var<"+ev+">" if header: for arg in [varArg]: objdb.forAllRelOper(RefCreator("Ref<int>","int","set"),arg) objdb.forAllRelOper(RefCreator("Ref<bool>","bool","set"),arg) objdb.forAllRelPred(RefCreator("Ref<CP::Var<Casper::IntSet> >","Casper::IntSet","set")) objdb.forAllRelPred(RefCreator("Ref<CP::Var<Casper::BoolSet> >","Casper::BoolSet","set"))
def printPost2(h): header = h class PostCreator: def __init__(self,m=None): self.header = header self.m = m def print1(self,f): if self.header: print "extern", print "template struct PostFilter<"+f+">;" def __call__(self,r,f): if r.properties["ev"]=="bool" and (self.m==None or objdb.getCPModule(r)==self.m): self.print1(f) def varArg(ev): if ev!="float": return None return "CP::Var<"+ev+">" def refArg(ev): if ev!="float": return None return "Ref<"+ev+">" for arg in [varArg,refArg]: objdb.forAllRelOper(PostCreator("real"),arg) objdb.forAllRelPred(PostCreator("real")) if header: objdb.forAllInstObjs(PostCreator())
def printRef(h): header = h class RefCreator: def __init__(self,t,ev=None,m=None): self.t = t self.ev = ev self.m = m def print1(self,f): if header: print "extern", print "template struct Create<"+f+","+self.t+">;" def __call__(self,r,f): if r.properties["ev"]==self.ev and objdb.getCPModule(r)==self.m: self.print1(f) def refArg(ev): if ev!="float": return None return "Ref<"+ev+">" RefCreator("Ref<float>").print1("CP::Var<float>") RefCreator("Ref<CP::Var<float> >").print1("CP::Var<float>") RefCreator("Ref<CP::Var<float> >").print1("Ref<float>") objdb.forAllRelOper(RefCreator("Ref<CP::Var<float> >","float","real"),refArg) objdb.forAllRelPred(RefCreator("Ref<CP::Var<float> >","float","real"))
def printPost2(h): header = h class PostCreator: def __init__(self,m=None): self.header = header self.m = m def print1(self,f): if self.header: print "extern", print "template struct PostFilter<"+f+">;" def __call__(self,r,f): if r.properties["ev"]=="bool" and objdb.getCPModule(r)==self.m: self.print1(f) def varArg(ev): if ev!="Casper::IntSet" and ev!="Casper::BoolSet": return None return "CP::Var<"+ev+">" # def refArg(ev): # if ev!="bool" and ev!="int": # return None # return "Ref<"+ev+">" # # def goalArg(ev): # if ev!="bool": # return None # return "Goal" for arg in [varArg]: #,refArg,goalArg]: objdb.forAllRelOper(PostCreator("set"),arg) objdb.forAllRelPred(PostCreator("set"))
def printRel(h): header = h class Rel: def print1(self,ev,f): if header: print "extern", print "template struct "+f+";" def __call__(self,r,f): self.print1(r.properties["ev"],f) def goalArg(ev): if ev!="bool": return None return "Goal" def refArg(ev): if ev!="bool" and ev!="int": return None return "Ref<"+ev+">" for arg in [goalArg,refArg]: objdb.forAllRelOper(Rel(),arg) objdb.forAllRelPred(Rel()) objdb.forAllInstObjs(Rel())
def printExprWrapper(h): header = h class ExprWrapper: def print1(self,ev,f): if header: print "extern", print "template struct ExprWrapper<"+ev+","+f+">;" def __call__(self,r,f): if objdb.getCPModule(r)=="set": self.print1(r.properties["ev"],f) def varArg(ev): if ev not in ["Casper::BoolSet","Casper::IntSet"]: return None return "CP::Var<"+ev+">" for ev in ["Casper::BoolSet","Casper::IntSet"]: ExprWrapper().print1(ev,"CP::Var<"+ev+">") ExprWrapper().print1("Seq<"+ev+">","CP::VarArray<"+ev+",1>") ExprWrapper().print1("Seq<"+ev+">","CP::VarArray<"+ev+",2>") for arg in [varArg]: objdb.forAllRelOper(ExprWrapper(),arg) objdb.forAllRelPred(ExprWrapper())
def printExpr(h): header = h class Expr: def print1(self,ev,f): if header: print "extern", print "template Expr<"+ev+">::Expr<"+f+">(const "+f+"&);" def __call__(self,r,f): self.print1(r.properties["ev"],f) def goalArg(ev): if ev!="bool": return None return "Goal" def refArg(ev): if ev!="bool" and ev!="int": return None return "Ref<"+ev+">" for ev in ["bool","int"]: Expr().print1(ev,"Ref<"+ev+">") Expr().print1(ev,ev) Expr().print1("Seq<"+ev+">","Casper::Util::StdList<Expr<"+ev+"> >") Expr().print1("bool","Goal") for arg in [goalArg,refArg]: objdb.forAllRelOper(Expr(),arg) objdb.forAllRelPred(Expr()) objdb.forAllInstObjs(Expr())
def printViews(h): header = h class ViewCreator: def __init__(self,t,ev=None,m=None): self.header = header self.t = t self.ev = ev self.m = m def print1(self,f): if self.header: print "extern", print "template struct Create<"+f+","+self.t+">;" def __call__(self,r,f): if r.properties["ev"]==self.ev and (self.m == None or objdb.getCPModule(r)==self.m): self.print1(f) def varArg(ev): if ev!="float": return None return "CP::Var<"+ev+">" def refArg(ev): if ev!="float": return None return "Ref<"+ev+">" for arg in ["CP::Var<float>","Ref<float>","float"]: ViewCreator("CP::BndExpr<float>").print1(arg) if header: args = [varArg,refArg] else: args = [varArg] for arg in args: objdb.forAllRelOper(ViewCreator("CP::BndExpr<float>","float","real"),arg) objdb.forAllRelOper(ViewCreator("CP::DomExpr<bool>","bool","real"),arg) objdb.forAllRelOper(ViewCreator("CP::BndExpr<bool>","bool","real"),arg) objdb.forAllRelOper(ViewCreator("CP::ValExpr<bool>","bool","real"),arg) objdb.forAllRelOper(ViewCreator("CP::ChkExpr","bool","real"),arg) objdb.forAllRelPred(ViewCreator("CP::BndExpr<float>","float","real")) objdb.forAllRelPred(ViewCreator("CP::DomExpr<bool>","bool","real")) objdb.forAllRelPred(ViewCreator("CP::BndExpr<bool>","bool","real")) objdb.forAllRelPred(ViewCreator("CP::ValExpr<bool>","bool","real")) objdb.forAllRelPred(ViewCreator("CP::ChkExpr","bool","real")) if header: objdb.forAllInstObjs(ViewCreator("CP::DomExpr<bool>","real")) objdb.forAllInstObjs(ViewCreator("CP::BndExpr<bool>","real")) objdb.forAllInstObjs(ViewCreator("CP::ValExpr<bool>","real")) objdb.forAllInstObjs(ViewCreator("CP::ChkExpr","real"))
def printExprWrapper(h,m=None): header = h class ExprWrapper: def __init__(self,m=None): self.m = m def print1(self,ev,f): if ev in ["Casper::IntSeq","Casper::BoolSeq","Seq<int>","Seq<bool>"]: if header: print "extern", print "template struct ExprWrapper<"+ev+","+f+">;" else: l = [ ("CP::DomExpr<"+ev+">","toCPDomExpr(CP::Store&) const"), ("CP::BndExpr<"+ev+">","toCPBndExpr(CP::Store&) const"), ("CP::ValExpr<"+ev+">","toCPValExpr(CP::Store&) const"), ("Ref<CP::Var<"+ev+"> >","toCPVarRef(State&) const"), ] if ev=="bool": l.append(("CP::ChkExpr","toChkExpr(CP::Store&) const")) l.append(("bool","postDomFilter(CP::Store&) const")) l.append(("bool","postBndFilter(CP::Store&) const")) l.append(("bool","postValFilter(CP::Store&) const")) for r,n in l: if header: print "extern", print "template "+r+" ExprWrapper<"+ev+","+f+">::"+n+";" def __call__(self,r,f): if self.m==None or objdb.getCPModule(r)==self.m: self.print1(r.properties["ev"],f) def goalArg(ev): if ev!="bool": return None return "Goal" def refArg(ev): if ev!="bool" and ev!="int": return None return "Ref<"+ev+">" for ev in ["bool","int"]: ExprWrapper().print1(ev,"Ref<"+ev+">") ExprWrapper().print1(ev,ev) ExprWrapper().print1("Seq<"+ev+">","Casper::Util::StdList<Expr<"+ev+"> >") ExprWrapper().print1("bool","Goal") for arg in [goalArg,refArg]: objdb.forAllRelOper(ExprWrapper(m),arg) objdb.forAllRelPred(ExprWrapper(m)) objdb.forAllInstObjs(ExprWrapper())
def printExprWrapper(h): header = h class ExprWrapper: def print1(self,ev,f): if ev in ["Casper::IntSeq","Casper::BoolSeq","Seq<int>","Seq<bool>"]: if header: print "extern", print "template struct ExprWrapper<"+ev+","+f+">;" else: l = [ (ev,"toLiteral() const"), ("Ref<"+ev+">","toRef(State&) const"), ("State* const","getPState() const"), ("std::ostream&","print(std::ostream&) const"), ] if ev=="bool": l.append(("Goal","toGoal(State&) const")) for r,n in l: if header: print "extern", print "template "+r+" ExprWrapper<"+ev+","+f+">::"+n+";" def __call__(self,r,f): self.print1(r.properties["ev"],f) def goalArg(ev): if ev!="bool": return None return "Goal" def refArg(ev): if ev!="bool" and ev!="int": return None return "Ref<"+ev+">" for ev in ["bool","int"]: ExprWrapper().print1(ev,"Ref<"+ev+">") ExprWrapper().print1(ev,ev) ExprWrapper().print1("Seq<"+ev+">","Casper::Util::StdList<Expr<"+ev+"> >") ExprWrapper().print1("bool","Goal") for arg in [goalArg,refArg]: objdb.forAllRelOper(ExprWrapper(),arg) objdb.forAllRelPred(ExprWrapper()) objdb.forAllInstObjs(ExprWrapper())
def printRel(h): header = h class Rel: def print1(self,ev,f): if header: print "extern", print "template struct "+f+";" def __call__(self,r,f): self.print1(r.properties["ev"],f) def varArg(ev): if ev not in ["float"]: return None return "CP::Var<"+ev+">" for arg in [varArg]: objdb.forAllRelOper(Rel(),arg)
def printGoal(h): header = h class GoalCreator: def print1(self,f): if header: print "extern", print "template struct Create<"+f+",Goal>;" def __call__(self,r,f): if r.properties["ev"]=="bool": self.print1(f) def goalArg(ev): if ev!="bool": return None return "Goal" GoalCreator().print1("Goal") GoalCreator().print1("Ref<bool>") objdb.forAllRelOper(GoalCreator(),goalArg) objdb.forAllRelPred(GoalCreator())
def printRef(h): header = h class RefCreator: def __init__(self,t,ev=None,m=None): self.t = t self.ev = ev self.m = m def print1(self,f): if header: print "extern", print "template struct Create<"+f+","+self.t+">;" def __call__(self,r,f): if r.properties["ev"]==self.ev and \ (self.m == None or objdb.getCPModule(r)==self.m): self.print1(f) def refArg(ev): if ev!="bool" and ev!="int": return None return "Ref<"+ev+">" def setRefArg(ev): if ev!="Casper::IntSet" and ev!="Casper::BoolSet": return None return "Ref<"+ev+">" RefCreator("Ref<int>").print1("Ref<int>") RefCreator("Ref<bool>").print1("Ref<bool>") RefCreator("Ref<bool>").print1("Goal") RefCreator("Ref<int>").print1("CP::Var<int>") RefCreator("Ref<bool>").print1("CP::Var<bool>") objdb.forAllRelOper(RefCreator("Ref<int>","int","int"),refArg) objdb.forAllRelOper(RefCreator("Ref<bool>","bool","int"),refArg) objdb.forAllRelPred(RefCreator("Ref<int>","int","int")) objdb.forAllRelPred(RefCreator("Ref<bool>","bool","int")) objdb.forAllRelOper(RefCreator("Ref<int>","int","set"),setRefArg) objdb.forAllRelOper(RefCreator("Ref<bool>","bool","set"),setRefArg) objdb.forAllRelPred(RefCreator("Ref<int>","int","set")) objdb.forAllRelPred(RefCreator("Ref<bool>","bool","set")) objdb.forAllInstObjs(RefCreator("Ref<int>","int")) objdb.forAllInstObjs(RefCreator("Ref<bool>","bool"))
def printViews(h): header = h class ViewCreator: def __init__(self,t,ev=None,m=None): self.header = header self.t = t self.ev = ev self.m = m def print1(self,f): if self.header: print "extern", print "template struct Create<"+f+","+self.t+">;" def __call__(self,r,f): if r.properties["ev"]==self.ev and objdb.getCPModule(r)==self.m: self.print1(f) def varArg(ev): if ev!="Casper::IntSet" and ev!="Casper::BoolSet": return None return "CP::Var<"+ev+">" for arg in ["CP::Var<Casper::IntSet>"]: ViewCreator("CP::DomExpr<Casper::IntSet>").print1(arg) for arg in ["CP::Var<Casper::BoolSet>"]: ViewCreator("CP::DomExpr<Casper::BoolSet>").print1(arg) for arg in [varArg]: objdb.forAllRelOper(ViewCreator("CP::DomExpr<Casper::IntSet>","Casper::IntSet","set"),arg) objdb.forAllRelOper(ViewCreator("CP::DomExpr<Casper::BoolSet>","Casper::BoolSet","set"),arg) for ev in ["int","bool"]: objdb.forAllRelOper(ViewCreator("CP::DomExpr<"+ev+">",ev,"set"),arg) objdb.forAllRelOper(ViewCreator("CP::BndExpr<"+ev+">",ev,"set"),arg) objdb.forAllRelOper(ViewCreator("CP::ValExpr<"+ev+">",ev,"set"),arg) objdb.forAllRelOper(ViewCreator("CP::ChkExpr","bool","set"),arg) objdb.forAllRelPred(ViewCreator("CP::DomExpr<Casper::IntSet>","Casper::IntSet","set")) objdb.forAllRelPred(ViewCreator("CP::DomExpr<Casper::BoolSet>","Casper::BoolSet","set")) for ev in ["int","bool"]: objdb.forAllRelPred(ViewCreator("CP::DomExpr<"+ev+">",ev,"set")) objdb.forAllRelPred(ViewCreator("CP::BndExpr<"+ev+">",ev,"set")) objdb.forAllRelPred(ViewCreator("CP::ValExpr<"+ev+">",ev,"set")) objdb.forAllRelPred(ViewCreator("CP::ChkExpr","bool","set"))