com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator Java Examples

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PositionCall.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();

    if (methodGen instanceof CompareGenerator) {
        il.append(((CompareGenerator)methodGen).loadCurrentNode());
    }
    else if (methodGen instanceof TestGenerator) {
        il.append(new ILOAD(POSITION_INDEX));
    }
    else {
        final ConstantPoolGen cpg = classGen.getConstantPool();
        final int index = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                                   "getPosition",
                                                   "()I");

        il.append(methodGen.loadIterator());
        il.append(new INVOKEINTERFACE(index,1));
    }
}
 
Example #2
Source File: Predicate.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Translate a predicate expression. If non of the optimizations apply
 * then this translation pushes two references on the stack: a reference
 * to a newly created filter object and a reference to the predicate's
 * closure. See class <code>Step</code> for further details.
 */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {

    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_nthPositionFilter || _nthDescendant) {
        _exp.translate(classGen, methodGen);
    }
    else if (isNodeValueTest() && (getParent() instanceof Step)) {
        _value.translate(classGen, methodGen);
        il.append(new CHECKCAST(cpg.addClass(STRING_CLASS)));
        il.append(new PUSH(cpg, ((EqualityExpr)_exp).getOp()));
    }
    else {
        translateFilter(classGen, methodGen);
    }
}
 
Example #3
Source File: Text.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generates code that loads the array that will contain the character
 * data represented by this Text node, followed by the offset of the
 * data from the start of the array, and then the length of the data.
 *
 * The pre-condition to calling this method is that
 * canLoadAsArrayOffsetLength() returns true.
 * @see #canLoadArrayOffsetLength()
 */
public void loadAsArrayOffsetLength(ClassGenerator classGen,
                                    MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final XSLTC xsltc = classGen.getParser().getXSLTC();

    // The XSLTC object keeps track of character data
    // that is to be stored in char arrays.
    final int offset = xsltc.addCharacterData(_text);
    final int length = _text.length();
    String charDataFieldName =
        STATIC_CHAR_DATA_FIELD + (xsltc.getCharacterDataCount()-1);

    il.append(new GETSTATIC(cpg.addFieldref(xsltc.getClassName(),
                                   charDataFieldName,
                                   STATIC_CHAR_DATA_FIELD_SIG)));
    il.append(new PUSH(cpg, offset));
    il.append(new PUSH(cpg, _text.length()));
}
 
Example #4
Source File: SyntaxTreeNode.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Call translate() on all child syntax tree nodes.
 * @param classGen BCEL Java class generator
 * @param methodGen BCEL Java method generator
 */
protected void translateContents(ClassGenerator classGen,
                                 MethodGenerator methodGen) {
    // Call translate() on all child nodes
    final int n = elementCount();

    for (int i = 0; i < n; i++) {
        methodGen.markChunkStart();
        final SyntaxTreeNode item = (SyntaxTreeNode)_contents.elementAt(i);
        item.translate(classGen, methodGen);
        methodGen.markChunkEnd();
    }

    // After translation, unmap any registers for any variables/parameters
    // that were declared in this scope. Performing this unmapping in the
    // same AST scope as the declaration deals with the problems of
    // references falling out-of-scope inside the for-each element.
    // (the cause of which being 'lazy' register allocation for references)
    for (int i = 0; i < n; i++) {
        if( _contents.elementAt(i) instanceof VariableBase) {
            final VariableBase var = (VariableBase)_contents.elementAt(i);
            var.unmapRegister(methodGen);
        }
    }
}
 
Example #5
Source File: Mode.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void compileTemplateCalls(ClassGenerator classGen,
                                  MethodGenerator methodGen,
                                  InstructionHandle next, int min, int max){
    for (Template template : _neededTemplates.keySet()) {
        final int prec = template.getImportPrecedence();
        if ((prec >= min) && (prec < max)) {
            if (template.hasContents()) {
                InstructionList til = template.compile(classGen, methodGen);
                til.append(new GOTO_W(next));
                _templateILs.put(template, til);
                _templateIHs.put(template, til.getStart());
            }
            else {
                // empty template
                _templateIHs.put(template, next);
            }
        }
    }
}
 
