1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.AssignmentCheckerPass; 28 import org.aspectj.compiler.base.*; 29 import org.aspectj.compiler.crosscuts.AccessFixer; 30 31 import java.util.*; 32 33 import org.aspectj.compiler.base.bcg.CodeBuilder; 34 35 39 public class BasicAssignExpr extends AssignExpr { 40 41 public Type discoverType() { 42 Type lhsType = lhs.getType(); 43 Type rhsType = rhs.getType(); 44 return lhsType; 45 } 46 47 50 public ASTObject postAssignmentCheck(AssignmentCheckerPass walker) { 51 Type lhsType = lhs.getType(); 52 Type rhsType = rhs.getType(); 53 if (! rhs.isAssignableTo(lhsType)) { 54 rhs.showTypeError(rhs.getType(), lhsType); 55 } 56 return this; 57 } 58 59 public ASTObject fixAccessToFieldSet(FieldAccessExpr expr) { 61 return getAST().makeCall(expr.getField().getBackdoorSetterMethod(), 62 expr.getExpr(), getRhs()); 63 } 64 65 68 public void walkFlow(FlowCheckerPass w) { 70 if (getLhs() instanceof VarExpr) { 71 w.process(getRhs()); 72 VarExpr lhs = (VarExpr)getLhs(); 73 VarDec dec = lhs.getVarDec(); 74 if (dec.isFinal()) { 75 if (! dec.isBlank()) { 76 w.showVarError(this, dec, "Final variable " + dec.getId() + 77 " already has a value"); 78 } else if (! w.getVars().isDefinitelyUnassigned(dec)) { 79 w.showVarError(this, dec, "Final variable " + dec.getId() + 80 " may already have a value"); 81 } else { 82 w.addPossiblyAssigned(dec); 83 } 84 } 85 w.setVars(w.getVars().addAssigned(dec)); 86 } else if (getLhs() instanceof FieldAccessExpr) { 87 FieldAccessExpr lhs = (FieldAccessExpr) getLhs(); 88 FieldDec dec = lhs.getFieldDec(); 89 if (lhs.isBare()) { 90 w.process(getRhs()); 91 if (dec.isFinal()) { 92 if (! dec.isBlank()) { 93 w.showVarError(this, dec, "Final field " + dec.getId() + 94 " already has a value"); 95 } else if (! w.getVars().isDefinitelyUnassigned(dec)) { 96 w.showVarError(this, dec, "Final field " + dec.getId() + 97 " may already have a value"); 98 } else { 99 w.addPossiblyAssigned(dec); 100 w.setVars(w.getVars().addAssigned(dec)); 101 } 102 } 103 } else { 104 w.process(lhs.getExpr()); 105 w.process(getRhs()); 106 if (dec.isFinal() 107 && ((! dec.isBlank()) 108 || (! w.getVars().isDefinitelyUnassigned(dec)))) { 109 w.showVarError(this, dec, "Final field " + dec.getId() + 110 " already has a value"); 111 } 112 } 113 } else { 114 w.process(getLhs()); 115 w.process(getRhs()); 116 } 117 } 118 119 protected void cgValue(CodeBuilder cb) { 122 cgValueEffect(cb, true); 123 } 124 protected void cgEffect(CodeBuilder cb) { 125 cgValueEffect(cb, false); 126 } 127 private void cgValueEffect(CodeBuilder cb, boolean needsValue) { 128 AssignableExpr lhs = getLhs(); 129 Expr rhs = getRhs(); 130 lhs.cgLvalue(cb); 131 rhs.cgValue(cb, lhs.getType()); 132 if (needsValue) lhs.cgDupRvalue(cb); 133 lhs.cgAssignment(cb); 134 } 135 136 138 public BasicAssignExpr(SourceLocation location, AssignableExpr _lhs, String _op, Expr _rhs) { 139 super(location, _lhs, _op, _rhs); 140 141 } 142 protected BasicAssignExpr(SourceLocation source) { 143 super(source); 144 } 145 146 public ASTObject copyWalk(CopyWalker walker) { 147 BasicAssignExpr ret = new BasicAssignExpr(getSourceLocation()); 148 ret.preCopy(walker, this); 149 if (lhs != null) ret.setLhs( (AssignableExpr)walker.process(lhs) ); 150 ret.op = op; 151 if (rhs != null) ret.setRhs( (Expr)walker.process(rhs) ); 152 return ret; 153 } 154 155 156 public String getDefaultDisplayName() { 157 return "BasicAssignExpr(op: "+op+")"; 158 } 159 160 } 162 | Popular Tags |