JavaPatternMatching/src/mycompiler/mystatement/PreDecExpr.java

300 lines
11 KiB
Java
Raw Normal View History

2013-10-18 11:33:46 +00:00
// ino.module.PreDecExpr.8648.package
package mycompiler.mystatement;
// ino.end
// ino.module.PreDecExpr.8648.import
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import mycompiler.mybytecode.ClassFile;
import mycompiler.mybytecode.CodeAttribute;
import mycompiler.mybytecode.JVMCode;
import mycompiler.myclass.Class;
import mycompiler.myexception.CTypeReconstructionException;
import mycompiler.myexception.JVMCodeException;
import mycompiler.myexception.SCExcept;
import mycompiler.myexception.SCStatementException;
import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.Pair;
import mycompiler.mytype.RefType;
import mycompiler.mytype.Type;
import mycompiler.mytype.Void;
import mycompiler.mytypereconstruction.CSupportData;
import mycompiler.mytypereconstruction.CTriple;
import mycompiler.mytypereconstruction.set.CSubstitutionSet;
import mycompiler.mytypereconstruction.set.CTripleSet;
import mycompiler.mytypereconstruction.set.CTypeAssumptionSet;
import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption;
import mycompiler.mytypereconstruction.unify.Unify;
import org.apache.log4j.Logger;
// ino.end
import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.TypeAssumptions;
// ino.class.PreDecExpr.26055.declaration
public class PreDecExpr extends UnaryExpr
// ino.end
// ino.class.PreDecExpr.26055.body
{
// ino.method.PreDecExpr.26059.definition
public PreDecExpr(int offset,int variableLength)
// ino.end
// ino.method.PreDecExpr.26059.body
{
super(offset,variableLength);
}
// ino.end
// ino.attribute.expr.26062.declaration
public Expr expr;
// ino.end
// ino.attribute.parserlog.26065.declaration
protected static Logger parserlog = Logger.getLogger("parser");
// ino.end
// ino.method.set_Expr.26068.definition
public void set_Expr(Expr ex)
// ino.end
// ino.method.set_Expr.26068.body
{
this.expr = ex;
}
// ino.end
// ino.method.get_Name.26071.definition
public String get_Name()
// ino.end
// ino.method.get_Name.26071.body
{
return null;
}
// ino.end
// ino.method.sc_check.26074.definition
public void sc_check(Vector<Class> classname, Hashtable ch, Hashtable<String, String> bh, boolean ext, Hashtable parach, Hashtable<String, Hashtable> parabh)
throws SCStatementException
// ino.end
// ino.method.sc_check.26074.body
{
SCStatementException ex=null;
if(ext)
parserlog.debug(" ---PreDecExpr---");
try
{
expr.sc_check(classname,ch,bh,ext,parach,parabh);
this.setType(new Type(expr.getTypeName(),getOffset()));
}
catch (SCStatementException except)
{
ex=except;
}
if(this.getType()==null)
{
if(ext)
parserlog.debug("Semantik-Check hat einen Typ-Fehler gefunden!!! --- NoTypeDefError :-)");
if(ex==null)
ex=new SCStatementException();
SCExcept exc = new SCExcept();
exc.set_error("Kein Typ vorhanden - NoTypeDefError");
exc.set_statement("PostDecExpr");
ex.addException(exc);
}
else
{
if(!this.getType().getName().equals("int"))
{
if (ext)
parserlog.error("Semantik-Check hat einen Typ-Fehler gefunden!!! -- wird auf anderen Typ als int angewendet.");
SCExcept exc = new SCExcept();
exc.set_error("-- Operator wird auf "+this.getType()+" angewendet.");
exc.set_statement("PreDecExpr");
if(ex==null)
ex = new SCStatementException();
ex.addException(exc);
}
}
if(ex!=null)
throw ex;
}
// ino.end
// ino.method.codegen.26077.definition
public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
throws JVMCodeException
// ino.end
// ino.method.codegen.26077.body
{
if(expr instanceof LocalOrFieldVar) {
String local_name = (String)((LocalOrFieldVar)expr).get_Name_Vector().lastElement();
int index = code.get_indexOf_Var(local_name);
if(index != -1) {
code.add_code(JVMCode.iinc);
code.add_code_byte(index);
code.add_code_byte(-1);
}
else {
if(expr instanceof LocalOrFieldVar) {
LocalOrFieldVar local = (LocalOrFieldVar)expr;
Vector name_vector = local.get_Name_Vector();
Vector type_vector = local.get_Type_Vector();
String class_name = null;
String type = null;
for(int i=0; i < name_vector.size()-1; i++) {
local_name = (String)name_vector.elementAt(i);
type = JVMCode.get_codegen_Type((String)type_vector.elementAt(i), paralist);
index = code.get_indexOf_Var(local_name);
if(index != -1) { // LocalVar
try{
String local_type = code.get_TypeOf_Var(local_name).getName();
code.add_code(JVMCode.nload_n(local_type, index));
}
catch(JVMCodeException e) { // out of nload_n
String local_type = code.get_TypeOf_Var(local_name).getName();
code.add_code(JVMCode.nload(local_type));
code.add_code_byte((byte)index);
}
}
else { // FieldVar
code.add_code(JVMCode.aload_0);
code.add_code(JVMCode.getfield);
code.add_code_short(classfile.add_field_ref(local_name, class_name, type));
}
class_name = (String)type_vector.elementAt(i);
}
local_name = (String)name_vector.lastElement();
index = classfile.add_field_ref(local_name, class_name, JVMCode.get_codegen_Type("int", paralist));
code.add_code(JVMCode.dup);
code.add_code(JVMCode.getfield);
code.add_code_short(index);
code.add_code(JVMCode.iconst_1);
code.add_code(JVMCode.isub);
code.add_code(JVMCode.putfield);
code.add_code_short(index);
}
}
}
else if(expr instanceof InstVar) {
InstVar instvar = (InstVar)expr;
String instvar_name = instvar.get_codegen_UsedId();
int index = classfile.add_field_ref(instvar_name, null, null);
code.add_code(JVMCode.aload_0);
code.add_code(JVMCode.dup);
code.add_code(JVMCode.getfield);
code.add_code_short(index);
code.add_code(JVMCode.iconst_1);
code.add_code(JVMCode.isub);
code.add_code(JVMCode.putfield);
code.add_code_short(index);
}
else throw new JVMCodeException("JVMCodeException: PreDecExpr: void codegen(ClassFile classfile, Code_attribute code)");
}
// ino.end
// ino.method.TRExp.26080.defdescription type=javadoc
/**
* Achtung Workaround: RefType "Integer" sollte irgendwann gegen BaseType
* <code>IntegerType</code> ausgetauscht werden.
* <br/>Author: J<EFBFBD>rg B<EFBFBD>uerle
* @param sigma
* @param V
* @param supportData
* @return
*/
// ino.end
// ino.method.TRExp.26080.definition
public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData)
// ino.end
// ino.method.TRExp.26080.body
{
CTripleSet returnSet = new CTripleSet();
// --------------------------
// TRExpr f<>r Expr rufen:
// --------------------------
CTripleSet exprSet = expr.TRExp(sigma, V, supportData);
// --------------------------
// Alle Triple durchgehen:
// --------------------------
Iterator<CTriple> exprIt = exprSet.getIterator();
while(exprIt.hasNext()){
CTriple exprTriple = exprIt.next();
// --------------------------
// ReturnType mit Integer unifizieren:
// --------------------------
Vector<Vector<Pair>> unifierPossibilities = Unify.unify(exprTriple.getResultType(), new RefType("java.lang.Integer",getOffset()), supportData.getFiniteClosure());
// --------------------------
// Wenn Unifier vorhanden, dann
// anwenden und Triple hinzuf<75>gen:
// --------------------------
if(unifierPossibilities.size()!=0){
// --------------------------
// Subset bauen:
// --------------------------
CTripleSet subSet = new CTripleSet();
// --------------------------
// Alle m<>glichen Unifier anwenden:
// --------------------------
for(int i=0; i<unifierPossibilities.size(); i++){
CSubstitutionSet unifier = new CSubstitutionSet(unifierPossibilities.elementAt(i));
CTriple intTriple = exprTriple.cloneAndApplyUnify(unifier);
subSet.addElement(intTriple);
}
returnSet.unite(subSet);
}
}
if(returnSet.getCardinality()==0){
throw new CTypeReconstructionException("PreDecExpr.TRExp(): Keiner der m<>glichen Typen l<>sst sich mit Typ \"Integer\" unifizieren.",this);
}
return returnSet;
}
// ino.end
// ino.method.TRStatement.26083.definition
public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData)
// ino.end
// ino.method.TRStatement.26083.body
{
CTripleSet tripleSet = this.TRExp(sigma, V, supportData).deepCopy();
Iterator<CTriple> tripleIt = tripleSet.getIterator();
while(tripleIt.hasNext()){
tripleIt.next().setResultType(new Void(getOffset()));
}
return tripleSet;
}
// ino.end
// ino.method.wandleRefTypeAttributes2GenericAttributes.26086.definition
public void wandleRefTypeAttributes2GenericAttributes(Vector<Type> paralist, Vector<GenericTypeVar> genericMethodParameters)
// ino.end
// ino.method.wandleRefTypeAttributes2GenericAttributes.26086.body
{
}
// ino.end
public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable)
{
expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable);
}
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
// TODO Auto-generated method stub
return null;
}
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
// TODO Auto-generated method stub
return null;
}
}
// ino.end