List of usage examples for org.eclipse.jdt.internal.compiler.codegen CodeStream aload_1
public void aload_1()
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.Lifting.java
License:Open Source License
/** * API for AbstractMethodDeclaration://from ww w . ja v a 2s. c o m * * Create a byte code sequence for a runtime check in a creation method: * R _OT$create_OT$R(B b) { * if (this._OT$cache_OT$R.contains(b)) * throw new DuplicateRoleException("R"); * // continue regular code. * } * * Note, the need for this runtime check is detected quite late. * At this point it is easier to create the byte code sequence directly, * rather the creating AST first. */ public static void createDuplicateRoleCheck(CodeStream codeStream, AbstractMethodDeclaration method) { MethodBinding binding = method.binding; Scope scope = method.scope; ReferenceBinding roleType = (ReferenceBinding) binding.returnType; String roleName = new String(roleType.readableName()); // TODO(SH): check why roleType.getRoleModel().getClassPartBinding().roleModel may yield a different result. // I think it occured in haeder/stopwatch from smile-CVS. //RoleModel role = roleType.getRealClass().roleModel; char[] cacheName = LiftingEnvironment.getCacheName(roleType.roleModel.getBoundRootRole()); ReferenceBinding teamBinding = roleType.enclosingType();//role.getTeamModel().getBinding(); FieldBinding cache = TypeAnalyzer.findField(teamBinding, cacheName, /*static*/false, /*outer*/false, ITranslationStates.STATE_FULL_LIFTING); // generated by this state if (cache == null) throw new InternalCompilerError("generated cache field not found: " + new String(cacheName)); //$NON-NLS-1$ ReferenceBinding map = (ReferenceBinding) scope.getType(IOTConstants.WEAK_HASH_MAP, 3); MethodBinding contains = map.getMethod(scope, IOTConstants.CONTAINS_KEY); ReferenceBinding exc = (ReferenceBinding) scope.getType(IOTConstants.ORG_OBJECTTEAMS_DUPLICATE_ROLE, 3); TypeBinding[] types = new TypeBinding[] { scope.getJavaLangString() }; MethodBinding excInit = exc.getExactConstructor(types); BranchLabel normalCase = new BranchLabel(codeStream); codeStream.aload_0(); // this codeStream.fieldAccess(Opcodes.OPC_getfield, cache, teamBinding); // getfield MyTeam._OT$cache_OT$R Ljava/util/WeakHashMap; codeStream.aload_1(); // arg0 codeStream.invoke(Opcodes.OPC_invokevirtual, contains, map); // invokevirtual java.util.WeakHashMap.containsKey (Ljava/lang/Object;)Z codeStream.ifeq(normalCase); // false -> #endif codeStream.new_(exc); // new <org.objectteams.DuplicateRoleException> codeStream.dup(); // dup codeStream.ldc(roleName); // ldc "R" codeStream.invoke(Opcodes.OPC_invokespecial, excInit, exc); // invokespecial org.objectteams.DuplicateRoleException.<init> (Ljava/lang/String;)V codeStream.athrow(); // athrow normalCase.place(); // #endif }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticRoleFieldAccess.java
License:Open Source License
public void generateBodyForRead(FieldBinding fieldBinding, CodeStream codeStream) { if (fieldBinding.isStatic()) { fieldBinding = checkAdjustRoleFieldAccess(fieldBinding, codeStream); // may insert cast, too. codeStream.fieldAccess(Opcodes.OPC_getstatic, fieldBinding, fieldBinding.declaringClass); // FIXME(SH): throw new InternalCompilerError("accessor for static field not applicable."); } else {//from w w w.ja v a2 s . c o m // prepare "this" and role args: LocalVariableBinding thisArg = createArgumentBinding(codeStream, "this".toCharArray(), //$NON-NLS-1$ fieldBinding.declaringClass.enclosingType(), 0); char[] argName = typeNameToLower(this.parameters[0].sourceName()); LocalVariableBinding arg1 = createArgumentBinding(codeStream, argName, this.parameters[0], 1); // generate code: codeStream.aload_1(); // not a static accessor, positions shifted by 1. fieldBinding = checkAdjustRoleFieldAccess(fieldBinding, codeStream); // may insert cast, too. codeStream.fieldAccess(Opcodes.OPC_getfield, fieldBinding, fieldBinding.declaringClass); // finish args: if ((codeStream.generateAttributes & (ClassFileConstants.ATTR_VARS | ClassFileConstants.ATTR_STACK_MAP_TABLE | ClassFileConstants.ATTR_STACK_MAP)) == 0) return; // avoid NPE below thisArg.recordInitializationEndPC(codeStream.position); arg1.recordInitializationEndPC(codeStream.position); } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticRoleFieldAccess.java
License:Open Source License
public void generateBodyForWrite(FieldBinding fieldBinding, CodeStream codeStream) { if (fieldBinding.isStatic()) { fieldBinding = checkAdjustRoleFieldAccess(fieldBinding, codeStream); codeStream.load(fieldBinding.type, 1); codeStream.fieldAccess(Opcodes.OPC_putstatic, fieldBinding, fieldBinding.declaringClass); } else {// ww w. ja va2 s . c o m // prepare "this" and role args: LocalVariableBinding thisArg = createArgumentBinding(codeStream, "this".toCharArray(), //$NON-NLS-1$ fieldBinding.declaringClass.enclosingType(), 0); char[] argName = typeNameToLower(this.parameters[0].sourceName()); LocalVariableBinding arg1 = createArgumentBinding(codeStream, argName, this.parameters[0], 1); LocalVariableBinding arg2 = createArgumentBinding(codeStream, "value".toCharArray(), this.parameters[1], //$NON-NLS-1$ 2); codeStream.aload_1(); // not a static accessor, positions shifted by 1. fieldBinding = checkAdjustRoleFieldAccess(fieldBinding, codeStream); codeStream.load(fieldBinding.type, 2); codeStream.fieldAccess(Opcodes.OPC_putfield, fieldBinding, fieldBinding.declaringClass); // finish args: if ((codeStream.generateAttributes & (ClassFileConstants.ATTR_VARS | ClassFileConstants.ATTR_STACK_MAP_TABLE | ClassFileConstants.ATTR_STACK_MAP)) == 0) return; // avoid NPE below thisArg.recordInitializationEndPC(codeStream.position); arg1.recordInitializationEndPC(codeStream.position); arg2.recordInitializationEndPC(codeStream.position); } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleMigrationImplementor.java
License:Open Source License
private static void doAddMigrateMethod(TypeDeclaration roleClassDecl, char[] selector, TypeReference argumentTypeRef, TypeReference returnTypeRef, final String kind, final char[] cacheName) { AstGenerator gen = new AstGenerator(roleClassDecl.sourceStart, roleClassDecl.sourceEnd); MethodDeclaration migrate = new MethodDeclaration(roleClassDecl.compilationResult) { @Override// w w w .j a v a2s . c o m protected void endOfMethodHook(ClassFile classfile) { // common code for both variants: CodeStream codeStream = classfile.codeStream; // if (otherTeam == null) BranchLabel goOn = new BranchLabel(codeStream); codeStream.aload_1(); //otherTeam / otherBase codeStream.ifnonnull(goOn); // { throw new NullPointerException("Team/base argument must not be null"); } ReferenceBinding npeBinding = (ReferenceBinding) this.scope.getType(JAVA_LANG_NULLPOINTEREXCEPTION, 3); codeStream.new_(npeBinding); codeStream.dup(); MethodBinding npeStringCtor = getStringArgCtor(npeBinding); if (npeStringCtor == null) throw new InternalCompilerError( "Expected constructor NullPointerException.<init>(String) not found"); //$NON-NLS-1$ codeStream.ldc(kind + " argument must not be null"); //$NON-NLS-1$ codeStream.invoke(Opcodes.OPC_invokespecial, npeStringCtor, npeBinding); codeStream.athrow(); goOn.place(); // specific code: if (kind == TEAM) genMigrateToTeamInstructions(codeStream, this.scope.enclosingSourceType()); else genMigrateToBaseInstructions(codeStream, this.scope.enclosingSourceType(), this.scope, cacheName); } private MethodBinding getStringArgCtor(ReferenceBinding npeBinding) { MethodBinding[] ctors = npeBinding.getMethods(TypeConstants.INIT); for (MethodBinding ctor : ctors) { if (ctor.parameters.length == 1 && ctor.parameters[0].id == TypeIds.T_JavaLangString) return ctor; } return null; } @Override public void analyseCode(ClassScope classScope, FlowContext flowContext, FlowInfo flowInfo) { // noop } }; gen.setMethodPositions(migrate); migrate.isGenerated = true; migrate.modifiers = AccPublic | AccSynchronized; migrate.typeParameters = new TypeParameter[] { gen.unboundedTypeParameter(RoleMigrationImplementor.TYPEPARAM) }; migrate.returnType = returnTypeRef; migrate.selector = selector; migrate.arguments = new Argument[] { gen.argument(("other" + kind).toCharArray(), argumentTypeRef) }; //$NON-NLS-1$ migrate.statements = new Statement[0]; migrate.hasParsedStatements = true; AstEdit.addMethod(roleClassDecl, migrate); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleMigrationImplementor.java
License:Open Source License
static void genMigrateToTeamInstructions(CodeStream codeStream, SourceTypeBinding roleBinding) { // this.this$n = (MyTeam)otherTeam codeStream.aload_0(); // this codeStream.aload_1(); // otherTeam codeStream.checkcast(roleBinding.enclosingType()); codeStream.fieldAccess(Opcodes.OPC_putfield, enclosingInstanceField(roleBinding), roleBinding); codeStream.aload_0();//from ww w .ja v a 2 s .c om codeStream.areturn(); // not handling caches here, cf. IProblem.MigrateBoundRole }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleMigrationImplementor.java
License:Open Source License
static void genMigrateToBaseInstructions(CodeStream codeStream, SourceTypeBinding roleBinding, Scope scope, char[] cacheName) { FieldBinding baseField = roleBinding.getField(IOTConstants._OT_BASE, true); // accessing the cache (using remove() and put()): ReferenceBinding cacheTypeBinding = (ReferenceBinding) scope.getType(IOTConstants.WEAK_HASH_MAP, 3); MethodBinding remove = getMethod(cacheTypeBinding, "remove".toCharArray(), 1); //$NON-NLS-1$ MethodBinding put = cacheTypeBinding.getMethod(scope, "put".toCharArray()); //$NON-NLS-1$ // accessing the base object (using _OT$removeRole() and _OT$addRole()): WeavingScheme weavingScheme = scope.compilerOptions().weavingScheme; ReferenceBinding iboundBase = (ReferenceBinding) scope .getType(weavingScheme == WeavingScheme.OTDRE ? IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE2 : IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE, 3); // remove old from cache codeStream.aload_0(); // this codeStream.fieldAccess(Opcodes.OPC_getfield, enclosingInstanceField(roleBinding), // this.this$n roleBinding);//from w w w. java 2 s .c o m codeStream.fieldAccess(Opcodes.OPC_getfield, roleBinding.enclosingType().getField(cacheName, true), // this.this$n._OT$cache$R roleBinding.enclosingType()); codeStream.dup(); // for use in put() below codeStream.aload_0(); // this codeStream.fieldAccess(Opcodes.OPC_getfield, baseField, // this._OT$base roleBinding); codeStream.dup(); // share for nested method call // this._OT$base // remove role from this (old) base genAddOrRemoveRole(codeStream, scope, iboundBase, false);// -> void // -> base._OT$removeRole(this) codeStream.invoke(Opcodes.OPC_invokevirtual, remove, // -> cache.remove(base) cacheTypeBinding); codeStream.pop(); // discard result // this._OT$base = (MyBase)otherBase codeStream.aload_0(); // this codeStream.aload_1(); // otherBase codeStream.checkcast(roleBinding.baseclass()); codeStream.fieldAccess(Opcodes.OPC_putfield, baseField, roleBinding); // add new to cache (cache is still on the stack) codeStream.aload_1(); // otherBase codeStream.aload_0(); // this (role) codeStream.invoke(Opcodes.OPC_invokevirtual, put, cacheTypeBinding); // add to new base: codeStream.aload_1(); // otherBase genAddOrRemoveRole(codeStream, scope, iboundBase, true); // -> void // -> base._OT$addRemoveRole(this, false) codeStream.return_(); }