| 1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.FlowCheckerPass; 28 import org.aspectj.compiler.base.JavaCompiler; 29 import org.aspectj.compiler.base.CodeWriter; 30 import java.io.IOException ; 31 32 33 import java.util.*; 34 35 import org.aspectj.compiler.base.bcg.CodeBuilder; 36 import org.aspectj.compiler.base.bcg.Label; 37 38 43 public class ArrayExpr extends AssignableExpr { 44 45 protected Type discoverType() { 46 Type intType = getTypeManager().intType; 47 if (! index.isAssignableTo(intType)) { 48 index.showTypeError(index.getType(), intType); 49 } 50 Type exprType = expr.getType(); 51 52 if (exprType.isAnyType()) return getTypeManager().anyType; 53 54 if (exprType instanceof ArrayType) { 55 return ((ArrayType)exprType).getComponentType(); 56 } else { 57 expr.showError("array required, but " + exprType.getString() + " found"); 58 return getTypeManager().anyType; 59 } 60 } 61 62 public void unparse(CodeWriter writer) throws IOException { 63 writer.write(expr); 64 writer.write('['); 65 writer.write(getIndex()); 66 writer.write(']'); 67 } 68 69 protected void cgLvalue(CodeBuilder cb) { 72 getExpr().cgValue(cb); 73 getIndex().cgValue(cb); 74 } 75 protected void cgLtoRvalue(CodeBuilder cb) { 76 getType().emitAload(cb); 77 } 78 protected void cgAssignment(CodeBuilder cb) { 79 getType().emitAstore(cb); 80 } 81 protected void cgDupLvalue(CodeBuilder cb) { 82 cb.emitDUP2(); 84 } 85 protected void cgDupRvalue(CodeBuilder cb) { 86 getType().emitDupX2(cb); 88 } 89 91 protected Expr expr; 93 public Expr getExpr() { return expr; } 94 public void setExpr(Expr _expr) { 95 if (_expr != null) _expr.setParent(this); 96 expr = _expr; 97 } 98 99 protected Expr index; 100 public Expr getIndex() { return index; } 101 public void setIndex(Expr _index) { 102 if (_index != null) _index.setParent(this); 103 index = _index; 104 } 105 106 public ArrayExpr(SourceLocation location, Expr _expr, Expr _index) { 107 super(location); 108 setExpr(_expr); 109 setIndex(_index); 110 } 111 protected ArrayExpr(SourceLocation source) { 112 super(source); 113 } 114 115 public ASTObject copyWalk(CopyWalker walker) { 116 ArrayExpr ret = new ArrayExpr(getSourceLocation()); 117 ret.preCopy(walker, this); 118 if (expr != null) ret.setExpr( (Expr)walker.process(expr) ); 119 if (index != null) ret.setIndex( (Expr)walker.process(index) ); 120 return ret; 121 } 122 123 public ASTObject getChildAt(int childIndex) { 124 switch(childIndex) { 125 case 0: return expr; 126 case 1: return index; 127 default: return super.getChildAt(childIndex); 128 } 129 } 130 public String getChildNameAt(int childIndex) { 131 switch(childIndex) { 132 case 0: return "expr"; 133 case 1: return "index"; 134 default: return super.getChildNameAt(childIndex); 135 } 136 } 137 public void setChildAt(int childIndex, ASTObject child) { 138 switch(childIndex) { 139 case 0: setExpr((Expr)child); return; 140 case 1: setIndex((Expr)child); return; 141 default: super.setChildAt(childIndex, child); return; 142 } 143 } 144 public int getChildCount() { 145 return 2; 146 } 147 148 public String getDefaultDisplayName() { 149 return "ArrayExpr()"; 150 } 151 152 } 154 | Popular Tags |