Skip to content

Commit

Permalink
Updates ixc to use stc v6 (#309)
Browse files Browse the repository at this point in the history
* The most significant changes involve the addition of a foreach loop in the `CsOnlinerSourceBuilder` and `CsPlainSourceBuilder` classes, which iterates over the `UsingDirectives` of the `fileSyntax` object and adds each `UsingDirective` to the source code with the appropriate namespace. Additionally, the `class_extended_by_known_type.g.cs` and `file_with_usings.g.cs` files have been updated to include more `using` directives, importing namespaces related to `Simatic.Ax.Stateframework`, `Simatic.Ax.StatePattern`, and various `FileWithUsings` namespaces.

1. The `CsOnlinerSourceBuilder` and `CsPlainSourceBuilder` classes have been updated to include a foreach loop that iterates over the `UsingDirectives` of the `fileSyntax` object. This loop adds each `UsingDirective` to the source code with the appropriate namespace. The `CsOnlinerSourceBuilder` adds the namespace as is, while the `CsPlainSourceBuilder` prepends "Pocos." to the namespace.
2. The `class_extended_by_known_type.g.cs` and `file_with_usings.g.cs` files have been updated to include additional `using` directives. These directives import namespaces related to the `Simatic.Ax.Stateframework`, `Simatic.Ax.StatePattern`, and various `FileWithUsings` namespaces.
3. The `class_extended_by_known_type.g.cs` and `file_with_usings.g.cs` files have also been updated to include additional `using` directives under the `Pocos` namespace. These directives import the same namespaces as above, but under the `Pocos` namespace.

* The most significant changes involve the modification of several methods to change the parameter type from `ISyntaxToken` to `PragmaSyntax`. This includes the `AddToDictionaryIfLocalizedString`, `IsPragmaToken`, and `IsStringToken` methods. Additionally, the `IterateSyntaxTreeForPragmas` method has been uncommented and modified, and the `IterateSyntaxTreeForStringLiterals` method has been commented out. The `IsStringToken` method now checks for different `SyntaxKind` types.

1. The `IterateSyntaxTreeForStringLiterals` method has been commented out, disabling its execution.
2. The `IterateSyntaxTreeForPragmas` method has been uncommented and modified. The `token` variable now refers to `pragmaSyntax` and the `IsAttributeNamePragmaToken` method checks the `PragmaContent` of the `token`.
3. The `AddToDictionaryIfLocalizedString` method's parameter type has been changed from `ISyntaxToken` to `PragmaSyntax`. The `TryToGetLocalizedStrings` method now checks the `PragmaContent` of the `token`.
4. The `pos` variable in the `AddToDictionaryIfLocalizedString` method now gets its value from `token.SourceText.GetLineSpan(token.Span).StartLinePosition`.
5. The `IsPragmaToken` and `IsStringToken` methods' parameter type has been changed from `ISyntaxToken` to `PragmaSyntax`. The check for `SyntaxKind.PragmaToken` in `IsPragmaToken` has been commented out.
6. The `IsStringToken` method now checks if the `SyntaxKind` of the `token` is `TypedStringDToken`, `TypedStringSToken`, `UntypedStringDToken`, or `UntypedStringSToken`.

* The most significant changes involve updates to the `CsOnlinerSourceBuilder` and `CsPlainSourceBuilder` classes, which now filter `UsingDirectives` based on the presence of the namespace's fully qualified name in the semantic tree of the compilation. This is achieved through a LINQ query.

Changes:

1. The `CsOnlinerSourceBuilder` and `CsPlainSourceBuilder` classes have been updated to filter `UsingDirectives` based on whether the fully qualified name of the namespace is present in the semantic tree of the compilation. This is done using a LINQ query that checks if the `FullyQualifiedName` of each namespace in the semantic tree is contained in the `QualifiedIdentifierList` of the `UsingDirectives`.

* asp

* fixies the issue with formating in library metadata

* mend

* clup

* clup
  • Loading branch information
PTKu authored May 7, 2024
1 parent d98d358 commit 6167a9a
Show file tree
Hide file tree
Showing 34 changed files with 2,263 additions and 435 deletions.
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mode: ContinuousDeployment
next-version: 0.19.1
next-version: 0.19.0
branches:
main:
regex: ^master$|^main$
Expand Down
22 changes: 14 additions & 8 deletions src/AXSharp.compiler/src/AXSharp.Compiler/AXSharp.Compiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CliWrap"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp"/>
<PackageReference Include="Newtonsoft.Json"/>
<PackageReference Include="NuGet.Configuration"/>
<PackageReference Include="NuGet.Packaging"/>
<PackageReference Include="Polly"/>
<PackageReference Include="Serilog.Sinks.Console"/>
<PackageReference Include="YamlDotNet"/>
<PackageReference Include="CliWrap" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="NuGet.Configuration" />
<PackageReference Include="NuGet.Packaging" />
<PackageReference Include="Polly" />
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="YamlDotNet" />
</ItemGroup>

<ItemGroup>
Expand All @@ -88,6 +89,11 @@
<HintPath>..\..\..\apax\stc\bin\AX.Text.dll</HintPath>
<Private>False</Private>
</Reference>

<Reference Include="AX.Text">
<HintPath>..\..\..\apax\stc\bin\AX.ST.Compiler.PluginAbstractions.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>

</Project>
25 changes: 13 additions & 12 deletions src/AXSharp.compiler/src/AXSharp.Compiler/AXSharpProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using System.Xml.Linq;
using AX.ST.Semantic;
using AX.ST.Semantic.Analyzer;
using AX.ST.Semantic.Model.Declarations;
using AX.ST.Semantic.Model.Declarations.Types;
using AX.ST.Syntax.Parser;
Expand Down Expand Up @@ -92,8 +93,8 @@ public void Generate()

var toCompile = refParseTrees.Concat(projectSources.Select(p => p.parseTree));

var compilation = Compilation.Create(toCompile, Compilation.Settings.Default).Result;

var compilationResult = Compilation.Create(toCompile, new List<ISemanticAnalyzer>(), Compilation.Settings.Default).Result;
this.CleanOutput(this.OutputFolder);

foreach (var origin in projectSources)
Expand All @@ -102,7 +103,7 @@ public void Generate()

foreach (var sourceBuilderType in BuilderTypes)
{
var builder = Activator.CreateInstance(sourceBuilderType, this, compilation);
var builder = Activator.CreateInstance(sourceBuilderType, this, compilationResult.Compilation);
var treeWalker = builder as ICombinedThreeVisitor;
var sourceBuilder = builder as ISourceBuilder;

Expand All @@ -115,7 +116,7 @@ public void Generate()
$"Could not create {sourceBuilderType.Name} as ISourceBuilder");


origin.parseTree.GetRoot().Visit(new IxNodeVisitor(compilation), treeWalker);
origin.parseTree.GetRoot().Visit(new IxNodeVisitor(compilationResult.Compilation), treeWalker);



Expand All @@ -135,7 +136,7 @@ public void Generate()
}

