Compare commits

..

2 Commits

Author SHA1 Message Date
Krauß, Josefine
f273c74693 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	Source/abstractSyntaxTree/Class/MethodDecl.java
#	Source/abstractSyntaxTree/Program.java
#	Source/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java
2024-05-08 14:31:39 +02:00
Krauß, Josefine
783bab8580 context tables 2024-05-08 14:28:51 +02:00
5 changed files with 36 additions and 16 deletions

View File

@ -7,5 +7,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="asm-9.7" level="project" />
</component>
</module>

9
Source/.idea/libraries/asm_9_7.xml generated Normal file
View 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>

View File

@ -9,27 +9,21 @@ import java.util.List;
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
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){
this.methodContext = methodContext;
this.typeContext = typeContext;
}
public TypeCheckResult typeCheck(List<MethodDecl> fieldsOrMethods) throws Exception {
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, String>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, List<MethodDecl> fieldsOrMethods) throws Exception {
// write localvars
// jede methode als block statement aufrufen
return null;
}
@Override
public void codeGen(ClassWriter cw) {
}
}

View File

@ -42,7 +42,7 @@ public class RefType extends AbstractType implements IClass {
}
for (MethodDecl methodDecl : methodDecls) {
methodDecl.typeCheck(methodDecls);
methodDecl.typeCheck(methodContext, typeContext, methodDecls);
}
result.type = "class";

View File

@ -2,10 +2,14 @@ package abstractSyntaxTree;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Class.FieldDecl;
import abstractSyntaxTree.Class.MethodDecl;
import abstractSyntaxTree.Datatype.RefType;
import org.objectweb.asm.MethodVisitor;
import abstractSyntaxTree.Class.RefType;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import java.util.*;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
@ -17,13 +21,25 @@ public class Program {
public List<RefType> classes;
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{
for(RefType oneClass : classes){
HashMap<String, String> classVars = new HashMap<>();
for (FieldDecl fielsDecl: oneClass.fieldDecls)
classVars.put(fielsDecl.type, fielsDecl.identifier);
for (FieldDecl fieldDecl: oneClass.fieldDecls){
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();
}
return null;