forked from JavaTX/JavaCompilerCore
263 lines
7.7 KiB
Java
Executable File
263 lines
7.7 KiB
Java
Executable File
// ino.module.Block.8625.package
|
||
package de.dhbwstuttgart.syntaxtree.statement;
|
||
// ino.end
|
||
// ino.module.Block.8625.import
|
||
import java.util.Enumeration;
|
||
import java.util.Hashtable;
|
||
import java.util.Iterator;
|
||
import de.dhbwstuttgart.typeinference.Menge;
|
||
|
||
import de.dhbwstuttgart.logger.Logger;
|
||
import de.dhbwstuttgart.logger.Section;
|
||
import de.dhbwstuttgart.bytecode.ClassFile;
|
||
import de.dhbwstuttgart.bytecode.CodeAttribute;
|
||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||
import de.dhbwstuttgart.myexception.SCExcept;
|
||
import de.dhbwstuttgart.myexception.SCStatementException;
|
||
import de.dhbwstuttgart.syntaxtree.Class;
|
||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||
import de.dhbwstuttgart.typeinference.ConstraintType;
|
||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||
|
||
|
||
|
||
|
||
// ino.class.Block.25037.declaration
|
||
public class Block extends Statement
|
||
// ino.end
|
||
// ino.class.Block.25037.body
|
||
{
|
||
|
||
// ino.method.Block.25041.definition
|
||
public Block()
|
||
// ino.end
|
||
// ino.method.Block.25041.body
|
||
{
|
||
super(-1,-1);
|
||
}
|
||
// ino.end
|
||
|
||
|
||
// ino.attribute.parserlog.25044.declaration
|
||
protected static Logger parserlog = Logger.getLogger("parser");
|
||
// ino.end
|
||
|
||
// ino.attribute.statements.25047.declaration
|
||
public Menge<Statement> statements = new Menge<Statement>();
|
||
// ino.end
|
||
|
||
|
||
//private String sc_meth_ret_type;
|
||
// ino.attribute.inferencelog.25059.decldescription type=javadoc
|
||
/**
|
||
* Logger: log4j
|
||
*/
|
||
// ino.end
|
||
// ino.attribute.inferencelog.25059.declaration
|
||
protected static Logger inferencelog = Logger.getLogger("inference");
|
||
// ino.end
|
||
protected static Logger typinferenceLog = Logger.getLogger("Typeinference");
|
||
|
||
|
||
|
||
// ino.method.get_Statement.25065.definition
|
||
public Menge<Statement> get_Statement()
|
||
// ino.end
|
||
// ino.method.get_Statement.25065.body
|
||
{
|
||
return statements;
|
||
}
|
||
// ino.end
|
||
|
||
|
||
|
||
// ino.method.set_Statement.25068.definition
|
||
public void set_Statement(Statement s)
|
||
// ino.end
|
||
// ino.method.set_Statement.25068.body
|
||
{
|
||
statements.addElement(s);
|
||
}
|
||
// ino.end
|
||
|
||
|
||
|
||
// ino.method.set_Statement_Menge.25071.definition
|
||
public void set_Statement_Menge(Menge<Statement> v)
|
||
// ino.end
|
||
// ino.method.set_Statement_Menge.25071.body
|
||
{
|
||
statements = v;
|
||
}
|
||
// ino.end
|
||
|
||
|
||
|
||
// ino.method.codegen.25074.definition
|
||
public void codegen(ClassFile classfile, CodeAttribute code, Menge paralist)
|
||
throws JVMCodeException
|
||
// ino.end
|
||
// ino.method.codegen.25074.body
|
||
{
|
||
for(int i = 0; i < statements.size(); i++)
|
||
{
|
||
statements.elementAt(i).codegen(classfile, code, paralist);
|
||
}
|
||
}
|
||
// ino.end
|
||
|
||
|
||
|
||
/////////////////////////////////////////////////////////////////////////
|
||
// TypeReconstructionAlgorithmus
|
||
/////////////////////////////////////////////////////////////////////////
|
||
|
||
|
||
|
||
// ino.method.toString.25083.defdescription type=javadoc
|
||
/**
|
||
* <br/>Author: Martin Pl<50>micke
|
||
* @return
|
||
*/
|
||
// ino.end
|
||
// ino.method.toString.25083.definition
|
||
public String toString()
|
||
// ino.end
|
||
// ino.method.toString.25083.body
|
||
{
|
||
return this.type + " { " + statements.toString();
|
||
}
|
||
// ino.end
|
||
|
||
|
||
// ino.method.wandleRefTypeAttributes2GenericAttributes.25086.defdescription type=javadoc
|
||
/**
|
||
* In allen lokalen Variablendeklarationen die "falschen" RefTypes ersetzen
|
||
* @param paralist
|
||
* @param genericMethodParameters
|
||
*/
|
||
// ino.end
|
||
// ino.method.wandleRefTypeAttributes2GenericAttributes.25086.definition
|
||
public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> paralist, Menge<GenericTypeVar> genericMethodParameters)
|
||
// ino.end
|
||
// ino.method.wandleRefTypeAttributes2GenericAttributes.25086.body
|
||
{
|
||
if(statements==null)
|
||
return;
|
||
|
||
for(int i=0;i<statements.size();i++){
|
||
statements.elementAt(i).wandleRefTypeAttributes2GenericAttributes(paralist,genericMethodParameters);
|
||
}
|
||
|
||
}
|
||
// ino.end
|
||
|
||
|
||
@Override
|
||
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
|
||
ConstraintsSet ret = new ConstraintsSet();
|
||
if(statements.size()==0)this.setType(new Void(this,0));
|
||
/* this.setTypeVariable(TypePlaceholder.fresh(this)); */
|
||
for(Statement stmt : statements){
|
||
typinferenceLog.debug("Prozessing statement: "+stmt, Section.TYPEINFERENCE);
|
||
ret.add(stmt.TYPEStmt(assumptions));
|
||
/* if((stmt instanceof Return)){
|
||
ret.add(new Constraint(stmt.getTypeVariable(), this.getTypeVariable()));//TODO: Dies nochmal prüfen.
|
||
}
|
||
*/
|
||
}
|
||
if(statements.size()>0){
|
||
Statement stmt = statements.elementAt(statements.size()-1);
|
||
typinferenceLog.debug("Prozessing statement: "+stmt, Section.TYPEINFERENCE);
|
||
this.setType(stmt.getType());
|
||
for(int i= statements.size()-2; i >= 0; i--) {
|
||
stmt = statements.elementAt(i);
|
||
typinferenceLog.debug("Prozessing statement: "+stmt, Section.TYPEINFERENCE);
|
||
if (!(stmt.getReturnType() instanceof Void))
|
||
if (this.getReturnType() instanceof Void) {
|
||
//this.setTypeVariable(stmt.getTypeVariable());
|
||
throw new TypeinferenceException("Block besitzt falschen R<>ckgabetyp (fehlendes return-stmt)", this);
|
||
}
|
||
else {
|
||
TypePlaceholder tph = TypePlaceholder.fresh(this);
|
||
ret.add(new SingleConstraint(this.getType().TYPE(assumptions, this), new ConstraintType(tph)));
|
||
ret.add(new SingleConstraint(stmt.getType().TYPE(assumptions, this), new ConstraintType(tph)));
|
||
this.setType(tph);
|
||
}
|
||
}
|
||
}else{
|
||
this.setType(new Void(this,0));
|
||
}
|
||
return ret;
|
||
}
|
||
|
||
/*
|
||
@Override
|
||
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
|
||
ConstraintsSet ret = new ConstraintsSet();
|
||
if(this.getTypeVariable()==null)this.setTypeVariable(TypePlaceholder.fresh(this));
|
||
for(Statement stmt : statements){
|
||
typinferenceLog.debug("Prozessing statement: "+stmt);
|
||
ret.add(stmt.TYPEStmt(assumptions));
|
||
if((stmt instanceof Return)){
|
||
ret.add(new Constraint(stmt.getTypeVariable(), this.getTypeVariable()));//TODO: Dies nochmal pr<70>fen.
|
||
}
|
||
}
|
||
return ret;
|
||
}
|
||
*/
|
||
|
||
@Override
|
||
public String getTypeInformation(){
|
||
String ret = "\n";
|
||
for(Statement s : this.get_Statement()){
|
||
ret += s.getTypeInformation()+"\n";
|
||
}
|
||
return ret;
|
||
}
|
||
|
||
|
||
public int getTypeLineNumber() {
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
|
||
|
||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||
JavaCodeResult ret = new JavaCodeResult().attach("{\n");
|
||
for(Statement stmt : this.get_Statement()){
|
||
ret.attach(stmt.printJavaCode(resultSet));
|
||
ret.attach((stmt instanceof ExprStmt ? ";" : "") + "\n");
|
||
}
|
||
return ret.attach("}");
|
||
|
||
}
|
||
|
||
@Override
|
||
public Menge<SyntaxTreeNode> getChildren() {
|
||
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
|
||
for(Statement st : this.get_Statement()){
|
||
ret.add(st);
|
||
}
|
||
return ret;
|
||
}
|
||
|
||
@Override
|
||
public String getDescription(){
|
||
return "Block";
|
||
}
|
||
}
|
||
// ino.end
|