Fixed nullPointer Exception for missing class name

This commit is contained in:
Jochen Seyfried 2024-05-09 14:41:07 +02:00
parent 965b758fba
commit 80917ec222
2 changed files with 5 additions and 3 deletions

View File

@ -15,7 +15,7 @@ public class Compiler {
Program abstractSyntaxTree = new Program(new ArrayList<>());
List<FieldDecl> emptyFieldDecl = new ArrayList<>();
List<MethodDecl> emptyMethodDecl = new ArrayList<>();
abstractSyntaxTree.classes.add(new RefType(emptyFieldDecl, emptyMethodDecl, null, null));
abstractSyntaxTree.classes.add(new RefType(emptyFieldDecl, emptyMethodDecl, null, null, "MyClass"));
abstractSyntaxTree.typeCheck();

View File

@ -26,7 +26,8 @@ public class RefType extends AbstractType implements IClass {
public RefType(List<FieldDecl> fieldDecls,
List<MethodDecl> methodDecls,
HashMap<String, HashMap<String, String>> typeContext,
HashMap<String, HashMap<String, HashMap<String, List<String>>>> methodContext){
HashMap<String, HashMap<String, HashMap<String, List<String>>>> methodContext, String name){
this.name = name;
this.fieldDecls = fieldDecls;
this.methodDecls = methodDecls;
this.typeContext = typeContext;
@ -36,7 +37,8 @@ public class RefType extends AbstractType implements IClass {
@Override
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, List<String>>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, List<MethodDecl> fieldsOrMethods) throws Exception {
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, List<String>>>> methodContext,
HashMap<String, HashMap<String, String>> typeContext, List<MethodDecl> fieldsOrMethods) throws Exception {
TypeCheckResult result = new TypeCheckResult();
for (FieldDecl fieldDecl : fieldDecls) {