1 4 package gnu.kawa.xml; 5 import gnu.bytecode.*; 6 import gnu.mapping.*; 7 import gnu.expr.*; 8 9 11 12 public class SortNodes extends Procedure1 implements Inlineable 13 { 14 public static final SortNodes sortNodes = new SortNodes(); 15 16 public Object apply1 (Object values) 17 { 18 SortedNodes nodes = new SortedNodes(); 19 Values.writeValues(values, nodes); 20 if (nodes.count > 1) 21 return nodes; 22 else if (nodes.count == 0) 23 return Values.empty; 24 else 25 return nodes.get(0); 26 } 27 28 public void compile (ApplyExp exp, Compilation comp, Target target) 29 { 30 Expression[] args = exp.getArgs(); 31 if (args.length != 1 || ! comp.mustCompile) 32 ApplyExp.compile(exp, comp, target); 33 else 34 { 35 Method resultMethod; 36 if (target instanceof ConsumerTarget 37 || (target instanceof StackTarget 38 && target.getType().isSubtype(Compilation.typeValues))) 39 resultMethod = null; 40 else 41 resultMethod = canonicalizeMethod; 42 ConsumerTarget.compileUsingConsumer(args[0], comp, target, 43 makeSortedNodesMethod, 44 resultMethod); 45 } 46 } 47 48 public Type getReturnType (Expression[] args) 49 { 50 return Compilation.typeObject; 51 } 52 53 public static final ClassType typeSortedNodes 54 = ClassType.make("gnu.kawa.xml.SortedNodes"); 55 public static final Method makeSortedNodesMethod 56 = typeSortedNodes.getDeclaredMethod("<init>", 0); 57 public static final Method canonicalizeMethod 58 = Compilation.typeValues.getDeclaredMethod("canonicalize", 0); 59 } 60 | Popular Tags |