1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/* *******************************************************************
* Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* PARC initial implementation
* ******************************************************************/
package org.aspectj.weaver.patterns;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.Message;
import org.aspectj.util.FuzzyBoolean;
import org.aspectj.weaver.CompressingDataOutputStream;
import org.aspectj.weaver.IntMap;
import org.aspectj.weaver.Member;
import org.aspectj.weaver.MemberImpl;
import org.aspectj.weaver.NameMangler;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.Shadow;
import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.WeaverMessages;
import org.aspectj.weaver.World;
import org.aspectj.weaver.ast.Expr;
import org.aspectj.weaver.ast.Test;
public class ConcreteCflowPointcut extends Pointcut {
private final Member cflowField;
List<Slot> slots; // exposed for testing
boolean usesCounter;
ResolvedType aspect;
// Can either use a counter or a stack to implement cflow.
public ConcreteCflowPointcut(ResolvedType aspect, Member cflowField, List<Slot> slots, boolean usesCounter) {
this.aspect = aspect;
this.cflowField = cflowField;
this.slots = slots;
this.usesCounter = usesCounter;
this.pointcutKind = CFLOW;
}
public int couldMatchKinds() {
return Shadow.ALL_SHADOW_KINDS_BITS;
}
public FuzzyBoolean fastMatch(FastMatchInfo type) {
return FuzzyBoolean.MAYBE;
}
protected FuzzyBoolean matchInternal(Shadow shadow) {
// ??? this is not maximally efficient
// Check we'll be able to do the residue!
// this bit is for pr145693 - we cannot match at all if one of the types is missing, we will be unable
// to create the residue
if (slots != null) {
for (Slot slot: slots) {
ResolvedType rt = slot.formalType;
if (rt.isMissing()) {
ISourceLocation[] locs = new ISourceLocation[] { getSourceLocation() };
Message m = new Message(WeaverMessages.format(WeaverMessages.MISSING_TYPE_PREVENTS_MATCH, rt.getName()), "",
Message.WARNING, shadow.getSourceLocation(), null, locs);
rt.getWorld().getMessageHandler().handleMessage(m);
return FuzzyBoolean.NO;
}
}
}
return FuzzyBoolean.MAYBE;
}
// used by weaver when validating bindings
public int[] getUsedFormalSlots() {
if (slots == null) {
return new int[0];
}
int[] indices = new int[slots.size()];
for (int i = 0; i < indices.length; i++) {
indices[i] = ((Slot) slots.get(i)).formalIndex;
}
return indices;
}
public void write(CompressingDataOutputStream s) throws IOException {
throw new RuntimeException("unimplemented");
}
public void resolveBindings(IScope scope, Bindings bindings) {
throw new RuntimeException("unimplemented");
}
public Pointcut parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w) {
throw new RuntimeException("unimplemented");
}
public boolean equals(Object other) {
if (!(other instanceof ConcreteCflowPointcut)) {
return false;
}
ConcreteCflowPointcut o = (ConcreteCflowPointcut) other;
return o.cflowField.equals(this.cflowField);
}
public int hashCode() {
int result = 17;
result = 37 * result + cflowField.hashCode();
return result;
}
public String toString() {
return "concretecflow(" + cflowField + ")";
}
protected Test findResidueInternal(Shadow shadow, ExposedState state) {
// System.out.println("find residue: " + this);
if (usesCounter) {
return Test.makeFieldGetCall(cflowField, cflowCounterIsValidMethod, Expr.NONE);
} else {
if (slots != null) { // null for cflows managed by counters
for (Slot slot: slots) {
// System.out.println("slot: " + slot.formalIndex);
state.set(slot.formalIndex,
aspect.getWorld().getWeavingSupport().makeCflowAccessVar(slot.formalType, cflowField, slot.arrayIndex));
}
}
return Test.makeFieldGetCall(cflowField, cflowStackIsValidMethod, Expr.NONE);
}
}
private static final Member cflowStackIsValidMethod = MemberImpl.method(NameMangler.CFLOW_STACK_UNRESOLVEDTYPE, 0,
UnresolvedType.BOOLEAN, "isValid", UnresolvedType.NONE);
private static final Member cflowCounterIsValidMethod = MemberImpl.method(NameMangler.CFLOW_COUNTER_UNRESOLVEDTYPE, 0,
UnresolvedType.BOOLEAN, "isValid", UnresolvedType.NONE);
public Pointcut concretize1(ResolvedType inAspect, ResolvedType declaringType, IntMap bindings) {
throw new RuntimeException("unimplemented");
}
public Object accept(PatternNodeVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public static class Slot {
int formalIndex;
ResolvedType formalType;
int arrayIndex;
public Slot(int formalIndex, ResolvedType formalType, int arrayIndex) {
this.formalIndex = formalIndex;
this.formalType = formalType;
this.arrayIndex = arrayIndex;
}
public boolean equals(Object other) {
if (!(other instanceof Slot)) {
return false;
}
Slot o = (Slot) other;
return o.formalIndex == this.formalIndex && o.arrayIndex == this.arrayIndex && o.formalType.equals(this.formalType);
}
public int hashCode() {
int result = 19;
result = 37 * result + formalIndex;
result = 37 * result + arrayIndex;
result = 37 * result + formalType.hashCode();
return result;
}
public String toString() {
return "Slot(" + formalIndex + ", " + formalType + ", " + arrayIndex + ")";
}
}
}
|