Example #6
Source File: Text.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generates code that loads the array that will contain the character
 * data represented by this Text node, followed by the offset of the
 * data from the start of the array, and then the length of the data.
 *
 * The pre-condition to calling this method is that
 * canLoadAsArrayOffsetLength() returns true.
 * @see #canLoadArrayOffsetLength()
 */
public void loadAsArrayOffsetLength(ClassGenerator classGen,
                                    MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final XSLTC xsltc = classGen.getParser().getXSLTC();

    // The XSLTC object keeps track of character data
    // that is to be stored in char arrays.
    final int offset = xsltc.addCharacterData(_text);
    final int length = _text.length();
    String charDataFieldName =
        STATIC_CHAR_DATA_FIELD + (xsltc.getCharacterDataCount()-1);

    il.append(new GETSTATIC(cpg.addFieldref(xsltc.getClassName(),
                                   charDataFieldName,
                                   STATIC_CHAR_DATA_FIELD_SIG)));
    il.append(new PUSH(cpg, offset));
    il.append(new PUSH(cpg, _text.length()));
}
 
Example #7
Source File: NumberCall.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    Type targ;

    if (argumentCount() == 0) {
        il.append(methodGen.loadContextNode());
        targ = Type.Node;
    }
    else {
        final Expression arg = argument();
        arg.translate(classGen, methodGen);
        arg.startIterator(classGen, methodGen);
        targ = arg.getType();
    }

    if (!targ.identicalTo(Type.Real)) {
        targ.translateTo(classGen, methodGen, Type.Real);
    }
}
 
Example #8
Source File: FunctionCall.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Compile the function call and treat as an expression
 * Update true/false-lists.
 */
@Override
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen)
{
    Type type = Type.Boolean;
    if (_chosenMethodType != null)
        type = _chosenMethodType.resultType();

    final InstructionList il = methodGen.getInstructionList();
    translate(classGen, methodGen);

    if ((type instanceof BooleanType) || (type instanceof IntType)) {
        _falseList.add(il.append(new IFEQ(null)));
    }
}
 
Example #9
Source File: FormatNumberCall.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    _value.translate(classGen, methodGen);
    _format.translate(classGen, methodGen);

    final int fn3arg = cpg.addMethodref(BASIS_LIBRARY_CLASS,
                                        "formatNumber",
                                        "(DLjava/lang/String;"+
                                        "Ljava/text/DecimalFormat;)"+
                                        "Ljava/lang/String;");
    final int get = cpg.addMethodref(TRANSLET_CLASS,
                                     "getDecimalFormat",
                                     "(Ljava/lang/String;)"+
                                     "Ljava/text/DecimalFormat;");

    il.append(classGen.loadTranslet());
    if (_name == null) {
        il.append(new PUSH(cpg, EMPTYSTRING));
    }
    else if (_resolvedQName != null) {
        il.append(new PUSH(cpg, _resolvedQName.toString()));
    }
    else {
        _name.translate(classGen, methodGen);
    }
    il.append(new INVOKEVIRTUAL(get));
    il.append(new INVOKESTATIC(fn3arg));
}
 
Example #10
Source File: AlternativePattern.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();

    _left.translate(classGen, methodGen);
    final InstructionHandle gotot = il.append(new GOTO(null));
    il.append(methodGen.loadContextNode());
    _right.translate(classGen, methodGen);

    _left._trueList.backPatch(gotot);
    _left._falseList.backPatch(gotot.getNext());

    _trueList.append(_right._trueList.add(gotot));
    _falseList.append(_right._falseList);
}
 
Example #11
Source File: RoundCall.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Get two copies of the argument on the stack
    argument().translate(classGen, methodGen);
            il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS,
                                                        "roundF", "(D)D")));
}
 
Example #12
Source File: ContainsCall.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compile expression and update true/false-lists
 */
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    _base.translate(classGen, methodGen);
    _token.translate(classGen, methodGen);
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS,
                                                 "indexOf",
                                                 "("+STRING_SIG+")I")));
    _falseList.add(il.append(new IFLT(null)));
}
 
