2024-05-02 11:12:39 +00:00
|
|
|
package abstractSyntaxTree.Class;
|
|
|
|
|
2024-05-08 09:22:12 +00:00
|
|
|
import TypeCheck.AbstractType;
|
|
|
|
import TypeCheck.TypeCheckHelper;
|
2024-05-08 08:10:44 +00:00
|
|
|
import TypeCheck.TypeCheckResult;
|
2024-05-08 09:22:12 +00:00
|
|
|
import abstractSyntaxTree.Program;
|
2024-05-08 08:10:44 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2024-05-08 10:48:56 +00:00
|
|
|
import java.util.HashMap;
|
2024-05-08 08:10:44 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2024-05-08 09:22:12 +00:00
|
|
|
public class FieldDecl extends AbstractType implements IClass{
|
2024-05-08 08:10:44 +00:00
|
|
|
|
2024-05-08 10:48:56 +00:00
|
|
|
private HashMap<String, HashMap<String, String>> typeContext; // form class from program
|
|
|
|
public String type; // from parser
|
|
|
|
public String identifier; // from parser
|
|
|
|
|
|
|
|
public FieldDecl(HashMap<String, HashMap<String, String>> typeContext){
|
|
|
|
this.typeContext = typeContext;
|
2024-05-08 09:22:12 +00:00
|
|
|
}
|
2024-05-08 08:10:44 +00:00
|
|
|
public TypeCheckResult typeCheck(List<FieldDecl> classFieldsIdentifier) throws Exception {
|
|
|
|
TypeCheckResult result = new TypeCheckResult();
|
|
|
|
if (classFieldsIdentifier.contains(this.identifier)){
|
|
|
|
throw new Exception("field already defined");
|
|
|
|
} else {
|
|
|
|
classFieldsIdentifier.add(this);
|
|
|
|
}
|
2024-05-08 09:22:12 +00:00
|
|
|
//TypeCheckHelper.typeExists(type, ) // need all types of classes
|
|
|
|
setTypeCheckResult(result);
|
2024-05-08 08:10:44 +00:00
|
|
|
|
|
|
|
return result;
|
2024-05-08 09:22:12 +00:00
|
|
|
|
|
|
|
//write field table
|
2024-05-08 08:10:44 +00:00
|
|
|
}
|
2024-05-02 11:12:39 +00:00
|
|
|
}
|