1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 import org.aspectj.compiler.base.cst.*; 29 30 35 public class ReferenceExpr extends Expr { 36 public Type discoverType() { return value.getType(); } 37 38 public ReferenceExpr(SourceLocation source, Expr value) { 39 this(source, value, new VarDec(source, value.getType().makeTypeD(), "tmp", null)); 40 } 41 42 public Expr makeReference() { 43 return getAST().makeVar(tmpDec); 44 } 45 46 public VarDec makeVarDec() { 47 tmpDec.getModifiers().setFinal(true); 48 tmpDec.setInitializer(value); 49 return tmpDec; 50 } 51 52 55 public void walkFlow(FlowCheckerPass w) { 56 throw new RuntimeException ("Unhandled reference expr"); 57 } 58 59 public ASTObject postFixAST(final ASTFixerPass fixer) { 61 BlockStmt body = getEnclosingCodeDec().getBody(); 62 body.addTemporary(tmpDec); return getAST().makeParen(getAST().makeSet(tmpDec, value)); 64 } 65 66 protected Expr value; 68 public Expr getValue() { return value; } 69 public void setValue(Expr _value) { 70 if (_value != null) _value.setParent(this); 71 value = _value; 72 } 73 74 protected VarDec tmpDec; 75 public VarDec getTmpDec() { return tmpDec; } 76 public void setTmpDec(VarDec _tmpDec) { 77 if (_tmpDec != null) _tmpDec.setParent(this); 78 tmpDec = _tmpDec; 79 } 80 81 public ReferenceExpr(SourceLocation location, Expr _value, VarDec _tmpDec) { 82 super(location); 83 setValue(_value); 84 setTmpDec(_tmpDec); 85 } 86 protected ReferenceExpr(SourceLocation source) { 87 super(source); 88 } 89 90 public ASTObject copyWalk(CopyWalker walker) { 91 ReferenceExpr ret = new ReferenceExpr(getSourceLocation()); 92 ret.preCopy(walker, this); 93 if (value != null) ret.setValue( (Expr)walker.process(value) ); 94 if (tmpDec != null) ret.setTmpDec( (VarDec)walker.process(tmpDec) ); 95 return ret; 96 } 97 98 public ASTObject getChildAt(int childIndex) { 99 switch(childIndex) { 100 case 0: return value; 101 case 1: return tmpDec; 102 default: return super.getChildAt(childIndex); 103 } 104 } 105 public String getChildNameAt(int childIndex) { 106 switch(childIndex) { 107 case 0: return "value"; 108 case 1: return "tmpDec"; 109 default: return super.getChildNameAt(childIndex); 110 } 111 } 112 public void setChildAt(int childIndex, ASTObject child) { 113 switch(childIndex) { 114 case 0: setValue((Expr)child); return; 115 case 1: setTmpDec((VarDec)child); return; 116 default: super.setChildAt(childIndex, child); return; 117 } 118 } 119 public int getChildCount() { 120 return 2; 121 } 122 123 public String getDefaultDisplayName() { 124 return "ReferenceExpr()"; 125 } 126 127 } 129 | Popular Tags |