Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recommendation for code formatting (and apply it) #4221

Merged
merged 22 commits into from Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b3a85dc
Some generic Formatting guides - consistent with how classes are usua…
HansOlsson Nov 2, 2023
c7d5c7f
Use protected as a heading for a number of declarations.
HansOlsson Nov 2, 2023
9b42089
Avoid bad line-breaks in connect-annotation.
HansOlsson Nov 2, 2023
a2c97aa
Do not use tab.
HansOlsson Nov 2, 2023
8d7eaab
Remove trailing white-space
HansOlsson Nov 2, 2023
d4a6596
The end of a class shall not be indented relative to class.
HansOlsson Nov 2, 2023
554af2d
RemoveTrailingWhiteSpace
HansOlsson Nov 2, 2023
27cdec9
NoTab
HansOlsson Nov 2, 2023
7d67b7d
Even for redeclare extends ensure that class contents is indented rel…
HansOlsson Nov 2, 2023
9381d61
Indent annotation relative to class
HansOlsson Nov 2, 2023
f04eb52
Documentation shall be indented relative to class
HansOlsson Nov 2, 2023
3ad98fa
And sensible formatting
HansOlsson Nov 2, 2023
e88b12c
Use protected as heading consistently.
HansOlsson Nov 2, 2023
85fdcd0
Remove weird line-breaks and format equation consistently.
HansOlsson Nov 2, 2023
a054172
Add separation rule as well.
HansOlsson Nov 2, 2023
02b813b
And apply the rule
HansOlsson Nov 2, 2023
8f5ff8a
Update Modelica/Electrical/Machines/Sensors/CurrentQuasiRMSSensor.mo
HansOlsson Nov 2, 2023
271c0ea
Apply suggestions from code review
HansOlsson Nov 2, 2023
385fb08
Apply suggestions from code review
HansOlsson Nov 6, 2023
b2ed2c2
Specify how to handle modifier lists.
HansOlsson Nov 6, 2023
8057a51
TrailingWhiteSpace
HansOlsson Jan 10, 2024
0b277be
TrailingWhiteSpaceOnEmptyLine
HansOlsson Jan 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Complex.mo
Expand Up @@ -182,6 +182,7 @@ operator record Complex "Complex number with overloaded operators"
<p>This function returns the given Complex number c1 to the power of the Complex number c2.</p>
</html>"));
end complexPower;

