Package org.allspice.bytecode

Examples of org.allspice.bytecode.MethodDef


    ClassDef cd = new ClassDef(ClassDefType.DEFAULT,null,new TypeName("TestClass"),TypeName.OBJECT) ;
    {
      // constructor called <init>
      // must call superclass's <init>
      // Returns nothing
      MethodDef md = new MethodDef(TypeName.VOID,"<init>").addInstructions(
          new Load(new Var(0,new TypeName("TestClass"))),
          new InvokeSpecial(new MethodRef(cd.superClass,TypeName.VOID,"<init>")),
          new Return(TypeCode.VOID)
      ) ;
      // Watch it!  ClassDef is immutable
      cd = cd.addMethod(md) ;
    }
    {
      // Two variables, x & y
      // Index 0 is "this"
      Var x = new Var(1,TypeName.INT) ; // index 1
      Var y = new Var(2,TypeName.INT) ; // index 2
      MethodDef md = new MethodDef(TypeName.INT,"add",x,y).addInstructions(
          new Load(x),
          new Load(y),
          new Add(TypeCode.INT),
          new Return(TypeCode.INT)
      ) ;
View Full Code Here


          if (mdd.name.equals("<clinit>")) {
            body = body.insertAll(mdd.body) ;
            continue ;
          }
          try {
            MethodDef def = getDef(converter,classPool,cdecl,mdd,fuinfo,fdcls,errors);
            if (def.name.equals("<init>")) {
              foundInit = true ;
            }
            cd = cd.addMethod(def) ;
          } catch (CompilerException e) {
View Full Code Here

    Scope scope =
        fieldAttrs.visibility == Visibility.PUBLIC ? Scope.PUBLIC :
        fieldAttrs.visibility == Visibility.PROTECTED ? Scope.PROTECTED :
        fieldAttrs.visibility == Visibility.PRIVATE ? Scope.PRIVATE :
        Scope.PROTECTED ;
    MethodDef mdef = new MethodDef(scope,retType,mdecl.name,vars) ;
    mdef = mdef.setAbstract(fieldAttrs.isAbstract) ;
    mdef = mdef.setStatic(fieldAttrs.isStatic) ;
    mdef = mdef.setSynchronized(fieldAttrs.isSynchronized) ;
    mdef = mdef.setNative(fieldAttrs.isNative) ;
    mdef = mdef.setFinal(fieldAttrs.isFinal) ;
    for(String ex: mdecl.exceptions) {
      mdef = mdef.addThrow(context.fullyQualified(ex)) ;
    }
    if (!fieldAttrs.isAbstract) {
      InstList il = new InstList() ;
      final ArrayList<Statement> body = new ArrayList<Statement>(mdecl.body);
      if (mdecl.name.equals("<init>")) {
        modifyConstructor(context, body);
      }
      for(Statement st: body) {
        context.compile(st,il) ;
      }
      StdJavaExpressions.loadZero(TypeCode.getType(retType),il) ;
      il.add(new Return(TypeCode.getType(retType))) ;
      mdef = mdef.addInstructions(il.instructions.toArray(new Inst[0])) ;
      errors.addAll(il.errors) ;
    }
    return mdef;
  }
View Full Code Here

  public static MethodDef getDef(StdJavaExpressions converter,ClassPool classPool,ClassDecl classDecl,MethodDecl mdecl,FileUnitInfo fuinfo, VarStack fdcls,
      Collection<Exception> errors) throws CompilerException {
    StubResolver stub = classPool.new SimpleResolver(ClassPool.getClassName(fuinfo.unit,classDecl)) ;
    VarStack vdcls = StdJavaExpressions.makeInitDecls(stub,mdecl,fuinfo,fdcls) ;
    EvaluationContext context = new EvaluationContext(converter,classPool,fuinfo.unit,stub,mdecl,vdcls) ;
    MethodDef mdef = makeMethDef(mdecl, context,fuinfo,errors);
    return mdef ;
  }
View Full Code Here

public class TestSHL extends MyTestCase {
  public ClassDef defadd(String ret,String type,int i1,int i2) {
    ClassDef cd = makeClassDef() ;
    Var x = new Var(i1,new TypeName(type)) ;
    Var y = new Var(i2,TypeName.INT) ;
    MethodDef md = new MethodDef(new TypeName(ret),"meth",x,y) ;
    md = md.addInstructions(
        new Load(x),
        new Load(y),
        new ShiftLeft(TypeCode.getType(type)),
        new Return(TypeCode.getType(ret))
        ) ;
View Full Code Here

public class TestNewArray extends MyTestCase {
  public ClassDef defadd(String type) {
    ClassDef cd = makeClassDef() ;
    {
      MethodDef md = new MethodDef(new TypeName(type+"[]"),"getFoo") ;
      md = md.setStatic(true) ;
      md = md.addInstructions(
          new Const(10),
          new New(new TypeName(type),1),
          new Return(TypeCode.ARRAY)
          ) ;
      cd = cd.addMethod(md) ;
View Full Code Here

public class TestIFLT extends MyTestCase {
  public ClassDef defadd(String type,int i1,int i2) {
    ClassDef cd = makeClassDef() ;
    Var x = new Var(i1,new TypeName(type)) ;
    Var y = new Var(i2,new TypeName(type)) ;
    MethodDef md = new MethodDef(TypeName.BOOLEAN,"meth",x,y) ;
    Mark one = new Mark() ;
    md = md.addInstructions(
        new Load(x),
        new Load(y),
        new IfLessThan(TypeCode.getType(type),one),
        new Const(false),
        new Return(TypeCode.BOOLEAN),
View Full Code Here

public class TestSHR extends MyTestCase {
  public ClassDef defadd(String ret,String type,int i1,int i2) {
    ClassDef cd = makeClassDef() ;
    Var x = new Var(i1,new TypeName(type)) ;
    Var y = new Var(i2,TypeName.INT) ;
    MethodDef md = new MethodDef(new TypeName(ret),"meth",x,y) ;
    md = md.addInstructions(
        new Load(x),
        new Load(y),
        new ShiftRight(TypeCode.getType(type)),
        new Return(TypeCode.getType(ret))
        ) ;
View Full Code Here

public class TestIFNE0 extends MyTestCase {
  public ClassDef defadd(String type,int i1) {
    ClassDef cd = makeClassDef() ;
    Var x = new Var(i1,new TypeName(type)) ;
    MethodDef md = new MethodDef(TypeName.BOOLEAN,"meth",x) ;
    Mark one = new Mark() ;
    md = md.addInstructions(
        new Load(x),
        new IfNotEquals0(TypeCode.getType(type),one),
        new Const(false),
        new Return(TypeCode.BOOLEAN),
        new Nop(one),
View Full Code Here

public class TestIncrement extends MyTestCase {
  public ClassDef defadd(String type,Number inc) {
    ClassDef cd = makeClassDef() ;
    Var x = new Var(1,new TypeName(type)) ;
    MethodDef md = new MethodDef(new TypeName(type),"meth",x) ;
    md = md.addInstructions(
        new Increment(x,inc),
        new Load(x),
        new Return(TypeCode.getType(type))
        ) ;
    return cd.addMethod(md)
View Full Code Here

TOP

Related Classes of org.allspice.bytecode.MethodDef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.