1 /*
2 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
3 * @LastModified: Oct 2017
4 */
5 /*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements. See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22 package com.sun.org.apache.xalan.internal.xsltc.compiler;
23
402 sortOrderTemp.setEnd(il.append(new ALOAD(sortOrderTemp.getIndex())));
403 sortTypeTemp.setEnd(il.append(new ALOAD(sortTypeTemp.getIndex())));
404 sortLangTemp.setEnd(il.append(new ALOAD(sortLangTemp.getIndex())));
405 sortCaseOrderTemp.setEnd(
406 il.append(new ALOAD(sortCaseOrderTemp.getIndex())));
407
408 il.append(new INVOKESPECIAL(
409 cpg.addMethodref(sortRecordFactoryClass, "<init>",
410 "(" + DOM_INTF_SIG
411 + STRING_SIG
412 + TRANSLET_INTF_SIG
413 + "[" + STRING_SIG
414 + "[" + STRING_SIG
415 + "[" + STRING_SIG
416 + "[" + STRING_SIG + ")V")));
417
418 // Initialize closure variables in sortRecordFactory
419 final List<VariableRefBase> dups = new ArrayList<>();
420
421 for (int j = 0; j < nsorts; j++) {
422 final Sort sort = (Sort) sortObjects.get(j);
423 final int length = (sort._closureVars == null) ? 0 :
424 sort._closureVars.size();
425
426 for (int i = 0; i < length; i++) {
427 VariableRefBase varRef = sort._closureVars.get(i);
428
429 // Discard duplicate variable references
430 if (dups.contains(varRef)) continue;
431
432 final VariableBase var = varRef.getVariable();
433
434 // Store variable in new closure
435 il.append(DUP);
436 il.append(var.loadInstruction());
437 il.append(new PUTFIELD(
438 cpg.addFieldref(sortRecordFactoryClass, var.getEscapedName(),
439 var.getType().toSignature())));
440 dups.add(varRef);
441 }
442 }
536 final MethodGenerator makeNodeSortRecord =
537 new MethodGenerator(ACC_PUBLIC,
538 Util.getJCRefType(NODE_SORT_RECORD_SIG),
539 new com.sun.org.apache.bcel.internal.generic.Type[] {
540 com.sun.org.apache.bcel.internal.generic.Type.INT,
541 com.sun.org.apache.bcel.internal.generic.Type.INT },
542 new String[] { "node", "last" }, "makeNodeSortRecord",
543 className, il, cpg);
544
545 il.append(ALOAD_0);
546 il.append(ILOAD_1);
547 il.append(ILOAD_2);
548 il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_FACTORY,
549 "makeNodeSortRecord", "(II)" + NODE_SORT_RECORD_SIG)));
550 il.append(DUP);
551 il.append(new CHECKCAST(cpg.addClass(sortRecordClass)));
552
553 // Initialize closure in record class
554 final int ndups = dups.size();
555 for (int i = 0; i < ndups; i++) {
556 final VariableRefBase varRef = (VariableRefBase) dups.get(i);
557 final VariableBase var = varRef.getVariable();
558 final Type varType = var.getType();
559
560 il.append(DUP);
561
562 // Get field from factory class
563 il.append(ALOAD_0);
564 il.append(new GETFIELD(
565 cpg.addFieldref(className,
566 var.getEscapedName(), varType.toSignature())));
567
568 // Put field in record class
569 il.append(new PUTFIELD(
570 cpg.addFieldref(sortRecordClass,
571 var.getEscapedName(), varType.toSignature())));
572 }
573 il.append(POP);
574 il.append(ARETURN);
575
576 constructor.setMaxLocals();
600 "sort$0.java",
601 ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
602 new String[] {},
603 classGen.getStylesheet());
604
605 final ConstantPoolGen cpg = sortRecord.getConstantPool();
606
607 // Add a new instance variable for each var in closure
608 final int nsorts = sortObjects.size();
609 final List<VariableRefBase> dups = new ArrayList<>();
610
611 for (int j = 0; j < nsorts; j++) {
612 final Sort sort = sortObjects.get(j);
613
614 // Set the name of the inner class in this sort object
615 sort.setInnerClassName(className);
616
617 final int length = (sort._closureVars == null) ? 0 :
618 sort._closureVars.size();
619 for (int i = 0; i < length; i++) {
620 final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);
621
622 // Discard duplicate variable references
623 if (dups.contains(varRef)) continue;
624
625 final VariableBase var = varRef.getVariable();
626 sortRecord.addField(new Field(ACC_PUBLIC,
627 cpg.addUtf8(var.getEscapedName()),
628 cpg.addUtf8(var.getType().toSignature()),
629 null, cpg.getConstantPool()));
630 dups.add(varRef);
631 }
632 }
633
634 MethodGenerator init = compileInit(sortRecord, cpg, className);
635 MethodGenerator extract = compileExtract(sortObjects, sortRecord,
636 cpg, className);
637 sortRecord.addMethod(init);
638 sortRecord.addMethod(extract);
639
640 xsltc.dumpClass(sortRecord.getJavaClass());
|
1 /*
2 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
3 * @LastModified: Nov 2017
4 */
5 /*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements. See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22 package com.sun.org.apache.xalan.internal.xsltc.compiler;
23
402 sortOrderTemp.setEnd(il.append(new ALOAD(sortOrderTemp.getIndex())));
403 sortTypeTemp.setEnd(il.append(new ALOAD(sortTypeTemp.getIndex())));
404 sortLangTemp.setEnd(il.append(new ALOAD(sortLangTemp.getIndex())));
405 sortCaseOrderTemp.setEnd(
406 il.append(new ALOAD(sortCaseOrderTemp.getIndex())));
407
408 il.append(new INVOKESPECIAL(
409 cpg.addMethodref(sortRecordFactoryClass, "<init>",
410 "(" + DOM_INTF_SIG
411 + STRING_SIG
412 + TRANSLET_INTF_SIG
413 + "[" + STRING_SIG
414 + "[" + STRING_SIG
415 + "[" + STRING_SIG
416 + "[" + STRING_SIG + ")V")));
417
418 // Initialize closure variables in sortRecordFactory
419 final List<VariableRefBase> dups = new ArrayList<>();
420
421 for (int j = 0; j < nsorts; j++) {
422 final Sort sort = sortObjects.get(j);
423 final int length = (sort._closureVars == null) ? 0 :
424 sort._closureVars.size();
425
426 for (int i = 0; i < length; i++) {
427 VariableRefBase varRef = sort._closureVars.get(i);
428
429 // Discard duplicate variable references
430 if (dups.contains(varRef)) continue;
431
432 final VariableBase var = varRef.getVariable();
433
434 // Store variable in new closure
435 il.append(DUP);
436 il.append(var.loadInstruction());
437 il.append(new PUTFIELD(
438 cpg.addFieldref(sortRecordFactoryClass, var.getEscapedName(),
439 var.getType().toSignature())));
440 dups.add(varRef);
441 }
442 }
536 final MethodGenerator makeNodeSortRecord =
537 new MethodGenerator(ACC_PUBLIC,
538 Util.getJCRefType(NODE_SORT_RECORD_SIG),
539 new com.sun.org.apache.bcel.internal.generic.Type[] {
540 com.sun.org.apache.bcel.internal.generic.Type.INT,
541 com.sun.org.apache.bcel.internal.generic.Type.INT },
542 new String[] { "node", "last" }, "makeNodeSortRecord",
543 className, il, cpg);
544
545 il.append(ALOAD_0);
546 il.append(ILOAD_1);
547 il.append(ILOAD_2);
548 il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_FACTORY,
549 "makeNodeSortRecord", "(II)" + NODE_SORT_RECORD_SIG)));
550 il.append(DUP);
551 il.append(new CHECKCAST(cpg.addClass(sortRecordClass)));
552
553 // Initialize closure in record class
554 final int ndups = dups.size();
555 for (int i = 0; i < ndups; i++) {
556 final VariableRefBase varRef = dups.get(i);
557 final VariableBase var = varRef.getVariable();
558 final Type varType = var.getType();
559
560 il.append(DUP);
561
562 // Get field from factory class
563 il.append(ALOAD_0);
564 il.append(new GETFIELD(
565 cpg.addFieldref(className,
566 var.getEscapedName(), varType.toSignature())));
567
568 // Put field in record class
569 il.append(new PUTFIELD(
570 cpg.addFieldref(sortRecordClass,
571 var.getEscapedName(), varType.toSignature())));
572 }
573 il.append(POP);
574 il.append(ARETURN);
575
576 constructor.setMaxLocals();
600 "sort$0.java",
601 ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
602 new String[] {},
603 classGen.getStylesheet());
604
605 final ConstantPoolGen cpg = sortRecord.getConstantPool();
606
607 // Add a new instance variable for each var in closure
608 final int nsorts = sortObjects.size();
609 final List<VariableRefBase> dups = new ArrayList<>();
610
611 for (int j = 0; j < nsorts; j++) {
612 final Sort sort = sortObjects.get(j);
613
614 // Set the name of the inner class in this sort object
615 sort.setInnerClassName(className);
616
617 final int length = (sort._closureVars == null) ? 0 :
618 sort._closureVars.size();
619 for (int i = 0; i < length; i++) {
620 final VariableRefBase varRef = sort._closureVars.get(i);
621
622 // Discard duplicate variable references
623 if (dups.contains(varRef)) continue;
624
625 final VariableBase var = varRef.getVariable();
626 sortRecord.addField(new Field(ACC_PUBLIC,
627 cpg.addUtf8(var.getEscapedName()),
628 cpg.addUtf8(var.getType().toSignature()),
629 null, cpg.getConstantPool()));
630 dups.add(varRef);
631 }
632 }
633
634 MethodGenerator init = compileInit(sortRecord, cpg, className);
635 MethodGenerator extract = compileExtract(sortObjects, sortRecord,
636 cpg, className);
637 sortRecord.addMethod(init);
638 sortRecord.addMethod(extract);
639
640 xsltc.dumpClass(sortRecord.getJavaClass());
|