JavaPatternMatching/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java
2016-08-17 00:45:14 +02:00

181 lines
5.7 KiB
Java
Executable File

// ino.module.LocalOrFieldVar.8637.package
package de.dhbwstuttgart.syntaxtree.statement;
// ino.end
// ino.module.LocalOrFieldVar.8637.import
import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.bcel.Constants;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.Instruction;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.LocalVariableInstruction;
import org.apache.bcel.generic.ObjectType;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.bytecode.MethodGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
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.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
// ino.class.LocalOrFieldVar.25503.declaration
public class LocalOrFieldVarOrClassname extends Expr
// ino.end
// ino.class.LocalOrFieldVar.25503.body
{
// ino.attribute.parserlog.25507.declaration
protected static Logger parserlog = Logger.getLogger("parser");
// ino.end
private boolean isFieldAccess = false;
private boolean isClassAccess = false;
// ino.method.LocalOrFieldVar.25510.definition
public LocalOrFieldVarOrClassname(int offset, int variableLength)
// ino.end
// ino.method.LocalOrFieldVar.25510.body
{
super(offset,variableLength);
}
// ino.end
// ino.method.LocalOrFieldVar.25513.definition
public LocalOrFieldVarOrClassname(String n, int offset)
// ino.end
// ino.method.LocalOrFieldVar.25513.body
{
super(offset,n.length());
usedid = new UsedId(offset);
usedid.set_Name(n);
}
// ino.end
// ino.method.set_UsedId.25519.definition
public void set_UsedId(UsedId u)
// ino.end
// ino.method.set_UsedId.25519.body
{
this.usedid=u;
}
// ino.end
// ino.method.get_Name.25522.definition
public String get_Name()
// ino.end
// ino.method.get_Name.25522.body
{
return usedid.get_Name_1Element();
}
// ino.end
// ino.method.toString.25534.defdescription type=javadoc
/**
* <br/>Author: Martin Pl�micke
* @return
*/
// ino.end
// ino.method.toString.25534.definition
public String toString()
// ino.end
// ino.method.toString.25534.body
{
if(getType()==null)return usedid.toString();
return usedid.toString() + ": " + getType().toString();
}
// ino.end
// ino.method.wandleRefTypeAttributes2GenericAttributes.25537.definition
public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> paralist, Menge<GenericTypeVar> genericMethodParameters)
// ino.end
// ino.method.wandleRefTypeAttributes2GenericAttributes.25537.body
{
}
// ino.end
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet();
//gibt es eine Assumption für den die LocalOrFieldVar-Variablen, dann folgendes ausführen:
Type thisTypeAssumption = assumptions.getVarType(this.get_Name(), this.getParentClass());
if(thisTypeAssumption == null){//Es ist keine Variable oder Feld
//Testen ob es ein Klassenname ist:
ClassAssumption cAss = assumptions.getClass(this.get_Name());
if(cAss == null)throw new TypeinferenceException("Weder eine Variable noch eine Klasse "+this.get_Name()+" ist in den Assumptions nicht vorhanden",this);
thisTypeAssumption = cAss.getAssumedClass().getType();
this.set_Type(thisTypeAssumption);
this.isClassAccess = true;
}else{
Type thisType = thisTypeAssumption.checkTYPE(assumptions, this);
this.setType(thisType);
//ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable()));
//Rausfinden, ob es Feld oder Locale Variable ist:
for(FieldAssumption fAss : assumptions.getFieldVars(this.get_Name())){
if(this.getParentClass().equals(fAss.getParentClass()))this.isFieldAccess = true;
};
}
return ret;
}
public String getTypeInformation(){
return this.getType()+" "+this.get_Name();
}
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
return new JavaCodeResult(this.get_Name());
}
@Override
public Menge<SyntaxTreeNode> getChildren() {
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
return ret;
}
@Override
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
InstructionList il = new InstructionList();
if(this.isFieldAccess){
il.append(cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(), this.get_Name(), this.getType().getBytecodeType(cg, rs), Constants.GETFIELD));
}
il.append(createLoad(cg, rs));
return il;
}
public LocalVariableInstruction createLoad(ClassGenerator cg, TypeinferenceResultSet rs){
Type type = this.getType();
org.apache.bcel.generic.Type byteCodeType = type.getBytecodeType(cg, rs);
String name = this.get_Name();
return cg.getMethodGenerator().createLoad(byteCodeType, name);
}
}
// ino.end