1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler; 21 22 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 23 import com.sun.org.apache.bcel.internal.generic.GETFIELD; 24 import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE; 25 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; 26 import com.sun.org.apache.bcel.internal.generic.PUSH; 27 import com.sun.org.apache.bcel.internal.generic.InstructionList; 28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 32 33 38 final class Comment extends Instruction { 39 40 public void parseContents(Parser parser) { 41 parseChildren(parser); 42 } 43 44 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 45 typeCheckContents(stable); 46 return Type.String; 47 } 48 49 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 50 final ConstantPoolGen cpg = classGen.getConstantPool(); 51 final InstructionList il = methodGen.getInstructionList(); 52 53 Text rawText = null; 55 if (elementCount() == 1) { 56 Object content = elementAt(0); 57 if (content instanceof Text) { 58 rawText = (Text) content; 59 } 60 } 61 62 if (rawText != null) { 67 il.append(methodGen.loadHandler()); 68 69 if (rawText.canLoadAsArrayOffsetLength()) { 70 rawText.loadAsArrayOffsetLength(classGen, methodGen); 71 final int comment = 72 cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, 73 "comment", 74 "([CII)V"); 75 il.append(new INVOKEINTERFACE(comment, 4)); 76 } else { 77 il.append(new PUSH(cpg, rawText.getText())); 78 final int comment = 79 cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, 80 "comment", 81 "(" + STRING_SIG + ")V"); 82 il.append(new INVOKEINTERFACE(comment, 2)); 83 } 84 } else { 85 il.append(methodGen.loadHandler()); 87 il.append(DUP); 89 il.append(classGen.loadTranslet()); 91 il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, 92 "stringValueHandler", 93 STRING_VALUE_HANDLER_SIG))); 94 il.append(DUP); 95 il.append(methodGen.storeHandler()); 96 97 translateContents(classGen, methodGen); 99 100 il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_VALUE_HANDLER, 102 "getValue", 103 "()" + STRING_SIG))); 104 final int comment = 106 cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, 107 "comment", 108 "(" + STRING_SIG + ")V"); 109 il.append(new INVOKEINTERFACE(comment, 2)); 110 il.append(methodGen.storeHandler()); 112 } 113 } 114 } 115 | Popular Tags |