Skip to content

Commit 16498b7

Browse files
authored
Merge pull request #84 from klauer/fix_83
FIX: format failure of #83
2 parents 3e1a543 + 554f57d commit 16498b7

File tree

5 files changed

+333
-2
lines changed

5 files changed

+333
-2
lines changed

blark/parse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ def get_items():
528528
print(dump_json(summary.CodeSummary, summarized, include_meta=include_meta))
529529
else:
530530
print(summarized)
531+
else:
532+
summarized = None
531533

532534
if not results_by_filename:
533535
return {}
@@ -543,6 +545,7 @@ def get_items():
543545
"results": results,
544546
"by_filename": results_by_filename,
545547
"failures": failures,
548+
"summary": summarized,
546549
},
547550
message=(
548551
f"Saw {len(results_by_filename)} files with {len(results)} "

blark/solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def parts_by_name(self) -> dict[str, SupportedPOUPart]:
718718
return {
719719
part.name: part
720720
for part in self.parts
721-
if not isinstance(part, TcUnknownXml)
721+
if isinstance(part, (TcAction, TcMethod, TcProperty))
722722
}
723723

724724
def get_child_by_identifier(

blark/tests/POUs/FB_Log.TcPOU

Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.12">
3+
<POU Name="FB_Log" Id="{109d7a4d-eb69-4ad3-a712-f6cfd124a520}" SpecialFunc="None">
4+
<Declaration><![CDATA[{attribute 'call_after_init'}
5+
{attribute 'reflection'}
6+
FUNCTION_BLOCK FB_Log IMPLEMENTS I_SendLog
7+
8+
VAR
9+
{attribute 'hide'}
10+
_aLogBaseExt : ARRAY[-1..SIZEOF(TwinCAT_SystemInfoVarList._TaskInfo)/SIZEOF(PlcTaskSystemInfo)] OF FB_LogBaseExt;
11+
{attribute 'hide'}
12+
_aInternalMsg : ARRAY[-1..SIZEOF(TwinCAT_SystemInfoVarList._TaskInfo)/SIZEOF(PlcTaskSystemInfo)] OF STRING(100);
13+
{attribute 'hide'}
14+
_aLogSeverity : ARRAY[-1..SIZEOF(TwinCAT_SystemInfoVarList._TaskInfo)/SIZEOF(PlcTaskSystemInfo)] OF E_Severity;
15+
16+
{attribute 'hide'}
17+
{attribute 'instance-path'}
18+
{attribute 'noinit'}
19+
_InstancePath : STRING; // contains instance path
20+
21+
22+
{attribute 'hide'}
23+
_bUseExternalName : BOOL;
24+
_InstanceName : STRING(25);
25+
26+
27+
END_VAR]]></Declaration>
28+
<Implementation>
29+
<ST><![CDATA[]]></ST>
30+
</Implementation>
31+
<Folder Name="External" Id="{44366482-53e3-4013-880e-78d7711b79ed}">
32+
<Folder Name="Severities" Id="{40aa847d-2e73-44e4-97ca-3b095735a324}" />
33+
</Folder>
34+
<Folder Name="Get/Set" Id="{3903cc3c-2e60-4fa9-a6b0-f48b20231a41}" />
35+
<Folder Name="Internal" Id="{4be4cd9f-341a-482f-b3a1-45a9d816dfcd}" />
36+
<Method Name="_GetLogConditionFullfilled" Id="{eff3713e-a77d-4fe0-9cd4-75ecc46ac5a5}" FolderPath="Get/Set\">
37+
<Declaration><![CDATA[METHOD Protected _GetLogConditionFullfilled : BOOL
38+
VAR_INPUT
39+
eSeverity : E_Severity;
40+
END_VAR
41+
]]></Declaration>
42+
<Implementation>
43+
<ST><![CDATA[ // Each Tasklogger is configured identically, therefore it is sufficient to check the first.
44+
_GetLogConditionFullfilled := _aLogBaseExt[1].GetLogConditionFullfilled(eSeverity);]]></ST>
45+
</Implementation>
46+
</Method>
47+
<Method Name="_Init" Id="{0e12f3d0-a254-410d-bda3-c19c038fd1dd}" FolderPath="Internal\">
48+
<Declaration><![CDATA[{attribute 'call_after_init'}
49+
METHOD protected _Init
50+
51+
VAR_INST
52+
i : UINT;
53+
_sShortenedPath : T_MAXSTRING;
54+
_nPosInString : INT := 0;
55+
END_VAR]]></Declaration>
56+
<Implementation>
57+
<ST><![CDATA[// Get Instance Path
58+
IF NOT _bUseExternalName THEN
59+
_sShortenedPath := _InstancePath;
60+
61+
WHILE(FIND(_sShortenedPath, '.') > 0) DO
62+
_nPosInString := FIND(_sShortenedPath, '.');
63+
_sShortenedPath := DELETE(_sShortenedPath, _nPosInString+1, 0);
64+
END_WHILE
65+
66+
_InstanceName := _sShortenedPath;
67+
Name := _sShortenedPath;
68+
END_IF]]></ST>
69+
</Implementation>
70+
</Method>
71+
<Method Name="AddString" Id="{e7f31b77-dc46-4ae0-8e44-0599c16ce265}" FolderPath="External\">
72+
<Declaration><![CDATA[METHOD AddString : I_SendLog
73+
VAR_INPUT
74+
sString : STRING(50);
75+
END_VAR
76+
]]></Declaration>
77+
<Implementation>
78+
<ST><![CDATA[IF _aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] <> E_Severity.off THEN
79+
_aInternalMsg[Tc2_System.GETCURTASKINDEXEX()] := Concat(_aInternalMsg[Tc2_System.GETCURTASKINDEXEX()],sString);
80+
END_IF
81+
AddString := THIS^;]]></ST>
82+
</Implementation>
83+
</Method>
84+
<Method Name="AddVar" Id="{41fcd9d6-a84a-44ca-9849-15cb6dfbaebc}" FolderPath="External\">
85+
<Declaration><![CDATA[{attribute 'hasanytype'}
86+
METHOD AddVar : I_SendLog
87+
88+
VAR_INPUT
89+
{attribute 'anytypeclass' := 'ANY'}
90+
anyVar : __SYSTEM.AnyType;
91+
END_VAR
92+
]]></Declaration>
93+
<Implementation>
94+
<ST><![CDATA[IF _aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] <> E_Severity.off THEN
95+
_aInternalMsg[Tc2_System.GETCURTASKINDEXEX()] := Concat(_aInternalMsg[Tc2_System.GETCURTASKINDEXEX()],TO_STRING(anyVar.pValue^));
96+
END_IF
97+
AddVar := THIS^;]]></ST>
98+
</Implementation>
99+
</Method>
100+
<Method Name="Debug" Id="{0ffe6957-f2b4-49bb-aa12-b3e0e497b253}" FolderPath="External\Severities\">
101+
<Declaration><![CDATA[METHOD Debug : I_SendLog
102+
VAR_INPUT
103+
sMsg : STRING(25);
104+
END_VAR
105+
]]></Declaration>
106+
<Implementation>
107+
<ST><![CDATA[IF _GetLogConditionFullfilled(eSeverity := E_Severity.debug) THEN
108+
_aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] := E_Severity.debug;
109+
_aInternalMsg[Tc2_System.GETCURTASKINDEXEX()] := sMsg;
110+
ELSE
111+
_aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] := E_severity.off;
112+
END_IF
113+
114+
Debug := THIS^;]]></ST>
115+
</Implementation>
116+
</Method>
117+
<Method Name="Error" Id="{4d0b31aa-bb30-4a69-a343-3f4217293006}" FolderPath="External\Severities\">
118+
<Declaration><![CDATA[METHOD Error : I_SendLog
119+
VAR_INPUT
120+
sMsg : STRING(25);
121+
END_VAR
122+
123+
]]></Declaration>
124+
<Implementation>
125+
<ST><![CDATA[IF _GetLogConditionFullfilled(eSeverity := E_Severity.error) THEN
126+
_aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] := E_Severity.error;
127+
_aInternalMsg[Tc2_System.GETCURTASKINDEXEX()] := sMsg;
128+
ELSE
129+
_aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] := E_severity.off;
130+
END_IF
131+
132+
Error := THIS^;]]></ST>
133+
</Implementation>
134+
</Method>
135+
<Method Name="Fatal" Id="{aeacf9c0-48e5-4e89-8083-0f2fef85d923}" FolderPath="External\Severities\">
136+
<Declaration><![CDATA[METHOD Fatal : I_SendLog
137+
VAR_INPUT
138+
sMsg : STRING;
139+
END_VAR
140+
]]></Declaration>
141+
<Implementation>
142+
<ST><![CDATA[IF _GetLogConditionFullfilled(eSeverity := E_Severity.fatal) THEN
143+
_aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] := E_Severity.fatal;
144+
_aInternalMsg[Tc2_System.GETCURTASKINDEXEX()] := sMsg;
145+
ELSE
146+
_aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] := E_severity.off;
147+
END_IF
148+
149+
Fatal := THIS^;]]></ST>
150+
</Implementation>
151+
</Method>
152+
<Method Name="Info" Id="{b4a1c211-05ac-4219-9a0e-1a843f9d4300}" FolderPath="External\Severities\">
153+
<Declaration><![CDATA[METHOD Info : I_SendLog
154+
VAR_INPUT
155+
sMsg : STRING;
156+
END_VAR
157+
]]></Declaration>
158+
<Implementation>
159+
<ST><![CDATA[IF _GetLogConditionFullfilled(eSeverity := E_Severity.info) THEN
160+
_aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] := E_Severity.info;
161+
_aInternalMsg[Tc2_System.GETCURTASKINDEXEX()] := sMsg;
162+
ELSE
163+
_aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] := E_severity.off;
164+
END_IF
165+
166+
Info := THIS^;]]></ST>
167+
</Implementation>
168+
</Method>
169+
<Property Name="LogCollector" Id="{ac06bd05-216f-4578-a924-892e6ec29b69}" FolderPath="Get/Set\">
170+
<Declaration><![CDATA[PROPERTY PUBLIC LogCollector : I_PushLog]]></Declaration>
171+
<Set Name="Set" Id="{caffe710-c626-4f41-9fe6-227b89e05871}">
172+
<Declaration><![CDATA[VAR
173+
n : DINT;
174+
END_VAR]]></Declaration>
175+
<Implementation>
176+
<ST><![CDATA[FOR n := -1 TO SIZEOF(TwinCAT_SystemInfoVarList._TaskInfo)/SIZEOF(PlcTaskSystemInfo) DO
177+
_aLogBaseExt[n].LogCollector := LogCollector;
178+
END_FOR]]></ST>
179+
</Implementation>
180+
</Set>
181+
</Property>
182+
<Property Name="MinSeverity" Id="{06ab50fe-2b74-4fc5-873d-6d606277c87b}" FolderPath="Get/Set\">
183+
<Declaration><![CDATA[PROPERTY Public MinSeverity : E_Severity]]></Declaration>
184+
<Set Name="Set" Id="{39e59a5e-b90d-4ee5-b370-19d4bd55a41c}">
185+
<Declaration><![CDATA[VAR
186+
n : DINT;
187+
END_VAR]]></Declaration>
188+
<Implementation>
189+
<ST><![CDATA[FOR n := -1 TO SIZEOF(TwinCAT_SystemInfoVarList._TaskInfo)/SIZEOF(PlcTaskSystemInfo) DO
190+
_aLogBaseExt[n].MinSeverity := MinSeverity;
191+
END_FOR]]></ST>
192+
</Implementation>
193+
</Set>
194+
</Property>
195+
<Property Name="Name" Id="{70eb1b3d-44f7-4c9a-98e8-82ecb25b0e5f}" FolderPath="Get/Set\">
196+
<Declaration><![CDATA[PROPERTY Name : String(25)]]></Declaration>
197+
<Set Name="Set" Id="{e577ca28-e360-4834-8716-8ab2be2e863b}">
198+
<Declaration><![CDATA[VAR
199+
n : DINT;
200+
END_VAR]]></Declaration>
201+
<Implementation>
202+
<ST><![CDATA[_bUseExternalName := TRUE;
203+
_InstanceName := Name;
204+
FOR n := -1 TO SIZEOF(TwinCAT_SystemInfoVarList._TaskInfo)/SIZEOF(PlcTaskSystemInfo) DO
205+
_aLogBaseExt[n].Name := Name;
206+
END_FOR]]></ST>
207+
</Implementation>
208+
</Set>
209+
</Property>
210+
<Method Name="Send" Id="{74aadea7-f021-411c-8f22-79856c996b07}" FolderPath="External\">
211+
<Declaration><![CDATA[METHOD Send : BOOL
212+
]]></Declaration>
213+
<Implementation>
214+
<ST><![CDATA[IF _aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] <> E_Severity.off THEN
215+
Send := _aLogBaseExt[Tc2_System.GETCURTASKINDEXEX()].SendMessage(sMsg := _aInternalMsg[Tc2_System.GETCURTASKINDEXEX()],
216+
eSeverity := _aLogSeverity[Tc2_System.GETCURTASKINDEXEX()]);
217+
ELSE
218+
Send := FALSE;
219+
END_IF
220+
]]></ST>
221+
</Implementation>
222+
</Method>
223+
<Method Name="Trace" Id="{2c57975a-5275-4c58-bf2f-2109fda3867c}" FolderPath="External\Severities\">
224+
<Declaration><![CDATA[METHOD Trace : I_SendLog
225+
VAR_INPUT
226+
sMsg : STRING;
227+
END_VAR
228+
]]></Declaration>
229+
<Implementation>
230+
<ST><![CDATA[IF _GetLogConditionFullfilled(eSeverity := E_Severity.trace) THEN
231+
_aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] := E_Severity.trace;
232+
_aInternalMsg[Tc2_System.GETCURTASKINDEXEX()] := sMsg;
233+
ELSE
234+
_aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] := E_severity.off;
235+
END_IF
236+
237+
Trace := THIS^;]]></ST>
238+
</Implementation>
239+
</Method>
240+
<Method Name="Warn" Id="{8fa6c46d-8bad-4dbb-8550-6e6ebeb2d493}" FolderPath="External\Severities\">
241+
<Declaration><![CDATA[METHOD Warn : I_SendLog
242+
VAR_INPUT
243+
sMsg : STRING;
244+
END_VAR
245+
]]></Declaration>
246+
<Implementation>
247+
<ST><![CDATA[IF _GetLogConditionFullfilled(eSeverity := E_Severity.warn) THEN
248+
_aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] := E_Severity.warn;
249+
_aInternalMsg[Tc2_System.GETCURTASKINDEXEX()] := sMsg;
250+
ELSE
251+
_aLogSeverity[Tc2_System.GETCURTASKINDEXEX()] := E_severity.off;
252+
END_IF
253+
254+
Warn := THIS^;]]></ST>
255+
</Implementation>
256+
</Method>
257+
<LineIds Name="FB_Log">
258+
<LineId Id="9" Count="0" />
259+
</LineIds>
260+
<LineIds Name="FB_Log._GetLogConditionFullfilled">
261+
<LineId Id="11" Count="0" />
262+
<LineId Id="15" Count="0" />
263+
</LineIds>
264+
<LineIds Name="FB_Log._Init">
265+
<LineId Id="6" Count="9" />
266+
<LineId Id="20" Count="0" />
267+
<LineId Id="2" Count="0" />
268+
</LineIds>
269+
<LineIds Name="FB_Log.AddString">
270+
<LineId Id="13" Count="0" />
271+
<LineId Id="15" Count="0" />
272+
<LineId Id="18" Count="0" />
273+
<LineId Id="7" Count="0" />
274+
</LineIds>
275+
<LineIds Name="FB_Log.AddVar">
276+
<LineId Id="42" Count="2" />
277+
<LineId Id="22" Count="0" />
278+
</LineIds>
279+
<LineIds Name="FB_Log.Debug">
280+
<LineId Id="27" Count="6" />
281+
<LineId Id="2" Count="0" />
282+
</LineIds>
283+
<LineIds Name="FB_Log.Error">
284+
<LineId Id="52" Count="6" />
285+
<LineId Id="2" Count="0" />
286+
</LineIds>
287+
<LineIds Name="FB_Log.Fatal">
288+
<LineId Id="7" Count="6" />
289+
<LineId Id="2" Count="0" />
290+
</LineIds>
291+
<LineIds Name="FB_Log.Info">
292+
<LineId Id="7" Count="6" />
293+
<LineId Id="2" Count="0" />
294+
</LineIds>
295+
<LineIds Name="FB_Log.LogCollector.Set">
296+
<LineId Id="6" Count="0" />
297+
<LineId Id="3" Count="0" />
298+
<LineId Id="7" Count="0" />
299+
</LineIds>
300+
<LineIds Name="FB_Log.MinSeverity.Set">
301+
<LineId Id="5" Count="1" />
302+
<LineId Id="2" Count="0" />
303+
</LineIds>
304+
<LineIds Name="FB_Log.Name.Set">
305+
<LineId Id="8" Count="1" />
306+
<LineId Id="4" Count="1" />
307+
<LineId Id="3" Count="0" />
308+
</LineIds>
309+
<LineIds Name="FB_Log.Send">
310+
<LineId Id="6" Count="0" />
311+
<LineId Id="9" Count="3" />
312+
<LineId Id="8" Count="0" />
313+
<LineId Id="4" Count="0" />
314+
</LineIds>
315+
<LineIds Name="FB_Log.Trace">
316+
<LineId Id="7" Count="6" />
317+
<LineId Id="2" Count="0" />
318+
</LineIds>
319+
<LineIds Name="FB_Log.Warn">
320+
<LineId Id="7" Count="6" />
321+
<LineId Id="2" Count="0" />
322+
</LineIds>
323+
</POU>
324+
</TcPlcObject>

blark/transform.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,9 +1203,13 @@ class ArraySpecification:
12031203
def base_type_name(self) -> Union[str, lark.Token]:
12041204
"""The base type name."""
12051205
if isinstance(self.type, DataType):
1206+
if isinstance(self.type.type_name, StringTypeSpecification):
1207+
return str(self.type)
12061208
return self.type.type_name
12071209
if isinstance(self.type, ArraySpecification):
12081210
return self.type.base_type_name
1211+
if isinstance(self.type, StringTypeSpecification):
1212+
return self.type.base_type_name
12091213
return str(self.type.name)
12101214

12111215
@property

0 commit comments

Comments
 (0)