forked from JavaTX/JavaCompilerCore
252 lines
8.5 KiB
Java
252 lines
8.5 KiB
Java
|
// ino.module.NegativeExpr.8640.package
|
|||
|
package mycompiler.mystatement;
|
|||
|
// ino.end
|
|||
|
// ino.module.NegativeExpr.8640.import
|
|||
|
import java.util.Hashtable;
|
|||
|
import java.util.Iterator;
|
|||
|
import java.util.Vector;
|
|||
|
import mycompiler.mybytecode.ClassFile;
|
|||
|
import mycompiler.mybytecode.CodeAttribute;
|
|||
|
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.NegativeExpr.25744.declaration
|
|||
|
public class NegativeExpr extends UnaryExpr
|
|||
|
// ino.end
|
|||
|
// ino.class.NegativeExpr.25744.body
|
|||
|
{
|
|||
|
// ino.method.NegativeExpr.25748.definition
|
|||
|
public NegativeExpr(int offset,int variableLength)
|
|||
|
// ino.end
|
|||
|
// ino.method.NegativeExpr.25748.body
|
|||
|
{
|
|||
|
super(offset,variableLength);
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
// ino.attribute.neg.25751.declaration
|
|||
|
private UnaryMinus neg;
|
|||
|
// ino.end
|
|||
|
// ino.attribute.expr.25754.declaration
|
|||
|
public Expr expr;
|
|||
|
// ino.end
|
|||
|
// ino.attribute.parserlog.25757.declaration
|
|||
|
protected static Logger parserlog = Logger.getLogger("parser");
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.get_Name.25760.definition
|
|||
|
public String get_Name()
|
|||
|
// ino.end
|
|||
|
// ino.method.get_Name.25760.body
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.sc_check.25763.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.25763.body
|
|||
|
{
|
|||
|
if(ext)
|
|||
|
parserlog.debug(" ---NegativeExpr---");
|
|||
|
SCStatementException except=null;
|
|||
|
String type = this.expr.getTypeName();
|
|||
|
try
|
|||
|
{
|
|||
|
this.expr.sc_check(classname,ch,bh,ext, parach, parabh);
|
|||
|
}
|
|||
|
catch(SCStatementException ex)
|
|||
|
{
|
|||
|
except=ex;
|
|||
|
}
|
|||
|
if(type != "int" || type != "boolean")
|
|||
|
{
|
|||
|
if(ext)
|
|||
|
parserlog.warn("Warnung -- Typfehler!! Moeglicher Datenverlust --> NegativeExpr.sc_check()");
|
|||
|
SCExcept neu=new SCExcept();
|
|||
|
neu.set_error("Typfehler");
|
|||
|
neu.set_statement("NegativeExpr");
|
|||
|
if(except==null)
|
|||
|
except=new SCStatementException();
|
|||
|
except.addException(neu);
|
|||
|
}
|
|||
|
if(except!=null)
|
|||
|
throw except;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.set_UnaryMinus.25766.definition
|
|||
|
public void set_UnaryMinus(UnaryMinus umin)
|
|||
|
// ino.end
|
|||
|
// ino.method.set_UnaryMinus.25766.body
|
|||
|
{
|
|||
|
this.neg = umin;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.set_Expr.25769.definition
|
|||
|
public void set_Expr(Expr ex)
|
|||
|
// ino.end
|
|||
|
// ino.method.set_Expr.25769.body
|
|||
|
{
|
|||
|
this.expr = ex;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.codegen.25772.definition
|
|||
|
public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
|
|||
|
throws JVMCodeException
|
|||
|
// ino.end
|
|||
|
// ino.method.codegen.25772.body
|
|||
|
{
|
|||
|
if(expr instanceof Binary) ((Binary)expr).neg_codegen(classfile, code, paralist);
|
|||
|
else if(expr instanceof NegativeExpr) ((NegativeExpr)expr).neg_codegen(classfile, code, paralist);
|
|||
|
else {
|
|||
|
expr.codegen(classfile, code, paralist);
|
|||
|
neg.codegen(classfile, code, expr.getTypeName(), true);
|
|||
|
}
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.neg_codegen.25775.definition
|
|||
|
public void neg_codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
|
|||
|
throws JVMCodeException
|
|||
|
// ino.end
|
|||
|
// ino.method.neg_codegen.25775.body
|
|||
|
{
|
|||
|
if(expr instanceof Binary) ((Binary)expr).codegen(classfile, code, paralist);
|
|||
|
else if(expr instanceof NegativeExpr) ((NegativeExpr)expr).codegen(classfile, code, paralist);
|
|||
|
else {
|
|||
|
expr.codegen(classfile, code, paralist);
|
|||
|
neg.codegen(classfile, code, expr.getTypeName(), false);
|
|||
|
}
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.TRExp.25778.defdescription type=javadoc
|
|||
|
/**
|
|||
|
* Implementierung des Algorithmus 5.41 von Martin Pl<EFBFBD>micke
|
|||
|
* <br/>Achtung Workaround: Wenn die BaseTypes endlich korrekt implementiert sind,
|
|||
|
* dann sollte der RefType "Integer" <EFBFBD>berall durch den BaseType "IntegerType"
|
|||
|
* ersetzt werden!!! <br>Author: J<EFBFBD>rg B<EFBFBD>uerle
|
|||
|
* @param sigma
|
|||
|
* @param V
|
|||
|
* @param supportData
|
|||
|
* @return
|
|||
|
*/
|
|||
|
// ino.end
|
|||
|
// ino.method.TRExp.25778.definition
|
|||
|
public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData)
|
|||
|
// ino.end
|
|||
|
// ino.method.TRExp.25778.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("NegativeExpr.TRExp(): Keiner der m<>glichen Typen l<>sst sich mit Typ \"Integer\" unifizieren.",this);
|
|||
|
}
|
|||
|
return returnSet;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
|
|||
|
// ino.method.TRStatement.25781.definition
|
|||
|
public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData)
|
|||
|
// ino.end
|
|||
|
// ino.method.TRStatement.25781.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.25784.definition
|
|||
|
public void wandleRefTypeAttributes2GenericAttributes(Vector<Type> paralist, Vector<GenericTypeVar> genericMethodParameters)
|
|||
|
// ino.end
|
|||
|
// ino.method.wandleRefTypeAttributes2GenericAttributes.25784.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
|