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.

BcelCflowAccessVar.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  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.apache.bcel.generic.Type;
  18. import org.aspectj.weaver.Member;
  19. import org.aspectj.weaver.NameMangler;
  20. import org.aspectj.weaver.ResolvedType;
  21. /**
  22. * XXX Erik and I need to discuss this hierarchy. Having FieldRef extend Var is convenient, but hopefully there's a better design.
  23. *
  24. * This is always a static reference.
  25. */
  26. public class BcelCflowAccessVar extends BcelVar {
  27. private Member stackField;
  28. private int index;
  29. /**
  30. * @param type The type to convert to from Object
  31. * @param stackField the member containing the CFLOW_STACK_TYPE
  32. * @param index yeah yeah
  33. */
  34. public BcelCflowAccessVar(ResolvedType type, Member stackField, int index) {
  35. super(type, 0);
  36. this.stackField = stackField;
  37. this.index = index;
  38. }
  39. public String toString() {
  40. return "BcelCflowAccessVar(" + getType() + " " + stackField + "." + index + ")";
  41. }
  42. public Instruction createLoad(InstructionFactory fact) {
  43. throw new RuntimeException("unimplemented");
  44. }
  45. public Instruction createStore(InstructionFactory fact) {
  46. throw new RuntimeException("unimplemented");
  47. }
  48. public InstructionList createCopyFrom(InstructionFactory fact, int oldSlot) {
  49. throw new RuntimeException("unimplemented");
  50. }
  51. public void appendLoad(InstructionList il, InstructionFactory fact) {
  52. il.append(createLoadInstructions(getType(), fact));
  53. }
  54. public InstructionList createLoadInstructions(ResolvedType toType, InstructionFactory fact) {
  55. InstructionList il = new InstructionList();
  56. il.append(Utility.createGet(fact, stackField));
  57. il.append(Utility.createConstant(fact, index));
  58. il.append(fact.createInvoke(NameMangler.CFLOW_STACK_TYPE, "get", Type.OBJECT, new Type[] { Type.INT },
  59. Constants.INVOKEVIRTUAL));
  60. il.append(Utility.createConversion(fact, Type.OBJECT, BcelWorld.makeBcelType(toType)));
  61. return il;
  62. }
  63. public void appendLoadAndConvert(InstructionList il, InstructionFactory fact, ResolvedType toType) {
  64. il.append(createLoadInstructions(toType, fact));
  65. }
  66. public void insertLoad(InstructionList il, InstructionFactory fact) {
  67. il.insert(createLoadInstructions(getType(), fact));
  68. }
  69. }