final int initNI = cpg.addMethodref(NTH_ITERATOR_CLASS, "<init>", "(" + NODE_ITERATOR_SIG + "I)V"); il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS))); il.append(DUP); translatePredicates(classGen, methodGen); predicate.translate(classGen, methodGen); il.append(new INVOKESPECIAL(initNI));
if ((_axis == 4) || (_axis == 5)) { il.append(methodGen.loadDOM()); System.err.println("node type is "+_nodeType); il.append(new PUSH(cpg, _nodeType)); predicate.translate(classGen, methodGen); int iter = cpg.addInterfaceMethodref(DOM_INTF, "getNthDescendant", "(II)"+NODE_ITERATOR_SIG); il.append(new INVOKEINTERFACE(iter, 3)); } else { final int initNI = cpg.addMethodref(NTH_ITERATOR_CLASS, "<init>", "(" + NODE_ITERATOR_SIG + "I)V"); il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS))); il.append(DUP); translatePredicates(classGen, methodGen); predicate.translate(classGen, methodGen); il.append(new INVOKESPECIAL(initNI)); }
    public void translatePredicates(ClassGenerator classGen,				    MethodGenerator methodGen) {	final ConstantPoolGen cpg = classGen.getConstantPool();	final InstructionList il = methodGen.getInstructionList();	if (_predicates.size() == 0) {	    translate(classGen, methodGen);	}	else {	    final Predicate predicate = (Predicate)_predicates.lastElement();	    _predicates.remove(predicate);	    // Special case for predicates that can use the NodeValueIterator	    // instead of an auxiliary class. Certain path/predicates pairs	    // are translated into a base path, on top of which we place a	    // node value iterator that tests for the desired value:	    //   foo[@attr = 'str']  ->  foo/@attr + test(value='str')	    //   foo[bar = 'str']    ->  foo/bar + test(value='str')	    //   foo/bar[. = 'str']  ->  foo/bar + test(value='str')	    if (predicate.isNodeValueTest()) {		Step step = predicate.getStep();		il.append(methodGen.loadDOM());		// If the predicate's Step is simply '.' we translate this Step		// and place the node test on top of the resulting iterator		if (step.isAbbreviatedDot()) {		    translate(classGen, methodGen);		    il.append(new ICONST(DOM.RETURN_CURRENT));		}		// Otherwise we create a parent location path with this Step and		// the predicates Step, and place the node test on top of that		else {		    ParentLocationPath path = new ParentLocationPath(this,step);		    try {			path.typeCheck(getParser().getSymbolTable());		    }		    catch (TypeCheckError e) { }		    path.translate(classGen, methodGen);		    il.append(new ICONST(DOM.RETURN_PARENT));		}		predicate.translate(classGen, methodGen);		int iter = cpg.addInterfaceMethodref(DOM_INTF,					     GET_NODE_VALUE_ITERATOR,					     GET_NODE_VALUE_ITERATOR_SIG);		il.append(new INVOKEINTERFACE(iter, 5));	    }	    // Handle '//*[n]' expression	    else if (predicate.isNthDescendant()) {		il.append(methodGen.loadDOM());		il.append(methodGen.loadContextNode());		predicate.translate(classGen, methodGen);		int iter = cpg.addInterfaceMethodref(DOM_INTF,						     "getNthDescendant",						     "(II)"+NODE_ITERATOR_SIG);		il.append(new INVOKEINTERFACE(iter, 3));	    }	    // Handle 'elem[n]' expression	    else if (predicate.isNthPositionFilter()) {		final int initNI =		    cpg.addMethodref(NTH_ITERATOR_CLASS,				     "<init>",				     "(" + NODE_ITERATOR_SIG + "I)V");		il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));		il.append(DUP);		translatePredicates(classGen, methodGen); // recursive call		predicate.translate(classGen, methodGen);		il.append(new INVOKESPECIAL(initNI));	    }	    else {		final int init = cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,						  "<init>",						  "("						  + NODE_ITERATOR_SIG						  + CURRENT_NODE_LIST_FILTER_SIG						  + NODE_SIG						  + TRANSLET_SIG						  + ")V");		// create new CurrentNodeListIterator		il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));		il.append(DUP);		translatePredicates(classGen, methodGen); // recursive call		predicate.translate(classGen, methodGen);				il.append(methodGen.loadCurrentNode());		il.append(classGen.loadTranslet());		if (classGen.isExternal()) {		    final String className = classGen.getClassName();		    il.append(new CHECKCAST(cpg.addClass(className)));		}		il.append(new INVOKESPECIAL(init));	    }	}    }