1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 import java.util.*; 29 30 import org.aspectj.compiler.crosscuts.ast.*; 32 33 import org.aspectj.compiler.base.bcg.CodeBuilder; 34 import org.aspectj.compiler.base.bcg.Label; 35 36 46 public abstract class Type extends SemanticObject { 47 private ArrayType arrayType = null; 48 public synchronized ArrayType getArrayType() { 49 if (arrayType == null) { 50 arrayType = new ArrayType(getCompiler(), this); 51 } 52 return arrayType; 53 } 54 55 public int getArrayDimCount() { return 0; } 56 57 public Type getBaseComponentType() { return this; } 58 59 protected final Set directSubTypes = new HashSet(); 62 protected final Set directSuperTypes = new HashSet(); 63 public void addDirectSuperType(Type superType) { 64 if (superType == this) { 66 getCompiler().showError(getTypeDec(), getString() + " tries to extend itself"); 67 } 68 69 directSuperTypes.add(superType); 70 superType.directSubTypes.add(this); 71 } 72 73 74 public Type(JavaCompiler compiler) { 75 super(compiler); 76 } 77 78 protected void showNotFoundError(String id, ASTObject fromWhere, String kind) { 79 getCompiler().showError(fromWhere, "no " + kind + "s on " + toShortString()); 80 } 81 82 public boolean isEffectivelyStatic() { 83 return true; 84 } 85 86 public void ensureBuiltTypeGraph() { 88 } 89 90 public void ensureFinishedSignature() { 91 } 92 93 94 public void buildTypeGraph() { } 95 public void validateTypeGraph() { } 96 public void finishTypeIntroductions() { ensureBuiltTypeGraph(); } 97 public void finish() { finishTypeIntroductions(); } 98 99 100 public Collection getDirectSuperTypes() { 101 buildTypeGraph(); 102 return directSuperTypes; 103 } 104 105 public Collection getDirectSubTypes() { 106 buildTypeGraph(); 107 return directSubTypes; 108 } 109 110 public Type getDeclaringType() { 111 return null; 112 } 113 114 public TypeDec getTypeDec() { return (TypeDec)dec; } 116 117 public PointcutSO getPointcut(String id, ASTObject fromWhere, boolean showError) { 118 if (showError) showNotFoundError(id, fromWhere, "pointcut"); 119 return null; } 121 122 public Field getField(String id, ASTObject fromWhere, boolean showError) { 123 if (showError) showNotFoundError(id, fromWhere, "field"); 124 return null; } 126 127 public Type getInnerType(String id, ASTObject fromWhere, boolean showError) { 128 if (showError) showNotFoundError(id, fromWhere, "inner type"); 129 return getTypeManager().TYPE_NOT_FOUND; 130 } 131 132 public Method getMethod(String id, ASTObject fromWhere, Exprs params, 133 boolean showError) 134 { 135 if (showError) showNotFoundError(id, fromWhere, "method"); 136 return null; } 138 139 public Constructor getConstructor(ASTObject fromWhere, Exprs params, 140 boolean showError) 141 { 142 if (showError) showNotFoundError(getPrettyString(), fromWhere, "constructor"); 143 return null; } 145 146 public boolean hasMethodNamed(String id) { 148 return false; 149 } 150 151 public SemanticObject findMatchingSemanticObject(SemanticObject o) { 153 return null; 154 } 155 156 161 public Dec findMatchingDec(Dec dec) { 162 SemanticObject o = findMatchingSemanticObject(dec.getCorrespondingSemanticObject()); 163 if (o == null) return null; 164 return o.getCorrespondingDec(); 165 } 166 167 public Collection getInheritedMethods() { 169 return Collections.EMPTY_LIST; 170 } 171 172 public Collection getInheritedMembers() { 174 return Collections.EMPTY_LIST; 175 } 176 177 public boolean isCloneable() { return false; } 178 179 public boolean isInterface() { return false; } 180 public boolean isClass() { return false; } 181 public boolean isAspect() { return false; } 182 183 public boolean isConcrete() { return isClass(); } 185 public boolean isAbstract() { return false; } 186 187 public boolean isInnerType() { return false; } 188 189 190 public boolean isMissing() { return false; } 191 192 public boolean isAnonymous() { return false; } 193 194 public boolean isAssignableFrom(Type other) { 195 return other.isSubtypeOf(this); 196 } 197 198 public boolean isSubtypeOf(Type other) { 199 ensureBuiltTypeGraph(); 200 if (this.isEquivalent(other)) return true; 202 203 for (Iterator i = directSuperTypes.iterator(); i.hasNext(); ) { 204 Type superType = (Type)i.next(); 205 if (superType.isMissing()) continue; 207 if (superType.isSubtypeOf(other)) return true; 209 } 210 return false; 211 } 212 213 public boolean isStrictSubtypeOf(Type other) { 214 return (this != other) && this.isSubtypeOf(other); 215 } 216 217 public abstract boolean isCoercableTo(Type other); 219 223 public boolean isMethodConvertableTo(Type other) { 225 return other.isAssignableFrom(this); 228 } 229 230 public boolean isEquivalent(Type other) { 231 return isAnyType() || other.isAnyType() || this == other; 232 } 233 234 public boolean dominates(Type other) { 235 return this.isStrictSubtypeOf(other); 236 } 237 238 public TypeD makeTypeD() { 239 return new ResolvedTypeD(getAST().getSourceLocation(), this); 241 } 242 243 public Expr getClassExpr() { 245 throw new RuntimeException ("internal error: no class expr for " + this); 246 } 247 public Expr fromObject(Expr expr) { return null; } 248 public Expr makeObject(Expr expr) { return expr; } public Expr getNullExpr() { return null; } 250 public Type getRefType() { return this; } 251 252 253 public Type getOutermostType() { 254 return this; 255 } 256 257 public Type getPrivateCookieType() { 258 return getOutermostType(); 259 } 260 261 public Type getPackageCookieType() { 262 return getOutermostType(); 263 } 264 265 266 public boolean isObject() { 269 if (this == getTypeManager().getObjectType()) return true; 270 return false; 271 } 272 273 public boolean isUncheckedThrowable() { 274 if (this.isSubtypeOf(getTypeManager().getErrorType())) return true; 275 if (this.isSubtypeOf(getTypeManager().getRuntimeExceptionType())) return true; 276 return false; 277 } 278 279 public boolean isVoid() { 280 return this == getTypeManager().voidType; 281 } 282 283 public boolean isReferenceType() { 284 return this instanceof RefType; 285 } 286 287 public boolean isString() { 288 return this == getTypeManager().getStringType(); 289 } 290 public final boolean isPrimitive() { 291 return isNumeric() || isBoolean() || isVoid(); 292 } 293 public final boolean isNumeric() { 294 return isIntegral() || this == getTypeManager().floatType || this == getTypeManager().doubleType; 295 } 296 public final boolean isIntegral() { 297 return this == getTypeManager().byteType || this == getTypeManager().charType || this == getTypeManager().shortType || 298 this == getTypeManager().intType || this == getTypeManager().longType; 299 } 300 public final boolean isBoolean() { 301 return this == getTypeManager().booleanType; 302 } 303 304 public boolean isAnyType() { 305 return false; 306 } 307 308 309 public abstract String toShortString(); 310 public String getString() { return toShortString(); } 311 public String getPrettyString() { return toShortString(); } 312 public String getId() { return toShortString(); } 313 public String getExtendedId() { return toShortString(); } 314 315 318 public String getSourceExtendedId() { return toShortString(); } 319 public String getPackageName() { return null; } 320 321 public Type getOutermostLexicalType() { return this; } 322 public Type getOutermostBytecodeType() { return getOutermostType(); } 323 324 public boolean isAccessible(ASTObject fromWhere, boolean inBytecode) { 325 if (isPrimitive()) return true; 327 if (getArrayDimCount() > 0) return getBaseComponentType().isAccessible(fromWhere, inBytecode); 328 return super.isAccessible(fromWhere, inBytecode); 329 } 330 331 private static boolean anyParentsInSet(Type type, Set set) { 333 for(Iterator iter = set.iterator(); iter.hasNext(); ) { 334 Type testType = (Type)iter.next(); 335 if (type.isStrictSubtypeOf(testType)) return true; 336 } 337 return false; 338 } 339 340 341 public static boolean hasMatchingType(Collection c, Type t) { 342 for (Iterator j = c.iterator(); j.hasNext(); ) { 343 Type testType = (Type)j.next(); 344 if (t.isSubtypeOf(testType)) return true; 345 } 346 return false; 347 } 348 349 public static Set intersect(Set t1, Set t2) { 350 Set ret = new HashSet(); 351 for (Iterator i = t1.iterator(); i.hasNext(); ) { 352 Type t = (Type)i.next(); 353 if (hasMatchingType(t2, t)) { 354 ret.add(t); 355 } 356 } 357 358 for (Iterator i = t2.iterator(); i.hasNext(); ) { 359 Type t = (Type)i.next(); 360 if (hasMatchingType(t1, t)) { 361 ret.add(t); 362 } 363 } 364 return ret; 365 } 366 367 public static Set filterTopTypes(Set set) { 368 Set topSet = new HashSet(); 369 for(Iterator iter = set.iterator(); iter.hasNext(); ) { 370 Type testType = (Type)iter.next(); 371 if (!anyParentsInSet(testType, set)) { 372 topSet.add(testType); 373 } 374 } 375 return topSet; 376 } 377 378 public static Set filterSubTypes(Type type, Set set) { 379 Set topSet = new HashSet(); 380 for(Iterator iter = set.iterator(); iter.hasNext(); ) { 381 Type testType = (Type)iter.next(); 382 if (testType.isSubtypeOf(type)) { 383 topSet.add(testType); 384 } else if (type.isSubtypeOf(testType)) { 385 topSet.add(type); 386 } 387 } 388 return topSet; 389 } 390 391 private void addMySubTypes(Set types) { 392 if (types.contains(this)) return; 393 394 types.add(this); 395 396 for (Iterator i = directSubTypes.iterator(); i.hasNext(); ) { 397 Type addType = (Type)i.next(); 398 addType.addMySubTypes(types); 399 } 400 } 401 402 403 public Set getSubTypes() { 404 Set subTypes = new HashSet(); 405 addMySubTypes(subTypes); 406 return subTypes; 407 } 408 409 410 public static Set addSubTypes(Set types) { 411 Set newTypes = new HashSet(); 412 413 for(Iterator iter = types.iterator(); iter.hasNext(); ) { 414 Type type = (Type)iter.next(); 415 newTypes.addAll(type.getSubTypes()); 416 } 417 return newTypes; 418 } 419 420 421 private void addMySuperInterfaces(Set types) { 422 if (types.contains(this)) return; 423 424 if (this.isInterface()) types.add(this); 425 426 for (Iterator i = directSuperTypes.iterator(); i.hasNext(); ) { 427 Type addType = (Type)i.next(); 428 addType.addMySuperInterfaces(types); 429 } 430 } 431 432 433 public Set getAllSuperInterfaces() { 434 Set newTypes = new HashSet(); 435 addMySuperInterfaces(newTypes); 436 return newTypes; 437 } 438 439 public static Set filterConcreteTypes(Set types) { 440 Set newTypes = new HashSet(); 441 442 for(Iterator iter = types.iterator(); iter.hasNext(); ) { 443 Type type = (Type)iter.next(); 444 if (type.isConcrete()) newTypes.add(type); 445 } 446 return newTypes; 447 } 448 449 public static Set makeTypeSet(Collection typeDecSet) { 450 HashSet ret = new HashSet(); 451 for (Iterator i = typeDecSet.iterator(); i.hasNext(); ) { 452 ret.add( ((TypeDec)i.next()).getType() ); 453 } 454 return ret; 455 } 456 457 460 final LiteralExpr unsupportedFold() { 461 throw new RuntimeException ("Unsupported fold on " + this); 462 } 463 abstract LiteralExpr foldCast(LiteralExpr lit); 464 465 abstract LiteralExpr foldPlusOp(LiteralExpr rand); 466 abstract LiteralExpr foldMinusOp(LiteralExpr rand); 467 abstract LiteralExpr foldBitNotOp(LiteralExpr rand); 468 abstract LiteralExpr foldLogNotOp(LiteralExpr rand); 469 470 abstract LiteralExpr foldAddOp(LiteralExpr lit1, LiteralExpr lit2); 471 abstract LiteralExpr foldNumericOp(String op, LiteralExpr lit1, LiteralExpr lit2); 472 abstract LiteralExpr foldBitwiseOp(String op, LiteralExpr lit1, LiteralExpr lit2); 473 abstract LiteralExpr foldShiftOp(String op, LiteralExpr lit1, LiteralExpr lit2); 474 abstract LiteralExpr foldEqualityTestOp(String op, LiteralExpr lit1, LiteralExpr lit2); 475 abstract LiteralExpr foldNumericTestOp(String op, LiteralExpr lit1, LiteralExpr lit2); 476 477 480 public static final int REF = 0; 482 public static final int VOID = 1; 483 public static final int BOOLEAN = 4; 484 public static final int CHAR = 5; 485 public static final int FLOAT = 6; 486 public static final int DOUBLE = 7; 487 public static final int BYTE = 8; 488 public static final int SHORT = 9; 489 public static final int INT = 10; 490 public static final int LONG = 11; 491 492 public int getTypeIndex() { return REF; } 493 494 void emitMultiNewarray(CodeBuilder cb, int filledDims) { 496 throw new RuntimeException ("Unsupported emit on " + this); 497 } 498 499 void emitPop(CodeBuilder cb) { cb.emitPOP(); } 501 void emitDup(CodeBuilder cb) { cb.emitDUP(); } 502 void emitDupX1(CodeBuilder cb) { cb.emitDUP_X1(); } 503 void emitDupX2(CodeBuilder cb) { cb.emitDUP_X2(); } 504 505 final void unsupportedEmit() { 507 throw new RuntimeException ("Unsupported emit on " + this); 508 } 509 abstract void emitAload(CodeBuilder cb); 510 abstract void emitAstore(CodeBuilder cb); 511 abstract void emitInstanceof(CodeBuilder cb); 512 abstract void emitBitNot(CodeBuilder cb); 513 abstract void emitLogNot(CodeBuilder cb); 514 abstract void emitNewarray(CodeBuilder cb); 515 abstract void emitZero(CodeBuilder cb); 516 abstract void emitOne(CodeBuilder cb); 517 abstract void emitMinusOne(CodeBuilder cb); 518 abstract void emitAdd(CodeBuilder cb); 519 abstract void emitNeg(CodeBuilder cb); 520 521 abstract void emitNumericOp(CodeBuilder cb, String op); 522 abstract void emitBitwiseOp(CodeBuilder cb, String op); 523 abstract void emitShiftOp(CodeBuilder cb, String op); 524 525 abstract void emitCast(CodeBuilder cb, Type castTo); 526 527 public abstract void emitLoad(CodeBuilder cb, int loc); 528 public abstract void emitStore(CodeBuilder cb, int loc); 529 public abstract void emitReturn(CodeBuilder cb); 530 531 abstract void emitEqualityCompare(CodeBuilder cb, String op, Label t, Label f); 532 abstract void emitNumericCompare(CodeBuilder cb, String op, Label t, Label f); 533 534 537 boolean hasFastEqualityTestOp() { return false; } 538 void emitFastEqualityTestOp(CodeBuilder cb, EqualityTestOpExpr e, 539 Label t, Label f) { 540 throw new RuntimeException ("no fast equality op available"); 541 } 542 543 544 boolean hasFastNumericTestOp() { return false; } 545 void emitFastNumericTestOp(CodeBuilder cb, NumericTestOpExpr e, 546 Label t, Label f) { 547 throw new RuntimeException ("no fast numeric op available"); 548 } 549 550 boolean hasFastIncOp(Expr lhs, int rhs) { return false; } 551 void emitFastIncOp(CodeBuilder cb, Expr lhs, int rhs) { 552 throw new RuntimeException ("no fast inc op available"); 553 } 554 555 558 561 public String getInternalName() { 562 throw new RuntimeException ("No internal name for " + this); 563 } 564 565 572 573 public String getExternalName() { return getString(); 576 } 577 578 579 public List getNamePieces() { 580 String s = getString(); 581 List ret = new ArrayList(); 582 int lastDot = 0; 583 while (true) { 584 int nextDot = s.indexOf('.', lastDot); 585 if (nextDot == -1) break; 586 ret.add(s.substring(lastDot, nextDot)); 587 lastDot = nextDot+1; 588 } 589 ret.add(s.substring(lastDot)); 590 return ret; 591 } 592 593 596 public abstract String getDescriptor(); 597 598 601 public int getSlotCount() { return 1; } 602 603 } 604 | Popular Tags |