2013-10-18 13:33:46 +02:00
// ino.module.MethodCall.8639.package
2014-09-02 10:33:54 +02:00
package de.dhbwstuttgart.syntaxtree.statement ;
2013-10-18 13:33:46 +02:00
// ino.end
// ino.module.MethodCall.8639.import
import java.util.Hashtable ;
2015-04-22 21:40:22 +02:00
import de.dhbwstuttgart.typeinference.Menge ;
2014-02-09 16:07:31 +01:00
2014-10-09 12:01:16 +02:00
import de.dhbwstuttgart.logger.Logger ;
2014-09-04 16:35:44 +02:00
import de.dhbwstuttgart.myexception.JVMCodeException ;
2014-09-02 10:33:54 +02:00
import de.dhbwstuttgart.syntaxtree.Method ;
2014-09-04 16:35:44 +02:00
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode ;
2014-09-02 10:33:54 +02:00
import de.dhbwstuttgart.syntaxtree.misc.UsedId ;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar ;
import de.dhbwstuttgart.syntaxtree.type.Type ;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder ;
import de.dhbwstuttgart.syntaxtree.type.Void ;
2015-02-26 15:50:23 +01:00
import de.dhbwstuttgart.typeinference.ConstraintType ;
2014-09-02 10:33:54 +02:00
import de.dhbwstuttgart.typeinference.ConstraintsSet ;
import de.dhbwstuttgart.typeinference.JavaCodeResult ;
2015-02-26 15:50:23 +01:00
import de.dhbwstuttgart.typeinference.OderConstraint ;
2014-09-02 10:33:54 +02:00
import de.dhbwstuttgart.typeinference.ResultSet ;
2015-02-26 15:50:23 +01:00
import de.dhbwstuttgart.typeinference.UndConstraint ;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption ;
2014-09-02 10:33:54 +02:00
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions ;
2015-02-26 15:50:23 +01:00
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException ;
2013-10-18 13:33:46 +02:00
// ino.class.MethodCall.25623.declaration
public class MethodCall extends Expr
// ino.end
// ino.class.MethodCall.25623.body
{
2015-02-25 16:34:29 +01:00
public MethodCall ( Receiver receiver , String methodName , ArgumentList argumentList , int offset ) {
this ( offset , 0 ) ;
this . set_Receiver ( receiver ) ;
this . set_Name ( methodName ) ;
this . set_ArgumentList ( argumentList ) ;
}
2013-10-18 13:33:46 +02:00
// ino.method.MethodCall.25627.definition
public MethodCall ( int offset , int variableLength )
// ino.end
// ino.method.MethodCall.25627.body
{
super ( offset , variableLength ) ;
}
// ino.end
// ino.attribute.receiver.25639.declaration
/ * *
* Diese Variable speichert die Expression , welche die Klasse von welcher die Methode aufgerufen wird darstellt .
* /
private Receiver receiver ;
// ino.end
// ino.attribute.arglist.25642.declaration
2014-02-22 04:58:49 +01:00
private ArgumentList arglist = new ArgumentList ( ) ;
2013-10-18 13:33:46 +02:00
// ino.attribute.parserlog.25663.declaration
protected static Logger parserlog = Logger . getLogger ( " parser " ) ;
// ino.end
// ino.method.set_ArgumentList.25666.definition
public void set_ArgumentList ( ArgumentList al )
// ino.end
// ino.method.set_ArgumentList.25666.body
{
this . arglist = al ;
}
// ino.end
// ino.method.getArgumentList.25669.definition
public ArgumentList getArgumentList ( )
// ino.end
// ino.method.getArgumentList.25669.body
{
if ( this . arglist = = null ) return this . arglist = new ArgumentList ( ) ;
return this . arglist ;
}
// ino.end
// ino.method.get_Receiver.25672.definition
public Receiver get_Receiver ( )
// ino.end
// ino.method.get_Receiver.25672.body
{
return receiver ;
}
// ino.end
// ino.method.get_Name.25675.definition
public String get_Name ( )
// ino.end
// ino.method.get_Name.25675.body
{
return this . usedid . name . firstElement ( ) ;
}
// ino.end
public void set_Name ( String name ) {
this . usedid = new UsedId ( name , 0 ) ;
}
// ino.method.set_Receiver.25693.definition
public void set_Receiver ( Receiver rec )
// ino.end
// ino.method.set_Receiver.25693.body
{
receiver = rec ;
}
// ino.end
// ino.method.set_UsedId.25696.definition
public void set_UsedId ( UsedId u )
// ino.end
// ino.method.set_UsedId.25696.body
{
usedid = u ;
}
// ino.end
2015-04-22 21:40:22 +02:00
// ino.method.set_Expr_Menge.25699.definition
public void set_Expr_Menge ( Menge < Expr > v )
2013-10-18 13:33:46 +02:00
// ino.end
2015-04-22 21:40:22 +02:00
// ino.method.set_Expr_Menge.25699.body
2013-10-18 13:33:46 +02:00
{
arglist . expr = v ;
}
// ino.end
// ino.method.add_Expr.25702.definition
public void add_Expr ( Expr e )
// ino.end
// ino.method.add_Expr.25702.body
{
arglist . expr . addElement ( e ) ;
}
// ino.end
2014-09-05 11:49:31 +02:00
2013-10-18 13:33:46 +02:00
// ino.method.toString.25738.defdescription type=javadoc
/ * *
2015-05-12 19:49:27 +02:00
* < br / > Author : Martin Plà ¯  ¿  ½ micke
2013-10-18 13:33:46 +02:00
* @return
* /
// ino.end
// ino.method.toString.25738.definition
public String toString ( )
// ino.end
// ino.method.toString.25738.body
{
//return receiver/*.toString()*/ + " " + usedid.toString();
return type + " ( " + this . get_Receiver ( ) + " . " + this . get_Name ( ) + " ( " + this . getArgumentList ( ) + " )) " ;
}
// ino.end
// ino.method.wandleRefTypeAttributes2GenericAttributes.25741.definition
2015-04-22 21:40:22 +02:00
public void wandleRefTypeAttributes2GenericAttributes ( Menge < Type > paralist , Menge < GenericTypeVar > genericMethodParameters )
2013-10-18 13:33:46 +02:00
// ino.end
// ino.method.wandleRefTypeAttributes2GenericAttributes.25741.body
{
}
// ino.end
2014-09-05 11:49:31 +02:00
2013-10-18 13:33:46 +02:00
/ * *
* @author Andreas Stadelmeier , a10023
* @return der Name der Methode , welcher dieser MethodCall aufruft .
* /
public String getName ( ) {
return this . usedid . toString ( ) ;
}
/ * *
* @author AI10023 - Andreas Stadelmeier
*
2015-05-12 19:49:27 +02:00
* MÃ ¶ gliche Probleme :
2013-10-18 13:33:46 +02:00
* Wenn die Methode ohne Angabe eines Receivers im Quelltext steht :
* methodCall ( param ) ; - > ( bedeutet : ) this . methodCall ( param ) ;
2015-05-12 19:49:27 +02:00
* Parser mà ¶ glicherweise anpassen ( siehe JavaParser . jay Zeile 1858 ff )
2013-10-18 13:33:46 +02:00
* /
@Override
public ConstraintsSet TYPEExpr ( TypeAssumptions assumptions ) {
2015-05-12 19:49:27 +02:00
//Hier der Ablauf für einen Methodenaufruf:
2013-10-18 13:33:46 +02:00
ConstraintsSet ret = new ConstraintsSet ( ) ;
2015-05-12 19:49:27 +02:00
//Der Return-Type des MEthodenaufrufs ist zunächst unbekannt:
2014-02-11 16:30:38 +01:00
this . setType ( TypePlaceholder . fresh ( this ) ) ;
2013-10-18 13:33:46 +02:00
//Berechne die Constraints des Receivers
if ( receiver = = null ) {
2014-04-24 01:53:35 +02:00
receiver = new Receiver ( new This ( this ) ) ;
2013-10-18 13:33:46 +02:00
}
ret . add ( receiver . get_Expr ( ) . TYPEExpr ( assumptions ) ) ;
2015-05-12 19:49:27 +02:00
//Berechne die Constraints der Argumente aus der Argumentlist (also der Parameter, welche der Funktion übergeben wurden)
2013-10-18 13:33:46 +02:00
if ( this . arglist ! = null ) for ( Expr arg : this . arglist . expr ) {
ret . add ( arg . TYPEExpr ( assumptions ) ) ;
}
2015-05-12 19:49:27 +02:00
//Noch das Overloading-Constraint anhängen:
2015-02-26 15:50:23 +01:00
ret . add ( overloading ( assumptions ) ) ;
2013-10-18 13:33:46 +02:00
return ret ;
}
2015-02-26 15:50:23 +01:00
/ * *
2015-05-12 19:49:27 +02:00
* Erstellt die Constraints fà ¼ r den eigentlichen Methodenaufruf .
2015-02-26 15:50:23 +01:00
* Sucht in den Assumptions nach passenden Methoden und erstellt ein OderConstraintSet .
* @param assumptions
* @return
* /
2015-02-26 17:41:29 +01:00
public ConstraintsSet overloading ( TypeAssumptions assumptions ) {
2015-02-26 15:50:23 +01:00
ConstraintsSet ret = new ConstraintsSet ( ) ;
//ret.add(new Overloading(assumptions, this, this.getType()).generateConsstraints());
OderConstraint oCons = new OderConstraint ( ) ;
2015-04-22 21:40:22 +02:00
Menge < MethodAssumption > methodAssumptions = assumptions . getMethodAssumptions ( this . getName ( ) , this . getArgumentList ( ) . size ( ) ) ;
2015-02-26 15:50:23 +01:00
if ( methodAssumptions . size ( ) = = 0 ) throw new TypeinferenceException ( " Eine Methode " + this . get_Name ( ) + " ist in den Assumptions nicht vorhanden " , this ) ;
2015-05-12 19:49:27 +02:00
//Alle möglichen Methoden durchgehen:
2015-02-26 15:50:23 +01:00
for ( MethodAssumption methodAssumption : methodAssumptions ) {
2015-05-12 19:49:27 +02:00
//Constraint nicht erstellen, falls Rückgabetyp von vorne herein nicht übereinstimmt:
2015-02-26 15:50:23 +01:00
if ( ! ( this . type instanceof TypePlaceholder ) & & ! this . type . equals ( methodAssumption . getAssumedType ( ) ) ) break ;
oCons . addConstraint ( constraintsFromMethodAssumption ( methodAssumption , assumptions ) ) ;
}
2015-03-03 11:34:42 +01:00
ret . add ( oCons ) ;
2015-02-26 15:50:23 +01:00
return ret ;
}
/ * *
* Spezifikation :
* overloading determines for all possible overloadings and overridings
* of a method the constraints , where constraints itself forms
* the constraints from the receiver type , the argument types , the return
* type and a given type assumption for the method . If it is a
* method from a class , which is not the actual class ( this ) , all type
* variables are replaced by fresh type variables ( fresh ) , as different
* instances can occur . sargs determines all type assumptions of a
* method , where the argument types are supertypes of a minimal type
* assumption .
*
2015-05-12 19:49:27 +02:00
* @TODO : wenn es sich um eine Methode einer anderen Klasse handelt , mà ¼ ssen neue TPH vergeben werden und nicht die der Assumption verwendet werden .
2015-02-26 15:50:23 +01:00
*
* @return
* /
2015-02-26 17:41:29 +01:00
public UndConstraint constraintsFromMethodAssumption ( MethodAssumption methodAssumption , TypeAssumptions assumptions ) {
2015-02-26 15:50:23 +01:00
UndConstraint methodConstraint = new UndConstraint ( ) ;
2015-05-12 19:49:27 +02:00
//Ein Constraint für den ReturnType der Methode...
2015-03-03 11:34:42 +01:00
methodConstraint . addConstraint ( methodAssumption . getAssumedType ( ) . TYPE ( assumptions , this ) , this . getType ( ) . TYPE ( assumptions , this ) ) ;
2015-05-12 19:49:27 +02:00
//Ein Constraint für die Parameter der Methode...
2015-02-26 15:50:23 +01:00
for ( int i = 0 ; i < methodAssumption . getParaCount ( ) ; i + + ) {
//Type der Argument Expressions <. AssumedType der Parameter
ConstraintType ct1 = this . getArgumentList ( ) . argumentAt ( i ) . getType ( ) . TYPE ( assumptions , this ) ;
ConstraintType ct2 = methodAssumption . getParameterType ( i ) . TYPE ( assumptions , this ) ;
methodConstraint . addConstraint ( ct1 , ct2 ) ;
}
2015-05-12 19:49:27 +02:00
//Ein Constraint für den Receiver der Methode (falls vorhanden)...
2015-02-26 15:50:23 +01:00
if ( this . get_Receiver ( ) ! = null & & this . get_Receiver ( ) . get_Expr ( ) ! = null ) {
//TODO: FunN-MethodAssumption darf keine Klasse (Class) als ParentClass besitzen. Denn der Typ der Klasse steht noch nicht fest (bisher ist es immer "FunN").
methodConstraint . addConstraint ( this . get_Receiver ( ) . get_Expr ( ) . getType ( ) . TYPE ( assumptions , this ) , methodAssumption . getParentClassType ( ) . TYPE ( assumptions , this ) ) ;
}
return methodConstraint ;
}
2013-10-18 13:33:46 +02:00
/ * *
* Spezifikation :
* TYPEStmt ( Ass , stmt ) =
* let ( stmt : rty , ConS ) = TYPEExpr ( Ass , stmt )
* in ( stmt : Void , ConS )
* /
@Override
public ConstraintsSet TYPEStmt ( TypeAssumptions assumptions ) {
ConstraintsSet ret = this . TYPEExpr ( assumptions ) ; //TypeExpr aufrufen
2014-09-14 18:38:43 +02:00
this . setType ( new Void ( this , 0 ) ) ; //Typ des Statments auf Void setzen, da als alleinstehendes Statement
2013-10-18 13:33:46 +02:00
return ret ;
}
@Override
public JavaCodeResult printJavaCode ( ResultSet resultSet ) {
JavaCodeResult ret = new JavaCodeResult ( ) ;
if ( this . receiver ! = null ) ret . attach ( this . receiver . printJavaCode ( resultSet ) ) . attach ( " . " ) ;
ret . attach ( this . get_Name ( ) ) ;
ret . attach ( " ( " ) . attach ( this . getArgumentList ( ) . printJavaCode ( resultSet ) ) . attach ( " ) " ) ;
return ret . attach ( " ; " ) ;
}
2014-02-22 04:58:49 +01:00
@Override
2015-04-22 21:40:22 +02:00
public Menge < SyntaxTreeNode > getChildren ( ) {
Menge < SyntaxTreeNode > ret = new Menge < SyntaxTreeNode > ( ) ;
2014-02-22 04:58:49 +01:00
for ( Expr e : this . arglist . expr ) {
ret . add ( e ) ;
}
if ( this . receiver ! = null ) ret . add ( this . receiver . get_Expr ( ) ) ;
return ret ;
}
@Override
public void parserPostProcessing ( SyntaxTreeNode parent ) {
super . parserPostProcessing ( parent ) ;
}
2013-10-18 13:33:46 +02:00
}
// ino.end