1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.JavaCompiler; 28 import org.aspectj.compiler.base.CompilerObject; 29 30 public class SyntheticGetSet extends CompilerObject { 31 public BangExpr bangExpr; 32 33 public SyntheticGetSet(JavaCompiler compiler, BangExpr bangExpr) { 34 super(compiler); 35 this.bangExpr = bangExpr; 36 } 37 38 public FieldAccessExpr makeGetExpr() { 39 makeInnerExprs(); 40 return getExpr; 41 } 42 43 public AssignExpr makeSetExpr() { 44 makeInnerExprs(); 45 return setExpr; 46 } 47 48 public BangExpr getBangExpr() { return bangExpr; } 49 50 boolean isConcrete = false; 51 public void makeConcrete() { 52 if (isConcrete) return; 53 isConcrete = true; 55 makeInnerExprs(); 56 bangExpr.replaceWith(finishSetExpr(setExpr)); 57 } 58 59 Expr finishSetExpr(Expr setExpr) { 60 if (bangExpr instanceof PostfixExpr) { 61 if (bangExpr.isInExprStmt()) return setExpr; 62 63 PostfixExpr postfixExpr = (PostfixExpr)bangExpr; 64 String op = "-"; 65 if (postfixExpr.getOp().equals("--")) op = "+"; 66 final AST ast = getAST(); 67 return ast.makeParen(ast.makeBinop(op, setExpr, ast.makeLiteral(1))); 68 } 69 return setExpr; 70 } 71 72 FieldAccessExpr getExpr; 73 AssignExpr setExpr; 74 75 AssignExpr makeAssignExpr(BangExpr bangExpr) { 76 if (bangExpr instanceof AssignExpr) return (AssignExpr)bangExpr; 77 if (bangExpr instanceof PrefixExpr) { 78 PrefixExpr prefixExpr = (PrefixExpr)bangExpr; 79 String op = prefixExpr.getOp().substring(1); 80 final AST ast = getAST(); 81 return ast.makeSet(bangExpr.getLhs(), op, ast.makeLiteral(1)); 82 } else if (bangExpr instanceof PostfixExpr) { 83 PostfixExpr postfixExpr = (PostfixExpr)bangExpr; 84 String op = postfixExpr.getOp().substring(1); 85 final AST ast = getAST(); 86 return ast.makeSet(bangExpr.getLhs(), op, ast.makeLiteral(1)); 87 } 88 return null; 89 } 90 91 92 void makeInnerExprs() { 93 if (getExpr != null) return; 94 95 AST ast = getAST(); 96 97 AssignExpr assignExpr = makeAssignExpr(bangExpr); 98 assignExpr.setParent(bangExpr.getParent()); 100 FieldAccessExpr fieldAccessExpr = (FieldAccessExpr)bangExpr.getLhs(); 101 FieldDec fieldDec = fieldAccessExpr.getFieldDec(); 102 103 Expr baseExpr = fieldAccessExpr.getExpr(); 104 BlockStmt body = bangExpr.getEnclosingCodeDec().getBody(); 105 106 String op = assignExpr.getOp(); 107 108 Expr newExpr = null; 109 if (baseExpr != null) newExpr = baseExpr.makeReference(); 110 getExpr = ast.makeGet(newExpr, fieldDec); 111 112 Expr newValue = 113 ast.makeCast(fieldDec.getType(), 114 ast.makeParen(ast.makeBinop(op, getExpr, assignExpr.getRhs()))); 115 116 Expr firstBaseExpr = fieldAccessExpr.getExpr(); 117 FieldAccessExpr lhs = ast.makeGet(firstBaseExpr, fieldDec); 118 119 setExpr = ast.makeSet(lhs, newValue); 120 } 121 } 122 | Popular Tags |