1 24 25 package org.aspectj.compiler.crosscuts; 26 27 import org.aspectj.compiler.base.*; 28 import org.aspectj.compiler.base.parser.*; 29 import org.aspectj.compiler.base.ast.*; 30 import org.aspectj.compiler.base.cst.*; 31 32 import java.util.*; 33 import java.io.*; 34 35 public class AspectJCompiler extends JavaCompiler { 36 40 public AspectJCompiler(ErrorHandler errorHandler) { 41 super(errorHandler); 42 this.scanner = AspectJParser.class; 43 } 45 46 public AspectJCompiler() { 47 this(null); 48 } 49 50 public JavaParser makeJavaParser() { 51 return new AspectJParser(this); 52 } 53 54 public void addPass(CompilerPass pass) { addPass(pass, false); } 56 public void addPass(CompilerPass pass, boolean exitOnErrors) { 57 passes.add(pass); 58 totalWorkEstimate += pass.getWorkEstimate(); 59 if (exitOnErrors) passes.add(new ExitOnErrorsPass(this)); 61 } 62 63 protected void addPreSymbolPasses() { 64 addPass(createParserPass(), true); 67 addPass(new TypeGraphBuilderPass(getCompiler())); 68 addPass(new SignatureBinderPass(getCompiler())); 70 addPass(new BodyBinderPass(getCompiler())); 71 addPass(new ForwardReferenceChecker(getCompiler())); 72 addPass(new InnerInfoPass(getCompiler())); 73 addPass(new AssignmentCheckerPass(getCompiler())); 74 addPass(new SpecChecker(getCompiler()), true); 75 76 addPass(new BuildAdvicePlannersPass(getCompiler()), true); 77 addPass(new InitializerCollector(getCompiler(), false)); 78 79 addPass(new JoinPointCollectorPass(getCompiler()), true); 80 addPass(new StaticJpPlannerPass(getCompiler())); 83 84 addPass(new FlowCheckerPass(getCompiler())); 85 addPass(new ThrowCheckerPass(getCompiler())); 86 87 addPass(new AdvicePlannerPass(getCompiler()), true); 88 89 addPass(new AdviceWeaver(getCompiler()), true); 90 } 91 92 protected void addPostSymbolPasses() { 93 95 addPass(new AbstractCompilerPass(getCompiler()) { 96 public String getDisplayName() { 97 return "emacssym "; 98 } 99 public void transformWorld() { 100 if (super.getCompiler().getOptions().emacssym) { 101 new org.aspectj.asm.views.EmacsViewManager().externalizeStructureView((AspectJCompiler)super.getCompiler()); 102 } 103 } 104 }); 105 106 addPass(new MixinImplementationPass(getCompiler())); 109 110 addPass(new PrivilegeFixer(getCompiler(), true)); 112 addPass(new ASTFixerPass(getCompiler()), true); 113 114 addPass(new InitializerCollector(getCompiler(), true)); 115 116 addPass(new LocalClassPass(getCompiler()), true); 117 } 118 119 protected void addSourceGenerationPasses() { 120 addPass(new NameHygienePass(getCompiler()), true); 121 addPass(new CodeGenerator(getCompiler()), true); 122 addPass(new RunJavacPass(getCompiler())); 124 } 126 127 protected void addBytecodeGenerationPasses() { 128 addPass(new MemberClassMunger(getCompiler())); 129 130 if (getOptions().bcgverbose) { 131 addPass(new CodeGenerator(getCompiler())); 133 } 134 135 addPass(new ClassExprPass(getCompiler())); 136 addPass(new InnerAccessFixer(getCompiler())); 137 138 139 addPass(new NameHygienePass(getCompiler()), true); 140 141 addPass(new ByteCodeCleanupPass(getCompiler())); 145 addPass(new FrameLocPass(getCompiler())); 146 147 addPass(new ByteCodeGenerator(getCompiler())); 148 149 } 151 152 protected void addPasses() { 153 passes = new ArrayList(); 154 addPreSymbolPasses(); 155 addPostSymbolPasses(); 156 if (getOptions().usejavac || getOptions().preprocess) { 157 addSourceGenerationPasses(); 158 } else { 159 addBytecodeGenerationPasses(); 160 } 161 } 162 163 164 protected JavaCompiler getCompiler() { return this; } 165 166 169 171 172 private Correspondences correspondences = new Correspondences(this); 173 public Correspondences getCorrespondences() { 174 return correspondences; 175 } 176 177 public String getBuildConfigFile() { return null; } 178 179 protected class ExitOnErrorsPass extends AbstractCompilerPass { 180 public ExitOnErrorsPass(JavaCompiler jc) { super(jc); } 181 182 public String getDisplayName() { return null; } 183 public double getWorkEstimate() { return 0.0; } 184 185 public void transformWorld() { 186 errorHandler.exitOnErrors(); 187 } 188 } 189 190 protected AbstractCompilerPass createParserPass() { 191 return new ParserPass(getCompiler()); 192 } 193 194 protected static class ParserPass extends AbstractCompilerPass { 195 public ParserPass(JavaCompiler jc) { super(jc); } 196 197 public String getDisplayName() { return "parse sources"; } 198 public double getWorkEstimate() { return 4.0; } 199 200 public void transform(CompilationUnit cu) { 201 this.getCompiler().showMessage(" parsing " + cu.getSourceFile()); 202 try { 203 JavaParser parser = this.getCompiler().allocateParser(); 204 parser.parseInterfaceOnly = false; 205 parser.interfaceParse(cu); 206 this.getCompiler().freeParser(parser); 207 } catch (ParseException pe) { 208 if (getOptions().dumpstack) { 209 pe.printStackTrace(); 210 } 211 this.getCompiler().showError(cu.getSourceFile(), 212 pe.getLine(), 213 pe.getColumn(), 214 pe.getMessage()); 215 } catch (IOException e) { 216 this.getCompiler().showError(null,e.toString()); 217 } 218 219 for (Iterator j = cu.getDefinedTypes().iterator(); j.hasNext(); ) { 220 TypeDec td = (TypeDec)j.next(); 221 getWorld().addSourceType(td.getType()); 222 addInnerTypes(td); } 224 } 225 226 private void addInnerTypes(TypeDec typeDec) { Decs body = typeDec.getBody(); 228 for (int i=0; i < body.size(); i++) { 229 if (body.get(i) instanceof TypeDec) { 230 TypeDec innerTypeDec = (TypeDec)body.get(i); 231 getTypeManager().addType( innerTypeDec.getType() ); 234 addInnerTypes(innerTypeDec); } 236 } 237 } 238 } 239 240 protected static class TypeGraphBuilderPass extends AbstractCompilerPass { 241 public TypeGraphBuilderPass(JavaCompiler jc) { super(jc); } 242 243 public String getDisplayName() { return "build type graph"; } 244 public void transform(CompilationUnit cu) { 245 cu.addTypesToTypeGraph(); 246 } 247 } 248 249 protected static class SignatureBinderPass extends WalkerPass { 250 public SignatureBinderPass(JavaCompiler jc) { super(jc); } 251 252 public String getDisplayName() { return "resolve type signatures"; } 253 254 public void transform(CompilationUnit cu) { 255 cu.buildSignatures(); 256 } 257 260 public void transformWorld() { 261 super.transformWorld(); 262 getWorld().collectedTypeDecPlanners = true; 263 } 264 } 265 266 protected static class BodyBinderPass extends AbstractCompilerPass { 267 public BodyBinderPass(JavaCompiler jc) { super(jc); } 268 269 public String getDisplayName() { return "bind names in bodies"; } 270 public void transform(CompilationUnit cu) { 271 new ScopeWalker(this.getCompiler()).process(cu); 272 } 273 } 274 275 protected static class JoinPointCollectorPass extends AbstractCompilerPass { 276 public JoinPointCollectorPass(JavaCompiler jc) { super(jc); } 277 278 public String getDisplayName() { return "collect join point shadows"; } 279 public void transform(TypeDec td) { 280 new JoinPointCollector(td).collect(); 281 } 282 } 283 284 protected static class ThrowCheckerPass extends WalkerPass { 285 public ThrowCheckerPass(JavaCompiler jc) { super(jc); } 286 287 public String getDisplayName() { return "checking throws"; } 288 public ASTObject process(ASTObject node) { 289 290 if (node instanceof CodeDec) { 291 CanThrowWalker.checkThrows((CodeDec)node); 292 } 293 return super.process(node); 294 } 295 } 296 } 297 298 | Popular Tags |