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.9KB

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