1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 import org.aspectj.compiler.crosscuts.*; 30 import org.aspectj.compiler.base.bcg.CodeBuilder; 31 import java.util.*; 32 33 import org.aspectj.compiler.base.bcg.ClassfileBuilder; 34 37 38 public class InitializerDec extends CodeDec { 39 40 public InitializerDec(SourceLocation location, Modifiers _modifiers, CodeBody _body) { 41 this(location, _modifiers, new Formals(location), new TypeDs(location), _body); 42 } 43 44 47 public final void walkFlow(FlowCheckerPass w) { 48 setupFlowWalker(w); 49 w.setLive(true); 50 w.process(getBody()); 51 if (! w.isLive()) { 52 showError("initializer must be able to complete normally"); 53 } 54 } 55 57 public String getId() { return getModifiers().isStatic() ? "<clinit>" : "<init>"; } 58 59 public TypeD getResultTypeD() { 60 return getTypeManager().voidType.makeTypeD(); 61 } 62 63 public boolean conflictsWith(Dec otherDec) { 64 return false; 65 } 66 67 public String toShortString() { 68 return "{}"; 69 } 70 71 public String getKind() { return "initializer"; } 72 73 public ASTObject postImplementMixin(MixinImplementationPass fixer) { 75 final TypeDec inTypeDec = getBytecodeTypeDec(); 76 77 if (!(inTypeDec instanceof InterfaceDec) || getBody() == null || isStatic()) return this; 78 79 Set topmostImplementors = 80 Type.filterTopTypes(Type.filterConcreteTypes(inTypeDec.getType().getSubTypes())); 81 82 for (Iterator i = topmostImplementors.iterator(); i.hasNext(); ) { 83 final Type implType = (Type)i.next(); 84 TypeDec implDec = implType.getTypeDec(); 85 86 CodeDec newDec = (CodeDec)fixer.copyToClass(this, implDec); 87 88 Decs decs = implDec.getBody(); 90 int j = decs.size()-1; 91 for (; j >= 0; j--) { 92 if (decs.get(j) instanceof InitializerDec) { 93 implDec.getBody().add(j, newDec); 94 break; 95 } 96 } 97 if (j < 0) implDec.getBody().add( newDec ); 98 99 } 100 101 return null; 102 } 103 104 105 public void unparse(CodeWriter writer) { 106 if (body == null || body.getStmts() == null || body.getStmts().size() == 0) return; 107 108 writeModifiers(writer); 120 writer.write(body); 121 writer.newLine(); 122 } 124 125 128 public void walkForwardReference(ForwardReferenceChecker w) { 129 this.walk(w.createInitializerChecker(isStatic())); 130 } 131 132 135 public ASTObject postCleanup(ByteCodeCleanupPass walker) { 136 if (getBody().isEmpty()) { 137 return null; 138 } else { 139 return super.postCleanup(walker); 140 } 141 } 142 143 protected void cgCodeMember(CodeBuilder cb) { 144 cb.setMaxFrame(getFrameSize()); 146 cb.enterBlock(); 147 getBody().cgTop(cb); 148 cb.exitBlock(); 149 } 150 151 public String getDescriptor() { 152 return "()V"; 153 } 154 155 public int getStackDelta() { return 0; } 156 157 160 public void walkAnalysis(LocalClassPass.AnalysisWalker walker) { 161 walker.enterCodeDec(this); 162 if (isStatic()) walker.inCode(true); 163 else walker.inConstructor(); 164 this.walk(walker); 165 walker.leaveCodeDec(); 166 } 167 168 public String toString() { 169 return "InitializerDec(" + (isStatic() ? "static" : "non-static") + ")"; 170 } 171 172 174 public InitializerDec(SourceLocation location, Modifiers _modifiers, Formals _formals, TypeDs __throws, CodeBody _body) { 175 super(location, _modifiers, _formals, __throws, _body); 176 177 } 178 protected InitializerDec(SourceLocation source) { 179 super(source); 180 } 181 182 public ASTObject copyWalk(CopyWalker walker) { 183 InitializerDec ret = new InitializerDec(getSourceLocation()); 184 ret.preCopy(walker, this); 185 if (modifiers != null) ret.setModifiers( (Modifiers)walker.process(modifiers) ); 186 if (formals != null) ret.setFormals( (Formals)walker.process(formals) ); 187 if (_throws != null) ret.setThrows( (TypeDs)walker.process(_throws) ); 188 if (body != null) ret.setBody( (CodeBody)walker.process(body) ); 189 return ret; 190 } 191 192 193 public String getDefaultDisplayName() { 194 return "InitializerDec()"; 195 } 196 197 } 199 | Popular Tags |