Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AspectClinit.java 4.7KB

vor 21 Jahren
vor 21 Jahren
vor 16 Jahren
vor 21 Jahren
vor 21 Jahren
vor 21 Jahren
vor 21 Jahren
vor 21 Jahren
vor 21 Jahren
vor 21 Jahren
vor 21 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  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.weaver.AjcMemberMaker;
  25. public class AspectClinit extends Clinit {
  26. private boolean hasPre, hasPost;
  27. private FieldBinding initFailureField;
  28. public AspectClinit(Clinit old, CompilationResult compilationResult, boolean hasPre, boolean hasPost, FieldBinding initFailureField) {
  29. super(compilationResult);
  30. // CHECK do we need all the bits or just the needfreereturn bit?
  31. // if ((old.bits & ASTNode.NeedFreeReturn)!=0) this.bits |= ASTNode.NeedFreeReturn;
  32. this.bits = old.bits;
  33. this.sourceEnd = old.sourceEnd;
  34. this.sourceStart = old.sourceStart;
  35. this.declarationSourceEnd = old.declarationSourceEnd;
  36. this.declarationSourceStart = old.declarationSourceStart;
  37. this.hasPre = hasPre;
  38. this.hasPost = hasPost;
  39. this.initFailureField = initFailureField;
  40. }
  41. private ExceptionLabel handlerLabel;
  42. protected void generateSyntheticCode(
  43. ClassScope classScope,
  44. CodeStream codeStream)
  45. {
  46. if (initFailureField != null) {
  47. handlerLabel = new ExceptionLabel(codeStream, classScope.getJavaLangThrowable());
  48. handlerLabel.placeStart();
  49. }
  50. if (hasPre) {
  51. final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(classScope);
  52. codeStream.invoke(Opcodes.OPC_invokestatic,world.makeMethodBindingForCall(
  53. AjcMemberMaker.ajcPreClinitMethod(
  54. world.fromBinding(classScope.referenceContext.binding)
  55. )),null);
  56. }
  57. super.generateSyntheticCode(classScope, codeStream);
  58. }
  59. protected void generatePostSyntheticCode(
  60. ClassScope classScope,
  61. CodeStream codeStream)
  62. {
  63. super.generatePostSyntheticCode(classScope, codeStream);
  64. if (hasPost) {
  65. final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(classScope);
  66. codeStream.invoke(Opcodes.OPC_invokestatic,world.makeMethodBindingForCall(
  67. AjcMemberMaker.ajcPostClinitMethod(
  68. world.fromBinding(classScope.referenceContext.binding)
  69. )),null);
  70. }
  71. boolean creatingStackMap = (codeStream.generateAttributes & (
  72. ClassFileConstants.ATTR_STACK_MAP_TABLE
  73. | ClassFileConstants.ATTR_STACK_MAP))!=0;
  74. if (initFailureField != null) {
  75. // Changes to this exception handling code may require changes to
  76. // BcelClassWeaver.isInitFailureHandler()
  77. handlerLabel.placeEnd();
  78. BranchLabel endLabel = new BranchLabel(codeStream);
  79. codeStream.goto_(endLabel);
  80. // In order to keep stack map computation happy, need to give it more information, about the exception type
  81. // here and the local variable being used to track the exception (in the catch block)
  82. codeStream.pushExceptionOnStack(this.scope.getJavaLangThrowable());
  83. handlerLabel.place();
  84. LocalVariableBinding localVariableBinding = null;
  85. if (creatingStackMap) {
  86. localVariableBinding = new LocalVariableBinding("throwable".toCharArray(), this.scope.getJavaLangThrowable(), 0, false); //$NON-NLS-1$
  87. codeStream.addVariable(localVariableBinding);
  88. localVariableBinding.recordInitializationStartPC(codeStream.position);
  89. }
  90. codeStream.astore_0(); // Bug #52394
  91. // CHECK THIS...
  92. codeStream.addVariable(new LocalVariableBinding("caughtException".toCharArray(),initFailureField.type,ClassFileConstants.AccPrivate,false));
  93. codeStream.aload_0();
  94. if (creatingStackMap) {
  95. localVariableBinding.recordInitializationEndPC(codeStream.position);
  96. }
  97. codeStream.fieldAccess(Opcodes.OPC_putstatic, initFailureField, null);
  98. endLabel.place();
  99. }
  100. }
  101. }