You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AspectClinit.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajdt.internal.compiler.ast;
  13. import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
  14. import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
  15. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Clinit;
  16. import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
  17. import org.aspectj.org.eclipse.jdt.internal.compiler.codegen.BranchLabel;
  18. import org.aspectj.org.eclipse.jdt.internal.compiler.codegen.CodeStream;
  19. import org.aspectj.org.eclipse.jdt.internal.compiler.codegen.ExceptionLabel;
  20. import org.aspectj.org.eclipse.jdt.internal.compiler.codegen.Opcodes;
  21. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope;
  22. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
  23. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
  24. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
  25. import org.aspectj.weaver.AjcMemberMaker;
  26. public class AspectClinit extends Clinit {
  27. private boolean hasPre, hasPost;
  28. private FieldBinding initFailureField;
  29. public AspectClinit(Clinit old, CompilationResult compilationResult, boolean hasPre, boolean hasPost, FieldBinding initFailureField) {
  30. super(compilationResult);
  31. // CHECK do we need all the bits or just the needfreereturn bit?
  32. // if ((old.bits & ASTNode.NeedFreeReturn)!=0) this.bits |= ASTNode.NeedFreeReturn;
  33. this.bits = old.bits;
  34. this.sourceEnd = old.sourceEnd;
  35. this.sourceStart = old.sourceStart;
  36. this.declarationSourceEnd = old.declarationSourceEnd;
  37. this.declarationSourceStart = old.declarationSourceStart;
  38. this.hasPre = hasPre;
  39. this.hasPost = hasPost;
  40. this.initFailureField = initFailureField;
  41. }
  42. private ExceptionLabel handlerLabel;
  43. protected void generateSyntheticCode(
  44. ClassScope classScope,
  45. CodeStream codeStream)
  46. {
  47. if (initFailureField != null) {
  48. handlerLabel = new ExceptionLabel(codeStream, classScope.getJavaLangThrowable());
  49. handlerLabel.placeStart();
  50. }
  51. if (hasPre) {
  52. final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(classScope);
  53. codeStream.invoke(Opcodes.OPC_invokestatic,world.makeMethodBindingForCall(
  54. AjcMemberMaker.ajcPreClinitMethod(
  55. world.fromBinding(classScope.referenceContext.binding)
  56. )),null);
  57. }
  58. super.generateSyntheticCode(classScope, codeStream);
  59. }
  60. protected void generatePostSyntheticCode(
  61. ClassScope classScope,
  62. CodeStream codeStream)
  63. {
  64. super.generatePostSyntheticCode(classScope, codeStream);
  65. if (hasPost) {
  66. final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(classScope);
  67. codeStream.invoke(Opcodes.OPC_invokestatic,world.makeMethodBindingForCall(
  68. AjcMemberMaker.ajcPostClinitMethod(
  69. world.fromBinding(classScope.referenceContext.binding)
  70. )),null);
  71. }
  72. boolean creatingStackMap = (codeStream.generateAttributes & (
  73. ClassFileConstants.ATTR_STACK_MAP_TABLE
  74. | ClassFileConstants.ATTR_STACK_MAP))!=0;
  75. if (initFailureField != null) {
  76. // Changes to this exception handling code may require changes to
  77. // BcelClassWeaver.isInitFailureHandler()
  78. handlerLabel.placeEnd();
  79. BranchLabel endLabel = new BranchLabel(codeStream);
  80. codeStream.goto_(endLabel);
  81. // In order to keep stack map computation happy, need to give it more information, about the exception type
  82. // here and the local variable being used to track the exception (in the catch block)
  83. codeStream.pushExceptionOnStack(this.scope.getJavaLangThrowable());
  84. handlerLabel.place();
  85. LocalVariableBinding localVariableBinding = null;
  86. if (creatingStackMap) {
  87. localVariableBinding = new LocalVariableBinding("throwable".toCharArray(), this.scope.getJavaLangThrowable(), 0, false); //$NON-NLS-1$
  88. codeStream.addVariable(localVariableBinding);
  89. localVariableBinding.recordInitializationStartPC(codeStream.position);
  90. }
  91. codeStream.astore_0(); // Bug #52394
  92. // CHECK THIS...
  93. codeStream.addVariable(new LocalVariableBinding("caughtException".toCharArray(),initFailureField.type,ClassFileConstants.AccPrivate,false));
  94. codeStream.aload_0();
  95. if (creatingStackMap) {
  96. localVariableBinding.recordInitializationEndPC(codeStream.position);
  97. }
  98. codeStream.fieldAccess(Opcodes.OPC_putstatic, initFailureField, null);
  99. endLabel.place();
  100. }
  101. }
  102. }