Skip to content

Commit 816fda5

Browse files
authored
Merge pull request #516 from Inxton/ixc-should-transpile-protected-and-internal-members
Enhance transpilation support for member visibility and data exchange operations
2 parents 86c01a5 + a8fe41b commit 816fda5

17 files changed

Lines changed: 92 additions & 28 deletions

File tree

docfx/articles/compiler/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
**AXSharp Compiler (`ixc`) translates PLC data structures into C# (PLC .NET Twin), which makes the PLC data available in a structured way for any .NET application.**
44

5+
### Member visibility and generated code behavior
6+
7+
AXSharp transpilation now supports members declared as `public`, `protected`, and `internal`.
8+
9+
- **Transpilation / twin generation:** `public`, `protected`, and `internal` members can be generated into twin/onliner classes.
10+
- **Data exchange (Plain/POCO and Shadow mappings):** only `public` members participate in `OnlineToPlain`, `PlainToOnline`, `ShadowToPlain`, `PlainToShadow`, and related `HasChanged` evaluation.
11+
12+
This means non-public members can exist in generated twins but are intentionally excluded from Plain/Shadow data-transfer operations.
13+
514
### Adding types and members to the communication over WebAPI
615

716
Starting from the version v2.0.0+ of `sld`, to make member or type accessible over the communication there is a need to add pragma `{S7.extern=ReadWrite}` or `{S7.extern=ReadOnly}` in the appropriate place in the code.

docfx/articles/connectors/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ See also
158158

159159
Shadows are off-line value holders. Each primitive type has a shadow property. This property only affects the Online values if explicitly instructed to do so by the program. Shadows are helpful when we need to modify multiple values, but we need to send them into the PLC in one shot.
160160

161+
> [!NOTE]
162+
> Data exchange mappings are limited to `public` members. Members transpiled as `protected` or `internal` are not included in Online/Shadow/Plain transfer operations.
163+
161164
### Sending data from online to shadow
162165

163166
~~~C#
@@ -180,6 +183,8 @@ See also
180183

