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.

BcelFieldRef.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.Constants;
  14. import org.aspectj.apache.bcel.generic.Instruction;
  15. import org.aspectj.apache.bcel.generic.InstructionFactory;
  16. import org.aspectj.apache.bcel.generic.InstructionList;
  17. import org.aspectj.weaver.ResolvedType;
  18. /**
  19. * XXX Erik and I need to discuss this hierarchy. Having FieldRef extend Var is convenient, but hopefully there's a better design.
  20. *
  21. * This is always a static reference.
  22. */
  23. public class BcelFieldRef extends BcelVar {
  24. private String className, fieldName;
  25. public BcelFieldRef(ResolvedType type, String className, String fieldName) {
  26. super(type, 0);
  27. this.className = className;
  28. this.fieldName = fieldName;
  29. }
  30. public String toString() {
  31. return "BcelFieldRef(" + getType() + " " + className + "." + fieldName + ")";
  32. }
  33. // public int getSlot() { return slot; }
  34. public Instruction createLoad(InstructionFactory fact) {
  35. return fact.createFieldAccess(className, fieldName, BcelWorld.makeBcelType(getType()), Constants.GETSTATIC);
  36. }
  37. public Instruction createStore(InstructionFactory fact) {
  38. return fact.createFieldAccess(className, fieldName, BcelWorld.makeBcelType(getType()), Constants.PUTSTATIC);
  39. }
  40. public InstructionList createCopyFrom(InstructionFactory fact, int oldSlot) {
  41. throw new RuntimeException("unimplemented");
  42. }
  43. // this is an array var
  44. // void appendConvertableArrayLoad(
  45. // InstructionList il,
  46. // InstructionFactory fact,
  47. // int index,
  48. // ResolvedType convertTo)
  49. // {
  50. // ResolvedType convertFromType = getType().getResolvedComponentType();
  51. // appendLoad(il, fact);
  52. // il.append(Utility.createConstant(fact, index));
  53. // il.append(fact.createArrayLoad(BcelWorld.makeBcelType(convertFromType)));
  54. // Utility.appendConversion(il, fact, convertFromType, convertTo);
  55. // }
  56. //
  57. // void appendConvertableArrayStore(
  58. // InstructionList il,
  59. // InstructionFactory fact,
  60. // int index,
  61. // BcelFieldRef storee)
  62. // {
  63. // ResolvedType convertToType = getType().getResolvedComponentType();
  64. // appendLoad(il, fact);
  65. // il.append(Utility.createConstant(fact, index));
  66. // storee.appendLoad(il, fact);
  67. // Utility.appendConversion(il, fact, storee.getType(), convertToType);
  68. // il.append(fact.createArrayStore(BcelWorld.makeBcelType(convertToType)));
  69. // }
  70. //
  71. // InstructionList createConvertableArrayStore(
  72. // InstructionFactory fact,
  73. // int index,
  74. // BcelFieldRef storee)
  75. // {
  76. // InstructionList il = new InstructionList();
  77. // appendConvertableArrayStore(il, fact, index, storee);
  78. // return il;
  79. // }
  80. // InstructionList createConvertableArrayLoad(
  81. // InstructionFactory fact,
  82. // int index,
  83. // ResolvedType convertTo)
  84. // {
  85. // InstructionList il = new InstructionList();
  86. // appendConvertableArrayLoad(il, fact, index, convertTo);
  87. // return il;
  88. // }
  89. }