Changeset cd5223ce in OpenModelica


Ignore:
Timestamp:
2024-06-13T11:43:00+02:00 (5 weeks ago)
Author:
kabdelhak <karim.abdelhak@…>
Parents:
d94c8c9
Message:

[NB] correctly skip to record elements

  • record elements in adjacency matrices are now correctly ordered and filtered for their relevant sub crefs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/NBackEnd/Util/NBSlice.mo

    rf2815de6 rcd5223ce  
    3939
    4040  // NF imports
    41   import Class = NFClass;
    42   import NFClassTree.ClassTree;
    4341  import ComplexType = NFComplexType;
    4442  import ComponentRef = NFComponentRef;
    4543  import Dimension = NFDimension;
    4644  import Expression = NFExpression;
    47   import NFInstNode.InstNode;
    4845  import Operator = NFOperator;
    4946  import SimplifyExp = NFSimplifyExp;
     
    10741071    input output Type ty;
    10751072    input list<Integer> skips;
     1073    input ComponentRef cref;
     1074    input UnorderedMap<ComponentRef, Integer> map           "unordered map to check for relevance";
    10761075  algorithm
    10771076    (index, ty) := match (ty, skips)
     
    10811080        Type sub_ty;
    10821081        list<Type> rest_ty;
    1083         list<InstNode> record_fields;
    1084         InstNode field;
     1082        Pointer<Variable> parent;
     1083        list<ComponentRef> crefs;
     1084        ComponentRef field;
    10851085
    10861086      // 0 skips are full dependencies
     
    10961096        sub_ty :: rest_ty := rest_ty;
    10971097        // see if there is nested skips
    1098       then resolveSkips(index, sub_ty, rest);
     1098      then resolveSkips(index, sub_ty, rest, cref, map);
    10991099
    11001100      // skip to a record element
    11011101      case (Type.COMPLEX(complexTy = ComplexType.RECORD()), skip::rest) algorithm
    1102         record_fields := ClassTree.enumerateComponents(Class.classTree(InstNode.getClass(ty.cls)));
    1103         for i in 1:skip-1 loop
    1104           field :: record_fields := record_fields;
    1105           index := index + Type.sizeOf(InstNode.getType(field));
    1106         end for;
    1107         field :: record_fields := record_fields;
     1102        // get the children and skip to correct one
     1103        field := match BVariable.getParent(BVariable.getVarPointer(cref))
     1104          case SOME(parent) algorithm
     1105            crefs :=  list(BVariable.getVarName(child) for child in BVariable.getRecordChildren(parent));
     1106            crefs := list(c for c guard(UnorderedMap.contains(c, map)) in crefs);
     1107            for i in 1:skip-1 loop
     1108              field :: crefs := crefs;
     1109              index := index + Type.sizeOf(ComponentRef.getSubscriptedType(field));
     1110            end for;
     1111            field :: crefs := crefs;
     1112          then field;
     1113          else algorithm
     1114            Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed because skip of " + intString(skip)
     1115              + " for type " + Type.toString(ty) + " is requested, but the cref is not part of a record:" + ComponentRef.toString(cref) + "."});
     1116          then fail();
     1117        end match;
    11081118        // see if there is nested skips
    1109       then resolveSkips(index, InstNode.getType(field), rest);
     1119      then resolveSkips(index, ComponentRef.getSubscriptedType(field), rest, cref, map);
    11101120
    11111121      // skip to an array element
     
    11131123        (rest, tail) := List.split(rest, listLength(ty.dimensions));
    11141124        index := locationToIndex(List.zip(list(Dimension.size(dim) for dim in ty.dimensions), rest), index);
    1115       then resolveSkips(index, ty.elementType, tail);
     1125      then resolveSkips(index, ty.elementType, tail, cref, map);
    11161126
    11171127      // skip for tuple or array, but the skip is too large
     
    12031213      (start, _)          := mapping.eqn_AtS[eqn_arr_idx];
    12041214      if not UnorderedSet.contains(cref, rep) then
    1205         (skip_idx, skip_ty) := resolveSkips(start, ty, d.skips);
     1215        (skip_idx, skip_ty) := resolveSkips(start, ty, d.skips, cref, map);
    12061216      else
    12071217        (skip_idx, skip_ty) := (start, ty);
Note: See TracChangeset for help on using the changeset viewer.