Example #13
Source File: TopLevelElement.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Translate this node into a fresh instruction list.
 * The original instruction list is saved and restored.
 */
public InstructionList compile(ClassGenerator classGen,
                               MethodGenerator methodGen) {
    final InstructionList result, save = methodGen.getInstructionList();
    methodGen.setInstructionList(result = new InstructionList());
    translate(classGen, methodGen);
    methodGen.setInstructionList(save);
    return result;
}
 
Example #14
Source File: FilterExpr.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void translateFilterExpr(ClassGenerator classGen,
                                 MethodGenerator methodGen,
                                 int predicateIndex) {
    if (predicateIndex >= 0) {
        translatePredicates(classGen, methodGen, predicateIndex);
    }
    else {
        _primary.translate(classGen, methodGen);
    }
}
 
Example #15
Source File: StringLengthCall.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (argumentCount() > 0) {
        argument().translate(classGen, methodGen);
    }
    else {
        il.append(methodGen.loadContextNode());
        Type.Node.translateTo(classGen, methodGen, Type.String);
    }
    il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS,
                                                 "getStringLength",
                                                 "(Ljava/lang/String;)I")));
}
 
Example #16
Source File: VariableBase.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Map this variable to a register
 */
public void mapRegister(MethodGenerator methodGen) {
    if (_local == null) {
        final InstructionList il = methodGen.getInstructionList();
        final String name = getEscapedName(); // TODO: namespace ?
        final com.sun.org.apache.bcel.internal.generic.Type varType = _type.toJCType();
        _local = methodGen.addLocalVariable2(name, varType, il.getEnd());
    }
}
 
Example #17
Source File: BooleanExpr.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    if (_value) {
        il.append(NOP);     // true list falls through
    }
    else {
        _falseList.add(il.append(new GOTO(null)));
    }
}
 
Example #18
Source File: NamespaceUriCall.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Translate code that leaves a node's namespace URI (as a String)
 * on the stack
 */
public void translate(ClassGenerator classGen,
                      MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Returns the string value for a node in the DOM
    final int getNamespace = cpg.addInterfaceMethodref(DOM_INTF,
                                                       "getNamespaceName",
                                                       "(I)"+STRING_SIG);
    super.translate(classGen, methodGen);
    il.append(new INVOKEINTERFACE(getNamespace, 2));
}
 
Example #19
Source File: StartsWithCall.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compile the expression - leave boolean expression on stack
 */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    _base.translate(classGen, methodGen);
    _token.translate(classGen, methodGen);
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS,
                                                 "startsWith",
                                                 "("+STRING_SIG+")Z")));
}
 
Example #20
Source File: ContainsCall.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Compile expression and update true/false-lists
 */
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    _base.translate(classGen, methodGen);
    _token.translate(classGen, methodGen);
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS,
                                                 "indexOf",
                                                 "("+STRING_SIG+")I")));
    _falseList.add(il.append(new IFLT(null)));
}
 
Example #21
Source File: Expression.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Translate this node into a fresh instruction list.
 * The original instruction list is saved and restored.
 */
public final InstructionList compile(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final InstructionList result, save = methodGen.getInstructionList();
    methodGen.setInstructionList(result = new InstructionList());
    translate(classGen, methodGen);
    methodGen.setInstructionList(save);
    return result;
}
 
Example #22
Source File: XslElement.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Override this method to make sure that xsl:attributes are not
 * copied to output if this xsl:element is to be ignored
 */
public void translateContents(ClassGenerator classGen,
                              MethodGenerator methodGen) {
    final int n = elementCount();
    for (int i = 0; i < n; i++) {
        final SyntaxTreeNode item = getContents().get(i);
        if (_ignore && item instanceof XslAttribute) continue;
        item.translate(classGen, methodGen);
    }
}
 
Example #23
Source File: ContainsCall.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compile expression and update true/false-lists
 */
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    _base.translate(classGen, methodGen);
    _token.translate(classGen, methodGen);
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS,
                                                 "indexOf",
                                                 "("+STRING_SIG+")I")));
    _falseList.add(il.append(new IFLT(null)));
}
 
