JavaPatternMatching/src/de/dhbwstuttgart/syntaxtree/Constant.java

235 lines
6.1 KiB
Java
Executable File

// ino.module.Constant.8556.package
package de.dhbwstuttgart.syntaxtree;
// ino.end
// ino.module.Constant.8556.import
import java.util.Vector;
import de.dhbwstuttgart.bytecode.AttributeInfo;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.JVMCode;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.statement.Literal;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
// ino.class.Constant.23212.description type=javadoc
/**
* Enthaelt die Eigenschaften einer Konstante (Name, Typ, Modifier, Wert)
*
* @author SCJU
*
*/
// ino.end
// ino.class.Constant.23212.declaration
public class Constant extends Method
// ino.end
// ino.class.Constant.23212.body
{
// ino.attribute.name.23216.declaration
protected String name; // Name der Konstante
// ino.end
// ino.attribute.mod.23219.declaration
protected Modifiers mod = new Modifiers(); // Access-Flags
// ino.end
// ino.attribute.exp.23222.declaration
protected Expr exp; // Wert der Konstante
// ino.end
// ino.attribute.typ.23225.declaration
protected Type typ; // Typ der Konstante
// ino.end
// ino.method.Constant.23228.definition
@Deprecated
public Constant(String name, Modifiers mod)
// ino.end
// ino.method.Constant.23228.body
{
super(0); //Nur ein Workaraound. Da Constant = Deprecated
this.name = name;
this.mod = mod;
}
// ino.end
// ino.method.getValue.23231.defdescription type=javadoc
/**
* Gibt den Wert der Konstantendefinition zurueck.
*/
// ino.end
// ino.method.getValue.23231.definition
public Expr getValue()
// ino.end
// ino.method.getValue.23231.body
{
return exp;
}
// ino.end
// ino.method.setValue.23234.defdescription type=javadoc
/**
* Legt den Wert der Konstantendefinition fest.
*/
// ino.end
// ino.method.setValue.23234.definition
public void setValue(Expr exp)
// ino.end
// ino.method.setValue.23234.body
{
this.exp = exp;
}
// ino.end
// ino.method.getType.23237.defdescription type=javadoc
/**
* Gibt den Typ der Konstantendefinition zurueck.
*/
// ino.end
// ino.method.getType.23237.definition
public Type getType()
// ino.end
// ino.method.getType.23237.body
{
return typ;
}
// ino.end
// ino.method.setType.23240.defdescription type=javadoc
/**
* Legt den Typ der Konstantendefinition fest
*/
// ino.end
// ino.method.setType.23240.definition
public void setType(Type typ)
// ino.end
// ino.method.setType.23240.body
{
this.typ = typ;
}
// ino.end
// ino.method.getTypeName.23243.definition
public JavaClassName getTypeName()
// ino.end
// ino.method.getTypeName.23243.body
{
return new JavaClassName(name);
}
// ino.end
// ino.method.getName.23246.definition
public String getIdentifier()
// ino.end
// ino.method.getName.23246.body
{
return name;
}
// ino.end
// ino.method.setName.23249.definition
public void setName(String name)
// ino.end
// ino.method.setName.23249.body
{
this.name = name;
}
// ino.end
// ino.method.getModifiers.23252.definition
public Modifiers getModifiers()
// ino.end
// ino.method.getModifiers.23252.body
{
return mod;
}
// ino.end
// ino.method.setModifiers.23255.definition
public void setModifiers(Modifiers modifiers)
// ino.end
// ino.method.setModifiers.23255.body
{
this.mod = modifiers;
}
// ino.end
// ino.method.codegen.23258.definition
public void codegen(ClassFile classfile, Vector paralist)
throws JVMCodeException
// ino.end
// ino.method.codegen.23258.body
{
// Zugehoerigen Typ (I, Z, C, Ljava/lang/String;) fuer den Typ ermitteln
String bcgType = JVMCode.get_codegen_Type(typ.getName().toString(), paralist);
if (getValue() == null || !(getValue() instanceof Literal) ) {
throw new JVMCodeException("Die Generierung der Konstante wird nicht unterstuetzt!");
}
// Attribut fuer Wertzuweisung erstellen
short index = (short) ((Literal)getValue()).ConstantCodegen(classfile);
AttributeInfo attrinfo = new AttributeInfo();
attrinfo.set_attribute_name_index(classfile.getConstantValueID());
attrinfo.set_info(JVMCode.shortToBytes(index));
// Field hinzufuegen
classfile.add_field(name, bcgType, mod.calculate_access_flags(), attrinfo);
}
// ino.end
// ino.method.getOffset.23261.definition
public int getOffset()
// ino.end
// ino.method.getOffset.23261.body
{
if(declid.size()<=0)
return MyCompiler.NO_LINENUMBER;
else{
return declid.elementAt(0).getOffset();
}
}
// ino.end
// ino.method.getLineNumber.23264.definition
public int getLineNumber()
// ino.end
// ino.method.getLineNumber.23264.body
{
if(declid.size()<=0)
return MyCompiler.NO_LINENUMBER;
else{
return declid.elementAt(0).getLineNumber();
}
}
// ino.end
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
throw new NotImplementedException();
}
@Override
public TypeAssumptions createTypeAssumptions(Class classmember) {
throw new NotImplementedException();
//return null;
}
@Override
public int getTypeLineNumber() {
// TODO Auto-generated method stub
return 0;
}
}
// ino.end