1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler; 21 22 import java.util.Enumeration ; 23 24 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 25 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL; 26 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; 27 import com.sun.org.apache.bcel.internal.generic.InstructionList; 28 import com.sun.org.apache.bcel.internal.generic.NEW; 29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util; 34 35 38 final class ApplyImports extends Instruction { 39 40 private QName _modeName; 41 private String _functionName; 42 private int _precedence; 43 44 public void display(int indent) { 45 indent(indent); 46 Util.println("ApplyTemplates"); 47 indent(indent + IndentIncrement); 48 if (_modeName != null) { 49 indent(indent + IndentIncrement); 50 Util.println("mode " + _modeName); 51 } 52 } 53 54 57 public boolean hasWithParams() { 58 return hasContents(); 59 } 60 61 68 private int getMinPrecedence(int max) { 69 Stylesheet stylesheet = getStylesheet(); 70 Stylesheet root = getParser().getTopLevelStylesheet(); 71 72 int min = max; 73 74 Enumeration templates = root.getContents().elements(); 75 while (templates.hasMoreElements()) { 76 SyntaxTreeNode child = (SyntaxTreeNode)templates.nextElement(); 77 if (child instanceof Template) { 78 Stylesheet curr = child.getStylesheet(); 79 while ((curr != null) && (curr != stylesheet)) { 80 if (curr._importedFrom != null) 81 curr = curr._importedFrom; 82 else if (curr._includedFrom != null) 83 curr = curr._includedFrom; 84 else 85 curr = null; 86 } 87 if (curr == stylesheet) { 88 int prec = child.getStylesheet().getImportPrecedence(); 89 if (prec < min) min = prec; 90 } 91 } 92 } 93 return (min); 94 } 95 96 99 public void parseContents(Parser parser) { 100 Stylesheet stylesheet = getStylesheet(); 103 stylesheet.setTemplateInlining(false); 104 105 Template template = getTemplate(); 107 _modeName = template.getModeName(); 108 _precedence = template.getImportPrecedence(); 109 110 stylesheet = parser.getTopLevelStylesheet(); 112 113 final int maxPrecedence = _precedence; 116 final int minPrecedence = getMinPrecedence(maxPrecedence); 117 final Mode mode = stylesheet.getMode(_modeName); 118 _functionName = mode.functionName(minPrecedence, maxPrecedence); 119 120 parseChildren(parser); } 122 123 126 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 127 typeCheckContents(stable); return Type.Void; 129 } 130 131 135 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 136 final Stylesheet stylesheet = classGen.getStylesheet(); 137 final ConstantPoolGen cpg = classGen.getConstantPool(); 138 final InstructionList il = methodGen.getInstructionList(); 139 final int current = methodGen.getLocalIndex("current"); 140 141 il.append(classGen.loadTranslet()); 143 il.append(methodGen.loadDOM()); 144 int init = cpg.addMethodref(SINGLETON_ITERATOR, 146 "<init>", "("+NODE_SIG+")V"); 147 il.append(new NEW(cpg.addClass(SINGLETON_ITERATOR))); 148 il.append(DUP); 149 il.append(methodGen.loadCurrentNode()); 150 il.append(new INVOKESPECIAL(init)); 151 152 il.append(methodGen.loadHandler()); 153 154 final String className = classGen.getStylesheet().getClassName(); 156 final String signature = classGen.getApplyTemplatesSig(); 157 final int applyTemplates = cpg.addMethodref(className, 158 _functionName, 159 signature); 160 il.append(new INVOKEVIRTUAL(applyTemplates)); 161 } 162 163 } 164 | Popular Tags |