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

[NEW-FEATURE] Ignore reading and writing when a particular attribute is declared for a member of type #237

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cake/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.IO.Compression;
using System.Linq;
using Build.FilteredSolution;
using Cake.Common.IO;
using Cake.Common.Tools.DotNet;
using Cake.Common.Tools.DotNet.Build;
using Cake.Common.Tools.DotNet.MSBuild;
Expand All @@ -22,6 +23,8 @@
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Frosting;
using Polly;
using static NuGet.Packaging.PackagingConstants;
using Path = System.IO.Path;

public class BuildContext : FrostingContext
Expand Down Expand Up @@ -90,6 +93,8 @@ public BuildContext(ICakeContext context, BuildParameters buildParameters)
public void UploadTestPlc(string workingDirectory, string targetIp,
string targetPlatform)
{
var lockFile = Path.Combine(workingDirectory, "apax-lock.json");
if (File.Exists(lockFile)) this.DeleteFile(lockFile);

this.Log.Information($"Installing dependencies for ax project '{workingDirectory}' at {targetIp}");

Expand Down
3 changes: 3 additions & 0 deletions cake/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
using Credentials = Octokit.Credentials;
using Path = System.IO.Path;
using ProductHeaderValue = Octokit.ProductHeaderValue;
using static NuGet.Packaging.PackagingConstants;


public static class Program
Expand Down Expand Up @@ -71,6 +72,8 @@ public override void Run(BuildContext context)
context.CleaUpAllBinsAndObjs();
context.CleanDirectory(context.Artifacts);
context.CleanDirectory(context.TestResults);


}
}

Expand Down
14 changes: 14 additions & 0 deletions docfx/articles/compiler/ATTRIBUTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ CLASS PUBLIC MyClass
END_CLASS
~~~

### Ignoring Communication with the Controller for POCO Operations

To minimize the communication overhead between the application and the controller during POCO operations, you can annotate specific members of a type to bypass data exchange. This attribute should be applied when the compiler omits the compilation of particular members in the POCO object.

```iecst
CLASS PUBLIC MyClass
VAR PUBLIC
{#ix-attr:[CompilerOmits("POCO")]}
{#ix-attr:[IgnoreOnPocoOperation()]}
MyStringIgnoredInPocos : STRING;
END_VAR
END_CLASS
```

### Generic extension attributes

