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.

ConcreteCflowPointcut.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.DataOutputStream;
  14. import java.io.IOException;
  15. import java.util.Iterator;
  16. import java.util.List;
  17. import java.util.Set;
  18. import org.aspectj.util.FuzzyBoolean;
  19. import org.aspectj.weaver.IntMap;
  20. import org.aspectj.weaver.Member;
  21. import org.aspectj.weaver.NameMangler;
  22. import org.aspectj.weaver.ResolvedTypeX;
  23. import org.aspectj.weaver.Shadow;
  24. import org.aspectj.weaver.TypeX;
  25. import org.aspectj.weaver.ast.Expr;
  26. import org.aspectj.weaver.ast.Test;
  27. import org.aspectj.weaver.bcel.BcelCflowAccessVar;
  28. public class ConcreteCflowPointcut extends Pointcut {
  29. private Member cflowField;
  30. List/*Slot*/ slots; // exposed for testing
  31. boolean usesCounter;
  32. // Can either use a counter or a stack to implement cflow.
  33. public ConcreteCflowPointcut(Member cflowField, List slots,boolean usesCounter) {
  34. this.cflowField = cflowField;
  35. this.slots = slots;
  36. this.usesCounter = usesCounter;
  37. this.pointcutKind = CFLOW;
  38. }
  39. public Set couldMatchKinds() {
  40. return Shadow.ALL_SHADOW_KINDS;
  41. }
  42. public FuzzyBoolean fastMatch(FastMatchInfo type) {
  43. return FuzzyBoolean.MAYBE;
  44. }
  45. protected FuzzyBoolean matchInternal(Shadow shadow) {
  46. //??? this is not maximally efficient
  47. return FuzzyBoolean.MAYBE;
  48. }
  49. /* (non-Javadoc)
  50. * @see org.aspectj.weaver.patterns.Pointcut#matchesDynamically(java.lang.Object, java.lang.Object, java.lang.Object[])
  51. */
  52. public boolean matchesDynamically(Object thisObject, Object targetObject,
  53. Object[] args) {
  54. throw new UnsupportedOperationException("cflow pointcut matching not supported by this operation");
  55. }
  56. /* (non-Javadoc)
  57. * @see org.aspectj.weaver.patterns.Pointcut#matchesStatically(java.lang.String, java.lang.reflect.Member, java.lang.Class, java.lang.Class, java.lang.reflect.Member)
  58. */
  59. public FuzzyBoolean matchesStatically(
  60. String joinpointKind, java.lang.reflect.Member member,
  61. Class thisClass, Class targetClass,
  62. java.lang.reflect.Member withinCode) {
  63. throw new UnsupportedOperationException("cflow pointcut matching not supported by this operation");
  64. }
  65. // used by weaver when validating bindings
  66. public int[] getUsedFormalSlots() {
  67. if (slots == null) return new int[0];
  68. int[] indices = new int[slots.size()];
  69. for (int i = 0; i < indices.length; i++) {
  70. indices[i] = ((Slot)slots.get(i)).formalIndex;
  71. }
  72. return indices;
  73. }
  74. public void write(DataOutputStream s) throws IOException {
  75. throw new RuntimeException("unimplemented");
  76. }
  77. public void resolveBindings(IScope scope, Bindings bindings) {
  78. throw new RuntimeException("unimplemented");
  79. }
  80. public void resolveBindingsFromRTTI() {
  81. throw new RuntimeException("unimplemented");
  82. }
  83. public boolean equals(Object other) {
  84. if (!(other instanceof ConcreteCflowPointcut)) return false;
  85. ConcreteCflowPointcut o = (ConcreteCflowPointcut)other;
  86. return o.cflowField.equals(this.cflowField);
  87. }
  88. public int hashCode() {
  89. int result = 17;
  90. result = 37*result + cflowField.hashCode();
  91. return result;
  92. }
  93. public String toString() {
  94. return "concretecflow(" + cflowField + ")";
  95. }
  96. protected Test findResidueInternal(Shadow shadow, ExposedState state) {
  97. //System.out.println("find residue: " + this);
  98. if (usesCounter) {
  99. return Test.makeFieldGetCall(cflowField, cflowCounterIsValidMethod, Expr.NONE);
  100. } else {
  101. if (slots != null) { // null for cflows managed by counters
  102. for (Iterator i = slots.iterator(); i.hasNext();) {
  103. Slot slot = (Slot) i.next();
  104. //System.out.println("slot: " + slot.formalIndex);
  105. state.set(slot.formalIndex,
  106. new BcelCflowAccessVar(slot.formalType, cflowField, slot.arrayIndex));
  107. }
  108. }
  109. return Test.makeFieldGetCall(cflowField, cflowStackIsValidMethod, Expr.NONE);
  110. }
  111. }
  112. private static final Member cflowStackIsValidMethod =
  113. Member.method(TypeX.forName(NameMangler.CFLOW_STACK_TYPE), 0, "isValid", "()Z");
  114. private static final Member cflowCounterIsValidMethod =
  115. Member.method(TypeX.forName(NameMangler.CFLOW_COUNTER_TYPE), 0, "isValid", "()Z");
  116. public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
  117. throw new RuntimeException("unimplemented");
  118. }
  119. public static class Slot {
  120. int formalIndex;
  121. ResolvedTypeX formalType;
  122. int arrayIndex;
  123. public Slot(
  124. int formalIndex,
  125. ResolvedTypeX formalType,
  126. int arrayIndex) {
  127. this.formalIndex = formalIndex;
  128. this.formalType = formalType;
  129. this.arrayIndex = arrayIndex;
  130. }
  131. public boolean equals(Object other) {
  132. if (!(other instanceof Slot)) return false;
  133. Slot o = (Slot)other;
  134. return o.formalIndex == this.formalIndex &&
  135. o.arrayIndex == this.arrayIndex &&
  136. o.formalType.equals(this.formalType);
  137. }
  138. public String toString() {
  139. return "Slot(" + formalIndex + ", " + formalType + ", " + arrayIndex + ")";
  140. }
  141. }
  142. }