Java Code Examples for com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator#containsField()

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator#containsField() . 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: Variable.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 2
Source File: Param.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_ignore) return;
    _ignore = true;

    /*
     * To fix bug 24518 related to setting parameters of the form
     * {namespaceuri}localName which will get mapped to an instance
     * variable in the class.
     */
    final String name = BasisLibrary.mapQNameToJavaName(_name.toString());
    final String signature = _type.toSignature();
    final String className = _type.getClassName();

    if (isLocal()) {
        /*
          * If simple named template then generate a conditional init of the
          * param using its default value:
          *       if (param == null) param = <default-value>
          */
        if (_isInSimpleNamedTemplate) {
            il.append(loadInstruction());
            BranchHandle ifBlock = il.append(new IFNONNULL(null));
            translateValue(classGen, methodGen);
            il.append(storeInstruction());
            ifBlock.setTarget(il.append(NOP));
            return;
        }

        il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, name));
        translateValue(classGen, methodGen);
        il.append(new PUSH(cpg, true));

        // Call addParameter() from this class
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                     ADD_PARAMETER,
                                                     ADD_PARAMETER_SIG)));
        if (className != EMPTYSTRING) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }

        _type.translateUnBox(classGen, methodGen);

        if (_refs.isEmpty()) { // nobody uses the value
            il.append(_type.POP());
            _local = null;
        }
        else {              // normal case
            _local = methodGen.addLocalVariable2(name,
                                                 _type.toJCType(),
                                                 il.getEnd());
            // Cache the result of addParameter() in a local variable
            il.append(_type.STORE(_local.getIndex()));
        }
    }
    else {
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));
            il.append(classGen.loadTranslet());
            il.append(DUP);
            il.append(new PUSH(cpg, name));
            translateValue(classGen, methodGen);
            il.append(new PUSH(cpg, true));

            // Call addParameter() from this class
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                 ADD_PARAMETER,
                                                 ADD_PARAMETER_SIG)));

            _type.translateUnBox(classGen, methodGen);

            // Cache the result of addParameter() in a field
            if (className != EMPTYSTRING) {
                il.append(new CHECKCAST(cpg.addClass(className)));
            }
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 3
Source File: Variable.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 4
Source File: Param.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_ignore) return;
    _ignore = true;

    /*
     * To fix bug 24518 related to setting parameters of the form
     * {namespaceuri}localName which will get mapped to an instance
     * variable in the class.
     */
    final String name = BasisLibrary.mapQNameToJavaName(_name.toString());
    final String signature = _type.toSignature();
    final String className = _type.getClassName();

    if (isLocal()) {
        /*
          * If simple named template then generate a conditional init of the
          * param using its default value:
          *       if (param == null) param = <default-value>
          */
        if (_isInSimpleNamedTemplate) {
            il.append(loadInstruction());
            BranchHandle ifBlock = il.append(new IFNONNULL(null));
            translateValue(classGen, methodGen);
            il.append(storeInstruction());
            ifBlock.setTarget(il.append(NOP));
            return;
        }

        il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, name));
        translateValue(classGen, methodGen);
        il.append(new PUSH(cpg, true));

        // Call addParameter() from this class
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                     ADD_PARAMETER,
                                                     ADD_PARAMETER_SIG)));
        if (className != EMPTYSTRING) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }

        _type.translateUnBox(classGen, methodGen);

        if (_refs.isEmpty()) { // nobody uses the value
            il.append(_type.POP());
            _local = null;
        }
        else {              // normal case
            _local = methodGen.addLocalVariable2(name,
                                                 _type.toJCType(),
                                                 il.getEnd());
            // Cache the result of addParameter() in a local variable
            il.append(_type.STORE(_local.getIndex()));
        }
    }
    else {
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));
            il.append(classGen.loadTranslet());
            il.append(DUP);
            il.append(new PUSH(cpg, name));
            translateValue(classGen, methodGen);
            il.append(new PUSH(cpg, true));

            // Call addParameter() from this class
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                 ADD_PARAMETER,
                                                 ADD_PARAMETER_SIG)));

            _type.translateUnBox(classGen, methodGen);

            // Cache the result of addParameter() in a field
            if (className != EMPTYSTRING) {
                il.append(new CHECKCAST(cpg.addClass(className)));
            }
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 5
Source File: Variable.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 6
Source File: Variable.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 7
Source File: Variable.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 8
Source File: Param.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_ignore) return;
    _ignore = true;

    /*
     * To fix bug 24518 related to setting parameters of the form
     * {namespaceuri}localName which will get mapped to an instance
     * variable in the class.
     */
    final String name = BasisLibrary.mapQNameToJavaName(_name.toString());
    final String signature = _type.toSignature();
    final String className = _type.getClassName();

    if (isLocal()) {
        /*
          * If simple named template then generate a conditional init of the
          * param using its default value:
          *       if (param == null) param = <default-value>
          */
        if (_isInSimpleNamedTemplate) {
            il.append(loadInstruction());
            BranchHandle ifBlock = il.append(new IFNONNULL(null));
            translateValue(classGen, methodGen);
            il.append(storeInstruction());
            ifBlock.setTarget(il.append(NOP));
            return;
        }

        il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, name));
        translateValue(classGen, methodGen);
        il.append(new PUSH(cpg, true));

        // Call addParameter() from this class
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                     ADD_PARAMETER,
                                                     ADD_PARAMETER_SIG)));
        if (className != EMPTYSTRING) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }

        _type.translateUnBox(classGen, methodGen);

        if (_refs.isEmpty()) { // nobody uses the value
            il.append(_type.POP());
            _local = null;
        }
        else {              // normal case
            _local = methodGen.addLocalVariable2(name,
                                                 _type.toJCType(),
                                                 il.getEnd());
            // Cache the result of addParameter() in a local variable
            il.append(_type.STORE(_local.getIndex()));
        }
    }
    else {
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));
            il.append(classGen.loadTranslet());
            il.append(DUP);
            il.append(new PUSH(cpg, name));
            translateValue(classGen, methodGen);
            il.append(new PUSH(cpg, true));

            // Call addParameter() from this class
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                 ADD_PARAMETER,
                                                 ADD_PARAMETER_SIG)));

            _type.translateUnBox(classGen, methodGen);

            // Cache the result of addParameter() in a field
            if (className != EMPTYSTRING) {
                il.append(new CHECKCAST(cpg.addClass(className)));
            }
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 9
Source File: Variable.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 10
Source File: Param.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_ignore) return;
    _ignore = true;

    /*
     * To fix bug 24518 related to setting parameters of the form
     * {namespaceuri}localName which will get mapped to an instance
     * variable in the class.
     */
    final String name = BasisLibrary.mapQNameToJavaName(_name.toString());
    final String signature = _type.toSignature();
    final String className = _type.getClassName();

    if (isLocal()) {
        /*
          * If simple named template then generate a conditional init of the
          * param using its default value:
          *       if (param == null) param = <default-value>
          */
        if (_isInSimpleNamedTemplate) {
            il.append(loadInstruction());
            BranchHandle ifBlock = il.append(new IFNONNULL(null));
            translateValue(classGen, methodGen);
            il.append(storeInstruction());
            ifBlock.setTarget(il.append(NOP));
            return;
        }

        il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, name));
        translateValue(classGen, methodGen);
        il.append(new PUSH(cpg, true));

        // Call addParameter() from this class
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                     ADD_PARAMETER,
                                                     ADD_PARAMETER_SIG)));
        if (className != EMPTYSTRING) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }

        _type.translateUnBox(classGen, methodGen);

        if (_refs.isEmpty()) { // nobody uses the value
            il.append(_type.POP());
            _local = null;
        }
        else {              // normal case
            _local = methodGen.addLocalVariable2(name,
                                                 _type.toJCType(),
                                                 il.getEnd());
            // Cache the result of addParameter() in a local variable
            il.append(_type.STORE(_local.getIndex()));
        }
    }
    else {
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));
            il.append(classGen.loadTranslet());
            il.append(DUP);
            il.append(new PUSH(cpg, name));
            translateValue(classGen, methodGen);
            il.append(new PUSH(cpg, true));

            // Call addParameter() from this class
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                 ADD_PARAMETER,
                                                 ADD_PARAMETER_SIG)));

            _type.translateUnBox(classGen, methodGen);

            // Cache the result of addParameter() in a field
            if (className != EMPTYSTRING) {
                il.append(new CHECKCAST(cpg.addClass(className)));
            }
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 11
Source File: Variable.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 12
Source File: Param.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_ignore) return;
    _ignore = true;

    /*
     * To fix bug 24518 related to setting parameters of the form
     * {namespaceuri}localName which will get mapped to an instance
     * variable in the class.
     */
    final String name = BasisLibrary.mapQNameToJavaName(_name.toString());
    final String signature = _type.toSignature();
    final String className = _type.getClassName();

    if (isLocal()) {
        /*
          * If simple named template then generate a conditional init of the
          * param using its default value:
          *       if (param == null) param = <default-value>
          */
        if (_isInSimpleNamedTemplate) {
            il.append(loadInstruction());
            BranchHandle ifBlock = il.append(new IFNONNULL(null));
            translateValue(classGen, methodGen);
            il.append(storeInstruction());
            ifBlock.setTarget(il.append(NOP));
            return;
        }

        il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, name));
        translateValue(classGen, methodGen);
        il.append(new PUSH(cpg, true));

        // Call addParameter() from this class
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                     ADD_PARAMETER,
                                                     ADD_PARAMETER_SIG)));
        if (className != EMPTYSTRING) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }

        _type.translateUnBox(classGen, methodGen);

        if (_refs.isEmpty()) { // nobody uses the value
            il.append(_type.POP());
            _local = null;
        }
        else {              // normal case
            _local = methodGen.addLocalVariable2(name,
                                                 _type.toJCType(),
                                                 il.getEnd());
            // Cache the result of addParameter() in a local variable
            il.append(_type.STORE(_local.getIndex()));
        }
    }
    else {
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));
            il.append(classGen.loadTranslet());
            il.append(DUP);
            il.append(new PUSH(cpg, name));
            translateValue(classGen, methodGen);
            il.append(new PUSH(cpg, true));

            // Call addParameter() from this class
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                 ADD_PARAMETER,
                                                 ADD_PARAMETER_SIG)));

            _type.translateUnBox(classGen, methodGen);

            // Cache the result of addParameter() in a field
            if (className != EMPTYSTRING) {
                il.append(new CHECKCAST(cpg.addClass(className)));
            }
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 13
Source File: Variable.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 14
Source File: Param.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_ignore) return;
    _ignore = true;

    /*
     * To fix bug 24518 related to setting parameters of the form
     * {namespaceuri}localName which will get mapped to an instance
     * variable in the class.
     */
    final String name = BasisLibrary.mapQNameToJavaName(_name.toString());
    final String signature = _type.toSignature();
    final String className = _type.getClassName();

    if (isLocal()) {
        /*
          * If simple named template then generate a conditional init of the
          * param using its default value:
          *       if (param == null) param = <default-value>
          */
        if (_isInSimpleNamedTemplate) {
            il.append(loadInstruction());
            BranchHandle ifBlock = il.append(new IFNONNULL(null));
            translateValue(classGen, methodGen);
            il.append(storeInstruction());
            ifBlock.setTarget(il.append(NOP));
            return;
        }

        il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, name));
        translateValue(classGen, methodGen);
        il.append(new PUSH(cpg, true));

        // Call addParameter() from this class
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                     ADD_PARAMETER,
                                                     ADD_PARAMETER_SIG)));
        if (className != EMPTYSTRING) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }

        _type.translateUnBox(classGen, methodGen);

        if (_refs.isEmpty()) { // nobody uses the value
            il.append(_type.POP());
            _local = null;
        }
        else {              // normal case
            _local = methodGen.addLocalVariable2(name,
                                                 _type.toJCType(),
                                                 il.getEnd());
            // Cache the result of addParameter() in a local variable
            il.append(_type.STORE(_local.getIndex()));
        }
    }
    else {
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));
            il.append(classGen.loadTranslet());
            il.append(DUP);
            il.append(new PUSH(cpg, name));
            translateValue(classGen, methodGen);
            il.append(new PUSH(cpg, true));

            // Call addParameter() from this class
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                 ADD_PARAMETER,
                                                 ADD_PARAMETER_SIG)));

            _type.translateUnBox(classGen, methodGen);

            // Cache the result of addParameter() in a field
            if (className != EMPTYSTRING) {
                il.append(new CHECKCAST(cpg.addClass(className)));
            }
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 15
Source File: Variable.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 16
Source File: Param.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_ignore) return;
    _ignore = true;

    /*
     * To fix bug 24518 related to setting parameters of the form
     * {namespaceuri}localName which will get mapped to an instance
     * variable in the class.
     */
    final String name = BasisLibrary.mapQNameToJavaName(_name.toString());
    final String signature = _type.toSignature();
    final String className = _type.getClassName();

    if (isLocal()) {
        /*
          * If simple named template then generate a conditional init of the
          * param using its default value:
          *       if (param == null) param = <default-value>
          */
        if (_isInSimpleNamedTemplate) {
            il.append(loadInstruction());
            BranchHandle ifBlock = il.append(new IFNONNULL(null));
            translateValue(classGen, methodGen);
            il.append(storeInstruction());
            ifBlock.setTarget(il.append(NOP));
            return;
        }

        il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, name));
        translateValue(classGen, methodGen);
        il.append(new PUSH(cpg, true));

        // Call addParameter() from this class
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                     ADD_PARAMETER,
                                                     ADD_PARAMETER_SIG)));
        if (className != EMPTYSTRING) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }

        _type.translateUnBox(classGen, methodGen);

        if (_refs.isEmpty()) { // nobody uses the value
            il.append(_type.POP());
            _local = null;
        }
        else {              // normal case
            _local = methodGen.addLocalVariable2(name,
                                                 _type.toJCType(),
                                                 il.getEnd());
            // Cache the result of addParameter() in a local variable
            il.append(_type.STORE(_local.getIndex()));
        }
    }
    else {
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));
            il.append(classGen.loadTranslet());
            il.append(DUP);
            il.append(new PUSH(cpg, name));
            translateValue(classGen, methodGen);
            il.append(new PUSH(cpg, true));

            // Call addParameter() from this class
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                 ADD_PARAMETER,
                                                 ADD_PARAMETER_SIG)));

            _type.translateUnBox(classGen, methodGen);

            // Cache the result of addParameter() in a field
            if (className != EMPTYSTRING) {
                il.append(new CHECKCAST(cpg.addClass(className)));
            }
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 17
Source File: Variable.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 18
Source File: Param.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_ignore) return;
    _ignore = true;

    /*
     * To fix bug 24518 related to setting parameters of the form
     * {namespaceuri}localName which will get mapped to an instance
     * variable in the class.
     */
    final String name = BasisLibrary.mapQNameToJavaName(_name.toString());
    final String signature = _type.toSignature();
    final String className = _type.getClassName();

    if (isLocal()) {
        /*
          * If simple named template then generate a conditional init of the
          * param using its default value:
          *       if (param == null) param = <default-value>
          */
        if (_isInSimpleNamedTemplate) {
            il.append(loadInstruction());
            BranchHandle ifBlock = il.append(new IFNONNULL(null));
            translateValue(classGen, methodGen);
            il.append(storeInstruction());
            ifBlock.setTarget(il.append(NOP));
            return;
        }

        il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, name));
        translateValue(classGen, methodGen);
        il.append(new PUSH(cpg, true));

        // Call addParameter() from this class
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                     ADD_PARAMETER,
                                                     ADD_PARAMETER_SIG)));
        if (className != EMPTYSTRING) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }

        _type.translateUnBox(classGen, methodGen);

        if (_refs.isEmpty()) { // nobody uses the value
            il.append(_type.POP());
            _local = null;
        }
        else {              // normal case
            _local = methodGen.addLocalVariable2(name,
                                                 _type.toJCType(),
                                                 il.getEnd());
            // Cache the result of addParameter() in a local variable
            il.append(_type.STORE(_local.getIndex()));
        }
    }
    else {
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));
            il.append(classGen.loadTranslet());
            il.append(DUP);
            il.append(new PUSH(cpg, name));
            translateValue(classGen, methodGen);
            il.append(new PUSH(cpg, true));

            // Call addParameter() from this class
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                 ADD_PARAMETER,
                                                 ADD_PARAMETER_SIG)));

            _type.translateUnBox(classGen, methodGen);

            // Cache the result of addParameter() in a field
            if (className != EMPTYSTRING) {
                il.append(new CHECKCAST(cpg.addClass(className)));
            }
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 19
Source File: Variable.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example 20
Source File: Param.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_ignore) return;
    _ignore = true;

    /*
     * To fix bug 24518 related to setting parameters of the form
     * {namespaceuri}localName which will get mapped to an instance
     * variable in the class.
     */
    final String name = BasisLibrary.mapQNameToJavaName(_name.toString());
    final String signature = _type.toSignature();
    final String className = _type.getClassName();

    if (isLocal()) {
        /*
          * If simple named template then generate a conditional init of the
          * param using its default value:
          *       if (param == null) param = <default-value>
          */
        if (_isInSimpleNamedTemplate) {
            il.append(loadInstruction());
            BranchHandle ifBlock = il.append(new IFNONNULL(null));
            translateValue(classGen, methodGen);
            il.append(storeInstruction());
            ifBlock.setTarget(il.append(NOP));
            return;
        }

        il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, name));
        translateValue(classGen, methodGen);
        il.append(new PUSH(cpg, true));

        // Call addParameter() from this class
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                     ADD_PARAMETER,
                                                     ADD_PARAMETER_SIG)));
        if (className != EMPTYSTRING) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }

        _type.translateUnBox(classGen, methodGen);

        if (_refs.isEmpty()) { // nobody uses the value
            il.append(_type.POP());
            _local = null;
        }
        else {              // normal case
            _local = methodGen.addLocalVariable2(name,
                                                 _type.toJCType(),
                                                 il.getEnd());
            // Cache the result of addParameter() in a local variable
            il.append(_type.STORE(_local.getIndex()));
        }
    }
    else {
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));
            il.append(classGen.loadTranslet());
            il.append(DUP);
            il.append(new PUSH(cpg, name));
            translateValue(classGen, methodGen);
            il.append(new PUSH(cpg, true));

            // Call addParameter() from this class
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                 ADD_PARAMETER,
                                                 ADD_PARAMETER_SIG)));

            _type.translateUnBox(classGen, methodGen);

            // Cache the result of addParameter() in a field
            if (className != EMPTYSTRING) {
                il.append(new CHECKCAST(cpg.addClass(className)));
            }
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}