1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.JavaCompiler; 28 import org.aspectj.compiler.base.CodeWriter; 29 import org.aspectj.compiler.base.LocalClassPass; 30 import org.aspectj.compiler.base.cst.*; 31 32 import org.aspectj.compiler.base.bcg.CodeBuilder; 33 import org.aspectj.compiler.base.bcg.Label; 34 import org.aspectj.compiler.base.bcg.MethodBuilder; 35 import org.aspectj.compiler.base.bcg.ClassfileBuilder; 36 37 41 42 public class ConstructorBody extends CodeBody { 43 44 protected void setupDefaultConstructorCall() { 45 if (constructorCall == null) { 46 Type superType = getDeclaringType().getTypeDec().getSuperClassType(); 47 Exprs args = getAST().makeExprs(); 48 Constructor superConstructor = superType.getConstructor(this, args, true); 49 ConstructorCallExpr newCallExpr = 50 getAST().makeSuperConstructorCall(superConstructor); 51 setConstructorCall(newCallExpr); 52 } 53 } 54 55 public void preScope(ScopeWalker walker) { 57 if (stmts != null && walker.walkBodies()) setupDefaultConstructorCall(); 58 super.preScope(walker); 59 } 60 61 public ConstructorBody(SourceLocation location, Stmts _stmts, ConstructorCallExpr _constructorCall, boolean _parsed) { 63 super(location,_stmts,_parsed); 64 setConstructorCall(_constructorCall); 65 } 66 67 public void unparse(CodeWriter writer) { 68 writer.openBlock(); 69 writer.write(constructorCall); 70 writer.newLine(); 71 if (tmpStmts != null) writer.write(tmpStmts); 72 writer.write(stmts); 73 writer.closeBlock(); 74 } 75 76 public void cleanup() { 77 constructorCall = null; 78 super.cleanup(); 79 } 80 81 84 public void preThreading(LocalClassPass.ThreadingWalker walker) { 85 if (getConstructorCall().getIsSuper()) { 86 walker.addFieldSets(getStmts()); 87 } 88 } 89 90 protected void cgStmt(CodeBuilder cb) { 93 getConstructorCall().cgEffect(cb); 94 super.cgStmt(cb); 95 } 96 97 100 public ConstructorBody(SourceLocation location, Stmts _stmts, 101 boolean _parsed, ConstructorCallExpr _constructorCall) { 102 this(location, null, _stmts, _parsed, _constructorCall); 103 } 104 105 protected ConstructorCallExpr constructorCall; 107 public ConstructorCallExpr getConstructorCall() { return constructorCall; } 108 public void setConstructorCall(ConstructorCallExpr _constructorCall) { 109 if (_constructorCall != null) _constructorCall.setParent(this); 110 constructorCall = _constructorCall; 111 } 112 113 public ConstructorBody(SourceLocation location, Stmts _tmpStmts, Stmts _stmts, boolean _parsed, ConstructorCallExpr _constructorCall) { 114 super(location, _tmpStmts, _stmts, _parsed); 115 setConstructorCall(_constructorCall); 116 } 117 protected ConstructorBody(SourceLocation source) { 118 super(source); 119 } 120 121 public ASTObject copyWalk(CopyWalker walker) { 122 ConstructorBody ret = new ConstructorBody(getSourceLocation()); 123 ret.preCopy(walker, this); 124 if (tmpStmts != null) ret.setTmpStmts( (Stmts)walker.process(tmpStmts) ); 125 if (stmts != null) ret.setStmts( (Stmts)walker.process(stmts) ); 126 ret.parsed = parsed; 127 if (constructorCall != null) ret.setConstructorCall( (ConstructorCallExpr)walker.process(constructorCall) ); 128 return ret; 129 } 130 131 public ASTObject getChildAt(int childIndex) { 132 switch(childIndex) { 133 case 2: return constructorCall; 134 default: return super.getChildAt(childIndex); 135 } 136 } 137 public String getChildNameAt(int childIndex) { 138 switch(childIndex) { 139 case 2: return "constructorCall"; 140 default: return super.getChildNameAt(childIndex); 141 } 142 } 143 public void setChildAt(int childIndex, ASTObject child) { 144 switch(childIndex) { 145 case 2: setConstructorCall((ConstructorCallExpr)child); return; 146 default: super.setChildAt(childIndex, child); return; 147 } 148 } 149 public int getChildCount() { 150 return 3; 151 } 152 153 public String getDefaultDisplayName() { 154 return "ConstructorBody(parsed: "+parsed+")"; 155 } 156 157 } 159 | Popular Tags |