| 1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 29 import org.aspectj.compiler.base.bcg.CodeBuilder; 30 31 34 public class SuperExpr extends Expr { 35 public final Type discoverType() { 36 return getThisType().getSuperClassType(); 37 } 38 39 public NameType getThisType() { 40 return (NameType) getDeclaringType(); 41 } 42 43 public void unparse(CodeWriter writer) { 44 if (inAllowedPosition()) { 45 writer.writeKeyword("super"); 46 } else { 47 writer.writeKeyword("this"); 48 } 49 } 50 51 52 55 public void checkSpec() { 57 super.checkSpec(); 58 59 if (!inAllowedPosition()) showError("bad identifier"); 60 } 61 62 63 public boolean inAllowedPosition() { 64 ASTObject self = this; 66 ASTObject parent = getParent(); 67 68 if (parent instanceof Expr) { 70 if (parent instanceof CallExpr) { 71 if (((CallExpr)parent).getExpr() == self) return true; 72 } else if (parent instanceof FieldAccessExpr) { 73 if (((FieldAccessExpr)parent).getExpr() == self) return true; 74 } 75 } 76 77 return false; 78 } 79 80 81 84 public void postInnerInfo(InnerInfoPass walker) { 85 if (!walker.isAccessibleExactly(getThisType())) { 86 if (!fromSource() && getParent().fromSource()) { 87 getParent().showError("no instance available"); 88 } else { 89 showError("no instance available"); 90 } 91 } 92 } 93 94 97 protected void cgValue(CodeBuilder cb) { 98 cb.emitALOAD(0); 99 } 100 101 103 public SuperExpr(SourceLocation location) { 104 super(location); 105 106 } 107 108 public ASTObject copyWalk(CopyWalker walker) { 109 SuperExpr ret = new SuperExpr(getSourceLocation()); 110 ret.preCopy(walker, this); 111 112 return ret; 113 } 114 115 116 public String getDefaultDisplayName() { 117 return "SuperExpr()"; 118 } 119 120 } 122 | Popular Tags |