Skip to content

Commit

Permalink
Added initial source code generator for attribute
Browse files Browse the repository at this point in the history
Converted projects to .NET 8.0
  • Loading branch information
ritchiecarroll committed Sep 16, 2024
1 parent 09eb5f1 commit 524be8a
Show file tree
Hide file tree
Showing 86 changed files with 1,220 additions and 283 deletions.
2 changes: 1 addition & 1 deletion src/Tests/ASTTests/ASTTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>

<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<PublishReadyToRun>true</PublishReadyToRun>
<RootNamespace>go</RootNamespace>
<AssemblyName>ArrayPassByValue</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>

<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Behavioral/ExprSwitch/ExprSwitch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<PublishReadyToRun>true</PublishReadyToRun>
<RootNamespace>go</RootNamespace>
<AssemblyName>ExprSwitch</AssemblyName>
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Behavioral/ForVariants/ForVariants.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<PublishReadyToRun>true</PublishReadyToRun>
<RootNamespace>go</RootNamespace>
<AssemblyName>ForVariants</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<PublishReadyToRun>true</PublishReadyToRun>
<RootNamespace>go</RootNamespace>
<AssemblyName>InterfaceCasting</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<PublishReadyToRun>true</PublishReadyToRun>
<RootNamespace>go</RootNamespace>
<AssemblyName>InterfaceImplementation</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<PublishReadyToRun>true</PublishReadyToRun>
<RootNamespace>go</RootNamespace>
<AssemblyName>InterfaceInheritance</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<PublishReadyToRun>true</PublishReadyToRun>
<RootNamespace>go</RootNamespace>
<AssemblyName>LambdaFunctions</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<PublishReadyToRun>true</PublishReadyToRun>
<RootNamespace>go</RootNamespace>
<AssemblyName>PointerToPointer</AssemblyName>
Expand Down
181 changes: 95 additions & 86 deletions src/Tests/Behavioral/SortArrayType/SortArrayType.cs
Original file line number Diff line number Diff line change
@@ -1,95 +1,104 @@
using static go.main_package;
namespace go;

namespace go
{
using fmt = fmt_package;
using sort = sort_package;
using static builtin;

public static partial class main_package {

public partial struct Person
{
public @string Name;
public nint Age;
public float ShoeSize;
}

public partial struct PeopleByShoeSize : ISlice<Person>
{
}

public partial struct PeopleByAge : ISlice<Person>
{
}

public static nint Len(this PeopleByShoeSize p)
{
return len(p);
}

public static void Swap(this PeopleByShoeSize p, nint i, nint j)
{
(p[i], p[j]) = (p[j], p[i]);
}

public static bool Less(this PeopleByShoeSize p, nint i, nint j)
{
return (p[i].ShoeSize < p[j].ShoeSize);
}

public static nint Len(this PeopleByAge p)
{
return len(p);
}

public static void Swap(this PeopleByAge p, nint i, nint j)
{
(p[i], p[j]) = (p[j], p[i]);
}

public static bool Less(this PeopleByAge p, nint i, nint j)
{
return (p[i].Age < p[j].Age);
}

private static void Main()
{
var people = new Person[] {
new() {
Name = "Person1"u8,
Age = 26,
ShoeSize = 8,
},
new() {
Name = "Person2"u8,
Age = 21,
ShoeSize = 4,
},
new() {
Name = "Person3"u8,
Age = 15,
ShoeSize = 9,
},
new() {
Name = "Person4"u8,
Age = 45,
ShoeSize = 15,
},
new() {
Name = "Person5"u8,
Age = 25,
ShoeSize = 8.50F,
}}.slice();

fmt.Println(people);

sort.Sort(new PeopleByShoeSize(people));
fmt.Println(people);

sort.Sort(new PeopleByAge(people));
fmt.Println(people);
}
[type("struct")]
public partial struct Person
{
public @string Name;
public nint Age;
public float32 ShoeSize;
}

[type("[]Person")]
public partial struct PeopleByShoeSize : ISlice<Person>
{
}

public partial struct PeopleByAge : ISlice<Person>
{
}

public static nint Len(this PeopleByShoeSize p)
{
return len(p);
}

public static void Swap(this PeopleByShoeSize p, nint i, nint j)
{
(p[i], p[j]) = (p[j], p[i]);
}

public static bool Less(this PeopleByShoeSize p, nint i, nint j)
{
return (p[i].ShoeSize < p[j].ShoeSize);
}

public static nint Len(this PeopleByAge p)
{
return len(p);
}

public static void Swap(this PeopleByAge p, nint i, nint j)
{
(p[i], p[j]) = (p[j], p[i]);
}

public static bool Less(this PeopleByAge p, nint i, nint j)
{
return (p[i].Age < p[j].Age);
}

private static void Main()
{
var people = new Person[] {
//new(
// Name: "Person1"u8,
// Age: 26,
// ShoeSize: 8
//),
//new(
// Name: "Person2"u8,
// Age: 21,
// ShoeSize: 4
//),
//new(
// Name: "Person3"u8,
// Age: 15,
// ShoeSize: 9
//),
//new(
// Name: "Person4"u8,
// Age: 45,
// ShoeSize: 15
//),
//new(
// Name: "Person5"u8,
// Age: 25,
// ShoeSize: 8.50F
//)
}.slice();

var test = new Person[]
{
new() { Name = "Person1"u8, Age = 26, ShoeSize = 8 },
new() { Name = "Person2"u8, Age = 21, ShoeSize = 4 },
new() { Name = "Person3"u8, Age = 15, ShoeSize = 9 },
new() { Name = "Person4"u8, Age = 45, ShoeSize = 15 },
new() { Name = "Person5"u8, Age = 25, ShoeSize = 8.50F }
};

fmt.Println(people);

sort.Sort(new PeopleByShoeSize(people));
fmt.Println(people);

sort.Sort(new PeopleByAge(people));
fmt.Println(people);
}

} // end main_package
}
8 changes: 3 additions & 5 deletions src/Tests/Behavioral/SortArrayType/SortArrayType.cs.target
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using static go.main_package;

