diff --git a/NewSource/Socordia.CodeAnalysis/AST/Declarations/ParameterDeclaration.cs b/NewSource/Socordia.CodeAnalysis/AST/Declarations/ParameterDeclaration.cs index eb278fdb..487220b4 100644 --- a/NewSource/Socordia.CodeAnalysis/AST/Declarations/ParameterDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/AST/Declarations/ParameterDeclaration.cs @@ -1,4 +1,6 @@ -namespace Socordia.CodeAnalysis.AST.Declarations; +using Socordia.CodeAnalysis.AST.TypeNames; + +namespace Socordia.CodeAnalysis.AST.Declarations; public class ParameterDeclaration : Declaration { @@ -16,5 +18,5 @@ public ParameterDeclaration(AstNode type, string name, AstNode? defaultValue, bo public AstNode? DefaultValue => Properties.GetOrDefault(nameof(DefaultValue)); public bool AssertNotNull => Properties.GetOrDefault(nameof(AssertNotNull)); - public AstNode Type => Children[0]; + public TypeName Type =>(TypeName) Children[0]; } \ No newline at end of file diff --git a/NewSource/SocordiaC/Compilation/CollectClassesListener.cs b/NewSource/SocordiaC/Compilation/CollectClassesListener.cs index 62da67c0..eda1724b 100644 --- a/NewSource/SocordiaC/Compilation/CollectClassesListener.cs +++ b/NewSource/SocordiaC/Compilation/CollectClassesListener.cs @@ -6,16 +6,17 @@ namespace SocordiaC.Compilation; -public class CollectClassesListener : Listener +public class CollectClassesListener : Listener + where TNode : ClassDeclaration { - protected override void ListenToNode(Driver context, ClassDeclaration node) + protected override void ListenToNode(Driver context, TNode node) { var type = context.Compilation.Module.CreateType(context.Settings.RootNamespace, node.Name, GetModifiers(node), GetBaseType(node, context.Compilation)); } - private TypeDefOrSpec? GetBaseType(ClassDeclaration node, DistIL.Compilation compilation) + private TypeDefOrSpec? GetBaseType(TNode node, DistIL.Compilation compilation) { if (node.Inheritances.Count == 0) { diff --git a/NewSource/SocordiaC/Compilation/CollectFunctionsListener.cs b/NewSource/SocordiaC/Compilation/CollectFunctionsListener.cs index 1088468b..f4b990e9 100644 --- a/NewSource/SocordiaC/Compilation/CollectFunctionsListener.cs +++ b/NewSource/SocordiaC/Compilation/CollectFunctionsListener.cs @@ -15,9 +15,10 @@ public class CollectFunctionsListener(TypeDef type) : Listener GetParameters(FunctionDefinition node) + { + var result = new List(); + + foreach (var param in node.Signature.Parameters) + { + var paramDef = new ParamDef(new TypeSig(Utils.GetTypeFromNode(param.Type, type)), param.Name); + //paramDef.DefaultValue = param.DefaultValue; //ToDo: convert default value + result.Add(paramDef); + } + + return result; + } + private MethodAttributes GetModifiers(Declaration node) { var attrs = (MethodAttributes)0; diff --git a/NewSource/SocordiaC/Stages/ConvertToIrStage.cs b/NewSource/SocordiaC/Stages/ConvertToIrStage.cs index ad68558e..644624ad 100644 --- a/NewSource/SocordiaC/Stages/ConvertToIrStage.cs +++ b/NewSource/SocordiaC/Stages/ConvertToIrStage.cs @@ -1,6 +1,7 @@ using Flo; using MrKWatkins.Ast.Listening; using Socordia.CodeAnalysis.AST; +using Socordia.CodeAnalysis.AST.Declarations; using SocordiaC.Compilation; namespace SocordiaC.Stages; @@ -10,9 +11,8 @@ public class ConvertToIrStage : IHandler public async Task HandleAsync(Driver context, Func> next) { var pipeline = CompositeListener.Build() - // .With(new BlockListener()) .With(new CollectFunctionsListener(context.FunctionsType)) - .With(new CollectClassesListener()) + .With(new CollectClassesListener()) .ToListener(); foreach (var tree in context.Trees) diff --git a/NewSource/SocordiaC/compilation.sc b/NewSource/SocordiaC/compilation.sc index 265d9ac4..38ff29a9 100644 --- a/NewSource/SocordiaC/compilation.sc +++ b/NewSource/SocordiaC/compilation.sc @@ -3,7 +3,7 @@ func main() -> none { } -private func test() -> i32 +private func test(hello: i32, flag: bool) -> i32 { }