// simply go through all unmatched elements making sure they match the
// required pattern.
int[] indices = new int[pattern_elements.length];
for (int i = 0, j = 0; i != pattern_elements.length - 1; ++i) {
Pattern pat = pattern_elements[i].first();
int item = environment.allocate(Type.T_ANY());
int index = environment.allocate(Type.T_ANY());
String idx = "r" + index;
indices[i] = index;
// Construct the for-loop for this element
myOut(level++, "for(int " + idx + "=0;" + idx + "!=c" + source
+ ".size();++" + idx + ") {");
// Check that the current element from the source collection is not
// already matched. If this is the first pattern element (i.e. i ==
// 0), then we don't need to do anything since nothing could have
// been matched yet.
if (i != 0) {
indent(level);
out.print("if(");
// check against earlier indices
for (int k = 0; k < i; ++k) {
if (k != 0) {
out.print(" || ");
}
out.print(idx + " == r" + indices[k]);
}
out.println(") { continue; }");
}
myOut(level, "int r" + item + " = c" + source + ".get(" + idx
+ ");");
level = translatePatternMatch(level, pat, declared_elements[j], item, environment);
// Increment j upto (but not past) the final declared element.
j = Math.min(j + 1, declared_elements.length - 1);
}
// ====================================================================
// Third, check all remaining elements against the unbounded match.
// ====================================================================
int lastPatternElementIndex = pattern_elements.length-1;
Pattern lastPatternElement = pattern_elements[lastPatternElementIndex].first();
Type lastDeclaredElement = declared_elements[declared_elements.length-1];
int item = environment.allocate(Type.T_VOID());
if(!willSkip(lastPatternElement,lastDeclaredElement)) {