Skip to content

Commit

Permalink
+ Improved handling of unary not operation on boolean array (#2286)
Browse files Browse the repository at this point in the history
- does not work recursively (also for 'and' and 'or')
  - (a and b and c) fails
  - (not (a and b)) fails
  - (not a and b) fails
  - (a and not b) succeeds

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16727 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Henning Kiel committed Aug 2, 2013
1 parent f7c8e5a commit 0d59bae
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
13 changes: 12 additions & 1 deletion Compiler/Template/CodegenC.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7276,7 +7276,18 @@ match exp
case LUNARY(__) then
let e = daeExp(exp, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
match operator
case NOT(__) then '(!<%e%>)'
case NOT(__) then
match exp
case CREF(ty = T_ARRAY(__)) then
let var = tempDecl("boolean_array", &varDecls)
let &preExp += 'not_boolean_array(&<%e%>,&<%var%>);<%\n%>'
'<%var%>'
case ARRAY(ty = T_ARRAY(__)) then
let var = tempDecl("boolean_array", &varDecls)
let &preExp += 'not_boolean_array(&<%e%>,&<%var%>);<%\n%>'
'<%var%>'
else
'(!<%e%>)'
end daeExpLunary;


Expand Down
25 changes: 21 additions & 4 deletions SimulationRuntime/c/util/boolean_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void copy_boolean_array_data(const boolean_array_t *source, boolean_array_t *des
void and_boolean_array(const boolean_array_t *source1, const boolean_array_t *source2, boolean_array_t *dest)
{
size_t i, nr_of_elements;

assert(base_array_ok(source1));
assert(base_array_ok(source2));
assert(base_array_shape_eq(source1, source2));
Expand All @@ -144,7 +144,7 @@ void and_boolean_array(const boolean_array_t *source1, const boolean_array_t *so
// assert(base_array_shape_eq(source1, dest));
alloc_boolean_array_data(dest);


nr_of_elements = base_array_nr_of_elements(source1);

for(i = 0; i < nr_of_elements; ++i) {
Expand All @@ -155,7 +155,7 @@ void and_boolean_array(const boolean_array_t *source1, const boolean_array_t *so
void or_boolean_array(const boolean_array_t *source1, const boolean_array_t *source2, boolean_array_t *dest)
{
size_t i, nr_of_elements;

assert(base_array_ok(source1));
assert(base_array_ok(source2));
assert(base_array_shape_eq(source1, source2));
Expand All @@ -165,14 +165,31 @@ void or_boolean_array(const boolean_array_t *source1, const boolean_array_t *sou
// assert(base_array_shape_eq(source1, dest));
alloc_boolean_array_data(dest);


nr_of_elements = base_array_nr_of_elements(source1);

for(i = 0; i < nr_of_elements; ++i) {
boolean_set(dest, i, boolean_get(source1, i) || boolean_get(source2, i));
}
}

void not_boolean_array(const boolean_array_t *source, boolean_array_t *dest)
{
size_t i, nr_of_elements;

assert(base_array_ok(source));

clone_base_array_spec(source, dest);
alloc_boolean_array_data(dest);


nr_of_elements = base_array_nr_of_elements(source);

for(i = 0; i < nr_of_elements; ++i) {
boolean_set(dest, i, !boolean_get(source, i));
}
}

void copy_boolean_array_data_mem(const boolean_array_t *source, modelica_boolean *dest)
{
size_t i, nr_of_elements;
Expand Down
3 changes: 3 additions & 0 deletions SimulationRuntime/c/util/boolean_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ void and_boolean_array(const boolean_array_t *source1, const boolean_array_t *so
/* 'or' two boolean arrays*/
void or_boolean_array(const boolean_array_t *source1, const boolean_array_t *source2, boolean_array_t *dest);

/* 'not' a boolean array*/
void not_boolean_array(const boolean_array_t *source, boolean_array_t *dest);

extern modelica_boolean* calc_boolean_index(int ndims, const _index_t* idx_vec, const boolean_array_t* arr);
extern modelica_boolean* calc_boolean_index_va(const boolean_array_t* source,int ndims,va_list ap);

Expand Down

0 comments on commit 0d59bae

Please sign in to comment.