function integerPower "Integer power of complex number"
import Complex;
input Complex c1 "Complex number";
Expand Down
4 changes: 2 additions & 2 deletions Modelica/Blocks/Sources.mo
Expand Up @@ -301,7 +301,7 @@ If parameter duration is set to 0.0, the limiting case of a Step signal is achie
if continuous then
y = offset + amplitude*smooth(0, (if time < startTime then Modelica.Math.sin(phase)
else Modelica.Math.sin(2*pi*f*(time - startTime) + phase)));
else
else
y = offset + (if time < startTime then 0 else amplitude*Modelica.Math.sin(2
*pi*f*(time - startTime) + phase));
end if;
Expand Down Expand Up @@ -614,7 +614,7 @@ and that the parameter <code>startTime</code> is omitted since the voltage can b
SI.Angle x=2*pi*f*(time - startTime);
equation
if continuous then
y = offset + amplitude*smooth(1, (if time < startTime then 1 else
y = offset + amplitude*smooth(1, (if time < startTime then 1 else
(if noEvent(time - startTime < eps) then 1 else (sin(x))/x)));
else
y = offset + (if time < startTime then 0 else amplitude*
Expand Down
3 changes: 1 addition & 2 deletions Modelica/Clocked/RealSignals/TimeBasedSources/Sine.mo
Expand Up @@ -10,8 +10,7 @@ block Sine "Generate sine signal"
"Output = offset for time < startTime";
protected
constant Real pi=Modelica.Constants.pi;
protected
SI.Time simTime;
SI.Time simTime;
equation
simTime = sample(time);
y = offset + (if simTime < startTime then 0 else amplitude*
Expand Down
Expand Up @@ -45,11 +45,9 @@ equation
connect(currentSource.p, ground.p)
annotation (Line(points={{-40,-10},{-20,-10}}, color={0,0,255}));
connect(ground.p, capacitor.n)
annotation (Line(points={{-20,-10},{0,-10}},
color={0,0,255}));
annotation (Line(points={{-20,-10},{0,-10}}, color={0,0,255}));
connect(currentSource.n, capacitor.p)
annotation (Line(points={{-40,10},{0,10}},
color={0,0,255}));
annotation (Line(points={{-40,10},{0,10}}, color={0,0,255}));
annotation (Icon(coordinateSystem(
preserveAspectRatio=false, extent={{-100,-100},{100,100}}),
graphics={Text(
Expand Down
54 changes: 27 additions & 27 deletions Modelica/Electrical/Digital.mo
Expand Up @@ -6112,9 +6112,9 @@ NC = no change
annotation (Placement(transformation(extent={{80,-20},{100,0}}),
iconTransformation(extent={{80,-20},{100,0}})));
protected
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL,y(start=L.'U', fixed=true));
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL,y(start=L.'U', fixed=true));
algorithm
nextstate := T.NXferTable[enable, x];
yy := nextstate;
Expand Down Expand Up @@ -6194,9 +6194,9 @@ UX: if dataIn == U then U else X
annotation (Placement(transformation(extent={{80,-20},{100,0}}),
iconTransformation(extent={{80,-20},{100,0}})));
protected
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL, y(start=L.'U', fixed=true));
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL, y(start=L.'U', fixed=true));
algorithm
nextstate := T.NRXferTable[enable, x];
yy := nextstate;
Expand Down Expand Up @@ -6276,9 +6276,9 @@ Strength Reduced: 0 -> L, 1 -> H, X -> W
annotation (Placement(transformation(extent={{80,-20},{100,0}}),
iconTransformation(extent={{80,-20},{100,0}})));
protected
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL);
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL);
algorithm
nextstate := T.PXferTable[enable, x];
yy := nextstate;
Expand Down Expand Up @@ -6358,9 +6358,9 @@ UX: if dataIn == U then U else X
annotation (Placement(transformation(extent={{80,-20},{100,0}}),
iconTransformation(extent={{80,-20},{100,0}})));
protected
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL);
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL);
algorithm
nextstate := T.PRXferTable[enable, x];
yy := nextstate;
Expand Down Expand Up @@ -6440,9 +6440,9 @@ UX: if dataIn == U then U else X
annotation (Placement(transformation(extent={{80,-20},{100,0}}),
iconTransformation(extent={{80,-20},{100,0}})));
protected
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL, y(start=L.'U', fixed=true));
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL, y(start=L.'U', fixed=true));
algorithm
nextstate := T.Buf3sTable[strength, T.UX01Conv[enable], T.UX01Conv[x]];
yy := nextstate;
Expand Down Expand Up @@ -6519,9 +6519,9 @@ DataOut*: Strength map for DataOut according to tristate table Buf3sTable
annotation (Placement(transformation(extent={{80,-20},{100,0}}),
iconTransformation(extent={{80,-20},{100,0}})));
protected
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL);
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL);
algorithm
nextstate := T.Buf3slTable[strength, T.UX01Conv[enable], T.UX01Conv[x]];
yy := nextstate;
Expand Down Expand Up @@ -6598,9 +6598,9 @@ DataOut*: Strength map for DataOut according to tristate table Buf3slTable
annotation (Placement(transformation(extent={{80,-20},{100,0}}),
iconTransformation(extent={{80,-20},{100,0}})));
protected
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL, y(start=L.'U',fixed=true));
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL, y(start=L.'U',fixed=true));
algorithm
nextstate := T.Buf3sTable[strength, T.UX01Conv[enable], T.UX01Conv[T.NotTable[x]]];
yy := nextstate;
Expand Down Expand Up @@ -6682,9 +6682,9 @@ DataOut*: Strength map for DataOut according to tristate table Buf3sTable
annotation (Placement(transformation(extent={{80,-20},{100,0}}),
iconTransformation(extent={{80,-20},{100,0}})));
protected
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL);
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL);
algorithm
nextstate := T.Buf3sTable[strength, T.UX01Conv[T.NotTable[enable]], T.UX01Conv[T.NotTable[x]]];
yy := nextstate;
Expand Down Expand Up @@ -7004,9 +7004,9 @@ Z = L.'Z'
iconTransformation(extent={{80,-10},{100,10}})));

