4using Microsoft.CodeAnalysis;
5using Microsoft.CodeAnalysis.Text;
16 public static DiagnosticDescriptor
CreateDescriptor(
string id,
string title,
string messageFormat,
string category, DiagnosticSeverity severity)
18 return new DiagnosticDescriptor(
id, title, messageFormat, category, severity,
true);
27 DiagnosticSeverity severity,
28 params
object?[]? args)
30 return CreateDescriptor(
id, title, messageFormat, category, severity).CreateDiagnostic(symbol, args);
33 public static Diagnostic
CreateDiagnostic(
this DiagnosticDescriptor descriptor, ISymbol symbol, params
object?[]? args)
35 return Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args);
38 public static Diagnostic
CreateDiagnostic(
this ISymbol symbol, DiagnosticDescriptor descriptor, params
object?[]? args)
40 return Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args);
63 public static AttributeData?
GetAttribute(
this ISymbol symbol,
string name)
65 return symbol.GetAttributes().FirstOrDefault(x => x.AttributeClass?.ToDisplayString() == name);
70 return symbol.GetReturnTypeAttributes().FirstOrDefault(x => x.AttributeClass?.ToDisplayString() == name);
76 "BadInteropAttributes.cs",
79namespace BadScript2.Interop
81 [AttributeUsage(AttributeTargets.Class)]
82 internal sealed class BadInteropApiAttribute : Attribute
84 public string? Name { get; }
85 public bool ConstructorPrivate { get; }
86 public BadInteropApiAttribute(string? name = null, bool constructorPrivate = false)
89 ConstructorPrivate = constructorPrivate;
93 [AttributeUsage(AttributeTargets.Method)]
94 internal sealed class BadMethodAttribute : Attribute
96 public string? Name { get; }
97 public string? Description { get; }
98 public BadMethodAttribute(string? name = null, string? description = null)
101 Description = description;
105 [AttributeUsage(AttributeTargets.Parameter)]
106 internal sealed class BadParameterAttribute : Attribute
108 public string? Name { get; }
109 public string? Description { get; }
110 public string? NativeType { get; }
111 public BadParameterAttribute(string? name = null, string? description = null, string? nativeType = null)
114 Description = description;
115 NativeType = nativeType;
119 [AttributeUsage(AttributeTargets.ReturnValue)]
120 internal sealed class BadReturnAttribute : Attribute
122 public string? Description { get; }
123 public bool AllowNativeTypes { get; }
124 public BadReturnAttribute(string? description = null, bool allowNativeTypes = false)
126 Description = description;
127 AllowNativeTypes = allowNativeTypes;
131 internal abstract class BadAutoGeneratedInteropApi : BadScript2.Runtime.Interop.BadInteropApi
133 protected BadAutoGeneratedInteropApi(string apiName) : base(apiName) { }
135 protected virtual void AdditionalData(BadScript2.Runtime.Objects.BadTable target) { }
static ? AttributeData GetInteropMethodAttribute(this IMethodSymbol symbol)
static ? AttributeData GetReturnTypeAttribute(this IMethodSymbol symbol, string name)
static ? AttributeData GetParameterAttribute(this IParameterSymbol symbol)
static DiagnosticDescriptor CreateDescriptor(string id, string title, string messageFormat, string category, DiagnosticSeverity severity)
static Diagnostic CreateDiagnostic(this ISymbol symbol, DiagnosticDescriptor descriptor, params object?[]? args)
static ? AttributeData GetReturnTypeAttribute(this IMethodSymbol symbol)
static Diagnostic CreateDiagnostic(this ISymbol symbol, string id, string title, string messageFormat, string category, DiagnosticSeverity severity, params object?[]? args)
const string INTEROP_METHOD_RETURN_ATTRIBUTE
const string INTEROP_METHOD_PARAMETER_ATTRIBUTE
static void RegisterAttributeSource(IncrementalGeneratorPostInitializationContext context)
const string INTEROP_METHOD_ATTRIBUTE
static Diagnostic CreateDiagnostic(this DiagnosticDescriptor descriptor, ISymbol symbol, params object?[]? args)
const string INTEROP_API_ATTRIBUTE
static ? AttributeData GetInteropApiAttribute(this ITypeSymbol symbol)
static ? AttributeData GetAttribute(this ISymbol symbol, string name)