context tables
This commit is contained in:
parent
56ee3602b5
commit
783bab8580
1
Source/.idea/Source.iml
generated
1
Source/.idea/Source.iml
generated
@ -7,5 +7,6 @@
|
|||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="asm-9.7" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
9
Source/.idea/libraries/asm_9_7.xml
generated
Normal file
9
Source/.idea/libraries/asm_9_7.xml
generated
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="asm-9.7">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/../Lib/asm-9.7.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
@ -1,30 +1,26 @@
|
|||||||
package abstractSyntaxTree.Class;
|
package abstractSyntaxTree.Class;
|
||||||
|
|
||||||
import TypeCheck.TypeCheckResult;
|
import TypeCheck.TypeCheckResult;
|
||||||
import abstractSyntaxTree.Program;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MethodDecl implements IClass {
|
public class MethodDecl implements IClass {
|
||||||
|
|
||||||
// name
|
public String classThatContainsMethod;
|
||||||
|
public String name;
|
||||||
|
public List<String> parameters;
|
||||||
|
public String returnType;
|
||||||
|
|
||||||
private HashMap<String, HashMap<String, HashMap<String, String>>> methodContext;
|
|
||||||
private HashMap<String, HashMap<String, String>> typeContext;
|
|
||||||
|
|
||||||
//TODO: Move this into the typeCheck
|
//TODO: Move this into the typeCheck
|
||||||
private HashMap<String, String> localVars; // (type, identifier) // add content here
|
private HashMap<String, String> localVars; // (type, identifier) // add content here
|
||||||
|
|
||||||
public MethodDecl(HashMap<String, HashMap<String, HashMap<String, String>>> methodContext, HashMap<String, HashMap<String, String>> typeContext){
|
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, String>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, List<MethodDecl> fieldsOrMethods) throws Exception {
|
||||||
this.methodContext = methodContext;
|
|
||||||
this.typeContext = typeContext;
|
|
||||||
}
|
|
||||||
public TypeCheckResult typeCheck(List<MethodDecl> fieldsOrMethods) throws Exception {
|
|
||||||
// write localvars
|
// write localvars
|
||||||
|
|
||||||
|
|
||||||
// jede methode als block statement aufrufen
|
// jede methode als block statement aufrufen
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class RefType extends AbstractType implements IDatatype {
|
public class RefType extends AbstractType implements IDatatype {
|
||||||
|
|
||||||
String name;
|
public String name;
|
||||||
public List<FieldDecl> fieldDecls;
|
public List<FieldDecl> fieldDecls;
|
||||||
public List<MethodDecl> methodDecls;
|
public List<MethodDecl> methodDecls;
|
||||||
private HashMap<String, HashMap<String, String>> typeContext; // (class, (type, identifier))
|
private HashMap<String, HashMap<String, String>> typeContext; // (class, (type, identifier))
|
||||||
@ -40,7 +40,7 @@ public class RefType extends AbstractType implements IDatatype {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (MethodDecl methodDecl : methodDecls) {
|
for (MethodDecl methodDecl : methodDecls) {
|
||||||
methodDecl.typeCheck(methodDecls);
|
methodDecl.typeCheck(methodContext, typeContext, methodDecls);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.type = "class";
|
result.type = "class";
|
||||||
|
@ -2,23 +2,35 @@ package abstractSyntaxTree;
|
|||||||
|
|
||||||
import TypeCheck.TypeCheckResult;
|
import TypeCheck.TypeCheckResult;
|
||||||
import abstractSyntaxTree.Class.FieldDecl;
|
import abstractSyntaxTree.Class.FieldDecl;
|
||||||
|
import abstractSyntaxTree.Class.MethodDecl;
|
||||||
import abstractSyntaxTree.Datatype.RefType;
|
import abstractSyntaxTree.Datatype.RefType;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Program {
|
public class Program {
|
||||||
public List<RefType> classes;
|
public List<RefType> classes;
|
||||||
|
|
||||||
public HashMap<String, HashMap<String, String>> typeContext; // (class, (type, identifier))
|
public HashMap<String, HashMap<String, String>> typeContext; // (class, (type, identifier))
|
||||||
public HashMap<String, HashMap<String, HashMap<String, String>>> methodContext; // (class, (returntype, (identifier, parameter)))
|
public HashMap<String, HashMap<String, HashMap<String, List<String>>>> methodContext; // (class, (returntype, (identifier, parameter)))
|
||||||
|
|
||||||
public TypeCheckResult typeCheck() throws Exception{
|
public TypeCheckResult typeCheck() throws Exception{
|
||||||
for(RefType oneClass : classes){
|
for(RefType oneClass : classes){
|
||||||
HashMap<String, String> classVars = new HashMap<>();
|
HashMap<String, String> classVars = new HashMap<>();
|
||||||
for (FieldDecl fielsDecl: oneClass.fieldDecls)
|
for (FieldDecl fieldDecl: oneClass.fieldDecls){
|
||||||
classVars.put(fielsDecl.type, fielsDecl.identifier);
|
classVars.put(fieldDecl.type, fieldDecl.identifier);
|
||||||
|
}
|
||||||
|
typeContext.put(oneClass.name, classVars);
|
||||||
|
|
||||||
|
HashMap<String, List<String>> methodIdentifierAndParameter = new HashMap<>();
|
||||||
|
HashMap<String, HashMap<String, List<String >>> returnTypeAndMethod = new HashMap<>();
|
||||||
|
for (MethodDecl methodDecl : oneClass.methodDecls){
|
||||||
|
methodIdentifierAndParameter.put(methodDecl.name, methodDecl.parameters);
|
||||||
|
returnTypeAndMethod.put(methodDecl.returnType, methodIdentifierAndParameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
methodContext.put(oneClass.name, returnTypeAndMethod);
|
||||||
|
|
||||||
oneClass.typeCheck();
|
oneClass.typeCheck();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -26,7 +38,7 @@ public class Program {
|
|||||||
|
|
||||||
public void codeGen() throws Exception{
|
public void codeGen() throws Exception{
|
||||||
for(RefType oneClass : classes){
|
for(RefType oneClass : classes){
|
||||||
oneClass.codeGen();
|
//oneClass.codeGen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,16 +43,20 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public void codeGen(MethodVisitor mv) throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void CodeGen(MethodVisitor mv) throws Exception {
|
public void CodeGen(MethodVisitor mv) throws Exception {
|
||||||
//Generate Bytecode for the receiver
|
//Generate Bytecode for the receiver
|
||||||
if(classThatHasTheMethodIfNotThis != null){
|
if(classThatHasTheMethodIfNotThis != null){
|
||||||
classThatHasTheMethodIfNotThis.CodeGen(mv);
|
classThatHasTheMethodIfNotThis.codeGen(mv);
|
||||||
} else {
|
} else {
|
||||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IExpression argument : arguments) {
|
for (IExpression argument : arguments) {
|
||||||
argument.CodeGen(mv);
|
argument.codeGen(mv);
|
||||||
}
|
}
|
||||||
|
|
||||||
//We need the class reference and the return type of the method
|
//We need the class reference and the return type of the method
|
||||||
|
Loading…
Reference in New Issue
Block a user