JavaPatternMatching/src/mycompiler/mystatement/Statement.java

278 lines
8.5 KiB
Java
Raw Normal View History

2013-10-18 11:33:46 +00:00
// ino.module.Statement.8652.package
package mycompiler.mystatement;
// ino.end
// ino.module.Statement.8652.import
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.Typable;
import typinferenz.TypeAssumptions;
import mycompiler.IItemWithOffset;
import mycompiler.mybytecode.ClassFile;
import mycompiler.mybytecode.CodeAttribute;
import mycompiler.myclass.Class;
import mycompiler.myexception.CTypeReconstructionException;
import mycompiler.myexception.JVMCodeException;
import mycompiler.myexception.SCStatementException;
import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.Pair;
import mycompiler.mytype.Type;
import mycompiler.mytype.TypePlaceholder;
import mycompiler.mytypereconstruction.CSupportData;
import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;
import mycompiler.mytypereconstruction.set.CSubstitutionSet;
import mycompiler.mytypereconstruction.set.CTripleSet;
import mycompiler.mytypereconstruction.set.CTypeAssumptionSet;
import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption;
// ino.end
// ino.class.Statement.26184.declaration
public abstract class Statement implements IItemWithOffset, Typable, ITypeReplacementListener
// ino.end
// ino.class.Statement.26184.body
{
// ino.attribute.offset.26188.declaration
private int offset;
// ino.end
// ino.attribute.variableLength.26191.declaration
private int variableLength;
// ino.end
protected Type type;
// ino.method.Statement.26194.definition
public Statement(int offset, int variableLength)
// ino.end
// ino.method.Statement.26194.body
{
this.offset=offset;
this.variableLength=variableLength;
}
// ino.end
// ino.method.getOffset.26197.definition
public int getOffset()
// ino.end
// ino.method.getOffset.26197.body
{
return offset;
}
// ino.end
// ino.method.getVariableLength.26200.definition
public int getVariableLength()
// ino.end
// ino.method.getVariableLength.26200.body
{
return variableLength;
}
// ino.end
// ino.method.sc_check.26203.declaration
abstract void sc_check(Vector<Class> classlist, Hashtable ch, Hashtable<String,String> bh, boolean ext, Hashtable parach, Hashtable<String,Hashtable> parabh)
throws SCStatementException;
// ino.end
// ino.method.codegen.26206.declaration
public abstract void codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
throws JVMCodeException;
// ino.end
// ino.method.string_rec.26209.definition
static String string_rec(Hashtable ht)
// ino.end
// ino.method.string_rec.26209.body
{
String record="";
if(ht != null){
record=record.concat("[");
for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){
String s = (String)k.nextElement();
Object o = e.nextElement();
record=record.concat(" "+s);
if(o instanceof Type){
record=record.concat(" = "+((Type)o).getName());
}
else if(o instanceof Hashtable){
record=record.concat("= ");
record=record.concat(string_rec((Hashtable)o));
if(e.hasMoreElements())
record=record.concat(", ");
}
else if(o instanceof String){
record=record.concat(" = "+o);
if(e.hasMoreElements())
record=record.concat(", ");
}
else record=("[FEHLER: string_rec: unbekannter Typ!!!!!!");
}
record=record.concat("]");
}
return(record);
}
// ino.end
// ino.method.string_rec.26212.definition
static String string_rec(Vector v)
// ino.end
// ino.method.string_rec.26212.body
{
String record="";
record=record.concat("{");
for(Enumeration e=v.elements();e.hasMoreElements();){
Type t = (Type)e.nextElement();
record=record.concat(" "+t.getName());
if(e.hasMoreElements())
record=record.concat(",");
}
record=record.concat("}");
return(record);
}
// ino.end
// ino.method.string_rec.26215.definition
static String string_rec(String st, Hashtable ht)
// ino.end
// ino.method.string_rec.26215.body
{
String record="";
record=record.concat(st);
record=record.concat("[");
for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){
String s = (String)k.nextElement();
Object o = e.nextElement();
record=record.concat(" "+s);
if(o instanceof Type){
record=record.concat(" = "+((Type)o).getName());
}
else if(o instanceof Hashtable){
record=record.concat("= ");
record=record.concat(string_rec((Hashtable)o));
if(e.hasMoreElements())
record=record.concat(", ");
}
else if(o instanceof String){
record=record.concat(" = "+o);
if(e.hasMoreElements())
record=record.concat(", ");
}
else record=("[FEHLER: string_rec: unbekannter Typ!!!!!!");
}
record=record.concat("]");
return(record);
}
// ino.end
// ino.method.string_rec.26218.definition
static String string_rec(String st,Vector v)
// ino.end
// ino.method.string_rec.26218.body
{
String record=(st);
record=record.concat("{");
for(Enumeration e=v.elements();e.hasMoreElements();){
Type t = (Type)e.nextElement();
record=record.concat(" "+t.getName());
if(e.hasMoreElements())
record=record.concat(", ");
}
record=record.concat("}");
return(record);
}
// ino.end
// ino.method.TRStatement.26221.declaration
public abstract CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData)
throws CTypeReconstructionException;
// ino.end
// ino.method.wandleRefTypeAttributes2GenericAttributes.26224.declaration
public abstract void wandleRefTypeAttributes2GenericAttributes(Vector<Type> paralist, Vector<GenericTypeVar> genericMethodParameters);
// ino.end
public abstract boolean addOffsetsToStatement(CTypeAssumption localAssumption, String NameVariable, boolean isMemberVariable);
/**
* @author AI10023 - Andreas Stadelmeier
* Implementierung des Java 8 - Typinferenzalgorithmus von Martin Pl<EFBFBD>micke
* Jedes Statement wird im Zuge des Algorithmus durch die TYPEExpr-Funktion angesprochen.
*/
public abstract ConstraintsSet TYPEStmt(TypeAssumptions assumptions);
/**
* @author AI10023 - Andreas Stadelmeier
* Jedem Statement und jeder Expression wird im Zuge des Typinferenzalgorithmus eine Typvariable zugewiesen.
* Daher m<EFBFBD>ssen alle Statements und Expressions die Methoden setTypeVariable und getTypeVariable implementieren.
*/
public void setTypeVariable(Type typ){
this.setType(typ);
}
public Type getTypeVariable(){
return type;
}
/**
* @author Andreas Stadelmeier, a10023
* Sollte von jedem Statement <EFBFBD>berschrieben werden.
* Liefert Informationen zum Statment und dessen Typ.
* @return
*/
public String getTypeInformation(){
return this.printJavaCode(new ResultSet(new Vector<Pair>()))+" : "+type.toString();
}
/**
* <br/>Author: J<EFBFBD>rg B<EFBFBD>uerle
* Verschoben aus ExprStmt von Andreas Stadelmeier, a10023
* @param t
*/
public void setType(Type t)
{
if(this.getTypeVariable() instanceof TypePlaceholder){
((TypePlaceholder)this.getTypeVariable()).removeReplacementListener(this);
}
if(t instanceof TypePlaceholder){
((TypePlaceholder)t).addReplacementListener(this);
}
this.type=t;
}
public void replaceType(CReplaceTypeEvent e)
{
if(getTypeVariable() instanceof TypePlaceholder){
((TypePlaceholder)getTypeVariable()).removeReplacementListener(this);
}
this.setType(e.getNewType());
}
public abstract JavaCodeResult printJavaCode(ResultSet resultSet);
}
// ino.end