Example #24
Source File: FormatNumberCall.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    _value.translate(classGen, methodGen);
    _format.translate(classGen, methodGen);

    final int fn3arg = cpg.addMethodref(BASIS_LIBRARY_CLASS,
                                        "formatNumber",
                                        "(DLjava/lang/String;"+
                                        "Ljava/text/DecimalFormat;)"+
                                        "Ljava/lang/String;");
    final int get = cpg.addMethodref(TRANSLET_CLASS,
                                     "getDecimalFormat",
                                     "(Ljava/lang/String;)"+
                                     "Ljava/text/DecimalFormat;");

    il.append(classGen.loadTranslet());
    if (_name == null) {
        il.append(new PUSH(cpg, EMPTYSTRING));
    }
    else if (_resolvedQName != null) {
        il.append(new PUSH(cpg, _resolvedQName.toString()));
    }
    else {
        _name.translate(classGen, methodGen);
    }
    il.append(new INVOKEVIRTUAL(get));
    il.append(new INVOKESTATIC(fn3arg));
}
 
Example #25
Source File: Whitespace.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compiles the predicate method
 */
private static void compileDefault(int defaultAction,
                                   ClassGenerator classGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = new InstructionList();
    final XSLTC xsltc = classGen.getParser().getXSLTC();

    // private boolean Translet.stripSpace(int type) - cannot be static
    final MethodGenerator stripSpace =
        new MethodGenerator(ACC_PUBLIC | ACC_FINAL ,
                    com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN,
                    new com.sun.org.apache.bcel.internal.generic.Type[] {
                        Util.getJCRefType(DOM_INTF_SIG),
                        com.sun.org.apache.bcel.internal.generic.Type.INT,
                        com.sun.org.apache.bcel.internal.generic.Type.INT
                    },
                    new String[] { "dom","node","type" },
                    "stripSpace",classGen.getClassName(),il,cpg);

    classGen.addInterface("com/sun/org/apache/xalan/internal/xsltc/StripFilter");

    if (defaultAction == STRIP_SPACE)
        il.append(ICONST_1);
    else
        il.append(ICONST_0);
    il.append(IRETURN);

    classGen.addMethod(stripSpace);
}
 
Example #26
Source File: TopLevelElement.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Translate this node into a fresh instruction list.
 * The original instruction list is saved and restored.
 */
public InstructionList compile(ClassGenerator classGen,
                               MethodGenerator methodGen) {
    final InstructionList result, save = methodGen.getInstructionList();
    methodGen.setInstructionList(result = new InstructionList());
    translate(classGen, methodGen);
    methodGen.setInstructionList(save);
    return result;
}
 
Example #27
Source File: BooleanExpr.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    if (_value) {
        il.append(NOP);     // true list falls through
    }
    else {
        _falseList.add(il.append(new GOTO(null)));
    }
}
 
Example #28
Source File: BooleanExpr.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    if (_value) {
        il.append(NOP);     // true list falls through
    }
    else {
        _falseList.add(il.append(new GOTO(null)));
    }
}
 
Example #29
Source File: Whitespace.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compiles the predicate method
 */
private static void compileDefault(int defaultAction,
                                   ClassGenerator classGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = new InstructionList();
    final XSLTC xsltc = classGen.getParser().getXSLTC();

    // private boolean Translet.stripSpace(int type) - cannot be static
    final MethodGenerator stripSpace =
        new MethodGenerator(ACC_PUBLIC | ACC_FINAL ,
                    com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN,
                    new com.sun.org.apache.bcel.internal.generic.Type[] {
                        Util.getJCRefType(DOM_INTF_SIG),
                        com.sun.org.apache.bcel.internal.generic.Type.INT,
                        com.sun.org.apache.bcel.internal.generic.Type.INT
                    },
                    new String[] { "dom","node","type" },
                    "stripSpace",classGen.getClassName(),il,cpg);

    classGen.addInterface("com/sun/org/apache/xalan/internal/xsltc/StripFilter");

    if (defaultAction == STRIP_SPACE)
        il.append(ICONST_1);
    else
        il.append(ICONST_0);
    il.append(IRETURN);

    classGen.addMethod(stripSpace);
}
 
Example #30
Source File: EqualityExpr.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}