47 lines
1.7 KiB
Java
Raw Normal View History

2014-09-02 10:33:54 +02:00
package de.dhbwstuttgart.syntaxtree.statement;
2017-03-06 17:59:01 +01:00
import de.dhbwstuttgart.typeinference.ConstraintSet;
import de.dhbwstuttgart.typeinference.OderConstraint;
2017-03-06 17:59:01 +01:00
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
import org.antlr.v4.runtime.Token;
2014-09-02 10:33:54 +02:00
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
2013-10-18 13:33:46 +02:00
2017-03-06 17:59:01 +01:00
public class MethodCall extends Statement
2013-10-18 13:33:46 +02:00
{
2017-03-06 17:59:01 +01:00
private final String name;
2013-10-18 13:33:46 +02:00
private Receiver receiver;
private ArgumentList arglist;
2014-02-22 04:58:49 +01:00
2017-03-06 17:59:01 +01:00
public MethodCall(Receiver receiver, String methodName, ArgumentList argumentList, Token offset){
super(TypePlaceholder.fresh(offset),offset);
this.arglist = argumentList;
this.name = methodName;
2017-03-15 16:17:07 +01:00
this.receiver = receiver;
2017-03-06 17:59:01 +01:00
}
2013-10-18 13:33:46 +02:00
2017-03-06 17:59:01 +01:00
@Override
public ConstraintSet getConstraints(TypeInferenceInformation info) {
ConstraintSet ret = receiver.getConstraints(info);
//Overloading:
OderConstraint overloading = new OderConstraint();
for(MethodAssumption m : info.getMethods(name, arglist)){
UndConstraint methodConstraints = new UndConstraint();
methodConstraints.addConstraint(receiver.getType(), m.getReceiverType());
methodConstraints.addConstraint(m.getReturnType(), this.getType());
for(int i = 0;i<arglist.getArguments().size();i++){
methodConstraints.addConstraint(m.getArgTypes().get(i),
arglist.getArguments().get(i).getType());
}
2017-03-15 16:54:43 +01:00
overloading.addConstraint(methodConstraints);
2017-03-06 17:59:01 +01:00
}
ret.add(overloading);
2017-03-06 17:59:01 +01:00
return ret;
2013-10-18 13:33:46 +02:00
}
}