Add parameters to function

This commit is contained in:
Tristan B. Kildaire 2021-03-22 11:18:56 +02:00
parent c02791d748
commit 69afebbe04
2 changed files with 42 additions and 5 deletions

View File

@ -363,7 +363,7 @@ public final class Parser
private struct funcDefPair
{
Statement[] bodyStatements;
ArgumentList[] args;
Variable[] args;
}
private funcDefPair parseFuncDef()
@ -371,7 +371,7 @@ public final class Parser
gprintln("parseFuncDef(): Enter", DebugType.WARNING);
Statement[] statements;
ArgumentList[] argumentList;
Variable[] argumentList;
funcDefPair bruh;
@ -399,6 +399,10 @@ public final class Parser
string identifier = getCurrentToken().getToken();
nextToken();
/* Add the local variable (parameter variable) */
argumentList ~= new Variable(type, identifier);
moreArgs = false;
parameterCount++;

View File

@ -423,6 +423,11 @@ public class Clazz : Entity
{
this.statements ~= statements;
}
public override string toString()
{
return "Class (Name: "~name~", Parent: "~parentClass~", Interfaces: "~to!(string)(interfaces)~")";
}
}
@ -434,14 +439,16 @@ public class ArgumentList
public class Function : TypedEntity
{
private string name;
private ArgumentList[] params;
private string returnType;
private Variable[] params;
private Statement[] bodyStatements;
this(string name, string returnType, Statement[] bodyStatements, ArgumentList[] args)
this(string name, string returnType, Statement[] bodyStatements, Variable[] args)
{
this.name = name;
this.returnType = returnType;
this.bodyStatements = bodyStatements;
this.params = args;
}
/**
@ -462,6 +469,27 @@ public class Function : TypedEntity
return variables;
}
public override string toString()
{
string argTypes;
for(ulong i = 0; i < params.length; i++)
{
Variable variable = params[i];
if(i == params.length-1)
{
argTypes ~= variable.getType();
}
else
{
argTypes ~= variable.getType() ~ ", ";
}
}
return "Function (Name: "~name~", ReturnType: "~returnType~", Args: "~argTypes~")";
}
}
public class Variable : TypedEntity
@ -487,6 +515,11 @@ public class Variable : TypedEntity
return assignment;
}
public string getType()
{
return type;
}
public override string toString()
{
return "Variable (Ident: "~identifier~", Type: "~type~")";