1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler; 21 22 import java.util.Vector ; 23 24 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 25 import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC; 26 import com.sun.org.apache.bcel.internal.generic.InstructionList; 27 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 31 32 36 class NameBase extends FunctionCall { 37 38 private Expression _param = null; 39 private Type _paramType = Type.Node; 40 41 44 public NameBase(QName fname) { 45 super(fname); 46 } 47 48 51 public NameBase(QName fname, Vector arguments) { 52 super(fname, arguments); 53 _param = argument(0); 54 } 55 56 57 61 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 62 63 switch(argumentCount()) { 65 case 0: 66 _paramType = Type.Node; 67 break; 68 case 1: 69 _paramType = _param.typeCheck(stable); 70 break; 71 default: 72 throw new TypeCheckError(this); 73 } 74 75 if ((_paramType != Type.NodeSet) && 77 (_paramType != Type.Node) && 78 (_paramType != Type.Reference)) { 79 throw new TypeCheckError(this); 80 } 81 82 return (_type = Type.String); 83 } 84 85 public Type getType() { 86 return _type; 87 } 88 89 93 public void translate(ClassGenerator classGen, 94 MethodGenerator methodGen) { 95 final ConstantPoolGen cpg = classGen.getConstantPool(); 96 final InstructionList il = methodGen.getInstructionList(); 97 98 il.append(methodGen.loadDOM()); 99 100 if (argumentCount() == 0) { 102 il.append(methodGen.loadContextNode()); 103 } 104 else if (_paramType == Type.Node) { 106 _param.translate(classGen, methodGen); 107 } 108 else if (_paramType == Type.Reference) { 109 _param.translate(classGen, methodGen); 110 il.append(new INVOKESTATIC(cpg.addMethodref 111 (BASIS_LIBRARY_CLASS, 112 "referenceToNodeSet", 113 "(" 114 + OBJECT_SIG 115 + ")" 116 + NODE_ITERATOR_SIG))); 117 il.append(methodGen.nextNode()); 118 } 119 else { 121 _param.translate(classGen, methodGen); 122 _param.startIterator(classGen, methodGen); 123 il.append(methodGen.nextNode()); 124 } 125 } 126 } 127 | Popular Tags |