forked from JavaTX/JavaCompilerCore
323 lines
12 KiB
Java
323 lines
12 KiB
Java
|
// ino.module.Interface.8582.package
|
|||
|
package mycompiler.myinterface;
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.module.Interface.8582.import
|
|||
|
import java.util.Vector;
|
|||
|
import mycompiler.AClassOrInterface;
|
|||
|
import mycompiler.mybytecode.ClassFile;
|
|||
|
import mycompiler.myclass.ClassHelper;
|
|||
|
import mycompiler.myclass.Constant;
|
|||
|
import mycompiler.myclass.FormalParameter;
|
|||
|
import mycompiler.myclass.Method;
|
|||
|
import mycompiler.myclass.ParameterList;
|
|||
|
import mycompiler.myexception.JVMCodeException;
|
|||
|
import mycompiler.mymodifier.Modifiers;
|
|||
|
import mycompiler.mytype.GenericTypeVar;
|
|||
|
import mycompiler.mytype.RefType;
|
|||
|
import mycompiler.mytype.Type;
|
|||
|
import mycompiler.mytypereconstruction.CIntersectionType;
|
|||
|
import mycompiler.mytypereconstruction.CTypeReconstructionResult;
|
|||
|
import mycompiler.mytypereconstruction.set.CTypeAssumptionSet;
|
|||
|
import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption;
|
|||
|
import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption;
|
|||
|
import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption;
|
|||
|
import mycompiler.SourceFile;
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.class.Interface.23932.description type=javadoc
|
|||
|
/**
|
|||
|
* Die Klasse stellt die Definition eines Interfaces dar.
|
|||
|
* @author SCJU
|
|||
|
*
|
|||
|
*/
|
|||
|
// ino.end
|
|||
|
// ino.class.Interface.23932.declaration
|
|||
|
public class Interface extends AClassOrInterface
|
|||
|
// ino.end
|
|||
|
// ino.class.Interface.23932.body
|
|||
|
{
|
|||
|
|
|||
|
// ino.attribute.ib.23936.declaration
|
|||
|
private InterfaceBody ib;
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.attribute.paralist.23939.decldescription type=line
|
|||
|
// HOTI 29. Apr 06
|
|||
|
// ino.end
|
|||
|
// ino.attribute.paralist.23939.declaration
|
|||
|
private Vector<Type> paralist = new Vector<Type>(); // Parameterliste 'interface xy<para1, para2,...>{}' wird gespeichert
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.attribute.containedTypes.23942.declaration
|
|||
|
private Vector<Type> containedTypes;
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.Interface.23945.defdescription type=line
|
|||
|
// Konstruktoren
|
|||
|
// ino.end
|
|||
|
// ino.method.Interface.23945.definition
|
|||
|
public Interface()
|
|||
|
// ino.end
|
|||
|
// ino.method.Interface.23945.body
|
|||
|
{
|
|||
|
super();
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.Interface.23948.definition
|
|||
|
public Interface(String name)
|
|||
|
// ino.end
|
|||
|
// ino.method.Interface.23948.body
|
|||
|
{
|
|||
|
super(name);
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.Interface.23951.definition
|
|||
|
public Interface(String name, Modifiers mod)
|
|||
|
// ino.end
|
|||
|
// ino.method.Interface.23951.body
|
|||
|
{
|
|||
|
super(name, mod);
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
|
|||
|
// ino.method.getParaList.23954.defdescription type=block
|
|||
|
/*public Vector<Type> complete_paralist(boolean ext)
|
|||
|
{
|
|||
|
|
|||
|
Diese Funktion vervollt<EFBFBD>ndigt die Parameterliste f<EFBFBD>r vererbte Klassen
|
|||
|
Vector<Type> child = paralist;
|
|||
|
|
|||
|
paralist = (Vector<Type>)superclassid.get_ParaList();
|
|||
|
|
|||
|
for(Enumeration<Type> e = child.elements();e.hasMoreElements();){
|
|||
|
paralist.addElement(e.nextElement());
|
|||
|
}
|
|||
|
|
|||
|
return this.paralist;
|
|||
|
}*/
|
|||
|
// ino.end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// ino.method.getParaList.23954.definition
|
|||
|
public Vector<Type> getParaList()
|
|||
|
// ino.end
|
|||
|
// ino.method.getParaList.23954.body
|
|||
|
{
|
|||
|
return this.paralist;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
// ino.method.setParaList.23957.definition
|
|||
|
public void setParaList(Vector<Type> paralist)
|
|||
|
// ino.end
|
|||
|
// ino.method.setParaList.23957.body
|
|||
|
{
|
|||
|
this.paralist=paralist;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
// ino.method.setContainedTypes.23960.definition
|
|||
|
public void setContainedTypes(Vector<Type> containedTypes)
|
|||
|
// ino.end
|
|||
|
// ino.method.setContainedTypes.23960.body
|
|||
|
{
|
|||
|
this.containedTypes = containedTypes;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.getContainedTypes.23963.definition
|
|||
|
public Vector<Type> getContainedTypes()
|
|||
|
// ino.end
|
|||
|
// ino.method.getContainedTypes.23963.body
|
|||
|
{
|
|||
|
return containedTypes;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.codegen.23966.definition
|
|||
|
public void codegen(SourceFile sf)
|
|||
|
throws JVMCodeException
|
|||
|
// ino.end
|
|||
|
// ino.method.codegen.23966.body
|
|||
|
{
|
|||
|
codegenlog.info("Definierte Superinterfaces: " + getSuperInterfaces().size());
|
|||
|
codegenlog.debug("Liste der Interfaces: " + getSuperInterfaces().toString());
|
|||
|
codegenlog.info("Definierte Konstanten: " + ib.getConstantVektor().size());
|
|||
|
codegenlog.info("Definierte Methoden: " + ib.getMethodVektor().size());
|
|||
|
|
|||
|
// Erzeugen einer Classfile auf Basis des Interfaces
|
|||
|
ClassFile classfile = new ClassFile(this, sf);
|
|||
|
|
|||
|
// Handling fuer Generics
|
|||
|
classfile.addGenerics(paralist, null, getSuperInterfaces());
|
|||
|
|
|||
|
// Handling fuer Superinterfaces
|
|||
|
classfile.addSuperInterfaces(getSuperInterfaces());
|
|||
|
|
|||
|
// Codegen fuer Interface-Body
|
|||
|
Vector<Type> paralist = new Vector<Type>();
|
|||
|
if(ib != null) ib.codegen(classfile, paralist);
|
|||
|
|
|||
|
classfile.codegen();
|
|||
|
|
|||
|
codegenlog.info("Compilierung erfolgreich abgeschlossen, "+ getName() + ".class erstellt.");
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.getInterfaceBody.23969.definition
|
|||
|
public InterfaceBody getInterfaceBody()
|
|||
|
// ino.end
|
|||
|
// ino.method.getInterfaceBody.23969.body
|
|||
|
{
|
|||
|
return ib;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.setInterfaceBody.23972.definition
|
|||
|
public void setInterfaceBody(InterfaceBody ib)
|
|||
|
// ino.end
|
|||
|
// ino.method.setInterfaceBody.23972.body
|
|||
|
{
|
|||
|
this.ib = ib;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.addThisToAssumptions.23975.definition
|
|||
|
public void addThisToAssumptions(CTypeReconstructionResult assumption)
|
|||
|
// ino.end
|
|||
|
// ino.method.addThisToAssumptions.23975.body
|
|||
|
{
|
|||
|
assumption.addClassName(getName());
|
|||
|
|
|||
|
InterfaceBody body = getInterfaceBody();
|
|||
|
if(body!=null){
|
|||
|
|
|||
|
Vector<GenericTypeVar> genericsList = new Vector<GenericTypeVar>();
|
|||
|
if(getParaList()!=null){
|
|||
|
for(int ii =0; ii<this.getParaList().size(); ii++){
|
|||
|
Type para = (Type)this.getParaList().elementAt(ii);
|
|||
|
if(para instanceof GenericTypeVar){
|
|||
|
genericsList.addElement((GenericTypeVar)para);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
assumption.addGenericTypeVars(this.getName(),genericsList);
|
|||
|
|
|||
|
// Konstanten in die Assumptions laden
|
|||
|
if(body.getConstantVektor()!=null){
|
|||
|
for(int cID=0;cID<body.getConstantVektor().size();cID++){
|
|||
|
Constant constant=body.getConstantVektor().elementAt(cID);
|
|||
|
CInstVarTypeAssumption assum = new CInstVarTypeAssumption(this.getName(), constant.getName(), constant.getType(), constant.getLineNumber(),constant.getOffset(),new Vector<Integer>()); // Typannahme bauen...
|
|||
|
assumption.addFieldOrLocalVarAssumption(assum);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
CTypeAssumptionSet V_fields_methods = new CTypeAssumptionSet();
|
|||
|
|
|||
|
// Methoden in V_fields_methods laden
|
|||
|
if(body.getMethodVektor()!=null){
|
|||
|
Vector<CMethodTypeAssumption> methodAssumptions=new Vector<CMethodTypeAssumption>();
|
|||
|
|
|||
|
for(int mID=0;mID<body.getMethodVektor().size();mID++){
|
|||
|
Method method=body.getMethodVektor().elementAt(mID);
|
|||
|
// FIXME HOTI Hier mit Thomas abklaeren, ob die Offsets geladen werden muessen
|
|||
|
CMethodTypeAssumption methodAssum = new CMethodTypeAssumption(new RefType(this.getName(),method.getGenericMethodParameters(), 0), method.get_Method_Name(), method.getReturnType(), method.getParameterCount(),method.getLineNumber(),method.getOffset(),new Vector<Integer>(),method.getGenericMethodParameters()); // Typannahme bauen...
|
|||
|
V_fields_methods.addElement(methodAssum);
|
|||
|
method.setOverloadedID(methodAssum.getHashSetKey().getOverloadedMethodID());
|
|||
|
|
|||
|
// Parameter hinzufuegen
|
|||
|
|
|||
|
ParameterList parameterList = method.getParameterList();
|
|||
|
if(parameterList!=null){
|
|||
|
for(int i=0; i<parameterList.sc_get_Formalparalist().size(); i++){
|
|||
|
FormalParameter para = parameterList.sc_get_Formalparalist().elementAt(i);
|
|||
|
// F<>r V_fields_methods:
|
|||
|
CParaTypeAssumption paraAssum = new CParaTypeAssumption(this.getName(), method.get_Method_Name(), method.getParameterCount(), method.getOverloadedID(),para.get_Name(), para.getType(), para.getLineNumber(),para.getOffset(),new Vector<Integer>());
|
|||
|
// FIXME HOTI Mit Thomas abkl<6B>ren, was hier getan werden muss!
|
|||
|
//Class.addOffsetsToAssumption(paraAssum,method.get_Block(),paraAssum.getIdentifier(),true);
|
|||
|
methodAssum.addParaAssumption(paraAssum);
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
methodAssumptions.add(methodAssum);
|
|||
|
|
|||
|
}
|
|||
|
// Aus den V_fields_methods die Methoden in die BasicAssumption legen
|
|||
|
for(int i=0;i<methodAssumptions.size();i++){
|
|||
|
CIntersectionType mISType=new CIntersectionType(methodAssumptions.get(i));
|
|||
|
assumption.addMethodIntersectionType(mISType);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
// ino.method.isAGenericType.23978.definition
|
|||
|
public boolean isAGenericType(RefType type)
|
|||
|
// ino.end
|
|||
|
// ino.method.isAGenericType.23978.body
|
|||
|
{
|
|||
|
if(paralist==null)
|
|||
|
return false;
|
|||
|
|
|||
|
for(int i=0;i<paralist.size();i++){
|
|||
|
if(paralist.get(i) instanceof GenericTypeVar){
|
|||
|
GenericTypeVar gtv=(GenericTypeVar)paralist.get(i);
|
|||
|
if(gtv.getName().equals(type.getName())){
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return(false);
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
// ino.method.wandleRefTypeAttributes2GenericAttributes.23981.defdescription type=javadoc
|
|||
|
/**
|
|||
|
* Alle RefTypes, die hier im Interface definiert sind
|
|||
|
* bspw: E doSomething()
|
|||
|
* und eigentlich Generics sind werden zu generics gewandelt
|
|||
|
*
|
|||
|
*/
|
|||
|
// ino.end
|
|||
|
// ino.method.wandleRefTypeAttributes2GenericAttributes.23981.definition
|
|||
|
public void wandleRefTypeAttributes2GenericAttributes()
|
|||
|
// ino.end
|
|||
|
// ino.method.wandleRefTypeAttributes2GenericAttributes.23981.body
|
|||
|
{
|
|||
|
if(ib==null)
|
|||
|
return;
|
|||
|
|
|||
|
Vector<Method> methods=ib.MethodVektor;
|
|||
|
|
|||
|
// Alle Methoden durchgehen
|
|||
|
for(int i=0;i<methods.size();i++){
|
|||
|
|
|||
|
Method method=methods.get(i);
|
|||
|
method.wandleRefTypeAttributes2GenericAttributes(paralist);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
for(int i=0;i<ib.ConstantVektor.size();i++){
|
|||
|
Constant instVar=(Constant)ib.ConstantVektor.get(i);
|
|||
|
Type type=instVar.getType();
|
|||
|
// Nur wenn es sich um ein RefType-Field handelt
|
|||
|
if(type instanceof RefType){
|
|||
|
GenericTypeVar pendant=ClassHelper.findGenericType(type,paralist,null);
|
|||
|
if(pendant!=null){ //Wenn generisch, dann modifizieren
|
|||
|
instVar.setType(pendant);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
}
|
|||
|
// ino.end
|