Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
adds option -b for building extended members with $base in symbols
  • Loading branch information
PTKu committed Sep 21, 2023
commit ce1a03e319d18d3dc51edd6b4ff6f8c4c32c6350
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ namespace AXSharp.Compiler;
public interface ICompilerOptions
{
string? OutputProjectFolder { get; set; }
bool UseBase { get; set; }
}
4 changes: 3 additions & 1 deletion src/AXSharp.compiler/src/AXSharp.Compiler/AXSharpConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public string OutputProjectFolder
set => _outputProjectFolder = value;
}


public bool UseBase { get; set; }


private string _axProjectFolder;

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions src/AXSharp.compiler/src/AXSharp.Compiler/AXSharpProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public AXSharpProject(AxProject axProject, IEnumerable<Type> builderTypes, Type
AxProject = axProject;
CompilerOptions = AXSharpConfig.UpdateAndGetIxConfig(axProject.ProjectFolder, cliCompilerOptions);
OutputFolder = Path.GetFullPath(Path.Combine(AxProject.ProjectFolder, CompilerOptions.OutputProjectFolder));
if (cliCompilerOptions != null) UseBaseSymbol = cliCompilerOptions.UseBase;
BuilderTypes = builderTypes;
TargetProject = Activator.CreateInstance(targetProjectType, this) as ITargetProject ?? throw new
InvalidOperationException("Target project type must implement ITargetProject interface.");
Expand Down Expand Up @@ -73,6 +74,8 @@ public AXSharpProject(AxProject axProject, IEnumerable<Type> builderTypes, Type
/// </summary>
public string OutputFolder { get; }

public bool UseBaseSymbol { get; }

/// <summary>
/// Generates outputs from the builders and emits the files into output folder.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using AX.ST.Semantic.Model;
using AX.ST.Semantic.Model.Declarations;
using AX.ST.Semantic.Model.Declarations.Types;
using AX.ST.Syntax.Parser;
using AXSharp.Compiler.Core;
using AXSharp.Compiler.Cs.Helpers;
using AXSharp.Compiler.Cs.Helpers.Onliners;
Expand Down Expand Up @@ -138,14 +139,22 @@ protected void AddToSource(string token, string separator = " ")
}

public static CsOnlinerConstructorBuilder Create(IxNodeVisitor visitor, IClassDeclaration semantics,
ISourceBuilder sourceBuilder, bool isExtended)
ISourceBuilder sourceBuilder, bool isExtended, AXSharpProject project)
{
var builder = new CsOnlinerConstructorBuilder(sourceBuilder);


builder.AddToSource(
$"public {semantics.Name}({typeof(ITwinObject).n()} parent, string readableTail, string symbolTail)");
if (isExtended) builder.AddToSource(": base(parent, readableTail, symbolTail)");


if (isExtended)
{
builder.AddToSource(project.UseBaseSymbol
? ": base(parent, readableTail, symbolTail + \".$base\") "
: ": base(parent, readableTail, symbolTail)");
}


builder.AddToSource("{");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void CreateClassDeclaration(IClassDeclarationSyntax classDeclarationSynta

AddToSource(CsOnlinerMemberBuilder.Create(visitor, classDeclaration, this).Output);

AddToSource(CsOnlinerConstructorBuilder.Create(visitor, classDeclaration, this, isExtended).Output);
AddToSource(CsOnlinerConstructorBuilder.Create(visitor, classDeclaration, this, isExtended, this.Project).Output);

AddToSource(CsOnlinerPlainerOnlineToPlainBuilder.Create(visitor, classDeclaration, this, isExtended).Output);
AddToSource(CsOnlinerPlainerOnlineToPlainProtectedBuilder.Create(visitor, classDeclaration, this, isExtended).Output);
Expand Down
4 changes: 4 additions & 0 deletions src/AXSharp.compiler/src/ixc/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ internal class Options : ICompilerOptions
[Option('o', "output-project-folder", Required = false,
HelpText = "Output project folder where compiler emits result. It must be either absolute path or path relative to the Simatic-ax project folder.")]
public string? OutputProjectFolder { get; set; }

[Option('b', "use-base-symbol", Required = false, Default = false,
HelpText = "Will use base symbol in inherited types")]
public bool UseBase { get; set; }
}

3 changes: 3 additions & 0 deletions src/AXSharp.compiler/src/ixr/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ internal class Options : ICompilerOptions
[Option('o', "output-project-folder", Required = false, HelpText = "Output project folder where compiler emits result.")]
public string? OutputProjectFolder { get; set; }

[Option('b', "use-base-symbol", Required = false, Default = false,
HelpText = "Will use base symbol in inherited types")]
public bool UseBase { get; set; }
}
}
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
@@ -1 +1 @@
{"OutputProjectFolder":"ix"}
{"OutputProjectFolder":"ix","UseBase":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"OutputProjectFolder":"ix"}
{"OutputProjectFolder":"ix","UseBase":false}