1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 import org.aspectj.compiler.crosscuts.AccessFixer; 29 30 import java.util.*; 31 32 37 public abstract class BangExpr extends Expr { 38 public Type discoverType() { 39 return lhs.getType(); 40 } 41 42 public boolean isLegalStmt() { 43 return true; 44 } 45 46 public ASTObject fixAccessPost(AccessFixer fixer) { 48 if (!(getLhs() instanceof FieldAccessExpr)) return this; 49 50 FieldAccessExpr fieldAccessExpr = (FieldAccessExpr)getLhs(); 51 Field field = fieldAccessExpr.getField(); 52 53 if (field == null) return this; 55 if (field.getDeclaringType().isInterface() && !field.isStatic()) { 56 return fixAccessToFieldSet(fieldAccessExpr).setSource(this); 57 } 58 if (field.isAccessible(this, true)) return this; 60 61 getCompiler().showMessage(" fixing privileged set: " + field.toShortString()); 62 65 if (!fixer.apply) { 67 field.getBackdoorGetterMethod(); 68 field.getBackdoorSetterMethod(); 69 return this; 70 } 71 72 return fixAccessToFieldSet(fieldAccessExpr).setSource(this); 73 } 74 75 91 public abstract ASTObject fixAccessToFieldSet(FieldAccessExpr fieldAccessExpr); 93 94 final Expr makeInPlaceSet(FieldAccessExpr expr, String op, Expr rhs) { 96 Expr lhs = expr.getExpr(); 97 Field field = expr.getField(); 98 99 Expr newExpr = lhs.makeReference(); 102 103 Method getMethod = field.getBackdoorGetterMethod(); 104 Method setMethod = field.getBackdoorSetterMethod(); 105 final AST ast = getAST(); 106 107 return ast.makeCall(setMethod, newExpr, 108 ast.makeBinop(op, 109 ast.makeCall(getMethod, newExpr.makeReference()), 110 rhs)); 111 } 112 113 116 public void walkFlow(FlowCheckerPass w) { 118 w.process(getLhs()); 119 if (getLhs() instanceof VarExpr) { 120 VarExpr lhs = (VarExpr)getLhs(); 121 VarDec dec = lhs.getVarDec(); 122 if (dec.isFinal() 123 && ((! dec.isBlank()) 124 || ! w.getVars().isDefinitelyUnassigned(dec))) { 125 w.showVarError(this, dec, "Final variable " + dec.getId() + 126 " already has a value"); 127 } 128 } else if (getLhs() instanceof FieldAccessExpr) { 129 FieldAccessExpr fa = (FieldAccessExpr) getLhs(); 130 FieldDec dec = fa.getFieldDec(); 131 if (dec.isFinal() 132 && ((! dec.isBlank()) 133 || ! w.getVars().isDefinitelyUnassigned(dec))) { 134 w.showVarError(this, dec, "Final field " + dec.getId() + 135 " already has a value"); 136 } 137 } 138 } 139 140 protected AssignableExpr lhs; 142 public AssignableExpr getLhs() { return lhs; } 143 public void setLhs(AssignableExpr _lhs) { 144 if (_lhs != null) _lhs.setParent(this); 145 lhs = _lhs; 146 } 147 148 public BangExpr(SourceLocation location, AssignableExpr _lhs) { 149 super(location); 150 setLhs(_lhs); 151 } 152 protected BangExpr(SourceLocation source) { 153 super(source); 154 } 155 156 public ASTObject getChildAt(int childIndex) { 157 switch(childIndex) { 158 case 0: return lhs; 159 default: return super.getChildAt(childIndex); 160 } 161 } 162 public String getChildNameAt(int childIndex) { 163 switch(childIndex) { 164 case 0: return "lhs"; 165 default: return super.getChildNameAt(childIndex); 166 } 167 } 168 public void setChildAt(int childIndex, ASTObject child) { 169 switch(childIndex) { 170 case 0: setLhs((AssignableExpr)child); return; 171 default: super.setChildAt(childIndex, child); return; 172 } 173 } 174 public int getChildCount() { 175 return 1; 176 } 177 178 public String getDefaultDisplayName() { 179 return "BangExpr()"; 180 } 181 182 } 184 | Popular Tags |