mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 01:38:03 +00:00
Add type to TypedClass
This commit is contained in:
parent
c7d756b083
commit
e1a0540a06
@ -25,6 +25,7 @@ public class TypedClass implements TypedNode {
|
||||
private List<TypedField> typedFields = new ArrayList<>();
|
||||
private List<TypedMethod> typedMethods = new ArrayList<>();
|
||||
private List<TypedConstructor> typedConstructors = new ArrayList<>();
|
||||
private Type type;
|
||||
|
||||
public TypedClass(Map<String, Type> localVar, Class c) {
|
||||
convertToTypedClass(localVar, c);
|
||||
@ -32,6 +33,7 @@ public class TypedClass implements TypedNode {
|
||||
|
||||
public void convertToTypedClass(Map<String, Type> localVar, Class c) {
|
||||
className = c.classname();
|
||||
type = Type.REFERENCE(className);
|
||||
|
||||
for (Declaration field : c.fieldDeclarations()) {
|
||||
typedFields.add(new TypedField(localVar, this, field));
|
||||
@ -46,7 +48,7 @@ public class TypedClass implements TypedNode {
|
||||
typedMethods.add(new TypedMethod(localVar, this, method));
|
||||
typedMethods.get(typedMethods.size() - 1).convertToTypedBlock(localVar, this, method);
|
||||
}
|
||||
|
||||
System.out.println("TypedClass: " + this.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,6 +76,61 @@ public class TypedClass implements TypedNode {
|
||||
return new TypedClass(local, c);
|
||||
}
|
||||
|
||||
public boolean isParameterWitNameInMethod(String parameterName) {
|
||||
for (TypedMethod m : typedMethods) {
|
||||
for (TypedParameter p : m.getTypedParameters()) {
|
||||
if (p.getParaName().equals(parameterName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Type getParameterType(String parameterName) {
|
||||
for (TypedMethod m : typedMethods) {
|
||||
for (TypedParameter p : m.getTypedParameters()) {
|
||||
if (p.getParaName().equals(parameterName)) {
|
||||
return p.getType();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isThereField(String fieldName) {
|
||||
|
||||
for (TypedField f : typedFields) {
|
||||
if (f.getVarName().equals(getFieldNameWithOutThis(fieldName))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private String getFieldNameWithOutThis(String fieldName) {
|
||||
if(fieldName.startsWith("this.")){
|
||||
fieldName = fieldName.substring(5);
|
||||
}
|
||||
return fieldName;
|
||||
}
|
||||
public Type getFieldType(String fieldName) {
|
||||
for (TypedField f : typedFields) {
|
||||
if (f.getVarName().equals(getFieldNameWithOutThis(fieldName))) {
|
||||
return f.getType();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Type getMethodType(String methodName) {
|
||||
for (TypedMethod m : typedMethods) {
|
||||
if (m.getName().equals(methodName)) {
|
||||
return m.getReturnType();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public byte[] codeGen() {
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, className, null, "java/lang/Object", null);
|
||||
|
Loading…
Reference in New Issue
Block a user