1 24 25 package org.aspectj.compiler.base; 26 27 import org.aspectj.compiler.base.ast.*; 28 import java.util.*; 29 30 69 70 public class ForwardReferenceChecker extends WalkerPass { 71 public ForwardReferenceChecker(JavaCompiler compiler) { 72 super(compiler); 73 } 74 75 public String getDisplayName() { 76 return "checking forward references"; 77 } 78 79 public ASTObject process(ASTObject node) { 80 node.walkForwardReference(this); 82 return node; 83 } 84 85 public ForwardReferenceChecker createTypeChecker(TypeDec ty) { 86 return new TypeChecker(getCompiler(), ty); 87 } 88 public ForwardReferenceChecker createInitializerChecker(boolean isStatic) { 89 throw new RuntimeException ("found initializer while walking with " + this); 90 } 91 public ForwardReferenceChecker createBodyChecker() { 92 throw new RuntimeException ("found body while walking with " + this); 93 } 94 public void addFieldDec(FieldDec f) { 95 throw new RuntimeException ("found field while walking with " + this); 96 } 97 public void checkReference(FieldAccessExpr f) { } 98 99 public String toString() { 100 return "<ForwardReferenceChecker in Compilation Unit>"; 101 } 102 103 105 static class TypeChecker extends ForwardReferenceChecker { 106 TypeDec context; 107 TypeChecker(JavaCompiler compiler, TypeDec ty) { 108 super(compiler); 109 context = ty; 110 } 111 Set statics = new HashSet(); 112 Set dynamics = new HashSet(); 113 114 public ForwardReferenceChecker createInitializerChecker(boolean isStatic) { 115 return new InitializerChecker(getCompiler(), isStatic, context, 116 isStatic ? statics : dynamics); 117 } 118 public ForwardReferenceChecker createBodyChecker() { 119 return new BodyChecker(getCompiler()); 120 } 121 public void addFieldDec(FieldDec f) { 122 (f.isStatic() ? statics : dynamics).add(f); 123 } 124 public String toString() { 125 return "<ForwardReferenceChecker in TypeDec with dynamics " + 126 dynamics + " and statics " + statics + ">"; 127 } 128 } 129 130 static class InitializerChecker extends ForwardReferenceChecker { 131 boolean isStatic; 132 TypeDec context; 133 Set fields; 134 InitializerChecker(JavaCompiler compiler, boolean isStatic, TypeDec context, Set fields) { 135 super(compiler); 136 this.isStatic = isStatic; 137 this.context = context; 138 this.fields = fields; 139 } 140 public ForwardReferenceChecker createBodyChecker() { 141 return this; 142 } 143 public void checkReference(FieldAccessExpr e) { 144 FieldDec dec = e.getFieldDec(); 145 if (dec.isStatic() != isStatic) return; 146 if (dec.getDeclaringType().getTypeDec() != context) return; 147 if (fields.contains(dec)) return; 148 e.showError("Illegal forward reference"); 149 } 150 public String toString() { 151 return "<ForwardReferenceChecker in " + 152 (isStatic ? "static" : "dynamic") + 153 " Init with fields " + fields + ">"; 154 } 155 } 156 157 static class BodyChecker extends ForwardReferenceChecker { 158 BodyChecker(JavaCompiler compiler) { super(compiler); } 159 160 public ForwardReferenceChecker createBodyChecker() { 161 return this; 162 } 163 public String toString() { 164 return "<ForwardReferenceChecker in Body>"; 165 } 166 167 } 168 } 169 170 | Popular Tags |