forked from JavaTX/JavaCompilerCore
180 lines
5.7 KiB
Java
Executable File
180 lines
5.7 KiB
Java
Executable File
// ino.module.IntLiteral.8635.package
|
|
package de.dhbwstuttgart.syntaxtree.statement;
|
|
// ino.end
|
|
// ino.module.IntLiteral.8635.import
|
|
import java.util.Hashtable;
|
|
import de.dhbwstuttgart.typeinference.Menge;
|
|
|
|
import de.dhbwstuttgart.logger.Logger;
|
|
import de.dhbwstuttgart.bytecode.ClassFile;
|
|
import de.dhbwstuttgart.bytecode.CodeAttribute;
|
|
import de.dhbwstuttgart.bytecode.JVMCode;
|
|
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
|
import de.dhbwstuttgart.myexception.JVMCodeException;
|
|
import de.dhbwstuttgart.syntaxtree.Class;
|
|
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
|
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
|
import de.dhbwstuttgart.syntaxtree.type.IntegerType;
|
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|
import de.dhbwstuttgart.syntaxtree.type.Type;
|
|
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
|
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
|
import de.dhbwstuttgart.typeinference.ResultSet;
|
|
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
|
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
|
|
|
|
|
|
|
|
|
// ino.class.IntLiteral.25447.declaration
|
|
public class IntLiteral extends Literal
|
|
// ino.end
|
|
// ino.class.IntLiteral.25447.body
|
|
{
|
|
// ino.attribute.Int.25451.declaration
|
|
private int Int;
|
|
// ino.end
|
|
// ino.attribute.parserlog.25454.declaration
|
|
protected static Logger parserlog = Logger.getLogger("parser");
|
|
// ino.end
|
|
|
|
|
|
// ino.method.IntLiteral.25457.definition
|
|
public IntLiteral()
|
|
// ino.end
|
|
// ino.method.IntLiteral.25457.body
|
|
{
|
|
super(-1,-1);
|
|
// #JB# 20.04.2005
|
|
// ###########################################################
|
|
this.setType(new IntegerType(this));
|
|
//this.setType(new Type("int"));
|
|
// ###########################################################
|
|
}
|
|
// ino.end
|
|
|
|
// ino.method.set_Int.25460.definition
|
|
public void set_Int(int i)
|
|
// ino.end
|
|
// ino.method.set_Int.25460.body
|
|
{
|
|
this.Int = i;
|
|
}
|
|
// ino.end
|
|
|
|
// ino.method.get_Int.25463.definition
|
|
public int get_Int()
|
|
// ino.end
|
|
// ino.method.get_Int.25463.body
|
|
{
|
|
return Int;
|
|
}
|
|
// ino.end
|
|
|
|
/*
|
|
// ino.method.sc_check.25466.definition
|
|
public void sc_check(Menge<Class> classname, Hashtable ch, Hashtable<String, String> bh, boolean ext, Hashtable parach, Hashtable<String, Hashtable> parabh)
|
|
// ino.end
|
|
// ino.method.sc_check.25466.body
|
|
{
|
|
parserlog.debug("SC -> Semantik-Check f�r IntLiteral wurde aufgerufen --> nichts zu tun!");
|
|
}
|
|
// ino.end
|
|
*/
|
|
|
|
// ino.method.get_Name.25469.definition
|
|
public String get_Name()
|
|
// ino.end
|
|
// ino.method.get_Name.25469.body
|
|
{
|
|
return null;
|
|
}
|
|
// ino.end
|
|
|
|
// ino.method.codegen.25472.definition
|
|
public void codegen(ClassFile classfile, CodeAttribute code, Menge paralist)
|
|
throws JVMCodeException
|
|
// ino.end
|
|
// ino.method.codegen.25472.body
|
|
{
|
|
if (Int >= 0 && Int <= 5) // Kleine Werte lassen sich direkt realisieren
|
|
code.add_code(JVMCode.nconst_n("int", Int));
|
|
else if (Int >= -128 && Int <= 127) { // Aenderung des Codes fuer etwas groessere Werte
|
|
code.add_code(JVMCode.bipush);
|
|
code.add_code_byte((byte) Int);
|
|
} else if (Int >= -32768 && Int <= 32767) { // Aenderung des Codes fuer groessere Werte
|
|
code.add_code(JVMCode.sipush);
|
|
code.add_code_short((short) Int);
|
|
} else { // Ablage als Konstante
|
|
int index = classfile.add_CONSTANT_Integer_info(Int);
|
|
if (index < 256) {
|
|
code.add_code(JVMCode.ldc);
|
|
code.add_code_byte((byte) index);
|
|
} else {
|
|
code.add_code(JVMCode.ldc_w);
|
|
code.add_code_short((short) index);
|
|
}
|
|
}
|
|
|
|
// Auto-Boxing: Da int nicht so nicht weiterverwendet werden kann,
|
|
// in Integer umwandeln.
|
|
if (!getPrimitiveFlag()) {
|
|
code.add_code(JVMCode.invokestatic);
|
|
code.add_code_short(classfile.add_method_ref("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;"));
|
|
}
|
|
}
|
|
// ino.end
|
|
|
|
// ino.method.ConstantCodegen.25475.definition
|
|
public short ConstantCodegen(ClassFile classfile)
|
|
throws JVMCodeException
|
|
// ino.end
|
|
// ino.method.ConstantCodegen.25475.body
|
|
{
|
|
return (short) classfile.add_CONSTANT_Integer_info(get_Int());
|
|
}
|
|
// ino.end
|
|
|
|
|
|
// ino.method.toString.25484.defdescription type=javadoc
|
|
/**
|
|
* <br/>Author: Martin Pl�micke
|
|
* @return
|
|
*/
|
|
// ino.end
|
|
// ino.method.toString.25484.definition
|
|
public String toString()
|
|
// ino.end
|
|
// ino.method.toString.25484.body
|
|
{
|
|
return getType().toString() + " " + Int;
|
|
}
|
|
// ino.end
|
|
// ino.method.wandleRefTypeAttributes2GenericAttributes.25487.definition
|
|
public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> paralist, Menge<GenericTypeVar> genericMethodParameters)
|
|
// ino.end
|
|
// ino.method.wandleRefTypeAttributes2GenericAttributes.25487.body
|
|
{
|
|
}
|
|
// ino.end
|
|
|
|
@Override
|
|
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
|
ConstraintsSet ret = new ConstraintsSet();
|
|
//this.setType(new IntegerType());
|
|
this.set_Type(assumptions.checkType(new RefType("java.lang.Integer",this,-1), this));
|
|
return ret;
|
|
}
|
|
|
|
@Override
|
|
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
|
return new JavaCodeResult(String.valueOf(this.Int));
|
|
}
|
|
@Override
|
|
public Menge<SyntaxTreeNode> getChildren() {
|
|
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
|
|
return ret;
|
|
}
|
|
}
|
|
// ino.end
|