mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-10-06 16:01:40 +00:00
Updated TypedField
This commit is contained in:
parent
e1a0540a06
commit
6e2a331a66
@ -12,6 +12,8 @@ import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static de.maishai.typedast.Type.Kind.REFERENCE;
|
||||
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@Data
|
||||
@ -24,20 +26,25 @@ public class TypedField implements TypedNode {
|
||||
}
|
||||
|
||||
public void convertToTypedField(Map<String, Type> localVar, TypedClass clas, Declaration declaration){
|
||||
if(localVar.containsKey(declaration.name())){
|
||||
throw new RuntimeException("Variable " + declaration.name() + " already declared");
|
||||
}
|
||||
|
||||
this.type = declaration.type();
|
||||
varName = declaration.name();
|
||||
type = declaration.type();
|
||||
localVar.put(this.varName, this.type);
|
||||
this.typeCheck(localVar, clas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type typeCheck(Map<String, Type> localVar, TypedClass clas) {
|
||||
if (localVar.containsKey(varName)) {
|
||||
throw new RuntimeException("Variable " + varName + " already declared");
|
||||
|
||||
if(clas.isThereField(varName)){
|
||||
throw new RuntimeException("Field " + varName + " already declared");
|
||||
}
|
||||
localVar.put(varName, type);
|
||||
if(type.getKind() == REFERENCE){
|
||||
if(!type.getReference().equals(clas.getClassName())){
|
||||
throw new RuntimeException("Field " + varName + " has wrong type");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user