FunN-Typen erstellen bei Methodenaufrufen
This commit is contained in:
parent
2c25e56a76
commit
1be1bb83ca
@ -22,12 +22,13 @@ import java.util.*;
|
||||
public class StatementGenerator {
|
||||
|
||||
private JavaClassRegistry reg;
|
||||
private Map<String, RefTypeOrTPHOrWildcardOrGeneric> localVars = new HashMap<>();
|
||||
private Map<String, RefTypeOrTPHOrWildcardOrGeneric> localVars;
|
||||
private GenericsRegistry generics;
|
||||
|
||||
public StatementGenerator(JavaClassRegistry reg, GenericsRegistry generics){
|
||||
public StatementGenerator(JavaClassRegistry reg, GenericsRegistry generics, Map<String, RefTypeOrTPHOrWildcardOrGeneric> localVars){
|
||||
this.reg = reg;
|
||||
this.generics = generics;
|
||||
this.localVars = localVars;
|
||||
}
|
||||
|
||||
public ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) {
|
||||
@ -798,14 +799,21 @@ public class StatementGenerator {
|
||||
params = new ParameterList(new ArrayList<>(), expression.getStart());
|
||||
}
|
||||
|
||||
HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> lambdaLocals = new HashMap<>();
|
||||
lambdaLocals.putAll(localVars);
|
||||
for(FormalParameter param : params.getFormalparalist()){
|
||||
lambdaLocals.put(param.getName(), param.getType());
|
||||
}
|
||||
StatementGenerator lambdaGenerator = new StatementGenerator(reg, generics, lambdaLocals);
|
||||
|
||||
Block block;
|
||||
if(expression.lambdaBody().expression() != null){
|
||||
List<Statement> statements = new ArrayList<>();
|
||||
statements.add(new Return(convert(expression.lambdaBody().expression()),
|
||||
statements.add(new Return(lambdaGenerator.convert(expression.lambdaBody().expression()),
|
||||
expression.lambdaBody().expression().getStart()));
|
||||
block = new Block(statements, expression.lambdaBody().getStart());
|
||||
}else{
|
||||
block = convert(expression.lambdaBody().block());
|
||||
block = lambdaGenerator.convert(expression.lambdaBody().block());
|
||||
}
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
|
||||
funNParams.add(TypePlaceholder.fresh(expression.getStart()));//ret-Type
|
||||
|
@ -209,7 +209,7 @@ public class SyntaxTreeGenerator{
|
||||
private Method convert(int modifiers, Java8Parser.MethodHeaderContext header, Java8Parser.MethodBodyContext body,
|
||||
JavaClassName parentClass, GenericsRegistry localGenerics) {
|
||||
|
||||
StatementGenerator stmtGen = new StatementGenerator(reg, localGenerics);
|
||||
StatementGenerator stmtGen = new StatementGenerator(reg, localGenerics, new HashMap<>());
|
||||
|
||||
String name = header.methodDeclarator().Identifier().getText();
|
||||
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), header.getStart());
|
||||
|
@ -17,4 +17,8 @@ public class FormalParameter extends SyntaxTreeNode
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
@ -243,6 +243,13 @@ public class TYPE implements StatementVisitor{
|
||||
|
||||
public static List<MethodAssumption> getMethods(String name, int numArgs, TypeInferenceBlockInformation info) {
|
||||
List<MethodAssumption> ret = new ArrayList<>();
|
||||
if(name.equals("apply")){
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
|
||||
for(int i = 0; i< numArgs + 1 ; i++){
|
||||
funNParams.add(TypePlaceholder.fresh(new NullToken()));
|
||||
}
|
||||
ret.add(new MethodAssumption(new FunN(funNParams), funNParams.get(0), funNParams.subList(1, funNParams.size())));
|
||||
}
|
||||
for(ClassOrInterface cl : info.getAvailableClasses()){
|
||||
for(Method m : cl.getMethods()){
|
||||
if(m.getName().equals(name) &&
|
||||
|
@ -26,7 +26,8 @@ public class JavaTXCompilerTest {
|
||||
|
||||
@Test
|
||||
public void test() throws IOException, ClassNotFoundException {
|
||||
filesToTest.add(new File(rootDirectory+"Lambda.jav"));
|
||||
filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Vector.jav"));
|
||||
|
Loading…
Reference in New Issue
Block a user