2014-09-02 10:33:54 +02:00
|
|
|
package de.dhbwstuttgart.syntaxtree.statement;
|
2014-02-09 16:07:31 +01:00
|
|
|
|
2017-03-06 17:59:01 +01:00
|
|
|
import de.dhbwstuttgart.typeinference.ConstraintSet;
|
2017-03-08 03:43:47 +01:00
|
|
|
import de.dhbwstuttgart.typeinference.OderConstraint;
|
2017-03-06 17:59:01 +01:00
|
|
|
import de.dhbwstuttgart.typeinference.Pair;
|
2017-03-08 03:43:47 +01:00
|
|
|
import de.dhbwstuttgart.typeinference.UndConstraint;
|
|
|
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
|
|
|
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
2017-02-17 16:34:40 +01:00
|
|
|
import org.antlr.v4.runtime.Token;
|
2015-06-16 14:58:27 +02:00
|
|
|
|
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;
|
2016-12-16 00:00:37 +01:00
|
|
|
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:
|
2017-03-08 03:43:47 +01:00
|
|
|
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
|
|
|
}
|
2017-03-08 03:43:47 +01:00
|
|
|
ret.add(overloading);
|
2017-03-06 17:59:01 +01:00
|
|
|
return ret;
|
2013-10-18 13:33:46 +02:00
|
|
|
}
|
|
|
|
}
|