summaryrefslogtreecommitdiffstats
path: root/src/ast/types
diff options
context:
space:
mode:
authorGeno <48206120+gabrielegenovese@users.noreply.github.com>2024-07-11 10:57:56 +0000
committerGitHub <noreply@github.com>2024-07-11 10:57:56 +0000
commitb50c7e99603e9f85d82d700d62c16c4fcef88715 (patch)
tree5052206f06e0426a43599cb236652614db04d22e /src/ast/types
parentf0692ff5f9e39cbd1c203e9d5abebf55a3d0f6fc (diff)
Code generation (#20)
Co-authored-by: geno <gabrigeno@gmail> Co-authored-by: Santo Cariotti <santo@dcariotti.me>
Diffstat (limited to 'src/ast/types')
-rw-r--r--src/ast/types/FunctionType.java25
-rw-r--r--src/ast/types/Type.java2
2 files changed, 24 insertions, 3 deletions
diff --git a/src/ast/types/FunctionType.java b/src/ast/types/FunctionType.java
index 5e6adaa..1a04bb6 100644
--- a/src/ast/types/FunctionType.java
+++ b/src/ast/types/FunctionType.java
@@ -7,13 +7,25 @@ public class FunctionType extends Type {
private final int paramNumber;
private final Type returnType;
+ private final String label;
+ private int localvarNum;
- public FunctionType(int paramNumber, Type returnType) {
+ public FunctionType(int paramNumber, Type returnType, String label) {
this.paramNumber = paramNumber;
this.returnType = returnType;
+ this.label = label;
+ this.localvarNum = 0;
}
- // Return the length of the parameters
+ public void addLocalVar() {
+ localvarNum++;
+ }
+
+ public int getLocalvarNum() {
+ return localvarNum;
+ }
+
+ // Return the number of the parameters
public int getParamNumber() {
return paramNumber;
}
@@ -22,8 +34,17 @@ public class FunctionType extends Type {
return returnType;
}
+ public String getLabel() {
+ return label;
+ }
+
@Override
public String toPrint(String prefix) {
return prefix + "Function\n";
}
+
+ @Override
+ public String toString() {
+ return "NP: " + paramNumber + " RT: " + returnType + " L: " + label;
+ }
}
diff --git a/src/ast/types/Type.java b/src/ast/types/Type.java
index 6190106..c5b8312 100644
--- a/src/ast/types/Type.java
+++ b/src/ast/types/Type.java
@@ -20,7 +20,7 @@ public class Type implements Node {
}
@Override
- public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting, FunctionType ft) {
// It is never invoked
return null;
}