@@ -149,6 +149,7 @@ public static class MatcherContext {
149149 final boolean traceVariableEliminations ;
150150 final Map <RewriterStatement , RewriterRule .LinkObject > ruleLinks ;
151151 final RewriterStatement expressionRoot ;
152+ final RewriterStatement thisExpressionRoot ;
152153 RewriterStatement matchRoot ;
153154 RewriterPredecessor pred ;
154155
@@ -161,16 +162,21 @@ public static class MatcherContext {
161162 private List <MatcherContext > subMatches ;
162163 private Tuple2 <RewriterStatement , RewriterStatement > firstMismatch ;
163164 private boolean debug ;
165+ private boolean assertionsFetched = false ;
166+ private RewriterAssertions assertionsThat ;
167+ private RewriterAssertions assertionsThis ;
168+ private Set <RewriterStatement > dontVisitAgain ;
164169
165- public MatcherContext (final RuleContext ctx , RewriterStatement matchRoot , RewriterStatement expressionRoot ) {
166- this (ctx , matchRoot , expressionRoot , false , false , false , false , false , false , false , false , false , Collections .emptyMap ());
170+ public MatcherContext (final RuleContext ctx , RewriterStatement matchRoot , RewriterStatement expressionRoot , RewriterStatement thisExpressionRoot ) {
171+ this (ctx , matchRoot , expressionRoot , thisExpressionRoot , false , false , false , false , false , false , false , false , false , Collections .emptyMap ());
167172 }
168173
169- public MatcherContext (final RuleContext ctx , RewriterStatement matchRoot , RewriterStatement expressionRoot , final boolean statementsCanBeVariables , final boolean literalsCanBeVariables , final boolean ignoreLiteralValues , final boolean allowDuplicatePointers , final boolean allowPropertyScan , final boolean allowTypeHierarchy , final boolean terminateOnFirstMatch , final boolean findMinimalMismatchRoot , boolean traceVariableEliminations , final Map <RewriterStatement , RewriterRule .LinkObject > ruleLinks ) {
174+ public MatcherContext (final RuleContext ctx , RewriterStatement matchRoot , RewriterStatement expressionRoot , RewriterStatement thisExpressionRoot , final boolean statementsCanBeVariables , final boolean literalsCanBeVariables , final boolean ignoreLiteralValues , final boolean allowDuplicatePointers , final boolean allowPropertyScan , final boolean allowTypeHierarchy , final boolean terminateOnFirstMatch , final boolean findMinimalMismatchRoot , boolean traceVariableEliminations , final Map <RewriterStatement , RewriterRule .LinkObject > ruleLinks ) {
170175 this .ctx = ctx ;
171176 this .matchRoot = matchRoot ;
172177 this .pred = new RewriterPredecessor ();
173178 this .expressionRoot = expressionRoot ;
179+ this .thisExpressionRoot = thisExpressionRoot ;
174180 this .statementsCanBeVariables = statementsCanBeVariables ;
175181 this .currentStatement = matchRoot ;
176182 this .literalsCanBeVariables = literalsCanBeVariables ;
@@ -185,11 +191,12 @@ public MatcherContext(final RuleContext ctx, RewriterStatement matchRoot, Rewrit
185191 this .debug = false ;
186192 }
187193
188- public MatcherContext (final RuleContext ctx , RewriterStatement matchRoot , RewriterPredecessor pred , RewriterStatement expressionRoot , final boolean statementsCanBeVariables , final boolean literalsCanBeVariables , final boolean ignoreLiteralValues , final boolean allowDuplicatePointers , final boolean allowPropertyScan , final boolean allowTypeHierarchy , final boolean terminateOnFirstMatch , final boolean findMinimalMismatchRoot , boolean traceVariableEliminations , final Map <RewriterStatement , RewriterRule .LinkObject > ruleLinks ) {
194+ public MatcherContext (final RuleContext ctx , RewriterStatement matchRoot , RewriterPredecessor pred , RewriterStatement expressionRoot , RewriterStatement thisExprRoot , final boolean statementsCanBeVariables , final boolean literalsCanBeVariables , final boolean ignoreLiteralValues , final boolean allowDuplicatePointers , final boolean allowPropertyScan , final boolean allowTypeHierarchy , final boolean terminateOnFirstMatch , final boolean findMinimalMismatchRoot , boolean traceVariableEliminations , final Map <RewriterStatement , RewriterRule .LinkObject > ruleLinks ) {
189195 this .ctx = ctx ;
190196 this .matchRoot = matchRoot ;
191197 this .pred = pred ;
192198 this .expressionRoot = expressionRoot ;
199+ this .thisExpressionRoot = thisExprRoot ;
193200 this .currentStatement = matchRoot ;
194201 this .statementsCanBeVariables = statementsCanBeVariables ;
195202 this .literalsCanBeVariables = literalsCanBeVariables ;
@@ -204,6 +211,41 @@ public MatcherContext(final RuleContext ctx, RewriterStatement matchRoot, Rewrit
204211 this .debug = false ;
205212 }
206213
214+ private void fetchAssertions () {
215+ if (!assertionsFetched ) {
216+ assertionsThat = (RewriterAssertions ) expressionRoot .getMeta ("_assertions" );
217+ assertionsThis = (RewriterAssertions ) thisExpressionRoot .getMeta ("_assertions" );
218+ assertionsFetched = true ;
219+ }
220+ }
221+
222+ public void dontVisitAgain (RewriterStatement stmt ) {
223+ if (dontVisitAgain == null ) {
224+ dontVisitAgain = new HashSet <>();
225+ }
226+
227+ dontVisitAgain .add (stmt );
228+ }
229+
230+ public boolean wasVisited (RewriterStatement stmt ) {
231+ if (dontVisitAgain == null )
232+ return false ;
233+
234+ return dontVisitAgain .contains (stmt );
235+ }
236+
237+ public RewriterAssertions getOldAssertionsThat () {
238+ fetchAssertions ();
239+
240+ return assertionsThat ;
241+ }
242+
243+ public RewriterAssertions getOldAssertionsThis () {
244+ fetchAssertions ();
245+
246+ return assertionsThis ;
247+ }
248+
207249 public Map <RewriterStatement , RewriterStatement > getDependencyMap () {
208250 if (dependencyMap == null )
209251 if (allowDuplicatePointers )
@@ -304,16 +346,16 @@ public boolean isDebug() {
304346 return debug ;
305347 }
306348
307- public static MatcherContext exactMatch (final RuleContext ctx , RewriterStatement stmt ) {
308- return new MatcherContext (ctx , stmt , stmt );
349+ public static MatcherContext exactMatch (final RuleContext ctx , RewriterStatement stmt , RewriterStatement thisExprRoot ) {
350+ return new MatcherContext (ctx , stmt , stmt , thisExprRoot );
309351 }
310352
311- public static MatcherContext exactMatchWithDifferentLiteralValues (final RuleContext ctx , RewriterStatement stmt ) {
312- return new MatcherContext (ctx , stmt , stmt , false , false , true , false , false , false , false , false , false , Collections .emptyMap ());
353+ public static MatcherContext exactMatchWithDifferentLiteralValues (final RuleContext ctx , RewriterStatement stmt , RewriterStatement thisExprRoot ) {
354+ return new MatcherContext (ctx , stmt , stmt , thisExprRoot , false , false , true , false , false , false , false , false , false , Collections .emptyMap ());
313355 }
314356
315- public static MatcherContext findMinimalDifference (final RuleContext ctx , RewriterStatement stmt ) {
316- return new MatcherContext (ctx , stmt , stmt , false , false , true , false , false , false , false , true , false , Collections .emptyMap ());
357+ public static MatcherContext findMinimalDifference (final RuleContext ctx , RewriterStatement stmt , RewriterStatement thisExpressionRoot ) {
358+ return new MatcherContext (ctx , stmt , stmt , thisExpressionRoot , false , false , true , false , false , false , false , true , false , Collections .emptyMap ());
317359 }
318360 }
319361
0 commit comments