Changeset 3eae525 in OpenModelica


Ignore:
Timestamp:
2021-11-26T17:34:24+01:00 (2 years ago)
Author:
GitHub <noreply@…>
Branches:
maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master, omlib-staging
Children:
6ec8257, b3681ace
Parents:
da94d68a
git-author:
perost <perost86@…> (11/26/21 17:34:24)
git-committer:
GitHub <noreply@…> (11/26/21 17:34:24)
Message:

Improve Flat Modelica output (#8231)

  • Only print visibility for blocks of variables, not for every variable.
  • Remove unnecessary public section at end of variable list.

Fixes #8227.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/NFFrontEnd/NFFlatModel.mo

    r4fb12f37 r3eae525  
    5353  import MetaModelica.Dangerous.listReverseInPlace;
    5454  import Util;
     55  import Prefixes = NFPrefixes;
     56  import NFPrefixes.Visibility;
    5557
    5658  import FlatModel = NFFlatModel;
     
    214216  protected
    215217    FlatModel flat_model = flatModel;
     218    Visibility visibility = Visibility.PUBLIC;
    216219  algorithm
    217220    s := IOStream.append(s, "class '" + flat_model.name + "'\n");
     
    232235
    233236    for v in flat_model.variables loop
     237      if visibility <> Variable.visibility(v) then
     238        visibility := Variable.visibility(v);
     239        s := IOStream.append(s, Prefixes.visibilityString(visibility));
     240        s := IOStream.append(s, "\n");
     241      end if;
     242
    234243      s := Variable.toFlatStream(v, "  ", printBindingTypes, s);
    235244      s := IOStream.append(s, ";\n");
    236245    end for;
    237 
    238     s := IOStream.append(s, "public\n");
    239246
    240247    if not listEmpty(flat_model.initialEquations) then
  • OMCompiler/Compiler/NFFrontEnd/NFVariable.mo

    rb90fb73 r3eae525  
    163163  end variability;
    164164
     165  function visibility
     166    input Variable variable;
     167    output Visibility visibility = variable.visibility;
     168  end visibility;
     169
    165170  function isEmptyArray
    166171    input Variable variable;
     
    317322    s := IOStream.append(s, indent);
    318323
    319     if var.visibility == Visibility.PROTECTED then
    320       s := IOStream.append(s, "protected ");
    321     else
    322       s := IOStream.append(s, "public ");
    323     end if;
    324 
    325324    s := Component.Attributes.toFlatStream(var.attributes, var.ty, s, ComponentRef.isSimple(var.name));
    326325    s := IOStream.append(s, Type.toFlatString(var.ty));
  • testsuite/flattening/modelica/scodeinst/CombineSubscripts3.mo

    rf6468ae r3eae525  
    2222// Result:
    2323// class 'CombineSubscripts3'
    24 //   public Real[3] 'b.p';
    25 //   public Real[3, 4] 'b.x';
    26 // public
     24//   Real[3] 'b.p';
     25//   Real[3, 4] 'b.x';
    2726// equation
    2827//   for 'i' in 1:3 loop
  • testsuite/openmodelica/flatmodelica/SD.mo

    r4fb12f37 r3eae525  
    4444// Result:
    4545// class 'SD'
    46 //   public parameter Integer 'N' = 3;
    47 //   public parameter Real[3] 'p' = {1.0, 1.5, 2.0};
    48 //   public Real[3] 'c.c.f';
    49 //   public Real[3] 'c.c.e';
    50 //   public Real[3, {3, 4, 5}] 'c.x';
    51 //   public parameter Real[3] 'c.p' = 'p'[:];
    52 //   public parameter Integer[3] 'c.N' = {3, 4, 5};
    53 //   public parameter Real 's.p' = 3.0;
    54 //   public Real 's.c.e';
    55 //   public Real 's.c.f';
    56 // public
     46//   parameter Integer 'N' = 3;
     47//   parameter Real[3] 'p' = {1.0, 1.5, 2.0};
     48//   Real[3] 'c.c.f';
     49//   Real[3] 'c.c.e';
     50//   Real[3, {3, 4, 5}] 'c.x';
     51//   parameter Real[3] 'c.p' = 'p'[:];
     52//   parameter Integer[3] 'c.N' = {3, 4, 5};
     53//   parameter Real 's.p' = 3.0;
     54//   Real 's.c.e';
     55//   Real 's.c.f';
    5756// equation
    5857//   'c.x'[:,1] = 'c.c.e'[:];
Note: See TracChangeset for help on using the changeset viewer.