/** * Generate instructions for field initializers or static initialization statements. * * @param node - the AST at the root of the statement. * @param isStatic - true if the code should be generated in a static context. */ private void generateInstructions(IASNode node, final boolean isStatic) { // Do we need to create new information for the class' // static initialization method? Note that this may // be undone if the codgen fails or doesn't produce // any instructions. final boolean createNewCinit = isStatic && this.cinfo.cInit == null; if (createNewCinit) { // Speculatively initialize the class' cinit // (static class initializer routine)'s data // structures; the code generator may need to // store information in them. this.cinfo.cInit = new MethodInfo(); MethodBodyInfo cinit_info = new MethodBodyInfo(); cinit_info.setMethodInfo(this.cinfo.cInit); this.classStaticScope.setMethodInfo(this.cinfo.cInit); this.classStaticScope.methodVisitor = emitter.visitMethod(this.cinfo.cInit); this.classStaticScope.methodVisitor.visit(); this.classStaticScope.methodBodyVisitor = this.classStaticScope.methodVisitor.visitBody(cinit_info); this.classStaticScope.methodBodyVisitor.visit(); } InstructionList cgResult = null; LexicalScope ls = isStatic ? this.classStaticScope : this.classScope; ls.resetDebugInfo(); cgResult = ls.getGenerator().generateInstructions(node, CmcEmitter.__statement_NT, ls); // If nothing came back, revert any change made to the cinit information. if ((cgResult == null || cgResult.isEmpty()) && createNewCinit) { this.cinfo.cInit = null; this.classStaticScope.resetMethodInfo(); this.classStaticScope.methodVisitor = null; this.classStaticScope.methodBodyVisitor = null; } // Save the generated instructions, if present. if (cgResult != null) { if (isStatic) this.cinitInsns.addAll(cgResult); else this.iinitInsns.addAll(cgResult); } }