namespace go
{
namespace go;

using fmt = fmt_package;
using sort = sort_package;
using static builtin;

public static partial class main_package {

public partial struct Person
{
public partial struct Person {
public @string Name;
public nint Age;
public float ShoeSize;
Expand Down Expand Up @@ -92,4 +91,3 @@ private static void Main()
}

} // end main_package
}
23 changes: 18 additions & 5 deletions src/Tests/Behavioral/SortArrayType/SortArrayType.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<PublishReadyToRun>true</PublishReadyToRun>
<RootNamespace>go</RootNamespace>
<AssemblyName>SortArrayType</AssemblyName>
Expand All @@ -11,16 +11,20 @@
<PackageProjectUrl>https://github.com/GridProtectionAlliance/go2cs</PackageProjectUrl>
<RepositoryUrl>https://github.com/GridProtectionAlliance/go2cs</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<ApplicationIcon>$(GOPATH)\src\go2cs\go2cs.ico</ApplicationIcon>
<Nullable>enable</Nullable>
<NoWarn>660;661;IDE1006</NoWarn>
<Version>0.1.0</Version>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(OutDir)'==''">
<OutDir>bin\$(Configuration)\$(TargetFramework)\</OutDir>
</PropertyGroup>

<ItemGroup>
<Compile Remove="SortArrayType_PersonStruct.cs" />
</ItemGroup>

<ItemGroup>
<Using Include="go.builtin" Static="True" />
<Using Include="System.Byte" Alias="uint8" />
Expand All @@ -37,15 +41,24 @@
<Using Include="System.Int32" Alias="rune" />
<Using Include="System.UIntPtr" Alias="uintptr" />

<Reference Include="golib">
<ProjectReference Include="..\..\..\gocore\golib\golib.csproj" Condition="'$(Configuration)'=='Debug'" />
<Reference Include="golib" Condition="'$(Configuration)'!='Debug'">
<HintPath>$(GOPATH)\src\go2cs\golib\$(OutDir)golib.dll</HintPath>
</Reference>
<Reference Include="fmt">

<ProjectReference Include="..\..\..\gocore\fmt\fmt.csproj" Condition="'$(Configuration)'=='Debug'" />
<Reference Include="fmt" Condition="'$(Configuration)'!='Debug'">
<HintPath>$(GOPATH)\src\go2cs\fmt\$(OutDir)fmt_package.dll</HintPath>
</Reference>
<Reference Include="sort">

<ProjectReference Include="..\..\..\gocore\sort\sort.csproj" Condition="'$(Configuration)'=='Debug'" />
<Reference Include="sort" Condition="'$(Configuration)'!='Debug'">
<HintPath>$(GOPATH)\src\go2cs\sort\$(OutDir)sort_package.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\go2cs.CodeGenerators\go2cs.CodeGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ public static partial class main_package
public partial struct Person
{
// Constructors
public Person(NilType _)
public Person(NilType _) : this(default, default, default)
{
this.Name = default;
this.Age = default;
this.ShoeSize = default;
}

public Person(@string Name = default, nint Age = default, float ShoeSize = default)
Expand Down Expand Up @@ -70,4 +67,4 @@ public static Person Person_cast(dynamic value)
return new Person(value.Name, value.Age, value.ShoeSize);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Tests/Behavioral/TypeSwitch/TypeSwitch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<PublishReadyToRun>true</PublishReadyToRun>
<RootNamespace>go</RootNamespace>
<AssemblyName>TypeSwitch</AssemblyName>
Expand Down
Loading

0 comments on commit 524be8a

Please sign in to comment.