Skip to content

Commit

Permalink
Fix all issues and add CopyFrom sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stenke committed Aug 23, 2022
1 parent 1d62e8c commit 4821e81
Show file tree
Hide file tree
Showing 53 changed files with 871 additions and 339 deletions.
15 changes: 15 additions & 0 deletions Durian.sln
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CopyFrom", "CopyFrom", "{07
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Durian.ConstExpr", "src\Durian.ConstExpr\Durian.ConstExpr.csproj", "{4563AEC2-3292-4CDD-B920-E615670CB101}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Durian.Samples.CopyFrom", "samples\Durian.Samples.CopyFrom\Durian.Samples.CopyFrom.csproj", "{9C383ACD-8C9E-4C24-B2EA-4326C7553866}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -442,6 +444,18 @@ Global
{4563AEC2-3292-4CDD-B920-E615670CB101}.Release|x64.Build.0 = Release|Any CPU
{4563AEC2-3292-4CDD-B920-E615670CB101}.Release|x86.ActiveCfg = Release|Any CPU
{4563AEC2-3292-4CDD-B920-E615670CB101}.Release|x86.Build.0 = Release|Any CPU
{9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Debug|x64.ActiveCfg = Debug|Any CPU
{9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Debug|x64.Build.0 = Debug|Any CPU
{9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Debug|x86.ActiveCfg = Debug|Any CPU
{9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Debug|x86.Build.0 = Debug|Any CPU
{9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Release|Any CPU.Build.0 = Release|Any CPU
{9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Release|x64.ActiveCfg = Release|Any CPU
{9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Release|x64.Build.0 = Release|Any CPU
{9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Release|x86.ActiveCfg = Release|Any CPU
{9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -474,6 +488,7 @@ Global
{99672AD8-65D0-4F8F-95D1-ADF6839F5584} = {F6EC89D8-4343-42A1-B6D6-B0022D3004A0}
{072AEE81-1199-4446-B2D5-54384D23DAE0} = {BA3DE2E2-7B32-4612-8219-24FBCF850813}
{4563AEC2-3292-4CDD-B920-E615670CB101} = {74D7ECF9-D1F6-46FA-B8D8-D34F86F713EA}
{9C383ACD-8C9E-4C24-B2EA-4326C7553866} = {D98DD137-AADE-4474-86EF-9F0874607687}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {09524C45-0D6D-4456-B89D-9673853B9FA0}
Expand Down
3 changes: 2 additions & 1 deletion internal/GenerateAnalyzerReleases/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -142,7 +143,7 @@ private static void HandleDiagnosticFiles(string[] files, string currentDirector

private static void WriteMatchData(MatchCollection matches, string moduleName, StringBuilder builder)
{
foreach (Match match in matches)
foreach (Match match in matches.Cast<Match>())
{
DiagnosticData? data = RetrieveDiagnosticData(match.ToString());

Expand Down
16 changes: 16 additions & 0 deletions samples/Durian.Samples.CopyFrom/Durian.Samples.CopyFrom.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>9</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Durian.CopyFrom" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Durian.Core" Version="3.0.0" />
</ItemGroup>
</Project>
32 changes: 32 additions & 0 deletions samples/Durian.Samples.CopyFrom/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Piotr Stenke. All rights reserved.
// Licensed under the MIT license.

using System;

namespace Durian.Samples.CopyFrom
{
internal class Program
{
private static void Main()
{
// This method will print "Hello world!".
Test.Source();

// This method will print "Hello beautiful world!", even though it wasn't explicily written anywhere in the code!
Test.Target();

Console.ReadKey();
}
}

public static partial class Test
{
[CopyFromMethod(nameof(Source)), Pattern("world", "beautiful world")]
public static partial void Target();

public static void Source()
{
Console.WriteLine("Hello world!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

<ItemGroup>
<PackageReference Include="Durian.Core" Version="3.0.0" />
<PackageReference Include="Durian.DefaultParam" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Durian.DefaultParam" Version="3.0.0" />
</ItemGroup>

</Project>

This file was deleted.

10 changes: 5 additions & 5 deletions samples/Durian.Samples.InterfaceTargets/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public class Class : IInterface
{
}

// Error!
//public struct Struct : IInterface
//{
//}

// This interface can only be implemented by classes.
[InterfaceTargets(Durian.InterfaceTargets.Class)]
public interface IInterface
Expand All @@ -20,9 +25,4 @@ private static void Main()
{
}
}

// Error!
//public struct Struct : IInterface
//{
//}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ internal AccessorData(IMethodSymbol symbol, ICompilationData compilation, Member
/// <inheritdoc/>
public ISymbolContainer<IMethodSymbol, ILocalFunctionData> GetLocalFunctions(IncludedMembers members)
{
_localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation);
_localFunctions ??= new LocalFunctionContainer(this, ParentCompilation);

if (_localFunctions is IMappedSymbolContainer<IMethodSymbol, ILocalFunctionData, IncludedMembers> mapped)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ internal ConstructorData(IMethodSymbol symbol, ICompilationData compilation, Mem
/// <inheritdoc/>
public ISymbolContainer<IMethodSymbol, ILocalFunctionData> GetLocalFunctions(IncludedMembers members)
{
_localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation);
_localFunctions ??= new LocalFunctionContainer(this, ParentCompilation);

if (_localFunctions is IMappedSymbolContainer<IMethodSymbol, ILocalFunctionData, IncludedMembers> mapped)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ internal ConversionOperatorData(IMethodSymbol symbol, ICompilationData compilati
/// <inheritdoc/>
public ISymbolContainer<IMethodSymbol, ILocalFunctionData> GetLocalFunctions(IncludedMembers members)
{
_localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation);
_localFunctions ??= new LocalFunctionContainer(this, ParentCompilation);

if (_localFunctions is IMappedSymbolContainer<IMethodSymbol, ILocalFunctionData, IncludedMembers> mapped)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ internal DestructorData(IMethodSymbol symbol, ICompilationData compilation, Memb
/// <inheritdoc/>
public ISymbolContainer<IMethodSymbol, ILocalFunctionData> GetLocalFunctions(IncludedMembers members)
{
_localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation);
_localFunctions ??= new LocalFunctionContainer(this, ParentCompilation);

if (_localFunctions is IMappedSymbolContainer<IMethodSymbol, ILocalFunctionData, IncludedMembers> mapped)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Durian.AnalysisServices/Data/FromSource/LambdaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ internal LambdaData(IMethodSymbol symbol, ICompilationData compilation, MemberDa
/// <inheritdoc/>
public ISymbolContainer<IMethodSymbol, ILocalFunctionData> GetLocalFunctions(IncludedMembers members)
{
_localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation);
_localFunctions ??= new LocalFunctionContainer(this, ParentCompilation);

if (_localFunctions is IMappedSymbolContainer<IMethodSymbol, ILocalFunctionData, IncludedMembers> mapped)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ internal LocalFunctionData(IMethodSymbol symbol, ICompilationData compilation, M
/// <inheritdoc/>
public ISymbolContainer<IMethodSymbol, ILocalFunctionData> GetLocalFunctions(IncludedMembers members)
{
_localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation);
_localFunctions ??= new LocalFunctionContainer(this, ParentCompilation);

if (_localFunctions is IMappedSymbolContainer<IMethodSymbol, ILocalFunctionData, IncludedMembers> mapped)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Durian.AnalysisServices/Data/FromSource/MethodData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ internal MethodData(IMethodSymbol symbol, ICompilationData compilation, MemberDa
/// <inheritdoc/>
public ISymbolContainer<IMethodSymbol, ILocalFunctionData> GetLocalFunctions(IncludedMembers members)
{
_localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation);
_localFunctions ??= new LocalFunctionContainer(this, ParentCompilation);

if (_localFunctions is IMappedSymbolContainer<IMethodSymbol, ILocalFunctionData, IncludedMembers> mapped)
{
Expand All @@ -359,7 +359,7 @@ public ISymbolContainer<IMethodSymbol, ILocalFunctionData> GetLocalFunctions(Inc
/// <inheritdoc/>
public ISymbolContainer<IMethodSymbol, IMethodData> GetOverloads(IncludedMembers members)
{
_overloads ??= new OverloadsContainer(this, ParentCompilation);
_overloads ??= new MethodOverloadContainer(this, ParentCompilation);

if (_localFunctions is IMappedSymbolContainer<IMethodSymbol, IMethodData, IncludedMembers> mapped)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Durian.AnalysisServices/Data/FromSource/NamespaceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public ISymbolContainer<INamespaceSymbol, INamespaceData> GetNamespaces(Included

switch (_members)
{
case NamespacesOrTypesContainer typed:
case NamespaceOrTypeContainer typed:
IMappedSymbolContainer<INamespaceSymbol, INamespaceData, IncludedMembers> namespaces = typed.GetNamespaces();
return namespaces.ResolveLevel(members);

Expand Down Expand Up @@ -191,7 +191,7 @@ public ISymbolContainer<INamedTypeSymbol, ITypeData> GetTypes(IncludedMembers me

switch (_members)
{
case NamespacesOrTypesContainer typed:
case NamespaceOrTypeContainer typed:
IMappedSymbolContainer<INamedTypeSymbol, ITypeData, IncludedMembers> types = typed.GetTypes();
return types.ResolveLevel(members);

Expand Down Expand Up @@ -287,7 +287,7 @@ INamespaceOrTypeData INamespaceOrTypeData.Clone()
[MemberNotNull(nameof(_members))]
private void InitMembers()
{
_members ??= new NamespacesOrTypesContainer(this, ParentCompilation);
_members ??= new NamespaceOrTypeContainer(this, ParentCompilation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal NamespaceOrTypeData(INamespaceOrTypeSymbol symbol, ICompilationData com
/// <inheritdoc/>
public ISymbolContainer<INamedTypeSymbol, ITypeData> GetTypes(IncludedMembers members)
{
_types ??= new NamespacesOrTypesContainer(this, ParentCompilation).GetTypes();
_types ??= new NamespaceOrTypeContainer(this, ParentCompilation).GetTypes();

#pragma warning disable IDE0066 // Convert switch statement to expression
switch (_types)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ internal OperatorData(IMethodSymbol symbol, ICompilationData compilation, Member
/// <inheritdoc/>
public ISymbolContainer<IMethodSymbol, ILocalFunctionData> GetLocalFunctions(IncludedMembers members)
{
_localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation);
_localFunctions ??= new LocalFunctionContainer(this, ParentCompilation);

if (_localFunctions is IMappedSymbolContainer<IMethodSymbol, ILocalFunctionData, IncludedMembers> mapped)
{
Expand Down
12 changes: 6 additions & 6 deletions src/Durian.AnalysisServices/Data/FromSource/TypeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public ISymbolContainer<IEventSymbol, IEventData> GetEvents(IncludedMembers memb

switch (_members)
{
case MembersOfTypeContainer typed:
case InnerMemberContainer typed:
IMappedSymbolContainer<IEventSymbol, IEventData, IncludedMembers> events = typed.GetEvents();
return events.ResolveLevel(members);

Expand All @@ -284,7 +284,7 @@ public ISymbolContainer<IFieldSymbol, IFieldData> GetFields(IncludedMembers memb

switch (_members)
{
case MembersOfTypeContainer typed:
case InnerMemberContainer typed:
IMappedSymbolContainer<IFieldSymbol, IFieldData, IncludedMembers> fields = typed.GetFields();
return fields.ResolveLevel(members);

Expand Down Expand Up @@ -322,7 +322,7 @@ public ISymbolContainer<IMethodSymbol, IMethodData> GetMethods(IncludedMembers m

switch (_members)
{
case MembersOfTypeContainer typed:
case InnerMemberContainer typed:
IMappedSymbolContainer<IMethodSymbol, IMethodData, IncludedMembers> methods = typed.GetMethods();
return methods.ResolveLevel(members);

Expand Down Expand Up @@ -353,7 +353,7 @@ public ISymbolContainer<IPropertySymbol, IPropertyData> GetProperties(IncludedMe

switch (_members)
{
case MembersOfTypeContainer typed:
case InnerMemberContainer typed:
IMappedSymbolContainer<IPropertySymbol, IPropertyData, IncludedMembers> properties = typed.GetProperties();
return properties.ResolveLevel(members);

Expand All @@ -378,7 +378,7 @@ public ISymbolContainer<INamedTypeSymbol, ITypeData> GetTypes(IncludedMembers me

switch (_members)
{
case MembersOfTypeContainer typed:
case InnerMemberContainer typed:
IMappedSymbolContainer<INamedTypeSymbol, ITypeData, IncludedMembers> types = typed.GetTypes();
return types.ResolveLevel(members);

Expand Down Expand Up @@ -488,7 +488,7 @@ INamespaceOrTypeData INamespaceOrTypeData.Clone()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void InitMembers()
{
_members ??= new MembersOfTypeContainer(this, ParentCompilation);
_members ??= new InnerMemberContainer(this, ParentCompilation);
}
}
}
Loading

0 comments on commit 4821e81

Please sign in to comment.