Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
[Cpp] Consider array slices with less subscripts than dimensions
Browse files Browse the repository at this point in the history
The remaining dimensions are treated as whole dim.

Belonging to [master]:
  - #2768
  - OpenModelica/OpenModelica-testsuite#1070
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Nov 7, 2018
1 parent 47d8ecf commit 648de42
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Compiler/Template/CodegenCppCommon.tpl
Expand Up @@ -368,7 +368,7 @@ case component as CREF(componentRef=cr, ty=ty) then
else if crefIsScalar(cr, context) then
contextCref(cr, context, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
else
if crefSubIsScalar(cr) then
if boolAnd(intEq(listLength(crefSubs(cr)), listLength(crefDims(cr))), crefSubIsScalar(cr)) then
// The array subscript results in a scalar
let arrName = contextCref(crefStripLastSubs(cr), context,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
let arrayType = expTypeShort(ty)
Expand Down
10 changes: 5 additions & 5 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -3267,6 +3267,11 @@ package ComponentReference
output list<DAE.ComponentRef> outCref;
end expandCref;

function crefHasScalarSubscripts
input DAE.ComponentRef cr;
output Boolean hasScalarSubs;
end crefHasScalarSubscripts;

function crefIsScalarWithAllConstSubs
input DAE.ComponentRef inCref;
output Boolean isScalar;
Expand Down Expand Up @@ -3341,11 +3346,6 @@ package Expression
output Boolean areConstant;
end subscriptConstants;

function crefHasScalarSubscripts
input DAE.ComponentRef cr;
output Boolean hasScalarSubs;
end crefHasScalarSubscripts;

function typeof
input DAE.Exp inExp;
output DAE.Type outType;
Expand Down
15 changes: 10 additions & 5 deletions SimulationRuntime/cpp/Include/Core/Math/ArraySlice.h
Expand Up @@ -101,14 +101,14 @@ class ArraySliceConst: public BaseArray<T> {
ArraySliceConst(const BaseArray<T> &baseArray, const vector<Slice> &slice)
: BaseArray<T>(baseArray.isStatic(), false)
, _baseArray(baseArray)
, _isets(slice.size())
, _idxs(slice.size())
, _baseIdx(slice.size())
, _isets(baseArray.getNumDims())
, _idxs(baseArray.getNumDims())
, _baseIdx(baseArray.getNumDims())
, _tmp_data(NULL) {

if (baseArray.getNumDims() != slice.size())
if (baseArray.getNumDims() < slice.size())
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
"Wrong dimensions for ArraySlice");
"Wrong slices exceeding array dimensions");
// create an explicit index set per dimension,
// except for all indices that are indicated with an empty index set
size_t dim, size;
Expand Down Expand Up @@ -145,6 +145,11 @@ class ArraySliceConst: public BaseArray<T> {
_dims.push_back(size);
dit++;
}
// use all indices of remaining dims
for (; dim <= baseArray.getNumDims(); dim++) {
_isets[dim - 1] = NULL;
_dims.push_back(_baseArray.getDim(dim));
}
}

virtual ~ArraySliceConst() {
Expand Down

0 comments on commit 648de42

Please sign in to comment.