2022-05-31 22:12:46 +02:00
|
|
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2023-06-28 01:27:48 +02:00
|
|
|
|
namespace Ryujinx.Horizon.Kernel.Generators
|
2022-05-31 22:12:46 +02:00
|
|
|
|
{
|
|
|
|
|
class SyscallSyntaxReceiver : ISyntaxReceiver
|
|
|
|
|
{
|
|
|
|
|
public List<MethodDeclarationSyntax> SvcImplementations { get; }
|
|
|
|
|
|
|
|
|
|
public SyscallSyntaxReceiver()
|
|
|
|
|
{
|
|
|
|
|
SvcImplementations = new List<MethodDeclarationSyntax>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
|
|
|
|
|
{
|
2023-03-28 14:59:43 +02:00
|
|
|
|
if (!(syntaxNode is ClassDeclarationSyntax classDeclaration) || classDeclaration.AttributeLists.Count == 0)
|
2022-05-31 22:12:46 +02:00
|
|
|
|
{
|
2023-03-28 14:59:43 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!classDeclaration.AttributeLists.Any(attributeList =>
|
|
|
|
|
attributeList.Attributes.Any(x => x.Name.GetText().ToString() == "SvcImpl")))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-31 22:12:46 +02:00
|
|
|
|
|
2023-03-28 14:59:43 +02:00
|
|
|
|
foreach (var memberDeclaration in classDeclaration.Members)
|
|
|
|
|
{
|
|
|
|
|
if (memberDeclaration is MethodDeclarationSyntax methodDeclaration)
|
|
|
|
|
{
|
|
|
|
|
VisitMethod(methodDeclaration);
|
2022-05-31 22:12:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void VisitMethod(MethodDeclarationSyntax methodDeclaration)
|
|
|
|
|
{
|
2023-03-28 14:59:43 +02:00
|
|
|
|
if (methodDeclaration.AttributeLists.Count == 0)
|
2022-05-31 22:12:46 +02:00
|
|
|
|
{
|
2023-03-28 14:59:43 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (methodDeclaration.AttributeLists.Any(attributeList =>
|
|
|
|
|
attributeList.Attributes.Any(x => x.Name.GetText().ToString() == "Svc")))
|
|
|
|
|
{
|
|
|
|
|
SvcImplementations.Add(methodDeclaration);
|
2022-05-31 22:12:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|