Skip to content

Commit

Permalink
Structuredtype initialize arrays fields (#313)
Browse files Browse the repository at this point in the history
* structured type array init

* test expected additions

---------

Co-authored-by: blazej.kuhajda <blazej.kuhajda@mts.sk>
  • Loading branch information
PTKu and blazej.kuhajda authored May 13, 2024
1 parent f72e44b commit 6370aa6
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using AXSharp.Connector.BuilderHelpers;
using AXSharp.Compiler.Cs;

namespace AXSharp.Compiler.Cs.Onliner;
namespace AXSharp.Compiler.Cs.Plain;

internal class CsPlainConstructorBuilder : ICombinedThreeVisitor
{
Expand Down Expand Up @@ -121,6 +121,31 @@ public static CsPlainConstructorBuilder Create(IxNodeVisitor visitor, IClassDecl
return builder;
}

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


builder.AddToSource(
$"public {semantics.Name}()");


if (isExtended)
{
builder.AddToSource(": base()");
}

builder.AddToSource("{");

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

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



private void AddArrayMemberInitialization(IArrayTypeDeclaration type, IFieldDeclaration field,
IxNodeVisitor visitor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,13 @@ public void CreateStructuredType(IStructTypeDeclarationSyntax structTypeDeclarat
IxNodeVisitor visitor)
{
TypeCommAccessibility = structuredTypeDeclaration.GetCommAccessibility(this);

AddToSource(
$"{structuredTypeDeclaration.AccessModifier.Transform()}partial class {structTypeDeclarationSyntax.Name.Text} ");
$"{structuredTypeDeclaration.AccessModifier.Transform()}partial class {structTypeDeclarationSyntax.Name.Text} : AXSharp.Connector.IPlain");
AddToSource("{");

AddToSource(CsPlainConstructorBuilder.Create(visitor, structuredTypeDeclaration, this, false, Project).Output);

structuredTypeDeclaration.Fields.ToList().ForEach(p => p.Accept(visitor, this));
AddToSource("}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,21 @@ public SomeClass()
public string SomeClassVariable { get; set; } = string.Empty;
}

public partial class Motor
public partial class Motor : AXSharp.Connector.IPlain
{
public Motor()
{
}

public Boolean isRunning { get; set; }
}

public partial class Vehicle
public partial class Vehicle : AXSharp.Connector.IPlain
{
public Vehicle()
{
}

public misc.Motor m { get; set; } = new misc.Motor();
public Int16 displacement { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,21 @@ public ComplexForConfig()
public Motor myMotor { get; set; } = new Motor();
}

public partial class Motor
public partial class Motor : AXSharp.Connector.IPlain
{
public Motor()
{
}

public Boolean isRunning { get; set; }
}

public partial class Vehicle
public partial class Vehicle : AXSharp.Connector.IPlain
{
public Vehicle()
{
}

public Motor m { get; set; } = new Motor();
public Int16 displacement { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,21 @@ public SomeClass()
public string SomeClassVariable { get; set; } = string.Empty;
}

public partial class Motor
public partial class Motor : AXSharp.Connector.IPlain
{
public Motor()
{
}

public Boolean isRunning { get; set; }
}

public partial class Vehicle
public partial class Vehicle : AXSharp.Connector.IPlain
{
public Vehicle()
{
}

public misc.Motor m { get; set; } = new misc.Motor();
public Int16 displacement { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,39 @@ public Motor()
public Boolean Run { get; set; }
}

public partial class struct1
public partial class struct1 : AXSharp.Connector.IPlain
{
public struct1()
{
}

public struct2 s2 { get; set; } = new struct2();
}

public partial class struct2
public partial class struct2 : AXSharp.Connector.IPlain
{
public struct2()
{
}

public struct3 s3 { get; set; } = new struct3();
}

public partial class struct3
public partial class struct3 : AXSharp.Connector.IPlain
{
public struct3()
{
}

public struct4 s4 { get; set; } = new struct4();
}

public partial class struct4
public partial class struct4 : AXSharp.Connector.IPlain
{
public struct4()
{
}

public Int16 s5 { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

namespace Pocos
{
public partial class Motor
public partial class Motor : AXSharp.Connector.IPlain
{
public Motor()
{
}

public Boolean isRunning { get; set; }
}

public partial class Vehicle
public partial class Vehicle : AXSharp.Connector.IPlain
{
public Vehicle()
{
}

public Motor m { get; set; } = new Motor();
public Int16 displacement { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ namespace Pocos
{
namespace TypeWithNameAttributes
{
public partial class Motor
public partial class Motor : AXSharp.Connector.IPlain
{
public Motor()
{
}

public Boolean isRunning { get; set; }
}

public partial class Vehicle
public partial class Vehicle : AXSharp.Connector.IPlain
{
public Vehicle()
{
}

public TypeWithNameAttributes.Motor m { get; set; } = new TypeWithNameAttributes.Motor();
public Int16 displacement { get; set; }
}
Expand Down

0 comments on commit 6370aa6

Please sign in to comment.