forked from JavaTX/JavaCompilerCore
443 lines
14 KiB
Java
Executable File
443 lines
14 KiB
Java
Executable File
// ino.module.LocalVarDecl.8638.package
|
||
package de.dhbwstuttgart.syntaxtree.statement;
|
||
// ino.end
|
||
// ino.module.LocalVarDecl.8638.import
|
||
import java.util.Enumeration;
|
||
import java.util.Hashtable;
|
||
import java.util.Vector;
|
||
|
||
import org.apache.log4j.Logger;
|
||
|
||
import de.dhbwstuttgart.bytecode.ClassFile;
|
||
import de.dhbwstuttgart.bytecode.CodeAttribute;
|
||
import de.dhbwstuttgart.core.MyCompiler;
|
||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||
import de.dhbwstuttgart.myexception.SCExcept;
|
||
import de.dhbwstuttgart.myexception.SCStatementException;
|
||
import de.dhbwstuttgart.syntaxtree.Class;
|
||
import de.dhbwstuttgart.syntaxtree.ClassHelper;
|
||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
|
||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||
import de.dhbwstuttgart.typeinference.TypeInsertable;
|
||
import de.dhbwstuttgart.typeinference.assumptions.LocalVarAssumption;
|
||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
|
||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||
|
||
|
||
|
||
|
||
// ino.class.LocalVarDecl.25540.declaration
|
||
public class LocalVarDecl extends Statement implements TypeInsertable
|
||
// ino.end
|
||
// ino.class.LocalVarDecl.25540.body
|
||
{
|
||
// ino.method.LocalVarDecl.25545.definition
|
||
public LocalVarDecl(int offset,int variableLength)
|
||
// ino.end
|
||
// ino.method.LocalVarDecl.25545.body
|
||
{
|
||
super(offset,variableLength);
|
||
}
|
||
// ino.end
|
||
|
||
// ino.attribute.declid.25548.declaration
|
||
private Vector<DeclId> declid = new Vector<DeclId>();
|
||
// ino.end
|
||
// ino.attribute.paralist.25554.declaration
|
||
private Vector paralist = null;
|
||
// ino.end
|
||
// ino.attribute.parahash.25557.declaration
|
||
private Hashtable<String,Type> parahash = null;
|
||
// ino.end
|
||
// ino.attribute.inferencelog.25560.declaration
|
||
protected static Logger inferencelog = Logger.getLogger("inference");
|
||
// ino.end
|
||
// ino.attribute.parserlog.25563.declaration
|
||
protected static Logger parserlog = Logger.getLogger("parser");
|
||
// ino.end
|
||
// ino.attribute.block.25566.declaration
|
||
public Block block;
|
||
// ino.end
|
||
|
||
// ino.method.set_DeclId.25575.definition
|
||
public void set_DeclId(DeclId did)
|
||
// ino.end
|
||
// ino.method.set_DeclId.25575.body
|
||
{
|
||
this.declid.addElement(did);
|
||
}
|
||
// ino.end
|
||
|
||
// ino.method.get_Name.25578.definition
|
||
public String get_Name()
|
||
// ino.end
|
||
// ino.method.get_Name.25578.body
|
||
{
|
||
DeclId hilf;
|
||
hilf=declid.elementAt(0);
|
||
return hilf.get_Name();
|
||
}
|
||
// ino.end
|
||
// ino.method.set_ParaList.25581.definition
|
||
public void set_ParaList(Vector pl)
|
||
// ino.end
|
||
// ino.method.set_ParaList.25581.body
|
||
{
|
||
this.paralist = pl;
|
||
}
|
||
// ino.end
|
||
|
||
// ino.method.is_declared.25587.definition
|
||
public void is_declared(Type t, Vector<Class> classlist)
|
||
throws SCStatementException
|
||
// ino.end
|
||
// ino.method.is_declared.25587.body
|
||
{
|
||
boolean flag=false;
|
||
for(Enumeration<Class> e = classlist.elements();e.hasMoreElements();){
|
||
flag = false;
|
||
Class c = e.nextElement();
|
||
|
||
// System.out.println("is_init: vergleiche "+t.get_Type_()+" mit "+c.get_classname());
|
||
if(c.getName().equals(t.getName())){
|
||
// System.out.println("Klasse "+t.get_Type()+" im Vector classlist gefunden.");
|
||
flag = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if ( t instanceof RefType )
|
||
{
|
||
if(((RefType)t).get_ParaList()!=null)
|
||
{
|
||
if( ((RefType)t).get_ParaList().size()>0)
|
||
{
|
||
for(Enumeration e1 = ((RefType)t).get_ParaList().elements();e1.hasMoreElements();)
|
||
{
|
||
try
|
||
{
|
||
is_declared((Type)e1.nextElement(),classlist);
|
||
}
|
||
catch(SCStatementException ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if(!flag)
|
||
{
|
||
SCStatementException ex = new SCStatementException();
|
||
SCExcept e = new SCExcept();
|
||
e.set_error("unbekannte Klasse "+t.getName()+".");
|
||
e.set_function("complete_parahashtable() --> is_declared()");
|
||
e.set_statement(t.getName().toString());
|
||
ex.addException(e);
|
||
throw ex;
|
||
}
|
||
}
|
||
// ino.end
|
||
|
||
// ino.method.check_anz.25590.definition
|
||
public void check_anz(Type type, Vector paralist, Vector<Class> classlist)
|
||
throws SCStatementException
|
||
// ino.end
|
||
// ino.method.check_anz.25590.body
|
||
{
|
||
boolean flag = false;
|
||
for(Enumeration<Class> e2 = classlist.elements();e2.hasMoreElements();){
|
||
Class c = e2.nextElement();
|
||
// System.out.println("vergleiche "+type.get_Type_()+" mit "+c.getName());
|
||
if(c.getName().equals(type.getName())){
|
||
// System.out.println("if(c.getName().equals(type.get_Type())){");
|
||
if(c.get_ParaList().size()>0 && paralist!=null){
|
||
|
||
parserlog.debug("Type "+type.getName()+" in classlist gefunden!");
|
||
parserlog.debug("Anzahl der localvar.paralist:"+ paralist.size()+" class.paralist: (soll) "+c.get_ParaList().size());
|
||
if(paralist.size()==c.get_ParaList().size()){
|
||
|
||
for(Enumeration e3=paralist.elements();e3.hasMoreElements();){
|
||
Type t = (Type)e3.nextElement();
|
||
parserlog.debug("Type "+t.getName()+" wird gerade untersucht");
|
||
|
||
try
|
||
{
|
||
if ( t instanceof RefType )
|
||
{
|
||
check_anz(t, ((RefType)t).get_ParaList(),classlist);
|
||
}
|
||
}
|
||
catch(SCStatementException ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
flag = true;
|
||
parserlog.debug("flag gesetzt");
|
||
break;
|
||
}
|
||
else{
|
||
SCStatementException ex = new SCStatementException();
|
||
SCExcept e = new SCExcept();
|
||
e.set_error("Klasse "+c.getName()+" ist falsch parametrisiert!");
|
||
e.set_function("complete_parahashtable() --> check_anz()");
|
||
e.set_statement(type.getName().toString());
|
||
ex.addException(e);
|
||
throw ex;
|
||
}
|
||
}
|
||
else if(c.get_ParaList().size()==0 && paralist!=null){
|
||
SCStatementException ex = new SCStatementException();
|
||
SCExcept e = new SCExcept();
|
||
e.set_error("Klasse "+c.getName()+" ist nicht parametrisierbar!");
|
||
e.set_function("complete_parahashtable() --> check_anz()");
|
||
e.set_statement(type.getName().toString());
|
||
ex.addException(e);
|
||
throw ex;
|
||
}
|
||
else if(paralist==null && c.get_ParaList().size()>0){
|
||
parserlog.debug(paralist);
|
||
parserlog.debug(c.getName()+" "+c.get_ParaList().size());
|
||
SCStatementException ex = new SCStatementException();
|
||
SCExcept e = new SCExcept();
|
||
e.set_error("Klasse "+c.getName()+" <20>berhaupt garnicht parametrisiert!");
|
||
e.set_function("complete_parahashtable() --> check_anz()");
|
||
e.set_statement(type.getName().toString());
|
||
ex.addException(e);
|
||
throw ex;
|
||
|
||
}
|
||
else{
|
||
flag = true;
|
||
parserlog.debug(type.getName()+" nicht parametrisierbar");
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if(!flag)
|
||
{
|
||
SCStatementException ex = new SCStatementException();
|
||
SCExcept e = new SCExcept();
|
||
if ( type instanceof RefType )
|
||
{
|
||
e.set_error("Type " + type.getName()+ " falsche Parameter-Anzahl " + ((RefType)type).get_ParaList().size());
|
||
}
|
||
e.set_function("complete_parahashtable() --> check_anz()");
|
||
e.set_statement(type.getName().toString());
|
||
ex.addException(e);
|
||
throw ex;
|
||
}
|
||
|
||
}
|
||
// ino.end
|
||
|
||
|
||
|
||
|
||
|
||
// ino.method.codegen.25593.definition
|
||
public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
|
||
throws JVMCodeException
|
||
// ino.end
|
||
// ino.method.codegen.25593.body
|
||
{
|
||
if(declid != null)
|
||
for(int i = 0; i < declid.size(); i++)
|
||
declid.elementAt(i).codegen_LocalVarDecl(classfile, code, this.getType(), paralist);
|
||
}
|
||
// ino.end
|
||
// ino.method.getDeclidVector.25596.definition
|
||
public Vector<DeclId> getDeclidVector()
|
||
// ino.end
|
||
// ino.method.getDeclidVector.25596.body
|
||
{
|
||
return declid;
|
||
}
|
||
// ino.end
|
||
// ino.method.setDeclidVector.25599.definition
|
||
public void setDeclidVector(Vector<DeclId> declid)
|
||
// ino.end
|
||
// ino.method.setDeclidVector.25599.body
|
||
{
|
||
this.declid = declid;
|
||
}
|
||
// ino.end
|
||
|
||
// ino.method.getLineNumber.25602.defdescription type=javadoc
|
||
/**
|
||
* <br/>Author: J<>rg B<>uerle
|
||
* @return
|
||
*/
|
||
// ino.end
|
||
// ino.method.getLineNumber.25602.definition
|
||
public int getLineNumber()
|
||
// ino.end
|
||
// ino.method.getLineNumber.25602.body
|
||
{
|
||
if(declid.size()<=0)
|
||
return MyCompiler.NO_LINENUMBER;
|
||
else{
|
||
return declid.elementAt(0).getLineNumber();
|
||
}
|
||
}
|
||
// ino.end
|
||
|
||
// ino.method.getOffset.25605.defdescription type=javadoc
|
||
/**
|
||
* <br/>Author: Thomas Hornberger
|
||
* @return
|
||
*/
|
||
// ino.end
|
||
// ino.method.getOffset.25605.definition
|
||
public int getOffset()
|
||
// ino.end
|
||
// ino.method.getOffset.25605.body
|
||
{
|
||
if(declid.size()<=0)
|
||
return MyCompiler.NO_LINENUMBER;
|
||
else{
|
||
return declid.elementAt(0).getOffset();
|
||
}
|
||
}
|
||
// ino.end
|
||
|
||
|
||
|
||
// ino.method.getTypeLineNumber.25611.defdescription type=javadoc
|
||
/**
|
||
* <br>Author: J<>rg B<>uerle
|
||
* @return
|
||
*/
|
||
// ino.end
|
||
// ino.method.getTypeLineNumber.25611.definition
|
||
public int getTypeLineNumber()
|
||
// ino.end
|
||
// ino.method.getTypeLineNumber.25611.body
|
||
{
|
||
return this.getLineNumber();
|
||
}
|
||
// ino.end
|
||
|
||
|
||
// ino.method.toString.25617.defdescription type=javadoc
|
||
/**
|
||
* <br/>Author: Martin Pl<50>micke
|
||
* @return
|
||
*/
|
||
// ino.end
|
||
// ino.method.toString.25617.definition
|
||
public String toString()
|
||
// ino.end
|
||
// ino.method.toString.25617.body
|
||
{
|
||
if(this.getType() == null)return "no type " + declid.toString();
|
||
return this.getType().toString() + " " + declid.toString();
|
||
}
|
||
// ino.end
|
||
// ino.method.wandleRefTypeAttributes2GenericAttributes.25620.definition
|
||
public void wandleRefTypeAttributes2GenericAttributes(Vector<Type> paralist, Vector<GenericTypeVar> genericMethodParameters)
|
||
// ino.end
|
||
// ino.method.wandleRefTypeAttributes2GenericAttributes.25620.body
|
||
{
|
||
|
||
Type fpType=getType();
|
||
// Nur wenn es sich um ein RefType-Field handelt
|
||
Type pendantPara = null;
|
||
if(fpType instanceof RefType)
|
||
pendantPara = ((RefType)fpType).findGenericType(paralist, new Vector<GenericTypeVar>());
|
||
//GenericTypeVar pendantPara=ClassHelper.findGenericType(fpType,paralist,genericMethodParameters);
|
||
if(pendantPara!=null){ //Wenn generisch, dann modifizieren
|
||
setType(pendantPara);
|
||
}
|
||
|
||
|
||
}
|
||
// ino.end
|
||
|
||
|
||
/**
|
||
* @author Andreas Stadelmeier, a10023
|
||
* Der Typ der Variablendeklaration wird den Assumptions angef<65>gt.
|
||
* Bei einer Deklaration ohne Typangabe wird ein TypePlaceholder den Assumptions hinzugef<65>gt.
|
||
*/
|
||
@Override
|
||
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
|
||
ConstraintsSet ret = new ConstraintsSet();
|
||
if((this.getType() instanceof RefType)){
|
||
Type replaceType = null;
|
||
replaceType = assumptions.checkType((RefType)this.getType(), this);
|
||
this.setType(replaceType);
|
||
}
|
||
assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird.
|
||
ret.add(new SingleConstraint(this.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
|
||
//assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden.
|
||
this.setReturnType(new Void(this,0)); //Return typ einer Variablendeklaration ist Void
|
||
return ret;
|
||
}
|
||
|
||
@Override
|
||
public String getDescription() {
|
||
if(this.getType() == null)return "no type " + declid.toString();
|
||
if(this.getType() instanceof TypePlaceholder)return declid.toString();
|
||
return this.getType().toString() + " " + declid.toString();
|
||
}
|
||
|
||
@Override
|
||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||
super.parserPostProcessing(parent);
|
||
if(this.getType()==null || this.getType() instanceof TypePlaceholder)this.setType(TypePlaceholder.fresh(this));
|
||
}
|
||
|
||
@Override
|
||
public String getTypeInformation(){
|
||
String ret = "VarDeclaration ";
|
||
if(this.getType()!=null)ret+= this.getType().toString()+" ";
|
||
ret+=this.get_Name();
|
||
return ret;
|
||
}
|
||
|
||
@Override
|
||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||
JavaCodeResult ret = new JavaCodeResult();
|
||
if(this.getType()!=null)ret.attach(getType().printJavaCode(resultSet)).attach(" ");
|
||
ret.attach(this.get_Name()+";");
|
||
return ret;}
|
||
|
||
@Override
|
||
public void setOffset(int offset) {
|
||
this.offset = offset;
|
||
}
|
||
|
||
@Override
|
||
public String getIdentifier() {
|
||
return this.get_Name();
|
||
}
|
||
|
||
@Override
|
||
public Vector<SyntaxTreeNode> getChildren() {
|
||
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
|
||
if(this.getType()!=null)ret.add(this.getType());
|
||
return ret;
|
||
}
|
||
|
||
@Override
|
||
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
|
||
ResultSet resultSet) {
|
||
return new TypeInsertPoint(this, this, resultSet.getTypeEqualTo(tph),resultSet);
|
||
}
|
||
}
|
||
// ino.end
|