ixc allows to declare generic attributes in ST that will add a genetic notation to transpiled types.
Expand Down
22 changes: 10 additions & 12 deletions src/AXSharp-L3-tests.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,40 @@
"AXSharp.abstractions\\src\\AXSharp.Abstractions\\AXSharp.Abstractions.csproj",
"AXSharp.blazor\\src\\AXSharp.Presentation.Blazor.Controls\\AXSharp.Presentation.Blazor.Controls.csproj",
"AXSharp.blazor\\src\\AXSharp.Presentation.Blazor\\AXSharp.Presentation.Blazor.csproj",
"AXSharp.blazor\\tests\\sandbox\\ComponentsExamples\\ComponentsExamples.csproj",
"AXSharp.blazor\\tests\\sandbox\\AXSharp.RenderableContent.Tests\\AXSharp.RenderableContent.Tests.csproj",
"AXSharp.blazor\\tests\\sandbox\\ComponentsExamples\\ComponentsExamples.csproj",
"AXSharp.blazor\\tests\\sandbox\\IxBlazor.App\\IxBlazor.App.csproj",
"AXSharp.blazor\\tests\\sandbox\\ax-blazor-example\\ix\\ax-blazor-example.csproj",
"AXSharp.blazor\\tests\\sandbox\\ax-blazor-example\\ix\\ax_blazor_example.csproj",
"AXSharp.compiler\\src\\AXSharp.Compiler.Abstractions\\AXSharp.Compiler.Abstractions.csproj",
"AXSharp.compiler\\src\\AXSharp.Compiler\\AXSharp.Compiler.csproj",
"AXSharp.compiler\\src\\AXSharp.Cs.Compiler\\AXSharp.Compiler.Cs.csproj",
"AXSharp.compiler\\src\\AXSharp.Compiler.Abstractions\\AXSharp.Compiler.Abstractions.csproj",
"AXSharp.compiler\\src\\ixc\\AXSharp.ixc.csproj",
"AXSharp.compiler\\src\\ixd\\AXSharp.ixd.csproj",
"AXSharp.compiler\\src\\ixr\\AXSharp.ixr.csproj",
"AXSharp.compiler\\tests\\AXSharp.CompilerTests\\AXSharp.CompilerTests.csproj",
"AXSharp.compiler\\tests\\AXSharp.Compiler.CsTests\\AXSharp.Compiler.CsTests.csproj",
"AXSharp.compiler\\tests\\AXSharp.CompilerTests\\AXSharp.CompilerTests.csproj",
"AXSharp.compiler\\tests\\AXSharp.ixc.Tests\\AXSharp.ixc.Tests.csproj",
"AXSharp.compiler\\tests\\AXSharp.ixr.Tests\\AXSharp.ixr.Tests.csproj",
"AXSharp.connectors\\src\\AXSharp.Connector.S71500.WebAPI\\AXSharp.Connector.S71500.WebAPI.csproj",
"AXSharp.connectors\\src\\AXSharp.Connector\\AXSharp.Connector.csproj",
"AXSharp.connectors\\src\\AXSharp.TIA.Connector\\AXSharp.TIA2AXSharp.csproj",
"AXSharp.connectors\\tests\\AXSharp.Connector.Sax.WebAPITests\\AXSharp.Connector.S71500.WebAPITests.csproj",
"AXSharp.connectors\\tests\\AXSharp.ConnectorLegacyTests\\AXSharp.ConnectorLegacyTests.csproj",
"AXSharp.connectors\\tests\\AXSharp.ConnectorTests\\AXSharp.ConnectorTests\\AXSharp.ConnectorTests.csproj",
"AXSharp.connectors\\tests\\AXSharp.TIA.ConnectorTests\\AXSharp.TIA2AXSharpTests_L3.csproj",
"AXSharp.connectors\\tests\\ax-test-project\\ix\\ax_test_project.csproj",
"AXSharp.connectors\\tests\\exploring\\Webserver.Api.Exploratory\\Webserver.Api.Exploratory.csproj",
"AXSharp.connectors\\tests\\exploring\\exploratory.consoleapp\\exploratory.consoleapp.csproj",
"AXSharp.examples\\hello.world.console\\hello.world.console.plc\\ix\\hello.world.console.plc.csproj",
"AXSharp.examples\\hello.world.console\\hello.world.console\\hello.world.console.csproj",
"AXSharp.templates\\working\\AXSharp.templates.csproj",
"AXSharp.templates\\working\\templates\\ixblazor\\ixblazor.app\\ixblazor.hmi.csproj",
"AXSharp.templates\\working\\templates\\ixblazor\\ixblazor.twin\\ixblazor.csproj",
"AXSharp.templates\\working\\templates\\ixconsole\\ixconsole.twin\\ixconsole.csproj",
"AXSharp.templates\\working\\templates\\ixconsole\\ixconsole\\ixconsole.app.csproj",
"AXSharp.templates\\working\\templates\\ixtwin\\ixtwin.csproj",
"AXSharp.tools\\tests\\AXSharp.LocalizablesToResx.Tests\\AXSharp.LocalizablesToResx.Tests.csproj"
"AXSharp.tools\\src\\AXSharp.LocalizablesToResx\\AXSharp.LocalizablesToResx.csproj",
"AXSharp.tools\\src\\AXSharp.TIA2AXTool\\AXSharp.TIA2AXTool.csproj",
"AXSharp.tools\\src\\AXSharp.nuget.update\\AXSharp.nuget.update.csproj",
"AXSharp.tools\\tests\\AXSharp.LocalizablesToResx.Tests\\AXSharp.LocalizablesToResx.Tests.csproj",
"AXSharp.tools\\tests\\AXSharp.nuget.update.Tests\\AXSharp.nuget.update.Tests.csproj",
"sanbox\\integration\\ix-integration-blazor\\ix-integration-blazor.csproj",
"sanbox\\integration\\ix-integration-library\\ix-integration-library.csproj",
"sanbox\\integration\\ix-integration-plc\\ix\\ix-integration-plc.csproj",
"sanbox\\integration\\ix-integration-plc\\ix\\ix_integration_plc.csproj",
"tests.integrations\\integrated\\src\\integrated.app\\integrated.hmi.csproj",
"tests.integrations\\integrated\\src\\integrated.twin\\integrated.csproj",
"tests.integrations\\integrated\\tests\\integrated.tests\\integrated.tests.csproj"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"OutputProjectFolder":"ix"}
{"OutputProjectFolder":"ix","UseBase":false}
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,18 @@ internal void CreateAssignment(ITypeDeclaration typeDeclaration, IDeclaration de
case IClassDeclaration classDeclaration:
//case IAnonymousTypeDeclaration anonymousTypeDeclaration:
case IStructuredTypeDeclaration structuredTypeDeclaration:
AddToSource($" plain.{declaration.Name} = await {declaration.Name}.{MethodName}Async();");
AddToSource($"#pragma warning disable CS0612\n");
AddToSource($" plain.{declaration.Name} = await {declaration.Name}.{MethodNameNoac}Async();");
AddToSource($"#pragma warning restore CS0612\n");
break;
case IArrayTypeDeclaration arrayTypeDeclaration:
switch (arrayTypeDeclaration.ElementTypeAccess.Type)
{
case IClassDeclaration classDeclaration:
case IStructuredTypeDeclaration structuredTypeDeclaration:
AddToSource($"plain.{declaration.Name} = {declaration.Name}.Select(async p => await p.{MethodName}Async()).Select(p => p.Result).ToArray();");
case IStructuredTypeDeclaration structuredTypeDeclaration:
AddToSource($"#pragma warning disable CS0612\n");
AddToSource($"plain.{declaration.Name} = {declaration.Name}.Select(async p => await p.{MethodNameNoac}Async()).Select(p => p.Result).ToArray();");
AddToSource($"#pragma warning restore CS0612\n");
break;
case IScalarTypeDeclaration scalarTypeDeclaration:
case IStringTypeDeclaration stringTypeDeclaration:
Expand Down Expand Up @@ -110,6 +114,7 @@ public void AddTypeConstructionParameters(string parametersString)
}

protected static readonly string MethodName = TwinObjectExtensions.OnlineToPlainMethodName;
protected static readonly string MethodNameNoac = $"_{TwinObjectExtensions.OnlineToPlainMethodName}Noac";

public static CsOnlinerPlainerOnlineToPlainBuilder Create(IxNodeVisitor visitor, IStructuredTypeDeclaration semantics,
ISourceBuilder sourceBuilder)
Expand All @@ -120,12 +125,24 @@ public static CsOnlinerPlainerOnlineToPlainBuilder Create(IxNodeVisitor visitor,

builder.AddToSource($"public async Task<Pocos.{semantics.FullyQualifiedName}> {MethodName}Async(){{\n");
builder.AddToSource($"Pocos.{semantics.FullyQualifiedName} plain = new Pocos.{semantics.FullyQualifiedName}();");
builder.AddToSource("await this.ReadAsync();");
builder.AddToSource("await this.ReadAsync<IgnoreOnPocoOperation>();");

semantics.Fields.ToList().ForEach(p => p.Accept(visitor, builder));

builder.AddToSource($"return plain;");
builder.AddToSource($"}}");


// Noac method
builder.AddToSource($"[Obsolete(\"This method should not be used if you indent to access the controllers data. Use `{MethodName}` instead.\")]");
builder.AddToSource("[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]");
builder.AddToSource($"public async Task<Pocos.{semantics.FullyQualifiedName}> {MethodNameNoac}Async(){{\n");
builder.AddToSource($"Pocos.{semantics.FullyQualifiedName} plain = new Pocos.{semantics.FullyQualifiedName}();");

semantics.Fields.ToList().ForEach(p => p.Accept(visitor, builder));
builder.AddToSource($"return plain;");
builder.AddToSource($"}}");

return builder;
}

Expand All @@ -140,16 +157,37 @@ public static CsOnlinerPlainerOnlineToPlainBuilder Create(IxNodeVisitor visitor,

builder.AddToSource($"public {qualifier} async Task<Pocos.{semantics.FullyQualifiedName}> {MethodName}Async(){{\n");
builder.AddToSource($"Pocos.{semantics.FullyQualifiedName} plain = new Pocos.{semantics.FullyQualifiedName}();");
builder.AddToSource("await this.ReadAsync();");
builder.AddToSource("await this.ReadAsync<IgnoreOnPocoOperation>();");

if (isExtended)
{
builder.AddToSource($"#pragma warning disable CS0612\n");
builder.AddToSource($"await base.{MethodNameNoac}Async(plain);");
builder.AddToSource($"#pragma warning restore CS0612\n");
}

semantics.Fields.ToList().ForEach(p => p.Accept(visitor, builder));
builder.AddToSource($"return plain;");
builder.AddToSource($"}}");

// Noac method

builder.AddToSource($"[Obsolete(\"This method should not be used if you indent to access the controllers data. Use `{MethodName}` instead.\")]");
builder.AddToSource("[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]");
builder.AddToSource($"public {qualifier} async Task<Pocos.{semantics.FullyQualifiedName}> {MethodNameNoac}Async(){{\n");
builder.AddToSource($"Pocos.{semantics.FullyQualifiedName} plain = new Pocos.{semantics.FullyQualifiedName}();");

if (isExtended)
{
builder.AddToSource($"await base.{MethodName}Async(plain);");
builder.AddToSource($"#pragma warning disable CS0612\n");
builder.AddToSource($"await base.{MethodNameNoac}Async(plain);");
builder.AddToSource($"#pragma warning restore CS0612\n");
}

semantics.Fields.ToList().ForEach(p => p.Accept(visitor, builder));
builder.AddToSource($"return plain;");
builder.AddToSource($"}}");

return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ protected CsOnlinerPlainerOnlineToPlainProtectedBuilder(ISourceBuilder sourceBui

//var qualifier = isExtended ? "new" : string.Empty;
var qualifier = string.Empty;
builder.AddToSource($"protected {qualifier} async Task<Pocos.{semantics.FullyQualifiedName}> {MethodName}Async(Pocos.{semantics.FullyQualifiedName} plain){{\n");
builder.AddToSource($"[Obsolete(\"This method should not be used if you indent to access the controllers data. Use `{MethodName}` instead.\")]");
builder.AddToSource("[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]");
builder.AddToSource($"protected {qualifier} async Task<Pocos.{semantics.FullyQualifiedName}> {MethodNameNoac}Async(Pocos.{semantics.FullyQualifiedName} plain){{\n");


if (isExtended)
{
builder.AddToSource($"await base.{MethodName}Async(plain);");
builder.AddToSource($"#pragma warning disable CS0612\n");
builder.AddToSource($"await base.{MethodNameNoac}Async(plain);");
builder.AddToSource($"#pragma warning restore CS0612\n");
}

semantics.Fields.ToList().ForEach(p => p.Accept(visitor, builder));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ private void CreateAssignment(ITypeDeclaration typeDeclaration, IDeclaration dec
case IClassDeclaration classDeclaration:
//case IAnonymousTypeDeclaration anonymousTypeDeclaration:
case IStructuredTypeDeclaration structuredTypeDeclaration:
AddToSource($" await this.{declaration.Name}.{MethodName}Async(plain.{declaration.Name});");
AddToSource($"#pragma warning disable CS0612\n");
AddToSource($" await this.{declaration.Name}.{MethodNameNoac}Async(plain.{declaration.Name});");
AddToSource($"#pragma warning restore CS0612\n");
break;
case IArrayTypeDeclaration arrayTypeDeclaration:

Expand All @@ -74,7 +76,9 @@ private void CreateAssignment(ITypeDeclaration typeDeclaration, IDeclaration dec
case IClassDeclaration classDeclaration:
case IStructuredTypeDeclaration structuredTypeDeclaration:
AddToSource($"var _{declaration.Name}_i_FE8484DAB3 = 0;");
AddToSource($"{declaration.Name}.Select(p => p.{MethodName}Async(plain.{declaration.Name}[_{declaration.Name}_i_FE8484DAB3++])).ToArray();");
AddToSource($"#pragma warning disable CS0612\n");
AddToSource($"{declaration.Name}.Select(p => p.{MethodNameNoac}Async(plain.{declaration.Name}[_{declaration.Name}_i_FE8484DAB3++])).ToArray();");
AddToSource($"#pragma warning restore CS0612\n");
break;
case IScalarTypeDeclaration scalarTypeDeclaration:
case IStringTypeDeclaration stringTypeDeclaration:
Expand Down Expand Up @@ -115,6 +119,8 @@ public void AddTypeConstructionParameters(string parametersString)
}

private static readonly string MethodName = TwinObjectExtensions.PlainToOnlineMethodName;
private static readonly string MethodNameNoac = $"_{TwinObjectExtensions.PlainToOnlineMethodName}Noac";


public static CsOnlinerPlainerPlainToOnlineBuilder Create(IxNodeVisitor visitor, IStructuredTypeDeclaration semantics,
ISourceBuilder sourceBuilder)
Expand All @@ -127,9 +133,19 @@ public static CsOnlinerPlainerPlainToOnlineBuilder Create(IxNodeVisitor visitor,

semantics.Fields.ToList().ForEach(p => p.Accept(visitor, builder));

builder.AddToSource("return await this.WriteAsync();");
builder.AddToSource("return await this.WriteAsync<IgnoreOnPocoOperation>();");

builder.AddToSource($"}}");

// Noac method
builder.AddToSource($"[Obsolete(\"This method should not be used if you indent to access the controllers data. Use `{MethodName}` instead.\")]");
builder.AddToSource("[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]");
builder.AddToSource($"public async Task {MethodNameNoac}Async(Pocos.{semantics.FullyQualifiedName} plain){{\n");

semantics.Fields.ToList().ForEach(p => p.Accept(visitor, builder));

builder.AddToSource($"}}");

return builder;
}

Expand All @@ -148,14 +164,29 @@ public static CsOnlinerPlainerPlainToOnlineBuilder Create(IxNodeVisitor visitor,

if (isExtended)
{
builder.AddToSource($"await base.{MethodName}Async(plain);");
builder.AddToSource($"await base.{MethodNameNoac}Async(plain);");
}

semantics.Fields.ToList().ForEach(p => p.Accept(visitor, builder));

builder.AddToSource("return await this.WriteAsync();");
builder.AddToSource("return await this.WriteAsync<IgnoreOnPocoOperation>();");

builder.AddToSource($"}}");

// Noac method
builder.AddToSource($"[Obsolete(\"This method should not be used if you indent to access the controllers data. Use `{MethodName}` instead.\")]");
builder.AddToSource("[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]");
builder.AddToSource($"public async Task {MethodNameNoac}Async(Pocos.{semantics.FullyQualifiedName} plain){{\n");

if (isExtended)
{
builder.AddToSource($"await base.{MethodNameNoac}Async(plain);");
}

semantics.Fields.ToList().ForEach(p => p.Accept(visitor, builder));

builder.AddToSource($"}}");

return builder;
}

Expand Down
Loading