protected
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL, y(start=L.'U',fixed=true));
D.Interfaces.Logic nextstate(start=L.'U');
D.Interfaces.DigitalOutput yy(start=L.'U');
D.Delay.InertialDelaySensitive inertialDelaySensitive(tLH=tLH, tHL=tHL, y(start=L.'U',fixed=true));

algorithm
nextstate := T.MUX2x1Table[T.UX01Conv[in1], T.UX01Conv[sel], T.UX01Conv[in0]];
Expand Down
Expand Up @@ -90,8 +90,7 @@ equation
connect(dcpm.flange, loadInertia.flange_a) annotation (Line(
points={{20,-20},{40,-20}}));
connect(dcpm.pin_an, ground.p)
annotation (Line(points={{4,-10},{4,0},{-8,0}},
color={0,0,255}));
annotation (Line(points={{4,-10},{4,0},{-8,0}}, color={0,0,255}));
connect(signalVoltage.p, currentSensor.p)
annotation (Line(points={{20,30},{20,20}}, color={0,0,255}));
connect(currentSensor.n, dcpm.pin_ap)
Expand Down
Expand Up @@ -39,8 +39,7 @@ equation
connect(ToSpacePhasor1.y, ToPolar1.u) annotation (Line(
points={{0,-1},{0,-18}}, color={0,0,127}));
connect(ToPolar1.y[1], Gain1.u) annotation (Line(
points={{0,-41},{0,-50.5},{0,-58}},
color={0,0,127}));
points={{0,-41},{0,-50.5},{0,-58}}, color={0,0,127}));
connect(Gain1.y, I) annotation (Line(
points={{0,-81},{0,-110}}, color={0,0,127}));
annotation (defaultComponentName="currentRMSSensor",
Expand Down
Expand Up @@ -151,8 +151,7 @@ equation
connect(multiSensor.pc, multiSensor.pv)
annotation (Line(points={{-10,40},{-10,50},{0,50}}, color={0,0,255}));
connect(multiSensor.nv,star2. plug_p)
annotation (Line(points={{0,30},{0,10}},
color={0,0,255}));
annotation (Line(points={{0,30},{0,10}}, color={0,0,255}));
connect(terminalBox.plug_sn, imc.plug_sn)
annotation (Line(points={{14,10},{14,10}}, color={0,0,255}));
connect(terminalBox.plug_sp, imc.plug_sp)
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Fluid/Pipes.mo
Expand Up @@ -940,7 +940,7 @@ This also allows for taking into account friction losses with respect to the act

// Assumptions
parameter Boolean allowFlowReversal=system.allowFlowReversal
"= true, if flow reversal is enabled, otherwise restrict flow to design direction (states[1] -> states[n+1])"
"= true, if flow reversal is enabled, otherwise restrict flow to design direction (states[1] -> states[n+1])"
HansOlsson marked this conversation as resolved.
Show resolved Hide resolved
annotation(Dialog(tab="Internal interface",enable=false,group="Assumptions"), Evaluate=true);
parameter Modelica.Fluid.Types.Dynamics momentumDynamics=system.momentumDynamics
"Formulation of momentum balance"
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Math/isPowerOf2.mo
Expand Up @@ -3,7 +3,7 @@ function isPowerOf2 "Determine if the integer input is a power of 2"
extends Modelica.Icons.Function;
input Integer i(min=1) "Integer scalar";
output Boolean result "= true, if integer scalar is a power of 2";
protected
protected
Integer target;
Integer powOf2;
algorithm
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Media/Air/ReferenceAir.mo
Expand Up @@ -2149,4 +2149,4 @@ Some parts of this library refer to the ThermoFluid library developed at Lund Un
Copyright &copy; 2013-2020, Modelica Association and contributors
</p>
</html>"));
end ReferenceAir;
end ReferenceAir;
2 changes: 1 addition & 1 deletion Modelica/Media/Air/ReferenceMoistAir.mo
Expand Up @@ -1859,7 +1859,7 @@ package ReferenceMoistAir
rho := max(p/(g.R_s*T*g.pi*g.gpi), 1e-9);
h_der := (1/rho - T*vt)*p_der - g.R_s*g.tau*g.tau*g.gtautau*T_der;
end h_pT_der;
annotation (Documentation(info="<html>
annotation (Documentation(info="<html>
<p>
This is a makeshift package avoiding the region validity checks of the IF97 utility functions
<a href=\"modelica://Modelica.Media.Water.IF97_Utilities.BaseIF97.Basic.g2\">BaseIF97.Basic.g2</a>,
Expand Down
8 changes: 4 additions & 4 deletions Modelica/Media/IdealGases/Common/package.mo
Expand Up @@ -147,7 +147,7 @@ Temperature T (= " + String(T) + " K) is not in the allowed range
end setState_dTX;

redeclare function extends setSmoothState
"Return thermodynamic state so that it smoothly approximates: if x > 0 then state_a else state_b"
"Return thermodynamic state so that it smoothly approximates: if x > 0 then state_a else state_b"
algorithm
state := ThermodynamicState(p=Media.Common.smoothStep(x, state_a.p, state_b.p, x_small),
T=Media.Common.smoothStep(x, state_a.T, state_b.T, x_small));
Expand Down Expand Up @@ -687,7 +687,7 @@ required from medium model \"" + mediumName + "\".");
end setState_dTX;

redeclare function extends setSmoothState
"Return thermodynamic state so that it smoothly approximates: if x > 0 then state_a else state_b"
"Return thermodynamic state so that it smoothly approximates: if x > 0 then state_a else state_b"
algorithm
state := ThermodynamicState(p=Media.Common.smoothStep(x, state_a.p, state_b.p, x_small),
T=Media.Common.smoothStep(x, state_a.T, state_b.T, x_small),
Expand Down Expand Up @@ -943,7 +943,7 @@ end gasMixtureViscosity;

redeclare replaceable function extends dynamicViscosity
"Return mixture dynamic viscosity"
protected
protected
DynamicViscosity[nX] etaX "Component dynamic viscosities";
algorithm
for i in 1:nX loop
Expand Down Expand Up @@ -1206,7 +1206,7 @@ end lowPressureThermalConductivity;
"Return thermal conductivity for low pressure gas mixtures"
input Integer method=methodForThermalConductivity
"Method to compute single component thermal conductivity";
protected
protected
ThermalConductivity[nX] lambdaX "Component thermal conductivities";
DynamicViscosity[nX] eta "Component thermal dynamic viscosities";
SpecificHeatCapacity[nX] cp "Component heat capacity";
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Media/package.mo
Expand Up @@ -4544,7 +4544,7 @@ This function computes an isentropic state transformation:
input ThermodynamicState state "Thermodynamic state record";
output MassFraction Xi[nXi] "Independent mass fractions";
end massFraction;

type MassFlowRate = SI.MassFlowRate (
quantity="MassFlowRate." + mediumName,
min=-1.0e5,
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Thermal/FluidHeatFlow/Examples/ParallelCooling.mo
Expand Up @@ -9,7 +9,7 @@ model ParallelCooling "Cooling circuit with parallel branches"
output SI.TemperatureDifference dTSource1=
prescribedHeatFlow1.port.T-TAmb "Temperature difference between heat source 1 and ambient condition";
output SI.TemperatureDifference dTtoPipe1=prescribedHeatFlow1.port.T-pipe1.T_q
"Temperature difference between heat source 1 and coolant in pipe 1";
"Temperature difference between heat source 1 and coolant in pipe 1";
output SI.TemperatureDifference dTCoolant1=pipe1.dT
"Coolant1's temperature increase in pipe 1";
output SI.TemperatureDifference dTSource2=
Expand Down
Expand Up @@ -4,7 +4,7 @@ model RelTemperatureSensor "Temperature difference sensor"
extends FluidHeatFlow.Interfaces.RelativeSensorBase;
Modelica.Blocks.Interfaces.RealOutput y(unit="K")
"Temperature difference as output signal"
annotation (absoluteValue = false, Placement(transformation(
annotation (absoluteValue = false, Placement(transformation(
origin={0,-110},
extent={{10,-10},{-10,10}},
rotation=90)));
Expand Down
3 changes: 1 addition & 2 deletions Modelica/Utilities/Streams.mo
Expand Up @@ -211,8 +211,7 @@ See <a href=\"modelica://Modelica.Utilities.Examples.ReadRealMatrixFromFile\">Ex
output Real matrix[nrow, ncol] "2D Real array";
external "C" ModelicaIO_readRealMatrix(fileName, matrixName, matrix, size(matrix, 1), size(matrix, 2), verboseRead)
annotation(IncludeDirectory="modelica://Modelica/Resources/C-Sources", Include="#include \"ModelicaIO.h\"", Library={"ModelicaIO", "ModelicaMatIO", "zlib"});
annotation(
Documentation(info="<html>
annotation(Documentation(info="<html>
<h4>Syntax</h4>
<blockquote><pre>
matrix = Streams.<strong>readRealMatrix</strong>(fileName, matrixName, nrow, ncol, verboseRead)
Expand Down
43 changes: 43 additions & 0 deletions Modelica/package.mo
Expand Up @@ -1300,6 +1300,49 @@ be defined like:
tab=\"Controller\",
group=\"Speed control\"));
</pre></blockquote>

<h4>Whitespace and Indentation</h4>
<p>
Trailing white-space (i.e., white-space at the end of the lines) shall not be used.
The tab-character shall not be used, since the tab-stops are not standardized.
</p>
<p>
The code in a&nbsp;class shall be indented relative to the class in steps of two spaces;
henrikt-ma marked this conversation as resolved.
Show resolved Hide resolved
except that the headings <code>public</code>, <code>protected</code>, <code>equation</code>,
<code>algorithm</code>, and <code>end</code> of class marker shall not be indented.
The keywords <code>public</code> and <code>protected</code> are headings for a&nbsp;group
henrikt-ma marked this conversation as resolved.
Show resolved Hide resolved
of declarations.
</p>
<p>
Long modifier lists shall be split into several indented lines with at most one modifier per line.
</p>
<p>
Full class definitions shall be separated by an empty line.
</p>

<h5>Example</h5>

<blockquote><pre>
<strong>package</strong> MyPackage
<strong>partial</strong> <strong>model</strong> BaseModel
<strong>parameter</strong> Real p;
<strong>input</strong> Real u(unit=\"m/s\");
<strong>protected</strong>
Real y;
Real x(
start=1,
unit=\"m\",
nominal=10);
<strong>equation</strong>
<strong>der</strong>(x) = u;
y = 2*x;
<strong>end</strong> BaseModel;

<strong>model</strong> ModelP2
<strong>extends</strong> BaseModel(p=2);
<strong>end</strong> ModelP2;
<strong>end</strong> MyPackage;
</pre></blockquote>
</html>"));
end Format;

Expand Down