forked from JavaTX/JavaCompilerCore
525 lines
17 KiB
Java
Executable File
525 lines
17 KiB
Java
Executable File
// ino.module.LocalVarDecl.8638.package
|
||
package mycompiler.mystatement;
|
||
// ino.end
|
||
// ino.module.LocalVarDecl.8638.import
|
||
import java.util.Enumeration;
|
||
import java.util.Hashtable;
|
||
import java.util.Vector;
|
||
|
||
import mycompiler.mybytecode.ClassFile;
|
||
import mycompiler.mybytecode.CodeAttribute;
|
||
import mycompiler.myclass.Class;
|
||
import mycompiler.myclass.ClassHelper;
|
||
import mycompiler.myclass.DeclId;
|
||
import mycompiler.MyCompiler;
|
||
import mycompiler.SyntaxTreeNode;
|
||
import mycompiler.myexception.JVMCodeException;
|
||
import mycompiler.myexception.SCExcept;
|
||
import mycompiler.myexception.SCStatementException;
|
||
import mycompiler.mytype.GenericTypeVar;
|
||
import mycompiler.mytype.RefType;
|
||
import mycompiler.mytype.Type;
|
||
import mycompiler.mytype.TypePlaceholder;
|
||
import mycompiler.mytype.Void;
|
||
import mycompiler.mytypereconstruction.CSupportData;
|
||
import mycompiler.mytypereconstruction.CTriple;
|
||
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.CLocalVarTypeAssumption;
|
||
import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption;
|
||
|
||
import org.apache.log4j.Logger;
|
||
// ino.end
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
import typinferenz.ConstraintsSet;
|
||
import typinferenz.FreshTypeVariable;
|
||
import typinferenz.JavaCodeResult;
|
||
import typinferenz.ResultSet;
|
||
import typinferenz.TypeInsertPoint;
|
||
import typinferenz.TypeInsertable;
|
||
import typinferenz.assumptions.LocalVarAssumption;
|
||
import typinferenz.assumptions.TypeAssumptions;
|
||
import typinferenz.exceptions.TypeinferenceException;
|
||
|
||
|
||
|
||
|
||
// 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());
|
||
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());
|
||
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());
|
||
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());
|
||
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());
|
||
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.replaceType.25608.defdescription type=javadoc
|
||
/**
|
||
* <br>Author: J<>rg B<>uerle
|
||
* @param e
|
||
*/
|
||
// ino.end
|
||
// ino.method.replaceType.25608.definition
|
||
public void replaceType(CReplaceTypeEvent e)
|
||
// ino.end
|
||
// ino.method.replaceType.25608.body
|
||
{
|
||
if(e.getOldType().equals(this.getType())){
|
||
inferencelog.debug("Ersetze Typ in LocalVarDecl \""+this.get_Name()+"\"\n");
|
||
if(getType() instanceof TypePlaceholder){
|
||
((TypePlaceholder)getType()).removeReplacementListener(this);
|
||
}
|
||
this.setType(e.getNewType());
|
||
}
|
||
if(e.getOldType().equals(this.getType())){
|
||
inferencelog.debug("Ersetze Typ in LocalVarDecl \""+this.get_Name()+"\"\n");
|
||
if(this.getType() instanceof TypePlaceholder){
|
||
((TypePlaceholder)this.getType()).removeReplacementListener(this);
|
||
}
|
||
this.setType(e.getNewType());
|
||
}
|
||
}
|
||
// 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.TRStatement.25614.defdescription type=javadoc
|
||
/**
|
||
* Implementierung des Algorithmus 5.24 von Martin Pl<50>micke
|
||
* <br>Author: J<>rg B<>uerle
|
||
* @param sigma
|
||
* @param V
|
||
* @param supportData
|
||
* @return
|
||
*/
|
||
// ino.end
|
||
// ino.method.TRStatement.25614.definition
|
||
public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData)
|
||
// ino.end
|
||
// ino.method.TRStatement.25614.body
|
||
{
|
||
CTripleSet resultSet = new CTripleSet();
|
||
V = V.shallowCopy();
|
||
CTypeAssumptionSet localSet = new CTypeAssumptionSet();
|
||
CLocalVarTypeAssumption varAssum = new CLocalVarTypeAssumption(supportData.getCurrentClass(), supportData.getCurrentMethod(), supportData.getCurrentMethodParaCount(), supportData.getCurrentMethodOverloadedID(), supportData.getCurrentBlockId(), this.get_Name() ,this.getType(), this.getLineNumber(),this.getOffset(),new Vector<Integer>());
|
||
Class.isFirstLocalVarDecl=true;
|
||
|
||
if(this.block != null)
|
||
this.block.addOffsetsToAssumption(varAssum,this.get_Name(),false);//hinzugef<65>gt hoth: 07.04.2006
|
||
|
||
localSet.addElement(varAssum);
|
||
V.unite(localSet);
|
||
resultSet.addElement(new CTriple(sigma, new Void(getOffset()), V));
|
||
return resultSet;
|
||
}
|
||
// 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
|
||
|
||
public boolean addOffsetsToStatement(CTypeAssumption localAssumption, String NameVariable, boolean isMemberVariable)
|
||
{
|
||
isMemberVariable=true;//hoth 02.05.06
|
||
if(isMemberVariable)//Wenn Objektvariable
|
||
{
|
||
if(this.get_Name().equals(NameVariable))
|
||
{
|
||
if(Class.isFirstLocalVarDecl==false)
|
||
{return false;}//Wenn jetzt lokale Variable kommt, dann springe raus
|
||
else
|
||
{Class.isFirstLocalVarDecl=false;}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* @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.getTypeFor((RefType)this.getType());
|
||
if(replaceType == null)
|
||
throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this);
|
||
this.setType(replaceType);
|
||
}
|
||
assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird.
|
||
//assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden.
|
||
this.setType(new Void(0)); //Return typ einer Variablendeklaration ist Void
|
||
return ret;
|
||
}
|
||
|
||
@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>();
|
||
return ret;
|
||
}
|
||
|
||
@Override
|
||
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
|
||
ResultSet resultSet) {
|
||
return new TypeInsertPoint(this, resultSet.getTypeEqualTo(tph),resultSet);
|
||
}
|
||
}
|
||
// ino.end
|