diff --git a/src/Draco.Compiler/Internal/Binding/BinderCache.cs b/src/Draco.Compiler/Internal/Binding/BinderCache.cs index f0fc11a01..f1a8c55c4 100644 --- a/src/Draco.Compiler/Internal/Binding/BinderCache.cs +++ b/src/Draco.Compiler/Internal/Binding/BinderCache.cs @@ -4,6 +4,7 @@ using System.Linq; using Draco.Compiler.Api; using Draco.Compiler.Api.Syntax; +using Draco.Compiler.Internal.Symbols; using Draco.Compiler.Internal.Symbols.Script; using Draco.Compiler.Internal.Symbols.Source; using Draco.Compiler.Internal.Symbols.Syntax; @@ -73,7 +74,7 @@ private ModuleBinder BuildModuleBinder(ModuleDeclarationSyntax syntax) // For that we unwrap from the injected import layer(s) var parent = UnwrapFromImportBinder(binder); var moduleSymbol = parent.DeclaredSymbols - .OfType() + .OfType() .FirstOrDefault(member => member.Name == syntax.Name.Text); Debug.Assert(moduleSymbol is not null); binder = WrapInImportBinder(binder, syntax); @@ -88,7 +89,7 @@ private FunctionBinder BuildFunctionDeclarationBinder(FunctionDeclarationSyntax // For that we unwrap from the injected import layer(s) var parent = UnwrapFromImportBinder(binder); var functionSymbol = parent.DeclaredSymbols - .OfType() + .OfType() .FirstOrDefault(member => member.DeclaringSyntax == syntax); Debug.Assert(functionSymbol is not null); // NOTE: We are not using the unwrapped parent, we need the injected import layers @@ -103,7 +104,7 @@ private ClassBinder BuildClassDeclarationBinder(ClassDeclarationSyntax syntax) // For that we unwrap from the injected import layer(s) var parent = UnwrapFromImportBinder(binder); var classSymbol = parent.DeclaredSymbols - .OfType() + .OfType() .First(member => member.DeclaringSyntax == syntax); // should we shove that in a helper ? return new ClassBinder(binder, classSymbol); } diff --git a/src/Draco.Compiler/Internal/OptimizingIr/Codegen/ClassCodegen.cs b/src/Draco.Compiler/Internal/OptimizingIr/Codegen/ClassCodegen.cs index bcc68f7b9..c11c58a4e 100644 --- a/src/Draco.Compiler/Internal/OptimizingIr/Codegen/ClassCodegen.cs +++ b/src/Draco.Compiler/Internal/OptimizingIr/Codegen/ClassCodegen.cs @@ -39,17 +39,13 @@ public override void VisitFunction(FunctionSymbol functionSymbol) public override void VisitField(FieldSymbol fieldSymbol) { - if (fieldSymbol is not SyntaxFieldSymbol and not AutoPropertyBackingFieldSymbol) return; + @class.DefineField(fieldSymbol); // TODO: Initializer value - @class.DefineField(fieldSymbol); } public override void VisitProperty(PropertySymbol propertySymbol) { - // TODO: Not flexible, won't work for non-auto props - if (propertySymbol is not SyntaxAutoPropertySymbol) return; - @class.DefineProperty(propertySymbol); // TODO: Initializer value diff --git a/src/Draco.Compiler/Internal/OptimizingIr/Codegen/ModuleCodegen.cs b/src/Draco.Compiler/Internal/OptimizingIr/Codegen/ModuleCodegen.cs index 86cbfd035..fd105b1a1 100644 --- a/src/Draco.Compiler/Internal/OptimizingIr/Codegen/ModuleCodegen.cs +++ b/src/Draco.Compiler/Internal/OptimizingIr/Codegen/ModuleCodegen.cs @@ -46,8 +46,6 @@ private void Complete() public override void VisitField(FieldSymbol fieldSymbol) { - if (fieldSymbol is not SyntaxFieldSymbol and not AutoPropertyBackingFieldSymbol) return; - this.module.DefineField(fieldSymbol); if (fieldSymbol is not SourceFieldSymbol sourceGlobal) return; @@ -79,9 +77,6 @@ public override void VisitType(TypeSymbol typeSymbol) public override void VisitProperty(PropertySymbol propertySymbol) { - // TODO: Not flexible, won't work for non-auto props - if (propertySymbol is not SyntaxAutoPropertySymbol) return; - this.module.DefineProperty(propertySymbol); if (propertySymbol is not SourceAutoPropertySymbol sourceAutoProp) return; diff --git a/src/Draco.Compiler/Internal/Symbols/Generic/FieldInstanceSymbol.cs b/src/Draco.Compiler/Internal/Symbols/Generic/FieldInstanceSymbol.cs index a9fa30afc..15966daae 100644 --- a/src/Draco.Compiler/Internal/Symbols/Generic/FieldInstanceSymbol.cs +++ b/src/Draco.Compiler/Internal/Symbols/Generic/FieldInstanceSymbol.cs @@ -1,4 +1,5 @@ using System.Threading; +using Draco.Compiler.Api.Syntax; namespace Draco.Compiler.Internal.Symbols.Generic; @@ -18,6 +19,7 @@ internal sealed class FieldInstanceSymbol( public override bool IsMutable => this.GenericDefinition.IsMutable; public override bool IsStatic => this.GenericDefinition.IsStatic; public override Api.Semantics.Visibility Visibility => this.GenericDefinition.Visibility; + public override SyntaxNode? DeclaringSyntax => this.GenericDefinition.DeclaringSyntax; public override Symbol? ContainingSymbol { get; } = containingSymbol; public override FieldSymbol GenericDefinition { get; } = genericDefinition; diff --git a/src/Draco.Compiler/Internal/Symbols/Generic/FunctionInstanceSymbol.cs b/src/Draco.Compiler/Internal/Symbols/Generic/FunctionInstanceSymbol.cs index b83f8b08c..c3c6010ef 100644 --- a/src/Draco.Compiler/Internal/Symbols/Generic/FunctionInstanceSymbol.cs +++ b/src/Draco.Compiler/Internal/Symbols/Generic/FunctionInstanceSymbol.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Text; using System.Threading; +using Draco.Compiler.Api.Syntax; using Draco.Compiler.Internal.BoundTree; using Draco.Compiler.Internal.Utilities; @@ -59,6 +60,7 @@ public override ImmutableArray GenericArguments public override BoundStatement? Body => this.GenericDefinition.Body; public override CodegenDelegate? Codegen => this.GenericDefinition.Codegen; public override Api.Semantics.Visibility Visibility => this.GenericDefinition.Visibility; + public override SyntaxNode? DeclaringSyntax => this.GenericDefinition.DeclaringSyntax; public override Symbol? ContainingSymbol { get; } = containingSymbol; public override FunctionSymbol GenericDefinition { get; } = genericDefinition; diff --git a/src/Draco.Compiler/Internal/Symbols/Generic/ParameterInstanceSymbol.cs b/src/Draco.Compiler/Internal/Symbols/Generic/ParameterInstanceSymbol.cs index 9ba1e3b10..386fcecd3 100644 --- a/src/Draco.Compiler/Internal/Symbols/Generic/ParameterInstanceSymbol.cs +++ b/src/Draco.Compiler/Internal/Symbols/Generic/ParameterInstanceSymbol.cs @@ -1,4 +1,5 @@ using System.Threading; +using Draco.Compiler.Api.Syntax; namespace Draco.Compiler.Internal.Symbols.Generic; @@ -16,6 +17,7 @@ internal sealed class ParameterInstanceSymbol( public override bool IsVariadic => this.GenericDefinition.IsVariadic; public override string Name => this.GenericDefinition.Name; + public override SyntaxNode? DeclaringSyntax => this.GenericDefinition.DeclaringSyntax; public override FunctionSymbol ContainingSymbol { get; } = containingSymbol; public override ParameterSymbol GenericDefinition { get; } = genericDefinition; diff --git a/src/Draco.Compiler/Internal/Symbols/Generic/PropertyAccessorInstanceSymbol.cs b/src/Draco.Compiler/Internal/Symbols/Generic/PropertyAccessorInstanceSymbol.cs index 023fa622f..031a3e6f9 100644 --- a/src/Draco.Compiler/Internal/Symbols/Generic/PropertyAccessorInstanceSymbol.cs +++ b/src/Draco.Compiler/Internal/Symbols/Generic/PropertyAccessorInstanceSymbol.cs @@ -1,3 +1,5 @@ +using Draco.Compiler.Api.Syntax; + namespace Draco.Compiler.Internal.Symbols.Generic; /// @@ -14,4 +16,5 @@ internal sealed class PropertyAccessorInstanceSymbol( { public PropertySymbol Property { get; } = property; public override Api.Semantics.Visibility Visibility => this.GenericDefinition.Visibility; + public override SyntaxNode? DeclaringSyntax => this.GenericDefinition.DeclaringSyntax; } diff --git a/src/Draco.Compiler/Internal/Symbols/Generic/PropertyInstanceSymbol.cs b/src/Draco.Compiler/Internal/Symbols/Generic/PropertyInstanceSymbol.cs index 9bb609916..d2499af82 100644 --- a/src/Draco.Compiler/Internal/Symbols/Generic/PropertyInstanceSymbol.cs +++ b/src/Draco.Compiler/Internal/Symbols/Generic/PropertyInstanceSymbol.cs @@ -1,4 +1,5 @@ using System.Threading; +using Draco.Compiler.Api.Syntax; using Draco.Compiler.Internal.Utilities; namespace Draco.Compiler.Internal.Symbols.Generic; @@ -26,6 +27,7 @@ internal sealed class PropertyInstanceSymbol( public override bool IsStatic => this.GenericDefinition.IsStatic; public override bool IsExplicitImplementation => this.GenericDefinition.IsExplicitImplementation; public override Api.Semantics.Visibility Visibility => this.GenericDefinition.Visibility; + public override SyntaxNode? DeclaringSyntax => this.GenericDefinition.DeclaringSyntax; public override Symbol? ContainingSymbol { get; } = containingSymbol; public override PropertySymbol GenericDefinition { get; } = genericDefinition; diff --git a/src/Draco.Compiler/Internal/Symbols/Generic/TypeInstanceSymbol.cs b/src/Draco.Compiler/Internal/Symbols/Generic/TypeInstanceSymbol.cs index 2d5cccf4e..88bc8f70c 100644 --- a/src/Draco.Compiler/Internal/Symbols/Generic/TypeInstanceSymbol.cs +++ b/src/Draco.Compiler/Internal/Symbols/Generic/TypeInstanceSymbol.cs @@ -2,6 +2,7 @@ using System.Collections.Immutable; using System.Linq; using System.Text; +using Draco.Compiler.Api.Syntax; using Draco.Compiler.Internal.Utilities; namespace Draco.Compiler.Internal.Symbols.Generic; @@ -63,6 +64,7 @@ public override ImmutableArray GenericArguments public override bool IsSealed => this.GenericDefinition.IsSealed; public override string Name => this.GenericDefinition.Name; public override Api.Semantics.Visibility Visibility => this.GenericDefinition.Visibility; + public override SyntaxNode? DeclaringSyntax => this.GenericDefinition.DeclaringSyntax; public override Symbol? ContainingSymbol { get; } = containingSymbol; diff --git a/src/Draco.Compiler/Internal/Symbols/Source/SourceClassSymbol.cs b/src/Draco.Compiler/Internal/Symbols/Source/SourceClassSymbol.cs index e54b0d94f..8bc9fd265 100644 --- a/src/Draco.Compiler/Internal/Symbols/Source/SourceClassSymbol.cs +++ b/src/Draco.Compiler/Internal/Symbols/Source/SourceClassSymbol.cs @@ -7,6 +7,8 @@ using Draco.Compiler.Api.Syntax; using Draco.Compiler.Internal.Binding; using Draco.Compiler.Internal.Declarations; +using Draco.Compiler.Internal.Solver.Constraints; +using Draco.Compiler.Internal.Symbols.Generic; using Draco.Compiler.Internal.Symbols.Synthetized; using Draco.Compiler.Internal.Utilities; @@ -92,7 +94,6 @@ private ImmutableArray BindMembers(IBinderProvider binderProvider) var earlierMember = result.FirstOrDefault(s => s.Name == member.Name); result.Add(member); - result.AddRange(member.GetAdditionalSymbols()); // We check for illegal shadowing if (earlierMember is null) continue; @@ -108,6 +109,25 @@ private ImmutableArray BindMembers(IBinderProvider binderProvider) location: syntax.Location, formatArgs: member.Name)); } + + // If this is a generic definition, we generic instantiate the members + if (this.IsGenericDefinition) + { + var genericContext = new GenericContext(this.GenericParameters.ToImmutableDictionary(t => t, t => t as TypeSymbol)); + for (var i = 0; i < result.Count; ++i) + { + result[i] = result[i].GenericInstantiate(this, genericContext); + } + } + + // Add additional symbols for each + var origCount = result.Count; + for (var i = 0; i < origCount; ++i) + { + var member = result[i]; + result.AddRange(member.GetAdditionalSymbols()); + } + return result.ToImmutable(); }