You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BcelVar.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import org.aspectj.apache.bcel.generic.Instruction;
  14. import org.aspectj.apache.bcel.generic.InstructionFactory;
  15. import org.aspectj.apache.bcel.generic.InstructionList;
  16. import org.aspectj.weaver.ResolvedType;
  17. import org.aspectj.weaver.ast.Var;
  18. public class BcelVar extends Var {
  19. private int positionInAroundState = -1;
  20. private int slot;
  21. public BcelVar(ResolvedType type, int slot) {
  22. super(type);
  23. this.slot = slot;
  24. }
  25. public String toString() {
  26. return "BcelVar(" + getType() + " " + slot + ((positionInAroundState != -1) ? (" " + positionInAroundState) : "") +
  27. ")";
  28. }
  29. public int getSlot() {
  30. return slot;
  31. }
  32. // fact is used in the subtypes
  33. public Instruction createLoad(InstructionFactory fact) {
  34. return InstructionFactory.createLoad(BcelWorld.makeBcelType(getType()), slot);
  35. }
  36. public Instruction createStore(InstructionFactory fact) {
  37. return InstructionFactory.createStore(BcelWorld.makeBcelType(getType()), slot);
  38. }
  39. public void appendStore(InstructionList il, InstructionFactory fact) {
  40. il.append(createStore(fact));
  41. }
  42. public void appendLoad(InstructionList il, InstructionFactory fact) {
  43. il.append(createLoad(fact));
  44. }
  45. public void appendLoadAndConvert(InstructionList il, InstructionFactory fact, ResolvedType toType) {
  46. il.append(createLoad(fact));
  47. Utility.appendConversion(il, fact, getType(), toType);
  48. }
  49. public void insertLoad(InstructionList il, InstructionFactory fact) {
  50. il.insert(createLoad(fact));
  51. }
  52. public InstructionList createCopyFrom(InstructionFactory fact, int oldSlot) {
  53. InstructionList il = new InstructionList();
  54. il.append(InstructionFactory.createLoad(BcelWorld.makeBcelType(getType()), oldSlot));
  55. il.append(createStore(fact));
  56. return il;
  57. }
  58. // this is an array var
  59. void appendConvertableArrayLoad(InstructionList il, InstructionFactory fact, int index, ResolvedType convertTo) {
  60. ResolvedType convertFromType = getType().getResolvedComponentType();
  61. appendLoad(il, fact);
  62. il.append(Utility.createConstant(fact, index));
  63. il.append(InstructionFactory.createArrayLoad(BcelWorld.makeBcelType(convertFromType)));
  64. Utility.appendConversion(il, fact, convertFromType, convertTo);
  65. }
  66. void appendConvertableArrayStore(InstructionList il, InstructionFactory fact, int index, BcelVar storee) {
  67. ResolvedType convertToType = getType().getResolvedComponentType();
  68. appendLoad(il, fact);
  69. il.append(Utility.createConstant(fact, index));
  70. storee.appendLoad(il, fact);
  71. Utility.appendConversion(il, fact, storee.getType(), convertToType);
  72. il.append(InstructionFactory.createArrayStore(BcelWorld.makeBcelType(convertToType)));
  73. }
  74. InstructionList createConvertableArrayStore(InstructionFactory fact, int index, BcelVar storee) {
  75. InstructionList il = new InstructionList();
  76. appendConvertableArrayStore(il, fact, index, storee);
  77. return il;
  78. }
  79. InstructionList createConvertableArrayLoad(InstructionFactory fact, int index, ResolvedType convertTo) {
  80. InstructionList il = new InstructionList();
  81. appendConvertableArrayLoad(il, fact, index, convertTo);
  82. return il;
  83. }
  84. public int getPositionInAroundState() {
  85. return positionInAroundState;
  86. }
  87. public void setPositionInAroundState(int positionInAroundState) {
  88. this.positionInAroundState = positionInAroundState;
  89. }
  90. // random useful fields
  91. public static final BcelVar[] NONE = new BcelVar[] {};
  92. }