diff options
author | Derick Huth <derickhuth@gmail.com> | 2014-10-06 12:42:34 -0600 |
---|---|---|
committer | Derick Huth <derickhuth@gmail.com> | 2014-10-06 12:42:34 -0600 |
commit | 8d73c8fcc75556c1df71dd39dd99783f8f86fc3e (patch) | |
tree | 157d627863d76a4c256a27cae27ce2e8566c7ea0 /omega/omega_lib/src/RelVar.cc | |
parent | e87b55ad69f0ac6211daae741b32c8ee9dcbe470 (diff) | |
parent | 8c646f24570079eac53e58fcf42d0d4fbc437ee3 (diff) | |
download | chill-8d73c8fcc75556c1df71dd39dd99783f8f86fc3e.tar.gz chill-8d73c8fcc75556c1df71dd39dd99783f8f86fc3e.tar.bz2 chill-8d73c8fcc75556c1df71dd39dd99783f8f86fc3e.zip |
Merge pull request #2 from dhuth/master
Moved omega into chill.
Diffstat (limited to 'omega/omega_lib/src/RelVar.cc')
-rw-r--r-- | omega/omega_lib/src/RelVar.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/omega/omega_lib/src/RelVar.cc b/omega/omega_lib/src/RelVar.cc new file mode 100644 index 0000000..d9b977c --- /dev/null +++ b/omega/omega_lib/src/RelVar.cc @@ -0,0 +1,71 @@ +#include <omega/RelBody.h> +#include <omega/omega_i.h> + +namespace omega { + +Variable_ID Rel_Body::get_local(const Variable_ID v) { + Global_Var_ID g; + if (v->kind() == Global_Var) { + g = v->get_global_var(); + if (g->arity()) return get_local(g,v->function_of()); + return get_local(g); + } + if (is_set()) return set_var(v->get_position()); + if (v->kind() == Input_Var) return input_var(v->get_position()); + if (v->kind() == Output_Var) return output_var(v->get_position()); + assert(0 && "Can only get local for variable with global scope"); + exit(1); + return 0; +} + +// +// Find or declare global variable. +// If the VarID does not exist, it is created. Otherwise it's returned. +// Note that this version now works only for 0-ary functions. +// +Variable_ID Rel_Body::get_local(const Global_Var_ID G) { + assert(G->arity() == 0); + for(Variable_Iterator i(Symbolic); i; i++) + if ((*i)->get_global_var() == G) + return (*i); + + Variable_ID v = G->get_local(); + Symbolic.append(v); + return v; +} + + +Variable_ID Rel_Body::get_local(const Global_Var_ID G, Argument_Tuple of) { + assert(G->arity() == 0 || of == Input_Tuple || of == Output_Tuple); + + for(Variable_Iterator i = Symbolic; i; i++) + if ((*i)->get_global_var() == G && (G->arity() == 0 || + of == (*i)->function_of())) + return (*i); + + Variable_ID V = G->get_local(of); + Symbolic.append(V); + return V; +} + + +bool Rel_Body::has_local(const Global_Var_ID G) { + assert(G->arity() == 0); + for(Variable_Iterator i = Symbolic; i; i++) + if ((*i)->get_global_var() == G) + return true; + return false; +} + + +bool Rel_Body::has_local(const Global_Var_ID G, Argument_Tuple of) { + assert(G->arity() == 0 || of == Input_Tuple || of == Output_Tuple); + + for(Variable_Iterator i = Symbolic; i; i++) + if ((*i)->get_global_var() == G && (G->arity() == 0 || + of == (*i)->function_of())) + return true; + return false; +} + +} // namespace |