TargetProject.ProvisionProjectStructure();
GenerateMetadata(compilation);
GenerateMetadata(compilationResult.Compilation);
TargetProject.GenerateResources();
TargetProject.GenerateCompanionData();
Log.Logger.Information($"Compilation of project '{AxProject.SrcFolder}' done.");
Expand Down Expand Up @@ -334,26 +335,26 @@ private static string CreateMetaType(ITypeDeclaration type)


var hasNamespace = type.ContainingNamespace != null;
if (hasNamespace) sb.Append($"NAMESPACE {type.ContainingNamespace!.FullyQualifiedName}\n");
if (hasNamespace) sb.Append($"NAMESPACE {type.ContainingNamespace!.FullyQualifiedName}\n\n");

type?.Pragmas?.ToList().ForEach(p => sb.Append($"{{{p.Content}}}"));
type?.Pragmas?.ToList().ForEach(p => sb.Append($"{{{p.Content}}}\n"));

switch (kind)
{
case DeclarationKind.Struct:
sb.Append($"TYPE {type.Name} : STRUCT ; END_STRUCT");
sb.Append($"TYPE {type.Name} : STRUCT ; END_STRUCT\n");
break;
case DeclarationKind.Class:
sb.Append($"CLASS {type.Name} END_CLASS");
sb.Append($"CLASS {type.Name} \nEND_CLASS\n");
break;
case DeclarationKind.Enumeration:
sb.Append($"TYPE {type.Name} : (item0); END_TYPE");
sb.Append($"TYPE {type.Name} : (item0); \nEND_TYPE\n");
break;
case DeclarationKind.Interface:
sb.Append($"INTERFACE {type.Name} END_INTERFACE");
sb.Append($"INTERFACE {type.Name} \nEND_INTERFACE\n");
break;
case DeclarationKind.NamedValueType:
sb.Append($"TYPE {type.Name} : INT (item0 := 0); END_TYPE");
sb.Append($"TYPE {type.Name} : INT (item0 := 0); \nEND_TYPE\n");
break;
}

Expand Down
Loading

0 comments on commit 6167a9a

Please sign in to comment.