diff --git a/Example.Shared/IDataList.cs b/Example.Shared/IDataList.cs new file mode 100644 index 0000000..90792d4 --- /dev/null +++ b/Example.Shared/IDataList.cs @@ -0,0 +1,12 @@ +using mROA.Implementation.Attributes; + +namespace Example.Shared +{ + // [SharedObjectInterface] + // public interface IDataList + // { + // T Get(int index); + // void Add(T item); + // void Set(int index, T item); + // } +} \ No newline at end of file diff --git a/mROA.Codegen/mROASourceGenerator.cs b/mROA.Codegen/mROASourceGenerator.cs index 70eefa9..b0cd06c 100644 --- a/mROA.Codegen/mROASourceGenerator.cs +++ b/mROA.Codegen/mROASourceGenerator.cs @@ -30,48 +30,6 @@ namespace {Namespace} }} }}"; - // public void Initialize(IncrementalGeneratorInitializationContext context) - // { - // // Filter classes annotated with the [Report] attribute. Only filtered Syntax Nodes can trigger code generation. - // var provider = context.SyntaxProvider - // .CreateSyntaxProvider( - // (s, _) => s is InterfaceDeclarationSyntax, - // (ctx, _) => GetClassDeclarationForSourceGen(ctx)) - // .Where(t => t.reportAttributeFound) - // .Select((t, _) => t.Item1); - // - // // Generate the source code. - // context.RegisterSourceOutput(context.CompilationProvider.Combine(provider.Collect()), - // ((ctx, t) => GenerateCode(ctx, t.Left, t.Right))); - // } - - /// - /// Checks whether the Node is annotated with the [Report] attribute and maps syntax context to the specific node type (ClassDeclarationSyntax). - /// - /// Syntax context, based on CreateSyntaxProvider predicate - /// The specific cast and whether the attribute was found. - // private static (InterfaceDeclarationSyntax, bool reportAttributeFound) GetClassDeclarationForSourceGen( - // GeneratorSyntaxContext context) - // { - // var classDeclarationSyntax = (InterfaceDeclarationSyntax)context.Node; - // - // // Go through all attributes of the class. - // foreach (AttributeListSyntax attributeListSyntax in classDeclarationSyntax.AttributeLists) - // foreach (AttributeSyntax attributeSyntax in attributeListSyntax.Attributes) - // { - // if (context.SemanticModel.GetSymbolInfo(attributeSyntax).Symbol is not IMethodSymbol attributeSymbol) - // continue; // if we can't get the symbol, ignore it - // - // string attributeName = attributeSymbol.ContainingType.ToDisplayString(); - // - // // Check the full name of the [Report] attribute. - // if (attributeName == "mROA.Implementation.Attributes.SharedObjectInterfaceAttribute") - // return (classDeclarationSyntax, true); - // } - // - // return (classDeclarationSyntax, false); - // } - /// /// Generate code action. /// It will be executed on specific nodes (ClassDeclarationSyntax annotated with the [Report] attribute) changed by the user. @@ -99,6 +57,8 @@ namespace {Namespace} var namespaceName = classSymbol.ContainingNamespace.ToDisplayString(); + + // 'Identifier' means the token of the node. Get class name from the syntax node. var className = classDeclarationSyntax.Identifier.Text; @@ -112,14 +72,13 @@ namespace {Namespace} var methodsText = new List(); - + foreach (var method in methodBody) { var index = methods.Count; methods.Add((namespaceName + "." + originalName, method)); var sb = new StringBuilder(); - bool isAsync = method.ReturnType.Name == "Task"; bool isVoid = method.ReturnType.Name == "Void" || method.ReturnType.ToString() == "System.Threading.Tasks.Task"; @@ -151,30 +110,6 @@ namespace {Namespace} if (!isVoid) prefix = "return " + prefix; - // if (method.ReturnType.OriginalDefinition.ToString() == "System.Threading.Tasks.Task") - // { - // var type = method.ReturnType.ToString(); - // type = type.Substring(type.IndexOf('<') + 1); - // type = type.Substring(0, type.Length - 1); - // sb.AppendLine( - // $"\t\tvar response = await serialisationModule.GetFinalCommandExecution<{type}>(defaultCallRequestCodegen.CallRequestId);"); - // sb.AppendLine($"\t\treturn ({type})response.Result;"); - // } - // else if (!isAsync && method.ReturnType.ToDisplayString() != "void") - // { - // var type = method.ReturnType.ToDisplayString(); - // sb.AppendLine( - // $"\t\tvar response = serialisationModule.GetFinalCommandExecution<{type}>(defaultCallRequestCodegen.CallRequestId).GetAwaiter().GetResult();"); - // sb.AppendLine($"\t\treturn ({type})response.Result;"); - // } - // else - // { - // sb.AppendLine( - // "\t\tserialisationModule.GetNextCommandExecution(defaultCallRequestCodegen.CallRequestId).Wait();"); - // } - // - // sb.AppendLine("\t}"); - sb.AppendLine("\t\t\t" + prefix + caller + postfix + ";"); sb.AppendLine("\t\t}"); @@ -213,8 +148,11 @@ namespace {namespaceName} if (methods.Count != 0) { + // var methodsStringed = methods.Select(i => + // $"typeof({i.Item1}).GetMethod(\"{i.Item2.Name}\", new Type[] {{{string.Join(", ", i.Item2.Parameters.Select(p => $"typeof({p.Type.ToDisplayString()})"))}}})") + // .ToList(); var methodsStringed = methods.Select(i => - $"typeof({i.Item1}).GetMethod(\"{i.Item2.Name}\", new Type[] {{{string.Join(", ", i.Item2.Parameters.Select(p => $"typeof({p.Type.ToDisplayString()})"))}}})") + $"typeof({i.Item1}).GetMethod(\"{i.Item2.Name}\")") .ToList(); var coCodegenRepoCode = @$"// diff --git a/mROA/Implementation/Backend/BasicExecutionModule.cs b/mROA/Implementation/Backend/BasicExecutionModule.cs index c1522ca..443a366 100644 --- a/mROA/Implementation/Backend/BasicExecutionModule.cs +++ b/mROA/Implementation/Backend/BasicExecutionModule.cs @@ -148,7 +148,7 @@ namespace mROA.Implementation.Backend { Id = command.Id }; - _cancellationRepo.FreeCancelation(command.Id); + _cancellationRepo?.FreeCancelation(command.Id); var multiClientOwnershipRepository = TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository; diff --git a/mROA/Implementation/SharedObject.cs b/mROA/Implementation/SharedObject.cs index b9d5256..af7847e 100644 --- a/mROA/Implementation/SharedObject.cs +++ b/mROA/Implementation/SharedObject.cs @@ -12,7 +12,7 @@ namespace mROA.Implementation public static class TransmissionConfig { #if TRACE - public static int TotalTransmittedBytes { get; set; } = 0; + public static int TotalTransmittedBytes { get; set; } #endif private static IContextRepository? _realContextRepository; private static IContextRepository? _remoteEndpointContextRepository;