181184
Onliners are somewhat heavy objects that are well suited for communication with the controller, but they carry too much information that are a burden in some use cases. AXSharp compiler, therefore, creates `Plain/POCO` objects that are light CLR (C#) objects that can retrieve and send data from and to the controller.
182185

186+
Only `public` members are included when converting between online/shadow twins and Plain/POCO objects.
187+
183188
### Getting POCO object
184189

185190
~~~C#

src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/wwwroot/css/operon-variables.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
--color-result-inprogress: #0065B3;
143143
--color-result-exclude: #7866B9;
144144
--color-result-bypasse: #912B88;
145-
--color-result-inconcllusive: #B58840;
145+
--color-result-inconclusive: #B58840;
146146
--color-result-running: #00A2A3;
147147
--color-result-noaction: #949494;
148148
/* #end of result colors*/

src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Helpers/SemanticsHelpers.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// AXSharp.Compiler
1+
// AXSharp.Compiler
22
// Copyright (c) 2023 MTS spol. s r.o., and Contributors. All Rights Reserved.
33
// Contributors: https://github.com/inxton/axsharp/graphs/contributors
44
// See the LICENSE file in the repository root for more information.
@@ -34,8 +34,8 @@ public static (bool isEligible, ITypeDeclaration eligibleType) IsMemberEligibleF
3434
string coBuilder = "", bool warnMissingOrInconsistent = false)
3535
{
3636
var eligibility = field.IsEligibleForTranspile(sourceBuilder, warnMissingOrInconsistent);
37-
var isEligible = (field.AccessModifier == AccessModifier.Public
38-
&& eligibility.isEligibe
37+
var isEligible = ((field.AccessModifier == AccessModifier.Public || field.AccessModifier == AccessModifier.Protected || field.AccessModifier == AccessModifier.Internal)
38+
&& eligibility.isEligibe
3939
&& !IsToBeOmitted(field, sourceBuilder, coBuilder));
4040

4141
return (isEligible, eligibility.eligibleType);
@@ -362,7 +362,7 @@ public static (bool isEligibe, ITypeDeclaration? eligibleType) IsMemberEligibleF
362362
public static (bool isEligibe, ITypeDeclaration? eligibleType) IsMemberEligibleForConstructor(this IFieldDeclaration field, ISourceBuilder sourceBuilder, string coBuilder = "")
363363
{
364364
var eligibility = field.IsMemberEligibleForTranspile(sourceBuilder, coBuilder);
365-
return ((field.AccessModifier == AccessModifier.Public && eligibility.isEligible), eligibility.eligibleType);
365+
return (eligibility.isEligible, eligibility.eligibleType);
366366
}
367367

368368
/// <summary>
@@ -377,6 +377,24 @@ public static (bool isEligibe, ITypeDeclaration? eligibleType) IsMemberEligibleF
377377
return variable.IsMemberEligibleForTranspile(sourceBuilder, coBuilder);
378378
}
379379

380+
/// <summary>
381+
/// Determines whether a field member is eligible for data exchange operations
382+
/// (OnlineToPlain, PlainToOnline, PlainToShadow, ShadowToPlain, HasChanged, and POCO generation).
383+
/// Only public members participate in data exchange; internal and private members are excluded.
384+
/// </summary>
385+
/// <param name="field">Field declaration</param>
386+
/// <param name="sourceBuilder">Source builder</param>
387+
/// <param name="coBuilder">Co-builder signature (e.g. POCO, Onliner, etc.)</param>
388+
/// <param name="warnMissingOrInconsistent">Issues warning when the type is eligible but not available.</param>
389+
/// <returns>True when the member is eligible for data exchange.</returns>
390+
public static (bool isEligible, ITypeDeclaration eligibleType) IsMemberEligibleForDataExchange(this IFieldDeclaration field, ISourceBuilder sourceBuilder,
391+
string coBuilder = "", bool warnMissingOrInconsistent = false)
392+
{
393+
var eligibility = field.IsMemberEligibleForTranspile(sourceBuilder, coBuilder, warnMissingOrInconsistent);
394+
var isEligible = eligibility.isEligible && field.AccessModifier == AccessModifier.Public;
395+
return (isEligible, eligibility.eligibleType);
396+
}
397+
380398
private static bool IsAvailableForComm(this IDeclaration declaration, ISourceBuilder sourceBuilder)
381399
{
382400
if (sourceBuilder.CompilerOptions is { IgnoreS7Pragmas: true }) return true;
@@ -449,4 +467,4 @@ public static string AddDocumentationComment(this IDocComment docComment, ISourc
449467
{
450468
return docComment.Content;
451469
}
452-
}
470+
}

src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerPlainerOnlineToPlainBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// AXSharp.Compiler.Cs
1+
// AXSharp.Compiler.Cs
22
// Copyright (c) 2023 MTS spol. s r.o., and Contributors. All Rights Reserved.
33
// Contributors: https://github.com/inxton/axsharp/graphs/contributors
44
// See the LICENSE file in the repository root for more information.
@@ -36,7 +36,7 @@ protected CsOnlinerPlainerOnlineToPlainBuilder(ISourceBuilder sourceBuilder)
3636

3737
public void CreateFieldDeclaration(IFieldDeclaration fieldDeclaration, IxNodeVisitor visitor)
3838
{
39-
var eligible = fieldDeclaration.IsMemberEligibleForTranspile(SourceBuilder, "POCO");
39+
var eligible = fieldDeclaration.IsMemberEligibleForDataExchange(SourceBuilder, "POCO");
4040
if (eligible.isEligible)
4141
{
4242
CreateAssignment(fieldDeclaration.Type, fieldDeclaration);
@@ -212,4 +212,4 @@ public void CreateDocComment(IDocComment semanticTypeAccess, ICombinedThreeVisit
212212
{
213213
AddToSource(semanticTypeAccess.AddDocumentationComment(SourceBuilder));
214214
}
215-
}
215+
}

src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerPlainerPlainToOnlineBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// AXSharp.Compiler.Cs
1+
// AXSharp.Compiler.Cs
22
// Copyright (c) 2023 MTS spol. s r.o., and Contributors. All Rights Reserved.
33
// Contributors: https://github.com/inxton/axsharp/graphs/contributors
44
// See the LICENSE file in the repository root for more information.
@@ -36,7 +36,7 @@ protected CsOnlinerPlainerPlainToOnlineBuilder(ISourceBuilder sourceBuilder)
3636

3737
public void CreateFieldDeclaration(IFieldDeclaration fieldDeclaration, IxNodeVisitor visitor)
3838
{
39-
var eligibility = fieldDeclaration.IsMemberEligibleForTranspile(SourceBuilder, "POCO");
39+
var eligibility = fieldDeclaration.IsMemberEligibleForDataExchange(SourceBuilder, "POCO");
4040
if (eligibility.isEligible)
4141
{
4242
CreateAssignment(fieldDeclaration.Type, fieldDeclaration);
@@ -215,4 +215,4 @@ public void CreateDocComment(IDocComment semanticTypeAccess, ICombinedThreeVisit
215215
{
216216
AddToSource(semanticTypeAccess.AddDocumentationComment(SourceBuilder));
217217
}
218-
}
218+
}

src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerPlainerPlainToShadowBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// AXSharp.Compiler.Cs
1+
// AXSharp.Compiler.Cs
22
// Copyright (c) 2023 MTS spol. s r.o., and Contributors. All Rights Reserved.
33
// Contributors: https://github.com/inxton/axsharp/graphs/contributors
44
// See the LICENSE file in the repository root for more information.
@@ -35,7 +35,7 @@ protected CsOnlinerPlainerPlainToShadowBuilder(ISourceBuilder sourceBuilder)
3535

3636
public void CreateFieldDeclaration(IFieldDeclaration fieldDeclaration, IxNodeVisitor visitor)
3737
{
38-
var eligibility = fieldDeclaration.IsMemberEligibleForTranspile(SourceBuilder, "POCO");
38+
var eligibility = fieldDeclaration.IsMemberEligibleForDataExchange(SourceBuilder, "POCO");
3939
if (eligibility.isEligible)
4040
{
4141
CreateAssignment(fieldDeclaration.Type, fieldDeclaration);

src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerPlainerShadowToPlainBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// AXSharp.Compiler.Cs
1+
// AXSharp.Compiler.Cs
22
// Copyright (c) 2023 MTS spol. s r.o., and Contributors. All Rights Reserved.
33
// Contributors: https://github.com/inxton/axsharp/graphs/contributors
44
// See the LICENSE file in the repository root for more information.
@@ -35,7 +35,7 @@ protected CsOnlinerPlainerShadowToPlainBuilder(ISourceBuilder sourceBuilder)
3535

3636
public void CreateFieldDeclaration(IFieldDeclaration fieldDeclaration, IxNodeVisitor visitor)
3737
{
38-
var eligibility = fieldDeclaration.IsMemberEligibleForTranspile(SourceBuilder, "POCO");
38+
var eligibility = fieldDeclaration.IsMemberEligibleForDataExchange(SourceBuilder, "POCO");
3939
if (eligibility.isEligible)
4040
{
4141
CreateAssignment(fieldDeclaration.Type, fieldDeclaration);

src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/HasChangedBuilder/CsOnlinerHasChangedBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// AXSharp.Compiler.Cs
1+
// AXSharp.Compiler.Cs
22
// Copyright (c) 2023 MTS spol. s r.o., and Contributors. All Rights Reserved.
33
// Contributors: https://github.com/inxton/axsharp/graphs/contributors
44
// See the LICENSE file in the repository root for more information.
@@ -35,7 +35,7 @@ protected CsOnlinerHasChangedBuilder(ISourceBuilder sourceBuilder)
3535

3636
public void CreateFieldDeclaration(IFieldDeclaration fieldDeclaration, IxNodeVisitor visitor)
3737
{
38-
var eligibility = fieldDeclaration.IsMemberEligibleForTranspile(SourceBuilder, "POCO");
38+
var eligibility = fieldDeclaration.IsMemberEligibleForDataExchange(SourceBuilder, "POCO");
3939
if (eligibility.isEligible)
4040
{
4141
CreateAssignment(fieldDeclaration.Type, fieldDeclaration);

src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Plain/CsPlainConstructorBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// AXSharp.Compiler.Cs
1+
// AXSharp.Compiler.Cs
22
// Copyright (c) 2023 MTS spol. s r.o., and Contributors. All Rights Reserved.
33
// Contributors: https://github.com/inxton/axsharp/graphs/contributors
44
// See the LICENSE file in the repository root for more information.
@@ -66,8 +66,8 @@ public void CreateStructuredType(IStructuredTypeDeclaration structuredTypeDeclar
6666

6767
public void CreateFieldDeclaration(IFieldDeclaration fieldDeclaration, IxNodeVisitor visitor)
6868
{
69-
var eligibility = fieldDeclaration.IsMemberEligibleForConstructor(SourceBuilder);
70-
if (eligibility.isEligibe)
69+
var eligibility = fieldDeclaration.IsMemberEligibleForDataExchange(SourceBuilder);
70+
if (eligibility.isEligible)
7171
{
7272
switch (fieldDeclaration.Type)
7373
{
@@ -192,4 +192,4 @@ public void CreateDocComment(IDocComment semanticTypeAccess, ICombinedThreeVisit
192192
{
193193
AddToSource(semanticTypeAccess.AddDocumentationComment(SourceBuilder));
194194
}
195-
}
195+
}

0 commit comments

Comments
 (0)