From 0f1eea08b632167ae78d63cf7af5e62b219b7a63 Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 8 May 2008 19:26:43 +0000 Subject: [PATCH] rewrite --- bcel-builder/.classpath | 3 +- bcel-builder/build.xml | 16 +- bcel-builder/patch.txt | 310 -- bcel-builder/readme.html | 86 +- .../apache/bcel/ExceptionConstants.java | 318 +- .../org/aspectj/apache/bcel/Repository.java | 492 +- .../apache/bcel/classfile/AccessFlags.java | 165 - .../bcel/classfile/AnnotationDefault.java | 110 +- .../apache/bcel/classfile/Attribute.java | 390 +- .../bcel/classfile/AttributeReader.java | 97 - .../apache/bcel/classfile/AttributeUtils.java | 186 +- .../bcel/classfile/ClassFormatException.java | 138 +- .../apache/bcel/classfile/ClassParser.java | 502 +- .../{Visitor.java => ClassVisitor.java} | 230 +- .../aspectj/apache/bcel/classfile/Code.java | 752 +-- .../apache/bcel/classfile/CodeException.java | 392 +- .../apache/bcel/classfile/Constant.java | 276 +- .../apache/bcel/classfile/ConstantCP.java | 308 +- .../apache/bcel/classfile/ConstantClass.java | 312 +- .../apache/bcel/classfile/ConstantDouble.java | 284 +- .../bcel/classfile/ConstantFieldref.java | 208 +- .../apache/bcel/classfile/ConstantFloat.java | 282 +- .../bcel/classfile/ConstantInteger.java | 296 +- .../classfile/ConstantInterfaceMethodref.java | 208 +- .../apache/bcel/classfile/ConstantLong.java | 278 +- .../bcel/classfile/ConstantMethodref.java | 208 +- .../bcel/classfile/ConstantNameAndType.java | 342 +- .../apache/bcel/classfile/ConstantObject.java | 138 +- .../apache/bcel/classfile/ConstantPool.java | 1223 +++-- .../apache/bcel/classfile/ConstantString.java | 294 +- .../apache/bcel/classfile/ConstantUtf8.java | 288 +- .../apache/bcel/classfile/ConstantValue.java | 356 +- .../apache/bcel/classfile/Deprecated.java | 338 +- .../bcel/classfile/EnclosingMethod.java | 174 +- .../apache/bcel/classfile/ExceptionTable.java | 404 +- .../aspectj/apache/bcel/classfile/Field.java | 287 +- .../apache/bcel/classfile/FieldOrMethod.java | 418 +- .../apache/bcel/classfile/InnerClass.java | 442 +- .../apache/bcel/classfile/InnerClasses.java | 362 +- .../apache/bcel/classfile/JavaClass.java | 1878 ++++--- .../apache/bcel/classfile/LineNumber.java | 332 +- .../bcel/classfile/LineNumberTable.java | 552 +- .../apache/bcel/classfile/LocalVariable.java | 518 +- .../bcel/classfile/LocalVariableTable.java | 468 +- .../classfile/LocalVariableTypeTable.java | 270 +- .../aspectj/apache/bcel/classfile/Method.java | 472 +- .../Modifiers.java} | 123 +- .../aspectj/apache/bcel/classfile/Node.java | 130 +- .../apache/bcel/classfile/PMGClass.java | 378 +- .../apache/bcel/classfile/Signature.java | 1068 ++-- .../apache/bcel/classfile/SourceFile.java | 346 +- .../apache/bcel/classfile/StackMap.java | 370 +- .../apache/bcel/classfile/StackMapEntry.java | 420 +- .../apache/bcel/classfile/StackMapType.java | 344 +- .../apache/bcel/classfile/Synthetic.java | 368 +- .../apache/bcel/classfile/Unknown.java | 424 +- .../apache/bcel/classfile/Utility.java | 2699 ++++----- .../bcel/classfile/annotation/Annotation.java | 130 - .../annotation/AnnotationElementValue.java | 51 - .../annotation/ArrayElementValue.java | 66 - .../annotation/ClassElementValue.java | 53 - .../annotation/ElementNameValuePair.java | 62 - .../classfile/annotation/ElementValue.java | 112 - .../annotation/EnumElementValue.java | 62 - .../RuntimeInvisibleAnnotations.java | 78 +- .../RuntimeInvisibleParameterAnnotations.java | 66 +- .../annotation/RuntimeVisibleAnnotations.java | 78 +- .../RuntimeVisibleParameterAnnotations.java | 66 +- .../annotation/SimpleElementValue.java | 169 - .../apache/bcel/classfile/package.html | 14 - .../aspectj/apache/bcel/generic/AALOAD.java | 87 - .../aspectj/apache/bcel/generic/AASTORE.java | 87 - .../apache/bcel/generic/ACONST_NULL.java | 94 - .../aspectj/apache/bcel/generic/ALOAD.java | 92 - .../apache/bcel/generic/ANEWARRAY.java | 114 - .../aspectj/apache/bcel/generic/ARETURN.java | 88 - .../apache/bcel/generic/ARRAYLENGTH.java | 92 - .../aspectj/apache/bcel/generic/ASTORE.java | 92 - .../aspectj/apache/bcel/generic/ATHROW.java | 92 - .../bcel/generic/AllocationInstruction.java | 64 - .../bcel/generic/ArithmeticInstruction.java | 106 - .../apache/bcel/generic/ArrayInstruction.java | 106 - .../apache/bcel/generic/ArrayType.java | 312 +- .../aspectj/apache/bcel/generic/BALOAD.java | 87 - .../aspectj/apache/bcel/generic/BASTORE.java | 87 - .../aspectj/apache/bcel/generic/BIPUSH.java | 131 - .../apache/bcel/generic/BREAKPOINT.java | 79 - .../apache/bcel/generic/BasicType.java | 202 +- .../apache/bcel/generic/BranchHandle.java | 282 +- .../bcel/generic/BranchInstruction.java | 246 - .../aspectj/apache/bcel/generic/CALOAD.java | 87 - .../aspectj/apache/bcel/generic/CASTORE.java | 87 - .../apache/bcel/generic/CHECKCAST.java | 117 - .../apache/bcel/generic/CPInstruction.java | 169 - .../aspectj/apache/bcel/generic/ClassGen.java | 1412 +++-- .../bcel/generic/ClassGenException.java | 136 +- .../apache/bcel/generic/ClassObserver.java | 67 - .../apache/bcel/generic/CodeExceptionGen.java | 404 +- .../bcel/generic/CompoundInstruction.java | 76 - .../apache/bcel/generic/ConstantPoolGen.java | 802 --- .../bcel/generic/ConstantPushInstruction.java | 70 - .../bcel/generic/ConversionInstruction.java | 102 - .../org/aspectj/apache/bcel/generic/D2F.java | 87 - .../org/aspectj/apache/bcel/generic/D2I.java | 87 - .../org/aspectj/apache/bcel/generic/D2L.java | 87 - .../org/aspectj/apache/bcel/generic/DADD.java | 88 - .../aspectj/apache/bcel/generic/DALOAD.java | 87 - .../aspectj/apache/bcel/generic/DASTORE.java | 87 - .../aspectj/apache/bcel/generic/DCMPG.java | 93 - .../aspectj/apache/bcel/generic/DCMPL.java | 92 - .../aspectj/apache/bcel/generic/DCONST.java | 111 - .../org/aspectj/apache/bcel/generic/DDIV.java | 88 - .../aspectj/apache/bcel/generic/DLOAD.java | 92 - .../org/aspectj/apache/bcel/generic/DMUL.java | 88 - .../org/aspectj/apache/bcel/generic/DNEG.java | 85 - .../org/aspectj/apache/bcel/generic/DREM.java | 88 - .../aspectj/apache/bcel/generic/DRETURN.java | 87 - .../aspectj/apache/bcel/generic/DSTORE.java | 92 - .../org/aspectj/apache/bcel/generic/DSUB.java | 88 - .../org/aspectj/apache/bcel/generic/DUP.java | 84 - .../org/aspectj/apache/bcel/generic/DUP2.java | 84 - .../aspectj/apache/bcel/generic/DUP2_X1.java | 82 - .../aspectj/apache/bcel/generic/DUP2_X2.java | 82 - .../aspectj/apache/bcel/generic/DUP_X1.java | 82 - .../aspectj/apache/bcel/generic/DUP_X2.java | 82 - .../apache/bcel/generic/ExceptionThrower.java | 79 - .../org/aspectj/apache/bcel/generic/F2D.java | 87 - .../org/aspectj/apache/bcel/generic/F2I.java | 87 - .../org/aspectj/apache/bcel/generic/F2L.java | 87 - .../org/aspectj/apache/bcel/generic/FADD.java | 87 - .../aspectj/apache/bcel/generic/FALOAD.java | 87 - .../aspectj/apache/bcel/generic/FASTORE.java | 87 - .../aspectj/apache/bcel/generic/FCMPG.java | 91 - .../aspectj/apache/bcel/generic/FCMPL.java | 91 - .../aspectj/apache/bcel/generic/FCONST.java | 113 - .../org/aspectj/apache/bcel/generic/FDIV.java | 87 - .../aspectj/apache/bcel/generic/FLOAD.java | 92 - .../org/aspectj/apache/bcel/generic/FMUL.java | 87 - .../org/aspectj/apache/bcel/generic/FNEG.java | 85 - .../org/aspectj/apache/bcel/generic/FREM.java | 87 - .../aspectj/apache/bcel/generic/FRETURN.java | 87 - .../aspectj/apache/bcel/generic/FSTORE.java | 92 - .../org/aspectj/apache/bcel/generic/FSUB.java | 87 - .../aspectj/apache/bcel/generic/FieldGen.java | 550 +- .../bcel/generic/FieldGenOrMethodGen.java | 317 +- .../apache/bcel/generic/FieldInstruction.java | 214 +- .../apache/bcel/generic/FieldObserver.java | 67 - .../apache/bcel/generic/FieldOrMethod.java | 268 +- .../aspectj/apache/bcel/generic/GETFIELD.java | 117 - .../apache/bcel/generic/GETSTATIC.java | 113 - .../org/aspectj/apache/bcel/generic/GOTO.java | 122 - .../aspectj/apache/bcel/generic/GOTO_W.java | 110 - .../apache/bcel/generic/GotoInstruction.java | 75 - .../org/aspectj/apache/bcel/generic/I2B.java | 87 - .../org/aspectj/apache/bcel/generic/I2C.java | 87 - .../org/aspectj/apache/bcel/generic/I2D.java | 87 - .../org/aspectj/apache/bcel/generic/I2F.java | 87 - .../org/aspectj/apache/bcel/generic/I2L.java | 87 - .../org/aspectj/apache/bcel/generic/I2S.java | 85 - .../org/aspectj/apache/bcel/generic/IADD.java | 87 - .../aspectj/apache/bcel/generic/IALOAD.java | 88 - .../org/aspectj/apache/bcel/generic/IAND.java | 85 - .../aspectj/apache/bcel/generic/IASTORE.java | 88 - .../aspectj/apache/bcel/generic/ICONST.java | 109 - .../org/aspectj/apache/bcel/generic/IDIV.java | 94 - .../org/aspectj/apache/bcel/generic/IFEQ.java | 98 - .../org/aspectj/apache/bcel/generic/IFGE.java | 98 - .../org/aspectj/apache/bcel/generic/IFGT.java | 98 - .../org/aspectj/apache/bcel/generic/IFLE.java | 98 - .../org/aspectj/apache/bcel/generic/IFLT.java | 98 - .../org/aspectj/apache/bcel/generic/IFNE.java | 98 - .../apache/bcel/generic/IFNONNULL.java | 97 - .../aspectj/apache/bcel/generic/IFNULL.java | 98 - .../apache/bcel/generic/IF_ACMPEQ.java | 97 - .../apache/bcel/generic/IF_ACMPNE.java | 98 - .../apache/bcel/generic/IF_ICMPEQ.java | 98 - .../apache/bcel/generic/IF_ICMPGE.java | 98 - .../apache/bcel/generic/IF_ICMPGT.java | 98 - .../apache/bcel/generic/IF_ICMPLE.java | 98 - .../apache/bcel/generic/IF_ICMPLT.java | 98 - .../apache/bcel/generic/IF_ICMPNE.java | 98 - .../org/aspectj/apache/bcel/generic/IINC.java | 216 +- .../aspectj/apache/bcel/generic/ILOAD.java | 92 - .../aspectj/apache/bcel/generic/IMPDEP1.java | 80 - .../aspectj/apache/bcel/generic/IMPDEP2.java | 80 - .../org/aspectj/apache/bcel/generic/IMUL.java | 87 - .../org/aspectj/apache/bcel/generic/INEG.java | 85 - .../apache/bcel/generic/INSTANCEOF.java | 106 - .../apache/bcel/generic/INVOKEINTERFACE.java | 220 +- .../apache/bcel/generic/INVOKESPECIAL.java | 113 - .../apache/bcel/generic/INVOKESTATIC.java | 110 - .../apache/bcel/generic/INVOKEVIRTUAL.java | 112 - .../org/aspectj/apache/bcel/generic/IOR.java | 85 - .../org/aspectj/apache/bcel/generic/IREM.java | 94 - .../aspectj/apache/bcel/generic/IRETURN.java | 87 - .../org/aspectj/apache/bcel/generic/ISHL.java | 85 - .../org/aspectj/apache/bcel/generic/ISHR.java | 85 - .../aspectj/apache/bcel/generic/ISTORE.java | 92 - .../org/aspectj/apache/bcel/generic/ISUB.java | 87 - .../aspectj/apache/bcel/generic/IUSHR.java | 85 - .../org/aspectj/apache/bcel/generic/IXOR.java | 85 - .../apache/bcel/generic/IfInstruction.java | 82 - .../bcel/generic/IndexedInstruction.java | 68 - .../{Visitor.java => InstVisitor.java} | 494 +- .../apache/bcel/generic/Instruction.java | 1793 +++--- .../bcel/generic/InstructionBranch.java | 679 +-- .../apache/bcel/generic/InstructionCP.java | 392 +- .../bcel/generic/InstructionComparator.java | 224 +- .../bcel/generic/InstructionConstants.java | 734 +-- .../bcel/generic/InstructionFactory.java | 1423 +++-- .../bcel/generic/InstructionHandle.java | 496 +- .../apache/bcel/generic/InstructionLV.java | 366 +- .../apache/bcel/generic/InstructionList.java | 2401 ++++---- .../bcel/generic/InstructionListObserver.java | 67 - .../bcel/generic/InstructionSelect.java | 546 +- .../bcel/generic/InstructionTargeter.java | 140 +- .../bcel/generic/InvokeInstruction.java | 264 +- .../org/aspectj/apache/bcel/generic/JSR.java | 119 - .../aspectj/apache/bcel/generic/JSR_W.java | 110 - .../apache/bcel/generic/JsrInstruction.java | 115 - .../org/aspectj/apache/bcel/generic/L2D.java | 85 - .../org/aspectj/apache/bcel/generic/L2F.java | 85 - .../org/aspectj/apache/bcel/generic/L2I.java | 85 - .../org/aspectj/apache/bcel/generic/LADD.java | 86 - .../aspectj/apache/bcel/generic/LALOAD.java | 87 - .../org/aspectj/apache/bcel/generic/LAND.java | 86 - .../aspectj/apache/bcel/generic/LASTORE.java | 87 - .../org/aspectj/apache/bcel/generic/LCMP.java | 92 - .../aspectj/apache/bcel/generic/LCONST.java | 111 - .../org/aspectj/apache/bcel/generic/LDC.java | 172 - .../aspectj/apache/bcel/generic/LDC2_W.java | 116 - .../aspectj/apache/bcel/generic/LDC_W.java | 88 - .../org/aspectj/apache/bcel/generic/LDIV.java | 91 - .../aspectj/apache/bcel/generic/LLOAD.java | 89 - .../org/aspectj/apache/bcel/generic/LMUL.java | 86 - .../org/aspectj/apache/bcel/generic/LNEG.java | 85 - .../apache/bcel/generic/LOOKUPSWITCH.java | 230 +- .../org/aspectj/apache/bcel/generic/LOR.java | 85 - .../org/aspectj/apache/bcel/generic/LREM.java | 88 - .../aspectj/apache/bcel/generic/LRETURN.java | 85 - .../org/aspectj/apache/bcel/generic/LSHL.java | 85 - .../org/aspectj/apache/bcel/generic/LSHR.java | 85 - .../aspectj/apache/bcel/generic/LSTORE.java | 89 - .../org/aspectj/apache/bcel/generic/LSUB.java | 86 - .../aspectj/apache/bcel/generic/LUSHR.java | 85 - .../org/aspectj/apache/bcel/generic/LXOR.java | 85 - .../apache/bcel/generic/LineNumberGen.java | 260 +- .../apache/bcel/generic/LineNumberTag.java | 84 +- .../apache/bcel/generic/LoadClass.java | 86 - .../apache/bcel/generic/LocalVariableGen.java | 412 +- .../generic/LocalVariableInstruction.java | 224 - .../apache/bcel/generic/LocalVariableTag.java | 156 +- .../apache/bcel/generic/MONITORENTER.java | 88 - .../apache/bcel/generic/MONITOREXIT.java | 88 - .../apache/bcel/generic/MULTIANEWARRAY.java | 322 +- .../apache/bcel/generic/MethodGen.java | 2199 ++++---- .../apache/bcel/generic/MethodObserver.java | 67 - .../org/aspectj/apache/bcel/generic/NEW.java | 110 - .../aspectj/apache/bcel/generic/NEWARRAY.java | 140 - .../org/aspectj/apache/bcel/generic/NOP.java | 80 - .../apache/bcel/generic/NamedAndTyped.java | 71 - .../apache/bcel/generic/ObjectType.java | 286 +- .../org/aspectj/apache/bcel/generic/POP.java | 85 - .../org/aspectj/apache/bcel/generic/POP2.java | 85 - .../org/aspectj/apache/bcel/generic/PUSH.java | 199 - .../aspectj/apache/bcel/generic/PUTFIELD.java | 118 - .../apache/bcel/generic/PUTSTATIC.java | 114 - .../apache/bcel/generic/PopInstruction.java | 68 - .../apache/bcel/generic/PushInstruction.java | 73 - .../org/aspectj/apache/bcel/generic/RET.java | 212 +- .../aspectj/apache/bcel/generic/RETURN.java | 85 - .../apache/bcel/generic/ReferenceType.java | 698 +-- .../bcel/generic/ReturnInstruction.java | 104 - .../bcel/generic/ReturnaddressType.java | 204 +- .../aspectj/apache/bcel/generic/SALOAD.java | 85 - .../aspectj/apache/bcel/generic/SASTORE.java | 85 - .../aspectj/apache/bcel/generic/SIPUSH.java | 128 - .../org/aspectj/apache/bcel/generic/SWAP.java | 84 - .../aspectj/apache/bcel/generic/SWITCH.java | 187 - .../aspectj/apache/bcel/generic/Select.java | 254 - .../apache/bcel/generic/StackConsumer.java | 68 - .../apache/bcel/generic/StackInstruction.java | 83 - .../apache/bcel/generic/StackProducer.java | 69 - .../apache/bcel/generic/StoreInstruction.java | 101 - .../apache/bcel/generic/SwitchBuilder.java | 362 +- .../apache/bcel/generic/TABLESWITCH.java | 272 +- .../org/aspectj/apache/bcel/generic/Tag.java | 85 +- .../bcel/generic/TargetLostException.java | 201 +- .../org/aspectj/apache/bcel/generic/Type.java | 792 +-- .../apache/bcel/generic/TypedInstruction.java | 67 - .../bcel/generic/UnconditionalBranch.java | 67 - .../generic/VariableLengthInstruction.java | 70 - .../annotation/AnnotationElementValueGen.java | 63 - .../generic/annotation/AnnotationGen.java | 166 - .../annotation/ArrayElementValueGen.java | 100 - .../annotation/ClassElementValueGen.java | 81 - .../annotation/ElementNameValuePairGen.java | 86 - .../generic/annotation/ElementValueGen.java | 146 - .../annotation/EnumElementValueGen.java | 101 - .../annotation/SimpleElementValueGen.java | 206 - .../aspectj/apache/bcel/generic/package.html | 16 - .../src/org/aspectj/apache/bcel/package.html | 17 - .../apache/bcel/util/AttributeHTML.java | 272 - .../apache/bcel/util/ByteSequence.java | 164 +- .../aspectj/apache/bcel/util/Class2HTML.java | 270 - .../aspectj/apache/bcel/util/ClassLoader.java | 227 - .../bcel/util/ClassLoaderRepository.java | 736 +-- .../aspectj/apache/bcel/util/ClassPath.java | 756 +-- .../aspectj/apache/bcel/util/ClassQueue.java | 162 +- .../aspectj/apache/bcel/util/ClassSet.java | 96 - .../aspectj/apache/bcel/util/ClassStack.java | 73 - .../aspectj/apache/bcel/util/ClassVector.java | 158 +- .../aspectj/apache/bcel/util/CodeHTML.java | 632 --- .../apache/bcel/util/ConstantHTML.java | 274 - .../aspectj/apache/bcel/util/JavaWrapper.java | 152 - .../aspectj/apache/bcel/util/MethodHTML.java | 208 - .../util/NonCachingClassLoaderRepository.java | 482 +- .../aspectj/apache/bcel/util/Repository.java | 210 +- .../apache/bcel/util/SyntheticRepository.java | 410 +- .../org/aspectj/apache/bcel/util/package.html | 25 - .../apache/bcel/verifier/exc/package.html | 24 - bcel-builder/testfile.txt | 0 .../tests/GenericSignatureParsingTest.java | 286 +- .../tests/ParameterAnnotationsTest.java | 6 +- ...RuntimeVisibleAnnotationAttributeTest.java | 13 +- .../bcel/classfile/tests/UtilTests.java | 12 +- .../bcel/verifier}/DescendingVisitor.java | 841 +-- .../bcel/verifier/EmptyClassVisitor.java} | 272 +- .../bcel/verifier/EmptyInstVisitor.java} | 504 +- .../bcel/verifier/GraphicalVerifier.java | 222 +- .../apache/bcel/verifier/NativeVerifier.java | 232 +- .../apache/bcel/verifier/PassVerifier.java | 286 +- .../apache/bcel/verifier/TransitiveHull.java | 274 +- .../bcel/verifier/VerificationResult.java | 270 +- .../apache/bcel/verifier/Verifier.java | 576 +- .../bcel/verifier/VerifierAppFrame.java | 818 +-- .../apache/bcel/verifier/VerifierFactory.java | 286 +- .../verifier/VerifierFactoryListModel.java | 212 +- .../verifier/VerifierFactoryObserver.java | 152 +- .../apache/bcel/verifier/VerifyDialog.java | 1118 ++-- .../exc/AssertionViolatedException.java | 214 +- .../exc/ClassConstraintException.java | 158 +- .../verifier/exc/CodeConstraintException.java | 154 +- .../verifier/exc/InvalidMethodException.java | 138 +- .../exc/LinkingConstraintException.java | 148 +- .../bcel/verifier/exc/LoadingException.java | 158 +- ...ocalVariableInfoInconsistentException.java | 162 +- .../exc/StaticCodeConstraintException.java | 142 +- ...ticCodeInstructionConstraintException.java | 148 +- ...InstructionOperandConstraintException.java | 148 +- .../StructuralCodeConstraintException.java | 164 +- .../apache/bcel/verifier/exc/Utility.java | 152 +- .../verifier/exc/VerificationException.java | 164 +- .../VerifierConstraintViolatedException.java | 214 +- .../aspectj/apache/bcel/verifier/package.html | 50 +- .../bcel/verifier/statics/DOUBLE_Upper.java | 158 +- .../apache/bcel/verifier/statics/IntList.java | 170 +- .../bcel/verifier/statics/LONG_Upper.java | 158 +- .../verifier/statics/LocalVariableInfo.java | 288 +- .../verifier/statics/LocalVariablesInfo.java | 212 +- .../bcel/verifier/statics/Pass1Verifier.java | 430 +- .../bcel/verifier/statics/Pass2Verifier.java | 2748 +++++----- .../bcel/verifier/statics/Pass3aVerifier.java | 2289 ++++---- .../statics/StringRepresentation.java | 538 +- .../apache/bcel/verifier/statics/package.html | 52 +- .../structurals/ControlFlowGraph.java | 950 ++-- .../structurals/ExceptionHandler.java | 186 +- .../structurals/ExceptionHandlers.java | 214 +- .../structurals/ExecutionVisitor.java | 2258 ++++---- .../bcel/verifier/structurals/Frame.java | 300 +- .../verifier/structurals/GenericArray.java | 132 +- .../structurals/InstConstraintVisitor.java | 4872 +++++++++-------- .../structurals/InstructionContext.java | 282 +- .../verifier/structurals/LocalVariables.java | 458 +- .../verifier/structurals/OperandStack.java | 550 +- .../verifier/structurals/Pass3bVerifier.java | 754 +-- .../bcel/verifier/structurals/Subroutine.java | 252 +- .../verifier/structurals/Subroutines.java | 1338 ++--- .../structurals/UninitializedObjectType.java | 194 +- .../bcel/verifier/structurals/package.html | 2 +- .../bcel/verifier}/util/BCELFactory.java | 734 +-- .../apache/bcel/verifier}/util/BCELifier.java | 655 +-- .../verifier}/util/InstructionFinder.java | 880 +-- 383 files changed, 38683 insertions(+), 61651 deletions(-) delete mode 100644 bcel-builder/patch.txt delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/classfile/AccessFlags.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/classfile/AttributeReader.java rename bcel-builder/src/org/aspectj/apache/bcel/classfile/{Visitor.java => ClassVisitor.java} (96%) rename bcel-builder/src/org/aspectj/apache/bcel/{generic/LoadInstruction.java => classfile/Modifiers.java} (59%) delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/Annotation.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/AnnotationElementValue.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ArrayElementValue.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ClassElementValue.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ElementNameValuePair.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ElementValue.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/EnumElementValue.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/SimpleElementValue.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/classfile/package.html delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/AALOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/AASTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ACONST_NULL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ALOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ANEWARRAY.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ARETURN.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ARRAYLENGTH.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ASTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ATHROW.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/AllocationInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ArithmeticInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ArrayInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/BALOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/BASTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/BIPUSH.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/BREAKPOINT.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/BranchInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/CALOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/CASTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/CHECKCAST.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/CPInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ClassObserver.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/CompoundInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ConstantPoolGen.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ConstantPushInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ConversionInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/D2F.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/D2I.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/D2L.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DADD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DALOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DASTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DCMPG.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DCMPL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DCONST.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DDIV.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DLOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DMUL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DNEG.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DREM.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DRETURN.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DSTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DSUB.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DUP.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DUP2.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DUP2_X1.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DUP2_X2.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DUP_X1.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/DUP_X2.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ExceptionThrower.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/F2D.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/F2I.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/F2L.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FADD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FALOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FASTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FCMPG.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FCMPL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FCONST.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FDIV.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FLOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FMUL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FNEG.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FREM.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FRETURN.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FSTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FSUB.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/FieldObserver.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/GETFIELD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/GETSTATIC.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/GOTO.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/GOTO_W.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/GotoInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/I2B.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/I2C.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/I2D.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/I2F.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/I2L.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/I2S.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IADD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IALOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IAND.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IASTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ICONST.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IDIV.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IFEQ.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IFGE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IFGT.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IFLE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IFLT.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IFNE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IFNONNULL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IFNULL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ACMPEQ.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ACMPNE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPEQ.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPGE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPGT.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPLE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPLT.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPNE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ILOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IMPDEP1.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IMPDEP2.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IMUL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/INEG.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/INSTANCEOF.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKESPECIAL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKESTATIC.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKEVIRTUAL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IOR.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IREM.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IRETURN.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ISHL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ISHR.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ISTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ISUB.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IUSHR.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IXOR.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IfInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/IndexedInstruction.java rename bcel-builder/src/org/aspectj/apache/bcel/generic/{Visitor.java => InstVisitor.java} (96%) delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionListObserver.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/JSR.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/JSR_W.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/JsrInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/L2D.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/L2F.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/L2I.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LADD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LALOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LAND.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LASTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LCMP.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LCONST.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LDC.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LDC2_W.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LDC_W.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LDIV.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LLOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LMUL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LNEG.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LOR.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LREM.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LRETURN.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LSHL.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LSHR.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LSTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LSUB.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LUSHR.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LXOR.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LoadClass.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/LocalVariableInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/MONITORENTER.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/MONITOREXIT.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/MethodObserver.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/NEW.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/NEWARRAY.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/NOP.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/NamedAndTyped.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/POP.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/POP2.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/PUSH.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/PUTFIELD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/PUTSTATIC.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/PopInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/PushInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/RETURN.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/ReturnInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/SALOAD.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/SASTORE.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/SIPUSH.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/SWAP.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/SWITCH.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/Select.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/StackConsumer.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/StackInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/StackProducer.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/StoreInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/TypedInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/UnconditionalBranch.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/VariableLengthInstruction.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/AnnotationElementValueGen.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/AnnotationGen.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/ArrayElementValueGen.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/ClassElementValueGen.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/ElementNameValuePairGen.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/ElementValueGen.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/EnumElementValueGen.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/SimpleElementValueGen.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/generic/package.html delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/package.html delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/util/AttributeHTML.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/util/Class2HTML.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/util/ClassLoader.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/util/ClassSet.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/util/ClassStack.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/util/CodeHTML.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/util/ConstantHTML.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/util/JavaWrapper.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/util/MethodHTML.java delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/util/package.html delete mode 100644 bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/package.html delete mode 100644 bcel-builder/testfile.txt rename bcel-builder/{src/org/aspectj/apache/bcel/classfile => verifier-src/org/aspectj/apache/bcel/verifier}/DescendingVisitor.java (82%) rename bcel-builder/{src/org/aspectj/apache/bcel/classfile/EmptyVisitor.java => verifier-src/org/aspectj/apache/bcel/verifier/EmptyClassVisitor.java} (71%) rename bcel-builder/{src/org/aspectj/apache/bcel/generic/EmptyVisitor.java => verifier-src/org/aspectj/apache/bcel/verifier/EmptyInstVisitor.java} (92%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/GraphicalVerifier.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/NativeVerifier.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/PassVerifier.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/TransitiveHull.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/VerificationResult.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/Verifier.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/VerifierAppFrame.java (97%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/VerifierFactory.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/VerifierFactoryListModel.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/VerifierFactoryObserver.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/VerifyDialog.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/AssertionViolatedException.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/ClassConstraintException.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/CodeConstraintException.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/InvalidMethodException.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/LinkingConstraintException.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/LoadingException.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/LocalVariableInfoInconsistentException.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/StaticCodeConstraintException.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionConstraintException.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionOperandConstraintException.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/StructuralCodeConstraintException.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/Utility.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/VerificationException.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/exc/VerifierConstraintViolatedException.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/package.html (87%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/statics/DOUBLE_Upper.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/statics/IntList.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/statics/LONG_Upper.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/statics/LocalVariableInfo.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/statics/LocalVariablesInfo.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/statics/Pass1Verifier.java (97%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/statics/Pass2Verifier.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/statics/Pass3aVerifier.java (97%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/statics/StringRepresentation.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/statics/package.html (87%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/ControlFlowGraph.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandler.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandlers.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/ExecutionVisitor.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/Frame.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/GenericArray.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/InstConstraintVisitor.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/InstructionContext.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/LocalVariables.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/OperandStack.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/Pass3bVerifier.java (97%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/Subroutine.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/Subroutines.java (96%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/UninitializedObjectType.java (95%) rename bcel-builder/{src => verifier-src}/org/aspectj/apache/bcel/verifier/structurals/package.html (92%) rename bcel-builder/{src/org/aspectj/apache/bcel => verifier-src/org/aspectj/apache/bcel/verifier}/util/BCELFactory.java (90%) rename bcel-builder/{src/org/aspectj/apache/bcel => verifier-src/org/aspectj/apache/bcel/verifier}/util/BCELifier.java (90%) rename bcel-builder/{src/org/aspectj/apache/bcel => verifier-src/org/aspectj/apache/bcel/verifier}/util/InstructionFinder.java (97%) diff --git a/bcel-builder/.classpath b/bcel-builder/.classpath index 955afd2c0..5cb8fd272 100644 --- a/bcel-builder/.classpath +++ b/bcel-builder/.classpath @@ -1,9 +1,10 @@ + - + diff --git a/bcel-builder/build.xml b/bcel-builder/build.xml index 157cfb9f5..9e7feacd8 100644 --- a/bcel-builder/build.xml +++ b/bcel-builder/build.xml @@ -1,10 +1,5 @@ - - - - - @@ -21,7 +16,6 @@ - @@ -63,14 +57,20 @@ + + + + - - + + + + diff --git a/bcel-builder/patch.txt b/bcel-builder/patch.txt deleted file mode 100644 index 63ff8b5de..000000000 --- a/bcel-builder/patch.txt +++ /dev/null @@ -1,310 +0,0 @@ -diff -N -a -u -r -b bcel-5.1/build.xml bcel/build.xml ---- bcel-5.1/build.xml 2003-04-25 09:06:14.000000000 +0100 -+++ bcel/build.xml 2004-08-11 21:25:17.449281600 +0100 -@@ -65,7 +65,7 @@ - - - -- -+ - `this' is local var 0 -- addLocalVariable("this", new ObjectType(class_name), start, end); -- } -+// if(!isStatic() && (class_name != null)) { // Instance method -> `this' is local var 0 -+// addLocalVariable("this", new ObjectType(class_name), start, end); -+// } - } - - if(arg_types != null) { -@@ -152,17 +152,17 @@ - throw new ClassGenException("Mismatch in argument array lengths: " + - size + " vs. " + arg_names.length); - } else { // Give them dummy names -- arg_names = new String[size]; -- -- for(int i=0; i < size; i++) -- arg_names[i] = "arg" + i; -- -- setArgumentNames(arg_names); -+// arg_names = new String[size]; -+// -+// for(int i=0; i < size; i++) -+// arg_names[i] = "arg" + i; -+// -+// setArgumentNames(arg_names); - } - - if(!abstract_) { - for(int i=0; i < size; i++) { -- addLocalVariable(arg_names[i], arg_types[i], start, end); -+// addLocalVariable(arg_names[i], arg_types[i], start, end); - } - } - } diff --git a/bcel-builder/readme.html b/bcel-builder/readme.html index 9a17e14bc..43f8f8c27 100644 --- a/bcel-builder/readme.html +++ b/bcel-builder/readme.html @@ -27,12 +27,6 @@ This module includes a modified form of BCEL - with some fixes in *and* support
  • The LocalVariableTypeTable attribute is supported (used for generics to tell you the original variable signature)
  • All this is implemented without using any Java 5 APIs.

    -

    There are a number of new TODO type tags in the code that may prove useful:

    -
      -
    • J5SUPPORT: Marks places where BCEL has been changed for 1.5 (might have missed a couple...)
    • -
    • BCELBUG: Marks things that might be BCEL problems that I came across
    • -
    • J5TODO: Marks either a missing bit of implementation (hopefully corner case) or an optimization we could make
    • -

    The contents of this directory are:

    @@ -40,6 +34,8 @@ This module includes a modified form of BCEL - with some fixes in *and* support
    • This file
    • src -- contains the source for BCEL, a modified variant of BCEL 5.1 that includes bug fixes and Java 5 support
    • +
    • verifier-src -- contains the source for the bcel verifier package, something used by tests but not packaged + and distributed (at the moment).
    • testsrc -- JUnit test cases for the Java 5 support
    • testdata -- Java5 testcode that can be built using the build.xml script in the testdata directory (see note on this below)
    • build.xml -- an ant script for manipulating the src folder, possibly useful if ever merging a base BCEL version
    • @@ -66,83 +62,5 @@ then used by the testcases - so if you do change the testdata code then you shou to rebuild testcode.jar.
      -

      The old stuff...

      -Before the Java 5 support was added we maintained this module as basically a patch to apply against -a particular download of BCEL. Changes to BCEL are occurring more frequently than we integrate -a new version of BCEL so it made sense to make the patching process easier, so we have checked in -the modified source for BCEL. -The original instructions for patching BCEL in the old way are below... - -

      And pretty much nothing else. Well, then, what do you do with -this directory? Well, the whole point is to generate bcel/bcel.jar in -the lib package. To do so, first stick -bcel-5.1-src.zip in this directory, then run ant. -(at one point, this was available at - -http://archive.apache.org/dist/jakarta/bcel/source/bcel-5.1-src.zip) -After much unzipping, patching, and compiling, you should get an -appropriate bcel.jar file. Now put it in the appropriate place.

      - -

      If there's something wrong with the bcel.jar in the lib -project, well, then you've got some development to do. You'll need -to know some more ant targets. But before anything, get that -bcel-5.1-src.zip and stick it in this directory. -NOTE: You should be working on BCEL when the package names are org.aspectj.apache.bcel, -and *not* when the package names are org.apache.bcel. If you run the extractAndPatch task -below, you will be left with a src folder in the correct state for further development. -

      - -

      There are five top-level ant targets apart from the usual "clean":

      - -
        -
      • ant extractAndPatchAndJar -- this is just the composition of the extract, - jar and srcjar targets, and is the default. It extracts the source from bcel-5.1-src.zip, - patches it, renames the files to start org.aspectj.apache rather than org.apache then - compiles the patched version into a jar and drops the new archives: - bcel.jar and bcel-src.zip, into the project root. This is the default task, mainly used - to sanity check the building and make sure we're generating something. - The bcel.jar and bcel-src.zip generated should be the same as that in ..\lib\bcel\. -
      • - -
      • ant extractAndPatch -- this extracts the source from bcel-5.1-src.zip, - patches it, renames the files to start org.aspectj.apache rather than org.apache then - copies the patched source into the project src directory, - there to be visible by eclipse for people to do development on it. - For the patch file to be applied you need to have a patch.exe on your path, - this bcel building process was tested with the version from cygwin. -
      • - -
      • ant jar -- this copies the edited source from the project source - directory and jars it up into bcel.jar, there to be tested. -
      • - -
      • ant srcjar -- this copies the edited source from the project source - directory and jars up the source code into bcel-src.zip. -
      • - -
      • ant push -- this pushes the new bcel.jar and bcel-src.zip into ..\lib\bcel\. - - ready to be used by the greater compiler.
      • - -
      • ant diff -- this creates the patch.txt file, composed of the differences - between the project src directory and the original bcel-5.1 source. - In order to create the patch, we transform the packages back to org.apache from - org.aspectj.apache. To continue working on BCEL once you have done this, you might - need to run the transformToAJ task to switch the packages back to the AJ prefix. - For the patch file to be built successfully you need to have a diff.exe on your path, - this bcel building process was tested with the version from cygwin. -
      • - -
      • ant transformToAJ - this changes the packages for the BCEL classes to - org.aspectj.apache from org.apache. This is used by the extractAndPatch task above. -
      • - -
      • ant transformFromAJ - this changes the packages for the BCEL classes to - org.apache from org.aspectj.apache. This is used by the diff task. -
      • -
      - -

      All of the tasks are destructive, so don't do "ant extract", for example, -if you have anything in the project source directory you care about. -

      diff --git a/bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java b/bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java index a9b721a4d..c5c7c0836 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java @@ -1,159 +1,159 @@ -package org.aspectj.apache.bcel; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Exception constants. - * - * @version $Id: ExceptionConstants.java,v 1.2.10.2 2008/04/25 17:55:37 aclement Exp $ - * @author E. Haase - */ -public interface ExceptionConstants { - /** The mother of all exceptions - */ - public static final Class THROWABLE = Throwable.class; - - /** Super class of any run-time exception - */ - public static final Class RUNTIME_EXCEPTION = RuntimeException.class; - - /** Super class of any linking exception (aka Linkage Error) - */ - public static final Class LINKING_EXCEPTION = LinkageError.class; - - /** Linking Exceptions - */ - public static final Class CLASS_CIRCULARITY_ERROR = ClassCircularityError.class; - public static final Class CLASS_FORMAT_ERROR = ClassFormatError.class; - public static final Class EXCEPTION_IN_INITIALIZER_ERROR = ExceptionInInitializerError.class; - public static final Class INCOMPATIBLE_CLASS_CHANGE_ERROR = IncompatibleClassChangeError.class; - public static final Class ABSTRACT_METHOD_ERROR = AbstractMethodError.class; - public static final Class ILLEGAL_ACCESS_ERROR = IllegalAccessError.class; - public static final Class INSTANTIATION_ERROR = InstantiationError.class; - public static final Class NO_SUCH_FIELD_ERROR = NoSuchFieldError.class; - public static final Class NO_SUCH_METHOD_ERROR = NoSuchMethodError.class; - public static final Class NO_CLASS_DEF_FOUND_ERROR = NoClassDefFoundError.class; - public static final Class UNSATISFIED_LINK_ERROR = UnsatisfiedLinkError.class; - public static final Class VERIFY_ERROR = VerifyError.class; - - /* UnsupportedClassVersionError is new in JDK 1.2 */ - //public static final Class UnsupportedClassVersionError = UnsupportedClassVersionError.class; - - /** Run-Time Exceptions - */ - public static final Class NULL_POINTER_EXCEPTION = NullPointerException.class; - public static final Class ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION = ArrayIndexOutOfBoundsException.class; - public static final Class ARITHMETIC_EXCEPTION = ArithmeticException.class; - public static final Class NEGATIVE_ARRAY_SIZE_EXCEPTION = NegativeArraySizeException.class; - public static final Class CLASS_CAST_EXCEPTION = ClassCastException.class; - public static final Class ILLEGAL_MONITOR_STATE = IllegalMonitorStateException.class; - - /** Pre-defined exception arrays according to chapters 5.1-5.4 of the Java Virtual - * Machine Specification - */ - public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION = { - NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, - EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR - }; // Chapter 5.1 - public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_MULTIANEWARRAY = { - NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, - EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR,NEGATIVE_ARRAY_SIZE_EXCEPTION,ILLEGAL_ACCESS_ERROR - }; - public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_ANEWARRAY = { - NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, - EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR,NEGATIVE_ARRAY_SIZE_EXCEPTION - }; // Chapter 5.1 - public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_CHECKCAST = { - NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, - EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR,CLASS_CAST_EXCEPTION - }; // Chapter 5.1 - public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_FOR_ALLOCATIONS= { - NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, - EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR, INSTANTIATION_ERROR,ILLEGAL_ACCESS_ERROR - }; - - public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION = { - NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR - }; // Chapter 5.2 - - public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION_GETFIELD_PUTFIELD = { - NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR,INCOMPATIBLE_CLASS_CHANGE_ERROR,NULL_POINTER_EXCEPTION - }; - - public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION_GETSTATIC_PUTSTATIC = { - NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR,INCOMPATIBLE_CLASS_CHANGE_ERROR - }; - - public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKEINTERFACE = { - INCOMPATIBLE_CLASS_CHANGE_ERROR,ILLEGAL_ACCESS_ERROR,ABSTRACT_METHOD_ERROR,UNSATISFIED_LINK_ERROR - }; - public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESPECIAL_INVOKEVIRTUAL = { - INCOMPATIBLE_CLASS_CHANGE_ERROR,NULL_POINTER_EXCEPTION,ABSTRACT_METHOD_ERROR,UNSATISFIED_LINK_ERROR - }; - - public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESTATIC = { - INCOMPATIBLE_CLASS_CHANGE_ERROR,UNSATISFIED_LINK_ERROR - }; - - - public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION = new Class[0]; // Chapter 5.3 (as below) - public static final Class[] EXCS_STRING_RESOLUTION = new Class[0]; - // Chapter 5.4 (no errors but the ones that _always_ could happen! How stupid.) - - public static final Class[] EXCS_ARRAY_EXCEPTION = { - NULL_POINTER_EXCEPTION, ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION - }; - -} +package org.aspectj.apache.bcel; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Exception constants. + * + * @version $Id: ExceptionConstants.java,v 1.2.10.3 2008/05/08 19:26:47 aclement Exp $ + * @author E. Haase + */ +public interface ExceptionConstants { + /** The mother of all exceptions + */ + public static final Class THROWABLE = Throwable.class; + + /** Super class of any run-time exception + */ + public static final Class RUNTIME_EXCEPTION = RuntimeException.class; + + /** Super class of any linking exception (aka Linkage Error) + */ + public static final Class LINKING_EXCEPTION = LinkageError.class; + + /** Linking Exceptions + */ + public static final Class CLASS_CIRCULARITY_ERROR = ClassCircularityError.class; + public static final Class CLASS_FORMAT_ERROR = ClassFormatError.class; + public static final Class EXCEPTION_IN_INITIALIZER_ERROR = ExceptionInInitializerError.class; + public static final Class INCOMPATIBLE_CLASS_CHANGE_ERROR = IncompatibleClassChangeError.class; + public static final Class ABSTRACT_METHOD_ERROR = AbstractMethodError.class; + public static final Class ILLEGAL_ACCESS_ERROR = IllegalAccessError.class; + public static final Class INSTANTIATION_ERROR = InstantiationError.class; + public static final Class NO_SUCH_FIELD_ERROR = NoSuchFieldError.class; + public static final Class NO_SUCH_METHOD_ERROR = NoSuchMethodError.class; + public static final Class NO_CLASS_DEF_FOUND_ERROR = NoClassDefFoundError.class; + public static final Class UNSATISFIED_LINK_ERROR = UnsatisfiedLinkError.class; + public static final Class VERIFY_ERROR = VerifyError.class; + + /* UnsupportedClassVersionError is new in JDK 1.2 */ + //public static final Class UnsupportedClassVersionError = UnsupportedClassVersionError.class; + + /** Run-Time Exceptions + */ + public static final Class NULL_POINTER_EXCEPTION = NullPointerException.class; + public static final Class ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION = ArrayIndexOutOfBoundsException.class; + public static final Class ARITHMETIC_EXCEPTION = ArithmeticException.class; + public static final Class NEGATIVE_ARRAY_SIZE_EXCEPTION = NegativeArraySizeException.class; + public static final Class CLASS_CAST_EXCEPTION = ClassCastException.class; + public static final Class ILLEGAL_MONITOR_STATE = IllegalMonitorStateException.class; + + /** Pre-defined exception arrays according to chapters 5.1-5.4 of the Java Virtual + * Machine Specification + */ + public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION = { + NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, + EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR + }; // Chapter 5.1 + public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_MULTIANEWARRAY = { + NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, + EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR,NEGATIVE_ARRAY_SIZE_EXCEPTION,ILLEGAL_ACCESS_ERROR + }; + public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_ANEWARRAY = { + NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, + EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR,NEGATIVE_ARRAY_SIZE_EXCEPTION + }; // Chapter 5.1 + public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_CHECKCAST = { + NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, + EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR,CLASS_CAST_EXCEPTION + }; // Chapter 5.1 + public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_FOR_ALLOCATIONS= { + NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, + EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR, INSTANTIATION_ERROR,ILLEGAL_ACCESS_ERROR + }; + + public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION = { + NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR + }; // Chapter 5.2 + + public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION_GETFIELD_PUTFIELD = { + NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR,INCOMPATIBLE_CLASS_CHANGE_ERROR,NULL_POINTER_EXCEPTION + }; + + public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION_GETSTATIC_PUTSTATIC = { + NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR,INCOMPATIBLE_CLASS_CHANGE_ERROR + }; + + public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKEINTERFACE = { + INCOMPATIBLE_CLASS_CHANGE_ERROR,ILLEGAL_ACCESS_ERROR,ABSTRACT_METHOD_ERROR,UNSATISFIED_LINK_ERROR + }; + public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESPECIAL_INVOKEVIRTUAL = { + INCOMPATIBLE_CLASS_CHANGE_ERROR,NULL_POINTER_EXCEPTION,ABSTRACT_METHOD_ERROR,UNSATISFIED_LINK_ERROR + }; + + public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESTATIC = { + INCOMPATIBLE_CLASS_CHANGE_ERROR,UNSATISFIED_LINK_ERROR + }; + + + public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION = new Class[0]; // Chapter 5.3 (as below) + public static final Class[] EXCS_STRING_RESOLUTION = new Class[0]; + // Chapter 5.4 (no errors but the ones that _always_ could happen! How stupid.) + + public static final Class[] EXCS_ARRAY_EXCEPTION = { + NULL_POINTER_EXCEPTION, ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION + }; + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/Repository.java b/bcel-builder/src/org/aspectj/apache/bcel/Repository.java index a306f54f2..16dac8ade 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/Repository.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/Repository.java @@ -1,246 +1,246 @@ -package org.aspectj.apache.bcel; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.util.*; -import java.io.*; - -/** - * The repository maintains informations about class interdependencies, e.g., - * whether a class is a sub-class of another. Delegates actual class loading - * to SyntheticRepository with current class path by default. - * - * @see org.aspectj.apache.bcel.util.Repository - * @see org.aspectj.apache.bcel.util.SyntheticRepository - * - * @version $Id: Repository.java,v 1.3.10.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - */ -public abstract class Repository { - private static org.aspectj.apache.bcel.util.Repository _repository = null; - - /** @return currently used repository instance - */ - public static org.aspectj.apache.bcel.util.Repository getRepository() { - if (_repository == null) _repository = SyntheticRepository.getInstance(); - return _repository; - } - - /** Set repository instance to be used for class loading - */ - public static void setRepository(org.aspectj.apache.bcel.util.Repository rep) { - _repository = rep; - } - - /** Lookup class somewhere found on your CLASSPATH, or whereever the - * repository instance looks for it. - * - * @return class object for given fully qualified class name, or null - * if the class could not be found or parsed correctly - */ - public static JavaClass lookupClass(String class_name) { - try { - JavaClass clazz = getRepository().findClass(class_name); - - if(clazz != null) return clazz; - - return getRepository().loadClass(class_name); - } catch(ClassNotFoundException ex) { return null; } - } - - /** - * Try to find class source via getResourceAsStream(). - * @see Class - * @return JavaClass object for given runtime class - */ - public static JavaClass lookupClass(Class clazz) { - try { - return getRepository().loadClass(clazz); - } catch(ClassNotFoundException ex) { return null; } - } - - /** @return class file object for given Java class. - */ - public static ClassPath.ClassFile lookupClassFile(String class_name) { - try { - return ClassPath.getSystemClassPath().getClassFile(class_name); - } catch(IOException e) { return null; } - } - - /** Clear the repository. - */ - public static void clearCache() { - getRepository().clear(); - } - - /** - * Add clazz to repository if there isn't an equally named class already in there. - * - * @return old entry in repository - */ - public static JavaClass addClass(JavaClass clazz) { - JavaClass old = getRepository().findClass(clazz.getClassName()); - getRepository().storeClass(clazz); - return old; - } - - /** - * Remove class with given (fully qualified) name from repository. - */ - public static void removeClass(String clazz) { - getRepository().removeClass(getRepository().findClass(clazz)); - } - - /** - * Remove given class from repository. - */ - public static void removeClass(JavaClass clazz) { - getRepository().removeClass(clazz); - } - - /** - * @return list of super classes of clazz in ascending order, i.e., - * Object is always the last element - */ - public static JavaClass[] getSuperClasses(JavaClass clazz) { - return clazz.getSuperClasses(); - } - - /** - * @return list of super classes of clazz in ascending order, i.e., - * Object is always the last element. return "null", if class - * cannot be found. - */ - public static JavaClass[] getSuperClasses(String class_name) { - JavaClass jc = lookupClass(class_name); - return (jc == null? null : getSuperClasses(jc)); - } - - /** - * @return all interfaces implemented by class and its super - * classes and the interfaces that those interfaces extend, and so on. - * (Some people call this a transitive hull). - */ - public static JavaClass[] getInterfaces(JavaClass clazz) { - return clazz.getAllInterfaces(); - } - - /** - * @return all interfaces implemented by class and its super - * classes and the interfaces that extend those interfaces, and so on - */ - public static JavaClass[] getInterfaces(String class_name) { - return getInterfaces(lookupClass(class_name)); - } - - /** - * Equivalent to runtime "instanceof" operator. - * @return true, if clazz is an instance of super_class - */ - public static boolean instanceOf(JavaClass clazz, JavaClass super_class) { - return clazz.instanceOf(super_class); - } - - /** - * @return true, if clazz is an instance of super_class - */ - public static boolean instanceOf(String clazz, String super_class) { - return instanceOf(lookupClass(clazz), lookupClass(super_class)); - } - - /** - * @return true, if clazz is an instance of super_class - */ - public static boolean instanceOf(JavaClass clazz, String super_class) { - return instanceOf(clazz, lookupClass(super_class)); - } - - /** - * @return true, if clazz is an instance of super_class - */ - public static boolean instanceOf(String clazz, JavaClass super_class) { - return instanceOf(lookupClass(clazz), super_class); - } - - /** - * @return true, if clazz is an implementation of interface inter - */ - public static boolean implementationOf(JavaClass clazz, JavaClass inter) { - return clazz.implementationOf(inter); - } - - /** - * @return true, if clazz is an implementation of interface inter - */ - public static boolean implementationOf(String clazz, String inter) { - return implementationOf(lookupClass(clazz), lookupClass(inter)); - } - - /** - * @return true, if clazz is an implementation of interface inter - */ - public static boolean implementationOf(JavaClass clazz, String inter) { - return implementationOf(clazz, lookupClass(inter)); - } - - /** - * @return true, if clazz is an implementation of interface inter - */ - public static boolean implementationOf(String clazz, JavaClass inter) { - return implementationOf(lookupClass(clazz), inter); - } -} - +package org.aspectj.apache.bcel; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.util.*; +import java.io.*; + +/** + * The repository maintains informations about class interdependencies, e.g., + * whether a class is a sub-class of another. Delegates actual class loading + * to SyntheticRepository with current class path by default. + * + * @see org.aspectj.apache.bcel.util.Repository + * @see org.aspectj.apache.bcel.util.SyntheticRepository + * + * @version $Id: Repository.java,v 1.3.10.3 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + */ +public abstract class Repository { + private static org.aspectj.apache.bcel.util.Repository _repository = null; + + /** @return currently used repository instance + */ + public static org.aspectj.apache.bcel.util.Repository getRepository() { + if (_repository == null) _repository = SyntheticRepository.getInstance(); + return _repository; + } + + /** Set repository instance to be used for class loading + */ + public static void setRepository(org.aspectj.apache.bcel.util.Repository rep) { + _repository = rep; + } + + /** Lookup class somewhere found on your CLASSPATH, or whereever the + * repository instance looks for it. + * + * @return class object for given fully qualified class name, or null + * if the class could not be found or parsed correctly + */ + public static JavaClass lookupClass(String class_name) { + try { + JavaClass clazz = getRepository().findClass(class_name); + + if(clazz != null) return clazz; + + return getRepository().loadClass(class_name); + } catch(ClassNotFoundException ex) { return null; } + } + + /** + * Try to find class source via getResourceAsStream(). + * @see Class + * @return JavaClass object for given runtime class + */ + public static JavaClass lookupClass(Class clazz) { + try { + return getRepository().loadClass(clazz); + } catch(ClassNotFoundException ex) { return null; } + } + + /** @return class file object for given Java class. + */ + public static ClassPath.ClassFile lookupClassFile(String class_name) { + try { + return ClassPath.getSystemClassPath().getClassFile(class_name); + } catch(IOException e) { return null; } + } + + /** Clear the repository. + */ + public static void clearCache() { + getRepository().clear(); + } + + /** + * Add clazz to repository if there isn't an equally named class already in there. + * + * @return old entry in repository + */ + public static JavaClass addClass(JavaClass clazz) { + JavaClass old = getRepository().findClass(clazz.getClassName()); + getRepository().storeClass(clazz); + return old; + } + + /** + * Remove class with given (fully qualified) name from repository. + */ + public static void removeClass(String clazz) { + getRepository().removeClass(getRepository().findClass(clazz)); + } + + /** + * Remove given class from repository. + */ + public static void removeClass(JavaClass clazz) { + getRepository().removeClass(clazz); + } + + /** + * @return list of super classes of clazz in ascending order, i.e., + * Object is always the last element + */ + public static JavaClass[] getSuperClasses(JavaClass clazz) { + return clazz.getSuperClasses(); + } + + /** + * @return list of super classes of clazz in ascending order, i.e., + * Object is always the last element. return "null", if class + * cannot be found. + */ + public static JavaClass[] getSuperClasses(String class_name) { + JavaClass jc = lookupClass(class_name); + return (jc == null? null : getSuperClasses(jc)); + } + + /** + * @return all interfaces implemented by class and its super + * classes and the interfaces that those interfaces extend, and so on. + * (Some people call this a transitive hull). + */ + public static JavaClass[] getInterfaces(JavaClass clazz) { + return clazz.getAllInterfaces(); + } + + /** + * @return all interfaces implemented by class and its super + * classes and the interfaces that extend those interfaces, and so on + */ + public static JavaClass[] getInterfaces(String class_name) { + return getInterfaces(lookupClass(class_name)); + } + + /** + * Equivalent to runtime "instanceof" operator. + * @return true, if clazz is an instance of super_class + */ + public static boolean instanceOf(JavaClass clazz, JavaClass super_class) { + return clazz.instanceOf(super_class); + } + + /** + * @return true, if clazz is an instance of super_class + */ + public static boolean instanceOf(String clazz, String super_class) { + return instanceOf(lookupClass(clazz), lookupClass(super_class)); + } + + /** + * @return true, if clazz is an instance of super_class + */ + public static boolean instanceOf(JavaClass clazz, String super_class) { + return instanceOf(clazz, lookupClass(super_class)); + } + + /** + * @return true, if clazz is an instance of super_class + */ + public static boolean instanceOf(String clazz, JavaClass super_class) { + return instanceOf(lookupClass(clazz), super_class); + } + + /** + * @return true, if clazz is an implementation of interface inter + */ + public static boolean implementationOf(JavaClass clazz, JavaClass inter) { + return clazz.implementationOf(inter); + } + + /** + * @return true, if clazz is an implementation of interface inter + */ + public static boolean implementationOf(String clazz, String inter) { + return implementationOf(lookupClass(clazz), lookupClass(inter)); + } + + /** + * @return true, if clazz is an implementation of interface inter + */ + public static boolean implementationOf(JavaClass clazz, String inter) { + return implementationOf(clazz, lookupClass(inter)); + } + + /** + * @return true, if clazz is an implementation of interface inter + */ + public static boolean implementationOf(String clazz, JavaClass inter) { + return implementationOf(lookupClass(clazz), inter); + } +} + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/AccessFlags.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/AccessFlags.java deleted file mode 100644 index f14c4aba0..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/AccessFlags.java +++ /dev/null @@ -1,165 +0,0 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; - -/** - * Super class for all objects that have modifiers like private, final, ... - * I.e. classes, fields, and methods. - * - * @version $Id: AccessFlags.java,v 1.2.10.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - */ -public abstract class AccessFlags implements java.io.Serializable { - protected int accessflags; - - public AccessFlags() {} - - public AccessFlags(int a) { - accessflags = a; - } - - public final int getAccessFlags() { return accessflags; } - public final int getModifiers() { return accessflags; } - - public final void setAccessFlags(int access_flags) { - this.accessflags = access_flags; - } - - public final void setModifiers(int access_flags) { - setAccessFlags(access_flags); - } - - private final void setFlag(int flag, boolean set) { - if((accessflags & flag) != 0) { // Flag is set already - if(!set) // Delete flag ? - accessflags ^= flag; - } else { // Flag not set - if(set) // Set flag ? - accessflags |= flag; - } - } - - public final void isPublic(boolean flag) { setFlag(Constants.ACC_PUBLIC, flag); } - public final boolean isPublic() { - return (accessflags & Constants.ACC_PUBLIC) != 0; - } - - public final void isPrivate(boolean flag) { setFlag(Constants.ACC_PRIVATE, flag); } - public final boolean isPrivate() { - return (accessflags & Constants.ACC_PRIVATE) != 0; - } - - public final void isProtected(boolean flag) { setFlag(Constants.ACC_PROTECTED, flag); } - public final boolean isProtected() { - return (accessflags & Constants.ACC_PROTECTED) != 0; - } - - public final void isStatic(boolean flag) { setFlag(Constants.ACC_STATIC, flag); } - public final boolean isStatic() { - return (accessflags & Constants.ACC_STATIC) != 0; - } - - public final void isFinal(boolean flag) { setFlag(Constants.ACC_FINAL, flag); } - public final boolean isFinal() { - return (accessflags & Constants.ACC_FINAL) != 0; - } - - public final void isSynchronized(boolean flag) { setFlag(Constants.ACC_SYNCHRONIZED, flag); } - public final boolean isSynchronized() { - return (accessflags & Constants.ACC_SYNCHRONIZED) != 0; - } - - public final void isVolatile(boolean flag) { setFlag(Constants.ACC_VOLATILE, flag); } - public final boolean isVolatile() { - return (accessflags & Constants.ACC_VOLATILE) != 0; - } - - public final void isTransient(boolean flag) { setFlag(Constants.ACC_TRANSIENT, flag); } - public final boolean isTransient() { - return (accessflags & Constants.ACC_TRANSIENT) != 0; - } - - public final void isNative(boolean flag) { setFlag(Constants.ACC_NATIVE, flag); } - public final boolean isNative() { - return (accessflags & Constants.ACC_NATIVE) != 0; - } - - public final void isInterface(boolean flag) { setFlag(Constants.ACC_INTERFACE, flag); } - public final boolean isInterface() { - return (accessflags & Constants.ACC_INTERFACE) != 0; - } - - public final void isAbstract(boolean flag) { setFlag(Constants.ACC_ABSTRACT, flag); } - public final boolean isAbstract() { - return (accessflags & Constants.ACC_ABSTRACT) != 0; - } - - public final void isStrictfp(boolean flag) { setFlag(Constants.ACC_STRICT, flag); } - public final boolean isStrictfp() { - return (accessflags & Constants.ACC_STRICT) != 0; - } - - public final void isVarargs(boolean flag) { setFlag(Constants.ACC_VARARGS, flag); } - public final boolean isVarargs() { - return (accessflags & Constants.ACC_VARARGS) != 0; - } - - public final void isBridge(boolean flag) { setFlag(Constants.ACC_BRIDGE, flag); } - public final boolean isBridge() { - return (accessflags & Constants.ACC_BRIDGE) != 0; - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/AnnotationDefault.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/AnnotationDefault.java index 85cb253f5..53cf1c33d 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/AnnotationDefault.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/AnnotationDefault.java @@ -1,55 +1,55 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * ******************************************************************/ -package org.aspectj.apache.bcel.classfile; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen; - -/** - * This attribute is attached to a method and indicates the default - * value for an annotation element. - */ -public class AnnotationDefault extends Attribute { - - private ElementValueGen value; - - public AnnotationDefault(int nameIndex, int len, DataInputStream dis, ConstantPool cpool) throws IOException { - this(nameIndex, len, ElementValueGen.readElementValue(dis,cpool), cpool); - } - - private AnnotationDefault(int nameIndex, int len, ElementValueGen value, ConstantPool cpool) { - super(Constants.ATTR_ANNOTATION_DEFAULT, nameIndex, len, cpool); - this.value = value; - } - - public Attribute copy(ConstantPool constant_pool) { - throw new RuntimeException("Not implemented yet!"); - // is this next line sufficient? - // return (EnclosingMethod)clone(); - } - - public final ElementValueGen getElementValue() { return value; } - - public final void dump(DataOutputStream dos) throws IOException { - super.dump(dos); - value.dump(dos); - } - - public void accept(Visitor v) { - v.visitAnnotationDefault(this); - } -} +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * ******************************************************************/ +package org.aspectj.apache.bcel.classfile; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen; + +/** + * This attribute is attached to a method and indicates the default + * value for an annotation element. + */ +public class AnnotationDefault extends Attribute { + + private ElementValueGen value; + + public AnnotationDefault(int nameIndex, int len, DataInputStream dis, ConstantPool cpool) throws IOException { + this(nameIndex, len, ElementValueGen.readElementValue(dis,cpool), cpool); + } + + private AnnotationDefault(int nameIndex, int len, ElementValueGen value, ConstantPool cpool) { + super(Constants.ATTR_ANNOTATION_DEFAULT, nameIndex, len, cpool); + this.value = value; + } + + public Attribute copy(ConstantPool constant_pool) { + throw new RuntimeException("Not implemented yet!"); + // is this next line sufficient? + // return (EnclosingMethod)clone(); + } + + public final ElementValueGen getElementValue() { return value; } + + public final void dump(DataOutputStream dos) throws IOException { + super.dump(dos); + value.dump(dos); + } + + public void accept(ClassVisitor v) { + v.visitAnnotationDefault(this); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Attribute.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Attribute.java index 3379778de..a3b115543 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Attribute.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Attribute.java @@ -1,195 +1,195 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; - -import java.io.*; - -/** - * Abstract super class for Attribute objects. Currently the - * ConstantValue, SourceFile, Code, - * Exceptiontable, LineNumberTable, - * LocalVariableTable, InnerClasses and - * Synthetic attributes are supported. The - * Unknown attribute stands for non-standard-attributes. - * - * @version $Id: Attribute.java,v 1.2.10.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see ConstantValue - * @see SourceFile - * @see Code - * @see Unknown - * @see ExceptionTable - * @see LineNumberTable - * @see LocalVariableTable - * @see InnerClasses - * @see Synthetic - * @see Deprecated - * @see Signature -*/ -public abstract class Attribute implements Cloneable, Node, Serializable { - public static Attribute[] NoAttributes = new Attribute[0]; - - - protected byte tag; // Tag to distinguish subclasses - protected int nameIndex; // Points to attribute name in constant pool - protected int length; // Content length of attribute field - protected ConstantPool constantPool; - - - protected Attribute(byte tag, int nameIndex, int length, ConstantPool constantPool) { - this.tag = tag; - this.nameIndex = nameIndex; - this.length = length; - this.constantPool = constantPool; - } - - - /** Dump attribute to file stream in binary format */ - public void dump(DataOutputStream file) throws IOException { - file.writeShort(nameIndex); - file.writeInt(length); - } - - - public static final Attribute readAttribute(DataInputStream file, ConstantPool cpool) throws IOException { - byte tag = Constants.ATTR_UNKNOWN; // Unknown attribute - int idx = file.readUnsignedShort(); - String name = cpool.getConstantUtf8(idx).getBytes(); - int len = file.readInt(); - - // Compare strings to find known attribute - for (byte i=0; i < Constants.KNOWN_ATTRIBUTES; i++) { - if (name.equals(Constants.ATTRIBUTE_NAMES[i])) { tag = i; break; } - } - switch(tag) { - case Constants.ATTR_UNKNOWN: return new Unknown(idx, len, file, cpool); - case Constants.ATTR_CONSTANT_VALUE: return new ConstantValue(idx, len, file, cpool); - case Constants.ATTR_SOURCE_FILE: return new SourceFile(idx, len, file, cpool); - case Constants.ATTR_CODE: return new Code(idx, len, file, cpool); - case Constants.ATTR_EXCEPTIONS: return new ExceptionTable(idx, len, file, cpool); - case Constants.ATTR_LINE_NUMBER_TABLE: return new LineNumberTable(idx, len, file, cpool); - case Constants.ATTR_LOCAL_VARIABLE_TABLE: return new LocalVariableTable(idx, len, file, cpool); - case Constants.ATTR_INNER_CLASSES: return new InnerClasses(idx, len, file, cpool); - case Constants.ATTR_SYNTHETIC: return new Synthetic(idx, len, file, cpool); - case Constants.ATTR_DEPRECATED: return new Deprecated(idx, len, file, cpool); - case Constants.ATTR_PMG: return new PMGClass(idx, len, file, cpool); - case Constants.ATTR_SIGNATURE: return new Signature(idx, len, file, cpool); - case Constants.ATTR_STACK_MAP: return new StackMap(idx, len, file, cpool); - case Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS: - return new RuntimeVisibleAnnotations(idx,len,file,cpool); - case Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS: - return new RuntimeInvisibleAnnotations(idx,len,file,cpool); - case Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS: - return new RuntimeVisibleParameterAnnotations(idx,len,file,cpool); - case Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS: - return new RuntimeInvisibleParameterAnnotations(idx,len,file,cpool); - case Constants.ATTR_ANNOTATION_DEFAULT: - return new AnnotationDefault(idx,len,file,cpool); - case Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE: - return new LocalVariableTypeTable(idx,len,file,cpool); - case Constants.ATTR_ENCLOSING_METHOD: - return new EnclosingMethod(idx,len,file,cpool); - default: throw new IllegalStateException(); - } - } - - public String getName() { - return constantPool.getConstantUtf8(nameIndex).getBytes(); - } - - public final int getLength() { return length; } - - public final int getNameIndex() { return nameIndex; } - - public final byte getTag() { return tag; } - - public final ConstantPool getConstantPool() { return constantPool; } - - /** - * Use copy() if you want to have a deep copy(), ie. with all references - * copied correctly. - * - * @return shallow copy of this attribute - */ - public Object clone() { - Object o = null; - - try { - o = super.clone(); - } catch(CloneNotSupportedException e) { - e.printStackTrace(); // Never occurs - } - - return o; - } - - /** - * @return deep copy of this attribute - */ - public abstract Attribute copy(ConstantPool constant_pool); - - public String toString() { - return Constants.ATTRIBUTE_NAMES[tag]; - } - - public abstract void accept(Visitor v); - -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; + +import java.io.*; + +/** + * Abstract super class for Attribute objects. Currently the + * ConstantValue, SourceFile, Code, + * Exceptiontable, LineNumberTable, + * LocalVariableTable, InnerClasses and + * Synthetic attributes are supported. The + * Unknown attribute stands for non-standard-attributes. + * + * @version $Id: Attribute.java,v 1.2.10.3 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + * @see ConstantValue + * @see SourceFile + * @see Code + * @see Unknown + * @see ExceptionTable + * @see LineNumberTable + * @see LocalVariableTable + * @see InnerClasses + * @see Synthetic + * @see Deprecated + * @see Signature +*/ +public abstract class Attribute implements Cloneable, Node, Serializable { + public static Attribute[] NoAttributes = new Attribute[0]; + + + protected byte tag; // Tag to distinguish subclasses + protected int nameIndex; // Points to attribute name in constant pool + protected int length; // Content length of attribute field + protected ConstantPool constantPool; + + + protected Attribute(byte tag, int nameIndex, int length, ConstantPool constantPool) { + this.tag = tag; + this.nameIndex = nameIndex; + this.length = length; + this.constantPool = constantPool; + } + + + /** Dump attribute to file stream in binary format */ + public void dump(DataOutputStream file) throws IOException { + file.writeShort(nameIndex); + file.writeInt(length); + } + + + public static final Attribute readAttribute(DataInputStream file, ConstantPool cpool) throws IOException { + byte tag = Constants.ATTR_UNKNOWN; // Unknown attribute + int idx = file.readUnsignedShort(); + String name = cpool.getConstantUtf8(idx).getBytes(); + int len = file.readInt(); + + // Compare strings to find known attribute + for (byte i=0; i < Constants.KNOWN_ATTRIBUTES; i++) { + if (name.equals(Constants.ATTRIBUTE_NAMES[i])) { tag = i; break; } + } + switch(tag) { + case Constants.ATTR_UNKNOWN: return new Unknown(idx, len, file, cpool); + case Constants.ATTR_CONSTANT_VALUE: return new ConstantValue(idx, len, file, cpool); + case Constants.ATTR_SOURCE_FILE: return new SourceFile(idx, len, file, cpool); + case Constants.ATTR_CODE: return new Code(idx, len, file, cpool); + case Constants.ATTR_EXCEPTIONS: return new ExceptionTable(idx, len, file, cpool); + case Constants.ATTR_LINE_NUMBER_TABLE: return new LineNumberTable(idx, len, file, cpool); + case Constants.ATTR_LOCAL_VARIABLE_TABLE: return new LocalVariableTable(idx, len, file, cpool); + case Constants.ATTR_INNER_CLASSES: return new InnerClasses(idx, len, file, cpool); + case Constants.ATTR_SYNTHETIC: return new Synthetic(idx, len, file, cpool); + case Constants.ATTR_DEPRECATED: return new Deprecated(idx, len, file, cpool); + case Constants.ATTR_PMG: return new PMGClass(idx, len, file, cpool); + case Constants.ATTR_SIGNATURE: return new Signature(idx, len, file, cpool); + case Constants.ATTR_STACK_MAP: return new StackMap(idx, len, file, cpool); + case Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS: + return new RuntimeVisibleAnnotations(idx,len,file,cpool); + case Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS: + return new RuntimeInvisibleAnnotations(idx,len,file,cpool); + case Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS: + return new RuntimeVisibleParameterAnnotations(idx,len,file,cpool); + case Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS: + return new RuntimeInvisibleParameterAnnotations(idx,len,file,cpool); + case Constants.ATTR_ANNOTATION_DEFAULT: + return new AnnotationDefault(idx,len,file,cpool); + case Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE: + return new LocalVariableTypeTable(idx,len,file,cpool); + case Constants.ATTR_ENCLOSING_METHOD: + return new EnclosingMethod(idx,len,file,cpool); + default: throw new IllegalStateException(); + } + } + + public String getName() { + return constantPool.getConstantUtf8(nameIndex).getBytes(); + } + + public final int getLength() { return length; } + + public final int getNameIndex() { return nameIndex; } + + public final byte getTag() { return tag; } + + public final ConstantPool getConstantPool() { return constantPool; } + + /** + * Use copy() if you want to have a deep copy(), ie. with all references + * copied correctly. + * + * @return shallow copy of this attribute + */ + public Object clone() { + Object o = null; + + try { + o = super.clone(); + } catch(CloneNotSupportedException e) { + e.printStackTrace(); // Never occurs + } + + return o; + } + + /** + * @return deep copy of this attribute + */ + public abstract Attribute copy(ConstantPool constant_pool); + + public String toString() { + return Constants.ATTRIBUTE_NAMES[tag]; + } + + public abstract void accept(ClassVisitor v); + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/AttributeReader.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/AttributeReader.java deleted file mode 100644 index 18c63eb05..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/AttributeReader.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Unknown (non-standard) attributes may be read via user-defined factory - * objects that can be registered with the Attribute.addAttributeReader - * method. These factory objects should implement this interface. - - * @see Attribute - * @version $Id: AttributeReader.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public interface AttributeReader { - /** - When this attribute reader is added via the static method - Attribute.addAttributeReader, an attribute name is associated with it. - As the class file parser parses attributes, it will call various - AttributeReaders based on the name of the attributes it is - constructing. - - @param name_index An index into the constant pool, indexing a - ConstantUtf8 that represents the name of the attribute. - - @param length The length of the data contained in the attribute. This - is written into the constant pool and should agree with what the - factory expects the length to be. - - @param file This is the data input stream that the factory needs to read - its data from. - - @param constant_pool This is the constant pool associated with the - Attribute that we are constructing. - - @return The user-defined AttributeReader should take this data and use - it to construct an attribute. In the case of errors, a null can be - returned which will cause the parsing of the class file to fail. - - @see Attribute#addAttributeReader( String, AttributeReader ) - */ - public Attribute createAttribute(int name_index, - int length, - java.io.DataInputStream file, - ConstantPool constant_pool); -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/AttributeUtils.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/AttributeUtils.java index a960bbe39..3c540e8c9 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/AttributeUtils.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/AttributeUtils.java @@ -1,93 +1,93 @@ -package org.aspectj.apache.bcel.classfile; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.Constants; - -public class AttributeUtils { - - public static Attribute[] readAttributes(DataInputStream dataInputstream, ConstantPool cpool) { - try { - int length = dataInputstream.readUnsignedShort(); - if (length==0) return Attribute.NoAttributes; - Attribute[] attrs = new Attribute[length]; - for (int i=0; i < length; i++) - attrs[i] = Attribute.readAttribute(dataInputstream, cpool); - return attrs; - } catch (IOException e) { - throw new ClassFormatException("IOException whilst reading set of attributes: "+e.toString()); - } - } - - /** Write (serialize) a set of attributes into a specified output stream */ - public static void writeAttributes(Attribute[] attributes,DataOutputStream file) throws IOException { - if (attributes==null) { - file.writeShort(0); - } else { - file.writeShort(attributes.length); - for(int i=0; i < attributes.length; i++) - attributes[i].dump(file); - } - } - - public static Attribute[] copy(Attribute[] attributes, ConstantPool constant_pool) { - if (attributes==null || attributes.length==0) return Attribute.NoAttributes; - Attribute[] attrs = new Attribute[attributes.length]; - for (int i = 0; i < attributes.length; i++) { - attrs[i] = attributes[i].copy(constant_pool); - } - return attrs; - } - - public static Signature getSignatureAttribute(Attribute[] attributes) { - for(int i=0; i < attributes.length; i++) { - if (attributes[i].tag==Constants.ATTR_SIGNATURE) return ((Signature)attributes[i]); - } - return null; - } - - public static Code getCodeAttribute(Attribute[] attributes) { - for(int i=0; i < attributes.length; i++) { - if (attributes[i].tag==Constants.ATTR_CODE) { return ((Code)attributes[i]);} - } - return null; - } - - public static ExceptionTable getExceptionTableAttribute(Attribute[] attributes) { - for(int i=0; i < attributes.length; i++) { - if (attributes[i].tag==Constants.ATTR_EXCEPTIONS) { return ((ExceptionTable)attributes[i]);} - } - return null; - } - - public static ConstantValue getConstantValueAttribute(Attribute[] attributes) { - for(int i=0; i < attributes.length; i++) { - if(attributes[i].getTag() == Constants.ATTR_CONSTANT_VALUE) return (ConstantValue)attributes[i]; - } - return null; - } - - public static void accept(Attribute[] attributes,Visitor visitor) { - for(int i=0; i < attributes.length; i++) - attributes[i].accept(visitor); - } - - public static boolean hasSyntheticAttribute(Attribute[] attributes) { - for (int i = 0; i < attributes.length; i++) { - if (attributes[i].tag==Constants.ATTR_SYNTHETIC) { - return true; - } - } - return false; - } - - public static SourceFile getSourceFileAttribute(Attribute[] attributes) { - for(int i=0; i < attributes.length; i++) { - if (attributes[i].tag==Constants.ATTR_SOURCE_FILE) { return ((SourceFile)attributes[i]);} - } - return null; - } - -} +package org.aspectj.apache.bcel.classfile; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import org.aspectj.apache.bcel.Constants; + +public class AttributeUtils { + + public static Attribute[] readAttributes(DataInputStream dataInputstream, ConstantPool cpool) { + try { + int length = dataInputstream.readUnsignedShort(); + if (length==0) return Attribute.NoAttributes; + Attribute[] attrs = new Attribute[length]; + for (int i=0; i < length; i++) + attrs[i] = Attribute.readAttribute(dataInputstream, cpool); + return attrs; + } catch (IOException e) { + throw new ClassFormatException("IOException whilst reading set of attributes: "+e.toString()); + } + } + + /** Write (serialize) a set of attributes into a specified output stream */ + public static void writeAttributes(Attribute[] attributes,DataOutputStream file) throws IOException { + if (attributes==null) { + file.writeShort(0); + } else { + file.writeShort(attributes.length); + for(int i=0; i < attributes.length; i++) + attributes[i].dump(file); + } + } + + public static Attribute[] copy(Attribute[] attributes, ConstantPool constant_pool) { + if (attributes==null || attributes.length==0) return Attribute.NoAttributes; + Attribute[] attrs = new Attribute[attributes.length]; + for (int i = 0; i < attributes.length; i++) { + attrs[i] = attributes[i].copy(constant_pool); + } + return attrs; + } + + public static Signature getSignatureAttribute(Attribute[] attributes) { + for(int i=0; i < attributes.length; i++) { + if (attributes[i].tag==Constants.ATTR_SIGNATURE) return ((Signature)attributes[i]); + } + return null; + } + + public static Code getCodeAttribute(Attribute[] attributes) { + for(int i=0; i < attributes.length; i++) { + if (attributes[i].tag==Constants.ATTR_CODE) { return ((Code)attributes[i]);} + } + return null; + } + + public static ExceptionTable getExceptionTableAttribute(Attribute[] attributes) { + for(int i=0; i < attributes.length; i++) { + if (attributes[i].tag==Constants.ATTR_EXCEPTIONS) { return ((ExceptionTable)attributes[i]);} + } + return null; + } + + public static ConstantValue getConstantValueAttribute(Attribute[] attributes) { + for(int i=0; i < attributes.length; i++) { + if(attributes[i].getTag() == Constants.ATTR_CONSTANT_VALUE) return (ConstantValue)attributes[i]; + } + return null; + } + + public static void accept(Attribute[] attributes,ClassVisitor visitor) { + for(int i=0; i < attributes.length; i++) + attributes[i].accept(visitor); + } + + public static boolean hasSyntheticAttribute(Attribute[] attributes) { + for (int i = 0; i < attributes.length; i++) { + if (attributes[i].tag==Constants.ATTR_SYNTHETIC) { + return true; + } + } + return false; + } + + public static SourceFile getSourceFileAttribute(Attribute[] attributes) { + for(int i=0; i < attributes.length; i++) { + if (attributes[i].tag==Constants.ATTR_SOURCE_FILE) { return ((SourceFile)attributes[i]);} + } + return null; + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassFormatException.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassFormatException.java index 3b0e0a188..e1cc9658e 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassFormatException.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassFormatException.java @@ -1,69 +1,69 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Thrown when the BCEL attempts to read a class file and determines - * that the file is malformed or otherwise cannot be interpreted as a - * class file. - * - * @version $Id: ClassFormatException.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - */ -public class ClassFormatException extends RuntimeException { - public ClassFormatException() { super(); } - public ClassFormatException(String s) { super(s); } -} - +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Thrown when the BCEL attempts to read a class file and determines + * that the file is malformed or otherwise cannot be interpreted as a + * class file. + * + * @version $Id: ClassFormatException.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + */ +public class ClassFormatException extends RuntimeException { + public ClassFormatException() { super(); } + public ClassFormatException(String s) { super(s); } +} + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassParser.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassParser.java index be2812e0f..3b4436316 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassParser.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassParser.java @@ -1,257 +1,245 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; -import java.util.zip.*; - -/** - * Wrapper class that parses a given Java .class file. The method parse returns a - * JavaClass object on success. When an I/O error or an - * inconsistency occurs an appropiate exception is propagated back to - * the caller. - * - * The structure and the names comply, except for a few conveniences, - * exactly with the - * JVM specification 1.0. See this paper for - * further details about the structure of a bytecode file. - * - * @version $Id: ClassParser.java,v 1.4.8.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - */ -public final class ClassParser { - private DataInputStream file; - private ZipFile zip; - private String filename; - private int classnameIndex; - private int superclassnameIndex; - private int major, minor; - private int accessflags; - private int[] interfaceIndices; - private ConstantPool cpool; - private Field[] fields; - private Method[] methods; - private Attribute[] attributes; - private boolean isZip; - - private static final int BUFSIZE = 16384; - - /** Parse class from the given stream */ - public ClassParser(InputStream file, String filename) { - this.filename = filename; - String clazz = file.getClass().getName(); // Not a very clean solution ... - isZip = clazz.startsWith("java.util.zip.") || clazz.startsWith("java.util.jar."); - - if (file instanceof DataInputStream) this.file = (DataInputStream)file; - else this.file = new DataInputStream(new BufferedInputStream(file,BUFSIZE)); - } - - /** Parse class from given .class file */ - public ClassParser(String file_name) throws IOException { - isZip = false; - this.filename = file_name; - file = new DataInputStream(new BufferedInputStream(new FileInputStream(file_name),BUFSIZE)); - } - - /** Parse class from given .class file in a ZIP-archive */ - public ClassParser(String zip_file, String file_name) throws IOException { - isZip = true; - zip = new ZipFile(zip_file); - ZipEntry entry = zip.getEntry(file_name); - this.filename = file_name; - file = new DataInputStream(new BufferedInputStream(zip.getInputStream(entry),BUFSIZE)); - } - - /** - * Parse the given Java class file and return an object that represents - * the contained data, i.e., constants, methods, fields and commands. - * A ClassFormatException is raised, if the file is not a valid - * .class file. (This does not include verification of the byte code as it - * is performed by the java interpreter). - */ - public JavaClass parse() throws IOException, ClassFormatException { - /****************** Read headers ********************************/ - // Check magic tag of class file - readID(); - - // Get compiler version - readVersion(); - - /****************** Read constant pool and related **************/ - // Read constant pool entries - readConstantPool(); - - // Get class information - readClassInfo(); - - // Get interface information, i.e., implemented interfaces - readInterfaces(); - - /****************** Read class fields and methods ***************/ - // Read class fields, i.e., the variables of the class - readFields(); - - // Read class methods, i.e., the functions in the class - readMethods(); - - // Read class attributes - readAttributes(); - - // Read everything of interest, so close the file - file.close(); - if(zip != null) zip.close(); - - // Return the information we have gathered in a new object - JavaClass jc= new JavaClass(classnameIndex, superclassnameIndex, - filename, major, minor, accessflags, - cpool, interfaceIndices, fields, - methods, attributes, isZip? JavaClass.ZIP : JavaClass.FILE); - return jc; - } - - - /** Read information about the attributes of the class */ - private final void readAttributes() { - attributes = AttributeUtils.readAttributes(file,cpool); - } - - /** Read information about the class and its super class */ - private final void readClassInfo() throws IOException { - accessflags = file.readUnsignedShort(); - - /* Interfaces are implicitely abstract, the flag should be set - * according to the JVM specification */ - if((accessflags & Constants.ACC_INTERFACE) != 0) - accessflags |= Constants.ACC_ABSTRACT; - - // don't police it like this... leave higher level verification code to check it. -// if(((access_flags & Constants.ACC_ABSTRACT) != 0) && -// ((access_flags & Constants.ACC_FINAL) != 0 )) -// throw new ClassFormatException("Class can't be both final and abstract"); - - classnameIndex = file.readUnsignedShort(); - superclassnameIndex = file.readUnsignedShort(); - } - - /** Read constant pool entries */ - private final void readConstantPool() throws IOException { - try { - cpool = new ConstantPool(file); - } catch (ClassFormatException cfe) { - // add some context if we can - cfe.printStackTrace(); - if (filename!=null) { - String newmessage = "File: '"+filename+"': "+cfe.getMessage(); - throw new ClassFormatException(newmessage); // this loses the old stack trace but I dont think that matters! - } - throw cfe; - } - } - - /** Read information about the fields of the class */ - private final void readFields() throws IOException, ClassFormatException { - int fieldCount = file.readUnsignedShort(); - if (fieldCount == 0) { - fields = Field.NoFields; - } else { - fields = new Field[fieldCount]; - for(int i=0; i < fieldCount; i++) - fields[i] = new Field(file, cpool); - } - } - - /** Check whether the header of the file is ok. Of course, this has - * to be the first action on successive file reads */ - private final void readID() throws IOException { - int magic = 0xCAFEBABE; - if (file.readInt() != magic) - throw new ClassFormatException(filename + " is not a Java .class file"); - } - - private static final int[] NO_INTERFACES = new int[0]; - - /** Read information about the interfaces implemented by this class */ - private final void readInterfaces() throws IOException { - int interfacesCount = file.readUnsignedShort(); - if (interfacesCount==0) { - interfaceIndices = NO_INTERFACES; - } else { - interfaceIndices = new int[interfacesCount]; - for(int i=0; i < interfacesCount; i++) - interfaceIndices[i] = file.readUnsignedShort(); - } - } - - /** Read information about the methods of the class */ - private final void readMethods() throws IOException { - int methodsCount = file.readUnsignedShort(); - if (methodsCount==0) { - methods = Method.NoMethods; - } else { - methods = new Method[methodsCount]; - for(int i=0; i < methodsCount; i++) - methods[i] = new Method(file, cpool); - } - } - - /** Read major and minor version of compiler which created the file */ - private final void readVersion() throws IOException { - minor = file.readUnsignedShort(); - major = file.readUnsignedShort(); - } - -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; +import java.util.zip.*; + +/** + * Wrapper class that parses a given Java .class file. The method parse returns a + * JavaClass object on success. When an I/O error or an + * inconsistency occurs an appropiate exception is propagated back to + * the caller. + * + * The structure and the names comply, except for a few conveniences, + * exactly with the + * JVM specification 1.0. See this paper for + * further details about the structure of a bytecode file. + * + * @version $Id: ClassParser.java,v 1.4.8.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + */ +public final class ClassParser { + private DataInputStream file; + private String filename; + private int classnameIndex; + private int superclassnameIndex; + private int major, minor; + private int accessflags; + private int[] interfaceIndices; + private ConstantPool cpool; + private Field[] fields; + private Method[] methods; + private Attribute[] attributes; + + private static final int BUFSIZE = 8192; + + /** Parse class from the given stream */ + public ClassParser(InputStream file, String filename) { + this.filename = filename; + if (file instanceof DataInputStream) this.file = (DataInputStream)file; + else this.file = new DataInputStream(new BufferedInputStream(file,BUFSIZE)); + } + + public ClassParser(ByteArrayInputStream baos, String filename) { + this.filename = filename; + this.file = new DataInputStream(baos); + } + + /** Parse class from given .class file */ + public ClassParser(String file_name) throws IOException { + this.filename = file_name; + file = new DataInputStream(new BufferedInputStream(new FileInputStream(file_name),BUFSIZE)); + } + + /** + * Parse the given Java class file and return an object that represents + * the contained data, i.e., constants, methods, fields and commands. + * A ClassFormatException is raised, if the file is not a valid + * .class file. (This does not include verification of the byte code as it + * is performed by the java interpreter). + */ + public JavaClass parse() throws IOException, ClassFormatException { + /****************** Read headers ********************************/ + // Check magic tag of class file + readID(); + + // Get compiler version + readVersion(); + + /****************** Read constant pool and related **************/ + // Read constant pool entries + readConstantPool(); + + // Get class information + readClassInfo(); + + // Get interface information, i.e., implemented interfaces + readInterfaces(); + + /****************** Read class fields and methods ***************/ + // Read class fields, i.e., the variables of the class + readFields(); + + // Read class methods, i.e., the functions in the class + readMethods(); + + // Read class attributes + readAttributes(); + + // Read everything of interest, so close the file + file.close(); + + // Return the information we have gathered in a new object + JavaClass jc= new JavaClass(classnameIndex, superclassnameIndex, + filename, major, minor, accessflags, + cpool, interfaceIndices, fields, + methods, attributes); + return jc; + } + + /** Read information about the attributes of the class */ + private final void readAttributes() { + attributes = AttributeUtils.readAttributes(file,cpool); + } + + /** Read information about the class and its super class */ + private final void readClassInfo() throws IOException { + accessflags = file.readUnsignedShort(); + + /* Interfaces are implicitely abstract, the flag should be set + * according to the JVM specification */ + if((accessflags & Constants.ACC_INTERFACE) != 0) + accessflags |= Constants.ACC_ABSTRACT; + + // don't police it like this... leave higher level verification code to check it. +// if(((access_flags & Constants.ACC_ABSTRACT) != 0) && +// ((access_flags & Constants.ACC_FINAL) != 0 )) +// throw new ClassFormatException("Class can't be both final and abstract"); + + classnameIndex = file.readUnsignedShort(); + superclassnameIndex = file.readUnsignedShort(); + } + + /** Read constant pool entries */ + private final void readConstantPool() throws IOException { + try { + cpool = new ConstantPool(file); + } catch (ClassFormatException cfe) { + // add some context if we can + cfe.printStackTrace(); + if (filename!=null) { + String newmessage = "File: '"+filename+"': "+cfe.getMessage(); + throw new ClassFormatException(newmessage); // this loses the old stack trace but I dont think that matters! + } + throw cfe; + } + } + + /** Read information about the fields of the class */ + private final void readFields() throws IOException, ClassFormatException { + int fieldCount = file.readUnsignedShort(); + if (fieldCount == 0) { + fields = Field.NoFields; + } else { + fields = new Field[fieldCount]; + for(int i=0; i < fieldCount; i++) + fields[i] = new Field(file, cpool); + } + } + + /** Check whether the header of the file is ok. Of course, this has + * to be the first action on successive file reads */ + private final void readID() throws IOException { + int magic = 0xCAFEBABE; + if (file.readInt() != magic) + throw new ClassFormatException(filename + " is not a Java .class file"); + } + + private static final int[] NO_INTERFACES = new int[0]; + + /** Read information about the interfaces implemented by this class */ + private final void readInterfaces() throws IOException { + int interfacesCount = file.readUnsignedShort(); + if (interfacesCount==0) { + interfaceIndices = NO_INTERFACES; + } else { + interfaceIndices = new int[interfacesCount]; + for(int i=0; i < interfacesCount; i++) + interfaceIndices[i] = file.readUnsignedShort(); + } + } + + /** Read information about the methods of the class */ + private final void readMethods() throws IOException { + int methodsCount = file.readUnsignedShort(); + if (methodsCount==0) { + methods = Method.NoMethods; + } else { + methods = new Method[methodsCount]; + for(int i=0; i < methodsCount; i++) + methods[i] = new Method(file, cpool); + } + } + + /** Read major and minor version of compiler which created the file */ + private final void readVersion() throws IOException { + minor = file.readUnsignedShort(); + major = file.readUnsignedShort(); + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Visitor.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassVisitor.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/classfile/Visitor.java rename to bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassVisitor.java index 8d9ace8f5..8600baf0f 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Visitor.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassVisitor.java @@ -1,115 +1,115 @@ -package org.aspectj.apache.bcel.classfile; - -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Interface to make use of the Visitor pattern programming style. - * I.e. a class that implements this interface can traverse the contents of - * a Java class just by calling the `accept' method which all classes have. - * - * Implemented by wish of - * Boris Bokowski. - * - * @version $Id: Visitor.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - */ -public interface Visitor { - public void visitCode(Code obj); - public void visitCodeException(CodeException obj); - public void visitConstantClass(ConstantClass obj); - public void visitConstantDouble(ConstantDouble obj); - public void visitConstantFieldref(ConstantFieldref obj); - public void visitConstantFloat(ConstantFloat obj); - public void visitConstantInteger(ConstantInteger obj); - public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj); - public void visitConstantLong(ConstantLong obj); - public void visitConstantMethodref(ConstantMethodref obj); - public void visitConstantNameAndType(ConstantNameAndType obj); - public void visitConstantPool(ConstantPool obj); - public void visitConstantString(ConstantString obj); - public void visitConstantUtf8(ConstantUtf8 obj); - public void visitConstantValue(ConstantValue obj); - public void visitDeprecated(Deprecated obj); - public void visitExceptionTable(ExceptionTable obj); - public void visitField(Field obj); - public void visitInnerClass(InnerClass obj); - public void visitInnerClasses(InnerClasses obj); - public void visitJavaClass(JavaClass obj); - public void visitLineNumber(LineNumber obj); - public void visitLineNumberTable(LineNumberTable obj); - public void visitLocalVariable(LocalVariable obj); - public void visitLocalVariableTable(LocalVariableTable obj); - public void visitMethod(Method obj); - public void visitSignature(Signature obj); - public void visitSourceFile(SourceFile obj); - public void visitSynthetic(Synthetic obj); - public void visitUnknown(Unknown obj); - public void visitStackMap(StackMap obj); - public void visitStackMapEntry(StackMapEntry obj); - - // Java5 - public void visitEnclosingMethod(EnclosingMethod obj); - public void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations obj); - public void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations obj); - public void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations obj); - public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations obj); - public void visitAnnotationDefault(AnnotationDefault obj); - public void visitLocalVariableTypeTable(LocalVariableTypeTable obj); -} +package org.aspectj.apache.bcel.classfile; + +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Interface to make use of the Visitor pattern programming style. + * I.e. a class that implements this interface can traverse the contents of + * a Java class just by calling the `accept' method which all classes have. + * + * Implemented by wish of + * Boris Bokowski. + * + * @version $Id: ClassVisitor.java,v 1.1.2.1 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + */ +public interface ClassVisitor { + public void visitCode(Code obj); + public void visitCodeException(CodeException obj); + public void visitConstantClass(ConstantClass obj); + public void visitConstantDouble(ConstantDouble obj); + public void visitConstantFieldref(ConstantFieldref obj); + public void visitConstantFloat(ConstantFloat obj); + public void visitConstantInteger(ConstantInteger obj); + public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj); + public void visitConstantLong(ConstantLong obj); + public void visitConstantMethodref(ConstantMethodref obj); + public void visitConstantNameAndType(ConstantNameAndType obj); + public void visitConstantPool(ConstantPool obj); + public void visitConstantString(ConstantString obj); + public void visitConstantUtf8(ConstantUtf8 obj); + public void visitConstantValue(ConstantValue obj); + public void visitDeprecated(Deprecated obj); + public void visitExceptionTable(ExceptionTable obj); + public void visitField(Field obj); + public void visitInnerClass(InnerClass obj); + public void visitInnerClasses(InnerClasses obj); + public void visitJavaClass(JavaClass obj); + public void visitLineNumber(LineNumber obj); + public void visitLineNumberTable(LineNumberTable obj); + public void visitLocalVariable(LocalVariable obj); + public void visitLocalVariableTable(LocalVariableTable obj); + public void visitMethod(Method obj); + public void visitSignature(Signature obj); + public void visitSourceFile(SourceFile obj); + public void visitSynthetic(Synthetic obj); + public void visitUnknown(Unknown obj); + public void visitStackMap(StackMap obj); + public void visitStackMapEntry(StackMapEntry obj); + + // Java5 + public void visitEnclosingMethod(EnclosingMethod obj); + public void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations obj); + public void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations obj); + public void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations obj); + public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations obj); + public void visitAnnotationDefault(AnnotationDefault obj); + public void visitLocalVariableTypeTable(LocalVariableTypeTable obj); +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Code.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Code.java index d36a0b1e2..67d44e079 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Code.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Code.java @@ -1,376 +1,376 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents a chunk of Java byte code contained in a - * method. It is instantiated by the - * Attribute.readAttribute() method. A Code - * attribute contains informations about operand stack, local - * variables, byte code and the exceptions handled within this - * method. - * - * This attribute has attributes itself, namely LineNumberTable which - * is used for debugging purposes and LocalVariableTable which - * contains information about the local variables. - * - * @version $Id: Code.java,v 1.3.4.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see Attribute - * @see CodeException - * @see LineNumberTable - * @see LocalVariableTable - */ -public final class Code extends Attribute { - private int maxStack; // Maximum size of stack used by this method - private int maxLocals; // Number of local variables - private byte[] code; // Actual byte code - private CodeException[] exceptionTable; - private Attribute[] attributes; - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use copy() for a physical copy. - */ - public Code(Code c) { - this(c.getNameIndex(), c.getLength(), c.getMaxStack(), c.getMaxLocals(), - c.getCode(), c.getExceptionTable(), c.getAttributes(), - c.getConstantPool()); - } - - - Code(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException { - // Initialize with some default values which will be overwritten later - this(name_index, length, - file.readUnsignedShort(), file.readUnsignedShort(), - (byte[])null, (CodeException[])null, (Attribute[])null, - constant_pool); - - int len = file.readInt(); - code = new byte[len]; // Read byte code - file.readFully(code); - - /* Read exception table that contains all regions where an exception - * handler is active, i.e., a try { ... } catch() block. - */ - len = file.readUnsignedShort(); - exceptionTable = new CodeException[len]; - for(int i=0; i < len; i++) - exceptionTable[i] = new CodeException(file); - - // Read all attributes, eg: LineNumberTable, LocalVariableTable - attributes = AttributeUtils.readAttributes(file,constant_pool); - - /* Adjust length, because of setAttributes in this(), s.b. length - * is incorrect, because it didn't take the internal attributes - * into account yet! Very subtle bug, fixed in 3.1.1. - */ - this.length = length; - } - - /** - * @param name_index Index pointing to the name Code - * @param length Content length in bytes - * @param max_stack Maximum size of stack - * @param max_locals Number of local variables - * @param code Actual byte code - * @param exception_table Table of handled exceptions - * @param attributes Attributes of code: LineNumber or LocalVariable - * @param constant_pool Array of constants - */ - public Code(int name_index, int length, - int max_stack, int max_locals, - byte[] code, - CodeException[] exception_table, - Attribute[] attributes, - ConstantPool constant_pool) - { - super(Constants.ATTR_CODE, name_index, length, constant_pool); - - this.maxStack = max_stack; - this.maxLocals = max_locals; - - setCode(code); - setExceptionTable(exception_table); - setAttributes(attributes); // Overwrites length! - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitCode(this); - } - - /** - * Dump code attribute to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - - file.writeShort(maxStack); - if (maxStack==3) { - int stop = 1; // fixme - } - file.writeShort(maxLocals); - file.writeInt(code.length); - file.write(code, 0, code.length); - - file.writeShort(exceptionTable.length); - for(int i=0; i < exceptionTable.length; i++) - exceptionTable[i].dump(file); - - file.writeShort(attributes.length); - for(int i=0; i < attributes.length; i++) - attributes[i].dump(file); - } - - /** - * @return Collection of code attributes. - * @see Attribute - */ - public final Attribute[] getAttributes() { return attributes; } - - /** - * @return LineNumberTable of Code, if it has one - */ - public LineNumberTable getLineNumberTable() { - for (int i=0; i < attributes.length; i++) - if (attributes[i].tag==Constants.ATTR_LINE_NUMBER_TABLE) return (LineNumberTable)attributes[i]; - return null; - } - - /** - * @return LocalVariableTable of Code, if it has one - */ - public LocalVariableTable getLocalVariableTable() { - for(int i=0; i < attributes.length; i++) - if (attributes[i].tag==Constants.ATTR_LOCAL_VARIABLE_TABLE) return (LocalVariableTable)attributes[i]; - return null; - } - - /** - * @return Actual byte code of the method. - */ - public final byte[] getCode() { return code; } - - /** - * @return Table of handled exceptions. - * @see CodeException - */ - public final CodeException[] getExceptionTable() { return exceptionTable; } - - /** - * @return Number of local variables. - */ - public final int getMaxLocals() { return maxLocals; } - - /** - * @return Maximum size of stack used by this method. - */ - - public final int getMaxStack() { return maxStack; } - - /** - * @return the internal length of this code attribute (minus the first 6 bytes) - * and excluding all its attributes - */ - private final int getInternalLength() { - return 2 /*max_stack*/ + 2 /*max_locals*/ + 4 /*code length*/ - + (code==null?0:code.length) /*byte-code*/ - + 2 /*exception-table length*/ - + 8 * (exceptionTable==null?0:exceptionTable.length) /* exception table */ - + 2 /* attributes count */; - } - - /** - * @return the full size of this code attribute, minus its first 6 bytes, - * including the size of all its contained attributes - */ - private final int calculateLength() { - int len = 0; - if (attributes!=null) { - for(int i=0; i < attributes.length; i++) - len += attributes[i].length + 6 /*attribute header size*/; - } - return len + getInternalLength(); - } - - /** - * @param attributes. - */ - public final void setAttributes(Attribute[] attributes) { - this.attributes = attributes; - length = calculateLength(); // Adjust length - } - - /** - * @param code byte code - */ - public final void setCode(byte[] code) { - this.code = code; - } - - /** - * @param exception_table exception table - */ - public final void setExceptionTable(CodeException[] exception_table) { - this.exceptionTable = exception_table; - } - - /** - * @param max_locals maximum number of local variables - */ - public final void setMaxLocals(int max_locals) { - this.maxLocals = max_locals; - } - - /** - * @param max_stack maximum stack size - */ - public final void setMaxStack(int max_stack) { - this.maxStack = max_stack; - } - - /** - * @return String representation of code chunk. - */ - public final String toString(boolean verbose) { - StringBuffer buf; - - buf = new StringBuffer("Code(max_stack = " + maxStack + - ", max_locals = " + maxLocals + - ", code_length = " + code.length + ")\n" + - Utility.codeToString(code, constantPool, 0, -1, verbose)); - - if(exceptionTable.length > 0) { - buf.append("\nException handler(s) = \n" + "From\tTo\tHandler\tType\n"); - - for(int i=0; i < exceptionTable.length; i++) - buf.append(exceptionTable[i].toString(constantPool, verbose) + "\n"); - } - - if(attributes.length > 0) { - buf.append("\nAttribute(s) = \n"); - - for(int i=0; i < attributes.length; i++) - buf.append(attributes[i].toString() + "\n"); - } - - return buf.toString(); - } - - /** - * @return String representation of code chunk. - */ - public final String toString() { - return toString(true); - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - Code c = (Code)clone(); - c.code = (byte[])code.clone(); - c.constantPool = constant_pool; - - c.exceptionTable = new CodeException[exceptionTable.length]; - for(int i=0; i < exceptionTable.length; i++) - c.exceptionTable[i] = exceptionTable[i].copy(); - - c.attributes = new Attribute[attributes.length]; - for(int i=0; i < attributes.length; i++) - c.attributes[i] = attributes[i].copy(constant_pool); - - return c; - } - - /** - * Returns the same as toString(true) except that the attribute information - * isn't included (line numbers). - * Can be used to check whether two pieces of code are equivalent. - */ - public String getCodeString() { - StringBuffer codeString = new StringBuffer(); - codeString.append("Code(max_stack = ").append(maxStack); - codeString.append(", max_locals = ").append(maxLocals); - codeString.append(", code_length = ").append(code.length).append(")\n"); - codeString.append(Utility.codeToString(code, constantPool, 0, -1,true)); - if (exceptionTable.length>0) { - codeString.append("\n").append("Exception entries = ").append(exceptionTable.length).append("\n"); - for (int i = 0; i < exceptionTable.length; i++) { - CodeException exc = exceptionTable[i]; - int type = exc.getCatchType(); - String name = "finally"; - if (type!=0) name = this.constantPool.getConstantString(type,Constants.CONSTANT_Class); - codeString.append(name).append("["); - codeString.append(exc.getStartPC()).append(">").append(exc.getEndPC()).append("]\n"); - } - } - return codeString.toString(); - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents a chunk of Java byte code contained in a + * method. It is instantiated by the + * Attribute.readAttribute() method. A Code + * attribute contains informations about operand stack, local + * variables, byte code and the exceptions handled within this + * method. + * + * This attribute has attributes itself, namely LineNumberTable which + * is used for debugging purposes and LocalVariableTable which + * contains information about the local variables. + * + * @version $Id: Code.java,v 1.3.4.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Attribute + * @see CodeException + * @see LineNumberTable + * @see LocalVariableTable + */ +public final class Code extends Attribute { + private int maxStack; // Maximum size of stack used by this method + private int maxLocals; // Number of local variables + private byte[] code; // Actual byte code + private CodeException[] exceptionTable; + private Attribute[] attributes; + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use copy() for a physical copy. + */ + public Code(Code c) { + this(c.getNameIndex(), c.getLength(), c.getMaxStack(), c.getMaxLocals(), + c.getCode(), c.getExceptionTable(), c.getAttributes(), + c.getConstantPool()); + } + + + Code(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException { + // Initialize with some default values which will be overwritten later + this(name_index, length, + file.readUnsignedShort(), file.readUnsignedShort(), + (byte[])null, (CodeException[])null, (Attribute[])null, + constant_pool); + + int len = file.readInt(); + code = new byte[len]; // Read byte code + file.readFully(code); + + /* Read exception table that contains all regions where an exception + * handler is active, i.e., a try { ... } catch() block. + */ + len = file.readUnsignedShort(); + exceptionTable = new CodeException[len]; + for(int i=0; i < len; i++) + exceptionTable[i] = new CodeException(file); + + // Read all attributes, eg: LineNumberTable, LocalVariableTable + attributes = AttributeUtils.readAttributes(file,constant_pool); + + /* Adjust length, because of setAttributes in this(), s.b. length + * is incorrect, because it didn't take the internal attributes + * into account yet! Very subtle bug, fixed in 3.1.1. + */ + this.length = length; + } + + /** + * @param name_index Index pointing to the name Code + * @param length Content length in bytes + * @param max_stack Maximum size of stack + * @param max_locals Number of local variables + * @param code Actual byte code + * @param exception_table Table of handled exceptions + * @param attributes Attributes of code: LineNumber or LocalVariable + * @param constant_pool Array of constants + */ + public Code(int name_index, int length, + int max_stack, int max_locals, + byte[] code, + CodeException[] exception_table, + Attribute[] attributes, + ConstantPool constant_pool) + { + super(Constants.ATTR_CODE, name_index, length, constant_pool); + + this.maxStack = max_stack; + this.maxLocals = max_locals; + + setCode(code); + setExceptionTable(exception_table); + setAttributes(attributes); // Overwrites length! + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitCode(this); + } + + /** + * Dump code attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + + file.writeShort(maxStack); + if (maxStack==3) { + int stop = 1; // fixme + } + file.writeShort(maxLocals); + file.writeInt(code.length); + file.write(code, 0, code.length); + + file.writeShort(exceptionTable.length); + for(int i=0; i < exceptionTable.length; i++) + exceptionTable[i].dump(file); + + file.writeShort(attributes.length); + for(int i=0; i < attributes.length; i++) + attributes[i].dump(file); + } + + /** + * @return Collection of code attributes. + * @see Attribute + */ + public final Attribute[] getAttributes() { return attributes; } + + /** + * @return LineNumberTable of Code, if it has one + */ + public LineNumberTable getLineNumberTable() { + for (int i=0; i < attributes.length; i++) + if (attributes[i].tag==Constants.ATTR_LINE_NUMBER_TABLE) return (LineNumberTable)attributes[i]; + return null; + } + + /** + * @return LocalVariableTable of Code, if it has one + */ + public LocalVariableTable getLocalVariableTable() { + for(int i=0; i < attributes.length; i++) + if (attributes[i].tag==Constants.ATTR_LOCAL_VARIABLE_TABLE) return (LocalVariableTable)attributes[i]; + return null; + } + + /** + * @return Actual byte code of the method. + */ + public final byte[] getCode() { return code; } + + /** + * @return Table of handled exceptions. + * @see CodeException + */ + public final CodeException[] getExceptionTable() { return exceptionTable; } + + /** + * @return Number of local variables. + */ + public final int getMaxLocals() { return maxLocals; } + + /** + * @return Maximum size of stack used by this method. + */ + + public final int getMaxStack() { return maxStack; } + + /** + * @return the internal length of this code attribute (minus the first 6 bytes) + * and excluding all its attributes + */ + private final int getInternalLength() { + return 2 /*max_stack*/ + 2 /*max_locals*/ + 4 /*code length*/ + + (code==null?0:code.length) /*byte-code*/ + + 2 /*exception-table length*/ + + 8 * (exceptionTable==null?0:exceptionTable.length) /* exception table */ + + 2 /* attributes count */; + } + + /** + * @return the full size of this code attribute, minus its first 6 bytes, + * including the size of all its contained attributes + */ + private final int calculateLength() { + int len = 0; + if (attributes!=null) { + for(int i=0; i < attributes.length; i++) + len += attributes[i].length + 6 /*attribute header size*/; + } + return len + getInternalLength(); + } + + /** + * @param attributes. + */ + public final void setAttributes(Attribute[] attributes) { + this.attributes = attributes; + length = calculateLength(); // Adjust length + } + + /** + * @param code byte code + */ + public final void setCode(byte[] code) { + this.code = code; + } + + /** + * @param exception_table exception table + */ + public final void setExceptionTable(CodeException[] exception_table) { + this.exceptionTable = exception_table; + } + + /** + * @param max_locals maximum number of local variables + */ + public final void setMaxLocals(int max_locals) { + this.maxLocals = max_locals; + } + + /** + * @param max_stack maximum stack size + */ + public final void setMaxStack(int max_stack) { + this.maxStack = max_stack; + } + + /** + * @return String representation of code chunk. + */ + public final String toString(boolean verbose) { + StringBuffer buf; + + buf = new StringBuffer("Code(max_stack = " + maxStack + + ", max_locals = " + maxLocals + + ", code_length = " + code.length + ")\n" + + Utility.codeToString(code, constantPool, 0, -1, verbose)); + + if(exceptionTable.length > 0) { + buf.append("\nException handler(s) = \n" + "From\tTo\tHandler\tType\n"); + + for(int i=0; i < exceptionTable.length; i++) + buf.append(exceptionTable[i].toString(constantPool, verbose) + "\n"); + } + + if(attributes.length > 0) { + buf.append("\nAttribute(s) = \n"); + + for(int i=0; i < attributes.length; i++) + buf.append(attributes[i].toString() + "\n"); + } + + return buf.toString(); + } + + /** + * @return String representation of code chunk. + */ + public final String toString() { + return toString(true); + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + Code c = (Code)clone(); + c.code = (byte[])code.clone(); + c.constantPool = constant_pool; + + c.exceptionTable = new CodeException[exceptionTable.length]; + for(int i=0; i < exceptionTable.length; i++) + c.exceptionTable[i] = exceptionTable[i].copy(); + + c.attributes = new Attribute[attributes.length]; + for(int i=0; i < attributes.length; i++) + c.attributes[i] = attributes[i].copy(constant_pool); + + return c; + } + + /** + * Returns the same as toString(true) except that the attribute information + * isn't included (line numbers). + * Can be used to check whether two pieces of code are equivalent. + */ + public String getCodeString() { + StringBuffer codeString = new StringBuffer(); + codeString.append("Code(max_stack = ").append(maxStack); + codeString.append(", max_locals = ").append(maxLocals); + codeString.append(", code_length = ").append(code.length).append(")\n"); + codeString.append(Utility.codeToString(code, constantPool, 0, -1,true)); + if (exceptionTable.length>0) { + codeString.append("\n").append("Exception entries = ").append(exceptionTable.length).append("\n"); + for (int i = 0; i < exceptionTable.length; i++) { + CodeException exc = exceptionTable[i]; + int type = exc.getCatchType(); + String name = "finally"; + if (type!=0) name = this.constantPool.getConstantString(type,Constants.CONSTANT_Class); + codeString.append(name).append("["); + codeString.append(exc.getStartPC()).append(">").append(exc.getEndPC()).append("]\n"); + } + } + return codeString.toString(); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/CodeException.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/CodeException.java index ac4564c22..73042c1c3 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/CodeException.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/CodeException.java @@ -1,196 +1,196 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents an entry in the exception table of the Code - * attribute and is used only there. It contains a range in which a - * particular exception handler is active. - * - * @version $Id: CodeException.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see Code - */ -public final class CodeException implements Cloneable, Constants, Node, Serializable { - private int start_pc; // Range in the code the exception handler is - private int end_pc; // active. start_pc is inclusive, end_pc exclusive - private int handler_pc; /* Starting address of exception handler, i.e., - * an offset from start of code. - */ - private int catch_type; /* If this is zero the handler catches any - * exception, otherwise it points to the - * exception class which is to be caught. - */ - - public CodeException(CodeException c) { - this(c.getStartPC(), c.getEndPC(), c.getHandlerPC(), c.getCatchType()); - } - - CodeException(DataInputStream file) throws IOException { - start_pc = file.readUnsignedShort(); - end_pc = file.readUnsignedShort(); - handler_pc = file.readUnsignedShort(); - catch_type = file.readUnsignedShort(); - } - - public CodeException(int start_pc, int end_pc, int handler_pc, int catch_type) { - this.start_pc = start_pc; - this.end_pc = end_pc; - this.handler_pc = handler_pc; - this.catch_type = catch_type; - } - - public void accept(Visitor v) { - v.visitCodeException(this); - } - - public final void dump(DataOutputStream file) throws IOException { - file.writeShort(start_pc); - file.writeShort(end_pc); - file.writeShort(handler_pc); - file.writeShort(catch_type); - } - - /** - * @return 0, if the handler catches any exception, otherwise it points to - * the exception class which is to be caught. - */ - public final int getCatchType() { return catch_type; } - - /** - * @return Exclusive end index of the region where the handler is active. - */ - public final int getEndPC() { return end_pc; } - - /** - * @return Starting address of exception handler, relative to the code. - */ - public final int getHandlerPC() { return handler_pc; } - - /** - * @return Inclusive start index of the region where the handler is active. - */ - public final int getStartPC() { return start_pc; } - - /** - * @param catch_type. - */ - public final void setCatchType(int catch_type) { - this.catch_type = catch_type; - } - - /** - * @param end_pc end of handled block - */ - public final void setEndPC(int end_pc) { - this.end_pc = end_pc; - } - - /** - * @param handler_pc where the actual code is - */ - public final void setHandlerPC(int handler_pc) { - this.handler_pc = handler_pc; - } - - /** - * @param start_pc start of handled block - */ - public final void setStartPC(int start_pc) { - this.start_pc = start_pc; - } - - /** - * @return String representation. - */ - public final String toString() { - return "CodeException(start_pc = " + start_pc + - ", end_pc = " + end_pc + - ", handler_pc = " + handler_pc + ", catch_type = " + catch_type + ")"; - } - - /** - * @return String representation. - */ - public final String toString(ConstantPool cp, boolean verbose) { - String str; - - if(catch_type == 0) - str = "(0)"; - else - str = Utility.compactClassName(cp.getConstantString(catch_type, CONSTANT_Class), false) + - (verbose? "(" + catch_type + ")" : ""); - - return start_pc + "\t" + end_pc + "\t" + handler_pc + "\t" + str; - } - - public final String toString(ConstantPool cp) { - return toString(cp, true); - } - - /** - * @return deep copy of this object - */ - public CodeException copy() { - try { - return (CodeException)clone(); - } catch(CloneNotSupportedException e) {} - - return null; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents an entry in the exception table of the Code + * attribute and is used only there. It contains a range in which a + * particular exception handler is active. + * + * @version $Id: CodeException.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Code + */ +public final class CodeException implements Cloneable, Constants, Node, Serializable { + private int start_pc; // Range in the code the exception handler is + private int end_pc; // active. start_pc is inclusive, end_pc exclusive + private int handler_pc; /* Starting address of exception handler, i.e., + * an offset from start of code. + */ + private int catch_type; /* If this is zero the handler catches any + * exception, otherwise it points to the + * exception class which is to be caught. + */ + + public CodeException(CodeException c) { + this(c.getStartPC(), c.getEndPC(), c.getHandlerPC(), c.getCatchType()); + } + + CodeException(DataInputStream file) throws IOException { + start_pc = file.readUnsignedShort(); + end_pc = file.readUnsignedShort(); + handler_pc = file.readUnsignedShort(); + catch_type = file.readUnsignedShort(); + } + + public CodeException(int start_pc, int end_pc, int handler_pc, int catch_type) { + this.start_pc = start_pc; + this.end_pc = end_pc; + this.handler_pc = handler_pc; + this.catch_type = catch_type; + } + + public void accept(ClassVisitor v) { + v.visitCodeException(this); + } + + public final void dump(DataOutputStream file) throws IOException { + file.writeShort(start_pc); + file.writeShort(end_pc); + file.writeShort(handler_pc); + file.writeShort(catch_type); + } + + /** + * @return 0, if the handler catches any exception, otherwise it points to + * the exception class which is to be caught. + */ + public final int getCatchType() { return catch_type; } + + /** + * @return Exclusive end index of the region where the handler is active. + */ + public final int getEndPC() { return end_pc; } + + /** + * @return Starting address of exception handler, relative to the code. + */ + public final int getHandlerPC() { return handler_pc; } + + /** + * @return Inclusive start index of the region where the handler is active. + */ + public final int getStartPC() { return start_pc; } + + /** + * @param catch_type. + */ + public final void setCatchType(int catch_type) { + this.catch_type = catch_type; + } + + /** + * @param end_pc end of handled block + */ + public final void setEndPC(int end_pc) { + this.end_pc = end_pc; + } + + /** + * @param handler_pc where the actual code is + */ + public final void setHandlerPC(int handler_pc) { + this.handler_pc = handler_pc; + } + + /** + * @param start_pc start of handled block + */ + public final void setStartPC(int start_pc) { + this.start_pc = start_pc; + } + + /** + * @return String representation. + */ + public final String toString() { + return "CodeException(start_pc = " + start_pc + + ", end_pc = " + end_pc + + ", handler_pc = " + handler_pc + ", catch_type = " + catch_type + ")"; + } + + /** + * @return String representation. + */ + public final String toString(ConstantPool cp, boolean verbose) { + String str; + + if(catch_type == 0) + str = "(0)"; + else + str = Utility.compactClassName(cp.getConstantString(catch_type, CONSTANT_Class), false) + + (verbose? "(" + catch_type + ")" : ""); + + return start_pc + "\t" + end_pc + "\t" + handler_pc + "\t" + str; + } + + public final String toString(ConstantPool cp) { + return toString(cp, true); + } + + /** + * @return deep copy of this object + */ + public CodeException copy() { + try { + return (CodeException)clone(); + } catch(CloneNotSupportedException e) {} + + return null; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Constant.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Constant.java index 519f9d928..6d1da26d7 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Constant.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Constant.java @@ -1,138 +1,138 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * Abstract superclass for classes to represent the different constant types - * in the constant pool of a class file. The classes keep closely to - * the JVM specification. - * - * @version $Id: Constant.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - */ -public abstract class Constant implements Cloneable, Node, Serializable { - /* In fact this tag is redundant since we can distinguish different - * `Constant' objects by their type, i.e., via `instanceof'. In some - * places we will use the tag for switch()es anyway. - * - * First, we want match the specification as closely as possible. Second we - * need the tag as an index to select the corresponding class name from the - * `CONSTANT_NAMES' array. - */ - protected byte tag; - - Constant(byte tag) { this.tag = tag; } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public abstract void accept(Visitor v); - - public abstract void dump(DataOutputStream file) throws IOException; - - /** - * @return Tag of constant, i.e., its type. No setTag() method to avoid - * confusion. - */ - public final byte getTag() { return tag; } - - /** - * @return String representation. - */ - public String toString() { - return Constants.CONSTANT_NAMES[tag] + "[" + tag + "]"; - } - - /** - * @return deep copy of this constant - */ - public Constant copy() { - try { - return (Constant)super.clone(); - } catch(CloneNotSupportedException e) {} - - return null; - } - - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - static final Constant readConstant(DataInputStream file) throws IOException, ClassFormatException { - byte b = file.readByte(); - switch(b) { - case Constants.CONSTANT_Class: return new ConstantClass(file); - case Constants.CONSTANT_NameAndType: return new ConstantNameAndType(file); - case Constants.CONSTANT_Utf8: return new ConstantUtf8(file); - case Constants.CONSTANT_Fieldref: return new ConstantFieldref(file); - case Constants.CONSTANT_Methodref: return new ConstantMethodref(file); - case Constants.CONSTANT_InterfaceMethodref: return new ConstantInterfaceMethodref(file); - case Constants.CONSTANT_String: return new ConstantString(file); - case Constants.CONSTANT_Integer: return new ConstantInteger(file); - case Constants.CONSTANT_Float: return new ConstantFloat(file); - case Constants.CONSTANT_Long: return new ConstantLong(file); - case Constants.CONSTANT_Double: return new ConstantDouble(file); - default: - throw new ClassFormatException("Invalid byte tag in constant pool: " + b); - } - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * Abstract superclass for classes to represent the different constant types + * in the constant pool of a class file. The classes keep closely to + * the JVM specification. + * + * @version $Id: Constant.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + */ +public abstract class Constant implements Cloneable, Node, Serializable { + /* In fact this tag is redundant since we can distinguish different + * `Constant' objects by their type, i.e., via `instanceof'. In some + * places we will use the tag for switch()es anyway. + * + * First, we want match the specification as closely as possible. Second we + * need the tag as an index to select the corresponding class name from the + * `CONSTANT_NAMES' array. + */ + protected byte tag; + + Constant(byte tag) { this.tag = tag; } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public abstract void accept(ClassVisitor v); + + public abstract void dump(DataOutputStream file) throws IOException; + + /** + * @return Tag of constant, i.e., its type. No setTag() method to avoid + * confusion. + */ + public final byte getTag() { return tag; } + + /** + * @return String representation. + */ + public String toString() { + return Constants.CONSTANT_NAMES[tag] + "[" + tag + "]"; + } + + /** + * @return deep copy of this constant + */ + public Constant copy() { + try { + return (Constant)super.clone(); + } catch(CloneNotSupportedException e) {} + + return null; + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + static final Constant readConstant(DataInputStream file) throws IOException, ClassFormatException { + byte b = file.readByte(); + switch(b) { + case Constants.CONSTANT_Class: return new ConstantClass(file); + case Constants.CONSTANT_NameAndType: return new ConstantNameAndType(file); + case Constants.CONSTANT_Utf8: return new ConstantUtf8(file); + case Constants.CONSTANT_Fieldref: return new ConstantFieldref(file); + case Constants.CONSTANT_Methodref: return new ConstantMethodref(file); + case Constants.CONSTANT_InterfaceMethodref: return new ConstantInterfaceMethodref(file); + case Constants.CONSTANT_String: return new ConstantString(file); + case Constants.CONSTANT_Integer: return new ConstantInteger(file); + case Constants.CONSTANT_Float: return new ConstantFloat(file); + case Constants.CONSTANT_Long: return new ConstantLong(file); + case Constants.CONSTANT_Double: return new ConstantDouble(file); + default: + throw new ClassFormatException("Invalid byte tag in constant pool: " + b); + } + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantCP.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantCP.java index cd11b5b3b..d28e68b5a 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantCP.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantCP.java @@ -1,154 +1,154 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; -import org.aspectj.apache.bcel.Constants; - -/** - * Abstract super class for Fieldref and Methodref constants. - * - * @version $Id: ConstantCP.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see ConstantFieldref - * @see ConstantMethodref - * @see ConstantInterfaceMethodref - */ -public abstract class ConstantCP extends Constant { - /** References to the constants containing the class and the field signature - */ - protected int class_index, name_and_type_index; - - /** - * Initialize from another object. - */ - public ConstantCP(ConstantCP c) { - this(c.getTag(), c.getClassIndex(), c.getNameAndTypeIndex()); - } - - /** - * Initialize instance from file data. - * - * @param tag Constant type tag - * @param file Input stream - * @throws IOException - */ - ConstantCP(byte tag, DataInputStream file) throws IOException - { - this(tag, file.readUnsignedShort(), file.readUnsignedShort()); - } - - /** - * @param class_index Reference to the class containing the field - * @param name_and_type_index and the field signature - */ - protected ConstantCP(byte tag, int class_index, - int name_and_type_index) { - super(tag); - this.class_index = class_index; - this.name_and_type_index = name_and_type_index; - } - - /** - * Dump constant field reference to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeByte(tag); - file.writeShort(class_index); - file.writeShort(name_and_type_index); - } - - /** - * @return Reference (index) to class this field or method belongs to. - */ - public final int getClassIndex() { return class_index; } - - /** - * @return Reference (index) to signature of the field. - */ - public final int getNameAndTypeIndex() { return name_and_type_index; } - - /** - * @param class_index points to Constant_class - */ - public final void setClassIndex(int class_index) { - this.class_index = class_index; - } - - /** - * @return Class this field belongs to. - */ - public String getClass(ConstantPool cp) { - return cp.constantToString(class_index, Constants.CONSTANT_Class); - } - - /** - * @param name_and_type_index points to Constant_NameAndType - */ - public final void setNameAndTypeIndex(int name_and_type_index) { - this.name_and_type_index = name_and_type_index; - } - - /** - * @return String representation. - */ - public final String toString() { - return super.toString() + "(class_index = " + class_index + - ", name_and_type_index = " + name_and_type_index + ")"; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.io.*; +import org.aspectj.apache.bcel.Constants; + +/** + * Abstract super class for Fieldref and Methodref constants. + * + * @version $Id: ConstantCP.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see ConstantFieldref + * @see ConstantMethodref + * @see ConstantInterfaceMethodref + */ +public abstract class ConstantCP extends Constant { + /** References to the constants containing the class and the field signature + */ + protected int class_index, name_and_type_index; + + /** + * Initialize from another object. + */ + public ConstantCP(ConstantCP c) { + this(c.getTag(), c.getClassIndex(), c.getNameAndTypeIndex()); + } + + /** + * Initialize instance from file data. + * + * @param tag Constant type tag + * @param file Input stream + * @throws IOException + */ + ConstantCP(byte tag, DataInputStream file) throws IOException + { + this(tag, file.readUnsignedShort(), file.readUnsignedShort()); + } + + /** + * @param class_index Reference to the class containing the field + * @param name_and_type_index and the field signature + */ + protected ConstantCP(byte tag, int class_index, + int name_and_type_index) { + super(tag); + this.class_index = class_index; + this.name_and_type_index = name_and_type_index; + } + + /** + * Dump constant field reference to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeByte(tag); + file.writeShort(class_index); + file.writeShort(name_and_type_index); + } + + /** + * @return Reference (index) to class this field or method belongs to. + */ + public final int getClassIndex() { return class_index; } + + /** + * @return Reference (index) to signature of the field. + */ + public final int getNameAndTypeIndex() { return name_and_type_index; } + + /** + * @param class_index points to Constant_class + */ + public final void setClassIndex(int class_index) { + this.class_index = class_index; + } + + /** + * @return Class this field belongs to. + */ + public String getClass(ConstantPool cp) { + return cp.constantToString(class_index, Constants.CONSTANT_Class); + } + + /** + * @param name_and_type_index points to Constant_NameAndType + */ + public final void setNameAndTypeIndex(int name_and_type_index) { + this.name_and_type_index = name_and_type_index; + } + + /** + * @return String representation. + */ + public final String toString() { + return super.toString() + "(class_index = " + class_index + + ", name_and_type_index = " + name_and_type_index + ")"; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantClass.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantClass.java index 250e84ceb..89fd3659f 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantClass.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantClass.java @@ -1,156 +1,156 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from the abstract - * Constant class - * and represents a reference to a (external) class. - * - * @version $Id: ConstantClass.java,v 1.2.10.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see Constant - */ -public final class ConstantClass extends Constant implements ConstantObject { - private int name_index; // Identical to ConstantString except for the name - - /** - * Initialize from another object. - */ - public ConstantClass(ConstantClass c) { - this(c.getNameIndex()); - } - - /** - * Initialize instance from file data. - * - * @param file Input stream - * @throws IOException - */ - ConstantClass(DataInputStream file) throws IOException - { - super(Constants.CONSTANT_Class); - this.name_index = file.readUnsignedShort(); -// this(file.readUnsignedShort()); - } - - /** - * @param name_index Name index in constant pool. Should refer to a - * ConstantUtf8. - */ - public ConstantClass(int name_index) { - super(Constants.CONSTANT_Class); - this.name_index = name_index; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitConstantClass(this); - } - - /** - * Dump constant class to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeByte(tag); - file.writeShort(name_index); - } - - /** - * @return Name index in constant pool of class name. - */ - public final int getNameIndex() { return name_index; } - - /** - * @param name_index. - */ - public final void setNameIndex(int name_index) { - this.name_index = name_index; - } - - - /** @return String object - */ - public Object getConstantValue(ConstantPool cp) { - Constant c = cp.getConstant(name_index, Constants.CONSTANT_Utf8); - return ((ConstantUtf8)c).getBytes(); - } - - /** @return dereferenced string - */ - public String getBytes(ConstantPool cp) { - return (String)getConstantValue(cp); - } - - /** - * @return String representation. - */ - public final String toString() { - return super.toString() + "(name_index = " + name_index + ")"; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from the abstract + * Constant class + * and represents a reference to a (external) class. + * + * @version $Id: ConstantClass.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Constant + */ +public final class ConstantClass extends Constant implements ConstantObject { + private int name_index; // Identical to ConstantString except for the name + + /** + * Initialize from another object. + */ + public ConstantClass(ConstantClass c) { + this(c.getNameIndex()); + } + + /** + * Initialize instance from file data. + * + * @param file Input stream + * @throws IOException + */ + ConstantClass(DataInputStream file) throws IOException + { + super(Constants.CONSTANT_Class); + this.name_index = file.readUnsignedShort(); +// this(file.readUnsignedShort()); + } + + /** + * @param name_index Name index in constant pool. Should refer to a + * ConstantUtf8. + */ + public ConstantClass(int name_index) { + super(Constants.CONSTANT_Class); + this.name_index = name_index; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitConstantClass(this); + } + + /** + * Dump constant class to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeByte(tag); + file.writeShort(name_index); + } + + /** + * @return Name index in constant pool of class name. + */ + public final int getNameIndex() { return name_index; } + + /** + * @param name_index. + */ + public final void setNameIndex(int name_index) { + this.name_index = name_index; + } + + + /** @return String object + */ + public Object getConstantValue(ConstantPool cp) { + Constant c = cp.getConstant(name_index, Constants.CONSTANT_Utf8); + return ((ConstantUtf8)c).getBytes(); + } + + /** @return dereferenced string + */ + public String getBytes(ConstantPool cp) { + return (String)getConstantValue(cp); + } + + /** + * @return String representation. + */ + public final String toString() { + return super.toString() + "(name_index = " + name_index + ")"; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantDouble.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantDouble.java index b3ecb2863..9ce6720fd 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantDouble.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantDouble.java @@ -1,142 +1,142 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from the abstract - * Constant class - * and represents a reference to a Double object. - * - * @version $Id: ConstantDouble.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see Constant - */ -public final class ConstantDouble extends Constant implements ConstantObject { - private double bytes; - - /** - * @param bytes Data - */ - public ConstantDouble(double bytes) { - super(Constants.CONSTANT_Double); - this.bytes = bytes; - } - - /** - * Initialize from another object. - */ - public ConstantDouble(ConstantDouble c) { - this(c.getBytes()); - } - - /** - * Initialize instance from file data. - * - * @param file Input stream - * @throws IOException - */ - ConstantDouble(DataInputStream file) throws IOException - { - this(file.readDouble()); - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitConstantDouble(this); - } - /** - * Dump constant double to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeByte(tag); - file.writeDouble(bytes); - } - /** - * @return data, i.e., 8 bytes. - */ - public final double getBytes() { return bytes; } - /** - * @param bytes. - */ - public final void setBytes(double bytes) { - this.bytes = bytes; - } - /** - * @return String representation. - */ - public final String toString() - { - return super.toString() + "(bytes = " + bytes + ")"; - } - - /** @return Double object - */ - public Object getConstantValue(ConstantPool cp) { - return new Double(bytes); - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from the abstract + * Constant class + * and represents a reference to a Double object. + * + * @version $Id: ConstantDouble.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Constant + */ +public final class ConstantDouble extends Constant implements ConstantObject { + private double bytes; + + /** + * @param bytes Data + */ + public ConstantDouble(double bytes) { + super(Constants.CONSTANT_Double); + this.bytes = bytes; + } + + /** + * Initialize from another object. + */ + public ConstantDouble(ConstantDouble c) { + this(c.getBytes()); + } + + /** + * Initialize instance from file data. + * + * @param file Input stream + * @throws IOException + */ + ConstantDouble(DataInputStream file) throws IOException + { + this(file.readDouble()); + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitConstantDouble(this); + } + /** + * Dump constant double to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeByte(tag); + file.writeDouble(bytes); + } + /** + * @return data, i.e., 8 bytes. + */ + public final double getBytes() { return bytes; } + /** + * @param bytes. + */ + public final void setBytes(double bytes) { + this.bytes = bytes; + } + /** + * @return String representation. + */ + public final String toString() + { + return super.toString() + "(bytes = " + bytes + ")"; + } + + /** @return Double object + */ + public Object getConstantValue(ConstantPool cp) { + return new Double(bytes); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantFieldref.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantFieldref.java index 66ac63353..9810563a9 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantFieldref.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantFieldref.java @@ -1,104 +1,104 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents a constant pool reference to a field. - * - * @version $Id: ConstantFieldref.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - */ -public final class ConstantFieldref extends ConstantCP { - /** - * Initialize from another object. - */ - public ConstantFieldref(ConstantFieldref c) { - super(Constants.CONSTANT_Fieldref, c.getClassIndex(), c.getNameAndTypeIndex()); - } - - /** - * Initialize instance from file data. - * - * @param file input stream - * @throws IOException - */ - ConstantFieldref(DataInputStream file) throws IOException - { - super(Constants.CONSTANT_Fieldref, file); - } - - /** - * @param class_index Reference to the class containing the Field - * @param name_and_type_index and the Field signature - */ - public ConstantFieldref(int class_index, - int name_and_type_index) { - super(Constants.CONSTANT_Fieldref, class_index, name_and_type_index); - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of Fields, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitConstantFieldref(this); - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents a constant pool reference to a field. + * + * @version $Id: ConstantFieldref.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + */ +public final class ConstantFieldref extends ConstantCP { + /** + * Initialize from another object. + */ + public ConstantFieldref(ConstantFieldref c) { + super(Constants.CONSTANT_Fieldref, c.getClassIndex(), c.getNameAndTypeIndex()); + } + + /** + * Initialize instance from file data. + * + * @param file input stream + * @throws IOException + */ + ConstantFieldref(DataInputStream file) throws IOException + { + super(Constants.CONSTANT_Fieldref, file); + } + + /** + * @param class_index Reference to the class containing the Field + * @param name_and_type_index and the Field signature + */ + public ConstantFieldref(int class_index, + int name_and_type_index) { + super(Constants.CONSTANT_Fieldref, class_index, name_and_type_index); + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of Fields, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitConstantFieldref(this); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantFloat.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantFloat.java index 52bd59681..08db79ea7 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantFloat.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantFloat.java @@ -1,141 +1,141 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from the abstract - * Constant class - * and represents a reference to a float object. - * - * @version $Id: ConstantFloat.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see Constant - */ -public final class ConstantFloat extends Constant implements ConstantObject { - private float bytes; - - /** - * @param bytes Data - */ - public ConstantFloat(float bytes) - { - super(Constants.CONSTANT_Float); - this.bytes = bytes; - } - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use clone() for a physical copy. - */ - public ConstantFloat(ConstantFloat c) { - this(c.getBytes()); - } - /** - * Initialize instance from file data. - * - * @param file Input stream - * @throws IOException - */ - ConstantFloat(DataInputStream file) throws IOException - { - this(file.readFloat()); - } - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitConstantFloat(this); - } - /** - * Dump constant float to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeByte(tag); - file.writeFloat(bytes); - } - /** - * @return data, i.e., 4 bytes. - */ - public final float getBytes() { return bytes; } - /** - * @param bytes. - */ - public final void setBytes(float bytes) { - this.bytes = bytes; - } - - /** - * @return String representation. - */ - public final String toString() { - return super.toString() + "(bytes = " + bytes + ")"; - } - - /** @return Float object - */ - public Object getConstantValue(ConstantPool cp) { - return new Float(bytes); - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from the abstract + * Constant class + * and represents a reference to a float object. + * + * @version $Id: ConstantFloat.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Constant + */ +public final class ConstantFloat extends Constant implements ConstantObject { + private float bytes; + + /** + * @param bytes Data + */ + public ConstantFloat(float bytes) + { + super(Constants.CONSTANT_Float); + this.bytes = bytes; + } + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use clone() for a physical copy. + */ + public ConstantFloat(ConstantFloat c) { + this(c.getBytes()); + } + /** + * Initialize instance from file data. + * + * @param file Input stream + * @throws IOException + */ + ConstantFloat(DataInputStream file) throws IOException + { + this(file.readFloat()); + } + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitConstantFloat(this); + } + /** + * Dump constant float to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeByte(tag); + file.writeFloat(bytes); + } + /** + * @return data, i.e., 4 bytes. + */ + public final float getBytes() { return bytes; } + /** + * @param bytes. + */ + public final void setBytes(float bytes) { + this.bytes = bytes; + } + + /** + * @return String representation. + */ + public final String toString() { + return super.toString() + "(bytes = " + bytes + ")"; + } + + /** @return Float object + */ + public Object getConstantValue(ConstantPool cp) { + return new Float(bytes); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInteger.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInteger.java index 6b643f0c5..a08ce5f1d 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInteger.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInteger.java @@ -1,148 +1,148 @@ - -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from the abstract - * Constant class - * and represents a reference to an int object. - * - * @version $Id: ConstantInteger.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see Constant - */ -public final class ConstantInteger extends Constant implements ConstantObject { - private int bytes; - - /** - * @param bytes Data - */ - public ConstantInteger(int bytes) - { - super(Constants.CONSTANT_Integer); - this.bytes = bytes; - } - - /** - * Initialize from another object. - */ - public ConstantInteger(ConstantInteger c) { - this(c.getBytes()); - } - - /** - * Initialize instance from file data. - * - * @param file Input stream - * @throws IOException - */ - ConstantInteger(DataInputStream file) throws IOException - { - this(file.readInt()); - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitConstantInteger(this); - } - - /** - * Dump constant integer to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeByte(tag); - file.writeInt(bytes); - } - - /** - * @return data, i.e., 4 bytes. - */ - public final int getBytes() { return bytes; } - - /** - * @param bytes. - */ - public final void setBytes(int bytes) { - this.bytes = bytes; - } - - /** - * @return String representation. - */ - public final String toString() { - return super.toString() + "(bytes = " + bytes + ")"; - } - - /** @return Integer object - */ - public Object getConstantValue(ConstantPool cp) { - return new Integer(bytes); - } -} + +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from the abstract + * Constant class + * and represents a reference to an int object. + * + * @version $Id: ConstantInteger.java,v 1.2.10.2 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + * @see Constant + */ +public final class ConstantInteger extends Constant implements ConstantObject { + private int bytes; + + /** + * @param bytes Data + */ + public ConstantInteger(int bytes) + { + super(Constants.CONSTANT_Integer); + this.bytes = bytes; + } + + /** + * Initialize from another object. + */ + public ConstantInteger(ConstantInteger c) { + this(c.getBytes()); + } + + /** + * Initialize instance from file data. + * + * @param file Input stream + * @throws IOException + */ + ConstantInteger(DataInputStream file) throws IOException + { + this(file.readInt()); + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitConstantInteger(this); + } + + /** + * Dump constant integer to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeByte(tag); + file.writeInt(bytes); + } + + /** + * @return data, i.e., 4 bytes. + */ + public final int getBytes() { return bytes; } + + /** + * @param bytes. + */ + public final void setBytes(int bytes) { + this.bytes = bytes; + } + + /** + * @return String representation. + */ + public final String toString() { + return super.toString() + "(bytes = " + bytes + ")"; + } + + /** @return Integer object + */ + public Object getConstantValue(ConstantPool cp) { + return new Integer(bytes); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInterfaceMethodref.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInterfaceMethodref.java index 20099868e..9b2db96bf 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInterfaceMethodref.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInterfaceMethodref.java @@ -1,104 +1,104 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents a constant pool reference to an interface method. - * - * @version $Id: ConstantInterfaceMethodref.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - */ -public final class ConstantInterfaceMethodref extends ConstantCP { - /** - * Initialize from another object. - */ - public ConstantInterfaceMethodref(ConstantInterfaceMethodref c) { - super(Constants.CONSTANT_InterfaceMethodref, c.getClassIndex(), c.getNameAndTypeIndex()); - } - - /** - * Initialize instance from file data. - * - * @param file input stream - * @throws IOException - */ - ConstantInterfaceMethodref(DataInputStream file) throws IOException - { - super(Constants.CONSTANT_InterfaceMethodref, file); - } - - /** - * @param class_index Reference to the class containing the method - * @param name_and_type_index and the method signature - */ - public ConstantInterfaceMethodref(int class_index, - int name_and_type_index) { - super(Constants.CONSTANT_InterfaceMethodref, class_index, name_and_type_index); - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitConstantInterfaceMethodref(this); - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents a constant pool reference to an interface method. + * + * @version $Id: ConstantInterfaceMethodref.java,v 1.2.10.2 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + */ +public final class ConstantInterfaceMethodref extends ConstantCP { + /** + * Initialize from another object. + */ + public ConstantInterfaceMethodref(ConstantInterfaceMethodref c) { + super(Constants.CONSTANT_InterfaceMethodref, c.getClassIndex(), c.getNameAndTypeIndex()); + } + + /** + * Initialize instance from file data. + * + * @param file input stream + * @throws IOException + */ + ConstantInterfaceMethodref(DataInputStream file) throws IOException + { + super(Constants.CONSTANT_InterfaceMethodref, file); + } + + /** + * @param class_index Reference to the class containing the method + * @param name_and_type_index and the method signature + */ + public ConstantInterfaceMethodref(int class_index, + int name_and_type_index) { + super(Constants.CONSTANT_InterfaceMethodref, class_index, name_and_type_index); + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitConstantInterfaceMethodref(this); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantLong.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantLong.java index 334722d4e..76e9d899b 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantLong.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantLong.java @@ -1,139 +1,139 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from the abstract - * Constant class - * and represents a reference to a long object. - * - * @version $Id: ConstantLong.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see Constant - */ -public final class ConstantLong extends Constant implements ConstantObject { - private long bytes; - - /** - * @param bytes Data - */ - public ConstantLong(long bytes) - { - super(Constants.CONSTANT_Long); - this.bytes = bytes; - } - /** - * Initialize from another object. - */ - public ConstantLong(ConstantLong c) { - this(c.getBytes()); - } - /** - * Initialize instance from file data. - * - * @param file Input stream - * @throws IOException - */ - ConstantLong(DataInputStream file) throws IOException - { - this(file.readLong()); - } - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitConstantLong(this); - } - /** - * Dump constant long to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeByte(tag); - file.writeLong(bytes); - } - /** - * @return data, i.e., 8 bytes. - */ - public final long getBytes() { return bytes; } - /** - * @param bytes. - */ - public final void setBytes(long bytes) { - this.bytes = bytes; - } - /** - * @return String representation. - */ - public final String toString() { - return super.toString() + "(bytes = " + bytes + ")"; - } - - /** @return Long object - */ - public Object getConstantValue(ConstantPool cp) { - return new Long(bytes); - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from the abstract + * Constant class + * and represents a reference to a long object. + * + * @version $Id: ConstantLong.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Constant + */ +public final class ConstantLong extends Constant implements ConstantObject { + private long bytes; + + /** + * @param bytes Data + */ + public ConstantLong(long bytes) + { + super(Constants.CONSTANT_Long); + this.bytes = bytes; + } + /** + * Initialize from another object. + */ + public ConstantLong(ConstantLong c) { + this(c.getBytes()); + } + /** + * Initialize instance from file data. + * + * @param file Input stream + * @throws IOException + */ + ConstantLong(DataInputStream file) throws IOException + { + this(file.readLong()); + } + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitConstantLong(this); + } + /** + * Dump constant long to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeByte(tag); + file.writeLong(bytes); + } + /** + * @return data, i.e., 8 bytes. + */ + public final long getBytes() { return bytes; } + /** + * @param bytes. + */ + public final void setBytes(long bytes) { + this.bytes = bytes; + } + /** + * @return String representation. + */ + public final String toString() { + return super.toString() + "(bytes = " + bytes + ")"; + } + + /** @return Long object + */ + public Object getConstantValue(ConstantPool cp) { + return new Long(bytes); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodref.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodref.java index a1f018690..c829ee82a 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodref.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodref.java @@ -1,104 +1,104 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents a constant pool reference to a method. - * - * @version $Id: ConstantMethodref.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - */ -public final class ConstantMethodref extends ConstantCP { - /** - * Initialize from another object. - */ - public ConstantMethodref(ConstantMethodref c) { - super(Constants.CONSTANT_Methodref, c.getClassIndex(), c.getNameAndTypeIndex()); - } - - /** - * Initialize instance from file data. - * - * @param file input stream - * @throws IOException - */ - ConstantMethodref(DataInputStream file) throws IOException - { - super(Constants.CONSTANT_Methodref, file); - } - - /** - * @param class_index Reference to the class containing the method - * @param name_and_type_index and the method signature - */ - public ConstantMethodref(int class_index, - int name_and_type_index) { - super(Constants.CONSTANT_Methodref, class_index, name_and_type_index); - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitConstantMethodref(this); - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents a constant pool reference to a method. + * + * @version $Id: ConstantMethodref.java,v 1.2.10.2 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + */ +public final class ConstantMethodref extends ConstantCP { + /** + * Initialize from another object. + */ + public ConstantMethodref(ConstantMethodref c) { + super(Constants.CONSTANT_Methodref, c.getClassIndex(), c.getNameAndTypeIndex()); + } + + /** + * Initialize instance from file data. + * + * @param file input stream + * @throws IOException + */ + ConstantMethodref(DataInputStream file) throws IOException + { + super(Constants.CONSTANT_Methodref, file); + } + + /** + * @param class_index Reference to the class containing the method + * @param name_and_type_index and the method signature + */ + public ConstantMethodref(int class_index, + int name_and_type_index) { + super(Constants.CONSTANT_Methodref, class_index, name_and_type_index); + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitConstantMethodref(this); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantNameAndType.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantNameAndType.java index 6fe1fdba4..6fb1b7e00 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantNameAndType.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantNameAndType.java @@ -1,171 +1,171 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from the abstract - * Constant class - * and represents a reference to the name and signature - * of a field or method. - * - * @version $Id: ConstantNameAndType.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see Constant - */ -public final class ConstantNameAndType extends Constant { - private int name_index; // Name of field/method - private int signature_index; // and its signature. - - /** - * Initialize from another object. - */ - public ConstantNameAndType(ConstantNameAndType c) { - this(c.getNameIndex(), c.getSignatureIndex()); - } - - /** - * Initialize instance from file data. - * - * @param file Input stream - * @throws IOException - */ - ConstantNameAndType(DataInputStream file) throws IOException - { - this(file.readUnsignedShort(), file.readUnsignedShort()); - } - - /** - * @param name_index Name of field/method - * @param signature_index and its signature - */ - public ConstantNameAndType(int name_index, - int signature_index) - { - super(Constants.CONSTANT_NameAndType); - this.name_index = name_index; - this.signature_index = signature_index; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitConstantNameAndType(this); - } - - /** - * Dump name and signature index to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeByte(tag); - file.writeShort(name_index); - file.writeShort(signature_index); - } - - /** - * @return Name index in constant pool of field/method name. - */ - public final int getNameIndex() { return name_index; } - - /** @return name - */ - public final String getName(ConstantPool cp) { - return cp.constantToString(getNameIndex(), Constants.CONSTANT_Utf8); - } - - /** - * @return Index in constant pool of field/method signature. - */ - public final int getSignatureIndex() { return signature_index; } - - /** @return signature - */ - public final String getSignature(ConstantPool cp) { - return cp.constantToString(getSignatureIndex(), Constants.CONSTANT_Utf8); - } - - /** - * @param name_index. - */ - public final void setNameIndex(int name_index) { - this.name_index = name_index; - } - - /** - * @param signature_index. - */ - public final void setSignatureIndex(int signature_index) { - this.signature_index = signature_index; - } - - /** - * @return String representation - */ - public final String toString() { - return super.toString() + "(name_index = " + name_index + - ", signature_index = " + signature_index + ")"; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from the abstract + * Constant class + * and represents a reference to the name and signature + * of a field or method. + * + * @version $Id: ConstantNameAndType.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Constant + */ +public final class ConstantNameAndType extends Constant { + private int name_index; // Name of field/method + private int signature_index; // and its signature. + + /** + * Initialize from another object. + */ + public ConstantNameAndType(ConstantNameAndType c) { + this(c.getNameIndex(), c.getSignatureIndex()); + } + + /** + * Initialize instance from file data. + * + * @param file Input stream + * @throws IOException + */ + ConstantNameAndType(DataInputStream file) throws IOException + { + this(file.readUnsignedShort(), file.readUnsignedShort()); + } + + /** + * @param name_index Name of field/method + * @param signature_index and its signature + */ + public ConstantNameAndType(int name_index, + int signature_index) + { + super(Constants.CONSTANT_NameAndType); + this.name_index = name_index; + this.signature_index = signature_index; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitConstantNameAndType(this); + } + + /** + * Dump name and signature index to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeByte(tag); + file.writeShort(name_index); + file.writeShort(signature_index); + } + + /** + * @return Name index in constant pool of field/method name. + */ + public final int getNameIndex() { return name_index; } + + /** @return name + */ + public final String getName(ConstantPool cp) { + return cp.constantToString(getNameIndex(), Constants.CONSTANT_Utf8); + } + + /** + * @return Index in constant pool of field/method signature. + */ + public final int getSignatureIndex() { return signature_index; } + + /** @return signature + */ + public final String getSignature(ConstantPool cp) { + return cp.constantToString(getSignatureIndex(), Constants.CONSTANT_Utf8); + } + + /** + * @param name_index. + */ + public final void setNameIndex(int name_index) { + this.name_index = name_index; + } + + /** + * @param signature_index. + */ + public final void setSignatureIndex(int signature_index) { + this.signature_index = signature_index; + } + + /** + * @return String representation + */ + public final String toString() { + return super.toString() + "(name_index = " + name_index + + ", signature_index = " + signature_index + ")"; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantObject.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantObject.java index d5b50e0e8..acb5e9e1a 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantObject.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantObject.java @@ -1,69 +1,69 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * This interface denotes those constants that have a "natural" value, - * such as ConstantLong, ConstantString, etc.. - * - * @version $Id: ConstantObject.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see Constant - */ -public interface ConstantObject { - /** @return object representing the constant, e.g., Long for ConstantLong - */ - public abstract Object getConstantValue(ConstantPool cp); -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * This interface denotes those constants that have a "natural" value, + * such as ConstantLong, ConstantString, etc.. + * + * @version $Id: ConstantObject.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Constant + */ +public interface ConstantObject { + /** @return object representing the constant, e.g., Long for ConstantLong + */ + public abstract Object getConstantValue(ConstantPool cp); +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java index f1c206eff..7c31b213d 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java @@ -1,613 +1,612 @@ -package org.aspectj.apache.bcel.classfile; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.generic.*; - -import java.io.*; - -/** - * This class represents the constant pool, i.e., a table of constants, of - * a parsed classfile. It may contain null references, due to the JVM - * specification that skips an entry after an 8-byte constant (double, - * long) entry. Those interested in generating constant pools - * programatically should see - * ConstantPoolGen. - */ -public class ConstantPool implements Node { - private Constant[] pool; - private int poolSize; // number of entries in the pool (could be < pool.length as the array is resized in 'chunks') - - public int getSize() { return poolSize; } - - public ConstantPool() { - pool = new Constant[10]; - poolSize=0; - } - - public ConstantPool(Constant[] constants) { - pool = constants; - poolSize = (constants==null?0:constants.length); - } - - ConstantPool(DataInputStream file) throws IOException { - byte tag; - poolSize = file.readUnsignedShort(); - pool = new Constant[poolSize]; - // pool[0] is unused by the compiler and may be used freely by the implementation - for (int i=1; i= pool.length || index < 0) - throw new ClassFormatException("Invalid constant pool reference: " + - index + ". Constant pool size is: " + pool.length); - return pool[index]; - } - - /** - * @return deep copy of this constant pool - */ - public ConstantPool copy() { - ConstantPool c = null; - Constant[] newConstants = new Constant[poolSize]; // use the correct size - for (int i=1;i= pool.length) { - Constant[] cs = pool; - pool = new Constant[cs.length+8]; - System.arraycopy(cs, 0, pool, 0, cs.length); - } - if (poolSize==0) poolSize = 1; // someone about to do something in here! - } - - public int addFieldref(String class_name, String field_name, String signature) { - int ret = lookupFieldref(class_name, field_name, signature); - int class_index, name_and_type_index; - - if (ret != -1) return ret; - - adjustSize(); - - class_index = addClass(class_name); - name_and_type_index = addNameAndType(field_name, signature); - ret = poolSize; - pool[poolSize++] = new ConstantFieldref(class_index, name_and_type_index); - - return ret; - } - - public int lookupFieldref(String searchClassname, String searchFieldname, String searchSignature) { - searchClassname = searchClassname.replace('.','/'); - for (int i=1;i= pool.length || index < 0) + throw new ClassFormatException("Invalid constant pool reference: " + + index + ". Constant pool size is: " + pool.length); + return pool[index]; + } + + /** + * @return deep copy of this constant pool + */ + public ConstantPool copy() { + ConstantPool c = null; + Constant[] newConstants = new Constant[poolSize]; // use the correct size + for (int i=1;i= pool.length) { + Constant[] cs = pool; + pool = new Constant[cs.length+8]; + System.arraycopy(cs, 0, pool, 0, cs.length); + } + if (poolSize==0) poolSize = 1; // someone about to do something in here! + } + + public int addFieldref(String class_name, String field_name, String signature) { + int ret = lookupFieldref(class_name, field_name, signature); + int class_index, name_and_type_index; + + if (ret != -1) return ret; + + adjustSize(); + + class_index = addClass(class_name); + name_and_type_index = addNameAndType(field_name, signature); + ret = poolSize; + pool[poolSize++] = new ConstantFieldref(class_index, name_and_type_index); + + return ret; + } + + public int lookupFieldref(String searchClassname, String searchFieldname, String searchSignature) { + searchClassname = searchClassname.replace('.','/'); + for (int i=1;i. - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from the abstract - * Constant class - * and represents a reference to a String object. - * - * @version $Id: ConstantString.java,v 1.2.10.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see Constant - */ -public final class ConstantString extends Constant implements ConstantObject { - private int string_index; // Identical to ConstantClass except for this name - - /** - * Initialize from another object. - */ - public ConstantString(ConstantString c) { - this(c.getStringIndex()); - } - /** - * Initialize instance from file data. - * - * @param file Input stream - * @throws IOException - */ - ConstantString(DataInputStream file) throws IOException - { - this(file.readUnsignedShort()); - } - /** - * @param string_index Index of Constant_Utf8 in constant pool - */ - public ConstantString(int string_index) - { - super(Constants.CONSTANT_String); - this.string_index = string_index; - } - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitConstantString(this); - } - /** - * Dump constant field reference to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeByte(tag); - file.writeShort(string_index); - } - /** - * @return Index in constant pool of the string (ConstantUtf8). - */ - public final int getStringIndex() { return string_index; } - /** - * @param string_index. - */ - public final void setStringIndex(int string_index) { - this.string_index = string_index; - } - /** - * @return String representation. - */ - public final String toString() - { - return super.toString() + "(string_index = " + string_index + ")"; - } - - /** @return String object - */ - public Object getConstantValue(ConstantPool cp) { - Constant c = cp.getConstant(string_index, Constants.CONSTANT_Utf8); - return ((ConstantUtf8)c).getBytes(); - } - - /** @return dereferenced string - */ - public String getBytes(ConstantPool cp) { - return (String)getConstantValue(cp); - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from the abstract + * Constant class + * and represents a reference to a String object. + * + * @version $Id: ConstantString.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Constant + */ +public final class ConstantString extends Constant implements ConstantObject { + private int string_index; // Identical to ConstantClass except for this name + + /** + * Initialize from another object. + */ + public ConstantString(ConstantString c) { + this(c.getStringIndex()); + } + /** + * Initialize instance from file data. + * + * @param file Input stream + * @throws IOException + */ + ConstantString(DataInputStream file) throws IOException + { + this(file.readUnsignedShort()); + } + /** + * @param string_index Index of Constant_Utf8 in constant pool + */ + public ConstantString(int string_index) + { + super(Constants.CONSTANT_String); + this.string_index = string_index; + } + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitConstantString(this); + } + /** + * Dump constant field reference to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeByte(tag); + file.writeShort(string_index); + } + /** + * @return Index in constant pool of the string (ConstantUtf8). + */ + public final int getStringIndex() { return string_index; } + /** + * @param string_index. + */ + public final void setStringIndex(int string_index) { + this.string_index = string_index; + } + /** + * @return String representation. + */ + public final String toString() + { + return super.toString() + "(string_index = " + string_index + ")"; + } + + /** @return String object + */ + public Object getConstantValue(ConstantPool cp) { + Constant c = cp.getConstant(string_index, Constants.CONSTANT_Utf8); + return ((ConstantUtf8)c).getBytes(); + } + + /** @return dereferenced string + */ + public String getBytes(ConstantPool cp) { + return (String)getConstantValue(cp); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantUtf8.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantUtf8.java index e2c4b6445..69134ad0e 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantUtf8.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantUtf8.java @@ -1,144 +1,144 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from the abstract - * Constant class - * and represents a reference to a Utf8 encoded string. - * - * @version $Id: ConstantUtf8.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see Constant - */ -public final class ConstantUtf8 extends Constant { - private String bytes; - - /** - * Initialize from another object. - */ - public ConstantUtf8(ConstantUtf8 c) { - this(c.getBytes()); - } - - /** - * Initialize instance from file data. - * - * @param file Input stream - * @throws IOException - */ - ConstantUtf8(DataInputStream file) throws IOException - { - super(Constants.CONSTANT_Utf8); - bytes=file.readUTF(); - } - - public ConstantUtf8(String bytes) - { - super(Constants.CONSTANT_Utf8); - - if(bytes == null) - throw new IllegalArgumentException("bytes must not be null!"); - this.bytes = bytes; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitConstantUtf8(this); - } - - /** - * Dump String in Utf8 format to file stream. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeByte(tag); - file.writeUTF(bytes); - } - - /** - * @return Data converted to string. - */ - public final String getBytes() { - return bytes; - } - - /** - * @param bytes. - */ - public final void setBytes(String bytes) { - this.bytes = bytes; - } - - /** - * @return String representation - */ - public final String toString() - { - return super.toString() + "(\"" + Utility.replace(bytes, "\n", "\\n") + "\")"; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from the abstract + * Constant class + * and represents a reference to a Utf8 encoded string. + * + * @version $Id: ConstantUtf8.java,v 1.2.10.3 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + * @see Constant + */ +public final class ConstantUtf8 extends Constant { + private String bytes; + + /** + * Initialize from another object. + */ + public ConstantUtf8(ConstantUtf8 c) { + this(c.getBytes()); + } + + /** + * Initialize instance from file data. + * + * @param file Input stream + * @throws IOException + */ + ConstantUtf8(DataInputStream file) throws IOException + { + super(Constants.CONSTANT_Utf8); + bytes=file.readUTF(); + } + + public ConstantUtf8(String bytes) + { + super(Constants.CONSTANT_Utf8); + + if(bytes == null) + throw new IllegalArgumentException("bytes must not be null!"); + this.bytes = bytes; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitConstantUtf8(this); + } + + /** + * Dump String in Utf8 format to file stream. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeByte(tag); + file.writeUTF(bytes); + } + + /** + * @return Data converted to string. + */ + public final String getBytes() { + return bytes; + } + + /** + * @param bytes. + */ + public final void setBytes(String bytes) { + this.bytes = bytes; + } + + /** + * @return String representation + */ + public final String toString() + { + return super.toString() + "(\"" + Utility.replace(bytes, "\n", "\\n") + "\")"; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantValue.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantValue.java index a44718599..d7bfdb097 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantValue.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantValue.java @@ -1,178 +1,178 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from Attribute and represents a constant - * value, i.e., a default value for initializing a class field. - * This class is instantiated by the Attribute.readAttribute() method. - * - * @version $Id: ConstantValue.java,v 1.2.10.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see Attribute - */ -public final class ConstantValue extends Attribute { - private int constantvalue_index; - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use clone() for a physical copy. - */ - public ConstantValue(ConstantValue c) { - this(c.getNameIndex(), c.getLength(), c.getConstantValueIndex(), - c.getConstantPool()); - } - - /** - * Construct object from file stream. - * @param name_index Name index in constant pool - * @param length Content length in bytes - * @param file Input stream - * @param constant_pool Array of constants - * @throw IOException - */ - ConstantValue(int name_index, int length, DataInputStream file, - ConstantPool constant_pool) throws IOException - { - this(name_index, length, file.readUnsignedShort(), constant_pool); - } - - /** - * @param name_index Name index in constant pool - * @param length Content length in bytes - * @param constantvalue_index Index in constant pool - * @param constant_pool Array of constants - */ - public ConstantValue(int name_index, int length, - int constantvalue_index, - ConstantPool constant_pool) - { - super(Constants.ATTR_CONSTANT_VALUE, name_index, length, constant_pool); - this.constantvalue_index = constantvalue_index; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitConstantValue(this); - } - /** - * Dump constant value attribute to file stream on binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - file.writeShort(constantvalue_index); - } - /** - * @return Index in constant pool of constant value. - */ - public final int getConstantValueIndex() { return constantvalue_index; } - - /** - * @param constantvalue_index. - */ - public final void setConstantValueIndex(int constantvalue_index) { - this.constantvalue_index = constantvalue_index; - } - - /** - * @return String representation of constant value. - */ - public final String toString() { - Constant c = constantPool.getConstant(constantvalue_index); - - String buf; - int i; - - // Print constant to string depending on its type - switch(c.getTag()) { - case Constants.CONSTANT_Long: buf = "" + ((ConstantLong)c).getBytes(); break; - case Constants.CONSTANT_Float: buf = "" + ((ConstantFloat)c).getBytes(); break; - case Constants.CONSTANT_Double: buf = "" + ((ConstantDouble)c).getBytes(); break; - case Constants.CONSTANT_Integer: buf = "" + ((ConstantInteger)c).getBytes(); break; - case Constants.CONSTANT_String: - i = ((ConstantString)c).getStringIndex(); - c = constantPool.getConstant(i, Constants.CONSTANT_Utf8); - buf = "\"" + Utility.convertString(((ConstantUtf8)c).getBytes()) + "\""; - break; - - default: - throw new IllegalStateException("Type of ConstValue invalid: " + c); - } - - return buf; - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - ConstantValue c = (ConstantValue)clone(); - c.constantPool = constant_pool; - return c; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from Attribute and represents a constant + * value, i.e., a default value for initializing a class field. + * This class is instantiated by the Attribute.readAttribute() method. + * + * @version $Id: ConstantValue.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Attribute + */ +public final class ConstantValue extends Attribute { + private int constantvalue_index; + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use clone() for a physical copy. + */ + public ConstantValue(ConstantValue c) { + this(c.getNameIndex(), c.getLength(), c.getConstantValueIndex(), + c.getConstantPool()); + } + + /** + * Construct object from file stream. + * @param name_index Name index in constant pool + * @param length Content length in bytes + * @param file Input stream + * @param constant_pool Array of constants + * @throw IOException + */ + ConstantValue(int name_index, int length, DataInputStream file, + ConstantPool constant_pool) throws IOException + { + this(name_index, length, file.readUnsignedShort(), constant_pool); + } + + /** + * @param name_index Name index in constant pool + * @param length Content length in bytes + * @param constantvalue_index Index in constant pool + * @param constant_pool Array of constants + */ + public ConstantValue(int name_index, int length, + int constantvalue_index, + ConstantPool constant_pool) + { + super(Constants.ATTR_CONSTANT_VALUE, name_index, length, constant_pool); + this.constantvalue_index = constantvalue_index; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitConstantValue(this); + } + /** + * Dump constant value attribute to file stream on binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + file.writeShort(constantvalue_index); + } + /** + * @return Index in constant pool of constant value. + */ + public final int getConstantValueIndex() { return constantvalue_index; } + + /** + * @param constantvalue_index. + */ + public final void setConstantValueIndex(int constantvalue_index) { + this.constantvalue_index = constantvalue_index; + } + + /** + * @return String representation of constant value. + */ + public final String toString() { + Constant c = constantPool.getConstant(constantvalue_index); + + String buf; + int i; + + // Print constant to string depending on its type + switch(c.getTag()) { + case Constants.CONSTANT_Long: buf = "" + ((ConstantLong)c).getBytes(); break; + case Constants.CONSTANT_Float: buf = "" + ((ConstantFloat)c).getBytes(); break; + case Constants.CONSTANT_Double: buf = "" + ((ConstantDouble)c).getBytes(); break; + case Constants.CONSTANT_Integer: buf = "" + ((ConstantInteger)c).getBytes(); break; + case Constants.CONSTANT_String: + i = ((ConstantString)c).getStringIndex(); + c = constantPool.getConstant(i, Constants.CONSTANT_Utf8); + buf = "\"" + Utility.convertString(((ConstantUtf8)c).getBytes()) + "\""; + break; + + default: + throw new IllegalStateException("Type of ConstValue invalid: " + c); + } + + return buf; + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + ConstantValue c = (ConstantValue)clone(); + c.constantPool = constant_pool; + return c; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Deprecated.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Deprecated.java index 90c086a92..4096c688b 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Deprecated.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Deprecated.java @@ -1,169 +1,169 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from Attribute and denotes that this is a - * deprecated method. - * It is instantiated from the Attribute.readAttribute() method. - * - * @version $Id: Deprecated.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see Attribute - */ -public final class Deprecated extends Attribute { - private byte[] bytes; - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use clone() for a physical copy. - */ - public Deprecated(Deprecated c) { - this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool()); - } - - /** - * @param name_index Index in constant pool to CONSTANT_Utf8 - * @param length Content length in bytes - * @param bytes Attribute contents - * @param constant_pool Array of constants - */ - public Deprecated(int name_index, int length, byte[] bytes, - ConstantPool constant_pool) - { - super(Constants.ATTR_DEPRECATED, name_index, length, constant_pool); - this.bytes = bytes; - } - - /** - * Construct object from file stream. - * @param name_index Index in constant pool to CONSTANT_Utf8 - * @param length Content length in bytes - * @param file Input stream - * @param constant_pool Array of constants - * @throws IOException - */ - Deprecated(int name_index, int length, DataInputStream file, - ConstantPool constant_pool) throws IOException - { - this(name_index, length, (byte [])null, constant_pool); - - if(length > 0) { - bytes = new byte[length]; - file.readFully(bytes); - System.err.println("Deprecated attribute with length > 0"); - } - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitDeprecated(this); - } - - /** - * Dump source file attribute to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - - if(length > 0) - file.write(bytes, 0, length); - } - - /** - * @return data bytes. - */ - public final byte[] getBytes() { return bytes; } - - /** - * @param bytes. - */ - public final void setBytes(byte[] bytes) { - this.bytes = bytes; - } - - /** - * @return attribute name - */ - public final String toString() { - return Constants.ATTRIBUTE_NAMES[Constants.ATTR_DEPRECATED]; - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - Deprecated c = (Deprecated)clone(); - - if(bytes != null) - c.bytes = (byte[])bytes.clone(); - - c.constantPool = constant_pool; - return c; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from Attribute and denotes that this is a + * deprecated method. + * It is instantiated from the Attribute.readAttribute() method. + * + * @version $Id: Deprecated.java,v 1.2.10.3 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + * @see Attribute + */ +public final class Deprecated extends Attribute { + private byte[] bytes; + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use clone() for a physical copy. + */ + public Deprecated(Deprecated c) { + this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool()); + } + + /** + * @param name_index Index in constant pool to CONSTANT_Utf8 + * @param length Content length in bytes + * @param bytes Attribute contents + * @param constant_pool Array of constants + */ + public Deprecated(int name_index, int length, byte[] bytes, + ConstantPool constant_pool) + { + super(Constants.ATTR_DEPRECATED, name_index, length, constant_pool); + this.bytes = bytes; + } + + /** + * Construct object from file stream. + * @param name_index Index in constant pool to CONSTANT_Utf8 + * @param length Content length in bytes + * @param file Input stream + * @param constant_pool Array of constants + * @throws IOException + */ + Deprecated(int name_index, int length, DataInputStream file, + ConstantPool constant_pool) throws IOException + { + this(name_index, length, (byte [])null, constant_pool); + + if(length > 0) { + bytes = new byte[length]; + file.readFully(bytes); + System.err.println("Deprecated attribute with length > 0"); + } + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitDeprecated(this); + } + + /** + * Dump source file attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + + if(length > 0) + file.write(bytes, 0, length); + } + + /** + * @return data bytes. + */ + public final byte[] getBytes() { return bytes; } + + /** + * @param bytes. + */ + public final void setBytes(byte[] bytes) { + this.bytes = bytes; + } + + /** + * @return attribute name + */ + public final String toString() { + return Constants.ATTRIBUTE_NAMES[Constants.ATTR_DEPRECATED]; + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + Deprecated c = (Deprecated)clone(); + + if(bytes != null) + c.bytes = (byte[])bytes.clone(); + + c.constantPool = constant_pool; + return c; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/EnclosingMethod.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/EnclosingMethod.java index af6495a3a..6b01d23e5 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/EnclosingMethod.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/EnclosingMethod.java @@ -1,87 +1,87 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * ******************************************************************/ -package org.aspectj.apache.bcel.classfile; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.Constants; - -/** - * This attribute exists for local or - * anonymous classes and ... there can be only one. - */ -public class EnclosingMethod extends Attribute { - - // Pointer to the CONSTANT_Class_info structure representing the - // innermost class that encloses the declaration of the current class. - private int classIndex; - - // If the current class is not immediately enclosed by a method or - // constructor, then the value of the method_index item must be zero. - // Otherwise, the value of the method_index item must point to a - // CONSTANT_NameAndType_info structure representing the name and the - // type of a method in the class referenced by the class we point - // to in the class_index. *It is the compiler responsibility* to - // ensure that the method identified by this index is the closest - // lexically enclosing method that includes the local/anonymous class. - private int methodIndex; - - // Ctors - and code to read an attribute in. - public EnclosingMethod(int nameIndex, int len, DataInputStream dis, ConstantPool cpool) throws IOException { - this(nameIndex, len, dis.readUnsignedShort(), dis.readUnsignedShort(), cpool); - } - - private EnclosingMethod(int nameIndex, int len, int classIdx,int methodIdx, ConstantPool cpool) { - super(Constants.ATTR_ENCLOSING_METHOD, nameIndex, len, cpool); - classIndex = classIdx; - methodIndex = methodIdx; - } - - public void accept(Visitor v) { - v.visitEnclosingMethod(this); - } - - public Attribute copy(ConstantPool constant_pool) { - throw new RuntimeException("Not implemented yet!"); - // is this next line sufficient? - // return (EnclosingMethod)clone(); - } - - // Accessors - public final int getEnclosingClassIndex() { return classIndex; } - public final int getEnclosingMethodIndex(){ return methodIndex;} - - public final void setEnclosingClassIndex(int idx) {classIndex = idx;} - public final void setEnclosingMethodIndex(int idx){methodIndex= idx;} - - public final ConstantClass getEnclosingClass() { - ConstantClass c = - (ConstantClass)constantPool.getConstant(classIndex,Constants.CONSTANT_Class); - return c; - } - - public final ConstantNameAndType getEnclosingMethod() { - if (methodIndex == 0) return null; - ConstantNameAndType nat = - (ConstantNameAndType)constantPool.getConstant(methodIndex,Constants.CONSTANT_NameAndType); - return nat; - } - - public final void dump(DataOutputStream file) throws IOException { - super.dump(file); - file.writeShort(classIndex); - file.writeShort(methodIndex); - } -} +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * ******************************************************************/ +package org.aspectj.apache.bcel.classfile; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import org.aspectj.apache.bcel.Constants; + +/** + * This attribute exists for local or + * anonymous classes and ... there can be only one. + */ +public class EnclosingMethod extends Attribute { + + // Pointer to the CONSTANT_Class_info structure representing the + // innermost class that encloses the declaration of the current class. + private int classIndex; + + // If the current class is not immediately enclosed by a method or + // constructor, then the value of the method_index item must be zero. + // Otherwise, the value of the method_index item must point to a + // CONSTANT_NameAndType_info structure representing the name and the + // type of a method in the class referenced by the class we point + // to in the class_index. *It is the compiler responsibility* to + // ensure that the method identified by this index is the closest + // lexically enclosing method that includes the local/anonymous class. + private int methodIndex; + + // Ctors - and code to read an attribute in. + public EnclosingMethod(int nameIndex, int len, DataInputStream dis, ConstantPool cpool) throws IOException { + this(nameIndex, len, dis.readUnsignedShort(), dis.readUnsignedShort(), cpool); + } + + private EnclosingMethod(int nameIndex, int len, int classIdx,int methodIdx, ConstantPool cpool) { + super(Constants.ATTR_ENCLOSING_METHOD, nameIndex, len, cpool); + classIndex = classIdx; + methodIndex = methodIdx; + } + + public void accept(ClassVisitor v) { + v.visitEnclosingMethod(this); + } + + public Attribute copy(ConstantPool constant_pool) { + throw new RuntimeException("Not implemented yet!"); + // is this next line sufficient? + // return (EnclosingMethod)clone(); + } + + // Accessors + public final int getEnclosingClassIndex() { return classIndex; } + public final int getEnclosingMethodIndex(){ return methodIndex;} + + public final void setEnclosingClassIndex(int idx) {classIndex = idx;} + public final void setEnclosingMethodIndex(int idx){methodIndex= idx;} + + public final ConstantClass getEnclosingClass() { + ConstantClass c = + (ConstantClass)constantPool.getConstant(classIndex,Constants.CONSTANT_Class); + return c; + } + + public final ConstantNameAndType getEnclosingMethod() { + if (methodIndex == 0) return null; + ConstantNameAndType nat = + (ConstantNameAndType)constantPool.getConstant(methodIndex,Constants.CONSTANT_NameAndType); + return nat; + } + + public final void dump(DataOutputStream file) throws IOException { + super.dump(file); + file.writeShort(classIndex); + file.writeShort(methodIndex); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ExceptionTable.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ExceptionTable.java index b9f6e216b..85b6d77b1 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ExceptionTable.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ExceptionTable.java @@ -1,202 +1,202 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents the table of exceptions that are thrown by a - * method. This attribute may be used once per method. The name of - * this class is ExceptionTable for historical reasons; The - * Java Virtual Machine Specification, Second Edition defines this - * attribute using the name Exceptions (which is inconsistent - * with the other classes). - * - * @version $Id: ExceptionTable.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see Code - */ -public final class ExceptionTable extends Attribute { - private int number_of_exceptions; // Table of indices into - private int[] exception_index_table; // constant pool - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use copy() for a physical copy. - */ - public ExceptionTable(ExceptionTable c) { - this(c.getNameIndex(), c.getLength(), c.getExceptionIndexTable(), - c.getConstantPool()); - } - - /** - * @param name_index Index in constant pool - * @param length Content length in bytes - * @param exception_index_table Table of indices in constant pool - * @param constant_pool Array of constants - */ - public ExceptionTable(int name_index, int length, - int[] exception_index_table, - ConstantPool constant_pool) - { - super(Constants.ATTR_EXCEPTIONS, name_index, length, constant_pool); - setExceptionIndexTable(exception_index_table); - } - - /** - * Construct object from file stream. - * @param name_index Index in constant pool - * @param length Content length in bytes - * @param file Input stream - * @param constant_pool Array of constants - * @throws IOException - */ - ExceptionTable(int name_index, int length, DataInputStream file, - ConstantPool constant_pool) throws IOException - { - this(name_index, length, (int[])null, constant_pool); - - number_of_exceptions = file.readUnsignedShort(); - exception_index_table = new int[number_of_exceptions]; - - for(int i=0; i < number_of_exceptions; i++) - exception_index_table[i] = file.readUnsignedShort(); - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionTable(this); - } - - /** - * Dump exceptions attribute to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - file.writeShort(number_of_exceptions); - for(int i=0; i < number_of_exceptions; i++) - file.writeShort(exception_index_table[i]); - } - - /** - * @return Array of indices into constant pool of thrown exceptions. - */ - public final int[] getExceptionIndexTable() {return exception_index_table;} - /** - * @return Length of exception table. - */ - public final int getNumberOfExceptions() { return number_of_exceptions; } - - /** - * @return class names of thrown exceptions - */ - public final String[] getExceptionNames() { - String[] names = new String[number_of_exceptions]; - for(int i=0; i < number_of_exceptions; i++) - names[i] = constantPool.getConstantString(exception_index_table[i], - Constants.CONSTANT_Class). - replace('/', '.'); - return names; - } - - /** - * @param exception_index_table. - * Also redefines number_of_exceptions according to table length. - */ - public final void setExceptionIndexTable(int[] exception_index_table) { - this.exception_index_table = exception_index_table; - number_of_exceptions = (exception_index_table == null)? 0 : - exception_index_table.length; - } - /** - * @return String representation, i.e., a list of thrown exceptions. - */ - public final String toString() { - StringBuffer buf = new StringBuffer(""); - String str; - - for(int i=0; i < number_of_exceptions; i++) { - str = constantPool.getConstantString(exception_index_table[i], - Constants.CONSTANT_Class); - buf.append(Utility.compactClassName(str, false)); - - if(i < number_of_exceptions - 1) - buf.append(", "); - } - - return buf.toString(); - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - ExceptionTable c = (ExceptionTable)clone(); - c.exception_index_table = (int[])exception_index_table.clone(); - c.constantPool = constant_pool; - return c; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents the table of exceptions that are thrown by a + * method. This attribute may be used once per method. The name of + * this class is ExceptionTable for historical reasons; The + * Java Virtual Machine Specification, Second Edition defines this + * attribute using the name Exceptions (which is inconsistent + * with the other classes). + * + * @version $Id: ExceptionTable.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Code + */ +public final class ExceptionTable extends Attribute { + private int number_of_exceptions; // Table of indices into + private int[] exception_index_table; // constant pool + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use copy() for a physical copy. + */ + public ExceptionTable(ExceptionTable c) { + this(c.getNameIndex(), c.getLength(), c.getExceptionIndexTable(), + c.getConstantPool()); + } + + /** + * @param name_index Index in constant pool + * @param length Content length in bytes + * @param exception_index_table Table of indices in constant pool + * @param constant_pool Array of constants + */ + public ExceptionTable(int name_index, int length, + int[] exception_index_table, + ConstantPool constant_pool) + { + super(Constants.ATTR_EXCEPTIONS, name_index, length, constant_pool); + setExceptionIndexTable(exception_index_table); + } + + /** + * Construct object from file stream. + * @param name_index Index in constant pool + * @param length Content length in bytes + * @param file Input stream + * @param constant_pool Array of constants + * @throws IOException + */ + ExceptionTable(int name_index, int length, DataInputStream file, + ConstantPool constant_pool) throws IOException + { + this(name_index, length, (int[])null, constant_pool); + + number_of_exceptions = file.readUnsignedShort(); + exception_index_table = new int[number_of_exceptions]; + + for(int i=0; i < number_of_exceptions; i++) + exception_index_table[i] = file.readUnsignedShort(); + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitExceptionTable(this); + } + + /** + * Dump exceptions attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + file.writeShort(number_of_exceptions); + for(int i=0; i < number_of_exceptions; i++) + file.writeShort(exception_index_table[i]); + } + + /** + * @return Array of indices into constant pool of thrown exceptions. + */ + public final int[] getExceptionIndexTable() {return exception_index_table;} + /** + * @return Length of exception table. + */ + public final int getNumberOfExceptions() { return number_of_exceptions; } + + /** + * @return class names of thrown exceptions + */ + public final String[] getExceptionNames() { + String[] names = new String[number_of_exceptions]; + for(int i=0; i < number_of_exceptions; i++) + names[i] = constantPool.getConstantString(exception_index_table[i], + Constants.CONSTANT_Class). + replace('/', '.'); + return names; + } + + /** + * @param exception_index_table. + * Also redefines number_of_exceptions according to table length. + */ + public final void setExceptionIndexTable(int[] exception_index_table) { + this.exception_index_table = exception_index_table; + number_of_exceptions = (exception_index_table == null)? 0 : + exception_index_table.length; + } + /** + * @return String representation, i.e., a list of thrown exceptions. + */ + public final String toString() { + StringBuffer buf = new StringBuffer(""); + String str; + + for(int i=0; i < number_of_exceptions; i++) { + str = constantPool.getConstantString(exception_index_table[i], + Constants.CONSTANT_Class); + buf.append(Utility.compactClassName(str, false)); + + if(i < number_of_exceptions - 1) + buf.append(", "); + } + + return buf.toString(); + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + ExceptionTable c = (ExceptionTable)clone(); + c.exception_index_table = (int[])exception_index_table.clone(); + c.constantPool = constant_pool; + return c; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Field.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Field.java index c8359acc2..88cce5a88 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Field.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Field.java @@ -1,143 +1,144 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.DataInputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.generic.Type; - -/** - * This class represents the field info structure, i.e., the representation - * for a variable in the class. See JVM specification for details. - * - * @version $Id: Field.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - */ -public final class Field extends FieldOrMethod { - - public static final Field[] NoFields = new Field[0]; - - private Type fieldType = null; // lazily initialized - - private Field() {} - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use clone() for a physical copy. - */ - public Field(Field c) { - super(c); - } - - Field(DataInputStream file, ConstantPool constant_pool) throws IOException { - super(file, constant_pool); - } - - public Field(int accessflags, int nameIndex, int signatureIndex,Attribute[] attributes, ConstantPool constant_pool) { - super(accessflags, nameIndex, signatureIndex, attributes, constant_pool); - } - - public void accept(Visitor v) { - v.visitField(this); - } - - /** - * @return constant value associated with this field (may be null) - */ - public final ConstantValue getConstantValue() { - return AttributeUtils.getConstantValueAttribute(attributes); - } - - /** - * Return string representation close to declaration format, eg: - * 'public static final short MAX = 100' - */ - public final String toString() { - String name, signature, access; // Short cuts to constant pool - - // Get names from constant pool - access = Utility.accessToString(accessflags); - access = access.equals("")? "" : (access + " "); - signature = Utility.signatureToString(getSignature()); - name = getName(); - - StringBuffer buf = new StringBuffer(access); - buf.append(signature).append(" ").append(name); - ConstantValue cv = getConstantValue(); - - if (cv != null) buf.append(" = ").append(cv); - - // append all attributes that are *not* "ConstantValue" - for(int i=0; i < attributes.length; i++) { - Attribute a = attributes[i]; - if(!(a instanceof ConstantValue)) buf.append(" [").append(a.toString()).append("]"); - } - - return buf.toString(); - } - - /** deep copy of this field */ - public final Field copy(ConstantPool constant_pool) { - return (Field)copy_(constant_pool); - } - - /** return the type of the field */ - public Type getType() { - if (fieldType==null) { - fieldType = Type.getReturnType(getSignature()); - } - return fieldType; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.io.DataInputStream; +import java.io.IOException; +import java.util.List; + +import org.aspectj.apache.bcel.generic.Type; + +/** + * This class represents the field info structure, i.e., the representation + * for a variable in the class. See JVM specification for details. + * + * @version $Id: Field.java,v 1.2.10.3 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + */ +public final class Field extends FieldOrMethod { + + public static final Field[] NoFields = new Field[0]; + + private Type fieldType = null; // lazily initialized + + private Field() {} + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use clone() for a physical copy. + */ + public Field(Field c) { + super(c); + } + + Field(DataInputStream file, ConstantPool constant_pool) throws IOException { + super(file, constant_pool); + } + + public Field(int accessflags, int nameIndex, int signatureIndex,Attribute[] attributes, ConstantPool constant_pool) { + super(accessflags, nameIndex, signatureIndex, attributes, constant_pool); + } + + public void accept(ClassVisitor v) { + v.visitField(this); + } + + /** + * @return constant value associated with this field (may be null) + */ + public final ConstantValue getConstantValue() { + return AttributeUtils.getConstantValueAttribute(attributes); + } + + /** + * Return string representation close to declaration format, eg: + * 'public static final short MAX = 100' + */ + public final String toString() { + String name, signature, access; // Short cuts to constant pool + + // Get names from constant pool + access = Utility.accessToString(modifiers); + access = access.equals("")? "" : (access + " "); + signature = Utility.signatureToString(getSignature()); + name = getName(); + + StringBuffer buf = new StringBuffer(access); + buf.append(signature).append(" ").append(name); + ConstantValue cv = getConstantValue(); + + if (cv != null) buf.append(" = ").append(cv); + + // append all attributes that are *not* "ConstantValue" + for(int i=0; i < attributes.length; i++) { + Attribute a = attributes[i]; + if(!(a instanceof ConstantValue)) buf.append(" [").append(a.toString()).append("]"); + } + + return buf.toString(); + } + + /** deep copy of this field */ + public final Field copy(ConstantPool constant_pool) { + return (Field)copy_(constant_pool); + } + + /** return the type of the field */ + public Type getType() { + if (fieldType==null) { + fieldType = Type.getReturnType(getSignature()); + } + return fieldType; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/FieldOrMethod.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/FieldOrMethod.java index 8c1e0003a..31fc6dc6b 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/FieldOrMethod.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/FieldOrMethod.java @@ -1,209 +1,209 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations; - -import java.io.*; -import java.util.ArrayList; -import java.util.List; - -/** - * Abstract super class for fields and methods. - * - * @version $Id: FieldOrMethod.java,v 1.5.8.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - */ -public abstract class FieldOrMethod extends AccessFlags implements Cloneable, Node { - protected int nameIndex; - protected int signatureIndex; - protected Attribute[] attributes; - protected int attributes_count;// No. of attributes - - protected ConstantPool cpool; - private String name; // lazily initialized - private String signature; // lazily initialized - private AnnotationGen[] annotations; // lazily initialized - private String signatureAttributeString = null; - private boolean searchedForSignatureAttribute = false; - - - - protected FieldOrMethod() {} - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use clone() for a physical copy. - */ - protected FieldOrMethod(FieldOrMethod c) { - this(c.getAccessFlags(), c.getNameIndex(), c.getSignatureIndex(),c.getAttributes(), c.getConstantPool()); - } - - protected FieldOrMethod(DataInputStream file, ConstantPool cpool) throws IOException { - this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), null, cpool); - attributes = AttributeUtils.readAttributes(file,cpool); - } - - protected FieldOrMethod(int accessFlags, int nameIndex, int signatureIndex, Attribute[] attributes, ConstantPool cpool) { - this.accessflags = accessFlags; - this.nameIndex = nameIndex; - this.signatureIndex = signatureIndex; - this.cpool = cpool; - this.attributes = attributes; - } - - - /** - * @param attributes Collection of object attributes. - */ - public void setAttributes(Attribute[] attributes) { - this.attributes = attributes; - attributes_count = (attributes == null)? 0 : attributes.length; - } - - - - public final void dump(DataOutputStream file) throws IOException { - file.writeShort(accessflags); - file.writeShort(nameIndex); - file.writeShort(signatureIndex); - AttributeUtils.writeAttributes(attributes,file); - } - - public final Attribute[] getAttributes() { return attributes; } - public final ConstantPool getConstantPool() { return cpool; } - public final int getNameIndex() { return nameIndex; } - public final int getSignatureIndex() { return signatureIndex; } - - public final String getName() { - if (name==null) { - ConstantUtf8 c = (ConstantUtf8)cpool.getConstant(nameIndex,Constants.CONSTANT_Utf8); - name = c.getBytes(); - } - return name; - } - - public final String getSignature() { - if (signature==null) { - ConstantUtf8 c = (ConstantUtf8)cpool.getConstant(signatureIndex,Constants.CONSTANT_Utf8); - signature = c.getBytes(); - } - return signature; - } - - /** - * This will return the contents of a signature attribute attached to a member, or if there - * is none it will return the same as 'getSignature()'. Signature attributes are attached - * to members that were declared generic. - */ - public final String getDeclaredSignature() { - if (getGenericSignature()!=null) return getGenericSignature(); - return getSignature(); - } - - /** - * @return deep copy of this field - */ - protected FieldOrMethod copy_(ConstantPool constant_pool) { - FieldOrMethod c = null; - - try { - c = (FieldOrMethod)clone(); - } catch(CloneNotSupportedException e) {} - - c.cpool = constant_pool; - c.attributes = AttributeUtils.copy(attributes,constant_pool); - return c; - } - - public AnnotationGen[] getAnnotations() { - // Ensure we have unpacked any attributes that contain annotations. - // We don't remove these annotation attributes from the attributes list, they - // remain there. - if (annotations==null) { - // Find attributes that contain annotation data - List accumulatedAnnotations = new ArrayList(); - for (int i = 0; i < attributes.length; i++) { - Attribute attribute = attributes[i]; - if (attribute instanceof RuntimeAnnotations) { - RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations)attribute; - accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations()); - } - } - if (accumulatedAnnotations.size()==0) { - annotations = AnnotationGen.NO_ANNOTATIONS; - } else { - annotations = (AnnotationGen[])accumulatedAnnotations.toArray(new AnnotationGen[]{}); - } - } - return annotations; - } - - /** - * Hunts for a signature attribute on the member and returns its contents. So where the 'regular' signature - * may be (Ljava/util/Vector;)V the signature attribute may in fact say 'Ljava/lang/Vector;' - * Coded for performance - searches for the attribute only when requested - only searches for it once. - */ - public final String getGenericSignature() { - if (!searchedForSignatureAttribute) { - Signature sig = AttributeUtils.getSignatureAttribute(attributes); - signatureAttributeString = (sig==null?null:sig.getSignature()); - searchedForSignatureAttribute=true; - } - return signatureAttributeString; - } - -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +/** + * Abstract super class for fields and methods. + * + * @version $Id: FieldOrMethod.java,v 1.5.8.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + */ +public abstract class FieldOrMethod extends Modifiers implements Cloneable, Node { + protected int nameIndex; + protected int signatureIndex; + protected Attribute[] attributes; + protected int attributes_count;// No. of attributes + + protected ConstantPool cpool; + private String name; // lazily initialized + private String signature; // lazily initialized + private AnnotationGen[] annotations; // lazily initialized + private String signatureAttributeString = null; + private boolean searchedForSignatureAttribute = false; + + + + protected FieldOrMethod() {} + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use clone() for a physical copy. + */ + protected FieldOrMethod(FieldOrMethod c) { + this(c.getModifiers(), c.getNameIndex(), c.getSignatureIndex(),c.getAttributes(), c.getConstantPool()); + } + + protected FieldOrMethod(DataInputStream file, ConstantPool cpool) throws IOException { + this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), null, cpool); + attributes = AttributeUtils.readAttributes(file,cpool); + } + + protected FieldOrMethod(int accessFlags, int nameIndex, int signatureIndex, Attribute[] attributes, ConstantPool cpool) { + this.modifiers = accessFlags; + this.nameIndex = nameIndex; + this.signatureIndex = signatureIndex; + this.cpool = cpool; + this.attributes = attributes; + } + + + /** + * @param attributes Collection of object attributes. + */ + public void setAttributes(Attribute[] attributes) { + this.attributes = attributes; + attributes_count = (attributes == null)? 0 : attributes.length; + } + + + + public final void dump(DataOutputStream file) throws IOException { + file.writeShort(modifiers); + file.writeShort(nameIndex); + file.writeShort(signatureIndex); + AttributeUtils.writeAttributes(attributes,file); + } + + public final Attribute[] getAttributes() { return attributes; } + public final ConstantPool getConstantPool() { return cpool; } + public final int getNameIndex() { return nameIndex; } + public final int getSignatureIndex() { return signatureIndex; } + + public final String getName() { + if (name==null) { + ConstantUtf8 c = (ConstantUtf8)cpool.getConstant(nameIndex,Constants.CONSTANT_Utf8); + name = c.getBytes(); + } + return name; + } + + public final String getSignature() { + if (signature==null) { + ConstantUtf8 c = (ConstantUtf8)cpool.getConstant(signatureIndex,Constants.CONSTANT_Utf8); + signature = c.getBytes(); + } + return signature; + } + + /** + * This will return the contents of a signature attribute attached to a member, or if there + * is none it will return the same as 'getSignature()'. Signature attributes are attached + * to members that were declared generic. + */ + public final String getDeclaredSignature() { + if (getGenericSignature()!=null) return getGenericSignature(); + return getSignature(); + } + + /** + * @return deep copy of this field + */ + protected FieldOrMethod copy_(ConstantPool constant_pool) { + FieldOrMethod c = null; + + try { + c = (FieldOrMethod)clone(); + } catch(CloneNotSupportedException e) {} + + c.cpool = constant_pool; + c.attributes = AttributeUtils.copy(attributes,constant_pool); + return c; + } + + public AnnotationGen[] getAnnotations() { + // Ensure we have unpacked any attributes that contain annotations. + // We don't remove these annotation attributes from the attributes list, they + // remain there. + if (annotations==null) { + // Find attributes that contain annotation data + List accumulatedAnnotations = new ArrayList(); + for (int i = 0; i < attributes.length; i++) { + Attribute attribute = attributes[i]; + if (attribute instanceof RuntimeAnnotations) { + RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations)attribute; + accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations()); + } + } + if (accumulatedAnnotations.size()==0) { + annotations = AnnotationGen.NO_ANNOTATIONS; + } else { + annotations = (AnnotationGen[])accumulatedAnnotations.toArray(new AnnotationGen[]{}); + } + } + return annotations; + } + + /** + * Hunts for a signature attribute on the member and returns its contents. So where the 'regular' signature + * may be (Ljava/util/Vector;)V the signature attribute may in fact say 'Ljava/lang/Vector;' + * Coded for performance - searches for the attribute only when requested - only searches for it once. + */ + public final String getGenericSignature() { + if (!searchedForSignatureAttribute) { + Signature sig = AttributeUtils.getSignatureAttribute(attributes); + signatureAttributeString = (sig==null?null:sig.getSignature()); + searchedForSignatureAttribute=true; + } + return signatureAttributeString; + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/InnerClass.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/InnerClass.java index 0ee971528..250e8af82 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/InnerClass.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/InnerClass.java @@ -1,221 +1,221 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents a inner class attribute, i.e., the class - * indices of the inner and outer classes, the name and the attributes - * of the inner class. - * - * @version $Id: InnerClass.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see InnerClasses - */ -public final class InnerClass implements Cloneable, Node { - private int inner_class_index; - private int outer_class_index; - private int inner_name_index; - private int inner_access_flags; - - /** - * Initialize from another object. - */ - public InnerClass(InnerClass c) { - this(c.getInnerClassIndex(), c.getOuterClassIndex(), c.getInnerNameIndex(), - c.getInnerAccessFlags()); - } - - /** - * Construct object from file stream. - * @param file Input stream - * @throws IOException - */ - InnerClass(DataInputStream file) throws IOException - { - this(file.readUnsignedShort(), file.readUnsignedShort(), - file.readUnsignedShort(), file.readUnsignedShort()); - } - - /** - * @param inner_class_index Class index in constant pool of inner class - * @param outer_class_index Class index in constant pool of outer class - * @param inner_name_index Name index in constant pool of inner class - * @param inner_access_flags Access flags of inner class - */ - public InnerClass(int inner_class_index, int outer_class_index, - int inner_name_index, int inner_access_flags) - { - this.inner_class_index = inner_class_index; - this.outer_class_index = outer_class_index; - this.inner_name_index = inner_name_index; - this.inner_access_flags = inner_access_flags; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitInnerClass(this); - } - /** - * Dump inner class attribute to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeShort(inner_class_index); - file.writeShort(outer_class_index); - file.writeShort(inner_name_index); - file.writeShort(inner_access_flags); - } - /** - * @return access flags of inner class. - */ - public final int getInnerAccessFlags() { return inner_access_flags; } - /** - * @return class index of inner class. - */ - public final int getInnerClassIndex() { return inner_class_index; } - /** - * @return name index of inner class. - */ - public final int getInnerNameIndex() { return inner_name_index; } - /** - * @return class index of outer class. - */ - public final int getOuterClassIndex() { return outer_class_index; } - /** - * @param inner_access_flags. - */ - public final void setInnerAccessFlags(int inner_access_flags) { - this.inner_access_flags = inner_access_flags; - } - /** - * @param inner_class_index. - */ - public final void setInnerClassIndex(int inner_class_index) { - this.inner_class_index = inner_class_index; - } - /** - * @param inner_name_index. - */ - public final void setInnerNameIndex(int inner_name_index) { - this.inner_name_index = inner_name_index; - } - /** - * @param outer_class_index. - */ - public final void setOuterClassIndex(int outer_class_index) { - this.outer_class_index = outer_class_index; - } - /** - * @return String representation. - */ - public final String toString() { - return "InnerClass(" + inner_class_index + ", " + outer_class_index + - ", " + inner_name_index + ", " + inner_access_flags + ")"; - } - - /** - * @return Resolved string representation - */ - public final String toString(ConstantPool constant_pool) { - String inner_class_name, outer_class_name, inner_name, access; - - inner_class_name = constant_pool.getConstantString(inner_class_index, - Constants.CONSTANT_Class); - inner_class_name = Utility.compactClassName(inner_class_name); - - if (outer_class_index != 0) { - outer_class_name = constant_pool.getConstantString(outer_class_index, - Constants.CONSTANT_Class); - outer_class_name = Utility.compactClassName(outer_class_name); - } - else - outer_class_name = ""; - - if(inner_name_index != 0) - inner_name = ((ConstantUtf8)constant_pool. - getConstant(inner_name_index, Constants.CONSTANT_Utf8)).getBytes(); - else - inner_name = ""; - - access = Utility.accessToString(inner_access_flags, true); - access = access.equals("")? "" : (access + " "); - - return "InnerClass:" + access + inner_class_name + - "(\"" + outer_class_name + "\", \"" + inner_name + "\")"; - } - - /** - * @return deep copy of this object - */ - public InnerClass copy() { - try { - return (InnerClass)clone(); - } catch(CloneNotSupportedException e) {} - - return null; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents a inner class attribute, i.e., the class + * indices of the inner and outer classes, the name and the attributes + * of the inner class. + * + * @version $Id: InnerClass.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see InnerClasses + */ +public final class InnerClass implements Cloneable, Node { + private int inner_class_index; + private int outer_class_index; + private int inner_name_index; + private int inner_access_flags; + + /** + * Initialize from another object. + */ + public InnerClass(InnerClass c) { + this(c.getInnerClassIndex(), c.getOuterClassIndex(), c.getInnerNameIndex(), + c.getInnerAccessFlags()); + } + + /** + * Construct object from file stream. + * @param file Input stream + * @throws IOException + */ + InnerClass(DataInputStream file) throws IOException + { + this(file.readUnsignedShort(), file.readUnsignedShort(), + file.readUnsignedShort(), file.readUnsignedShort()); + } + + /** + * @param inner_class_index Class index in constant pool of inner class + * @param outer_class_index Class index in constant pool of outer class + * @param inner_name_index Name index in constant pool of inner class + * @param inner_access_flags Access flags of inner class + */ + public InnerClass(int inner_class_index, int outer_class_index, + int inner_name_index, int inner_access_flags) + { + this.inner_class_index = inner_class_index; + this.outer_class_index = outer_class_index; + this.inner_name_index = inner_name_index; + this.inner_access_flags = inner_access_flags; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitInnerClass(this); + } + /** + * Dump inner class attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeShort(inner_class_index); + file.writeShort(outer_class_index); + file.writeShort(inner_name_index); + file.writeShort(inner_access_flags); + } + /** + * @return access flags of inner class. + */ + public final int getInnerAccessFlags() { return inner_access_flags; } + /** + * @return class index of inner class. + */ + public final int getInnerClassIndex() { return inner_class_index; } + /** + * @return name index of inner class. + */ + public final int getInnerNameIndex() { return inner_name_index; } + /** + * @return class index of outer class. + */ + public final int getOuterClassIndex() { return outer_class_index; } + /** + * @param inner_access_flags. + */ + public final void setInnerAccessFlags(int inner_access_flags) { + this.inner_access_flags = inner_access_flags; + } + /** + * @param inner_class_index. + */ + public final void setInnerClassIndex(int inner_class_index) { + this.inner_class_index = inner_class_index; + } + /** + * @param inner_name_index. + */ + public final void setInnerNameIndex(int inner_name_index) { + this.inner_name_index = inner_name_index; + } + /** + * @param outer_class_index. + */ + public final void setOuterClassIndex(int outer_class_index) { + this.outer_class_index = outer_class_index; + } + /** + * @return String representation. + */ + public final String toString() { + return "InnerClass(" + inner_class_index + ", " + outer_class_index + + ", " + inner_name_index + ", " + inner_access_flags + ")"; + } + + /** + * @return Resolved string representation + */ + public final String toString(ConstantPool constant_pool) { + String inner_class_name, outer_class_name, inner_name, access; + + inner_class_name = constant_pool.getConstantString(inner_class_index, + Constants.CONSTANT_Class); + inner_class_name = Utility.compactClassName(inner_class_name); + + if (outer_class_index != 0) { + outer_class_name = constant_pool.getConstantString(outer_class_index, + Constants.CONSTANT_Class); + outer_class_name = Utility.compactClassName(outer_class_name); + } + else + outer_class_name = ""; + + if(inner_name_index != 0) + inner_name = ((ConstantUtf8)constant_pool. + getConstant(inner_name_index, Constants.CONSTANT_Utf8)).getBytes(); + else + inner_name = ""; + + access = Utility.accessToString(inner_access_flags, true); + access = access.equals("")? "" : (access + " "); + + return "InnerClass:" + access + inner_class_name + + "(\"" + outer_class_name + "\", \"" + inner_name + "\")"; + } + + /** + * @return deep copy of this object + */ + public InnerClass copy() { + try { + return (InnerClass)clone(); + } catch(CloneNotSupportedException e) {} + + return null; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/InnerClasses.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/InnerClasses.java index c50f2e6a5..32634cc04 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/InnerClasses.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/InnerClasses.java @@ -1,181 +1,181 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from Attribute and denotes that this class - * is an Inner class of another. - * to the source file of this class. - * It is instantiated from the Attribute.readAttribute() method. - * - * @version $Id: InnerClasses.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see Attribute - */ -public final class InnerClasses extends Attribute { - private InnerClass[] inner_classes; - private int number_of_classes; - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use clone() for a physical copy. - */ - public InnerClasses(InnerClasses c) { - this(c.getNameIndex(), c.getLength(), c.getInnerClasses(), - c.getConstantPool()); - } - - /** - * @param name_index Index in constant pool to CONSTANT_Utf8 - * @param length Content length in bytes - * @param inner_classes array of inner classes attributes - * @param constant_pool Array of constants - * @param sourcefile_index Index in constant pool to CONSTANT_Utf8 - */ - public InnerClasses(int name_index, int length, - InnerClass[] inner_classes, - ConstantPool constant_pool) - { - super(Constants.ATTR_INNER_CLASSES, name_index, length, constant_pool); - setInnerClasses(inner_classes); - } - - /** - * Construct object from file stream. - * - * @param name_index Index in constant pool to CONSTANT_Utf8 - * @param length Content length in bytes - * @param file Input stream - * @param constant_pool Array of constants - * @throws IOException - */ - InnerClasses(int name_index, int length, DataInputStream file, - ConstantPool constant_pool) throws IOException - { - this(name_index, length, (InnerClass[])null, constant_pool); - - number_of_classes = file.readUnsignedShort(); - inner_classes = new InnerClass[number_of_classes]; - - for(int i=0; i < number_of_classes; i++) - inner_classes[i] = new InnerClass(file); - } - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitInnerClasses(this); - } - /** - * Dump source file attribute to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - file.writeShort(number_of_classes); - - for(int i=0; i < number_of_classes; i++) - inner_classes[i].dump(file); - } - - /** - * @return array of inner class "records" - */ - public final InnerClass[] getInnerClasses() { return inner_classes; } - - /** - * @param inner_classes. - */ - public final void setInnerClasses(InnerClass[] inner_classes) { - this.inner_classes = inner_classes; - number_of_classes = (inner_classes == null)? 0 : inner_classes.length; - } - - /** - * @return String representation. - */ - public final String toString() { - StringBuffer buf = new StringBuffer(); - - for(int i=0; i < number_of_classes; i++) - buf.append(inner_classes[i].toString(constantPool) + "\n"); - - return buf.toString(); - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - InnerClasses c = (InnerClasses)clone(); - - c.inner_classes = new InnerClass[number_of_classes]; - for(int i=0; i < number_of_classes; i++) - c.inner_classes[i] = inner_classes[i].copy(); - - c.constantPool = constant_pool; - return c; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from Attribute and denotes that this class + * is an Inner class of another. + * to the source file of this class. + * It is instantiated from the Attribute.readAttribute() method. + * + * @version $Id: InnerClasses.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Attribute + */ +public final class InnerClasses extends Attribute { + private InnerClass[] inner_classes; + private int number_of_classes; + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use clone() for a physical copy. + */ + public InnerClasses(InnerClasses c) { + this(c.getNameIndex(), c.getLength(), c.getInnerClasses(), + c.getConstantPool()); + } + + /** + * @param name_index Index in constant pool to CONSTANT_Utf8 + * @param length Content length in bytes + * @param inner_classes array of inner classes attributes + * @param constant_pool Array of constants + * @param sourcefile_index Index in constant pool to CONSTANT_Utf8 + */ + public InnerClasses(int name_index, int length, + InnerClass[] inner_classes, + ConstantPool constant_pool) + { + super(Constants.ATTR_INNER_CLASSES, name_index, length, constant_pool); + setInnerClasses(inner_classes); + } + + /** + * Construct object from file stream. + * + * @param name_index Index in constant pool to CONSTANT_Utf8 + * @param length Content length in bytes + * @param file Input stream + * @param constant_pool Array of constants + * @throws IOException + */ + InnerClasses(int name_index, int length, DataInputStream file, + ConstantPool constant_pool) throws IOException + { + this(name_index, length, (InnerClass[])null, constant_pool); + + number_of_classes = file.readUnsignedShort(); + inner_classes = new InnerClass[number_of_classes]; + + for(int i=0; i < number_of_classes; i++) + inner_classes[i] = new InnerClass(file); + } + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitInnerClasses(this); + } + /** + * Dump source file attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + file.writeShort(number_of_classes); + + for(int i=0; i < number_of_classes; i++) + inner_classes[i].dump(file); + } + + /** + * @return array of inner class "records" + */ + public final InnerClass[] getInnerClasses() { return inner_classes; } + + /** + * @param inner_classes. + */ + public final void setInnerClasses(InnerClass[] inner_classes) { + this.inner_classes = inner_classes; + number_of_classes = (inner_classes == null)? 0 : inner_classes.length; + } + + /** + * @return String representation. + */ + public final String toString() { + StringBuffer buf = new StringBuffer(); + + for(int i=0; i < number_of_classes; i++) + buf.append(inner_classes[i].toString(constantPool) + "\n"); + + return buf.toString(); + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + InnerClasses c = (InnerClasses)clone(); + + c.inner_classes = new InnerClass[number_of_classes]; + for(int i=0; i < number_of_classes; i++) + c.inner_classes[i] = inner_classes[i].copy(); + + c.constantPool = constant_pool; + return c; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java index 50c895c9c..743852d1d 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java @@ -1,958 +1,920 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.util.SyntheticRepository; -import org.aspectj.apache.bcel.util.ClassVector; -import org.aspectj.apache.bcel.util.ClassQueue; -import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations; -import org.aspectj.apache.bcel.generic.Type; - -import java.io.*; -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -/** - * Represents a Java class, i.e., the data structures, constant pool, - * fields, methods and commands contained in a Java .class file. - * See JVM - * specification for details. - - * The intent of this class is to represent a parsed or otherwise existing - * class file. Those interested in programatically generating classes - * should see the ClassGen class. - - * @version $Id: JavaClass.java,v 1.9.8.2 2008/04/25 17:55:36 aclement Exp $ - * @see org.aspectj.apache.bcel.generic.ClassGen - * @author M. Dahm - */ -public class JavaClass extends AccessFlags implements Cloneable, Node { - private String file_name; - private String package_name; - private String source_file_name; - private int class_name_index; - private int superclass_name_index; - private String class_name; - private String superclass_name; - private int major, minor; // Compiler version - private ConstantPool constant_pool; // Constant pool - private int[] interfaces; // implemented interfaces - private String[] interface_names; - private Field[] fields; // Fields, i.e., variables of class - private Method[] methods; // methods defined in the class - private Attribute[] attributes; // attributes defined in the class - private AnnotationGen[] annotations; // annotations defined on the class - private byte source = HEAP; // Generated in memory - private boolean isGeneric = false; - private boolean isAnonymous = false; - private boolean isNested = false; - private boolean computedNestedTypeStatus = false; - - public static final byte HEAP = 1; - public static final byte FILE = 2; - public static final byte ZIP = 3; - - static boolean debug = false; // Debugging on/off - static char sep = '/'; // directory separator - - // Annotations are collected from certain attributes, don't do it more than necessary! - private boolean annotationsOutOfDate = true; - - // state for dealing with generic signature string - private String signatureAttributeString = null; - private Signature signatureAttribute = null; - private boolean searchedForSignatureAttribute = false; - - /** - * In cases where we go ahead and create something, - * use the default SyntheticRepository, because we - * don't know any better. - */ - private transient org.aspectj.apache.bcel.util.Repository repository = null; - - - /** - * Constructor gets all contents as arguments. - * - * @param class_name_index Index into constant pool referencing a - * ConstantClass that represents this class. - * @param superclass_name_index Index into constant pool referencing a - * ConstantClass that represents this class's superclass. - * @param file_name File name - * @param major Major compiler version - * @param minor Minor compiler version - * @param access_flags Access rights defined by bit flags - * @param constant_pool Array of constants - * @param interfaces Implemented interfaces - * @param fields Class fields - * @param methods Class methods - * @param attributes Class attributes - * @param source Read from file or generated in memory? - */ - public JavaClass(int class_name_index, - int superclass_name_index, - String file_name, - int major, - int minor, - int access_flags, - ConstantPool constant_pool, - int[] interfaces, - Field[] fields, - Method[] methods, - Attribute[] attributes, - byte source) - { - if(interfaces == null) // Allowed for backward compatibility - interfaces = new int[0]; - if (attributes == null) this.attributes = Attribute.NoAttributes; - if(fields == null) - fields = new Field[0]; // TODO create a constant for no fields - if(methods == null) - methods = new Method[0]; // TODO create a constant for no methods - - this.class_name_index = class_name_index; - this.superclass_name_index = superclass_name_index; - this.file_name = file_name; - this.major = major; - this.minor = minor; - this.accessflags = access_flags; - this.constant_pool = constant_pool; - this.interfaces = interfaces; - this.fields = fields; - this.methods = methods; - this.attributes = attributes; - annotationsOutOfDate = true; - this.source = source; - - // Get source file name if available - SourceFile sfAttribute = AttributeUtils.getSourceFileAttribute(attributes); - source_file_name = (sfAttribute==null?"":sfAttribute.getSourceFileName()); - - /* According to the specification the following entries must be of type - * `ConstantClass' but we check that anyway via the - * `ConstPool.getConstant' method. - */ - class_name = constant_pool.getConstantString(class_name_index, - Constants.CONSTANT_Class); - class_name = Utility.compactClassName(class_name, false); - - int index = class_name.lastIndexOf('.'); - if(index < 0) - package_name = ""; - else - package_name = class_name.substring(0, index); - - if(superclass_name_index > 0) { // May be zero -> class is java.lang.Object - superclass_name = constant_pool.getConstantString(superclass_name_index, - Constants.CONSTANT_Class); - superclass_name = Utility.compactClassName(superclass_name, false); - } - else - superclass_name = "java.lang.Object"; - - interface_names = new String[interfaces.length]; - for(int i=0; i < interfaces.length; i++) { - String str = constant_pool.getConstantString(interfaces[i], Constants.CONSTANT_Class); - interface_names[i] = Utility.compactClassName(str, false); - } - } - - /** - * Constructor gets all contents as arguments. - * - * @param class_name_index Class name - * @param superclass_name_index Superclass name - * @param file_name File name - * @param major Major compiler version - * @param minor Minor compiler version - * @param access_flags Access rights defined by bit flags - * @param constant_pool Array of constants - * @param interfaces Implemented interfaces - * @param fields Class fields - * @param methods Class methods - * @param attributes Class attributes - */ - public JavaClass(int class_name_index, - int superclass_name_index, - String file_name, - int major, - int minor, - int access_flags, - ConstantPool constant_pool, - int[] interfaces, - Field[] fields, - Method[] methods, - Attribute[] attributes) { - this(class_name_index, superclass_name_index, file_name, major, minor, access_flags, - constant_pool, interfaces, fields, methods, attributes, HEAP); - } - - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitJavaClass(this); - } - - /* Print debug information depending on `JavaClass.debug' - */ - static final void Debug(String str) { - if(debug) - System.out.println(str); - } - - /** - * Dump class to a file. - * - * @param file Output file - * @throws IOException - */ - public void dump(File file) throws IOException - { - String parent = file.getParent(); - - if(parent != null) { - File dir = new File(parent); - - if(dir != null) - dir.mkdirs(); - } - - dump(new DataOutputStream(new FileOutputStream(file))); - } - - /** - * Dump class to a file named file_name. - * - * @param file_name Output file name - * @exception IOException - */ - public void dump(String file_name) throws IOException - { - dump(new File(file_name)); - } - - /** - * @return class in binary format - */ - public byte[] getBytes() { - ByteArrayOutputStream s = new ByteArrayOutputStream(); - DataOutputStream ds = new DataOutputStream(s); - - try { - dump(ds); - } catch(IOException e) { - e.printStackTrace(); - } finally { - try { ds.close(); } catch(IOException e2) { e2.printStackTrace(); } - } - - return s.toByteArray(); - } - - /** - * Dump Java class to output stream in binary format. - * - * @param file Output stream - * @exception IOException - */ - public void dump(OutputStream file) throws IOException { - dump(new DataOutputStream(file)); - } - - /** - * Dump Java class to output stream in binary format. - * - * @param file Output stream - * @exception IOException - */ - public void dump(DataOutputStream file) throws IOException - { - file.writeInt(0xcafebabe); - file.writeShort(minor); - file.writeShort(major); - - constant_pool.dump(file); - - file.writeShort(accessflags); - file.writeShort(class_name_index); - file.writeShort(superclass_name_index); - - file.writeShort(interfaces.length); - for(int i=0; i < interfaces.length; i++) - file.writeShort(interfaces[i]); - - file.writeShort(fields.length); - for(int i=0; i < fields.length; i++) - fields[i].dump(file); - - file.writeShort(methods.length); - for(int i=0; i < methods.length; i++) - methods[i].dump(file); - - AttributeUtils.writeAttributes(attributes,file); - - file.close(); - } - - /** - * @return Attributes of the class. - */ - public Attribute[] getAttributes() { return attributes; } - - public AnnotationGen[] getAnnotations() { - if (annotationsOutOfDate) { - // Find attributes that contain annotation data - List accumulatedAnnotations = new ArrayList(); - for (int i = 0; i < attributes.length; i++) { - Attribute attribute = attributes[i]; - if (attribute instanceof RuntimeAnnotations) { - RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations)attribute; - accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations()); - } - } - annotations = (AnnotationGen[])accumulatedAnnotations.toArray(new AnnotationGen[]{}); - annotationsOutOfDate = false; - } - return annotations; - } - /** - * @return Class name. - */ - public String getClassName() { return class_name; } - - /** - * @return Package name. - */ - public String getPackageName() { return package_name; } - - /** - * @return Class name index. - */ - public int getClassNameIndex() { return class_name_index; } - - /** - * @return Constant pool. - */ - public ConstantPool getConstantPool() { return constant_pool; } - - /** - * @return Fields, i.e., variables of the class. Like the JVM spec - * mandates for the classfile format, these fields are those specific to - * this class, and not those of the superclass or superinterfaces. - */ - public Field[] getFields() { return fields; } - - /** - * @return File name of class, aka SourceFile attribute value - */ - public String getFileName() { return file_name; } - - /** - * @return Names of implemented interfaces. - */ - public String[] getInterfaceNames() { return interface_names; } - - /** - * @return Indices in constant pool of implemented interfaces. - */ - public int[] getInterfaceIndices() { return interfaces; } - - /** - * @return Major number of class file version. - */ - public int getMajor() { return major; } - - /** - * @return Methods of the class. - */ - public Method[] getMethods() { return methods; } - - /** - * @return A org.aspectj.apache.bcel.classfile.Method corresponding to - * java.lang.reflect.Method if any - */ - public Method getMethod(java.lang.reflect.Method m) { - for(int i = 0; i < methods.length; i++) { - Method method = methods[i]; - - if(m.getName().equals(method.getName()) && - (m.getModifiers() == method.getModifiers()) && - Type.getSignature(m).equals(method.getSignature())) { - return method; - } - } - - return null; - } - - public Method getMethod(java.lang.reflect.Constructor c) { - for (int i = 0; i < methods.length; i++) { - Method method = methods[i]; - - if (method.getName().equals("") - && (c.getModifiers() == method.getModifiers()) - && Type.getSignature(c).equals(method.getSignature())) { - return method; - } - } - - return null; - } - - public Field getField(java.lang.reflect.Field field) { - for (int i = 0; i < fields.length; i++) { - if (fields[i].getName().equals(field.getName())) return fields[i]; - } - return null; - } - - /** - * @return Minor number of class file version. - */ - public int getMinor() { return minor; } - - /** - * @return sbsolute path to file where this class was read from - */ - public String getSourceFileName() { return source_file_name; } - - /** - * @return Superclass name. - */ - public String getSuperclassName() { return superclass_name; } - - /** - * @return Class name index. - */ - public int getSuperclassNameIndex() { return superclass_name_index; } - - static { - // Debugging ... on/off - String debug = System.getProperty("JavaClass.debug"); - - if(debug != null) - JavaClass.debug = new Boolean(debug).booleanValue(); - - // Get path separator either / or \ usually - String sep = System.getProperty("file.separator"); - - if(sep != null) - try { - JavaClass.sep = sep.charAt(0); - } catch(StringIndexOutOfBoundsException e) {} // Never reached - } - - /** - * @param attributes . - */ - public void setAttributes(Attribute[] attributes) { - this.attributes = attributes; - annotationsOutOfDate = true; - } - - /** - * @param class_name . - */ - public void setClassName(String class_name) { - this.class_name = class_name; - } - - /** - * @param class_name_index . - */ - public void setClassNameIndex(int class_name_index) { - this.class_name_index = class_name_index; - } - - /** - * @param constant_pool . - */ - public void setConstantPool(ConstantPool constant_pool) { - this.constant_pool = constant_pool; - } - - /** - * @param fields . - */ - public void setFields(Field[] fields) { - this.fields = fields; - } - - /** - * Set File name of class, aka SourceFile attribute value - */ - public void setFileName(String file_name) { - this.file_name = file_name; - } - - /** - * @param interface_names . - */ - public void setInterfaceNames(String[] interface_names) { - this.interface_names = interface_names; - } - - /** - * @param interfaces . - */ - public void setInterfaces(int[] interfaces) { - this.interfaces = interfaces; - } - - /** - * @param major . - */ - public void setMajor(int major) { - this.major = major; - } - - /** - * @param methods . - */ - public void setMethods(Method[] methods) { - this.methods = methods; - } - - /** - * @param minor . - */ - public void setMinor(int minor) { - this.minor = minor; - } - - /** - * Set absolute path to file this class was read from. - */ - public void setSourceFileName(String source_file_name) { - this.source_file_name = source_file_name; - } - - /** - * @param superclass_name . - */ - public void setSuperclassName(String superclass_name) { - this.superclass_name = superclass_name; - } - - /** - * @param superclass_name_index . - */ - public void setSuperclassNameIndex(int superclass_name_index) { - this.superclass_name_index = superclass_name_index; - } - - /** - * @return String representing class contents. - */ - public String toString() { - String access = Utility.accessToString(accessflags, true); - access = access.equals("")? "" : (access + " "); - - StringBuffer buf = new StringBuffer(access + - Utility.classOrInterface(accessflags) + - " " + - class_name + " extends " + - Utility.compactClassName(superclass_name, - false) + '\n'); - int size = interfaces.length; - - if(size > 0) { - buf.append("implements\t\t"); - - for(int i=0; i < size; i++) { - buf.append(interface_names[i]); - if(i < size - 1) - buf.append(", "); - } - - buf.append('\n'); - } - - buf.append("filename\t\t" + file_name + '\n'); - buf.append("compiled from\t\t" + source_file_name + '\n'); - buf.append("compiler version\t" + major + "." + minor + '\n'); - buf.append("access flags\t\t" + accessflags + '\n'); - buf.append("constant pool\t\t" + constant_pool.getLength() + " entries\n"); - buf.append("ACC_SUPER flag\t\t" + isSuper() + "\n"); - - if(attributes.length > 0) { - buf.append("\nAttribute(s):\n"); - for(int i=0; i < attributes.length; i++) buf.append(indent(attributes[i])); - } - - if (annotations!=null && annotations.length>0) { - buf.append("\nAnnotation(s):\n"); - for (int i=0; i 0) { - buf.append("\n" + fields.length + " fields:\n"); - for(int i=0; i < fields.length; i++) - buf.append("\t" + fields[i] + '\n'); - } - - if(methods.length > 0) { - buf.append("\n" + methods.length + " methods:\n"); - for(int i=0; i < methods.length; i++) - buf.append("\t" + methods[i] + '\n'); - } - - return buf.toString(); - } - - private static final String indent(Object obj) { - StringTokenizer tok = new StringTokenizer(obj.toString(), "\n"); - StringBuffer buf = new StringBuffer(); - - while(tok.hasMoreTokens()) - buf.append("\t" + tok.nextToken() + "\n"); - - return buf.toString(); - } - - /** - * @return deep copy of this class - */ - public JavaClass copy() { - JavaClass c = null; - - try { - c = (JavaClass)clone(); - } catch(CloneNotSupportedException e) {} - - c.constant_pool = constant_pool.copy(); - c.interfaces = (int[])interfaces.clone(); - c.interface_names = (String[])interface_names.clone(); - - c.fields = new Field[fields.length]; - for(int i=0; i < fields.length; i++) - c.fields[i] = fields[i].copy(c.constant_pool); - - c.methods = new Method[methods.length]; - for(int i=0; i < methods.length; i++) - c.methods[i] = methods[i].copy(c.constant_pool); - - c.attributes = AttributeUtils.copy(attributes,c.constant_pool); - - //J5SUPPORT: As the annotations exist as attributes against the class, copying - // the attributes will copy the annotations across, so we don't have to - // also copy them individually. - - return c; - } - - public final boolean isSuper() { - return (accessflags & Constants.ACC_SUPER) != 0; - } - - public final boolean isClass() { - return (accessflags & Constants.ACC_INTERFACE) == 0; - } - - public final boolean isAnonymous() { - computeNestedTypeStatus(); - return this.isAnonymous; - } - - public final boolean isNested() { - computeNestedTypeStatus(); - return this.isNested; - } - - private final void computeNestedTypeStatus() { - if (computedNestedTypeStatus) return; - //Attribute[] attrs = attributes.getAttributes(); - for (int i = 0; i Ljava/lang/Object". We can learn the type variable names, their bounds, - * and the true superclass and superinterface types (including any parameterizations) - * Coded for performance - searches for the attribute only when requested - only searches for it once. - */ - public final String getGenericSignature() { - loadGenericSignatureInfoIfNecessary(); - return signatureAttributeString; - } - - public boolean isGeneric() { - loadGenericSignatureInfoIfNecessary(); - return isGeneric; - } - - private void loadGenericSignatureInfoIfNecessary() { - if (!searchedForSignatureAttribute) { - signatureAttribute = AttributeUtils.getSignatureAttribute(attributes); - signatureAttributeString = signatureAttribute==null?null:signatureAttribute.getSignature(); - isGeneric = signatureAttribute!=null && signatureAttributeString.charAt(0)=='<'; - searchedForSignatureAttribute=true; - } - } - - /** - * the parsed version of the above - */ - public final Signature.ClassSignature getGenericClassTypeSignature() { - loadGenericSignatureInfoIfNecessary(); - if (signatureAttribute != null) { - return signatureAttribute.asClassSignature(); - } - return null; - } - -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.util.SyntheticRepository; +import org.aspectj.apache.bcel.util.ClassVector; +import org.aspectj.apache.bcel.util.ClassQueue; +import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations; +import org.aspectj.apache.bcel.generic.Type; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +/** + * Represents a Java class, i.e., the data structures, constant pool, + * fields, methods and commands contained in a Java .class file. + * See JVM + * specification for details. + + * The intent of this class is to represent a parsed or otherwise existing + * class file. Those interested in programatically generating classes + * should see the ClassGen class. + + * @version $Id: JavaClass.java,v 1.9.8.3 2008/05/08 19:26:46 aclement Exp $ + * @see org.aspectj.apache.bcel.generic.ClassGen + * @author M. Dahm + */ +public class JavaClass extends Modifiers implements Cloneable, Node { + private String file_name; + private String package_name; + private String source_file_name; + private int class_name_index; + private int superclass_name_index; + private String class_name; + private String superclass_name; + private int major, minor; // Compiler version + private ConstantPool constant_pool; // Constant pool + private int[] interfaces; // implemented interfaces + private String[] interface_names; + private Field[] fields; // Fields, i.e., variables of class + private Method[] methods; // methods defined in the class + private Attribute[] attributes; // attributes defined in the class + private AnnotationGen[] annotations; // annotations defined on the class + private boolean isGeneric = false; + private boolean isAnonymous = false; + private boolean isNested = false; + private boolean computedNestedTypeStatus = false; + + public static final byte HEAP = 1; + public static final byte FILE = 2; + public static final byte ZIP = 3; + + static boolean debug = false; // Debugging on/off + static char sep = '/'; // directory separator + + // Annotations are collected from certain attributes, don't do it more than necessary! + private boolean annotationsOutOfDate = true; + + // state for dealing with generic signature string + private String signatureAttributeString = null; + private Signature signatureAttribute = null; + private boolean searchedForSignatureAttribute = false; + + /** + * In cases where we go ahead and create something, + * use the default SyntheticRepository, because we + * don't know any better. + */ + private transient org.aspectj.apache.bcel.util.Repository repository = null; + + + /** + * Constructor gets all contents as arguments. + * + * @param class_name_index Index into constant pool referencing a + * ConstantClass that represents this class. + * @param superclass_name_index Index into constant pool referencing a + * ConstantClass that represents this class's superclass. + * @param file_name File name + * @param major Major compiler version + * @param minor Minor compiler version + * @param access_flags Access rights defined by bit flags + * @param constant_pool Array of constants + * @param interfaces Implemented interfaces + * @param fields Class fields + * @param methods Class methods + * @param attributes Class attributes + * @param source Read from file or generated in memory? + */ + public JavaClass(int class_name_index, + int superclass_name_index, + String file_name, + int major, + int minor, + int access_flags, + ConstantPool constant_pool, + int[] interfaces, + Field[] fields, + Method[] methods, + Attribute[] attributes) + { + if(interfaces == null) // Allowed for backward compatibility + interfaces = new int[0]; + if (attributes == null) this.attributes = Attribute.NoAttributes; + if(fields == null) + fields = new Field[0]; // TODO create a constant for no fields + if(methods == null) + methods = new Method[0]; // TODO create a constant for no methods + + this.class_name_index = class_name_index; + this.superclass_name_index = superclass_name_index; + this.file_name = file_name; + this.major = major; + this.minor = minor; + this.modifiers = access_flags; + this.constant_pool = constant_pool; + this.interfaces = interfaces; + this.fields = fields; + this.methods = methods; + this.attributes = attributes; + annotationsOutOfDate = true; + + // Get source file name if available + SourceFile sfAttribute = AttributeUtils.getSourceFileAttribute(attributes); + source_file_name = (sfAttribute==null?"":sfAttribute.getSourceFileName()); + + /* According to the specification the following entries must be of type + * `ConstantClass' but we check that anyway via the + * `ConstPool.getConstant' method. + */ + class_name = constant_pool.getConstantString(class_name_index, + Constants.CONSTANT_Class); + class_name = Utility.compactClassName(class_name, false); + + int index = class_name.lastIndexOf('.'); + if(index < 0) + package_name = ""; + else + package_name = class_name.substring(0, index); + + if(superclass_name_index > 0) { // May be zero -> class is java.lang.Object + superclass_name = constant_pool.getConstantString(superclass_name_index, + Constants.CONSTANT_Class); + superclass_name = Utility.compactClassName(superclass_name, false); + } + else + superclass_name = "java.lang.Object"; + + interface_names = new String[interfaces.length]; + for(int i=0; i < interfaces.length; i++) { + String str = constant_pool.getConstantString(interfaces[i], Constants.CONSTANT_Class); + interface_names[i] = Utility.compactClassName(str, false); + } + } + + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitJavaClass(this); + } + + /* Print debug information depending on `JavaClass.debug' + */ + static final void Debug(String str) { + if(debug) + System.out.println(str); + } + + /** + * Dump class to a file. + * + * @param file Output file + * @throws IOException + */ + public void dump(File file) throws IOException + { + String parent = file.getParent(); + + if(parent != null) { + File dir = new File(parent); + + if(dir != null) + dir.mkdirs(); + } + + dump(new DataOutputStream(new FileOutputStream(file))); + } + + /** + * Dump class to a file named file_name. + * + * @param file_name Output file name + * @exception IOException + */ + public void dump(String file_name) throws IOException + { + dump(new File(file_name)); + } + + /** + * @return class in binary format + */ + public byte[] getBytes() { + ByteArrayOutputStream s = new ByteArrayOutputStream(); + DataOutputStream ds = new DataOutputStream(s); + + try { + dump(ds); + } catch(IOException e) { + e.printStackTrace(); + } finally { + try { ds.close(); } catch(IOException e2) { e2.printStackTrace(); } + } + + return s.toByteArray(); + } + + /** + * Dump Java class to output stream in binary format. + * + * @param file Output stream + * @exception IOException + */ + public void dump(OutputStream file) throws IOException { + dump(new DataOutputStream(file)); + } + + /** + * Dump Java class to output stream in binary format. + * + * @param file Output stream + * @exception IOException + */ + public void dump(DataOutputStream file) throws IOException + { + file.writeInt(0xcafebabe); + file.writeShort(minor); + file.writeShort(major); + + constant_pool.dump(file); + + file.writeShort(modifiers); + file.writeShort(class_name_index); + file.writeShort(superclass_name_index); + + file.writeShort(interfaces.length); + for(int i=0; i < interfaces.length; i++) + file.writeShort(interfaces[i]); + + file.writeShort(fields.length); + for(int i=0; i < fields.length; i++) + fields[i].dump(file); + + file.writeShort(methods.length); + for(int i=0; i < methods.length; i++) + methods[i].dump(file); + + AttributeUtils.writeAttributes(attributes,file); + + file.close(); + } + + /** + * @return Attributes of the class. + */ + public Attribute[] getAttributes() { return attributes; } + + public AnnotationGen[] getAnnotations() { + if (annotationsOutOfDate) { + // Find attributes that contain annotation data + List accumulatedAnnotations = new ArrayList(); + for (int i = 0; i < attributes.length; i++) { + Attribute attribute = attributes[i]; + if (attribute instanceof RuntimeAnnotations) { + RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations)attribute; + accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations()); + } + } + annotations = (AnnotationGen[])accumulatedAnnotations.toArray(new AnnotationGen[]{}); + annotationsOutOfDate = false; + } + return annotations; + } + /** + * @return Class name. + */ + public String getClassName() { return class_name; } + + /** + * @return Package name. + */ + public String getPackageName() { return package_name; } + + /** + * @return Class name index. + */ + public int getClassNameIndex() { return class_name_index; } + + /** + * @return Constant pool. + */ + public ConstantPool getConstantPool() { return constant_pool; } + + /** + * @return Fields, i.e., variables of the class. Like the JVM spec + * mandates for the classfile format, these fields are those specific to + * this class, and not those of the superclass or superinterfaces. + */ + public Field[] getFields() { return fields; } + + /** + * @return File name of class, aka SourceFile attribute value + */ + public String getFileName() { return file_name; } + + /** + * @return Names of implemented interfaces. + */ + public String[] getInterfaceNames() { return interface_names; } + + /** + * @return Indices in constant pool of implemented interfaces. + */ + public int[] getInterfaceIndices() { return interfaces; } + + /** + * @return Major number of class file version. + */ + public int getMajor() { return major; } + + /** + * @return Methods of the class. + */ + public Method[] getMethods() { return methods; } + + /** + * @return A org.aspectj.apache.bcel.classfile.Method corresponding to + * java.lang.reflect.Method if any + */ + public Method getMethod(java.lang.reflect.Method m) { + for(int i = 0; i < methods.length; i++) { + Method method = methods[i]; + + if(m.getName().equals(method.getName()) && + (m.getModifiers() == method.getModifiers()) && + Type.getSignature(m).equals(method.getSignature())) { + return method; + } + } + + return null; + } + + public Method getMethod(java.lang.reflect.Constructor c) { + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + + if (method.getName().equals("") + && (c.getModifiers() == method.getModifiers()) + && Type.getSignature(c).equals(method.getSignature())) { + return method; + } + } + + return null; + } + + public Field getField(java.lang.reflect.Field field) { + for (int i = 0; i < fields.length; i++) { + if (fields[i].getName().equals(field.getName())) return fields[i]; + } + return null; + } + + /** + * @return Minor number of class file version. + */ + public int getMinor() { return minor; } + + /** + * @return sbsolute path to file where this class was read from + */ + public String getSourceFileName() { return source_file_name; } + + /** + * @return Superclass name. + */ + public String getSuperclassName() { return superclass_name; } + + /** + * @return Class name index. + */ + public int getSuperclassNameIndex() { return superclass_name_index; } + + static { + // Debugging ... on/off + String debug = System.getProperty("JavaClass.debug"); + + if(debug != null) + JavaClass.debug = new Boolean(debug).booleanValue(); + + // Get path separator either / or \ usually + String sep = System.getProperty("file.separator"); + + if(sep != null) + try { + JavaClass.sep = sep.charAt(0); + } catch(StringIndexOutOfBoundsException e) {} // Never reached + } + + /** + * @param attributes . + */ + public void setAttributes(Attribute[] attributes) { + this.attributes = attributes; + annotationsOutOfDate = true; + } + + /** + * @param class_name . + */ + public void setClassName(String class_name) { + this.class_name = class_name; + } + + /** + * @param class_name_index . + */ + public void setClassNameIndex(int class_name_index) { + this.class_name_index = class_name_index; + } + + /** + * @param constant_pool . + */ + public void setConstantPool(ConstantPool constant_pool) { + this.constant_pool = constant_pool; + } + + /** + * @param fields . + */ + public void setFields(Field[] fields) { + this.fields = fields; + } + + /** + * Set File name of class, aka SourceFile attribute value + */ + public void setFileName(String file_name) { + this.file_name = file_name; + } + + /** + * @param interface_names . + */ + public void setInterfaceNames(String[] interface_names) { + this.interface_names = interface_names; + } + + /** + * @param interfaces . + */ + public void setInterfaces(int[] interfaces) { + this.interfaces = interfaces; + } + + /** + * @param major . + */ + public void setMajor(int major) { + this.major = major; + } + + /** + * @param methods . + */ + public void setMethods(Method[] methods) { + this.methods = methods; + } + + /** + * @param minor . + */ + public void setMinor(int minor) { + this.minor = minor; + } + + /** + * Set absolute path to file this class was read from. + */ + public void setSourceFileName(String source_file_name) { + this.source_file_name = source_file_name; + } + + /** + * @param superclass_name . + */ + public void setSuperclassName(String superclass_name) { + this.superclass_name = superclass_name; + } + + /** + * @param superclass_name_index . + */ + public void setSuperclassNameIndex(int superclass_name_index) { + this.superclass_name_index = superclass_name_index; + } + + /** + * @return String representing class contents. + */ + public String toString() { + String access = Utility.accessToString(modifiers, true); + access = access.equals("")? "" : (access + " "); + + StringBuffer buf = new StringBuffer(access + + Utility.classOrInterface(modifiers) + + " " + + class_name + " extends " + + Utility.compactClassName(superclass_name, + false) + '\n'); + int size = interfaces.length; + + if(size > 0) { + buf.append("implements\t\t"); + + for(int i=0; i < size; i++) { + buf.append(interface_names[i]); + if(i < size - 1) + buf.append(", "); + } + + buf.append('\n'); + } + + buf.append("filename\t\t" + file_name + '\n'); + buf.append("compiled from\t\t" + source_file_name + '\n'); + buf.append("compiler version\t" + major + "." + minor + '\n'); + buf.append("access flags\t\t" + modifiers + '\n'); + buf.append("constant pool\t\t" + constant_pool.getLength() + " entries\n"); + buf.append("ACC_SUPER flag\t\t" + isSuper() + "\n"); + + if(attributes.length > 0) { + buf.append("\nAttribute(s):\n"); + for(int i=0; i < attributes.length; i++) buf.append(indent(attributes[i])); + } + + if (annotations!=null && annotations.length>0) { + buf.append("\nAnnotation(s):\n"); + for (int i=0; i 0) { + buf.append("\n" + fields.length + " fields:\n"); + for(int i=0; i < fields.length; i++) + buf.append("\t" + fields[i] + '\n'); + } + + if(methods.length > 0) { + buf.append("\n" + methods.length + " methods:\n"); + for(int i=0; i < methods.length; i++) + buf.append("\t" + methods[i] + '\n'); + } + + return buf.toString(); + } + + private static final String indent(Object obj) { + StringTokenizer tok = new StringTokenizer(obj.toString(), "\n"); + StringBuffer buf = new StringBuffer(); + + while(tok.hasMoreTokens()) + buf.append("\t" + tok.nextToken() + "\n"); + + return buf.toString(); + } + + /** + * @return deep copy of this class + */ + public JavaClass copy() { + JavaClass c = null; + + try { + c = (JavaClass)clone(); + } catch(CloneNotSupportedException e) {} + + c.constant_pool = constant_pool.copy(); + c.interfaces = (int[])interfaces.clone(); + c.interface_names = (String[])interface_names.clone(); + + c.fields = new Field[fields.length]; + for(int i=0; i < fields.length; i++) + c.fields[i] = fields[i].copy(c.constant_pool); + + c.methods = new Method[methods.length]; + for(int i=0; i < methods.length; i++) + c.methods[i] = methods[i].copy(c.constant_pool); + + c.attributes = AttributeUtils.copy(attributes,c.constant_pool); + + //J5SUPPORT: As the annotations exist as attributes against the class, copying + // the attributes will copy the annotations across, so we don't have to + // also copy them individually. + + return c; + } + + public final boolean isSuper() { + return (modifiers & Constants.ACC_SUPER) != 0; + } + + public final boolean isClass() { + return (modifiers & Constants.ACC_INTERFACE) == 0; + } + + public final boolean isAnonymous() { + computeNestedTypeStatus(); + return this.isAnonymous; + } + + public final boolean isNested() { + computeNestedTypeStatus(); + return this.isNested; + } + + private final void computeNestedTypeStatus() { + if (computedNestedTypeStatus) return; + //Attribute[] attrs = attributes.getAttributes(); + for (int i = 0; i Ljava/lang/Object". We can learn the type variable names, their bounds, + * and the true superclass and superinterface types (including any parameterizations) + * Coded for performance - searches for the attribute only when requested - only searches for it once. + */ + public final String getGenericSignature() { + loadGenericSignatureInfoIfNecessary(); + return signatureAttributeString; + } + + public boolean isGeneric() { + loadGenericSignatureInfoIfNecessary(); + return isGeneric; + } + + private void loadGenericSignatureInfoIfNecessary() { + if (!searchedForSignatureAttribute) { + signatureAttribute = AttributeUtils.getSignatureAttribute(attributes); + signatureAttributeString = signatureAttribute==null?null:signatureAttribute.getSignature(); + isGeneric = signatureAttribute!=null && signatureAttributeString.charAt(0)=='<'; + searchedForSignatureAttribute=true; + } + } + + /** + * the parsed version of the above + */ + public final Signature.ClassSignature getGenericClassTypeSignature() { + loadGenericSignatureInfoIfNecessary(); + if (signatureAttribute != null) { + return signatureAttribute.asClassSignature(); + } + return null; + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumber.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumber.java index e913f2b2e..9cf787ea2 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumber.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumber.java @@ -1,166 +1,166 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.Serializable; - -/** - * This class represents a (PC offset, line number) pair, i.e., a line number in - * the source that corresponds to a relative address in the byte code. This - * is used for debugging purposes. - * - * @version $Id: LineNumber.java,v 1.3.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see LineNumberTable - */ -public final class LineNumber implements Cloneable, Node, Serializable { - private int start_pc; // Program Counter (PC) corresponds to line - private int line_number; // number in source file - - /** - * Initialize from another object. - */ - public LineNumber(LineNumber c) { - this(c.getStartPC(), c.getLineNumber()); - } - - /** - * Construct object from file stream. - * @param file Input stream - * @throws IOException - */ - LineNumber(DataInputStream file) throws IOException - { - this(file.readUnsignedShort(), file.readUnsignedShort()); - } - - /** - * @param start_pc Program Counter (PC) corresponds to - * @param line_number line number in source file - */ - public LineNumber(int start_pc, int line_number) - { - this.start_pc = start_pc; - this.line_number = line_number; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitLineNumber(this); - } - - /** - * Dump line number/pc pair to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeShort(start_pc); - file.writeShort(line_number); - - } - /** - * @return Corresponding source line - */ - public final int getLineNumber() { return line_number; } - - /** - * @return PC in code - */ - public final int getStartPC() { return start_pc; } - - /** - * @param line_number. - */ - public final void setLineNumber(int line_number) { - this.line_number = line_number; - } - - /** - * @param start_pc. - */ - public final void setStartPC(int start_pc) { - this.start_pc = start_pc; - } - - /** - * @return String representation - */ - public final String toString() { - return "LineNumber(" + start_pc + ", " + line_number + ")"; - } - - /** - * @return deep copy of this object - */ - public LineNumber copy() { - try { - return (LineNumber)clone(); - } catch(CloneNotSupportedException e) {} - - return null; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.Serializable; + +/** + * This class represents a (PC offset, line number) pair, i.e., a line number in + * the source that corresponds to a relative address in the byte code. This + * is used for debugging purposes. + * + * @version $Id: LineNumber.java,v 1.3.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see LineNumberTable + */ +public final class LineNumber implements Cloneable, Node, Serializable { + private int start_pc; // Program Counter (PC) corresponds to line + private int line_number; // number in source file + + /** + * Initialize from another object. + */ + public LineNumber(LineNumber c) { + this(c.getStartPC(), c.getLineNumber()); + } + + /** + * Construct object from file stream. + * @param file Input stream + * @throws IOException + */ + LineNumber(DataInputStream file) throws IOException + { + this(file.readUnsignedShort(), file.readUnsignedShort()); + } + + /** + * @param start_pc Program Counter (PC) corresponds to + * @param line_number line number in source file + */ + public LineNumber(int start_pc, int line_number) + { + this.start_pc = start_pc; + this.line_number = line_number; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitLineNumber(this); + } + + /** + * Dump line number/pc pair to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeShort(start_pc); + file.writeShort(line_number); + + } + /** + * @return Corresponding source line + */ + public final int getLineNumber() { return line_number; } + + /** + * @return PC in code + */ + public final int getStartPC() { return start_pc; } + + /** + * @param line_number. + */ + public final void setLineNumber(int line_number) { + this.line_number = line_number; + } + + /** + * @param start_pc. + */ + public final void setStartPC(int start_pc) { + this.start_pc = start_pc; + } + + /** + * @return String representation + */ + public final String toString() { + return "LineNumber(" + start_pc + ", " + line_number + ")"; + } + + /** + * @return deep copy of this object + */ + public LineNumber copy() { + try { + return (LineNumber)clone(); + } catch(CloneNotSupportedException e) {} + + return null; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumberTable.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumberTable.java index d5576262d..93c288996 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumberTable.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumberTable.java @@ -1,276 +1,276 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents a table of line numbers for debugging - * purposes. This attribute is used by the Code attribute. It - * contains pairs of PCs and line numbers. - * - * @version $Id: LineNumberTable.java,v 1.3.6.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see Code - * - * changes: - * asc Feb06 Made unpacking lazy - */ -public final class LineNumberTable extends Attribute { - - - // if 'isInPackedState' then this data needs unpacking - private boolean isInPackedState = false; - private byte[] data; - - private int line_number_table_length; - private LineNumber[] line_number_table; // Table of line/numbers pairs - - /* - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use copy() for a physical copy. - */ - public LineNumberTable(LineNumberTable c) { - this(c.getNameIndex(), c.getLength(), c.getLineNumberTable(), c.getConstantPool()); - } - - /* - * @param name_index Index of name - * @param length Content length in bytes - * @param line_number_table Table of line/numbers pairs - * @param constant_pool Array of constants - */ - public LineNumberTable(int name_index, int length, - LineNumber[] line_number_table, ConstantPool constant_pool) { - super(Constants.ATTR_LINE_NUMBER_TABLE, name_index, length, constant_pool); - setLineNumberTable(line_number_table); - isInPackedState=false; - } - - /** - * Construct object from file stream. - * @param name_index Index of name - * @param length Content length in bytes - * @param file Input stream - * @throws IOException - * @param constant_pool Array of constants - */ - LineNumberTable(int name_index, int length, DataInputStream file, - ConstantPool constant_pool) throws IOException - { - this(name_index, length, (LineNumber[])null, constant_pool); - data = new byte[length]; - int byteReads = file.read(data); - isInPackedState = true; - // assert(bytesRead==length) - } - - // Unpacks the byte array into the table - private void unpack() { - if (!isInPackedState) return; - - try { - ByteArrayInputStream bs = new ByteArrayInputStream(data); - DataInputStream dis = new DataInputStream(bs); - line_number_table_length = (dis.readUnsignedShort()); - line_number_table = new LineNumber[line_number_table_length]; - for (int i=0; i < line_number_table_length; i++) - line_number_table[i] = new LineNumber(dis); - dis.close(); - data = null; // throw it away now - } catch (IOException e) { - throw new RuntimeException("Unpacking of LineNumberTable attribute failed"); - } - isInPackedState=false; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - unpack(); - v.visitLineNumberTable(this); - } - - /** - * Dump line number table attribute to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - if (isInPackedState) { - file.write(data); - } else { - file.writeShort(line_number_table_length); - for(int i=0; i < line_number_table_length; i++) - line_number_table[i].dump(file); - } - } - - /** - * @return Array of (pc offset, line number) pairs. - */ - public final LineNumber[] getLineNumberTable() { unpack();return line_number_table; } - - /** - * @param line_number_table. - */ - public final void setLineNumberTable(LineNumber[] line_number_table) { - this.data = null; - this.isInPackedState=false; - this.line_number_table = line_number_table; - - line_number_table_length = (line_number_table == null)? 0 : - line_number_table.length; - } - - /** - * @return String representation. - */ - public final String toString() { - unpack(); - StringBuffer buf = new StringBuffer(); - StringBuffer line = new StringBuffer(); - - for(int i=0; i < line_number_table_length; i++) { - line.append(line_number_table[i].toString()); - - if(i < line_number_table_length - 1) - line.append(", "); - - if(line.length() > 72) { - line.append('\n'); - buf.append(line); - line.setLength(0); - } - } - - buf.append(line); - - return buf.toString(); - } - - /** - * Map byte code positions to source code lines. - * - * @param pos byte code offset - * @return corresponding line in source code - */ - public int getSourceLine(int pos) { - unpack(); - int l = 0, r = line_number_table_length-1; - - if(r < 0) // array is empty - return -1; - - int min_index = -1, min=-1; - - /* Do a binary search since the array is ordered. - */ - do { - int i = (l + r) / 2; - int j = line_number_table[i].getStartPC(); - - if(j == pos) - return line_number_table[i].getLineNumber(); - else if(pos < j) // else constrain search area - r = i - 1; - else // pos > j - l = i + 1; - - /* If exact match can't be found (which is the most common case) - * return the line number that corresponds to the greatest index less - * than pos. - */ - if(j < pos && j > min) { - min = j; - min_index = i; - } - } while(l <= r); - - /* It's possible that we did not find any valid entry for the bytecode - * offset we were looking for. - */ - if (min_index < 0) - return -1; - - return line_number_table[min_index].getLineNumber(); - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - unpack(); - LineNumberTable c = (LineNumberTable)clone(); - - c.line_number_table = new LineNumber[line_number_table_length]; - for(int i=0; i < line_number_table_length; i++) - c.line_number_table[i] = line_number_table[i].copy(); - - c.constantPool = constant_pool; - return c; - } - - public final int getTableLength() { unpack();return line_number_table_length; } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents a table of line numbers for debugging + * purposes. This attribute is used by the Code attribute. It + * contains pairs of PCs and line numbers. + * + * @version $Id: LineNumberTable.java,v 1.3.6.3 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + * @see Code + * + * changes: + * asc Feb06 Made unpacking lazy + */ +public final class LineNumberTable extends Attribute { + + + // if 'isInPackedState' then this data needs unpacking + private boolean isInPackedState = false; + private byte[] data; + + private int line_number_table_length; + private LineNumber[] line_number_table; // Table of line/numbers pairs + + /* + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use copy() for a physical copy. + */ + public LineNumberTable(LineNumberTable c) { + this(c.getNameIndex(), c.getLength(), c.getLineNumberTable(), c.getConstantPool()); + } + + /* + * @param name_index Index of name + * @param length Content length in bytes + * @param line_number_table Table of line/numbers pairs + * @param constant_pool Array of constants + */ + public LineNumberTable(int name_index, int length, + LineNumber[] line_number_table, ConstantPool constant_pool) { + super(Constants.ATTR_LINE_NUMBER_TABLE, name_index, length, constant_pool); + setLineNumberTable(line_number_table); + isInPackedState=false; + } + + /** + * Construct object from file stream. + * @param name_index Index of name + * @param length Content length in bytes + * @param file Input stream + * @throws IOException + * @param constant_pool Array of constants + */ + LineNumberTable(int name_index, int length, DataInputStream file, + ConstantPool constant_pool) throws IOException + { + this(name_index, length, (LineNumber[])null, constant_pool); + data = new byte[length]; + int byteReads = file.read(data); + isInPackedState = true; + // assert(bytesRead==length) + } + + // Unpacks the byte array into the table + private void unpack() { + if (!isInPackedState) return; + + try { + ByteArrayInputStream bs = new ByteArrayInputStream(data); + DataInputStream dis = new DataInputStream(bs); + line_number_table_length = (dis.readUnsignedShort()); + line_number_table = new LineNumber[line_number_table_length]; + for (int i=0; i < line_number_table_length; i++) + line_number_table[i] = new LineNumber(dis); + dis.close(); + data = null; // throw it away now + } catch (IOException e) { + throw new RuntimeException("Unpacking of LineNumberTable attribute failed"); + } + isInPackedState=false; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + unpack(); + v.visitLineNumberTable(this); + } + + /** + * Dump line number table attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + if (isInPackedState) { + file.write(data); + } else { + file.writeShort(line_number_table_length); + for(int i=0; i < line_number_table_length; i++) + line_number_table[i].dump(file); + } + } + + /** + * @return Array of (pc offset, line number) pairs. + */ + public final LineNumber[] getLineNumberTable() { unpack();return line_number_table; } + + /** + * @param line_number_table. + */ + public final void setLineNumberTable(LineNumber[] line_number_table) { + this.data = null; + this.isInPackedState=false; + this.line_number_table = line_number_table; + + line_number_table_length = (line_number_table == null)? 0 : + line_number_table.length; + } + + /** + * @return String representation. + */ + public final String toString() { + unpack(); + StringBuffer buf = new StringBuffer(); + StringBuffer line = new StringBuffer(); + + for(int i=0; i < line_number_table_length; i++) { + line.append(line_number_table[i].toString()); + + if(i < line_number_table_length - 1) + line.append(", "); + + if(line.length() > 72) { + line.append('\n'); + buf.append(line); + line.setLength(0); + } + } + + buf.append(line); + + return buf.toString(); + } + + /** + * Map byte code positions to source code lines. + * + * @param pos byte code offset + * @return corresponding line in source code + */ + public int getSourceLine(int pos) { + unpack(); + int l = 0, r = line_number_table_length-1; + + if(r < 0) // array is empty + return -1; + + int min_index = -1, min=-1; + + /* Do a binary search since the array is ordered. + */ + do { + int i = (l + r) / 2; + int j = line_number_table[i].getStartPC(); + + if(j == pos) + return line_number_table[i].getLineNumber(); + else if(pos < j) // else constrain search area + r = i - 1; + else // pos > j + l = i + 1; + + /* If exact match can't be found (which is the most common case) + * return the line number that corresponds to the greatest index less + * than pos. + */ + if(j < pos && j > min) { + min = j; + min_index = i; + } + } while(l <= r); + + /* It's possible that we did not find any valid entry for the bytecode + * offset we were looking for. + */ + if (min_index < 0) + return -1; + + return line_number_table[min_index].getLineNumber(); + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + unpack(); + LineNumberTable c = (LineNumberTable)clone(); + + c.line_number_table = new LineNumber[line_number_table_length]; + for(int i=0; i < line_number_table_length; i++) + c.line_number_table[i] = line_number_table[i].copy(); + + c.constantPool = constant_pool; + return c; + } + + public final int getTableLength() { unpack();return line_number_table_length; } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariable.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariable.java index ef4b2ee14..c66124bc9 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariable.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariable.java @@ -1,259 +1,259 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents a local variable within a method. It contains its - * scope, name, signature and index on the method's frame. - * - * @version $Id: LocalVariable.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see LocalVariableTable - */ -public final class LocalVariable - implements Constants, Cloneable, Node, Serializable -{ - private int start_pc; // Range in which the variable is valid - private int length; - private int name_index; // Index in constant pool of variable name - private int signature_index; // Index of variable signature - private int index; /* Variable is `index'th local variable on - * this method's frame. - */ - - private ConstantPool constant_pool; - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use copy() for a physical copy. - */ - public LocalVariable(LocalVariable c) { - this(c.getStartPC(), c.getLength(), c.getNameIndex(), - c.getSignatureIndex(), c.getIndex(), c.getConstantPool()); - } - - /** - * Construct object from file stream. - * @param file Input stream - * @throws IOException - */ - LocalVariable(DataInputStream file, ConstantPool constant_pool) - throws IOException - { - this(file.readUnsignedShort(), file.readUnsignedShort(), - file.readUnsignedShort(), file.readUnsignedShort(), - file.readUnsignedShort(), constant_pool); - } - - /** - * @param start_pc Range in which the variable - * @param length ... is valid - * @param name_index Index in constant pool of variable name - * @param signature_index Index of variable's signature - * @param index Variable is `index'th local variable on the method's frame - * @param constant_pool Array of constants - */ - public LocalVariable(int start_pc, int length, int name_index, - int signature_index, int index, - ConstantPool constant_pool) - { - this.start_pc = start_pc; - this.length = length; - this.name_index = name_index; - this.signature_index = signature_index; - this.index = index; - this.constant_pool = constant_pool; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitLocalVariable(this); - } - - /** - * Dump local variable to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeShort(start_pc); - file.writeShort(length); - file.writeShort(name_index); - file.writeShort(signature_index); - file.writeShort(index); - } - - /** - * @return Constant pool used by this object. - */ - public final ConstantPool getConstantPool() { return constant_pool; } - - /** - * @return Variable is valid within getStartPC() .. getStartPC()+getLength() - */ - public final int getLength() { return length; } - - /** - * @return Variable name. - */ - public final String getName() { - ConstantUtf8 c; - - c = (ConstantUtf8)constant_pool.getConstant(name_index, CONSTANT_Utf8); - return c.getBytes(); - } - - /** - * @return Index in constant pool of variable name. - */ - public final int getNameIndex() { return name_index; } - - /** - * @return Signature. - */ - public final String getSignature() { - ConstantUtf8 c; - c = (ConstantUtf8)constant_pool.getConstant(signature_index, - CONSTANT_Utf8); - return c.getBytes(); - } - - /** - * @return Index in constant pool of variable signature. - */ - public final int getSignatureIndex() { return signature_index; } - - /** - * @return index of register where variable is stored - */ - public final int getIndex() { return index; } - - /** - * @return Start of range where he variable is valid - */ - public final int getStartPC() { return start_pc; } - - /** - * @param constant_pool Constant pool to be used for this object. - */ - public final void setConstantPool(ConstantPool constant_pool) { - this.constant_pool = constant_pool; - } - - /** - * @param length. - */ - public final void setLength(int length) { - this.length = length; - } - - /** - * @param name_index. - */ - public final void setNameIndex(int name_index) { - this.name_index = name_index; - } - - /** - * @param signature_index. - */ - public final void setSignatureIndex(int signature_index) { - this.signature_index = signature_index; - } - - /** - * @param index. - */ - public final void setIndex(int index) { this.index = index; } - - /** - * @param start_pc Specify range where the local variable is valid. - */ - public final void setStartPC(int start_pc) { - this.start_pc = start_pc; - } - - /** - * @return string representation. - */ - public final String toString() { - String name = getName(), signature = Utility.signatureToString(getSignature()); - - return "LocalVariable(start_pc = " + start_pc + ", length = " + length + - ", index = " + index + ":" + signature + " " + name + ")"; - } - - /** - * @return deep copy of this object - */ - public LocalVariable copy() { - try { - return (LocalVariable)clone(); - } catch(CloneNotSupportedException e) {} - - return null; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents a local variable within a method. It contains its + * scope, name, signature and index on the method's frame. + * + * @version $Id: LocalVariable.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see LocalVariableTable + */ +public final class LocalVariable + implements Constants, Cloneable, Node, Serializable +{ + private int start_pc; // Range in which the variable is valid + private int length; + private int name_index; // Index in constant pool of variable name + private int signature_index; // Index of variable signature + private int index; /* Variable is `index'th local variable on + * this method's frame. + */ + + private ConstantPool constant_pool; + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use copy() for a physical copy. + */ + public LocalVariable(LocalVariable c) { + this(c.getStartPC(), c.getLength(), c.getNameIndex(), + c.getSignatureIndex(), c.getIndex(), c.getConstantPool()); + } + + /** + * Construct object from file stream. + * @param file Input stream + * @throws IOException + */ + LocalVariable(DataInputStream file, ConstantPool constant_pool) + throws IOException + { + this(file.readUnsignedShort(), file.readUnsignedShort(), + file.readUnsignedShort(), file.readUnsignedShort(), + file.readUnsignedShort(), constant_pool); + } + + /** + * @param start_pc Range in which the variable + * @param length ... is valid + * @param name_index Index in constant pool of variable name + * @param signature_index Index of variable's signature + * @param index Variable is `index'th local variable on the method's frame + * @param constant_pool Array of constants + */ + public LocalVariable(int start_pc, int length, int name_index, + int signature_index, int index, + ConstantPool constant_pool) + { + this.start_pc = start_pc; + this.length = length; + this.name_index = name_index; + this.signature_index = signature_index; + this.index = index; + this.constant_pool = constant_pool; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitLocalVariable(this); + } + + /** + * Dump local variable to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeShort(start_pc); + file.writeShort(length); + file.writeShort(name_index); + file.writeShort(signature_index); + file.writeShort(index); + } + + /** + * @return Constant pool used by this object. + */ + public final ConstantPool getConstantPool() { return constant_pool; } + + /** + * @return Variable is valid within getStartPC() .. getStartPC()+getLength() + */ + public final int getLength() { return length; } + + /** + * @return Variable name. + */ + public final String getName() { + ConstantUtf8 c; + + c = (ConstantUtf8)constant_pool.getConstant(name_index, CONSTANT_Utf8); + return c.getBytes(); + } + + /** + * @return Index in constant pool of variable name. + */ + public final int getNameIndex() { return name_index; } + + /** + * @return Signature. + */ + public final String getSignature() { + ConstantUtf8 c; + c = (ConstantUtf8)constant_pool.getConstant(signature_index, + CONSTANT_Utf8); + return c.getBytes(); + } + + /** + * @return Index in constant pool of variable signature. + */ + public final int getSignatureIndex() { return signature_index; } + + /** + * @return index of register where variable is stored + */ + public final int getIndex() { return index; } + + /** + * @return Start of range where he variable is valid + */ + public final int getStartPC() { return start_pc; } + + /** + * @param constant_pool Constant pool to be used for this object. + */ + public final void setConstantPool(ConstantPool constant_pool) { + this.constant_pool = constant_pool; + } + + /** + * @param length. + */ + public final void setLength(int length) { + this.length = length; + } + + /** + * @param name_index. + */ + public final void setNameIndex(int name_index) { + this.name_index = name_index; + } + + /** + * @param signature_index. + */ + public final void setSignatureIndex(int signature_index) { + this.signature_index = signature_index; + } + + /** + * @param index. + */ + public final void setIndex(int index) { this.index = index; } + + /** + * @param start_pc Specify range where the local variable is valid. + */ + public final void setStartPC(int start_pc) { + this.start_pc = start_pc; + } + + /** + * @return string representation. + */ + public final String toString() { + String name = getName(), signature = Utility.signatureToString(getSignature()); + + return "LocalVariable(start_pc = " + start_pc + ", length = " + length + + ", index = " + index + ":" + signature + " " + name + ")"; + } + + /** + * @return deep copy of this object + */ + public LocalVariable copy() { + try { + return (LocalVariable)clone(); + } catch(CloneNotSupportedException e) {} + + return null; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTable.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTable.java index 6a0acee13..f880f7676 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTable.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTable.java @@ -1,234 +1,234 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents collection of local variables in a - * method. This attribute is contained in the Code attribute. - * - * @version $Id: LocalVariableTable.java,v 1.3.6.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see Code - * @see LocalVariable - * - * Updates: Andy 14Feb06 - Made unpacking of the data lazy, depending on someone - * actually asking for it. - */ -public class LocalVariableTable extends Attribute { - - // if 'isInPackedState' then this data needs unpacking - private boolean isInPackedState = false; - private byte[] data; - - private int localVariableTableLength; - private LocalVariable[] localVariableTable; - - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use copy() for a physical copy. - */ - public LocalVariableTable(LocalVariableTable c) { - this(c.getNameIndex(), c.getLength(), c.getLocalVariableTable(),c.getConstantPool()); - } - - /** - * @param name_index Index in constant pool to `LocalVariableTable' - * @param length Content length in bytes - * @param local_variable_table Table of local variables - * @param constant_pool Array of constants - */ - public LocalVariableTable(int name_index, int length, - LocalVariable[] local_variable_table, - ConstantPool constant_pool) - { - super(Constants.ATTR_LOCAL_VARIABLE_TABLE, name_index, length, constant_pool); - setLocalVariableTable(local_variable_table); - } - - /** - * Construct object from file stream. - * @param name_index Index in constant pool - * @param length Content length in bytes - * @param file Input stream - * @param constant_pool Array of constants - * @throws IOException - */ - LocalVariableTable(int name_index, int length, DataInputStream file, - ConstantPool constant_pool) throws IOException - { - super(Constants.ATTR_LOCAL_VARIABLE_TABLE,name_index, length, constant_pool); - data = new byte[length]; - int byteReads = file.read(data); - isInPackedState = true; - // assert(bytesRead==length) - } - - - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - unpack(); - v.visitLocalVariableTable(this); - } - - /** - * Dump local variable table attribute to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - if (isInPackedState) { - file.write(data); - } else { - file.writeShort(localVariableTableLength); - for(int i=0; i < localVariableTableLength; i++) - localVariableTable[i].dump(file); - } - } - - /** - * @return Array of local variables of method. - */ - public final LocalVariable[] getLocalVariableTable() { - unpack(); - return localVariableTable; - } - - /** @return first matching variable using index - */ - public final LocalVariable getLocalVariable(int index) { - unpack(); - for(int i=0; i < localVariableTableLength; i++) - if (localVariableTable[i].getIndex() == index) return localVariableTable[i]; - return null; - } - - public final void setLocalVariableTable(LocalVariable[] local_variable_table) - { - data=null; - isInPackedState=false; - this.localVariableTable = local_variable_table; - localVariableTableLength = (local_variable_table == null)? 0 : - local_variable_table.length; - } - - /** - * @return String representation. - */ - public final String toString() { - StringBuffer buf = new StringBuffer(""); - unpack(); - for(int i=0; i < localVariableTableLength; i++) { - buf.append(localVariableTable[i].toString()); - - if(i < localVariableTableLength - 1) - buf.append('\n'); - } - - return buf.toString(); - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - unpack(); - LocalVariableTable c = (LocalVariableTable)clone(); - - c.localVariableTable = new LocalVariable[localVariableTableLength]; - for(int i=0; i < localVariableTableLength; i++) - c.localVariableTable[i] = localVariableTable[i].copy(); - - c.constantPool = constant_pool; - return c; - } - - public final int getTableLength() { - unpack(); - return localVariableTableLength; - } - - // --- - // Unpacks the byte array into the table - private void unpack() { - if (!isInPackedState) return; - try { - ByteArrayInputStream bs = new ByteArrayInputStream(data); - DataInputStream dis = new DataInputStream(bs); - localVariableTableLength = (dis.readUnsignedShort()); - localVariableTable = new LocalVariable[localVariableTableLength]; - for (int i=0; i < localVariableTableLength; i++) - localVariableTable[i] = new LocalVariable(dis,constantPool); - dis.close(); - data = null; // throw it away now - } catch (IOException e) { - throw new RuntimeException("Unpacking of LocalVariableTable attribute failed"); - } - isInPackedState=false; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents collection of local variables in a + * method. This attribute is contained in the Code attribute. + * + * @version $Id: LocalVariableTable.java,v 1.3.6.3 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + * @see Code + * @see LocalVariable + * + * Updates: Andy 14Feb06 - Made unpacking of the data lazy, depending on someone + * actually asking for it. + */ +public class LocalVariableTable extends Attribute { + + // if 'isInPackedState' then this data needs unpacking + private boolean isInPackedState = false; + private byte[] data; + + private int localVariableTableLength; + private LocalVariable[] localVariableTable; + + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use copy() for a physical copy. + */ + public LocalVariableTable(LocalVariableTable c) { + this(c.getNameIndex(), c.getLength(), c.getLocalVariableTable(),c.getConstantPool()); + } + + /** + * @param name_index Index in constant pool to `LocalVariableTable' + * @param length Content length in bytes + * @param local_variable_table Table of local variables + * @param constant_pool Array of constants + */ + public LocalVariableTable(int name_index, int length, + LocalVariable[] local_variable_table, + ConstantPool constant_pool) + { + super(Constants.ATTR_LOCAL_VARIABLE_TABLE, name_index, length, constant_pool); + setLocalVariableTable(local_variable_table); + } + + /** + * Construct object from file stream. + * @param name_index Index in constant pool + * @param length Content length in bytes + * @param file Input stream + * @param constant_pool Array of constants + * @throws IOException + */ + LocalVariableTable(int name_index, int length, DataInputStream file, + ConstantPool constant_pool) throws IOException + { + super(Constants.ATTR_LOCAL_VARIABLE_TABLE,name_index, length, constant_pool); + data = new byte[length]; + int byteReads = file.read(data); + isInPackedState = true; + // assert(bytesRead==length) + } + + + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + unpack(); + v.visitLocalVariableTable(this); + } + + /** + * Dump local variable table attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + if (isInPackedState) { + file.write(data); + } else { + file.writeShort(localVariableTableLength); + for(int i=0; i < localVariableTableLength; i++) + localVariableTable[i].dump(file); + } + } + + /** + * @return Array of local variables of method. + */ + public final LocalVariable[] getLocalVariableTable() { + unpack(); + return localVariableTable; + } + + /** @return first matching variable using index + */ + public final LocalVariable getLocalVariable(int index) { + unpack(); + for(int i=0; i < localVariableTableLength; i++) + if (localVariableTable[i].getIndex() == index) return localVariableTable[i]; + return null; + } + + public final void setLocalVariableTable(LocalVariable[] local_variable_table) + { + data=null; + isInPackedState=false; + this.localVariableTable = local_variable_table; + localVariableTableLength = (local_variable_table == null)? 0 : + local_variable_table.length; + } + + /** + * @return String representation. + */ + public final String toString() { + StringBuffer buf = new StringBuffer(""); + unpack(); + for(int i=0; i < localVariableTableLength; i++) { + buf.append(localVariableTable[i].toString()); + + if(i < localVariableTableLength - 1) + buf.append('\n'); + } + + return buf.toString(); + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + unpack(); + LocalVariableTable c = (LocalVariableTable)clone(); + + c.localVariableTable = new LocalVariable[localVariableTableLength]; + for(int i=0; i < localVariableTableLength; i++) + c.localVariableTable[i] = localVariableTable[i].copy(); + + c.constantPool = constant_pool; + return c; + } + + public final int getTableLength() { + unpack(); + return localVariableTableLength; + } + + // --- + // Unpacks the byte array into the table + private void unpack() { + if (!isInPackedState) return; + try { + ByteArrayInputStream bs = new ByteArrayInputStream(data); + DataInputStream dis = new DataInputStream(bs); + localVariableTableLength = (dis.readUnsignedShort()); + localVariableTable = new LocalVariable[localVariableTableLength]; + for (int i=0; i < localVariableTableLength; i++) + localVariableTable[i] = new LocalVariable(dis,constantPool); + dis.close(); + data = null; // throw it away now + } catch (IOException e) { + throw new RuntimeException("Unpacking of LocalVariableTable attribute failed"); + } + isInPackedState=false; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTypeTable.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTypeTable.java index c7a91eeec..81af0cc3a 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTypeTable.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTypeTable.java @@ -1,135 +1,135 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * Heavily based on LocalVariableTable - * ******************************************************************/ -package org.aspectj.apache.bcel.classfile; - - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -// The new table is used when generic types are about... - -//LocalVariableTable_attribute { -// u2 attribute_name_index; -// u4 attribute_length; -// u2 local_variable_table_length; -// { u2 start_pc; -// u2 length; -// u2 name_index; -// u2 descriptor_index; -// u2 index; -// } local_variable_table[local_variable_table_length]; -// } - -//LocalVariableTypeTable_attribute { -// u2 attribute_name_index; -// u4 attribute_length; -// u2 local_variable_type_table_length; -// { -// u2 start_pc; -// u2 length; -// u2 name_index; -// u2 signature_index; -// u2 index; -// } local_variable_type_table[local_variable_type_table_length]; -// } -// J5TODO: Needs some testing ! -public class LocalVariableTypeTable extends Attribute { - private int local_variable_type_table_length; // Table of local - private LocalVariable[] local_variable_type_table; // variables - - public LocalVariableTypeTable(LocalVariableTypeTable c) { - this(c.getNameIndex(), c.getLength(), c.getLocalVariableTypeTable(), - c.getConstantPool()); - } - - public LocalVariableTypeTable(int name_index, int length, - LocalVariable[] local_variable_table, - ConstantPool constant_pool) - { - super(Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE, name_index, length, constant_pool); - setLocalVariableTable(local_variable_table); - } - - LocalVariableTypeTable(int nameIdx, int len, DataInputStream dis,ConstantPool cpool) throws IOException { - this(nameIdx, len, (LocalVariable[])null, cpool); - - local_variable_type_table_length = (dis.readUnsignedShort()); - local_variable_type_table = new LocalVariable[local_variable_type_table_length]; - - for(int i=0; i < local_variable_type_table_length; i++) - local_variable_type_table[i] = new LocalVariable(dis, cpool); - } - - public void accept(Visitor v) { - v.visitLocalVariableTypeTable(this); - } - - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - file.writeShort(local_variable_type_table_length); - for(int i=0; i < local_variable_type_table_length; i++) - local_variable_type_table[i].dump(file); - } - - public final LocalVariable[] getLocalVariableTypeTable() { - return local_variable_type_table; - } - - public final LocalVariable getLocalVariable(int index) { - for(int i=0; i < local_variable_type_table_length; i++) - if(local_variable_type_table[i].getIndex() == index) - return local_variable_type_table[i]; - - return null; - } - - public final void setLocalVariableTable(LocalVariable[] local_variable_table) - { - this.local_variable_type_table = local_variable_table; - local_variable_type_table_length = (local_variable_table == null)? 0 : - local_variable_table.length; - } - - /** - * @return String representation. - */ - public final String toString() { - StringBuffer buf = new StringBuffer(""); - - for(int i=0; i < local_variable_type_table_length; i++) { - buf.append(local_variable_type_table[i].toString()); - - if(i < local_variable_type_table_length - 1) buf.append('\n'); - } - - return buf.toString(); - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - LocalVariableTypeTable c = (LocalVariableTypeTable)clone(); - - c.local_variable_type_table = new LocalVariable[local_variable_type_table_length]; - for(int i=0; i < local_variable_type_table_length; i++) - c.local_variable_type_table[i] = local_variable_type_table[i].copy(); - - c.constantPool = constant_pool; - return c; - } - - public final int getTableLength() { return local_variable_type_table_length; } -} +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * Heavily based on LocalVariableTable + * ******************************************************************/ +package org.aspectj.apache.bcel.classfile; + + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +// The new table is used when generic types are about... + +//LocalVariableTable_attribute { +// u2 attribute_name_index; +// u4 attribute_length; +// u2 local_variable_table_length; +// { u2 start_pc; +// u2 length; +// u2 name_index; +// u2 descriptor_index; +// u2 index; +// } local_variable_table[local_variable_table_length]; +// } + +//LocalVariableTypeTable_attribute { +// u2 attribute_name_index; +// u4 attribute_length; +// u2 local_variable_type_table_length; +// { +// u2 start_pc; +// u2 length; +// u2 name_index; +// u2 signature_index; +// u2 index; +// } local_variable_type_table[local_variable_type_table_length]; +// } +// J5TODO: Needs some testing ! +public class LocalVariableTypeTable extends Attribute { + private int local_variable_type_table_length; // Table of local + private LocalVariable[] local_variable_type_table; // variables + + public LocalVariableTypeTable(LocalVariableTypeTable c) { + this(c.getNameIndex(), c.getLength(), c.getLocalVariableTypeTable(), + c.getConstantPool()); + } + + public LocalVariableTypeTable(int name_index, int length, + LocalVariable[] local_variable_table, + ConstantPool constant_pool) + { + super(Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE, name_index, length, constant_pool); + setLocalVariableTable(local_variable_table); + } + + LocalVariableTypeTable(int nameIdx, int len, DataInputStream dis,ConstantPool cpool) throws IOException { + this(nameIdx, len, (LocalVariable[])null, cpool); + + local_variable_type_table_length = (dis.readUnsignedShort()); + local_variable_type_table = new LocalVariable[local_variable_type_table_length]; + + for(int i=0; i < local_variable_type_table_length; i++) + local_variable_type_table[i] = new LocalVariable(dis, cpool); + } + + public void accept(ClassVisitor v) { + v.visitLocalVariableTypeTable(this); + } + + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + file.writeShort(local_variable_type_table_length); + for(int i=0; i < local_variable_type_table_length; i++) + local_variable_type_table[i].dump(file); + } + + public final LocalVariable[] getLocalVariableTypeTable() { + return local_variable_type_table; + } + + public final LocalVariable getLocalVariable(int index) { + for(int i=0; i < local_variable_type_table_length; i++) + if(local_variable_type_table[i].getIndex() == index) + return local_variable_type_table[i]; + + return null; + } + + public final void setLocalVariableTable(LocalVariable[] local_variable_table) + { + this.local_variable_type_table = local_variable_table; + local_variable_type_table_length = (local_variable_table == null)? 0 : + local_variable_table.length; + } + + /** + * @return String representation. + */ + public final String toString() { + StringBuffer buf = new StringBuffer(""); + + for(int i=0; i < local_variable_type_table_length; i++) { + buf.append(local_variable_type_table[i].toString()); + + if(i < local_variable_type_table_length - 1) buf.append('\n'); + } + + return buf.toString(); + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + LocalVariableTypeTable c = (LocalVariableTypeTable)clone(); + + c.local_variable_type_table = new LocalVariable[local_variable_type_table_length]; + for(int i=0; i < local_variable_type_table_length; i++) + c.local_variable_type_table[i] = local_variable_type_table[i].copy(); + + c.constantPool = constant_pool; + return c; + } + + public final int getTableLength() { return local_variable_type_table_length; } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Method.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Method.java index b33e9b5aa..e11d0ba9a 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Method.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Method.java @@ -1,114 +1,114 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.DataInputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; -import org.aspectj.apache.bcel.generic.Type; -import java.io.*; -import java.util.*; - -/** - * This class represents the method info structure, i.e., the representation - * for a method in the class. See JVM specification for details. - * A method has access flags, a name, a signature and a number of attributes. - * - * @version $Id: Method.java,v 1.2.10.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - */ -public final class Method extends FieldOrMethod { - - public static final AnnotationGen[][] NO_PARAMETER_ANNOTATIONS = new AnnotationGen[][]{}; - public static final AnnotationGen[] NO_ANNOTATIONS = new AnnotationGen[]{}; - - public static final Method[] NoMethods = new Method[0]; - +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.io.DataInputStream; +import java.io.IOException; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; +import org.aspectj.apache.bcel.generic.Type; +import java.io.*; +import java.util.*; + +/** + * This class represents the method info structure, i.e., the representation + * for a method in the class. See JVM specification for details. + * A method has access flags, a name, a signature and a number of attributes. + * + * @version $Id: Method.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + */ +public final class Method extends FieldOrMethod { + + public static final AnnotationGen[][] NO_PARAMETER_ANNOTATIONS = new AnnotationGen[][]{}; + public static final AnnotationGen[] NO_ANNOTATIONS = new AnnotationGen[]{}; + + public static final Method[] NoMethods = new Method[0]; + private boolean parameterAnnotationsOutOfDate = true; private AnnotationGen[][] unpackedParameterAnnotations; - - private Method() { - parameterAnnotationsOutOfDate = true; - } - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use clone() for a physical copy. - */ - public Method(Method c) { - super(c); + + private Method() { parameterAnnotationsOutOfDate = true; - } - - Method(DataInputStream file, ConstantPool constant_pool) throws IOException { - super(file, constant_pool); - } - - public Method(int access_flags, int name_index, int signature_index, Attribute[] attributes, ConstantPool constant_pool) { - super(access_flags, name_index, signature_index, attributes, constant_pool); + } + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use clone() for a physical copy. + */ + public Method(Method c) { + super(c); + parameterAnnotationsOutOfDate = true; + } + + Method(DataInputStream file, ConstantPool constant_pool) throws IOException { + super(file, constant_pool); + } + + public Method(int access_flags, int name_index, int signature_index, Attribute[] attributes, ConstantPool constant_pool) { + super(access_flags, name_index, signature_index, attributes, constant_pool); parameterAnnotationsOutOfDate = true; - } - - public void accept(Visitor v) { - v.visitMethod(this); - } - - // CUSTARD mutable or not? + } + + public void accept(ClassVisitor v) { + v.visitMethod(this); + } + + // CUSTARD mutable or not? public void setAttributes(Attribute[] attributes) { parameterAnnotationsOutOfDate = true; super.setAttributes(attributes); @@ -117,94 +117,94 @@ public final class Method extends FieldOrMethod { /** * @return Code attribute of method, if any */ - public final Code getCode() { - return AttributeUtils.getCodeAttribute(attributes); - } - - public final ExceptionTable getExceptionTable() { - return AttributeUtils.getExceptionTableAttribute(attributes); - } - - /** - * Return LocalVariableTable of code attribute if any (the call is forwarded - * to the Code attribute) - */ - public final LocalVariableTable getLocalVariableTable() { - Code code = getCode(); - if (code != null) return code.getLocalVariableTable(); - return null; - } - - /** - * Return LineNumberTable of code attribute if any (the call is forwarded - * to the Code attribute) - */ - public final LineNumberTable getLineNumberTable() { - Code code = getCode(); - if (code != null) return code.getLineNumberTable(); - return null; - } - - /** - * Return string representation close to declaration format, eg: - * 'public static void main(String[] args) throws IOException' - */ - public final String toString() { - ConstantUtf8 c; - String name, signature, access; // Short cuts to constant pool - StringBuffer buf; - - access = Utility.accessToString(accessflags); - - // Get name and signature from constant pool - c = (ConstantUtf8)cpool.getConstant(signatureIndex, - Constants.CONSTANT_Utf8); - signature = c.getBytes(); - - c = (ConstantUtf8)cpool.getConstant(nameIndex, Constants.CONSTANT_Utf8); - name = c.getBytes(); - - signature = Utility.methodSignatureToString(signature, name, access, true, - getLocalVariableTable()); - buf = new StringBuffer(signature); - - for(int i=0; i < attributes.length; i++) { - Attribute a = attributes[i]; - if(!((a instanceof Code) || (a instanceof ExceptionTable))) buf.append(" [" + a.toString() + "]"); - } - - ExceptionTable e = getExceptionTable(); - if(e != null) { - String str = e.toString(); - if(!str.equals("")) - buf.append("\n\t\tthrows " + str); - } - - return buf.toString(); - } - - /** - * Return a deep copy of this method - */ - public final Method copy(ConstantPool constant_pool) { - return (Method)copy_(constant_pool); - } - - /** - * @return return type of method - */ - public Type getReturnType() { - return Type.getReturnType(getSignature()); - } - - /** - * @return array of method argument types - */ - public Type[] getArgumentTypes() { - return Type.getArgumentTypes(getSignature()); - } - - private void ensureParameterAnnotationsUnpacked() { + public final Code getCode() { + return AttributeUtils.getCodeAttribute(attributes); + } + + public final ExceptionTable getExceptionTable() { + return AttributeUtils.getExceptionTableAttribute(attributes); + } + + /** + * Return LocalVariableTable of code attribute if any (the call is forwarded + * to the Code attribute) + */ + public final LocalVariableTable getLocalVariableTable() { + Code code = getCode(); + if (code != null) return code.getLocalVariableTable(); + return null; + } + + /** + * Return LineNumberTable of code attribute if any (the call is forwarded + * to the Code attribute) + */ + public final LineNumberTable getLineNumberTable() { + Code code = getCode(); + if (code != null) return code.getLineNumberTable(); + return null; + } + + /** + * Return string representation close to declaration format, eg: + * 'public static void main(String[] args) throws IOException' + */ + public final String toString() { + ConstantUtf8 c; + String name, signature, access; // Short cuts to constant pool + StringBuffer buf; + + access = Utility.accessToString(modifiers); + + // Get name and signature from constant pool + c = (ConstantUtf8)cpool.getConstant(signatureIndex, + Constants.CONSTANT_Utf8); + signature = c.getBytes(); + + c = (ConstantUtf8)cpool.getConstant(nameIndex, Constants.CONSTANT_Utf8); + name = c.getBytes(); + + signature = Utility.methodSignatureToString(signature, name, access, true, + getLocalVariableTable()); + buf = new StringBuffer(signature); + + for(int i=0; i < attributes.length; i++) { + Attribute a = attributes[i]; + if(!((a instanceof Code) || (a instanceof ExceptionTable))) buf.append(" [" + a.toString() + "]"); + } + + ExceptionTable e = getExceptionTable(); + if(e != null) { + String str = e.toString(); + if(!str.equals("")) + buf.append("\n\t\tthrows " + str); + } + + return buf.toString(); + } + + /** + * Return a deep copy of this method + */ + public final Method copy(ConstantPool constant_pool) { + return (Method)copy_(constant_pool); + } + + /** + * @return return type of method + */ + public Type getReturnType() { + return Type.getReturnType(getSignature()); + } + + /** + * @return array of method argument types + */ + public Type[] getArgumentTypes() { + return Type.getArgumentTypes(getSignature()); + } + + private void ensureParameterAnnotationsUnpacked() { if (!parameterAnnotationsOutOfDate) return; parameterAnnotationsOutOfDate = false; @@ -217,51 +217,53 @@ public final class Method extends FieldOrMethod { RuntimeVisibleParameterAnnotations parameterAnnotationsVis = null; RuntimeInvisibleParameterAnnotations parameterAnnotationsInvis = null; - // Find attributes that contain annotation data + // Find attributes that contain annotation data Attribute[] attrs = getAttributes(); List accumulatedAnnotations = new ArrayList(); - + for (int i = 0; i < attrs.length; i++) { Attribute attribute = attrs[i]; - if (attribute instanceof RuntimeVisibleParameterAnnotations) { - parameterAnnotationsVis = (RuntimeVisibleParameterAnnotations)attribute; + if (attribute instanceof RuntimeVisibleParameterAnnotations) { + parameterAnnotationsVis = (RuntimeVisibleParameterAnnotations)attribute; } else if (attribute instanceof RuntimeInvisibleParameterAnnotations) { - parameterAnnotationsInvis = (RuntimeInvisibleParameterAnnotations)attribute; - } - } + parameterAnnotationsInvis = (RuntimeInvisibleParameterAnnotations)attribute; + } + } - // Build a list of annotation arrays, one per argument - List annotationsForEachParameter = new ArrayList(); - AnnotationGen[] visibleOnes = null; - AnnotationGen[] invisibleOnes = null; boolean foundSome = false; - for (int i=0; i. */ +import org.aspectj.apache.bcel.Constants; + /** - * Denotes an unparameterized instruction to load a value from a local - * variable, e.g. ILOAD. - * - * @version $Id: LoadInstruction.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ + * Super class for all objects that have modifiers like private, final, ... I.e. + * classes, fields, and methods. + * was AccessFlags + * + * @version $Id: Modifiers.java,v 1.1.2.1 2008/05/08 19:26:46 aclement Exp $ * @author M. Dahm */ -public abstract class LoadInstruction extends LocalVariableInstruction - implements PushInstruction -{ - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - * tag and length are defined in readInstruction and initFromFile, respectively. - */ - LoadInstruction(short canon_tag, short c_tag) { - super(canon_tag, c_tag); - } - - /** - * @param opcode Instruction opcode - * @param c_tag Instruction number for compact version, ALOAD_0, e.g. - * @param n local variable index (unsigned short) - */ - protected LoadInstruction(short opcode, short c_tag, int n) { - super(opcode, c_tag, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitTypedInstruction(this); - v.visitLocalVariableInstruction(this); - v.visitLoadInstruction(this); - } -} +public abstract class Modifiers { + + protected int modifiers; + + public Modifiers() { } + + public Modifiers(int a) { + modifiers = a; + } + + public final int getModifiers() { + return modifiers; + } + + public final void setModifiers(int modifiers) { + this.modifiers = modifiers; + } + + public final boolean isPublic() { + return (modifiers & Constants.ACC_PUBLIC) != 0; + } + + public final boolean isPrivate() { + return (modifiers & Constants.ACC_PRIVATE) != 0; + } + + public final boolean isProtected() { + return (modifiers & Constants.ACC_PROTECTED) != 0; + } + + public final boolean isStatic() { + return (modifiers & Constants.ACC_STATIC) != 0; + } + public final boolean isFinal() { + return (modifiers & Constants.ACC_FINAL) != 0; + } + + public final boolean isSynchronized() { + return (modifiers & Constants.ACC_SYNCHRONIZED) != 0; + } + + public final boolean isVolatile() { + return (modifiers & Constants.ACC_VOLATILE) != 0; + } + + public final boolean isTransient() { + return (modifiers & Constants.ACC_TRANSIENT) != 0; + } + + public final boolean isNative() { + return (modifiers & Constants.ACC_NATIVE) != 0; + } + + public final boolean isInterface() { + return (modifiers & Constants.ACC_INTERFACE) != 0; + } + + public final boolean isAbstract() { + return (modifiers & Constants.ACC_ABSTRACT) != 0; + } + + public final boolean isStrictfp() { + return (modifiers & Constants.ACC_STRICT) != 0; + } + + public final boolean isVarargs() { + return (modifiers & Constants.ACC_VARARGS) != 0; + } + + public final boolean isBridge() { + return (modifiers & Constants.ACC_BRIDGE) != 0; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Node.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Node.java index 1ee83a1a8..7edfe43a8 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Node.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Node.java @@ -1,65 +1,65 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denote class to have an accept method(); - * - * @version $Id: Node.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - */ -public interface Node { - public void accept(Visitor obj); -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Denote class to have an accept method(); + * + * @version $Id: Node.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + */ +public interface Node { + public void accept(ClassVisitor obj); +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/PMGClass.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/PMGClass.java index e0438c09f..d6d28428c 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/PMGClass.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/PMGClass.java @@ -1,189 +1,189 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from Attribute and represents a reference - * to a PMG - * attribute. - * - * @version $Id: PMGClass.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see Attribute - */ -public final class PMGClass extends Attribute { - private int pmg_class_index, pmg_index; - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use clone() for a physical copy. - */ - public PMGClass(PMGClass c) { - this(c.getNameIndex(), c.getLength(), c.getPMGIndex(), c.getPMGClassIndex(), - c.getConstantPool()); - } - - /** - * Construct object from file stream. - * @param name_index Index in constant pool to CONSTANT_Utf8 - * @param length Content length in bytes - * @param file Input stream - * @param constant_pool Array of constants - * @throws IOException - */ - PMGClass(int name_index, int length, DataInputStream file, - ConstantPool constant_pool) throws IOException - { - this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), - constant_pool); - } - - /** - * @param name_index Index in constant pool to CONSTANT_Utf8 - * @param length Content length in bytes - * @param constant_pool Array of constants - * @param PMGClass_index Index in constant pool to CONSTANT_Utf8 - */ - public PMGClass(int name_index, int length, int pmg_index, int pmg_class_index, - ConstantPool constant_pool) - { - super(Constants.ATTR_PMG, name_index, length, constant_pool); - this.pmg_index = pmg_index; - this.pmg_class_index = pmg_class_index; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - System.err.println("Visiting non-standard PMGClass object"); - } - - /** - * Dump source file attribute to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - file.writeShort(pmg_index); - file.writeShort(pmg_class_index); - } - - /** - * @return Index in constant pool of source file name. - */ - public final int getPMGClassIndex() { return pmg_class_index; } - - /** - * @param PMGClass_index. - */ - public final void setPMGClassIndex(int pmg_class_index) { - this.pmg_class_index = pmg_class_index; - } - - /** - * @return Index in constant pool of source file name. - */ - public final int getPMGIndex() { return pmg_index; } - - /** - * @param PMGClass_index. - */ - public final void setPMGIndex(int pmg_index) { - this.pmg_index = pmg_index; - } - - /** - * @return PMG name. - */ - public final String getPMGName() { - ConstantUtf8 c = (ConstantUtf8)constantPool.getConstant(pmg_index, - Constants.CONSTANT_Utf8); - return c.getBytes(); - } - - /** - * @return PMG class name. - */ - public final String getPMGClassName() { - ConstantUtf8 c = (ConstantUtf8)constantPool.getConstant(pmg_class_index, - Constants.CONSTANT_Utf8); - return c.getBytes(); - } - - /** - * @return String representation - */ - public final String toString() { - return "PMGClass(" + getPMGName() + ", " + getPMGClassName() + ")"; - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - return (PMGClass)clone(); - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from Attribute and represents a reference + * to a PMG + * attribute. + * + * @version $Id: PMGClass.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Attribute + */ +public final class PMGClass extends Attribute { + private int pmg_class_index, pmg_index; + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use clone() for a physical copy. + */ + public PMGClass(PMGClass c) { + this(c.getNameIndex(), c.getLength(), c.getPMGIndex(), c.getPMGClassIndex(), + c.getConstantPool()); + } + + /** + * Construct object from file stream. + * @param name_index Index in constant pool to CONSTANT_Utf8 + * @param length Content length in bytes + * @param file Input stream + * @param constant_pool Array of constants + * @throws IOException + */ + PMGClass(int name_index, int length, DataInputStream file, + ConstantPool constant_pool) throws IOException + { + this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), + constant_pool); + } + + /** + * @param name_index Index in constant pool to CONSTANT_Utf8 + * @param length Content length in bytes + * @param constant_pool Array of constants + * @param PMGClass_index Index in constant pool to CONSTANT_Utf8 + */ + public PMGClass(int name_index, int length, int pmg_index, int pmg_class_index, + ConstantPool constant_pool) + { + super(Constants.ATTR_PMG, name_index, length, constant_pool); + this.pmg_index = pmg_index; + this.pmg_class_index = pmg_class_index; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + System.err.println("Visiting non-standard PMGClass object"); + } + + /** + * Dump source file attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + file.writeShort(pmg_index); + file.writeShort(pmg_class_index); + } + + /** + * @return Index in constant pool of source file name. + */ + public final int getPMGClassIndex() { return pmg_class_index; } + + /** + * @param PMGClass_index. + */ + public final void setPMGClassIndex(int pmg_class_index) { + this.pmg_class_index = pmg_class_index; + } + + /** + * @return Index in constant pool of source file name. + */ + public final int getPMGIndex() { return pmg_index; } + + /** + * @param PMGClass_index. + */ + public final void setPMGIndex(int pmg_index) { + this.pmg_index = pmg_index; + } + + /** + * @return PMG name. + */ + public final String getPMGName() { + ConstantUtf8 c = (ConstantUtf8)constantPool.getConstant(pmg_index, + Constants.CONSTANT_Utf8); + return c.getBytes(); + } + + /** + * @return PMG class name. + */ + public final String getPMGClassName() { + ConstantUtf8 c = (ConstantUtf8)constantPool.getConstant(pmg_class_index, + Constants.CONSTANT_Utf8); + return c.getBytes(); + } + + /** + * @return String representation + */ + public final String toString() { + return "PMGClass(" + getPMGName() + ", " + getPMGClassName() + ")"; + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + return (PMGClass)clone(); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Signature.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Signature.java index bfeb6b566..8c8c5a1e4 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Signature.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Signature.java @@ -1,534 +1,534 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - * - * Extended by Adrian Colyer, June 2005 to support unpacking of Signature - * attribute - */ - - -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.Constants; - -/** - * This class is derived from Attribute and represents a reference - * to a GJ attribute. - * - * @version $Id: Signature.java,v 1.6.8.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see Attribute - */ -public final class Signature extends Attribute { - private int signature_index; - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use clone() for a physical copy. - */ - public Signature(Signature c) { - this(c.getNameIndex(), c.getLength(), c.getSignatureIndex(), c.getConstantPool()); - } - - /** - * Construct object from file stream. - * @param name_index Index in constant pool to CONSTANT_Utf8 - * @param length Content length in bytes - * @param file Input stream - * @param constant_pool Array of constants - * @throws IOException - */ - Signature(int name_index, int length, DataInputStream file, - ConstantPool constant_pool) throws IOException - { - this(name_index, length, file.readUnsignedShort(), constant_pool); - } - - /** - * @param name_index Index in constant pool to CONSTANT_Utf8 - * @param length Content length in bytes - * @param constant_pool Array of constants - * @param Signature_index Index in constant pool to CONSTANT_Utf8 - */ - public Signature(int name_index, int length, int signature_index, - ConstantPool constant_pool) - { - super(Constants.ATTR_SIGNATURE, name_index, length, constant_pool); - this.signature_index = signature_index; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - System.err.println("Visiting non-standard Signature object"); - v.visitSignature(this); - } - - /** - * Dump source file attribute to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - file.writeShort(signature_index); - } - - /** - * @return Index in constant pool of source file name. - */ - public final int getSignatureIndex() { return signature_index; } - - /** - * @param Signature_index. - */ - public final void setSignatureIndex(int signature_index) { - this.signature_index = signature_index; - } - - /** - * @return GJ signature. - */ - public final String getSignature() { - ConstantUtf8 c = (ConstantUtf8)constantPool.getConstant(signature_index, - Constants.CONSTANT_Utf8); - return c.getBytes(); - } - - /** - * Extends ByteArrayInputStream to make 'unreading' chars possible. - */ - private static final class MyByteArrayInputStream extends ByteArrayInputStream { - MyByteArrayInputStream(String data) { super(data.getBytes()); } - final int mark() { return pos; } - final String getData() { return new String(buf); } - final void reset(int p) { pos = p; } - final void unread() { if(pos > 0) pos--; } - } - - private static boolean identStart(int ch) { - return ch == 'T' || ch == 'L'; - } - - private static boolean identPart(int ch) { - return ch == '/' || ch == ';'; - } - - private static final void matchIdent(MyByteArrayInputStream in, StringBuffer buf) { - int ch; - - if((ch = in.read()) == -1) - throw new RuntimeException("Illegal signature: " + in.getData() + - " no ident, reaching EOF"); - - //System.out.println("return from ident:" + (char)ch); - - if(!identStart(ch)) { - StringBuffer buf2 = new StringBuffer(); - - int count = 1; - while(Character.isJavaIdentifierPart((char)ch)) { - buf2.append((char)ch); - count++; - ch = in.read(); - } - - if(ch == ':') { // Ok, formal parameter - in.skip("Ljava/lang/Object".length()); - buf.append(buf2); - - ch = in.read(); - in.unread(); - //System.out.println("so far:" + buf2 + ":next:" +(char)ch); - } else { - for(int i=0; i < count; i++) - in.unread(); - } - - return; - } - - StringBuffer buf2 = new StringBuffer(); - ch = in.read(); - - do { - buf2.append((char)ch); - ch = in.read(); - //System.out.println("within ident:"+ (char)ch); - - } while((ch != -1) && (Character.isJavaIdentifierPart((char)ch) || (ch == '/'))); - - buf.append(buf2.toString().replace('/', '.')); - - //System.out.println("regular return ident:"+ (char)ch + ":" + buf2); - - if(ch != -1) - in.unread(); - } - - private static final void matchGJIdent(MyByteArrayInputStream in, - StringBuffer buf) - { - int ch; - - matchIdent(in, buf); - - ch = in.read(); - if((ch == '<') || ch == '(') { // Parameterized or method - //System.out.println("Enter <"); - buf.append((char)ch); - matchGJIdent(in, buf); - - while(((ch = in.read()) != '>') && (ch != ')')) { // List of parameters - if(ch == -1) - throw new RuntimeException("Illegal signature: " + in.getData() + - " reaching EOF"); - - //System.out.println("Still no >"); - buf.append(", "); - in.unread(); - matchGJIdent(in, buf); // Recursive call - } - - //System.out.println("Exit >"); - - buf.append((char)ch); - } else - in.unread(); - - ch = in.read(); - if(identStart(ch)) { - in.unread(); - matchGJIdent(in, buf); - } else if(ch == ')') { - in.unread(); - return; - } else if(ch != ';') - throw new RuntimeException("Illegal signature: " + in.getData() + " read " + - (char)ch); - } - - public static String translate(String s) { - //System.out.println("Sig:" + s); - StringBuffer buf = new StringBuffer(); - - matchGJIdent(new MyByteArrayInputStream(s), buf); - - return buf.toString(); - } - - public static final boolean isFormalParameterList(String s) { - return s.startsWith("<") && (s.indexOf(':') > 0); - } - - public static final boolean isActualParameterList(String s) { - return s.startsWith("L") && s.endsWith(">;"); - } - - /** - * @return String representation - */ - public final String toString() { - String s = getSignature(); - - return "Signature(" + s + ")"; - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - return (Signature)clone(); - } - - // ============================================= - // AMC extensions - - private ClassSignature classSig; - private MethodTypeSignature methodSig; - private FieldTypeSignature fieldSig; - - public ClassSignature asClassSignature() { - if (classSig == null) { - GenericSignatureParser parser = new GenericSignatureParser(); - classSig = parser.parseAsClassSignature(getSignature()); - } - return classSig; - } - - public MethodTypeSignature asMethodTypeSignature() { - if (methodSig == null) { - GenericSignatureParser parser = new GenericSignatureParser(); - methodSig = parser.parseAsMethodSignature(getSignature()); - } - return methodSig; - } - - public FieldTypeSignature asFieldTypeSignature() { - if (fieldSig == null) { - GenericSignatureParser parser = new GenericSignatureParser(); - fieldSig = parser.parseAsFieldSignature(getSignature()); - } - return fieldSig; - } - - /** - * structure holding a parsed class signature - */ - public static class ClassSignature { - public FormalTypeParameter[] formalTypeParameters = new FormalTypeParameter[0]; - public ClassTypeSignature superclassSignature; - public ClassTypeSignature[] superInterfaceSignatures = new ClassTypeSignature[0]; - public String toString() { - StringBuffer ret = new StringBuffer(); - ret.append(formalTypeParameters.toString()); - ret.append(superclassSignature.toString()); - for (int i = 0; i < superInterfaceSignatures.length; i++) { - ret.append(superInterfaceSignatures[i].toString()); - } - return ret.toString(); - } - } - - public static class MethodTypeSignature { - public FormalTypeParameter[] formalTypeParameters = new FormalTypeParameter[0]; - public TypeSignature[] parameters = new TypeSignature[0]; - public TypeSignature returnType; - public FieldTypeSignature[] throwsSignatures = new FieldTypeSignature[0]; - - public MethodTypeSignature( - FormalTypeParameter[] aFormalParameterList, - TypeSignature[] aParameterList, - TypeSignature aReturnType, - FieldTypeSignature[] aThrowsSignatureList - ) { - this.formalTypeParameters = aFormalParameterList; - this.parameters = aParameterList; - this.returnType = aReturnType; - this.throwsSignatures = aThrowsSignatureList; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - if (formalTypeParameters.length > 0) { - sb.append("<"); - for (int i = 0; i < formalTypeParameters.length; i++) { - sb.append(formalTypeParameters[i].toString()); - } - sb.append(">"); - } - sb.append("("); - for (int i = 0; i < parameters.length; i++) { - sb.append(parameters[i].toString()); - } - sb.append(")"); - sb.append(returnType.toString()); - for (int i = 0; i < throwsSignatures.length; i++) { - sb.append("^"); - sb.append(throwsSignatures[i].toString()); - } - return sb.toString(); - } - } - - /** - * structure capturing a FormalTypeParameter from the Signature grammar - */ - public static class FormalTypeParameter { - public String identifier; - public FieldTypeSignature classBound; - public FieldTypeSignature[] interfaceBounds; - public String toString() { - StringBuffer ret = new StringBuffer(); - ret.append("T"); - ret.append(identifier); - ret.append(":"); - ret.append(classBound.toString()); - for (int i = 0; i < interfaceBounds.length; i++) { - ret.append(":"); - ret.append(interfaceBounds[i].toString()); - } - return ret.toString(); - } - } - - public static abstract class TypeSignature { - public boolean isBaseType() { return false; } - } - - public static class BaseTypeSignature extends TypeSignature { - private String sig; - public BaseTypeSignature(String aPrimitiveType) { - sig = aPrimitiveType; - } - public boolean isBaseType() { return true; } - public String toString() { - return sig; - } - } - - public static abstract class FieldTypeSignature extends TypeSignature { - public boolean isClassTypeSignature() { return false; } - public boolean isTypeVariableSignature() { return false; } - public boolean isArrayTypeSignature() { return false; } - } - - public static class ClassTypeSignature extends FieldTypeSignature { - public String classSignature; - public SimpleClassTypeSignature outerType; - public SimpleClassTypeSignature[] nestedTypes; - public ClassTypeSignature(String sig,String identifier) { - this.classSignature = sig; - this.outerType = new SimpleClassTypeSignature(identifier); - this.nestedTypes = new SimpleClassTypeSignature[0]; - } - public ClassTypeSignature(String sig, SimpleClassTypeSignature outer, SimpleClassTypeSignature[] inners) { - this.classSignature = sig; - this.outerType = outer; - this.nestedTypes = inners; - } - public boolean isClassTypeSignature() { return true; } - - public String toString() { - return classSignature; - } - } - - public static class TypeVariableSignature extends FieldTypeSignature { - public String typeVariableName; - public TypeVariableSignature(String typeVarToken) { - this.typeVariableName = typeVarToken.substring(1); - } - public boolean isTypeVariableSignature() { return true; } - public String toString() { - return "T" + typeVariableName + ";"; - } - } - - public static class ArrayTypeSignature extends FieldTypeSignature { - public TypeSignature typeSig; - public ArrayTypeSignature(TypeSignature aTypeSig) { - this.typeSig = aTypeSig; - } - public boolean isArrayTypeSignature() { return true; } - public String toString() { - return "[" + typeSig.toString(); - } - } - - public static class SimpleClassTypeSignature { - public String identifier; - public TypeArgument[] typeArguments; - - public SimpleClassTypeSignature(String identifier) { - this.identifier = identifier; - this.typeArguments = new TypeArgument[0]; - } - - public SimpleClassTypeSignature(String identifier, TypeArgument[] args) { - this.identifier = identifier; - this.typeArguments = args; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append(identifier); - if (typeArguments.length > 0) { - sb.append("<"); - for (int i = 0; i < typeArguments.length; i++) { - sb.append(typeArguments[i].toString()); - } - sb.append(">"); - } - return sb.toString(); - } - } - - public static class TypeArgument { - public boolean isWildcard = false; - public boolean isPlus = false; - public boolean isMinus = false; - public FieldTypeSignature signature; // null if isWildcard - - public TypeArgument() { - isWildcard = true; - } - - public TypeArgument(boolean plus, boolean minus, FieldTypeSignature aSig) { - this.isPlus = plus; - this.isMinus = minus; - this.signature = aSig; - } - - public String toString() { - if (isWildcard) return "*"; - StringBuffer sb = new StringBuffer(); - if (isPlus) sb.append("+"); - if (isMinus) sb.append("-"); - sb.append(signature.toString()); - return sb.toString(); - } - } - -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Extended by Adrian Colyer, June 2005 to support unpacking of Signature + * attribute + */ + + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import org.aspectj.apache.bcel.Constants; + +/** + * This class is derived from Attribute and represents a reference + * to a GJ attribute. + * + * @version $Id: Signature.java,v 1.6.8.3 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + * @see Attribute + */ +public final class Signature extends Attribute { + private int signature_index; + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use clone() for a physical copy. + */ + public Signature(Signature c) { + this(c.getNameIndex(), c.getLength(), c.getSignatureIndex(), c.getConstantPool()); + } + + /** + * Construct object from file stream. + * @param name_index Index in constant pool to CONSTANT_Utf8 + * @param length Content length in bytes + * @param file Input stream + * @param constant_pool Array of constants + * @throws IOException + */ + Signature(int name_index, int length, DataInputStream file, + ConstantPool constant_pool) throws IOException + { + this(name_index, length, file.readUnsignedShort(), constant_pool); + } + + /** + * @param name_index Index in constant pool to CONSTANT_Utf8 + * @param length Content length in bytes + * @param constant_pool Array of constants + * @param Signature_index Index in constant pool to CONSTANT_Utf8 + */ + public Signature(int name_index, int length, int signature_index, + ConstantPool constant_pool) + { + super(Constants.ATTR_SIGNATURE, name_index, length, constant_pool); + this.signature_index = signature_index; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + System.err.println("Visiting non-standard Signature object"); + v.visitSignature(this); + } + + /** + * Dump source file attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + file.writeShort(signature_index); + } + + /** + * @return Index in constant pool of source file name. + */ + public final int getSignatureIndex() { return signature_index; } + + /** + * @param Signature_index. + */ + public final void setSignatureIndex(int signature_index) { + this.signature_index = signature_index; + } + + /** + * @return GJ signature. + */ + public final String getSignature() { + ConstantUtf8 c = (ConstantUtf8)constantPool.getConstant(signature_index, + Constants.CONSTANT_Utf8); + return c.getBytes(); + } + + /** + * Extends ByteArrayInputStream to make 'unreading' chars possible. + */ + private static final class MyByteArrayInputStream extends ByteArrayInputStream { + MyByteArrayInputStream(String data) { super(data.getBytes()); } + final int mark() { return pos; } + final String getData() { return new String(buf); } + final void reset(int p) { pos = p; } + final void unread() { if(pos > 0) pos--; } + } + + private static boolean identStart(int ch) { + return ch == 'T' || ch == 'L'; + } + + private static boolean identPart(int ch) { + return ch == '/' || ch == ';'; + } + + private static final void matchIdent(MyByteArrayInputStream in, StringBuffer buf) { + int ch; + + if((ch = in.read()) == -1) + throw new RuntimeException("Illegal signature: " + in.getData() + + " no ident, reaching EOF"); + + //System.out.println("return from ident:" + (char)ch); + + if(!identStart(ch)) { + StringBuffer buf2 = new StringBuffer(); + + int count = 1; + while(Character.isJavaIdentifierPart((char)ch)) { + buf2.append((char)ch); + count++; + ch = in.read(); + } + + if(ch == ':') { // Ok, formal parameter + in.skip("Ljava/lang/Object".length()); + buf.append(buf2); + + ch = in.read(); + in.unread(); + //System.out.println("so far:" + buf2 + ":next:" +(char)ch); + } else { + for(int i=0; i < count; i++) + in.unread(); + } + + return; + } + + StringBuffer buf2 = new StringBuffer(); + ch = in.read(); + + do { + buf2.append((char)ch); + ch = in.read(); + //System.out.println("within ident:"+ (char)ch); + + } while((ch != -1) && (Character.isJavaIdentifierPart((char)ch) || (ch == '/'))); + + buf.append(buf2.toString().replace('/', '.')); + + //System.out.println("regular return ident:"+ (char)ch + ":" + buf2); + + if(ch != -1) + in.unread(); + } + + private static final void matchGJIdent(MyByteArrayInputStream in, + StringBuffer buf) + { + int ch; + + matchIdent(in, buf); + + ch = in.read(); + if((ch == '<') || ch == '(') { // Parameterized or method + //System.out.println("Enter <"); + buf.append((char)ch); + matchGJIdent(in, buf); + + while(((ch = in.read()) != '>') && (ch != ')')) { // List of parameters + if(ch == -1) + throw new RuntimeException("Illegal signature: " + in.getData() + + " reaching EOF"); + + //System.out.println("Still no >"); + buf.append(", "); + in.unread(); + matchGJIdent(in, buf); // Recursive call + } + + //System.out.println("Exit >"); + + buf.append((char)ch); + } else + in.unread(); + + ch = in.read(); + if(identStart(ch)) { + in.unread(); + matchGJIdent(in, buf); + } else if(ch == ')') { + in.unread(); + return; + } else if(ch != ';') + throw new RuntimeException("Illegal signature: " + in.getData() + " read " + + (char)ch); + } + + public static String translate(String s) { + //System.out.println("Sig:" + s); + StringBuffer buf = new StringBuffer(); + + matchGJIdent(new MyByteArrayInputStream(s), buf); + + return buf.toString(); + } + + public static final boolean isFormalParameterList(String s) { + return s.startsWith("<") && (s.indexOf(':') > 0); + } + + public static final boolean isActualParameterList(String s) { + return s.startsWith("L") && s.endsWith(">;"); + } + + /** + * @return String representation + */ + public final String toString() { + String s = getSignature(); + + return "Signature(" + s + ")"; + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + return (Signature)clone(); + } + + // ============================================= + // AMC extensions + + private ClassSignature classSig; + private MethodTypeSignature methodSig; + private FieldTypeSignature fieldSig; + + public ClassSignature asClassSignature() { + if (classSig == null) { + GenericSignatureParser parser = new GenericSignatureParser(); + classSig = parser.parseAsClassSignature(getSignature()); + } + return classSig; + } + + public MethodTypeSignature asMethodTypeSignature() { + if (methodSig == null) { + GenericSignatureParser parser = new GenericSignatureParser(); + methodSig = parser.parseAsMethodSignature(getSignature()); + } + return methodSig; + } + + public FieldTypeSignature asFieldTypeSignature() { + if (fieldSig == null) { + GenericSignatureParser parser = new GenericSignatureParser(); + fieldSig = parser.parseAsFieldSignature(getSignature()); + } + return fieldSig; + } + + /** + * structure holding a parsed class signature + */ + public static class ClassSignature { + public FormalTypeParameter[] formalTypeParameters = new FormalTypeParameter[0]; + public ClassTypeSignature superclassSignature; + public ClassTypeSignature[] superInterfaceSignatures = new ClassTypeSignature[0]; + public String toString() { + StringBuffer ret = new StringBuffer(); + ret.append(formalTypeParameters.toString()); + ret.append(superclassSignature.toString()); + for (int i = 0; i < superInterfaceSignatures.length; i++) { + ret.append(superInterfaceSignatures[i].toString()); + } + return ret.toString(); + } + } + + public static class MethodTypeSignature { + public FormalTypeParameter[] formalTypeParameters = new FormalTypeParameter[0]; + public TypeSignature[] parameters = new TypeSignature[0]; + public TypeSignature returnType; + public FieldTypeSignature[] throwsSignatures = new FieldTypeSignature[0]; + + public MethodTypeSignature( + FormalTypeParameter[] aFormalParameterList, + TypeSignature[] aParameterList, + TypeSignature aReturnType, + FieldTypeSignature[] aThrowsSignatureList + ) { + this.formalTypeParameters = aFormalParameterList; + this.parameters = aParameterList; + this.returnType = aReturnType; + this.throwsSignatures = aThrowsSignatureList; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + if (formalTypeParameters.length > 0) { + sb.append("<"); + for (int i = 0; i < formalTypeParameters.length; i++) { + sb.append(formalTypeParameters[i].toString()); + } + sb.append(">"); + } + sb.append("("); + for (int i = 0; i < parameters.length; i++) { + sb.append(parameters[i].toString()); + } + sb.append(")"); + sb.append(returnType.toString()); + for (int i = 0; i < throwsSignatures.length; i++) { + sb.append("^"); + sb.append(throwsSignatures[i].toString()); + } + return sb.toString(); + } + } + + /** + * structure capturing a FormalTypeParameter from the Signature grammar + */ + public static class FormalTypeParameter { + public String identifier; + public FieldTypeSignature classBound; + public FieldTypeSignature[] interfaceBounds; + public String toString() { + StringBuffer ret = new StringBuffer(); + ret.append("T"); + ret.append(identifier); + ret.append(":"); + ret.append(classBound.toString()); + for (int i = 0; i < interfaceBounds.length; i++) { + ret.append(":"); + ret.append(interfaceBounds[i].toString()); + } + return ret.toString(); + } + } + + public static abstract class TypeSignature { + public boolean isBaseType() { return false; } + } + + public static class BaseTypeSignature extends TypeSignature { + private String sig; + public BaseTypeSignature(String aPrimitiveType) { + sig = aPrimitiveType; + } + public boolean isBaseType() { return true; } + public String toString() { + return sig; + } + } + + public static abstract class FieldTypeSignature extends TypeSignature { + public boolean isClassTypeSignature() { return false; } + public boolean isTypeVariableSignature() { return false; } + public boolean isArrayTypeSignature() { return false; } + } + + public static class ClassTypeSignature extends FieldTypeSignature { + public String classSignature; + public SimpleClassTypeSignature outerType; + public SimpleClassTypeSignature[] nestedTypes; + public ClassTypeSignature(String sig,String identifier) { + this.classSignature = sig; + this.outerType = new SimpleClassTypeSignature(identifier); + this.nestedTypes = new SimpleClassTypeSignature[0]; + } + public ClassTypeSignature(String sig, SimpleClassTypeSignature outer, SimpleClassTypeSignature[] inners) { + this.classSignature = sig; + this.outerType = outer; + this.nestedTypes = inners; + } + public boolean isClassTypeSignature() { return true; } + + public String toString() { + return classSignature; + } + } + + public static class TypeVariableSignature extends FieldTypeSignature { + public String typeVariableName; + public TypeVariableSignature(String typeVarToken) { + this.typeVariableName = typeVarToken.substring(1); + } + public boolean isTypeVariableSignature() { return true; } + public String toString() { + return "T" + typeVariableName + ";"; + } + } + + public static class ArrayTypeSignature extends FieldTypeSignature { + public TypeSignature typeSig; + public ArrayTypeSignature(TypeSignature aTypeSig) { + this.typeSig = aTypeSig; + } + public boolean isArrayTypeSignature() { return true; } + public String toString() { + return "[" + typeSig.toString(); + } + } + + public static class SimpleClassTypeSignature { + public String identifier; + public TypeArgument[] typeArguments; + + public SimpleClassTypeSignature(String identifier) { + this.identifier = identifier; + this.typeArguments = new TypeArgument[0]; + } + + public SimpleClassTypeSignature(String identifier, TypeArgument[] args) { + this.identifier = identifier; + this.typeArguments = args; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append(identifier); + if (typeArguments.length > 0) { + sb.append("<"); + for (int i = 0; i < typeArguments.length; i++) { + sb.append(typeArguments[i].toString()); + } + sb.append(">"); + } + return sb.toString(); + } + } + + public static class TypeArgument { + public boolean isWildcard = false; + public boolean isPlus = false; + public boolean isMinus = false; + public FieldTypeSignature signature; // null if isWildcard + + public TypeArgument() { + isWildcard = true; + } + + public TypeArgument(boolean plus, boolean minus, FieldTypeSignature aSig) { + this.isPlus = plus; + this.isMinus = minus; + this.signature = aSig; + } + + public String toString() { + if (isWildcard) return "*"; + StringBuffer sb = new StringBuffer(); + if (isPlus) sb.append("+"); + if (isMinus) sb.append("-"); + sb.append(signature.toString()); + return sb.toString(); + } + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/SourceFile.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/SourceFile.java index 87177a838..31691e693 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/SourceFile.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/SourceFile.java @@ -1,173 +1,173 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class is derived from Attribute and represents a reference - * to the source file of this class. At most one SourceFile attribute - * should appear per classfile. The intention of this class is that it is - * instantiated from the Attribute.readAttribute() method. - * - * @version $Id: SourceFile.java,v 1.2.10.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see Attribute - */ -public final class SourceFile extends Attribute { - private int sourcefile_index; - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use clone() for a physical copy. - */ - public SourceFile(SourceFile c) { - this(c.getNameIndex(), c.getLength(), c.getSourceFileIndex(), - c.getConstantPool()); - } - - /** - * Construct object from file stream. - * @param name_index Index in constant pool to CONSTANT_Utf8 - * @param length Content length in bytes - * @param file Input stream - * @param constant_pool Array of constants - * @throws IOException - */ - SourceFile(int name_index, int length, DataInputStream file, - ConstantPool constant_pool) throws IOException - { - this(name_index, length, file.readUnsignedShort(), constant_pool); - } - - /** - * @param name_index Index in constant pool to CONSTANT_Utf8, which - * should represent the string "SourceFile". - * @param length Content length in bytes, the value should be 2. - * @param constant_pool The constant pool that this attribute is - * associated with. - * @param sourcefile_index Index in constant pool to CONSTANT_Utf8. This - * string will be interpreted as the name of the file from which this - * class was compiled. It will not be interpreted as indicating the name - * of the directory contqining the file or an absolute path; this - * information has to be supplied the consumer of this attribute - in - * many cases, the JVM. - */ - public SourceFile(int name_index, int length, int sourcefile_index, - ConstantPool constant_pool) - { - super(Constants.ATTR_SOURCE_FILE, name_index, length, constant_pool); - this.sourcefile_index = sourcefile_index; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitSourceFile(this); - } - - /** - * Dump source file attribute to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - file.writeShort(sourcefile_index); - } - - /** - * @return Index in constant pool of source file name. - */ - public final int getSourceFileIndex() { return sourcefile_index; } - - /** - * @param sourcefile_index. - */ - public final void setSourceFileIndex(int sourcefile_index) { - this.sourcefile_index = sourcefile_index; - } - - /** - * @return Source file name. - */ - public final String getSourceFileName() { - ConstantUtf8 c = (ConstantUtf8)constantPool.getConstant(sourcefile_index, - Constants.CONSTANT_Utf8); - return c.getBytes(); - } - - /** - * @return String representation - */ - public final String toString() { - return "SourceFile(" + getSourceFileName() + ")"; - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - return (SourceFile)clone(); - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class is derived from Attribute and represents a reference + * to the source file of this class. At most one SourceFile attribute + * should appear per classfile. The intention of this class is that it is + * instantiated from the Attribute.readAttribute() method. + * + * @version $Id: SourceFile.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Attribute + */ +public final class SourceFile extends Attribute { + private int sourcefile_index; + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use clone() for a physical copy. + */ + public SourceFile(SourceFile c) { + this(c.getNameIndex(), c.getLength(), c.getSourceFileIndex(), + c.getConstantPool()); + } + + /** + * Construct object from file stream. + * @param name_index Index in constant pool to CONSTANT_Utf8 + * @param length Content length in bytes + * @param file Input stream + * @param constant_pool Array of constants + * @throws IOException + */ + SourceFile(int name_index, int length, DataInputStream file, + ConstantPool constant_pool) throws IOException + { + this(name_index, length, file.readUnsignedShort(), constant_pool); + } + + /** + * @param name_index Index in constant pool to CONSTANT_Utf8, which + * should represent the string "SourceFile". + * @param length Content length in bytes, the value should be 2. + * @param constant_pool The constant pool that this attribute is + * associated with. + * @param sourcefile_index Index in constant pool to CONSTANT_Utf8. This + * string will be interpreted as the name of the file from which this + * class was compiled. It will not be interpreted as indicating the name + * of the directory contqining the file or an absolute path; this + * information has to be supplied the consumer of this attribute - in + * many cases, the JVM. + */ + public SourceFile(int name_index, int length, int sourcefile_index, + ConstantPool constant_pool) + { + super(Constants.ATTR_SOURCE_FILE, name_index, length, constant_pool); + this.sourcefile_index = sourcefile_index; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitSourceFile(this); + } + + /** + * Dump source file attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + file.writeShort(sourcefile_index); + } + + /** + * @return Index in constant pool of source file name. + */ + public final int getSourceFileIndex() { return sourcefile_index; } + + /** + * @param sourcefile_index. + */ + public final void setSourceFileIndex(int sourcefile_index) { + this.sourcefile_index = sourcefile_index; + } + + /** + * @return Source file name. + */ + public final String getSourceFileName() { + ConstantUtf8 c = (ConstantUtf8)constantPool.getConstant(sourcefile_index, + Constants.CONSTANT_Utf8); + return c.getBytes(); + } + + /** + * @return String representation + */ + public final String toString() { + return "SourceFile(" + getSourceFileName() + ")"; + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + return (SourceFile)clone(); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMap.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMap.java index d63486cbc..e805a56d7 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMap.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMap.java @@ -1,185 +1,185 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents a stack map attribute used for - * preverification of Java classes for the Java 2 Micro Edition - * (J2ME). This attribute is used by the KVM and contained - * within the Code attribute of a method. See CLDC specification - * §5.3.1.2 - * - * @version $Id: StackMap.java,v 1.2.10.2 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see Code - * @see StackMapEntry - * @see StackMapType - */ -public final class StackMap extends Attribute implements Node { - private int map_length; - private StackMapEntry[] map; // Table of stack map entries - - /* - * @param name_index Index of name - * @param length Content length in bytes - * @param map Table of stack map entries - * @param constant_pool Array of constants - */ - public StackMap(int name_index, int length, StackMapEntry[] map, - ConstantPool constant_pool) - { - super(Constants.ATTR_STACK_MAP, name_index, length, constant_pool); - - setStackMap(map); - } - - /** - * Construct object from file stream. - * @param name_index Index of name - * @param length Content length in bytes - * @param file Input stream - * @throws IOException - * @param constant_pool Array of constants - */ - StackMap(int name_index, int length, DataInputStream file, - ConstantPool constant_pool) throws IOException - { - this(name_index, length, (StackMapEntry[])null, constant_pool); - - map_length = file.readUnsignedShort(); - map = new StackMapEntry[map_length]; - - for(int i=0; i < map_length; i++) - map[i] = new StackMapEntry(file, constant_pool); - } - - /** - * Dump line number table attribute to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - file.writeShort(map_length); - for(int i=0; i < map_length; i++) - map[i].dump(file); - } - - /** - * @return Array of stack map entries - */ - public final StackMapEntry[] getStackMap() { return map; } - - /** - * @param map Array of stack map entries - */ - public final void setStackMap(StackMapEntry[] map) { - this.map = map; - - map_length = (map == null)? 0 : map.length; - } - - /** - * @return String representation. - */ - public final String toString() { - StringBuffer buf = new StringBuffer("StackMap("); - - for(int i=0; i < map_length; i++) { - buf.append(map[i].toString()); - - if(i < map_length - 1) - buf.append(", "); - } - - buf.append(')'); - - return buf.toString(); - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - StackMap c = (StackMap)clone(); - - c.map = new StackMapEntry[map_length]; - for(int i=0; i < map_length; i++) - c.map[i] = map[i].copy(); - - c.constantPool = constant_pool; - return c; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackMap(this); - } - - public final int getMapLength() { return map_length; } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents a stack map attribute used for + * preverification of Java classes for the Java 2 Micro Edition + * (J2ME). This attribute is used by the KVM and contained + * within the Code attribute of a method. See CLDC specification + * §5.3.1.2 + * + * @version $Id: StackMap.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see Code + * @see StackMapEntry + * @see StackMapType + */ +public final class StackMap extends Attribute implements Node { + private int map_length; + private StackMapEntry[] map; // Table of stack map entries + + /* + * @param name_index Index of name + * @param length Content length in bytes + * @param map Table of stack map entries + * @param constant_pool Array of constants + */ + public StackMap(int name_index, int length, StackMapEntry[] map, + ConstantPool constant_pool) + { + super(Constants.ATTR_STACK_MAP, name_index, length, constant_pool); + + setStackMap(map); + } + + /** + * Construct object from file stream. + * @param name_index Index of name + * @param length Content length in bytes + * @param file Input stream + * @throws IOException + * @param constant_pool Array of constants + */ + StackMap(int name_index, int length, DataInputStream file, + ConstantPool constant_pool) throws IOException + { + this(name_index, length, (StackMapEntry[])null, constant_pool); + + map_length = file.readUnsignedShort(); + map = new StackMapEntry[map_length]; + + for(int i=0; i < map_length; i++) + map[i] = new StackMapEntry(file, constant_pool); + } + + /** + * Dump line number table attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + file.writeShort(map_length); + for(int i=0; i < map_length; i++) + map[i].dump(file); + } + + /** + * @return Array of stack map entries + */ + public final StackMapEntry[] getStackMap() { return map; } + + /** + * @param map Array of stack map entries + */ + public final void setStackMap(StackMapEntry[] map) { + this.map = map; + + map_length = (map == null)? 0 : map.length; + } + + /** + * @return String representation. + */ + public final String toString() { + StringBuffer buf = new StringBuffer("StackMap("); + + for(int i=0; i < map_length; i++) { + buf.append(map[i].toString()); + + if(i < map_length - 1) + buf.append(", "); + } + + buf.append(')'); + + return buf.toString(); + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + StackMap c = (StackMap)clone(); + + c.map = new StackMapEntry[map_length]; + for(int i=0; i < map_length; i++) + c.map[i] = map[i].copy(); + + c.constantPool = constant_pool; + return c; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitStackMap(this); + } + + public final int getMapLength() { return map_length; } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMapEntry.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMapEntry.java index 35b6117a1..1416eb9fe 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMapEntry.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMapEntry.java @@ -1,210 +1,210 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -/** - * This class represents a stack map entry recording the types of - * local variables and the the of stack items at a given byte code offset. - * See CLDC specification §5.3.1.2 - * - * @version $Id: StackMapEntry.java,v 1.4.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see StackMap - * @see StackMapType - */ -public final class StackMapEntry implements Cloneable { - private int byte_code_offset; - private int number_of_locals; - private StackMapType[] types_of_locals; - private int number_of_stack_items; - private StackMapType[] types_of_stack_items; - private ConstantPool constant_pool; - - /** - * Construct object from file stream. - * @param file Input stream - * @throws IOException - */ - StackMapEntry(DataInputStream file, ConstantPool constant_pool) throws IOException - { - this(file.readShort(), file.readShort(), null, -1, null, constant_pool); - - types_of_locals = new StackMapType[number_of_locals]; - for(int i=0; i < number_of_locals; i++) - types_of_locals[i] = new StackMapType(file, constant_pool); - - number_of_stack_items = file.readShort(); - types_of_stack_items = new StackMapType[number_of_stack_items]; - for(int i=0; i < number_of_stack_items; i++) - types_of_stack_items[i] = new StackMapType(file, constant_pool); - } - - public StackMapEntry(int byte_code_offset, int number_of_locals, - StackMapType[] types_of_locals, - int number_of_stack_items, - StackMapType[] types_of_stack_items, - ConstantPool constant_pool) { - this.byte_code_offset = byte_code_offset; - this.number_of_locals = number_of_locals; - this.types_of_locals = types_of_locals; - this.number_of_stack_items = number_of_stack_items; - this.types_of_stack_items = types_of_stack_items; - this.constant_pool = constant_pool; - } - - /** - * Dump stack map entry - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeShort(byte_code_offset); - - file.writeShort(number_of_locals); - for(int i=0; i < number_of_locals; i++) - types_of_locals[i].dump(file); - - file.writeShort(number_of_stack_items); - for(int i=0; i < number_of_stack_items; i++) - types_of_stack_items[i].dump(file); - } - - /** - * @return String representation. - */ - public final String toString() { - StringBuffer buf = new StringBuffer("(offset=" + byte_code_offset); - - if(number_of_locals > 0) { - buf.append(", locals={"); - - for(int i=0; i < number_of_locals; i++) { - buf.append(types_of_locals[i]); - if(i < number_of_locals - 1) - buf.append(", "); - } - - buf.append("}"); - } - - if(number_of_stack_items > 0) { - buf.append(", stack items={"); - - for(int i=0; i < number_of_stack_items; i++) { - buf.append(types_of_stack_items[i]); - if(i < number_of_stack_items - 1) - buf.append(", "); - } - - buf.append("}"); - } - - buf.append(")"); - - return buf.toString(); - } - - - public void setByteCodeOffset(int b) { byte_code_offset = b; } - public int getByteCodeOffset() { return byte_code_offset; } - public void setNumberOfLocals(int n) { number_of_locals = n; } - public int getNumberOfLocals() { return number_of_locals; } - public void setTypesOfLocals(StackMapType[] t) { types_of_locals = t; } - public StackMapType[] getTypesOfLocals() { return types_of_locals; } - public void setNumberOfStackItems(int n) { number_of_stack_items = n; } - public int getNumberOfStackItems() { return number_of_stack_items; } - public void setTypesOfStackItems(StackMapType[] t) { types_of_stack_items = t; } - public StackMapType[] getTypesOfStackItems() { return types_of_stack_items; } - - /** - * @return deep copy of this object - */ - public StackMapEntry copy() { - try { - return (StackMapEntry)clone(); - } catch(CloneNotSupportedException e) {} - - return null; - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackMapEntry(this); - } - - /** - * @return Constant pool used by this object. - */ - public final ConstantPool getConstantPool() { return constant_pool; } - - /** - * @param constant_pool Constant pool to be used for this object. - */ - public final void setConstantPool(ConstantPool constant_pool) { - this.constant_pool = constant_pool; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * This class represents a stack map entry recording the types of + * local variables and the the of stack items at a given byte code offset. + * See CLDC specification §5.3.1.2 + * + * @version $Id: StackMapEntry.java,v 1.4.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see StackMap + * @see StackMapType + */ +public final class StackMapEntry implements Cloneable { + private int byte_code_offset; + private int number_of_locals; + private StackMapType[] types_of_locals; + private int number_of_stack_items; + private StackMapType[] types_of_stack_items; + private ConstantPool constant_pool; + + /** + * Construct object from file stream. + * @param file Input stream + * @throws IOException + */ + StackMapEntry(DataInputStream file, ConstantPool constant_pool) throws IOException + { + this(file.readShort(), file.readShort(), null, -1, null, constant_pool); + + types_of_locals = new StackMapType[number_of_locals]; + for(int i=0; i < number_of_locals; i++) + types_of_locals[i] = new StackMapType(file, constant_pool); + + number_of_stack_items = file.readShort(); + types_of_stack_items = new StackMapType[number_of_stack_items]; + for(int i=0; i < number_of_stack_items; i++) + types_of_stack_items[i] = new StackMapType(file, constant_pool); + } + + public StackMapEntry(int byte_code_offset, int number_of_locals, + StackMapType[] types_of_locals, + int number_of_stack_items, + StackMapType[] types_of_stack_items, + ConstantPool constant_pool) { + this.byte_code_offset = byte_code_offset; + this.number_of_locals = number_of_locals; + this.types_of_locals = types_of_locals; + this.number_of_stack_items = number_of_stack_items; + this.types_of_stack_items = types_of_stack_items; + this.constant_pool = constant_pool; + } + + /** + * Dump stack map entry + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeShort(byte_code_offset); + + file.writeShort(number_of_locals); + for(int i=0; i < number_of_locals; i++) + types_of_locals[i].dump(file); + + file.writeShort(number_of_stack_items); + for(int i=0; i < number_of_stack_items; i++) + types_of_stack_items[i].dump(file); + } + + /** + * @return String representation. + */ + public final String toString() { + StringBuffer buf = new StringBuffer("(offset=" + byte_code_offset); + + if(number_of_locals > 0) { + buf.append(", locals={"); + + for(int i=0; i < number_of_locals; i++) { + buf.append(types_of_locals[i]); + if(i < number_of_locals - 1) + buf.append(", "); + } + + buf.append("}"); + } + + if(number_of_stack_items > 0) { + buf.append(", stack items={"); + + for(int i=0; i < number_of_stack_items; i++) { + buf.append(types_of_stack_items[i]); + if(i < number_of_stack_items - 1) + buf.append(", "); + } + + buf.append("}"); + } + + buf.append(")"); + + return buf.toString(); + } + + + public void setByteCodeOffset(int b) { byte_code_offset = b; } + public int getByteCodeOffset() { return byte_code_offset; } + public void setNumberOfLocals(int n) { number_of_locals = n; } + public int getNumberOfLocals() { return number_of_locals; } + public void setTypesOfLocals(StackMapType[] t) { types_of_locals = t; } + public StackMapType[] getTypesOfLocals() { return types_of_locals; } + public void setNumberOfStackItems(int n) { number_of_stack_items = n; } + public int getNumberOfStackItems() { return number_of_stack_items; } + public void setTypesOfStackItems(StackMapType[] t) { types_of_stack_items = t; } + public StackMapType[] getTypesOfStackItems() { return types_of_stack_items; } + + /** + * @return deep copy of this object + */ + public StackMapEntry copy() { + try { + return (StackMapEntry)clone(); + } catch(CloneNotSupportedException e) {} + + return null; + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitStackMapEntry(this); + } + + /** + * @return Constant pool used by this object. + */ + public final ConstantPool getConstantPool() { return constant_pool; } + + /** + * @param constant_pool Constant pool to be used for this object. + */ + public final void setConstantPool(ConstantPool constant_pool) { + this.constant_pool = constant_pool; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMapType.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMapType.java index a57764ceb..f4dc6c804 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMapType.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMapType.java @@ -1,172 +1,172 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents the type of a local variable or item on stack - * used in the StackMap entries. - * - * @version $Id: StackMapType.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author M. Dahm - * @see StackMapEntry - * @see StackMap - * @see Constants - */ -public final class StackMapType implements Cloneable { - private byte type; - private int index = -1; // Index to CONSTANT_Class or offset - private ConstantPool constant_pool; - - /** - * Construct object from file stream. - * @param file Input stream - * @throws IOException - */ - StackMapType(DataInputStream file, ConstantPool constant_pool) throws IOException - { - this(file.readByte(), -1, constant_pool); - - if(hasIndex()) - setIndex(file.readShort()); - - setConstantPool(constant_pool); - } - - /** - * @param type type tag as defined in the Constants interface - * @param index index to constant pool, or byte code offset - */ - public StackMapType(byte type, int index, ConstantPool constant_pool) { - setType(type); - setIndex(index); - setConstantPool(constant_pool); - } - - public void setType(byte t) { - if((t < Constants.ITEM_Bogus) || (t > Constants.ITEM_NewObject)) - throw new RuntimeException("Illegal type for StackMapType: " + t); - type = t; - } - - public byte getType() { return type; } - public void setIndex(int t) { index = t; } - - /** @return index to constant pool if type == ITEM_Object, or offset - * in byte code, if type == ITEM_NewObject, and -1 otherwise - */ - public int getIndex() { return index; } - - /** - * Dump type entries to file. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - file.writeByte(type); - if(hasIndex()) - file.writeShort(getIndex()); - } - - /** @return true, if type is either ITEM_Object or ITEM_NewObject - */ - public final boolean hasIndex() { - return ((type == Constants.ITEM_Object) || - (type == Constants.ITEM_NewObject)); - } - - private String printIndex() { - if(type == Constants.ITEM_Object) - return ", class=" + constant_pool.constantToString(index, Constants.CONSTANT_Class); - else if(type == Constants.ITEM_NewObject) - return ", offset=" + index; - else - return ""; - } - - /** - * @return String representation - */ - public final String toString() { - return "(type=" + Constants.ITEM_NAMES[type] + printIndex() + ")"; - } - - /** - * @return deep copy of this object - */ - public StackMapType copy() { - try { - return (StackMapType)clone(); - } catch(CloneNotSupportedException e) {} - - return null; - } - - /** - * @return Constant pool used by this object. - */ - public final ConstantPool getConstantPool() { return constant_pool; } - - /** - * @param constant_pool Constant pool to be used for this object. - */ - public final void setConstantPool(ConstantPool constant_pool) { - this.constant_pool = constant_pool; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents the type of a local variable or item on stack + * used in the StackMap entries. + * + * @version $Id: StackMapType.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see StackMapEntry + * @see StackMap + * @see Constants + */ +public final class StackMapType implements Cloneable { + private byte type; + private int index = -1; // Index to CONSTANT_Class or offset + private ConstantPool constant_pool; + + /** + * Construct object from file stream. + * @param file Input stream + * @throws IOException + */ + StackMapType(DataInputStream file, ConstantPool constant_pool) throws IOException + { + this(file.readByte(), -1, constant_pool); + + if(hasIndex()) + setIndex(file.readShort()); + + setConstantPool(constant_pool); + } + + /** + * @param type type tag as defined in the Constants interface + * @param index index to constant pool, or byte code offset + */ + public StackMapType(byte type, int index, ConstantPool constant_pool) { + setType(type); + setIndex(index); + setConstantPool(constant_pool); + } + + public void setType(byte t) { + if((t < Constants.ITEM_Bogus) || (t > Constants.ITEM_NewObject)) + throw new RuntimeException("Illegal type for StackMapType: " + t); + type = t; + } + + public byte getType() { return type; } + public void setIndex(int t) { index = t; } + + /** @return index to constant pool if type == ITEM_Object, or offset + * in byte code, if type == ITEM_NewObject, and -1 otherwise + */ + public int getIndex() { return index; } + + /** + * Dump type entries to file. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + file.writeByte(type); + if(hasIndex()) + file.writeShort(getIndex()); + } + + /** @return true, if type is either ITEM_Object or ITEM_NewObject + */ + public final boolean hasIndex() { + return ((type == Constants.ITEM_Object) || + (type == Constants.ITEM_NewObject)); + } + + private String printIndex() { + if(type == Constants.ITEM_Object) + return ", class=" + constant_pool.constantToString(index, Constants.CONSTANT_Class); + else if(type == Constants.ITEM_NewObject) + return ", offset=" + index; + else + return ""; + } + + /** + * @return String representation + */ + public final String toString() { + return "(type=" + Constants.ITEM_NAMES[type] + printIndex() + ")"; + } + + /** + * @return deep copy of this object + */ + public StackMapType copy() { + try { + return (StackMapType)clone(); + } catch(CloneNotSupportedException e) {} + + return null; + } + + /** + * @return Constant pool used by this object. + */ + public final ConstantPool getConstantPool() { return constant_pool; } + + /** + * @param constant_pool Constant pool to be used for this object. + */ + public final void setConstantPool(ConstantPool constant_pool) { + this.constant_pool = constant_pool; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Synthetic.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Synthetic.java index 1aebe7685..39dd2f236 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Synthetic.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Synthetic.java @@ -1,184 +1,184 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; - -import java.io.*; - -/** - * This class is derived from Attribute and declares this class as - * `synthetic', i.e., it needs special handling. The JVM specification - * states "A class member that does not appear in the source code must be - * marked using a Synthetic attribute." It may appear in the ClassFile - * attribute table, a field_info table or a method_info table. This class - * is intended to be instantiated from the - * Attribute.readAttribute() method. - * - * @version $Id: Synthetic.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see Attribute - */ -public final class Synthetic extends Attribute { - private byte[] bytes; - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use copy() for a physical copy. - */ - public Synthetic(Synthetic c) { - this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool()); - } -// -// public Synthetic(ConstantPoolGen cpool) { -// super(Constants.ATTR_SYNTHETIC, cpool.addUtf8("Synthetic"), 0, cpool); -// ConstantPoolGen cpg = myGen.getConstantPool(); -// int index = ; -// Attribute synthetic = new Synthetic(index, 0, new byte[0], cpg.getConstantPool()); -// } - - /** - * @param name_index Index in constant pool to CONSTANT_Utf8, which - * should represent the string "Synthetic". - * @param length Content length in bytes - should be zero. - * @param bytes Attribute contents - * @param constant_pool The constant pool this attribute is associated - * with. - */ - public Synthetic(int name_index, int length, byte[] bytes, - ConstantPool constant_pool) - { - super(Constants.ATTR_SYNTHETIC, name_index, length, constant_pool); - this.bytes = bytes; - } - - /** - * Construct object from file stream. - * @param name_index Index in constant pool to CONSTANT_Utf8 - * @param length Content length in bytes - * @param file Input stream - * @param constant_pool Array of constants - * @throws IOException - */ - Synthetic(int name_index, int length, DataInputStream file, - ConstantPool constant_pool) throws IOException - { - this(name_index, length, (byte [])null, constant_pool); - - if(length > 0) { - bytes = new byte[length]; - file.readFully(bytes); - System.err.println("Synthetic attribute with length > 0"); - } - } - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitSynthetic(this); - } - /** - * Dump source file attribute to file stream in binary format. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - if(length > 0) - file.write(bytes, 0, length); - } - /** - * @return data bytes. - */ - public final byte[] getBytes() { return bytes; } - - /** - * @param bytes. - */ - public final void setBytes(byte[] bytes) { - this.bytes = bytes; - } - - /** - * @return String representation. - */ - public final String toString() { - StringBuffer buf = new StringBuffer("Synthetic"); - - if(length > 0) - buf.append(" " + Utility.toHexString(bytes)); - - return buf.toString(); - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - Synthetic c = (Synthetic)clone(); - - if(bytes != null) - c.bytes = (byte[])bytes.clone(); - - c.constantPool = constant_pool; - return c; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; + +import java.io.*; + +/** + * This class is derived from Attribute and declares this class as + * `synthetic', i.e., it needs special handling. The JVM specification + * states "A class member that does not appear in the source code must be + * marked using a Synthetic attribute." It may appear in the ClassFile + * attribute table, a field_info table or a method_info table. This class + * is intended to be instantiated from the + * Attribute.readAttribute() method. + * + * @version $Id: Synthetic.java,v 1.2.10.3 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + * @see Attribute + */ +public final class Synthetic extends Attribute { + private byte[] bytes; + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use copy() for a physical copy. + */ + public Synthetic(Synthetic c) { + this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool()); + } +// +// public Synthetic(ConstantPoolGen cpool) { +// super(Constants.ATTR_SYNTHETIC, cpool.addUtf8("Synthetic"), 0, cpool); +// ConstantPoolGen cpg = myGen.getConstantPool(); +// int index = ; +// Attribute synthetic = new Synthetic(index, 0, new byte[0], cpg.getConstantPool()); +// } + + /** + * @param name_index Index in constant pool to CONSTANT_Utf8, which + * should represent the string "Synthetic". + * @param length Content length in bytes - should be zero. + * @param bytes Attribute contents + * @param constant_pool The constant pool this attribute is associated + * with. + */ + public Synthetic(int name_index, int length, byte[] bytes, + ConstantPool constant_pool) + { + super(Constants.ATTR_SYNTHETIC, name_index, length, constant_pool); + this.bytes = bytes; + } + + /** + * Construct object from file stream. + * @param name_index Index in constant pool to CONSTANT_Utf8 + * @param length Content length in bytes + * @param file Input stream + * @param constant_pool Array of constants + * @throws IOException + */ + Synthetic(int name_index, int length, DataInputStream file, + ConstantPool constant_pool) throws IOException + { + this(name_index, length, (byte [])null, constant_pool); + + if(length > 0) { + bytes = new byte[length]; + file.readFully(bytes); + System.err.println("Synthetic attribute with length > 0"); + } + } + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitSynthetic(this); + } + /** + * Dump source file attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + if(length > 0) + file.write(bytes, 0, length); + } + /** + * @return data bytes. + */ + public final byte[] getBytes() { return bytes; } + + /** + * @param bytes. + */ + public final void setBytes(byte[] bytes) { + this.bytes = bytes; + } + + /** + * @return String representation. + */ + public final String toString() { + StringBuffer buf = new StringBuffer("Synthetic"); + + if(length > 0) + buf.append(" " + Utility.toHexString(bytes)); + + return buf.toString(); + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + Synthetic c = (Synthetic)clone(); + + if(bytes != null) + c.bytes = (byte[])bytes.clone(); + + c.constantPool = constant_pool; + return c; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Unknown.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Unknown.java index 7c577606e..223e9d6be 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Unknown.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Unknown.java @@ -1,212 +1,212 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import java.io.*; - -/** - * This class represents a reference to an unknown (i.e., - * application-specific) attribute of a class. It is instantiated from the - * Attribute.readAttribute() method. Applications that need to - * read in application-specific attributes should create an AttributeReader implementation and - * attach it via Attribute.addAttributeReader. - - * - * @version $Id: Unknown.java,v 1.3.6.2 2008/04/25 17:55:36 aclement Exp $ - * @see org.aspectj.apache.bcel.classfile.Attribute - * @author M. Dahm - */ -public final class Unknown extends Attribute { - private byte[] bytes; - private String name; - - // evil static - removed by Andy C - no apparent users (4 Mar 06) -// private static HashMap unknown_attributes = new HashMap(); - - /** @return array of unknown attributes, but just one for each kind. - */ -// static Unknown[] getUnknownAttributes() { -// Unknown[] unknowns = new Unknown[unknown_attributes.size()]; -// Iterator entries = unknown_attributes.values().iterator(); -// -// for(int i=0; entries.hasNext(); i++) -// unknowns[i] = (Unknown)entries.next(); -// -// unknown_attributes.clear(); -// return unknowns; -// } - - /** - * Initialize from another object. Note that both objects use the same - * references (shallow copy). Use clone() for a physical copy. - */ - public Unknown(Unknown c) { - this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool()); - } - - /** - * Create a non-standard attribute. - * - * @param name_index Index in constant pool - * @param length Content length in bytes - * @param bytes Attribute contents - * @param constant_pool Array of constants - */ - public Unknown(int name_index, int length, byte[] bytes, - ConstantPool constant_pool) - { - super(Constants.ATTR_UNKNOWN, name_index, length, constant_pool); - this.bytes = bytes; - - name = ((ConstantUtf8)constant_pool.getConstant(name_index, - Constants.CONSTANT_Utf8)).getBytes(); -// unknown_attributes.put(name, this); - } - - /** - * Construct object from file stream. - * @param name_index Index in constant pool - * @param length Content length in bytes - * @param file Input stream - * @param constant_pool Array of constants - * @throws IOException - */ - Unknown(int name_index, int length, DataInputStream file, - ConstantPool constant_pool) - throws IOException - { - this(name_index, length, (byte [])null, constant_pool); - - if(length > 0) { - bytes = new byte[length]; - file.readFully(bytes); - } - } - - /** - * Called by objects that are traversing the nodes of the tree implicitely - * defined by the contents of a Java class. I.e., the hierarchy of methods, - * fields, attributes, etc. spawns a tree of objects. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitUnknown(this); - } - /** - * Dump unknown bytes to file stream. - * - * @param file Output file stream - * @throws IOException - */ - public final void dump(DataOutputStream file) throws IOException - { - super.dump(file); - if(length > 0) - file.write(bytes, 0, length); - } - /** - * @return data bytes. - */ - public final byte[] getBytes() { return bytes; } - - /** - * @return name of attribute. - */ - public String getName() { return name; } - - /** - * @param bytes. - */ - public final void setBytes(byte[] bytes) { - this.bytes = bytes; - } - - /** - * @return String representation. - */ - public final String toString() { - if(length == 0 || bytes == null) - return "(Unknown attribute " + name + ")"; - - String hex; - if(length > 10) { - byte[] tmp = new byte[10]; - System.arraycopy(bytes, 0, tmp, 0, 10); - hex = Utility.toHexString(tmp) + "... (truncated)"; - } - else - hex = Utility.toHexString(bytes); - - return "(Unknown attribute " + name + ": " + hex + ")"; - } - - /** - * @return deep copy of this attribute - */ - public Attribute copy(ConstantPool constant_pool) { - Unknown c = (Unknown)clone(); - - if(bytes != null) - c.bytes = (byte[])bytes.clone(); - - c.constantPool = constant_pool; - return c; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +/** + * This class represents a reference to an unknown (i.e., + * application-specific) attribute of a class. It is instantiated from the + * Attribute.readAttribute() method. Applications that need to + * read in application-specific attributes should create an AttributeReader implementation and + * attach it via Attribute.addAttributeReader. + + * + * @version $Id: Unknown.java,v 1.3.6.3 2008/05/08 19:26:46 aclement Exp $ + * @see org.aspectj.apache.bcel.classfile.Attribute + * @author M. Dahm + */ +public final class Unknown extends Attribute { + private byte[] bytes; + private String name; + + // evil static - removed by Andy C - no apparent users (4 Mar 06) +// private static HashMap unknown_attributes = new HashMap(); + + /** @return array of unknown attributes, but just one for each kind. + */ +// static Unknown[] getUnknownAttributes() { +// Unknown[] unknowns = new Unknown[unknown_attributes.size()]; +// Iterator entries = unknown_attributes.values().iterator(); +// +// for(int i=0; entries.hasNext(); i++) +// unknowns[i] = (Unknown)entries.next(); +// +// unknown_attributes.clear(); +// return unknowns; +// } + + /** + * Initialize from another object. Note that both objects use the same + * references (shallow copy). Use clone() for a physical copy. + */ + public Unknown(Unknown c) { + this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool()); + } + + /** + * Create a non-standard attribute. + * + * @param name_index Index in constant pool + * @param length Content length in bytes + * @param bytes Attribute contents + * @param constant_pool Array of constants + */ + public Unknown(int name_index, int length, byte[] bytes, + ConstantPool constant_pool) + { + super(Constants.ATTR_UNKNOWN, name_index, length, constant_pool); + this.bytes = bytes; + + name = ((ConstantUtf8)constant_pool.getConstant(name_index, + Constants.CONSTANT_Utf8)).getBytes(); +// unknown_attributes.put(name, this); + } + + /** + * Construct object from file stream. + * @param name_index Index in constant pool + * @param length Content length in bytes + * @param file Input stream + * @param constant_pool Array of constants + * @throws IOException + */ + Unknown(int name_index, int length, DataInputStream file, + ConstantPool constant_pool) + throws IOException + { + this(name_index, length, (byte [])null, constant_pool); + + if(length > 0) { + bytes = new byte[length]; + file.readFully(bytes); + } + } + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept(ClassVisitor v) { + v.visitUnknown(this); + } + /** + * Dump unknown bytes to file stream. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + if(length > 0) + file.write(bytes, 0, length); + } + /** + * @return data bytes. + */ + public final byte[] getBytes() { return bytes; } + + /** + * @return name of attribute. + */ + public String getName() { return name; } + + /** + * @param bytes. + */ + public final void setBytes(byte[] bytes) { + this.bytes = bytes; + } + + /** + * @return String representation. + */ + public final String toString() { + if(length == 0 || bytes == null) + return "(Unknown attribute " + name + ")"; + + String hex; + if(length > 10) { + byte[] tmp = new byte[10]; + System.arraycopy(bytes, 0, tmp, 0, 10); + hex = Utility.toHexString(tmp) + "... (truncated)"; + } + else + hex = Utility.toHexString(bytes); + + return "(Unknown attribute " + name + ": " + hex + ")"; + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + Unknown c = (Unknown)clone(); + + if(bytes != null) + c.bytes = (byte[])bytes.clone(); + + c.constantPool = constant_pool; + return c; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java index 13739af97..846e3761a 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java @@ -1,1652 +1,1047 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.CharArrayReader; -import java.io.CharArrayWriter; -import java.io.DataOutputStream; -import java.io.FilterReader; -import java.io.FilterWriter; -import java.io.IOException; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.Reader; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; -import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * Utility functions that do not really belong to any class in particular. - * - * @version $Id: Utility.java,v 1.5.4.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * - * modified: Andy Clement 2-mar-05 Removed unnecessary static and optimized - */ -public abstract class Utility { - - /* The 'WIDE' instruction is used in the byte code to allow 16-bit wide indices for local - * variables. This opcode precedes an 'ILOAD', e.g.. The opcode immediately following takes - * an extra byte which is combined with the following byte to form a 16-bit value. - */ - private static boolean wide = false; - - /** - * Convert bit field of flags into string such as 'static final'. - * - * @param access_flags Access flags - * @return String representation of flags - */ - public static final String accessToString(int access_flags) { - return accessToString(access_flags, false); - } - - - /** - * Convert bit field of flags into string such as 'static final'. - * - * Special case: Classes compiled with new compilers and with the - * 'ACC_SUPER' flag would be said to be "synchronized". This is - * because SUN used the same value for the flags 'ACC_SUPER' and - * 'ACC_SYNCHRONIZED'. - * - * @param access_flags Access flags - * @param for_class access flags are for class qualifiers ? - * @return String representation of flags - */ - public static final String accessToString(int access_flags, boolean for_class) { - StringBuffer buf = new StringBuffer(); - - int p = 0; - for (int i=0; p < Constants.MAX_ACC_FLAG; i++) { // Loop through known flags - p = pow2(i); - if ((access_flags & p) != 0) { - // Special case: see comment at top of class... - if (for_class && ((p == Constants.ACC_SUPER) || (p == Constants.ACC_INTERFACE))) - continue; - buf.append(Constants.ACCESS_NAMES[i]).append(" "); - } - } - return buf.toString().trim(); - } - - - /** - * @return "class" or "interface", depending on the ACC_INTERFACE flag - */ - public static final String classOrInterface(int access_flags) { - return ((access_flags & Constants.ACC_INTERFACE) != 0)? "interface" : "class"; - } - - - /** - * Disassemble a byte array of JVM byte codes starting from code line - * 'index' and return the disassembled string representation. Decode only - * 'num' opcodes (including their operands), use -1 if you want to - * decompile everything. - * - * @param code byte code array - * @param constant_pool Array of constants - * @param index offset in `code' array - * (number of opcodes, not bytes!) - * @param length number of opcodes to decompile, -1 for all - * @param verbose be verbose, e.g. print constant pool index - * @return String representation of byte codes - */ - public static final String codeToString(byte[] code, - ConstantPool constant_pool, - int index, int length, boolean verbose) - { - StringBuffer buf = new StringBuffer(code.length * 20); // Should be sufficient - ByteSequence stream = new ByteSequence(code); - - try { - for (int i=0; i < index; i++) // Skip `index' lines of code - codeToString(stream, constant_pool, verbose); - - for (int i=0; stream.available() > 0; i++) { - if ((length < 0) || (i < length)) { - String indices = fillup(stream.getIndex() + ":", 6, true, ' '); - buf.append(indices + codeToString(stream, constant_pool, verbose) + '\n'); - } - } - } catch(IOException e) { - System.out.println(buf.toString()); - e.printStackTrace(); - throw new ClassFormatException("Byte code error: " + e); - } - - return buf.toString(); - } - - - - /** - * Disassemble a stream of byte codes and return the - * string representation. - */ - public static final String codeToString(byte[] code, ConstantPool constant_pool, int index, int length) { - return codeToString(code, constant_pool, index, length, true); - } - - - - public static final String codeToString(ByteSequence bytes, ConstantPool constant_pool) - throws IOException { - return codeToString(bytes, constant_pool, true); - } - - /** - * Shorten long class names, java/lang/String becomes String. - * - * @param str The long class name - * @return Compacted class name - */ - public static final String compactClassName(String str) { - return compactClassName(str, true); - } - - /** - * Shorten long class name str, i.e., chop off the prefix, - * if the - * class name starts with this string and the flag chopit is true. - * Slashes / are converted to dots .. - * - * @param str The long class name - * @param prefix The prefix the get rid off - * @param chopit Flag that determines whether chopping is executed or not - * @return Compacted class name - */ - public static final String compactClassName(String str, - String prefix, - boolean chopit) - { - int len = prefix.length(); - - str = str.replace('/', '.'); // Is '/' on all systems, even DOS - - if (chopit) { - // If string starts with 'prefix' and contains no further dots - if (str.startsWith(prefix) && (str.substring(len).indexOf('.') == -1)) - str = str.substring(len); - } - - return str; - } - - - - /** - * Shorten long class names, java/lang/String becomes - * java.lang.String, - * e.g.. If chopit is true the prefix java.lang - * is also removed. - * - * @param str The long class name - * @param chopit Flag that determines whether chopping is executed or not - * @return Compacted class name - */ - public static final String compactClassName(String str, boolean chopit) { - return compactClassName(str, "java.lang.", chopit); - } - - // bit modification - - /** - * @return 'flag' with bit 'i' set to 1 - */ - public static final int setBit(int flag, int i) { - return flag | pow2(i); - } - - /** - * @return 'flag' with bit 'i' set to 0 - */ - public static final int clearBit(int flag, int i) { - int bit = pow2(i); - return (flag & bit) == 0? flag : flag ^ bit; - } - - /** - * @return true, if bit 'i' in 'flag' is set - */ - public static final boolean isSet(int flag, int i) { - return (flag & pow2(i)) != 0; - } - - - - /** - * Converts string containing the method return and argument types - * to a byte code method signature. - * - * @param returnType Return type of method (e.g. "char" or "java.lang.String[]") - * @param methodArgs Types of method arguments - * @return Byte code representation of method signature - */ - public final static String methodTypeToSignature(String returnType, String[] methodArgs) throws ClassFormatException { - - StringBuffer buf = new StringBuffer("("); - - if (methodArgs != null) { - for (int i=0; i < methodArgs.length; i++) { - String str = getSignature(methodArgs[i]); - - if (str.equals("V")) // void can't be a method argument - throw new ClassFormatException("Invalid type: " + methodArgs[i]); - - buf.append(str); - } - } - - buf.append(")" + getSignature(returnType)); - - return buf.toString(); - } - - - - /** - * @param signature Method signature - * @return Array of argument types - * @throws ClassFormatException - */ - public static final String[] methodSignatureArgumentTypes(String signature) throws ClassFormatException { - return methodSignatureArgumentTypes(signature, true); - } - - - - - /** - * For some method signature (class file format) like '([Ljava/lang/String;Z)V' this returns an array - * of strings representing the arguments in their 'normal' form, e.g. '{java.lang.String[],boolean}' - * - * @param signature Method signature - * @param chopit Shorten class names - * @return Array of argument types - */ - public static final String[] methodSignatureArgumentTypes(String signature,boolean chopit) throws ClassFormatException { - ArrayList vec = new ArrayList(); - int index; - String[] types; - - try { // Read all declarations between for `(' and `)' - if (signature.charAt(0) != '(') - throw new ClassFormatException("Invalid method signature: " + signature); - - index = 1; // current string position - - while(signature.charAt(index) != ')') { - ResultHolder rh = signatureToStringInternal(signature.substring(index),chopit); - vec.add(rh.getResult()); - index += rh.getConsumedChars(); - } - } catch(StringIndexOutOfBoundsException e) { - throw new ClassFormatException("Invalid method signature: " + signature); - } - - types = new String[vec.size()]; - vec.toArray(types); - return types; - } - - - /** - * For some method signature (class file format) like '([Ljava/lang/String;)Z' this returns - * the string representing the return type its 'normal' form, e.g. 'boolean' - * - * @param signature Method signature - * @return return type of method - * @throws ClassFormatException - */ - public static final String methodSignatureReturnType(String signature) throws ClassFormatException { - return methodSignatureReturnType(signature, true); - } - - - /** - * For some method signature (class file format) like '([Ljava/lang/String;)Z' this returns - * the string representing the return type its 'normal' form, e.g. 'boolean' - * - * @param signature Method signature - * @param chopit Shorten class names - * @return return type of method - */ - public static final String methodSignatureReturnType(String signature,boolean chopit) throws ClassFormatException { - int index; - String type; - try { - // Read return type after `)' - index = signature.lastIndexOf(')') + 1; - type = signatureToString(signature.substring(index), chopit); - } catch (StringIndexOutOfBoundsException e) { - throw new ClassFormatException("Invalid method signature: " + signature); - } - return type; - } - - - - public static final String methodSignatureToString(String signature,String name,String access) { - return methodSignatureToString(signature, name, access, true); - } - - public static final String methodSignatureToString(String signature,String name, - String access,boolean chopit) { - return methodSignatureToString(signature, name, access, chopit, null); - } - - /** - * This method converts such a string into a Java type declaration like - * 'void main(String[])' and throws a 'ClassFormatException' when the parsed - * type is invalid. - * - * @param signature Method signature - * @param name Method name - * @param access Method access rights - * @return Java type declaration - * @throws ClassFormatException - */ - public static final String methodSignatureToString(String signature, String name, - String access, boolean chopit, LocalVariableTable vars) throws ClassFormatException { -// -// -// if (signature.charAt(0)!='(') -// throw new ClassFormatException("Invalid method signature: " + signature); -// -// // Break the signature into two pieces: ([PARAMS])[RETURNTYPE] -// int lastBracketPos = signature.lastIndexOf(")"); -// String parameters = signature.substring(1,lastBracketPos); -// String returnType = signature.substring(lastBracketPos+1); -// -// // e.g. parameters="Ljava/util/List;" -// // returnType="V" -// -// // Break signature into its parts -// // dont want lots of substringing so lets use an index -// int posn=0; -// StringBuffer piece; -// while (posn= 0)? 0 : 1; - - try { // Read all declarations between for `(' and `)' - if (signature.charAt(0) != '(') - throw new ClassFormatException("Invalid method signature: " + signature); - - index = 1; // current string position - - while(signature.charAt(index) != ')') { - ResultHolder rh = signatureToStringInternal(signature.substring(index), chopit); - String param_type = rh.getResult(); - buf.append(param_type); - - if(vars != null) { - LocalVariable l = vars.getLocalVariable(var_index); - - if(l != null) - buf.append(" " + l.getName()); - } else - buf.append(" arg" + var_index); - - if("double".equals(param_type) || "long".equals(param_type)) - var_index += 2; - else - var_index++; - - buf.append(", "); - index += rh.getConsumedChars(); - } - - index++; - - // Read return type after `)' - type = signatureToString(signature.substring(index), chopit); - - } catch(StringIndexOutOfBoundsException e) { // Should never occur - throw new ClassFormatException("Invalid method signature: " + signature); - } - - if(buf.length() > 1) // Tack off the extra ", " - buf.setLength(buf.length() - 2); - - buf.append(")"); - - return access + ((access.length() > 0)? " " : "") + // May be an empty string - type + " " + name + buf.toString(); - } - - - - /** - * Replace all occurences of old in str with new. - * - * @param str String to permute - * @param old String to be replaced - * @param new Replacement string - * @return new String object - */ - public static final String replace(String str, String old, String new_) { - int index, old_index; - StringBuffer buf = new StringBuffer(); - - try { - index = str.indexOf(old); - if ( index != -1) { - old_index = 0; - - // While we have something to replace - while((index = str.indexOf(old, old_index)) != -1) { - buf.append(str.substring(old_index, index)); // append prefix - buf.append(new_); // append replacement - old_index = index + old.length(); // Skip 'old'.length chars - } - - buf.append(str.substring(old_index)); // append rest of string - str = buf.toString(); - } - } catch(StringIndexOutOfBoundsException e) { - System.err.println(e); - } - - return str; - } - - /** - * Converts signature to string with all class names compacted. - * - * @param signature to convert - * @return Human readable signature - */ - public static final String signatureToString(String signature) { - return signatureToString(signature, true); - } - - - public static final String signatureToString(String signature,boolean chopit) { - ResultHolder rh = signatureToStringInternal(signature,chopit); - return rh.getResult(); - } - - /** - * This method converts this string into a Java type declaration such as - * 'String[]' and throws a `ClassFormatException' when the parsed type is - * invalid. - * - * @param signature Class signature - * @param chopit Flag that determines whether chopping is executed or not - * @return Java type declaration - */ - public static final ResultHolder signatureToStringInternal(String signature,boolean chopit) { - int processedChars = 1; // This is the default, read just one char - try { - switch(signature.charAt(0)) { - case 'B' : return ResultHolder.BYTE; - case 'C' : return ResultHolder.CHAR; - case 'D' : return ResultHolder.DOUBLE; - case 'F' : return ResultHolder.FLOAT; - case 'I' : return ResultHolder.INT; - case 'J' : return ResultHolder.LONG; - - case 'L' : { // Full class name - int index = signature.indexOf(';'); // Look for closing `;' - // Jump to the correct ';' - if (index!=-1 && - signature.length()>index+1 && - signature.charAt(index+1)=='>') index = index+2; - - if (index < 0) - throw new ClassFormatException("Invalid signature: " + signature); - - int genericStart = signature.indexOf('<'); - int genericEnd = signature.indexOf('>'); - if (genericStart !=-1) { - // FIXME asc going to need a lot more work in here for generics - ResultHolder rh = signatureToStringInternal(signature.substring(genericStart+1,genericEnd),chopit); - ResultHolder retval = new ResultHolder(compactClassName(signature.substring(1,genericStart)+"<"+ - rh.getResult()+">",chopit),genericEnd+1); - return retval; - } else { - processedChars = index + 1; // "Lblabla;" `L' and `;' are removed - ResultHolder retval = new ResultHolder(compactClassName(signature.substring(1, index), chopit),processedChars); - return retval; - } - } - - case 'S' : return ResultHolder.SHORT; - case 'Z' : return ResultHolder.BOOLEAN; - - case '[' : { // Array declaration - StringBuffer brackets; - int consumedChars,n; - - brackets = new StringBuffer(); // Accumulate []'s - // Count opening brackets and look for optional size argument - for(n=0; signature.charAt(n) == '['; n++) - brackets.append("[]"); - consumedChars = n; - // The rest of the string denotes a `' - ResultHolder restOfIt = signatureToStringInternal(signature.substring(n),chopit); - - // type = signatureToString(signature.substring(n), chopit); - - consumedChars+= restOfIt.getConsumedChars(); - return new ResultHolder(restOfIt.getResult() + brackets.toString(),consumedChars); - } - - case 'V' : return ResultHolder.VOID; - - default : throw new ClassFormatException("Invalid signature: `" + - signature + "'"); - } - } catch(StringIndexOutOfBoundsException e) { // Should never occur - throw new ClassFormatException("Invalid signature: " + e + ":" + signature); - } - } - - - - - /** - * Parse Java type such as "char", or "java.lang.String[]" and return the - * signature in byte code format, e.g. "C" or "[Ljava/lang/String;" respectively. - * - * @param type Java type - * @return byte code signature - */ - public static String getSignature(String type) { - StringBuffer buf = new StringBuffer(); - char[] chars = type.toCharArray(); - boolean char_found = false, delim = false; - int index = -1; - - loop: - for (int i=0; i < chars.length; i++) { - switch (chars[i]) { - case ' ': case '\t': case '\n': case '\r': case '\f': - if (char_found) delim = true; - break; - - case '[': - if (!char_found) throw new RuntimeException("Illegal type: " + type); - index = i; - break loop; - - default: - char_found = true; - if (!delim) buf.append(chars[i]); - } - } - - int brackets = 0; - - if(index > 0) brackets = countBrackets(type.substring(index)); - - type = buf.toString(); - buf.setLength(0); - - for (int i=0; i < brackets; i++) buf.append('['); - - boolean found = false; - - for(int i=Constants.T_BOOLEAN; (i <= Constants.T_VOID) && !found; i++) { - if (Constants.TYPE_NAMES[i].equals(type)) { - found = true; - buf.append(Constants.SHORT_TYPE_NAMES[i]); - } - } - - // Class name - if (!found) buf.append('L' + type.replace('.', '/') + ';'); - - return buf.toString(); - } - - - - - /** - * Return type of method signature as a byte value as defined in Constants - * - * @param signature in format described above - * @return type of method signature - * @see Constants - */ - public static final byte typeOfMethodSignature(String signature) throws ClassFormatException { - int index; - - try { - if (signature.charAt(0) != '(') - throw new ClassFormatException("Invalid method signature: " + signature); - index = signature.lastIndexOf(')') + 1; - return typeOfSignature(signature.substring(index)); - } catch(StringIndexOutOfBoundsException e) { - throw new ClassFormatException("Invalid method signature: " + signature); - } - } - - - - /** Map opcode names to opcode numbers. E.g., return Constants.ALOAD for "aload" - */ - public static short searchOpcode(String name) { - name = name.toLowerCase(); - - for (short i=0; i < Constants.OPCODE_NAMES.length; i++) { - if (Constants.OPCODE_NAMES[i].equals(name)) - return i; - } - - return -1; - } - - /** - * Convert (signed) byte to (unsigned) short value, i.e., all negative - * values become positive. - */ - private static final short byteToShort(byte b) { - return (b < 0)? (short)(256 + b) : (short)b; - } - - /** - * Convert bytes into hexidecimal string - * - * @return bytes as hexidecimal string, e.g. 00 FA 12 ... - */ - public static final String toHexString(byte[] bytes) { - StringBuffer buf = new StringBuffer(); - - for(int i=0; i < bytes.length; i++) { - short b = byteToShort(bytes[i]); - String hex = Integer.toString(b, 0x10); - - // Just one digit, so prepend 0 - if (b < 0x10) buf.append('0'); - - buf.append(hex); - - if (i < bytes.length - 1) buf.append(' '); - } - - return buf.toString(); - } - - /** - * Return a string for an integer justified left or right and filled up with - * 'fill' characters if necessary. - * - * @param i integer to format - * @param length length of desired string - * @param left_justify format left or right - * @param fill fill character - * @return formatted int - */ - public static final String format(int i, int length, boolean left_justify, char fill) { - return fillup(Integer.toString(i), length, left_justify, fill); - } - - /** - * Fillup char with up to length characters with char `fill' and justify it left or right. - * - * @param str string to format - * @param length length of desired string - * @param left_justify format left or right - * @param fill fill character - * @return formatted string - */ - public static final String fillup(String str, int length, boolean left_justify, char fill) { - int len = length - str.length(); - char[] buf = new char[(len < 0)? 0 : len]; - - for(int j=0; j < buf.length; j++) - buf[j] = fill; - - if(left_justify) - return str + new String(buf); - else - return new String(buf) + str; - } - - static final boolean equals(byte[] a, byte[] b) { - int size; - - if((size=a.length) != b.length) - return false; - - for(int i=0; i < size; i++) - if(a[i] != b[i]) - return false; - - return true; - } - - public static final void printArray(PrintStream out, Object[] obj) { - out.println(printArray(obj, true)); - } - - public static final void printArray(PrintWriter out, Object[] obj) { - out.println(printArray(obj, true)); - } - - public static final String printArray(Object[] obj) { - return printArray(obj, true); - } - - public static final String printArray(Object[] obj, boolean braces) { - return printArray(obj, braces, false); - } - - public static final String printArray(Object[] obj, boolean braces, - boolean quote) { - if(obj == null) - return null; - - StringBuffer buf = new StringBuffer(); - if(braces) - buf.append('{'); - - for(int i=0; i < obj.length; i++) { - if(obj[i] != null) { - buf.append((quote? "\"" : "") + obj[i].toString() + (quote? "\"" : "")); - } else { - buf.append("null"); - } - - if(i < obj.length - 1) { - buf.append(", "); - } - } - - if(braces) - buf.append('}'); - - return buf.toString(); - } - - /** @return true, if character is one of (a, ... z, A, ... Z, 0, ... 9, _) - */ - public static boolean isJavaIdentifierPart(char ch) { - return ((ch >= 'a') && (ch <= 'z')) || - ((ch >= 'A') && (ch <= 'Z')) || - ((ch >= '0') && (ch <= '9')) || - (ch == '_'); - } - - /** - * Encode byte array it into Java identifier string, i.e., a string - * that only contains the following characters: (a, ... z, A, ... Z, - * 0, ... 9, _, $). The encoding algorithm itself is not too - * clever: if the current byte's ASCII value already is a valid Java - * identifier part, leave it as it is. Otherwise it writes the - * escape character($) followed by

      • the ASCII value as a - * hexadecimal string, if the value is not in the range - * 200..247
      • a Java identifier char not used in a lowercase - * hexadecimal string, if the value is in the range - * 200..247
        • - * - *

          This operation inflates the original byte array by roughly 40-50%

          - * - * @param bytes the byte array to convert - * @param compress use gzip to minimize string - */ - public static String encode(byte[] bytes, boolean compress) throws IOException { - if(compress) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - GZIPOutputStream gos = new GZIPOutputStream(baos); - - gos.write(bytes, 0, bytes.length); - gos.close(); - baos.close(); - - bytes = baos.toByteArray(); - } - - CharArrayWriter caw = new CharArrayWriter(); - JavaWriter jw = new JavaWriter(caw); - - for(int i=0; i < bytes.length; i++) { - int in = bytes[i] & 0x000000ff; // Normalize to unsigned - jw.write(in); - } - - return caw.toString(); - } - - /** Decode a string back to a byte array. - * - * @param bytes the byte array to convert - * @param uncompress use gzip to uncompress the stream of bytes - */ - public static byte[] decode(String s, boolean uncompress) throws IOException { - char[] chars = s.toCharArray(); - - CharArrayReader car = new CharArrayReader(chars); - JavaReader jr = new JavaReader(car); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - - int ch; - - while((ch = jr.read()) >= 0) { - bos.write(ch); - } - - bos.close(); - car.close(); - jr.close(); - - byte[] bytes = bos.toByteArray(); - - if(uncompress) { - GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes)); - - byte[] tmp = new byte[bytes.length * 3]; // Rough estimate - int count = 0; - int b; - - while((b = gis.read()) >= 0) - tmp[count++] = (byte)b; - - bytes = new byte[count]; - System.arraycopy(tmp, 0, bytes, 0, count); - } - - return bytes; - } - - // A-Z, g-z, _, $ - private static final int FREE_CHARS = 48; - private static int[] CHAR_MAP = new int[FREE_CHARS]; - private static int[] MAP_CHAR = new int[256]; // Reverse map - private static final char ESCAPE_CHAR = '$'; - - static { - int j = 0, k = 0; - for(int i='A'; i <= 'Z'; i++) { - CHAR_MAP[j] = i; - MAP_CHAR[i] = j; - j++; - } - - for(int i='g'; i <= 'z'; i++) { - CHAR_MAP[j] = i; - MAP_CHAR[i] = j; - j++; - } - - CHAR_MAP[j] = '$'; - MAP_CHAR['$'] = j; - j++; - - CHAR_MAP[j] = '_'; - MAP_CHAR['_'] = j; - } - - /** Decode characters into bytes. - * Used by decode() - */ - private static class JavaReader extends FilterReader { - public JavaReader(Reader in) { - super(in); - } - - public int read() throws IOException { - int b = in.read(); - - if(b != ESCAPE_CHAR) { - return b; - } else { - int i = in.read(); - - if(i < 0) - return -1; - - if(((i >= '0') && (i <= '9')) || ((i >= 'a') && (i <= 'f'))) { // Normal escape - int j = in.read(); - - if(j < 0) - return -1; - - char[] tmp = { (char)i, (char)j }; - int s = Integer.parseInt(new String(tmp), 16); - - return s; - } else { // Special escape - return MAP_CHAR[i]; - } - } - } - - public int read(char[] cbuf, int off, int len) throws IOException { - for(int i=0; i < len; i++) - cbuf[off + i] = (char)read(); - - return len; - } - } - - /** Encode bytes into valid java identifier characters. - * Used by encode() - */ - private static class JavaWriter extends FilterWriter { - public JavaWriter(Writer out) { - super(out); - } - - public void write(int b) throws IOException { - if(isJavaIdentifierPart((char)b) && (b != ESCAPE_CHAR)) { - out.write(b); - } else { - out.write(ESCAPE_CHAR); // Escape character - - // Special escape - if(b >= 0 && b < FREE_CHARS) { - out.write(CHAR_MAP[b]); - } else { // Normal escape - char[] tmp = Integer.toHexString(b).toCharArray(); - - if(tmp.length == 1) { - out.write('0'); - out.write(tmp[0]); - } else { - out.write(tmp[0]); - out.write(tmp[1]); - } - } - } - } - - public void write(char[] cbuf, int off, int len) throws IOException { - for(int i=0; i < len; i++) - write(cbuf[off + i]); - } - - public void write(String str, int off, int len) throws IOException { - write(str.toCharArray(), off, len); - } - } - - /** - * Escape all occurences of newline chars '\n', quotes \", etc. - */ - public static final String convertString(String label) { - char[] ch = label.toCharArray(); - StringBuffer buf = new StringBuffer(); - - for(int i=0; i < ch.length; i++) { - switch(ch[i]) { - case '\n': - buf.append("\\n"); break; - case '\r': - buf.append("\\r"); break; - case '\"': - buf.append("\\\""); break; - case '\'': - buf.append("\\'"); break; - case '\\': - buf.append("\\\\"); break; - default: - buf.append(ch[i]); break; - } - } - - return buf.toString(); - } - - public static List getListOfAnnotationNames(AnnotationGen a) { - List l = a.getValues(); - List names = new ArrayList(); - for (Iterator i = l.iterator(); i.hasNext();) { - ElementNameValuePairGen element = (ElementNameValuePairGen) i.next(); - names.add(element.getNameString()); - } - return names; - } - - - /** - * Converts a list of AnnotationGen objects into a set of attributes - * that can be attached to the class file. - * - * @param cp The constant pool gen where we can create the necessary name refs - * @param vec A list of AnnotationGen objects - */ - public static Attribute[] getAnnotationAttributes(ConstantPool cp,List vec) { - - if (vec.size()==0) return null; - - try { - int countVisible = 0; - int countInvisible = 0; - - // put the annotations in the right output stream - for (int i=0; i2) rvaIndex = cp.addUtf8("RuntimeVisibleAnnotations"); - if (riaData.length>2) riaIndex = cp.addUtf8("RuntimeInvisibleAnnotations"); - - List newAttributes = new ArrayList(); - if (rvaData.length>2) { - newAttributes.add( - new RuntimeVisibleAnnotations(rvaIndex,rvaData.length,rvaData,cp)); - } - if (riaData.length>2) { - newAttributes.add( - new RuntimeInvisibleAnnotations(riaIndex,riaData.length,riaData,cp)); - } - - return (Attribute[])newAttributes.toArray(new Attribute[]{}); - } catch (IOException e) { - System.err.println("IOException whilst processing annotations"); - e.printStackTrace(); - } - return null; - } - - /** - * Annotations against a class are stored in one of four attribute kinds: - * - RuntimeVisibleParameterAnnotations - * - RuntimeInvisibleParameterAnnotations - */ - public static Attribute[] getParameterAnnotationAttributes(ConstantPool cp,List[] /*Array of lists, array size depends on #params */ vec) { - - int visCount[] = new int[vec.length]; - int totalVisCount = 0; - int invisCount[] = new int[vec.length]; - int totalInvisCount = 0; - try { - - for (int i=0; i0) { - List l = vec[i]; - for (Iterator iter = l.iterator(); iter.hasNext();) { - AnnotationGen element = (AnnotationGen) iter.next(); - if (element.isRuntimeVisible()) element.dump(rvaDos); - } - } - } - rvaDos.close(); - - // Lets do the invisible ones - ByteArrayOutputStream riaBytes = new ByteArrayOutputStream(); - DataOutputStream riaDos = new DataOutputStream(riaBytes); - riaDos.writeByte(vec.length); // First goes number of parameters - - for (int i=0; i0) { - List l = vec[i]; - for (Iterator iter = l.iterator(); iter.hasNext();) { - AnnotationGen element = (AnnotationGen) iter.next(); - if (!element.isRuntimeVisible()) element.dump(riaDos); - } - } - } - riaDos.close(); - - byte[] rvaData = rvaBytes.toByteArray(); - byte[] riaData = riaBytes.toByteArray(); - - int rvaIndex = -1; - int riaIndex = -1; - - if (totalVisCount>0) rvaIndex = cp.addUtf8("RuntimeVisibleParameterAnnotations"); - if (totalInvisCount>0) riaIndex = cp.addUtf8("RuntimeInvisibleParameterAnnotations"); - - List newAttributes = new ArrayList(); - - if (totalVisCount>0) { - newAttributes.add( - new RuntimeVisibleParameterAnnotations(rvaIndex,rvaData.length,rvaData,cp)); - } - - - if (totalInvisCount>0) { - newAttributes.add( - new RuntimeInvisibleParameterAnnotations(riaIndex,riaData.length,riaData,cp)); - } - - return (Attribute[])newAttributes.toArray(new Attribute[]{}); - } catch (IOException e) { - System.err.println("IOException whilst processing parameter annotations"); - e.printStackTrace(); - } - return null; - } - - -// private static final boolean is_digit(char ch) { -// return (ch >= '0') && (ch <= '9'); -// } -// -// private static final boolean is_space(char ch) { -// return (ch == ' ') || (ch == '\t') || (ch == '\r') || (ch == '\n'); -// } - - private static class ResultHolder { - private String result; - private int consumed; - - public static final ResultHolder BYTE = new ResultHolder("byte",1); - public static final ResultHolder CHAR = new ResultHolder("char",1); - public static final ResultHolder DOUBLE = new ResultHolder("double",1); - public static final ResultHolder FLOAT = new ResultHolder("float",1); - public static final ResultHolder INT = new ResultHolder("int",1); - public static final ResultHolder LONG = new ResultHolder("long",1); - public static final ResultHolder SHORT = new ResultHolder("short",1); - public static final ResultHolder BOOLEAN = new ResultHolder("boolean",1); - public static final ResultHolder VOID = new ResultHolder("void",1); - - public ResultHolder(String s,int c) { - result = s; - consumed = c; - } - - public String getResult() { return result;} - public int getConsumedChars() { return consumed; } - } - - // code below here I am happy with .... - - /** - * Return type of signature as a byte value as defined in Constants - * - * @param signature in format described above - * @return type of signature - * @see Constants - */ - public static final byte typeOfSignature(String signature) throws ClassFormatException { - try { - switch(signature.charAt(0)) { - case 'B' : return Constants.T_BYTE; - case 'C' : return Constants.T_CHAR; - case 'D' : return Constants.T_DOUBLE; - case 'F' : return Constants.T_FLOAT; - case 'I' : return Constants.T_INT; - case 'J' : return Constants.T_LONG; - case 'L' : return Constants.T_REFERENCE; - case '[' : return Constants.T_ARRAY; - case 'V' : return Constants.T_VOID; - case 'Z' : return Constants.T_BOOLEAN; - case 'S' : return Constants.T_SHORT; - default: - throw new ClassFormatException("Invalid method signature: " + signature); - } - } catch(StringIndexOutOfBoundsException e) { - throw new ClassFormatException("Invalid method signature: " + signature); - } - } - - public static final byte typeOfSignature(char c) throws ClassFormatException { - switch(c) { - case 'B' : return Constants.T_BYTE; - case 'C' : return Constants.T_CHAR; - case 'D' : return Constants.T_DOUBLE; - case 'F' : return Constants.T_FLOAT; - case 'I' : return Constants.T_INT; - case 'J' : return Constants.T_LONG; - case 'L' : return Constants.T_REFERENCE; - case '[' : return Constants.T_ARRAY; - case 'V' : return Constants.T_VOID; - case 'Z' : return Constants.T_BOOLEAN; - case 'S' : return Constants.T_SHORT; - default: - throw new ClassFormatException("Invalid type of signature: " + c); - } - } - - public static final String readClassTypeSignatureFrom(String signature) { - StringBuffer sb = new StringBuffer(); - readClassTypeSignatureFrom(signature,0,sb,false); - return sb.toString(); - } - - /** - * Takes a string and consumes a single complete signature from it, returning - * how many chars it consumed. The chopit flag indicates whether to shorten - * type references ( java/lang/String => String ) - * - * FIXME asc this should also create some kind of object you can query for information about whether its parameterized, what the bounds are, etc... - */ - public static final int readClassTypeSignatureFrom(String signature, int posn, StringBuffer result, boolean chopit) { - int idx = posn; - try { - switch (signature.charAt(idx)) { - case 'B' : result.append("byte"); return 1; - case 'C' : result.append("char"); return 1; - case 'D' : result.append("double"); return 1; - case 'F' : result.append("float"); return 1; - case 'I' : result.append("int"); return 1; - case 'J' : result.append("long"); return 1; - case 'S' : result.append("short"); return 1; - case 'Z' : result.append("boolean");return 1; - case 'V' : result.append("void"); return 1; - - - //FIXME ASC Need a state machine to check we are parsing the right stuff here ! - case 'T' : - idx++; - int nextSemiIdx = signature.indexOf(';',idx); - result.append(signature.substring(idx,nextSemiIdx)); - return nextSemiIdx+1-posn; - - case '+' : - result.append("? extends "); - return readClassTypeSignatureFrom(signature,idx+1,result,chopit)+1; - - case '-' : - result.append("? super "); - return readClassTypeSignatureFrom(signature,idx+1,result,chopit)+1; - - case '*' : - result.append("?"); - return 1; - - case 'L' : // Full class name - boolean parameterized = false; - int idxSemicolon = signature.indexOf(';',idx); // Look for closing ';' or '<' - int idxAngly = signature.indexOf('<',idx); - int endOfSig = idxSemicolon; - if ((idxAngly!=-1) && idxAngly");idx++; - } - if (signature.charAt(idx)!=';') throw new RuntimeException("Did not find ';' at end of signature, found "+signature.charAt(idx)); - idx++; - return idx-posn; - - - case '[' : // Array declaration - int dim = 0; - while (signature.charAt(idx)=='[') {dim++;idx++;} - idx+=readClassTypeSignatureFrom(signature,idx,result,chopit); - while (dim>0) {result.append("[]");dim--;} - return idx-posn; - - default : throw new ClassFormatException("Invalid signature: `" + - signature + "'"); - } - } catch(StringIndexOutOfBoundsException e) { // Should never occur - throw new ClassFormatException("Invalid signature: " + e + ":" + signature); - } - } - - private static int countBrackets(String brackets) { - char[] chars = brackets.toCharArray(); - int count = 0; - boolean open = false; - - for(int i=0; i"); break; - - // Access object/class fields - case Constants.GETFIELD: case Constants.GETSTATIC: case Constants.PUTFIELD: case Constants.PUTSTATIC: - index = bytes.readUnsignedShort(); - buf.append("\t\t" + - constant_pool.constantToString(index, Constants.CONSTANT_Fieldref) + - (verbose? " (" + index + ")" : "")); - break; - - // Operands are references to classes in constant pool - case Constants.NEW: - case Constants.CHECKCAST: - buf.append("\t"); - case Constants.INSTANCEOF: - index = bytes.readUnsignedShort(); - buf.append("\t<" + constant_pool.constantToString(index,Constants.CONSTANT_Class) + - ">" + (verbose? " (" + index + ")" : "")); - break; - - // Operands are references to methods in constant pool - case Constants.INVOKESPECIAL: case Constants.INVOKESTATIC: case Constants.INVOKEVIRTUAL: - index = bytes.readUnsignedShort(); - buf.append("\t" + constant_pool.constantToString(index,Constants.CONSTANT_Methodref) + - (verbose? " (" + index + ")" : "")); - break; - - case Constants.INVOKEINTERFACE: - index = bytes.readUnsignedShort(); - int nargs = bytes.readUnsignedByte(); // historical, redundant - buf.append("\t" + - constant_pool.constantToString(index,Constants.CONSTANT_InterfaceMethodref) + - (verbose? " (" + index + ")\t" : "") + nargs + "\t" + - bytes.readUnsignedByte()); // Last byte is a reserved space - break; - - // Operands are references to items in constant pool - case Constants.LDC_W: case Constants.LDC2_W: - index = bytes.readUnsignedShort(); - buf.append("\t\t" + constant_pool.constantToString - (index, constant_pool.getConstant(index).getTag()) + - (verbose? " (" + index + ")" : "")); - break; - - case Constants.LDC: - index = bytes.readUnsignedByte(); - buf.append("\t\t" + - constant_pool.constantToString - (index, constant_pool.getConstant(index).getTag()) + - (verbose? " (" + index + ")" : "")); - break; - - // Array of references - case Constants.ANEWARRAY: - index = bytes.readUnsignedShort(); - buf.append("\t\t<" + compactClassName(constant_pool.getConstantString - (index, Constants.CONSTANT_Class), false) + - ">" + (verbose? " (" + index + ")": "")); - break; - - // Multidimensional array of references - case Constants.MULTIANEWARRAY: { - index = bytes.readUnsignedShort(); - int dimensions = bytes.readUnsignedByte(); - - buf.append("\t<" + compactClassName(constant_pool.getConstantString - (index, Constants.CONSTANT_Class), false) + - ">\t" + dimensions + (verbose? " (" + index + ")" : "")); - } - break; - - // Increment local variable - case Constants.IINC: - if (wide) { - vindex = bytes.readUnsignedShort(); - constant = bytes.readShort(); - wide = false; - } else { - vindex = bytes.readUnsignedByte(); - constant = bytes.readByte(); - } - buf.append("\t\t%" + vindex + "\t" + constant); - break; - - default: - if ((Constants.iLen[opcode]-1) > 0) { - for (int i=0; i < Constants.TYPE_OF_OPERANDS[opcode].length; i++) { - buf.append("\t\t"); - switch(Constants.TYPE_OF_OPERANDS[opcode][i]) { - case Constants.T_BYTE: buf.append(bytes.readByte()); break; - case Constants.T_SHORT: buf.append(bytes.readShort()); break; - case Constants.T_INT: buf.append(bytes.readInt()); break; - - default: // Never reached - System.err.println("Unreachable default case reached!"); - System.exit(-1); - } - } - } - } - return buf.toString(); - } - - // private helpers - private static final int pow2(int n) { - return 1 << n; - } -} +package org.aspectj.apache.bcel.classfile; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.CharArrayReader; +import java.io.CharArrayWriter; +import java.io.DataOutputStream; +import java.io.FilterReader; +import java.io.FilterWriter; +import java.io.IOException; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; +import org.aspectj.apache.bcel.util.ByteSequence; + +/** + * Utility functions that do not really belong to any class in particular. + * + * @version $Id: Utility.java,v 1.5.4.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * + * modified: Andy Clement 2-mar-05 Removed unnecessary static and optimized + */ +public abstract class Utility { + + /* The 'WIDE' instruction is used in the byte code to allow 16-bit wide indices for local + * variables. This opcode precedes an 'ILOAD', e.g.. The opcode immediately following takes + * an extra byte which is combined with the following byte to form a 16-bit value. + */ + private static boolean wide = false; + + /** + * Convert bit field of flags into string such as 'static final'. + * + * @param access_flags Access flags + * @return String representation of flags + */ + public static final String accessToString(int access_flags) { + return accessToString(access_flags, false); + } + + /** + * Convert bit field of flags into string such as 'static final'. + * + * Special case: Classes compiled with new compilers and with the + * 'ACC_SUPER' flag would be said to be "synchronized". This is + * because SUN used the same value for the flags 'ACC_SUPER' and + * 'ACC_SYNCHRONIZED'. + * + * @param access_flags Access flags + * @param for_class access flags are for class qualifiers ? + * @return String representation of flags + */ + public static final String accessToString(int access_flags, boolean for_class) { + StringBuffer buf = new StringBuffer(); + + int p = 0; + for (int i=0; p < Constants.MAX_ACC_FLAG; i++) { // Loop through known flags + p = pow2(i); + if ((access_flags & p) != 0) { + // Special case: see comment at top of class... + if (for_class && ((p == Constants.ACC_SUPER) || (p == Constants.ACC_INTERFACE))) + continue; + buf.append(Constants.ACCESS_NAMES[i]).append(" "); + } + } + return buf.toString().trim(); + } + + + /** + * @return "class" or "interface", depending on the ACC_INTERFACE flag + */ + public static final String classOrInterface(int access_flags) { + return ((access_flags & Constants.ACC_INTERFACE) != 0)? "interface" : "class"; + } + + + /** + * Disassemble a byte array of JVM byte codes starting from code line + * 'index' and return the disassembled string representation. Decode only + * 'num' opcodes (including their operands), use -1 if you want to + * decompile everything. + * + * @param code byte code array + * @param constant_pool Array of constants + * @param index offset in `code' array + * (number of opcodes, not bytes!) + * @param length number of opcodes to decompile, -1 for all + * @param verbose be verbose, e.g. print constant pool index + * @return String representation of byte codes + */ + public static final String codeToString(byte[] code, + ConstantPool constant_pool, + int index, int length, boolean verbose) + { + StringBuffer buf = new StringBuffer(code.length * 20); // Should be sufficient + ByteSequence stream = new ByteSequence(code); + + try { + for (int i=0; i < index; i++) // Skip `index' lines of code + codeToString(stream, constant_pool, verbose); + + for (int i=0; stream.available() > 0; i++) { + if ((length < 0) || (i < length)) { + String indices = fillup(stream.getIndex() + ":", 6, true, ' '); + buf.append(indices + codeToString(stream, constant_pool, verbose) + '\n'); + } + } + } catch(IOException e) { + System.out.println(buf.toString()); + e.printStackTrace(); + throw new ClassFormatException("Byte code error: " + e); + } + + return buf.toString(); + } + + + + /** + * Disassemble a stream of byte codes and return the + * string representation. + */ + public static final String codeToString(byte[] code, ConstantPool constant_pool, int index, int length) { + return codeToString(code, constant_pool, index, length, true); + } + + + + public static final String codeToString(ByteSequence bytes, ConstantPool constant_pool) + throws IOException { + return codeToString(bytes, constant_pool, true); + } + + /** + * Shorten long class names, java/lang/String becomes String. + * + * @param str The long class name + * @return Compacted class name + */ + public static final String compactClassName(String str) { + return compactClassName(str, true); + } + + /** + * Shorten long class name str, i.e., chop off the prefix, + * if the + * class name starts with this string and the flag chopit is true. + * Slashes / are converted to dots .. + * + * @param str The long class name + * @param prefix The prefix the get rid off + * @param chopit Flag that determines whether chopping is executed or not + * @return Compacted class name + */ + public static final String compactClassName(String str, + String prefix, + boolean chopit) + { + int len = prefix.length(); + + str = str.replace('/', '.'); // Is '/' on all systems, even DOS + + if (chopit) { + // If string starts with 'prefix' and contains no further dots + if (str.startsWith(prefix)) { + String result = str.substring(len); + if ( result.indexOf('.') == -1) { + str = result; + } + } + } + return str; + } + + + + /** + * Shorten long class names, java/lang/String becomes + * java.lang.String, + * e.g.. If chopit is true the prefix java.lang + * is also removed. + * + * @param str The long class name + * @param chopit Flag that determines whether chopping is executed or not + * @return Compacted class name + */ + public static final String compactClassName(String str, boolean chopit) { + return compactClassName(str, "java.lang.", chopit); + } + + public static final String methodSignatureToString(String signature,String name,String access) { + return methodSignatureToString(signature, name, access, true); + } + + public static final String methodSignatureToString(String signature,String name, + String access,boolean chopit) { + return methodSignatureToString(signature, name, access, chopit, null); + } + + /** + * This method converts such a string into a Java type declaration like + * 'void main(String[])' and throws a 'ClassFormatException' when the parsed + * type is invalid. + * + * @param signature Method signature + * @param name Method name + * @param access Method access rights + * @return Java type declaration + * @throws ClassFormatException + */ + public static final String methodSignatureToString(String signature, String name, + String access, boolean chopit, LocalVariableTable vars) throws ClassFormatException { +// +// +// if (signature.charAt(0)!='(') +// throw new ClassFormatException("Invalid method signature: " + signature); +// +// // Break the signature into two pieces: ([PARAMS])[RETURNTYPE] +// int lastBracketPos = signature.lastIndexOf(")"); +// String parameters = signature.substring(1,lastBracketPos); +// String returnType = signature.substring(lastBracketPos+1); +// +// // e.g. parameters="Ljava/util/List;" +// // returnType="V" +// +// // Break signature into its parts +// // dont want lots of substringing so lets use an index +// int posn=0; +// StringBuffer piece; +// while (posn= 0)? 0 : 1; + + try { // Read all declarations between for `(' and `)' + if (signature.charAt(0) != '(') + throw new ClassFormatException("Invalid method signature: " + signature); + + index = 1; // current string position + + while(signature.charAt(index) != ')') { + ResultHolder rh = signatureToStringInternal(signature.substring(index), chopit); + String param_type = rh.getResult(); + buf.append(param_type); + + if(vars != null) { + LocalVariable l = vars.getLocalVariable(var_index); + + if(l != null) + buf.append(" " + l.getName()); + } else + buf.append(" arg" + var_index); + + if("double".equals(param_type) || "long".equals(param_type)) + var_index += 2; + else + var_index++; + + buf.append(", "); + index += rh.getConsumedChars(); + } + + index++; + + // Read return type after `)' + type = signatureToString(signature.substring(index), chopit); + + } catch(StringIndexOutOfBoundsException e) { // Should never occur + throw new ClassFormatException("Invalid method signature: " + signature); + } + + if(buf.length() > 1) // Tack off the extra ", " + buf.setLength(buf.length() - 2); + + buf.append(")"); + + return access + ((access.length() > 0)? " " : "") + // May be an empty string + type + " " + name + buf.toString(); + } + + + + /** + * Replace all occurences of old in str with new. + * + * @param str String to permute + * @param old String to be replaced + * @param new Replacement string + * @return new String object + */ + public static final String replace(String str, String old, String new_) { + int index, old_index; + StringBuffer buf = new StringBuffer(); + + try { + index = str.indexOf(old); + if ( index != -1) { + old_index = 0; + + // While we have something to replace + while((index = str.indexOf(old, old_index)) != -1) { + buf.append(str.substring(old_index, index)); // append prefix + buf.append(new_); // append replacement + old_index = index + old.length(); // Skip 'old'.length chars + } + + buf.append(str.substring(old_index)); // append rest of string + str = buf.toString(); + } + } catch(StringIndexOutOfBoundsException e) { + System.err.println(e); + } + + return str; + } + + /** + * Converts signature to string with all class names compacted. + * + * @param signature to convert + * @return Human readable signature + */ + public static final String signatureToString(String signature) { + return signatureToString(signature, true); + } + + + public static final String signatureToString(String signature,boolean chopit) { + ResultHolder rh = signatureToStringInternal(signature,chopit); + return rh.getResult(); + } + + /** + * This method converts this string into a Java type declaration such as + * 'String[]' and throws a `ClassFormatException' when the parsed type is + * invalid. + * + * @param signature Class signature + * @param chopit Flag that determines whether chopping is executed or not + * @return Java type declaration + */ + public static final ResultHolder signatureToStringInternal(String signature,boolean chopit) { + int processedChars = 1; // This is the default, read just one char + try { + switch(signature.charAt(0)) { + case 'B' : return ResultHolder.BYTE; + case 'C' : return ResultHolder.CHAR; + case 'D' : return ResultHolder.DOUBLE; + case 'F' : return ResultHolder.FLOAT; + case 'I' : return ResultHolder.INT; + case 'J' : return ResultHolder.LONG; + + case 'L' : { // Full class name + int index = signature.indexOf(';'); // Look for closing `;' + // Jump to the correct ';' + if (index!=-1 && + signature.length()>index+1 && + signature.charAt(index+1)=='>') index = index+2; + + if (index < 0) + throw new ClassFormatException("Invalid signature: " + signature); + + int genericStart = signature.indexOf('<'); + int genericEnd = signature.indexOf('>'); + if (genericStart !=-1) { + // FIXME asc going to need a lot more work in here for generics + ResultHolder rh = signatureToStringInternal(signature.substring(genericStart+1,genericEnd),chopit); + ResultHolder retval = new ResultHolder(compactClassName(signature.substring(1,genericStart)+"<"+ + rh.getResult()+">",chopit),genericEnd+1); + return retval; + } else { + processedChars = index + 1; // "Lblabla;" `L' and `;' are removed + ResultHolder retval = new ResultHolder(compactClassName(signature.substring(1, index), chopit),processedChars); + return retval; + } + } + + case 'S' : return ResultHolder.SHORT; + case 'Z' : return ResultHolder.BOOLEAN; + + case '[' : { // Array declaration + StringBuffer brackets; + int consumedChars,n; + + brackets = new StringBuffer(); // Accumulate []'s + // Count opening brackets and look for optional size argument + for(n=0; signature.charAt(n) == '['; n++) + brackets.append("[]"); + consumedChars = n; + // The rest of the string denotes a `' + ResultHolder restOfIt = signatureToStringInternal(signature.substring(n),chopit); + + // type = signatureToString(signature.substring(n), chopit); + + consumedChars+= restOfIt.getConsumedChars(); + return new ResultHolder(restOfIt.getResult() + brackets.toString(),consumedChars); + } + + case 'V' : return ResultHolder.VOID; + + default : throw new ClassFormatException("Invalid signature: `" + + signature + "'"); + } + } catch(StringIndexOutOfBoundsException e) { // Should never occur + throw new ClassFormatException("Invalid signature: " + e + ":" + signature); + } + } + + + + + /** + * Return type of method signature as a byte value as defined in Constants + * + * @param signature in format described above + * @return type of method signature + * @see Constants + */ + public static final byte typeOfMethodSignature(String signature) throws ClassFormatException { + int index; + + try { + if (signature.charAt(0) != '(') + throw new ClassFormatException("Invalid method signature: " + signature); + index = signature.lastIndexOf(')') + 1; + return typeOfSignature(signature.substring(index)); + } catch(StringIndexOutOfBoundsException e) { + throw new ClassFormatException("Invalid method signature: " + signature); + } + } + + /** + * Convert (signed) byte to (unsigned) short value, i.e., all negative + * values become positive. + */ + private static final short byteToShort(byte b) { + return (b < 0)? (short)(256 + b) : (short)b; + } + + /** + * Convert bytes into hexidecimal string + * + * @return bytes as hexidecimal string, e.g. 00 FA 12 ... + */ + public static final String toHexString(byte[] bytes) { + StringBuffer buf = new StringBuffer(); + + for(int i=0; i < bytes.length; i++) { + short b = byteToShort(bytes[i]); + String hex = Integer.toString(b, 0x10); + + // Just one digit, so prepend 0 + if (b < 0x10) buf.append('0'); + + buf.append(hex); + + if (i < bytes.length - 1) buf.append(' '); + } + + return buf.toString(); + } + + /** + * Return a string for an integer justified left or right and filled up with + * 'fill' characters if necessary. + * + * @param i integer to format + * @param length length of desired string + * @param left_justify format left or right + * @param fill fill character + * @return formatted int + */ + public static final String format(int i, int length, boolean left_justify, char fill) { + return fillup(Integer.toString(i), length, left_justify, fill); + } + + /** + * Fillup char with up to length characters with char `fill' and justify it left or right. + * + * @param str string to format + * @param length length of desired string + * @param left_justify format left or right + * @param fill fill character + * @return formatted string + */ + public static final String fillup(String str, int length, boolean left_justify, char fill) { + int len = length - str.length(); + char[] buf = new char[(len < 0)? 0 : len]; + + for(int j=0; j < buf.length; j++) + buf[j] = fill; + + if(left_justify) + return str + new String(buf); + else + return new String(buf) + str; + } + + /** + * Escape all occurences of newline chars '\n', quotes \", etc. + */ + public static final String convertString(String label) { + char[] ch = label.toCharArray(); + StringBuffer buf = new StringBuffer(); + + for(int i=0; i < ch.length; i++) { + switch(ch[i]) { + case '\n': + buf.append("\\n"); break; + case '\r': + buf.append("\\r"); break; + case '\"': + buf.append("\\\""); break; + case '\'': + buf.append("\\'"); break; + case '\\': + buf.append("\\\\"); break; + default: + buf.append(ch[i]); break; + } + } + + return buf.toString(); + } + + /** + * Converts a list of AnnotationGen objects into a set of attributes + * that can be attached to the class file. + * + * @param cp The constant pool gen where we can create the necessary name refs + * @param vec A list of AnnotationGen objects + */ + public static Attribute[] getAnnotationAttributes(ConstantPool cp,List vec) { + + if (vec.size()==0) return null; + + try { + int countVisible = 0; + int countInvisible = 0; + + // put the annotations in the right output stream + for (int i=0; i2) rvaIndex = cp.addUtf8("RuntimeVisibleAnnotations"); + if (riaData.length>2) riaIndex = cp.addUtf8("RuntimeInvisibleAnnotations"); + + List newAttributes = new ArrayList(); + if (rvaData.length>2) { + newAttributes.add( + new RuntimeVisibleAnnotations(rvaIndex,rvaData.length,rvaData,cp)); + } + if (riaData.length>2) { + newAttributes.add( + new RuntimeInvisibleAnnotations(riaIndex,riaData.length,riaData,cp)); + } + + return (Attribute[])newAttributes.toArray(new Attribute[]{}); + } catch (IOException e) { + System.err.println("IOException whilst processing annotations"); + e.printStackTrace(); + } + return null; + } + + /** + * Annotations against a class are stored in one of four attribute kinds: + * - RuntimeVisibleParameterAnnotations + * - RuntimeInvisibleParameterAnnotations + */ + // OPTIMIZE looks heavyweight? + public static Attribute[] getParameterAnnotationAttributes(ConstantPool cp,List[] /*Array of lists, array size depends on #params */ vec) { + + int visCount[] = new int[vec.length]; + int totalVisCount = 0; + int invisCount[] = new int[vec.length]; + int totalInvisCount = 0; + try { + + for (int i=0; i0) { + List l = vec[i]; + for (Iterator iter = l.iterator(); iter.hasNext();) { + AnnotationGen element = (AnnotationGen) iter.next(); + if (element.isRuntimeVisible()) element.dump(rvaDos); + } + } + } + rvaDos.close(); + + // Lets do the invisible ones + ByteArrayOutputStream riaBytes = new ByteArrayOutputStream(); + DataOutputStream riaDos = new DataOutputStream(riaBytes); + riaDos.writeByte(vec.length); // First goes number of parameters + + for (int i=0; i0) { + List l = vec[i]; + for (Iterator iter = l.iterator(); iter.hasNext();) { + AnnotationGen element = (AnnotationGen) iter.next(); + if (!element.isRuntimeVisible()) element.dump(riaDos); + } + } + } + riaDos.close(); + + byte[] rvaData = rvaBytes.toByteArray(); + byte[] riaData = riaBytes.toByteArray(); + + int rvaIndex = -1; + int riaIndex = -1; + + if (totalVisCount>0) rvaIndex = cp.addUtf8("RuntimeVisibleParameterAnnotations"); + if (totalInvisCount>0) riaIndex = cp.addUtf8("RuntimeInvisibleParameterAnnotations"); + + List newAttributes = new ArrayList(); + + if (totalVisCount>0) { + newAttributes.add( + new RuntimeVisibleParameterAnnotations(rvaIndex,rvaData.length,rvaData,cp)); + } + + + if (totalInvisCount>0) { + newAttributes.add( + new RuntimeInvisibleParameterAnnotations(riaIndex,riaData.length,riaData,cp)); + } + + return (Attribute[])newAttributes.toArray(new Attribute[]{}); + } catch (IOException e) { + System.err.println("IOException whilst processing parameter annotations"); + e.printStackTrace(); + } + return null; + } + + public static class ResultHolder { + private String result; + private int consumed; + + public static final ResultHolder BYTE = new ResultHolder("byte",1); + public static final ResultHolder CHAR = new ResultHolder("char",1); + public static final ResultHolder DOUBLE = new ResultHolder("double",1); + public static final ResultHolder FLOAT = new ResultHolder("float",1); + public static final ResultHolder INT = new ResultHolder("int",1); + public static final ResultHolder LONG = new ResultHolder("long",1); + public static final ResultHolder SHORT = new ResultHolder("short",1); + public static final ResultHolder BOOLEAN = new ResultHolder("boolean",1); + public static final ResultHolder VOID = new ResultHolder("void",1); + + public ResultHolder(String s,int c) { + result = s; + consumed = c; + } + + public String getResult() { return result;} + public int getConsumedChars() { return consumed; } + } + + + /** + * Return type of signature as a byte value as defined in Constants + * + * @param signature in format described above + * @return type of signature + * @see Constants + */ + public static final byte typeOfSignature(String signature) throws ClassFormatException { + try { + switch(signature.charAt(0)) { + case 'B' : return Constants.T_BYTE; + case 'C' : return Constants.T_CHAR; + case 'D' : return Constants.T_DOUBLE; + case 'F' : return Constants.T_FLOAT; + case 'I' : return Constants.T_INT; + case 'J' : return Constants.T_LONG; + case 'L' : return Constants.T_REFERENCE; + case '[' : return Constants.T_ARRAY; + case 'V' : return Constants.T_VOID; + case 'Z' : return Constants.T_BOOLEAN; + case 'S' : return Constants.T_SHORT; + default: + throw new ClassFormatException("Invalid method signature: " + signature); + } + } catch(StringIndexOutOfBoundsException e) { + throw new ClassFormatException("Invalid method signature: " + signature); + } + } + + public static final byte typeOfSignature(char c) throws ClassFormatException { + switch(c) { + case 'B' : return Constants.T_BYTE; + case 'C' : return Constants.T_CHAR; + case 'D' : return Constants.T_DOUBLE; + case 'F' : return Constants.T_FLOAT; + case 'I' : return Constants.T_INT; + case 'J' : return Constants.T_LONG; + case 'L' : return Constants.T_REFERENCE; + case '[' : return Constants.T_ARRAY; + case 'V' : return Constants.T_VOID; + case 'Z' : return Constants.T_BOOLEAN; + case 'S' : return Constants.T_SHORT; + default: + throw new ClassFormatException("Invalid type of signature: " + c); + } + } + + /** + * Disassemble a stream of byte codes and return the string representation. + * + * @param bytes stream of bytes + * @param constant_pool Array of constants + * @param verbose be verbose, e.g. print constant pool index + * @return String representation of byte code + */ + public static final String codeToString(ByteSequence bytes, + ConstantPool constant_pool, boolean verbose) throws IOException { + short opcode = (short)bytes.readUnsignedByte(); + int default_offset=0, low, high, npairs; + int index, vindex, constant; + int[] match, jump_table; + int no_pad_bytes=0, offset; + StringBuffer buf = new StringBuffer(Constants.OPCODE_NAMES[opcode]); + + /* Special case: Skip (0-3) padding bytes, i.e., the + * following bytes are 4-byte-aligned + */ + if ((opcode == Constants.TABLESWITCH) || (opcode == Constants.LOOKUPSWITCH)) { + int remainder = bytes.getIndex() % 4; + no_pad_bytes = (remainder == 0)? 0 : 4 - remainder; + + for (int i=0; i < no_pad_bytes; i++) { + byte b = bytes.readByte(); + if (b != 0) + System.err.println("Warning: Padding byte != 0 in " + Constants.OPCODE_NAMES[opcode] + ":" + b); + } + + // Both cases have a field default_offset in common + default_offset = bytes.readInt(); + } + + switch(opcode) { + /* Table switch has variable length arguments. + */ + case Constants.TABLESWITCH: + low = bytes.readInt(); + high = bytes.readInt(); + + offset = bytes.getIndex() - 12 - no_pad_bytes - 1; + default_offset += offset; + + buf.append("\tdefault = " + default_offset + ", low = " + low + + ", high = " + high + "("); + + jump_table = new int[high - low + 1]; + for (int i=0; i < jump_table.length; i++) { + jump_table[i] = offset + bytes.readInt(); + buf.append(jump_table[i]); + if (i < jump_table.length - 1) buf.append(", "); + } + buf.append(")"); + break; + + /* Lookup switch has variable length arguments. + */ + case Constants.LOOKUPSWITCH: { + + npairs = bytes.readInt(); + offset = bytes.getIndex() - 8 - no_pad_bytes - 1; + + match = new int[npairs]; + jump_table = new int[npairs]; + default_offset += offset; + + buf.append("\tdefault = " + default_offset + ", npairs = " + npairs + " ("); + + for (int i=0; i < npairs; i++) { + match[i] = bytes.readInt(); + jump_table[i] = offset + bytes.readInt(); + buf.append("(" + match[i] + ", " + jump_table[i] + ")"); + if(i < npairs - 1) buf.append(", "); + } + buf.append(")"); + } + break; + + // Two address bytes + offset from start of byte stream form the jump target + case Constants.GOTO: case Constants.IFEQ: case Constants.IFGE: case Constants.IFGT: + case Constants.IFLE: case Constants.IFLT: case Constants.JSR: case Constants.IFNE: + case Constants.IFNONNULL: case Constants.IFNULL: case Constants.IF_ACMPEQ: + case Constants.IF_ACMPNE: case Constants.IF_ICMPEQ: case Constants.IF_ICMPGE: case Constants.IF_ICMPGT: + case Constants.IF_ICMPLE: case Constants.IF_ICMPLT: case Constants.IF_ICMPNE: + buf.append("\t\t#" + ((bytes.getIndex() - 1) + bytes.readShort())); + break; + + // 32-bit wide jumps + case Constants.GOTO_W: case Constants.JSR_W: + buf.append("\t\t#" + ((bytes.getIndex() - 1) + bytes.readInt())); + break; + + // Index byte references local variable (register) + case Constants.ALOAD: case Constants.ASTORE: case Constants.DLOAD: case Constants.DSTORE: case Constants.FLOAD: + case Constants.FSTORE: case Constants.ILOAD: case Constants.ISTORE: case Constants.LLOAD: case Constants.LSTORE: + case Constants.RET: + if (wide) { + vindex = bytes.readUnsignedShort(); + wide=false; // Clear flag + } else + vindex = bytes.readUnsignedByte(); + buf.append("\t\t%" + vindex); + break; + + /* + * Remember wide byte which is used to form a 16-bit address in the + * following instruction. Relies on that the method is called again with + * the following opcode. + */ + case Constants.WIDE: wide=true; buf.append("\t(wide)"); break; + + // Array of basic type + case Constants.NEWARRAY: buf.append("\t\t<" + Constants.TYPE_NAMES[bytes.readByte()] + ">"); break; + + // Access object/class fields + case Constants.GETFIELD: case Constants.GETSTATIC: case Constants.PUTFIELD: case Constants.PUTSTATIC: + index = bytes.readUnsignedShort(); + buf.append("\t\t" + + constant_pool.constantToString(index, Constants.CONSTANT_Fieldref) + + (verbose? " (" + index + ")" : "")); + break; + + // Operands are references to classes in constant pool + case Constants.NEW: + case Constants.CHECKCAST: + buf.append("\t"); + case Constants.INSTANCEOF: + index = bytes.readUnsignedShort(); + buf.append("\t<" + constant_pool.constantToString(index,Constants.CONSTANT_Class) + + ">" + (verbose? " (" + index + ")" : "")); + break; + + // Operands are references to methods in constant pool + case Constants.INVOKESPECIAL: case Constants.INVOKESTATIC: case Constants.INVOKEVIRTUAL: + index = bytes.readUnsignedShort(); + buf.append("\t" + constant_pool.constantToString(index,Constants.CONSTANT_Methodref) + + (verbose? " (" + index + ")" : "")); + break; + + case Constants.INVOKEINTERFACE: + index = bytes.readUnsignedShort(); + int nargs = bytes.readUnsignedByte(); // historical, redundant + buf.append("\t" + + constant_pool.constantToString(index,Constants.CONSTANT_InterfaceMethodref) + + (verbose? " (" + index + ")\t" : "") + nargs + "\t" + + bytes.readUnsignedByte()); // Last byte is a reserved space + break; + + // Operands are references to items in constant pool + case Constants.LDC_W: case Constants.LDC2_W: + index = bytes.readUnsignedShort(); + buf.append("\t\t" + constant_pool.constantToString + (index, constant_pool.getConstant(index).getTag()) + + (verbose? " (" + index + ")" : "")); + break; + + case Constants.LDC: + index = bytes.readUnsignedByte(); + buf.append("\t\t" + + constant_pool.constantToString + (index, constant_pool.getConstant(index).getTag()) + + (verbose? " (" + index + ")" : "")); + break; + + // Array of references + case Constants.ANEWARRAY: + index = bytes.readUnsignedShort(); + buf.append("\t\t<" + compactClassName(constant_pool.getConstantString + (index, Constants.CONSTANT_Class), false) + + ">" + (verbose? " (" + index + ")": "")); + break; + + // Multidimensional array of references + case Constants.MULTIANEWARRAY: { + index = bytes.readUnsignedShort(); + int dimensions = bytes.readUnsignedByte(); + + buf.append("\t<" + compactClassName(constant_pool.getConstantString + (index, Constants.CONSTANT_Class), false) + + ">\t" + dimensions + (verbose? " (" + index + ")" : "")); + } + break; + + // Increment local variable + case Constants.IINC: + if (wide) { + vindex = bytes.readUnsignedShort(); + constant = bytes.readShort(); + wide = false; + } else { + vindex = bytes.readUnsignedByte(); + constant = bytes.readByte(); + } + buf.append("\t\t%" + vindex + "\t" + constant); + break; + + default: + if ((Constants.iLen[opcode]-1) > 0) { + for (int i=0; i < Constants.TYPE_OF_OPERANDS[opcode].length; i++) { + buf.append("\t\t"); + switch(Constants.TYPE_OF_OPERANDS[opcode][i]) { + case Constants.T_BYTE: buf.append(bytes.readByte()); break; + case Constants.T_SHORT: buf.append(bytes.readShort()); break; + case Constants.T_INT: buf.append(bytes.readInt()); break; + + default: // Never reached + System.err.println("Unreachable default case reached!"); + System.exit(-1); + } + } + } + } + return buf.toString(); + } + + // private helpers + private static final int pow2(int n) { + return 1 << n; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/Annotation.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/Annotation.java deleted file mode 100644 index 4b609fd06..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/Annotation.java +++ /dev/null @@ -1,130 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * ******************************************************************/ -package org.aspectj.apache.bcel.classfile.annotation; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.ConstantUtf8; -import org.aspectj.apache.bcel.classfile.Utility; - -/** - * An annotation is an immutable object (AnnotationGen is the mutable variant) - it basically contains a list - * of name-value pairs. - */ -public class Annotation { - private int typeIndex; - private List /* ElementNameValuePair */ evs = new ArrayList(); - private ConstantPool cpool; - private boolean isRuntimeVisible; - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("ANNOTATION ["+getTypeSignature()+"] ["+ - (isRuntimeVisible?"runtimeVisible":"runtimeInvisible")+"] ["); - for (Iterator iter = evs.iterator(); iter.hasNext();) { - ElementNameValuePair element = (ElementNameValuePair) iter.next(); - sb.append(element.toString()); - if (iter.hasNext()) sb.append(","); - } - sb.append("]"); - return sb.toString(); - } - - private Annotation(ConstantPool cpool) { - this.cpool = cpool; - } - - public Annotation(int index,ConstantPool cpool,boolean visible) { - this.cpool = cpool; - this.typeIndex = index; - this.isRuntimeVisible = visible; - } - - protected static Annotation read(DataInputStream dis,ConstantPool cpool,boolean isRuntimeVisible) throws IOException { - Annotation a = new Annotation(cpool); - a.typeIndex = dis.readUnsignedShort(); - int elemValuePairCount = dis.readUnsignedShort(); - for (int i=0;i0) { - result.append("("); - for (Iterator iter = getValues().iterator(); iter.hasNext();) { - ElementNameValuePair element = (ElementNameValuePair) iter.next(); - result.append(element.toShortString()); - } - result.append(")"); - } - return result.toString(); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/AnnotationElementValue.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/AnnotationElementValue.java deleted file mode 100644 index 1959f20d8..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/AnnotationElementValue.java +++ /dev/null @@ -1,51 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement - initial implementation {date} - * ******************************************************************/ -package org.aspectj.apache.bcel.classfile.annotation; - -import java.io.DataOutputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.classfile.ConstantPool; - -/** - * An element value that is an annotation. - */ -public class AnnotationElementValue extends ElementValue { - - // For annotation element values, this is the annotation - private Annotation a; - - public AnnotationElementValue(int type, Annotation annotation, ConstantPool cpool) { - super(type,cpool); - if (type != ANNOTATION) - throw new RuntimeException("Only element values of type annotation can be built with this ctor"); - this.a = annotation; - } - - public void dump(DataOutputStream dos) throws IOException { - dos.writeByte(type); // u1 type of value (ANNOTATION == '@') - a.dump(dos); - } - - public String stringifyValue() { - StringBuffer sb = new StringBuffer(); - sb.append(a.toString()); - return sb.toString(); - } - - public String toString() { - return stringifyValue(); - } - - public Annotation getAnnotation() { return a;} - -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ArrayElementValue.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ArrayElementValue.java deleted file mode 100644 index 6feeeddf4..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ArrayElementValue.java +++ /dev/null @@ -1,66 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement - initial implementation {date} - * ******************************************************************/ - -package org.aspectj.apache.bcel.classfile.annotation; - -import java.io.DataOutputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.classfile.ConstantPool; - - -public class ArrayElementValue extends ElementValue { - - // For array types, this is the array - private ElementValue[] evalues; - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("{"); - for (int i = 0; i < evalues.length; i++) { - sb.append(evalues[i].toString()); - if ((i+1) - - - - - -

          -This package contains the classes that describe the structure of a -Java class file and a class file parser. -

          - - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/AALOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/AALOAD.java deleted file mode 100644 index 1cc20e33a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/AALOAD.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * AALOAD - Load reference from array - *
          Stack: ..., arrayref, index -> value
          - * - * @version $Id: AALOAD.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class AALOAD extends ArrayInstruction implements StackProducer { - /** Load reference from array - */ - public AALOAD() { - super(org.aspectj.apache.bcel.Constants.AALOAD); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitAALOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/AASTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/AASTORE.java deleted file mode 100644 index 35818a756..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/AASTORE.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * AASTORE - Store into reference array - *
          Stack: ..., arrayref, index, value -> ...
          - * - * @version $Id: AASTORE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class AASTORE extends ArrayInstruction implements StackConsumer { - /** Store into reference array - */ - public AASTORE() { - super(org.aspectj.apache.bcel.Constants.AASTORE); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitAASTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ACONST_NULL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ACONST_NULL.java deleted file mode 100644 index 596264631..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ACONST_NULL.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * ACONST_NULL - Push null reference - *
          Stack: ... -> ..., null
          - * - * @version $Id: ACONST_NULL.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class ACONST_NULL extends Instruction - implements PushInstruction, TypedInstruction { - /** - * Push null reference - */ - public ACONST_NULL() { - super(org.aspectj.apache.bcel.Constants.ACONST_NULL, (short)1); - } - - /** @return Type.NULL - */ - public Type getType(ConstantPoolGen cp) { - return Type.NULL; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitTypedInstruction(this); - v.visitACONST_NULL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ALOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ALOAD.java deleted file mode 100644 index 9cb2dd121..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ALOAD.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * ALOAD - Load reference from local variable - *
          Stack: ... -> ..., objectref
          - * - * @version $Id: ALOAD.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class ALOAD extends LoadInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - ALOAD() { - super(org.aspectj.apache.bcel.Constants.ALOAD, org.aspectj.apache.bcel.Constants.ALOAD_0); - } - - /** Load reference from local variable - * @param n index of local variable - */ - public ALOAD(int n) { - super(org.aspectj.apache.bcel.Constants.ALOAD, org.aspectj.apache.bcel.Constants.ALOAD_0, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - super.accept(v); - v.visitALOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ANEWARRAY.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ANEWARRAY.java deleted file mode 100644 index 8db7270c2..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ANEWARRAY.java +++ /dev/null @@ -1,114 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.ExceptionConstants; - -/** - * ANEWARRAY - Create new array of references - *
          Stack: ..., count -> ..., arrayref
          - * - * @version $Id: ANEWARRAY.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class ANEWARRAY extends CPInstruction - implements LoadClass, AllocationInstruction, ExceptionThrower, StackProducer { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - ANEWARRAY() {} - - public ANEWARRAY(int index) { - super(org.aspectj.apache.bcel.Constants.ANEWARRAY, index); - } - - public Class[] getExceptions(){ - Class[] cs = new Class[1 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length]; - - System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, - cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length); - cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = - ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION; - return cs; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitLoadClass(this); - v.visitAllocationInstruction(this); - v.visitExceptionThrower(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitCPInstruction(this); - v.visitANEWARRAY(this); - } - - public ObjectType getLoadClassType(ConstantPoolGen cpg) { - Type t = getType(cpg); - - if (t instanceof ArrayType){ - t = ((ArrayType) t).getBasicType(); - } - - return (t instanceof ObjectType)? (ObjectType) t : null; - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ARETURN.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ARETURN.java deleted file mode 100644 index 9425440f5..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ARETURN.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * ARETURN - Return reference from method - *
          Stack: ..., objectref -> <empty>
          - * - * @version $Id: ARETURN.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class ARETURN extends ReturnInstruction { - /** - * Return reference from method - */ - public ARETURN() { - super(org.aspectj.apache.bcel.Constants.ARETURN); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackConsumer(this); - v.visitReturnInstruction(this); - v.visitARETURN(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ARRAYLENGTH.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ARRAYLENGTH.java deleted file mode 100644 index 64e079afb..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ARRAYLENGTH.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * ARRAYLENGTH - Get length of array - *
          Stack: ..., arrayref -> ..., length
          - * - * @version $Id: ARRAYLENGTH.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class ARRAYLENGTH extends Instruction - implements ExceptionThrower, StackProducer { - /** Get length of array - */ - public ARRAYLENGTH() { - super(org.aspectj.apache.bcel.Constants.ARRAYLENGTH, (short)1); - } - - /** @return exceptions this instruction may cause - */ - public Class[] getExceptions() { - return new Class[] { org.aspectj.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION }; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitStackProducer(this); - v.visitARRAYLENGTH(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ASTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ASTORE.java deleted file mode 100644 index 8d7db57d7..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ASTORE.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * ASTORE - Store reference into local variable - *
          Stack ..., objectref -> ... 
          - * - * @version $Id: ASTORE.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class ASTORE extends StoreInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - ASTORE() { - super(org.aspectj.apache.bcel.Constants.ASTORE, org.aspectj.apache.bcel.Constants.ASTORE_0); - } - - /** Store reference into local variable - * @param n index of local variable - */ - public ASTORE(int n) { - super(org.aspectj.apache.bcel.Constants.ASTORE, org.aspectj.apache.bcel.Constants.ASTORE_0, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - super.accept(v); - v.visitASTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ATHROW.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ATHROW.java deleted file mode 100644 index 8beffc698..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ATHROW.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * ATHROW - Throw exception - *
          Stack: ..., objectref -> objectref
          - * - * @version $Id: ATHROW.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class ATHROW extends Instruction implements UnconditionalBranch, ExceptionThrower { - /** - * Throw exception - */ - public ATHROW() { - super(org.aspectj.apache.bcel.Constants.ATHROW, (short)1); - } - - /** @return exceptions this instruction may cause - */ - public Class[] getExceptions() { - return new Class[] { org.aspectj.apache.bcel.ExceptionConstants.THROWABLE }; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitUnconditionalBranch(this); - v.visitExceptionThrower(this); - v.visitATHROW(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/AllocationInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/AllocationInstruction.java deleted file mode 100644 index c3cea122f..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/AllocationInstruction.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denote family of instructions that allocates space in the heap. - * - * @version $Id: AllocationInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public interface AllocationInstruction {} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ArithmeticInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ArithmeticInstruction.java deleted file mode 100644 index 1e1c602ee..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ArithmeticInstruction.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; -/** - * Super class for the family of arithmetic instructions. - * - * @version $Id: ArithmeticInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public abstract class ArithmeticInstruction extends Instruction - implements TypedInstruction, StackProducer, StackConsumer { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - ArithmeticInstruction() {} - - /** - * @param opcode of instruction - */ - protected ArithmeticInstruction(short opcode) { - super(opcode, (short)1); - } - - /** @return type associated with the instruction - */ - public Type getType(ConstantPoolGen cp) { - switch(opcode) { - case Constants.DADD: case Constants.DDIV: case Constants.DMUL: - case Constants.DNEG: case Constants.DREM: case Constants.DSUB: - return Type.DOUBLE; - - case Constants.FADD: case Constants.FDIV: case Constants.FMUL: - case Constants.FNEG: case Constants.FREM: case Constants.FSUB: - return Type.FLOAT; - - case Constants.IADD: case Constants.IAND: case Constants.IDIV: - case Constants.IMUL: case Constants.INEG: case Constants.IOR: case Constants.IREM: - case Constants.ISHL: case Constants.ISHR: case Constants.ISUB: - case Constants.IUSHR: case Constants.IXOR: - return Type.INT; - - case Constants.LADD: case Constants.LAND: case Constants.LDIV: - case Constants.LMUL: case Constants.LNEG: case Constants.LOR: case Constants.LREM: - case Constants.LSHL: case Constants.LSHR: case Constants.LSUB: - case Constants.LUSHR: case Constants.LXOR: - return Type.LONG; - - default: // Never reached - throw new ClassGenException("Unknown type " + opcode); - } - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ArrayInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ArrayInstruction.java deleted file mode 100644 index 26aae716a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ArrayInstruction.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Super class for instructions dealing with array access such as IALOAD. - * - * @version $Id: ArrayInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public abstract class ArrayInstruction extends Instruction - implements ExceptionThrower, TypedInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - ArrayInstruction() {} - - /** - * @param opcode of instruction - */ - protected ArrayInstruction(short opcode) { - super(opcode, (short)1); - } - - public Class[] getExceptions() { - return org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; - } - - /** @return type associated with the instruction - */ - public Type getType(ConstantPoolGen cp) { - switch(opcode) { - case org.aspectj.apache.bcel.Constants.IALOAD: case org.aspectj.apache.bcel.Constants.IASTORE: - return Type.INT; - case org.aspectj.apache.bcel.Constants.CALOAD: case org.aspectj.apache.bcel.Constants.CASTORE: - return Type.CHAR; - case org.aspectj.apache.bcel.Constants.BALOAD: case org.aspectj.apache.bcel.Constants.BASTORE: - return Type.BYTE; - case org.aspectj.apache.bcel.Constants.SALOAD: case org.aspectj.apache.bcel.Constants.SASTORE: - return Type.SHORT; - case org.aspectj.apache.bcel.Constants.LALOAD: case org.aspectj.apache.bcel.Constants.LASTORE: - return Type.LONG; - case org.aspectj.apache.bcel.Constants.DALOAD: case org.aspectj.apache.bcel.Constants.DASTORE: - return Type.DOUBLE; - case org.aspectj.apache.bcel.Constants.FALOAD: case org.aspectj.apache.bcel.Constants.FASTORE: - return Type.FLOAT; - case org.aspectj.apache.bcel.Constants.AALOAD: case org.aspectj.apache.bcel.Constants.AASTORE: - return Type.OBJECT; - - default: throw new ClassGenException("Oops: unknown case in switch" + opcode); - } - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ArrayType.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ArrayType.java index 6da18e636..1b417dab2 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ArrayType.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/ArrayType.java @@ -1,156 +1,156 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; - -/** - * Denotes array type, such as int[][] - * - * @version $Id: ArrayType.java,v 1.2.10.1 2008/04/25 17:55:35 aclement Exp $ - * @author M. Dahm - */ -public final class ArrayType extends ReferenceType { - private int dimensions; - private Type basic_type; - - /** - * Convenience constructor for array type, e.g. int[] - * - * @param type array type, e.g. T_INT - */ - public ArrayType(byte type, int dimensions) { - this(BasicType.getType(type), dimensions); - } - - /** - * Convenience constructor for reference array type, e.g. Object[] - * - * @param class_name complete name of class (java.lang.String, e.g.) - */ - public ArrayType(String class_name, int dimensions) { - this(new ObjectType(class_name), dimensions); - } - - /** - * Constructor for array of given type - * - * @param type type of array (may be an array itself) - */ - public ArrayType(Type type, int dimensions) { - super(Constants.T_ARRAY, ""); - - if((dimensions < 1) || (dimensions > Constants.MAX_BYTE)) - throw new ClassGenException("Invalid number of dimensions: " + dimensions); - - switch(type.getType()) { - case Constants.T_ARRAY: - ArrayType array = (ArrayType)type; - this.dimensions = dimensions + array.dimensions; - basic_type = array.basic_type; - break; - - case Constants.T_VOID: - throw new ClassGenException("Invalid type: void[]"); - - default: // Basic type or reference - this.dimensions = dimensions; - basic_type = type; - break; - } - - StringBuffer buf = new StringBuffer(); - for(int i=0; i < this.dimensions; i++) - buf.append('['); - - buf.append(basic_type.getSignature()); - - signature = buf.toString(); - } - - /** - * @return basic type of array, i.e., for int[][][] the basic type is int - */ - public Type getBasicType() { - return basic_type; - } - - /** - * @return element type of array, i.e., for int[][][] the element type is int[][] - */ - public Type getElementType() { - if(dimensions == 1) - return basic_type; - else - return new ArrayType(basic_type, dimensions - 1); - } - - /** @return number of dimensions of array - */ - public int getDimensions() { return dimensions; } - - /** @return a hash code value for the object. - */ - public int hashcode() { return basic_type.hashCode() ^ dimensions; } - - /** @return true if both type objects refer to the same array type. - */ - public boolean equals(Object type) { - if(type instanceof ArrayType) { - ArrayType array = (ArrayType)type; - return (array.dimensions == dimensions) && array.basic_type.equals(basic_type); - } else - return false; - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import org.aspectj.apache.bcel.Constants; + +/** + * Denotes array type, such as int[][] + * + * @version $Id: ArrayType.java,v 1.2.10.2 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + */ +public final class ArrayType extends ReferenceType { + private int dimensions; + private Type basic_type; + + /** + * Convenience constructor for array type, e.g. int[] + * + * @param type array type, e.g. T_INT + */ + public ArrayType(byte type, int dimensions) { + this(BasicType.getType(type), dimensions); + } + + /** + * Convenience constructor for reference array type, e.g. Object[] + * + * @param class_name complete name of class (java.lang.String, e.g.) + */ + public ArrayType(String class_name, int dimensions) { + this(new ObjectType(class_name), dimensions); + } + + /** + * Constructor for array of given type + * + * @param type type of array (may be an array itself) + */ + public ArrayType(Type type, int dimensions) { + super(Constants.T_ARRAY, ""); + + if((dimensions < 1) || (dimensions > Constants.MAX_BYTE)) + throw new ClassGenException("Invalid number of dimensions: " + dimensions); + + switch(type.getType()) { + case Constants.T_ARRAY: + ArrayType array = (ArrayType)type; + this.dimensions = dimensions + array.dimensions; + basic_type = array.basic_type; + break; + + case Constants.T_VOID: + throw new ClassGenException("Invalid type: void[]"); + + default: // Basic type or reference + this.dimensions = dimensions; + basic_type = type; + break; + } + + StringBuffer buf = new StringBuffer(); + for(int i=0; i < this.dimensions; i++) + buf.append('['); + + buf.append(basic_type.getSignature()); + + signature = buf.toString(); + } + + /** + * @return basic type of array, i.e., for int[][][] the basic type is int + */ + public Type getBasicType() { + return basic_type; + } + + /** + * @return element type of array, i.e., for int[][][] the element type is int[][] + */ + public Type getElementType() { + if(dimensions == 1) + return basic_type; + else + return new ArrayType(basic_type, dimensions - 1); + } + + /** @return number of dimensions of array + */ + public int getDimensions() { return dimensions; } + + /** @return a hash code value for the object. + */ + public int hashcode() { return basic_type.hashCode() ^ dimensions; } + + /** @return true if both type objects refer to the same array type. + */ + public boolean equals(Object type) { + if(type instanceof ArrayType) { + ArrayType array = (ArrayType)type; + return (array.dimensions == dimensions) && array.basic_type.equals(basic_type); + } else + return false; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/BALOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/BALOAD.java deleted file mode 100644 index ac55a2640..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/BALOAD.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * BALOAD - Load byte or boolean from array - *
          Stack: ..., arrayref, index -> ..., value
          - * - * @version $Id: BALOAD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class BALOAD extends ArrayInstruction implements StackProducer { - /** Load byte or boolean from array - */ - public BALOAD() { - super(org.aspectj.apache.bcel.Constants.BALOAD); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitBALOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/BASTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/BASTORE.java deleted file mode 100644 index 6822be233..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/BASTORE.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * BASTORE - Store into byte or boolean array - *
          Stack: ..., arrayref, index, value -> ...
          - * - * @version $Id: BASTORE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class BASTORE extends ArrayInstruction implements StackConsumer { - /** Store byte or boolean into array - */ - public BASTORE() { - super(org.aspectj.apache.bcel.Constants.BASTORE); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitBASTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/BIPUSH.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/BIPUSH.java deleted file mode 100644 index 699012316..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/BIPUSH.java +++ /dev/null @@ -1,131 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.*; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * BIPUSH - Push byte on stack - * - *
          Stack: ... -> ..., value
          - * - * @version $Id: BIPUSH.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class BIPUSH extends Instruction implements ConstantPushInstruction { - private byte b; - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - BIPUSH() {} - - /** Push byte on stack - */ - public BIPUSH(byte b) { - super(org.aspectj.apache.bcel.Constants.BIPUSH, (short)2); - this.b = b; - } - - /** - * Dump instruction as byte code to stream out. - */ - public void dump(DataOutputStream out) throws IOException { - super.dump(out); - out.writeByte(b); - } - - /** - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - return super.toString(verbose) + " " + b; - } - - /** - * Read needed data (e.g. index) from file. - */ - protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException - { - length = 2; - b = bytes.readByte(); - } - - public Number getValue() { return new Integer(b); } - - /** @return Type.BYTE - */ - public Type getType(ConstantPoolGen cp) { - return Type.BYTE; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitPushInstruction(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitConstantPushInstruction(this); - v.visitBIPUSH(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/BREAKPOINT.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/BREAKPOINT.java deleted file mode 100644 index 93cb32278..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/BREAKPOINT.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * BREAKPOINT, JVM dependent, ignored by default - * - * @version $Id: BREAKPOINT.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class BREAKPOINT extends Instruction { - public BREAKPOINT() { - super(org.aspectj.apache.bcel.Constants.BREAKPOINT, (short)1); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitBREAKPOINT(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/BasicType.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/BasicType.java index 26de7e5a8..0b3b29432 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/BasicType.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/BasicType.java @@ -1,101 +1,101 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; - -/** - * Denotes basic type such as int. - * - * @version $Id: BasicType.java,v 1.2.10.1 2008/04/25 17:55:32 aclement Exp $ - * @author M. Dahm - */ -public final class BasicType extends Type { - /** - * Constructor for basic types such as int, long, `void' - * - * @param type one of T_INT, T_BOOLEAN, ..., T_VOID - * @see org.aspectj.apache.bcel.Constants - */ - BasicType(byte type) { - super(type, Constants.SHORT_TYPE_NAMES[type]); - - if((type < Constants.T_BOOLEAN) || (type > Constants.T_VOID)) - throw new ClassGenException("Invalid type: " + type); - } - - public static final BasicType getType(byte type) { - switch(type) { - case Constants.T_VOID: return VOID; - case Constants.T_BOOLEAN: return BOOLEAN; - case Constants.T_BYTE: return BYTE; - case Constants.T_SHORT: return SHORT; - case Constants.T_CHAR: return CHAR; - case Constants.T_INT: return INT; - case Constants.T_LONG: return LONG; - case Constants.T_DOUBLE: return DOUBLE; - case Constants.T_FLOAT: return FLOAT; - - default: - throw new ClassGenException("Invalid type: " + type); - } - } - - /** @return true if both type objects refer to the same type - */ - public boolean equals(Object type) { - return (type instanceof BasicType)? - ((BasicType)type).type == this.type : false; - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import org.aspectj.apache.bcel.Constants; + +/** + * Denotes basic type such as int. + * + * @version $Id: BasicType.java,v 1.2.10.2 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public final class BasicType extends Type { + /** + * Constructor for basic types such as int, long, `void' + * + * @param type one of T_INT, T_BOOLEAN, ..., T_VOID + * @see org.aspectj.apache.bcel.Constants + */ + BasicType(byte type) { + super(type, Constants.SHORT_TYPE_NAMES[type]); + + if((type < Constants.T_BOOLEAN) || (type > Constants.T_VOID)) + throw new ClassGenException("Invalid type: " + type); + } + + public static final BasicType getType(byte type) { + switch(type) { + case Constants.T_VOID: return VOID; + case Constants.T_BOOLEAN: return BOOLEAN; + case Constants.T_BYTE: return BYTE; + case Constants.T_SHORT: return SHORT; + case Constants.T_CHAR: return CHAR; + case Constants.T_INT: return INT; + case Constants.T_LONG: return LONG; + case Constants.T_DOUBLE: return DOUBLE; + case Constants.T_FLOAT: return FLOAT; + + default: + throw new ClassGenException("Invalid type: " + type); + } + } + + /** @return true if both type objects refer to the same type + */ + public boolean equals(Object type) { + return (type instanceof BasicType)? + ((BasicType)type).type == this.type : false; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/BranchHandle.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/BranchHandle.java index 5d31b4bb3..4465bce97 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/BranchHandle.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/BranchHandle.java @@ -1,151 +1,131 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * BranchHandle is returned by specialized InstructionList.append() whenever a - * BranchInstruction is appended. This is useful when the target of this - * instruction is not known at time of creation and must be set later - * via setTarget(). - * - * @see InstructionHandle - * @see Instruction - * @see InstructionList - * @version $Id: BranchHandle.java,v 1.2.10.2 2008/04/25 17:55:33 aclement Exp $ - * @author M. Dahm - */ -public final class BranchHandle extends InstructionHandle { - private InstructionBranch bi; // An alias in fact, but saves lots of casts - - private BranchHandle(InstructionBranch i) { - super(i); - bi = i; - } - - /** Factory methods. - */ - private static BranchHandle bh_list = null; // List of reusable handles - - static final BranchHandle getBranchHandle(InstructionBranch i) { - if(bh_list == null) - return new BranchHandle(i); - else { - BranchHandle bh = bh_list; - bh_list = (BranchHandle)bh.next; - - bh.setInstruction(i); - - return bh; - } - } - - /** Handle adds itself to the list of resuable handles. - */ - protected void addHandle() { - next = bh_list; - bh_list = this; - } - - /* Override InstructionHandle methods: delegate to branch instruction. - * Through this overriding all access to the private i_position field should - * be prevented. - */ - public int getPosition() { return bi.positionOfThisInstruction; } - - void setPosition(int pos) { - i_position = bi.positionOfThisInstruction = pos; - } - - protected int updatePosition(int offset, int max_offset) { - int x = bi.updatePosition(offset, max_offset); - i_position = bi.positionOfThisInstruction; - return x; - } - - /** - * Pass new target to instruction. - */ - public void setTarget(InstructionHandle ih) { - bi.setTarget(ih); - } - - /** - * Update target of instruction. - */ - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { - bi.updateTarget(old_ih, new_ih); - } - - /** - * @return target of instruction. - */ - public InstructionHandle getTarget() { - return bi.getTarget(); - } - - /** - * Set new contents. Old instruction is disposed and may not be used anymore. - */ - public void setInstruction(Instruction i) { - super.setInstruction(i); - - if(!(i instanceof InstructionBranch)) - throw new ClassGenException("Assigning " + i + - " to branch handle which is not a branch instruction"); - - bi = (InstructionBranch)i; - } -} - +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * BranchHandle is returned by specialized InstructionList.append() whenever a + * BranchInstruction is appended. This is useful when the target of this + * instruction is not known at time of creation and must be set later + * via setTarget(). + * + * @see InstructionHandle + * @see Instruction + * @see InstructionList + * @version $Id: BranchHandle.java,v 1.2.10.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + */ +public final class BranchHandle extends InstructionHandle { + private InstructionBranch bi; // An alias in fact, but saves lots of casts + + private BranchHandle(InstructionBranch i) { + super(i); + bi = i; + } + + static final BranchHandle getBranchHandle(InstructionBranch i) { + return new BranchHandle(i); + } + + /* Override InstructionHandle methods: delegate to branch instruction. + * Through this overriding all access to the private i_position field should + * be prevented. + */ + public int getPosition() { return bi.positionOfThisInstruction; } + + void setPosition(int pos) { + i_position = bi.positionOfThisInstruction = pos; + } + + protected int updatePosition(int offset, int max_offset) { + int x = bi.updatePosition(offset, max_offset); + i_position = bi.positionOfThisInstruction; + return x; + } + + /** + * Pass new target to instruction. + */ + public void setTarget(InstructionHandle ih) { + bi.setTarget(ih); + } + + /** + * Update target of instruction. + */ + public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { + bi.updateTarget(old_ih, new_ih); + } + + /** + * @return target of instruction. + */ + public InstructionHandle getTarget() { + return bi.getTarget(); + } + + /** + * Set new contents. Old instruction is disposed and may not be used anymore. + */ + public void setInstruction(Instruction i) { + super.setInstruction(i); + + if(!(i instanceof InstructionBranch)) + throw new ClassGenException("Assigning " + i + + " to branch handle which is not a branch instruction"); + + bi = (InstructionBranch)i; + } +} + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/BranchInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/BranchInstruction.java deleted file mode 100644 index c81508076..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/BranchInstruction.java +++ /dev/null @@ -1,246 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.*; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * Abstract super class for branching instructions like GOTO, IFEQ, etc.. - * Branch instructions may have a variable length, namely GOTO, JSR, - * LOOKUPSWITCH and TABLESWITCH. - * - * @see InstructionList - * @version $Id: BranchInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public abstract class BranchInstruction extends Instruction implements InstructionTargeter { - protected int index; // Branch target relative to this instruction - protected InstructionHandle target; // Target object in instruction list - protected int position; // Byte code offset - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - BranchInstruction() {} - - /** Common super constructor - * @param opcodee Instruction opcode - * @param target instruction to branch to - */ - protected BranchInstruction(short opcode, InstructionHandle target) { - super(opcode, (short)3); - setTarget(target); - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - out.writeByte(opcode); - - index = getTargetOffset(); - - if(Math.abs(index) >= 32767) // too large for short - throw new ClassGenException("Branch target offset too large for short"); - - out.writeShort(index); // May be negative, i.e., point backwards - } - - /** - * @param target branch target - * @return the offset to `target' relative to this instruction - */ - protected int getTargetOffset(InstructionHandle target) { - if(target == null) - throw new ClassGenException("Target of " + super.toString(true) + - " is invalid null handle"); - - int t = target.getPosition(); - - if(t < 0) - throw new ClassGenException("Invalid branch target position offset for " + - super.toString(true) + ":" + t + ":" + target); - - return t - position; - } - - /** - * @return the offset to this instruction's target - */ - protected int getTargetOffset() { return getTargetOffset(target); } - - /** - * Called by InstructionList.setPositions when setting the position for every - * instruction. In the presence of variable length instructions `setPositions' - * performs multiple passes over the instruction list to calculate the - * correct (byte) positions and offsets by calling this function. - * - * @param offset additional offset caused by preceding (variable length) instructions - * @param max_offset the maximum offset that may be caused by these instructions - * @return additional offset caused by possible change of this instruction's length - */ - protected int updatePosition(int offset, int max_offset) { - position += offset; - return 0; - } - - /** - * Long output format: - * - * <position in byte code> - * <name of opcode> "["<opcode number>"]" - * "("<length of instruction>")" - * "<"<target instruction>">" "@"<branch target offset> - * - * @param verbose long/short format switch - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - String s = super.toString(verbose); - String t = "null"; - - if(verbose) { - if(target != null) { - if(target.getInstruction() == this) - t = ""; - else if(target.getInstruction() == null) - t = ""; - else - t = target.getInstruction().toString(false); // Avoid circles - } - } else { - if(target != null) { - index = getTargetOffset(); - t = "" + (index + position); - } - } - - return s + " -> " + t; - } - - /** - * Read needed data (e.g. index) from file. Conversion to a InstructionHandle - * is done in InstructionList(byte[]). - * - * @param bytes input stream - * @param wide wide prefix? - * @see InstructionList - */ - protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException - { - length = 3; - index = bytes.readShort(); - } - - /** - * @return target offset in byte code - */ - public final int getIndex() { return index; } - - /** - * @return target of branch instruction - */ - public InstructionHandle getTarget() { return target; } - - /** - * Set branch target - * @param target branch target - */ - public void setTarget(InstructionHandle target) { - notifyTarget(this.target, target, this); - this.target = target; - } - - /** - * Used by BranchInstruction, LocalVariableGen, CodeExceptionGen - */ - static final void notifyTarget(InstructionHandle old_ih, InstructionHandle new_ih, - InstructionTargeter t) { - if(old_ih != null) - old_ih.removeTargeter(t); - if(new_ih != null) - new_ih.addTargeter(t); - } - - /** - * @param old_ih old target - * @param new_ih new target - */ - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { - if(target == old_ih) - setTarget(new_ih); - else - throw new ClassGenException("Not targeting " + old_ih + ", but " + target); - } - - /** - * @return true, if ih is target of this instruction - */ - public boolean containsTarget(InstructionHandle ih) { - return (target == ih); - } - - /** - * Inform target that it's not targeted anymore. - */ - void dispose() { - setTarget(null); - index=-1; - position=-1; - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/CALOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/CALOAD.java deleted file mode 100644 index c63464260..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/CALOAD.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * CALOAD - Load char from array - *
          Stack: ..., arrayref, index -> ..., value
          - * - * @version $Id: CALOAD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class CALOAD extends ArrayInstruction implements StackProducer { - /** Load char from array - */ - public CALOAD() { - super(org.aspectj.apache.bcel.Constants.CALOAD); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitCALOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/CASTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/CASTORE.java deleted file mode 100644 index 4cf608c9e..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/CASTORE.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * CASTORE - Store into char array - *
          Stack: ..., arrayref, index, value -> ...
          - * - * @version $Id: CASTORE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class CASTORE extends ArrayInstruction implements StackConsumer { - /** Store char into array - */ - public CASTORE() { - super(org.aspectj.apache.bcel.Constants.CASTORE); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitCASTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/CHECKCAST.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/CHECKCAST.java deleted file mode 100644 index 22a16b0e7..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/CHECKCAST.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.ExceptionConstants; -/** - * CHECKCAST - Check whether object is of given type - *
          Stack: ..., objectref -> ..., objectref
          - * - * @version $Id: CHECKCAST.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class CHECKCAST extends CPInstruction - implements LoadClass, ExceptionThrower, StackProducer, StackConsumer { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - CHECKCAST() {} - - /** Check whether object is of given type - * @param n index to class in constant pool - */ - public CHECKCAST(int index) { - super(org.aspectj.apache.bcel.Constants.CHECKCAST, index); - } - - /** @return exceptions this instruction may cause - */ - public Class[] getExceptions() { - Class[] cs = new Class[1 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length]; - - System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, - cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length); - cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = - ExceptionConstants.CLASS_CAST_EXCEPTION; - return cs; - } - - public ObjectType getLoadClassType(ConstantPoolGen cpg) { - Type t = getType(cpg); - - if(t instanceof ArrayType) - t = ((ArrayType) t).getBasicType(); - - return (t instanceof ObjectType)? (ObjectType) t : null; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitLoadClass(this); - v.visitExceptionThrower(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitTypedInstruction(this); - v.visitCPInstruction(this); - v.visitCHECKCAST(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/CPInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/CPInstruction.java deleted file mode 100644 index de89b5fd2..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/CPInstruction.java +++ /dev/null @@ -1,169 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.DataOutputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.classfile.Constant; -import org.aspectj.apache.bcel.classfile.ConstantClass; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * Abstract super class for instructions that use an index into the - * constant pool such as LDC, INVOKEVIRTUAL, etc. - * - * @see ConstantPoolGen - * @see LDC - * @see INVOKEVIRTUAL - * - * @version $Id: CPInstruction.java,v 1.4 2004/11/22 08:31:27 aclement Exp $ - * @author M. Dahm - */ -public abstract class CPInstruction extends Instruction - implements TypedInstruction, IndexedInstruction -{ - protected int index; // index to constant pool - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - CPInstruction() {} - - /** - * @param index to constant pool - */ - protected CPInstruction(short opcode, int index) { - super(opcode, (short)3); - setIndex(index); - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - out.writeByte(opcode); - out.writeShort(index); - } - - /** - * Long output format: - * - * <name of opcode> "["<opcode number>"]" - * "("<length of instruction>")" "<"< constant pool index>">" - * - * @param verbose long/short format switch - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - return super.toString(verbose) + " " + index; - } - - /** - * @return mnemonic for instruction with symbolic references resolved - */ - public String toString(ConstantPool cp) { - Constant c = cp.getConstant(index); - String str = cp.constantToString(c); - - if(c instanceof ConstantClass) - str = str.replace('.', '/'); - - return org.aspectj.apache.bcel.Constants.OPCODE_NAMES[opcode] + " " + str; - } - - /** - * Read needed data (i.e., index) from file. - * @param bytes input stream - * @param wide wide prefix? - */ - protected void initFromFile(ByteSequence bytes, boolean wide) - throws IOException - { - setIndex(bytes.readUnsignedShort()); - length = 3; - } - - /** - * @return index in constant pool referred by this instruction. - */ - public final int getIndex() { return index; } - - /** - * Set the index to constant pool. - * @param index in constant pool. - */ - public void setIndex(int index) { - if(index < 0) - throw new ClassGenException("Negative index value: " + index); - - this.index = index; - } - - /** @return type related with this instruction. - */ - public Type getType(ConstantPoolGen cpg) { - ConstantPool cp = cpg.getConstantPool(); - String name = cp.getConstantString(index, org.aspectj.apache.bcel.Constants.CONSTANT_Class); - - if(!name.startsWith("[")) - name = "L" + name + ";"; - - return Type.getType(name); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ClassGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ClassGen.java index 5c1e68171..8584655b4 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ClassGen.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/ClassGen.java @@ -1,712 +1,700 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.lang.reflect.Modifier; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.AccessFlags; -import org.aspectj.apache.bcel.classfile.Attribute; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.Field; -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.classfile.SourceFile; -import org.aspectj.apache.bcel.classfile.Utility; -import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; - -/** - * Template class for building up a java class. May be initialized with an - * existing java class (file). - * - * @see JavaClass - * @version $Id: ClassGen.java,v 1.8.4.2 2008/04/25 17:55:34 aclement Exp $ - * @author M. Dahm - * - * Upgraded, Andy Clement 9th Mar 06 - calculates SUID - */ -public class ClassGen extends AccessFlags implements Cloneable { - /* Corresponds to the fields found in a JavaClass object. - */ - private String class_name, super_class_name, file_name; - private int class_name_index = -1, superclass_name_index = -1; - private int major = Constants.MAJOR_1_1, minor = Constants.MINOR_1_1; - - private ConstantPool cp; // Template for building up constant pool - - // ArrayLists instead of arrays to gather fields, methods, etc. - private ArrayList field_vec = new ArrayList(); - private ArrayList method_vec = new ArrayList(); - private ArrayList attribute_vec = new ArrayList(); - private ArrayList interface_vec = new ArrayList(); - private ArrayList annotation_vec= new ArrayList(); - private boolean unpackedAnnotations = false; - - /** Convenience constructor to set up some important values initially. - * - * @param class_name fully qualified class name - * @param super_class_name fully qualified superclass name - * @param file_name source file name - * @param access_flags access qualifiers - * @param interfaces implemented interfaces - * @param cp constant pool to use - */ - public ClassGen(String class_name, String super_class_name, String file_name, - int access_flags, String[] interfaces, ConstantPool cp) { - this.class_name = class_name; - this.super_class_name = super_class_name; - this.file_name = file_name; - this.accessflags = access_flags; - this.cp = cp; - - // Put everything needed by default into the constant pool and the vectors - if(file_name != null) - addAttribute(new SourceFile(cp.addUtf8("SourceFile"), 2, - cp.addUtf8(file_name), cp)); - - class_name_index = cp.addClass(class_name); - superclass_name_index = cp.addClass(super_class_name); - - if(interfaces != null) - for(int i=0; i < interfaces.length; i++) - addInterface(interfaces[i]); - } - - /** Convenience constructor to set up some important values initially. - * - * @param class_name fully qualified class name - * @param super_class_name fully qualified superclass name - * @param file_name source file name - * @param access_flags access qualifiers - * @param interfaces implemented interfaces - */ - public ClassGen(String class_name, String super_class_name, String file_name, - int access_flags, String[] interfaces) { - this(class_name, super_class_name, file_name, access_flags, interfaces, - new ConstantPool()); - } - - /** - * Initialize with existing class. - * @param clazz JavaClass object (e.g. read from file) - */ - public ClassGen(JavaClass clazz) { - class_name_index = clazz.getClassNameIndex(); - superclass_name_index = clazz.getSuperclassNameIndex(); - class_name = clazz.getClassName(); - super_class_name = clazz.getSuperclassName(); - file_name = clazz.getSourceFileName(); - accessflags = clazz.getAccessFlags(); - cp = clazz.getConstantPool().copy(); - major = clazz.getMajor(); - minor = clazz.getMinor(); - - Attribute[] attributes = clazz.getAttributes(); - // J5TODO: Could make unpacking lazy, done on first reference - AnnotationGen[] annotations = unpackAnnotations(attributes); - Method[] methods = clazz.getMethods(); - Field[] fields = clazz.getFields(); - String[] interfaces = clazz.getInterfaceNames(); - - for(int i=0; i < interfaces.length; i++) - addInterface(interfaces[i]); - - //Attribute[] attrs = attributes.getAttributes(); - for(int i=0; i < attributes.length; i++) { - // Dont add attributes for annotations as those will have been unpacked - if (annotations.length==0) { - addAttribute(attributes[i]); - } else if (!attributes[i].getName().equals("RuntimeVisibleAnnotations") && - !attributes[i].getName().equals("RuntimeInvisibleAnnotations")) { - addAttribute(attributes[i]); - } - } - for(int i=0; i < annotations.length; i++) - addAnnotation(annotations[i]); - - for(int i=0; i < methods.length; i++) { - Method m = methods[i]; - addMethod(m); - } - - for(int i=0; i < fields.length; i++) - addField(fields[i]); - } - - /** - * Look for attributes representing annotations and unpack them. - */ - private AnnotationGen[] unpackAnnotations(Attribute[] attrs) { - List /*AnnotationGen*/ annotationGenObjs = new ArrayList(); - for (int i = 0; i < attrs.length; i++) { - Attribute attr = attrs[i]; - if (attr instanceof RuntimeVisibleAnnotations) { - RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations)attr; - List annos = rva.getAnnotations(); - for (Iterator iter = annos.iterator(); iter.hasNext();) { - AnnotationGen a = (AnnotationGen) iter.next(); - annotationGenObjs.add(new AnnotationGen(a,getConstantPool(),false)); - } - } else if (attr instanceof RuntimeInvisibleAnnotations) { - RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations)attr; - List annos = ria.getAnnotations(); - for (Iterator iter = annos.iterator(); iter.hasNext();) { - AnnotationGen a = (AnnotationGen) iter.next(); - annotationGenObjs.add(new AnnotationGen(a,getConstantPool(),false)); - } - } - } - return (AnnotationGen[])annotationGenObjs.toArray(new AnnotationGen[]{}); - } - - /** - * @return the (finally) built up Java class object. - */ - public JavaClass getJavaClass() { - int[] interfaces = getInterfaces(); - Field[] fields = getFields(); - Method[] methods = getMethods(); - - Attribute[] attributes = null; - if (annotation_vec.size()==0) { - attributes = getAttributes(); - } else { - // TODO: Sometime later, trash any attributes called 'RuntimeVisibleAnnotations' or 'RuntimeInvisibleAnnotations' - Attribute[] annAttributes = Utility.getAnnotationAttributes(cp,annotation_vec); - attributes = new Attribute[attribute_vec.size()+annAttributes.length]; - attribute_vec.toArray(attributes); - System.arraycopy(annAttributes,0,attributes,attribute_vec.size(),annAttributes.length); - } - - // Must be last since the above calls may still add something to it - ConstantPool cp = this.cp.getFinalConstantPool(); - - return new JavaClass(class_name_index, superclass_name_index, - file_name, major, minor, accessflags, - cp, interfaces, fields, methods, attributes); - } - - /** - * Add an interface to this class, i.e., this class has to implement it. - * @param name interface to implement (fully qualified class name) - */ - public void addInterface(String name) { - interface_vec.add(name); - } - - /** - * Remove an interface from this class. - * @param name interface to remove (fully qualified name) - */ - public void removeInterface(String name) { - interface_vec.remove(name); - } - - /** - * @return major version number of class file - */ - public int getMajor() { return major; } - - /** Set major version number of class file, default value is 45 (JDK 1.1) - * @param major major version number - */ - public void setMajor(int major) { - this.major = major; - } - - /** Set minor version number of class file, default value is 3 (JDK 1.1) - * @param minor minor version number - */ - public void setMinor(int minor) { - this.minor = minor; - } - - /** - * @return minor version number of class file - */ - public int getMinor() { return minor; } - - /** - * Add an attribute to this class. - * @param a attribute to add - */ - public void addAttribute(Attribute a) { attribute_vec.add(a); } - - public void addAnnotation(AnnotationGen a) { annotation_vec.add(a); } - /** - * Add a method to this class. - * @param m method to add - */ - public void addMethod(Method m) { method_vec.add(m); } - - /** - * Convenience method. - * - * Add an empty constructor to this class that does nothing but calling super(). - * @param access rights for constructor - */ - public void addEmptyConstructor(int access_flags) { - InstructionList il = new InstructionList(); - il.append(InstructionConstants.THIS); // Push `this' - il.append(new InvokeInstruction(Constants.INVOKESPECIAL,cp.addMethodref(super_class_name,"", "()V"))); - il.append(InstructionConstants.RETURN); - - MethodGen mg = new MethodGen(access_flags, Type.VOID, Type.NO_ARGS, null, - "", class_name, il, cp); - mg.setMaxStack(1); - mg.setMaxLocals(); - addMethod(mg.getMethod()); - } - - /** - * Add a field to this class. - * @param f field to add - */ - public void addField(Field f) { field_vec.add(f); } - - public boolean containsField(Field f) { return field_vec.contains(f); } - - /** @return field object with given name, or null - */ - public Field containsField(String name) { - for(Iterator e=field_vec.iterator(); e.hasNext(); ) { - Field f = (Field)e.next(); - if(f.getName().equals(name)) - return f; - } - - return null; - } - - /** @return method object with given name and signature, or null - */ - public Method containsMethod(String name, String signature) { - for(Iterator e=method_vec.iterator(); e.hasNext();) { - Method m = (Method)e.next(); - if(m.getName().equals(name) && m.getSignature().equals(signature)) - return m; - } - - return null; - } - - /** - * Remove an attribute from this class. - * @param a attribute to remove - */ - public void removeAttribute(Attribute a) { attribute_vec.remove(a); } - public void removeAnnotation(AnnotationGen a) {annotation_vec.remove(a);} - - /** - * Remove a method from this class. - * @param m method to remove - */ - public void removeMethod(Method m) { method_vec.remove(m); } - - /** Replace given method with new one. If the old one does not exist - * add the new_ method to the class anyway. - */ - public void replaceMethod(Method old, Method new_) { - if(new_ == null) - throw new ClassGenException("Replacement method must not be null"); - - int i = method_vec.indexOf(old); - - if(i < 0) - method_vec.add(new_); - else - method_vec.set(i, new_); - } - - /** Replace given field with new one. If the old one does not exist - * add the new_ field to the class anyway. - */ - public void replaceField(Field old, Field new_) { - if(new_ == null) - throw new ClassGenException("Replacement method must not be null"); - - int i = field_vec.indexOf(old); - - if(i < 0) - field_vec.add(new_); - else - field_vec.set(i, new_); - } - - /** - * Remove a field to this class. - * @param f field to remove - */ - public void removeField(Field f) { field_vec.remove(f); } - - public String getClassName() { return class_name; } - public String getSuperclassName() { return super_class_name; } - public String getFileName() { return file_name; } - - public void setClassName(String name) { - class_name = name.replace('/', '.'); - class_name_index = cp.addClass(name); - } - - public void setSuperclassName(String name) { - super_class_name = name.replace('/', '.'); - superclass_name_index = cp.addClass(name); - } - - public Method[] getMethods() { - Method[] methods = new Method[method_vec.size()]; - method_vec.toArray(methods); - return methods; - } - - public void setMethods(Method[] methods) { - method_vec.clear(); - for(int m=0; m0) classmods|=Constants.ACC_ABSTRACT; - } else { - classmods|=Constants.ACC_ABSTRACT; - } - } - - dos.writeInt(classmods); - - // 3. ordered list of interfaces - List list = new ArrayList(); - String[] names = getInterfaceNames(); - if (names!=null) { - Arrays.sort(names); - for (int i = 0; i < names.length; i++) dos.writeUTF(names[i]); - } - - // 4. ordered list of fields (ignoring private static and private transient fields): - // (relevant modifiers are ACC_PUBLIC, ACC_PRIVATE, - // ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_VOLATILE, - // ACC_TRANSIENT) - list.clear(); - for (int i = 0; i < fields.length; i++) { - Field field = fields[i]; - if (!(field.isPrivate() && field.isStatic()) && - !(field.isPrivate() && field.isTransient())) list.add(field); - } - Collections.sort(list,new FieldComparator()); - int relevantFlags = Constants.ACC_PUBLIC | Constants.ACC_PRIVATE | Constants.ACC_PROTECTED | - Constants.ACC_STATIC | Constants.ACC_FINAL | Constants.ACC_VOLATILE | Constants.ACC_TRANSIENT; - for (Iterator iter = list.iterator(); iter.hasNext();) { - Field f = (Field) iter.next(); - dos.writeUTF(f.getName()); - dos.writeInt(relevantFlags&f.getModifiers()); - dos.writeUTF(f.getType().getSignature()); - } - - // some up front method processing: discover clinit, init and ordinary methods of interest: - list.clear(); // now used for methods - List ctors = new ArrayList(); - boolean hasClinit = false; - for (int i = 0; i < methods.length; i++) { - Method m = methods[i]; - boolean couldBeInitializer = m.getName().charAt(0)=='<'; - if (couldBeInitializer && m.getName().equals("")) { - hasClinit=true; - } else if (couldBeInitializer && m.getName().equals("")) { - if (!m.isPrivate()) ctors.add(m); - } else { - if (!m.isPrivate()) list.add(m); - } - } - Collections.sort(ctors, new ConstructorComparator()); - Collections.sort(list, new MethodComparator()); - - - // 5. If a class initializer exists, write out the following: - // 1. The name of the method, . - // 2. The modifier of the method, java.lang.reflect.Modifier.STATIC, written as a 32-bit integer. - // 3. The descriptor of the method, ()V. - if (hasClinit) { - dos.writeUTF(""); - dos.writeInt(Modifier.STATIC); - dos.writeUTF("()V"); - } - - // for methods and constructors: - // ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, - // ACC_NATIVE, ACC_ABSTRACT and ACC_STRICT - relevantFlags = - Constants.ACC_PUBLIC | Constants.ACC_PRIVATE | Constants.ACC_PROTECTED | - Constants.ACC_STATIC | Constants.ACC_FINAL | Constants.ACC_SYNCHRONIZED | - Constants.ACC_NATIVE | Constants.ACC_ABSTRACT | Constants.ACC_STRICT; - - // 6. sorted non-private constructors - for (Iterator iter = ctors.iterator(); iter.hasNext();) { - Method m = (Method) iter.next(); - dos.writeUTF(m.getName()); // - dos.writeInt(relevantFlags & m.getModifiers()); - dos.writeUTF(m.getSignature().replace('/','.')); - } - - // 7. sorted non-private methods - for (Iterator iter = list.iterator(); iter.hasNext();) { - Method m = (Method) iter.next(); - dos.writeUTF(m.getName()); - dos.writeInt(relevantFlags & m.getModifiers()); - dos.writeUTF(m.getSignature().replace('/','.')); - } - dos.flush(); - dos.close(); - byte[] bs = baos.toByteArray(); - MessageDigest md = MessageDigest.getInstance("SHA"); - byte[] result = md.digest(bs); - - long suid = 0L; - int pos = result.length>8?7:result.length-1; // use the bytes we have - while (pos>=0) { - suid = suid<<8 | ((long)result[pos--]&0xff); - } - - // if it was definetly 8 everytime... - // long suid = ((long)(sha[0]&0xff) | (long)(sha[1]&0xff) << 8 | - // (long)(sha[2]&0xff) << 16 | (long)(sha[3]&0xff) << 24 | - // (long)(sha[4]&0xff) << 32 | (long)(sha[5]&0xff) << 40 | - // (long)(sha[6]&0xff) << 48 | (long)(sha[7]&0xff) << 56); - return suid; - } catch (Exception e) { - System.err.println("Unable to calculate suid for "+getClassName()); - e.printStackTrace(); - throw new RuntimeException("Unable to calculate suid for "+getClassName()+": "+e.toString()); - } - } - - private static class FieldComparator implements Comparator { - public int compare(Object arg0, Object arg1) { - return ((Field)arg0).getName().compareTo(((Field)arg1).getName()); - } - } - private static class ConstructorComparator implements Comparator { - public int compare(Object arg0, Object arg1) { - // can ignore the name... - return ((Method)arg0).getSignature().compareTo(((Method)arg1).getSignature()); - } - } - private static class MethodComparator implements Comparator { - public int compare(Object arg0, Object arg1) { - Method m1 = (Method)arg0; - Method m2 = (Method)arg1; - int result = m1.getName().compareTo(m2.getName()); - if (result!=0) return result; - return m1.getSignature().compareTo(m2.getSignature()); - } - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.lang.reflect.Modifier; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.Modifiers; +import org.aspectj.apache.bcel.classfile.Attribute; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.classfile.Field; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.classfile.SourceFile; +import org.aspectj.apache.bcel.classfile.Utility; +import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; + +/** + * Template class for building up a java class. May be initialized with an + * existing java class (file). + * + * @see JavaClass + * @version $Id: ClassGen.java,v 1.8.4.3 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + * + * Upgraded, Andy Clement 9th Mar 06 - calculates SUID + */ +public class ClassGen extends Modifiers implements Cloneable { + + private String class_name, super_class_name, file_name; + private int class_name_index = -1, superclass_name_index = -1; + private int major = Constants.MAJOR_1_1, minor = Constants.MINOR_1_1; + + private ConstantPool cp; + + private ArrayList field_vec = new ArrayList(); + private ArrayList method_vec = new ArrayList(); + private ArrayList attributesList = new ArrayList(); + private ArrayList interface_vec = new ArrayList(); + private ArrayList annotation_vec= new ArrayList(); + private boolean unpackedAnnotations = false; + + /** Convenience constructor to set up some important values initially. + * + * @param class_name fully qualified class name + * @param super_class_name fully qualified superclass name + * @param file_name source file name + * @param access_flags access qualifiers + * @param interfaces implemented interfaces + * @param cp constant pool to use + */ + public ClassGen(String class_name, String super_class_name, String file_name, + int access_flags, String[] interfaces, ConstantPool cp) { + this.class_name = class_name; + this.super_class_name = super_class_name; + this.file_name = file_name; + this.modifiers = access_flags; + this.cp = cp; + + // Put everything needed by default into the constant pool and the vectors + if (file_name != null) { + addAttribute(new SourceFile(cp.addUtf8("SourceFile"), 2, cp.addUtf8(file_name), cp)); + } + + class_name_index = cp.addClass(class_name); + superclass_name_index = cp.addClass(super_class_name); + + if (interfaces != null) { + for(int i=0; i < interfaces.length; i++) + addInterface(interfaces[i]); + } + } + + /** Convenience constructor to set up some important values initially. + * + * @param class_name fully qualified class name + * @param super_class_name fully qualified superclass name + * @param file_name source file name + * @param access_flags access qualifiers + * @param interfaces implemented interfaces + */ + public ClassGen(String class_name, String super_class_name, String file_name, + int access_flags, String[] interfaces) { + this(class_name, super_class_name, file_name, access_flags, interfaces, + new ConstantPool()); + } + + /** + * Initialize with existing class. + * @param clazz JavaClass object (e.g. read from file) + */ + public ClassGen(JavaClass clazz) { + class_name_index = clazz.getClassNameIndex(); + superclass_name_index = clazz.getSuperclassNameIndex(); + class_name = clazz.getClassName(); + super_class_name = clazz.getSuperclassName(); + file_name = clazz.getSourceFileName(); + modifiers = clazz.getModifiers(); + cp = clazz.getConstantPool().copy(); + major = clazz.getMajor(); + minor = clazz.getMinor(); + + Attribute[] attributes = clazz.getAttributes(); + // J5TODO: Could make unpacking lazy, done on first reference + AnnotationGen[] annotations = unpackAnnotations(attributes); + Method[] methods = clazz.getMethods(); + Field[] fields = clazz.getFields(); + String[] interfaces = clazz.getInterfaceNames(); + + for(int i=0; i < interfaces.length; i++) + addInterface(interfaces[i]); + + //Attribute[] attrs = attributes.getAttributes(); + for(int i=0; i < attributes.length; i++) { + // Dont add attributes for annotations as those will have been unpacked + if (annotations.length==0) { + addAttribute(attributes[i]); + } else if (!attributes[i].getName().equals("RuntimeVisibleAnnotations") && + !attributes[i].getName().equals("RuntimeInvisibleAnnotations")) { + addAttribute(attributes[i]); + } + } + for(int i=0; i < annotations.length; i++) + addAnnotation(annotations[i]); + + for(int i=0; i < methods.length; i++) { + Method m = methods[i]; + addMethod(m); + } + + for(int i=0; i < fields.length; i++) + addField(fields[i]); + } + + /** + * Look for attributes representing annotations and unpack them. + */ + private AnnotationGen[] unpackAnnotations(Attribute[] attrs) { + List /*AnnotationGen*/ annotationGenObjs = new ArrayList(); + for (int i = 0; i < attrs.length; i++) { + Attribute attr = attrs[i]; + if (attr instanceof RuntimeVisibleAnnotations) { + RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations)attr; + List annos = rva.getAnnotations(); + for (Iterator iter = annos.iterator(); iter.hasNext();) { + AnnotationGen a = (AnnotationGen) iter.next(); + annotationGenObjs.add(new AnnotationGen(a,getConstantPool(),false)); + } + } else if (attr instanceof RuntimeInvisibleAnnotations) { + RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations)attr; + List annos = ria.getAnnotations(); + for (Iterator iter = annos.iterator(); iter.hasNext();) { + AnnotationGen a = (AnnotationGen) iter.next(); + annotationGenObjs.add(new AnnotationGen(a,getConstantPool(),false)); + } + } + } + return (AnnotationGen[])annotationGenObjs.toArray(new AnnotationGen[]{}); + } + + /** + * @return the (finally) built up Java class object. + */ + public JavaClass getJavaClass() { + int[] interfaces = getInterfaces(); + Field[] fields = getFields(); + Method[] methods = getMethods(); + + // OPTIMIZE sort out this mangling of arrays and collections + Attribute[] attributes = null; + if (annotation_vec.size()==0) { + attributes = getAttributes(); + } else { + // TODO: Sometime later, trash any attributes called 'RuntimeVisibleAnnotations' or 'RuntimeInvisibleAnnotations' + Attribute[] annAttributes = Utility.getAnnotationAttributes(cp,annotation_vec); + attributes = new Attribute[attributesList.size()+annAttributes.length]; + attributesList.toArray(attributes); + System.arraycopy(annAttributes,0,attributes,attributesList.size(),annAttributes.length); + } + + // Must be last since the above calls may still add something to it + ConstantPool cp = this.cp.getFinalConstantPool(); + + return new JavaClass(class_name_index, superclass_name_index, + file_name, major, minor, modifiers, + cp, interfaces, fields, methods, attributes); + } + + /** + * Add an interface to this class, i.e., this class has to implement it. + * @param name interface to implement (fully qualified class name) + */ + public void addInterface(String name) { + interface_vec.add(name); + } + + /** + * Remove an interface from this class. + * @param name interface to remove (fully qualified name) + */ + public void removeInterface(String name) { + interface_vec.remove(name); + } + + /** + * @return major version number of class file + */ + public int getMajor() { return major; } + + /** Set major version number of class file, default value is 45 (JDK 1.1) + * @param major major version number + */ + public void setMajor(int major) { + this.major = major; + } + + /** Set minor version number of class file, default value is 3 (JDK 1.1) + * @param minor minor version number + */ + public void setMinor(int minor) { + this.minor = minor; + } + + /** + * @return minor version number of class file + */ + public int getMinor() { return minor; } + + /** + * Add an attribute to this class. + * @param a attribute to add + */ + public void addAttribute(Attribute a) { attributesList.add(a); } + + public void addAnnotation(AnnotationGen a) { annotation_vec.add(a); } + /** + * Add a method to this class. + * @param m method to add + */ + public void addMethod(Method m) { method_vec.add(m); } + + /** + * Convenience method. + * + * Add an empty constructor to this class that does nothing but calling super(). + * @param access rights for constructor + */ + public void addEmptyConstructor(int access_flags) { + InstructionList il = new InstructionList(); + il.append(InstructionConstants.THIS); // Push `this' + il.append(new InvokeInstruction(Constants.INVOKESPECIAL,cp.addMethodref(super_class_name,"", "()V"))); + il.append(InstructionConstants.RETURN); + + MethodGen mg = new MethodGen(access_flags, Type.VOID, Type.NO_ARGS, null, + "", class_name, il, cp); + mg.setMaxStack(1); + mg.setMaxLocals(); + addMethod(mg.getMethod()); + } + + /** + * Add a field to this class. + * @param f field to add + */ + public void addField(Field f) { field_vec.add(f); } + + public boolean containsField(Field f) { return field_vec.contains(f); } + + /** @return field object with given name, or null + */ + public Field containsField(String name) { + for(Iterator e=field_vec.iterator(); e.hasNext(); ) { + Field f = (Field)e.next(); + if(f.getName().equals(name)) + return f; + } + + return null; + } + + /** @return method object with given name and signature, or null + */ + public Method containsMethod(String name, String signature) { + for(Iterator e=method_vec.iterator(); e.hasNext();) { + Method m = (Method)e.next(); + if(m.getName().equals(name) && m.getSignature().equals(signature)) + return m; + } + + return null; + } + + /** + * Remove an attribute from this class. + * @param a attribute to remove + */ + public void removeAttribute(Attribute a) { attributesList.remove(a); } + public void removeAnnotation(AnnotationGen a) {annotation_vec.remove(a);} + + /** + * Remove a method from this class. + * @param m method to remove + */ + public void removeMethod(Method m) { method_vec.remove(m); } + + /** Replace given method with new one. If the old one does not exist + * add the new_ method to the class anyway. + */ + public void replaceMethod(Method old, Method new_) { + if(new_ == null) + throw new ClassGenException("Replacement method must not be null"); + + int i = method_vec.indexOf(old); + + if (i < 0) + method_vec.add(new_); + else + method_vec.set(i, new_); + } + + /** Replace given field with new one. If the old one does not exist + * add the new_ field to the class anyway. + */ + public void replaceField(Field old, Field new_) { + if(new_ == null) + throw new ClassGenException("Replacement method must not be null"); + + int i = field_vec.indexOf(old); + + if(i < 0) + field_vec.add(new_); + else + field_vec.set(i, new_); + } + + /** + * Remove a field to this class. + * @param f field to remove + */ + public void removeField(Field f) { field_vec.remove(f); } + + public String getClassName() { return class_name; } + public String getSuperclassName() { return super_class_name; } + public String getFileName() { return file_name; } + + public void setClassName(String name) { + class_name = name.replace('/', '.'); + class_name_index = cp.addClass(name); + } + + public void setSuperclassName(String name) { + super_class_name = name.replace('/', '.'); + superclass_name_index = cp.addClass(name); + } + + public Method[] getMethods() { + Method[] methods = new Method[method_vec.size()]; + method_vec.toArray(methods); + return methods; + } + + public void setMethods(Method[] methods) { + method_vec.clear(); + for(int m=0; m0) classmods|=Constants.ACC_ABSTRACT; + } else { + classmods|=Constants.ACC_ABSTRACT; + } + } + + dos.writeInt(classmods); + + // 3. ordered list of interfaces + List list = new ArrayList(); + String[] names = getInterfaceNames(); + if (names!=null) { + Arrays.sort(names); + for (int i = 0; i < names.length; i++) dos.writeUTF(names[i]); + } + + // 4. ordered list of fields (ignoring private static and private transient fields): + // (relevant modifiers are ACC_PUBLIC, ACC_PRIVATE, + // ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_VOLATILE, + // ACC_TRANSIENT) + list.clear(); + for (int i = 0; i < fields.length; i++) { + Field field = fields[i]; + if (!(field.isPrivate() && field.isStatic()) && + !(field.isPrivate() && field.isTransient())) list.add(field); + } + Collections.sort(list,new FieldComparator()); + int relevantFlags = Constants.ACC_PUBLIC | Constants.ACC_PRIVATE | Constants.ACC_PROTECTED | + Constants.ACC_STATIC | Constants.ACC_FINAL | Constants.ACC_VOLATILE | Constants.ACC_TRANSIENT; + for (Iterator iter = list.iterator(); iter.hasNext();) { + Field f = (Field) iter.next(); + dos.writeUTF(f.getName()); + dos.writeInt(relevantFlags&f.getModifiers()); + dos.writeUTF(f.getType().getSignature()); + } + + // some up front method processing: discover clinit, init and ordinary methods of interest: + list.clear(); // now used for methods + List ctors = new ArrayList(); + boolean hasClinit = false; + for (int i = 0; i < methods.length; i++) { + Method m = methods[i]; + boolean couldBeInitializer = m.getName().charAt(0)=='<'; + if (couldBeInitializer && m.getName().equals("")) { + hasClinit=true; + } else if (couldBeInitializer && m.getName().equals("")) { + if (!m.isPrivate()) ctors.add(m); + } else { + if (!m.isPrivate()) list.add(m); + } + } + Collections.sort(ctors, new ConstructorComparator()); + Collections.sort(list, new MethodComparator()); + + + // 5. If a class initializer exists, write out the following: + // 1. The name of the method, . + // 2. The modifier of the method, java.lang.reflect.Modifier.STATIC, written as a 32-bit integer. + // 3. The descriptor of the method, ()V. + if (hasClinit) { + dos.writeUTF(""); + dos.writeInt(Modifier.STATIC); + dos.writeUTF("()V"); + } + + // for methods and constructors: + // ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, + // ACC_NATIVE, ACC_ABSTRACT and ACC_STRICT + relevantFlags = + Constants.ACC_PUBLIC | Constants.ACC_PRIVATE | Constants.ACC_PROTECTED | + Constants.ACC_STATIC | Constants.ACC_FINAL | Constants.ACC_SYNCHRONIZED | + Constants.ACC_NATIVE | Constants.ACC_ABSTRACT | Constants.ACC_STRICT; + + // 6. sorted non-private constructors + for (Iterator iter = ctors.iterator(); iter.hasNext();) { + Method m = (Method) iter.next(); + dos.writeUTF(m.getName()); // + dos.writeInt(relevantFlags & m.getModifiers()); + dos.writeUTF(m.getSignature().replace('/','.')); + } + + // 7. sorted non-private methods + for (Iterator iter = list.iterator(); iter.hasNext();) { + Method m = (Method) iter.next(); + dos.writeUTF(m.getName()); + dos.writeInt(relevantFlags & m.getModifiers()); + dos.writeUTF(m.getSignature().replace('/','.')); + } + dos.flush(); + dos.close(); + byte[] bs = baos.toByteArray(); + MessageDigest md = MessageDigest.getInstance("SHA"); + byte[] result = md.digest(bs); + + long suid = 0L; + int pos = result.length>8?7:result.length-1; // use the bytes we have + while (pos>=0) { + suid = suid<<8 | ((long)result[pos--]&0xff); + } + + // if it was definetly 8 everytime... + // long suid = ((long)(sha[0]&0xff) | (long)(sha[1]&0xff) << 8 | + // (long)(sha[2]&0xff) << 16 | (long)(sha[3]&0xff) << 24 | + // (long)(sha[4]&0xff) << 32 | (long)(sha[5]&0xff) << 40 | + // (long)(sha[6]&0xff) << 48 | (long)(sha[7]&0xff) << 56); + return suid; + } catch (Exception e) { + System.err.println("Unable to calculate suid for "+getClassName()); + e.printStackTrace(); + throw new RuntimeException("Unable to calculate suid for "+getClassName()+": "+e.toString()); + } + } + + private static class FieldComparator implements Comparator { + public int compare(Object arg0, Object arg1) { + return ((Field)arg0).getName().compareTo(((Field)arg1).getName()); + } + } + private static class ConstructorComparator implements Comparator { + public int compare(Object arg0, Object arg1) { + // can ignore the name... + return ((Method)arg0).getSignature().compareTo(((Method)arg1).getSignature()); + } + } + private static class MethodComparator implements Comparator { + public int compare(Object arg0, Object arg1) { + Method m1 = (Method)arg0; + Method m2 = (Method)arg1; + int result = m1.getName().compareTo(m2.getName()); + if (result!=0) return result; + return m1.getSignature().compareTo(m2.getSignature()); + } + } + + public boolean hasAttribute(String attributeName) { + for (Iterator iter = attributesList.iterator(); iter.hasNext();) { + Attribute attr = (Attribute) iter.next(); + if (attr.getName().equals(attributeName)) return true; + } + return false; + } + + public Attribute getAttribute(String attributeName) { + for (Iterator iter = attributesList.iterator(); iter.hasNext();) { + Attribute attr = (Attribute) iter.next(); + if (attr.getName().equals(attributeName)) return attr; + } + return null; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ClassGenException.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ClassGenException.java index 195b48740..2eb7e8215 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ClassGenException.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/ClassGenException.java @@ -1,68 +1,68 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Thrown on internal errors. Extends RuntimeException so it hasn't to be declared - * in the throws clause every time. - * - * @version $Id: ClassGenException.java,v 1.2.10.1 2008/04/25 17:55:32 aclement Exp $ - * @author M. Dahm - */ -public class ClassGenException extends RuntimeException { - public ClassGenException() { super(); } - public ClassGenException(String s) { super(s); } -} - +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Thrown on internal errors. Extends RuntimeException so it hasn't to be declared + * in the throws clause every time. + * + * @version $Id: ClassGenException.java,v 1.2.10.2 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + */ +public class ClassGenException extends RuntimeException { + public ClassGenException() { super(); } + public ClassGenException(String s) { super(s); } +} + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ClassObserver.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ClassObserver.java deleted file mode 100644 index 896d98abc..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ClassObserver.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Implement this interface if you're interested in changes to a ClassGen object - * and register yourself with addObserver(). - * - * @version $Id: ClassObserver.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public interface ClassObserver { - public void notify(ClassGen clazz); -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/CodeExceptionGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/CodeExceptionGen.java index 044177d36..bcf024f98 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/CodeExceptionGen.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/CodeExceptionGen.java @@ -1,202 +1,202 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.classfile.CodeException; -import org.aspectj.apache.bcel.classfile.ConstantPool; - -/** - * This class represents an exception handler, i.e., specifies the region where - * a handler is active and an instruction where the actual handling is done. - * pool as parameters. Opposed to the JVM specification the end of the handled - * region is set to be inclusive, i.e. all instructions between start and end - * are protected including the start and end instructions (handles) themselves. - * The end of the region is automatically mapped to be exclusive when calling - * getCodeException(), i.e., there is no difference semantically. - * - * @version $Id: CodeExceptionGen.java,v 1.4.10.2 2008/04/25 17:55:33 aclement Exp $ - * @author M. Dahm - * @see MethodGen - * @see CodeException - * @see InstructionHandle - */ -public final class CodeExceptionGen - implements InstructionTargeter, Cloneable, java.io.Serializable { - private InstructionHandle start_pc; - private InstructionHandle end_pc; - private InstructionHandle handler_pc; - private ObjectType catch_type; - - /** - * Add an exception handler, i.e., specify region where a handler is active and an - * instruction where the actual handling is done. - * - * @param start_pc Start of handled region (inclusive) - * @param end_pc End of handled region (inclusive) - * @param handler_pc Where handling is done - * @param catch_type which exception is handled, null for ANY - */ - public CodeExceptionGen(InstructionHandle start_pc, InstructionHandle end_pc, - InstructionHandle handler_pc, ObjectType catch_type) { - setStartPC(start_pc); - setEndPC(end_pc); - setHandlerPC(handler_pc); - this.catch_type = catch_type; - } - - /** - * Get CodeException object.
          - * - * This relies on that the instruction list has already been dumped - * to byte code or or that the `setPositions' methods has been - * called for the instruction list. - * - * @param cp constant pool - */ - public CodeException getCodeException(ConstantPool cp) { - return new CodeException(start_pc.getPosition(), - end_pc.getPosition() + end_pc.getInstruction().getLength(), - handler_pc.getPosition(), - (catch_type == null)? 0 : cp.addClass(catch_type)); - } - - /* Set start of handler - * @param start_pc Start of handled region (inclusive) - */ - public void setStartPC(InstructionHandle start_pc) { - InstructionBranch.notifyTarget(this.start_pc, start_pc, this); - this.start_pc = start_pc; - } - - /* Set end of handler - * @param end_pc End of handled region (inclusive) - */ - public void setEndPC(InstructionHandle end_pc) { - InstructionBranch.notifyTarget(this.end_pc, end_pc, this); - this.end_pc = end_pc; - } - - /* Set handler code - * @param handler_pc Start of handler - */ - public void setHandlerPC(InstructionHandle handler_pc) { - InstructionBranch.notifyTarget(this.handler_pc, handler_pc, this); - this.handler_pc = handler_pc; - } - - /** - * @param old_ih old target, either start or end - * @param new_ih new target - */ - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { - boolean targeted = false; - - if(start_pc == old_ih) { - targeted = true; - setStartPC(new_ih); - } - - if(end_pc == old_ih) { - targeted = true; - setEndPC(new_ih); - } - - if(handler_pc == old_ih) { - targeted = true; - setHandlerPC(new_ih); - } - - if(!targeted) - throw new ClassGenException("Not targeting " + old_ih + ", but {" + start_pc + ", " + - end_pc + ", " + handler_pc + "}"); - } - - /** - * @return true, if ih is target of this handler - */ - public boolean containsTarget(InstructionHandle ih) { - return (start_pc == ih) || (end_pc == ih) || (handler_pc == ih); - } - - /** Sets the type of the Exception to catch. Set 'null' for ANY. */ - public void setCatchType(ObjectType catch_type) { this.catch_type = catch_type; } - /** Gets the type of the Exception to catch, 'null' for ANY. */ - public ObjectType getCatchType() { return catch_type; } - - /** @return start of handled region (inclusive) - */ - public InstructionHandle getStartPC() { return start_pc; } - - /** @return end of handled region (inclusive) - */ - public InstructionHandle getEndPC() { return end_pc; } - - /** @return start of handler - */ - public InstructionHandle getHandlerPC() { return handler_pc; } - - public String toString() { - return "CodeExceptionGen(" + start_pc + ", " + end_pc + ", " + handler_pc + ")"; - } - - public Object clone() { - try { - return super.clone(); - } catch(CloneNotSupportedException e) { - System.err.println(e); - return null; - } - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.classfile.CodeException; +import org.aspectj.apache.bcel.classfile.ConstantPool; + +/** + * This class represents an exception handler, i.e., specifies the region where + * a handler is active and an instruction where the actual handling is done. + * pool as parameters. Opposed to the JVM specification the end of the handled + * region is set to be inclusive, i.e. all instructions between start and end + * are protected including the start and end instructions (handles) themselves. + * The end of the region is automatically mapped to be exclusive when calling + * getCodeException(), i.e., there is no difference semantically. + * + * @version $Id: CodeExceptionGen.java,v 1.4.10.3 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + * @see MethodGen + * @see CodeException + * @see InstructionHandle + */ +public final class CodeExceptionGen + implements InstructionTargeter, Cloneable, java.io.Serializable { + private InstructionHandle start_pc; + private InstructionHandle end_pc; + private InstructionHandle handler_pc; + private ObjectType catch_type; + + /** + * Add an exception handler, i.e., specify region where a handler is active and an + * instruction where the actual handling is done. + * + * @param start_pc Start of handled region (inclusive) + * @param end_pc End of handled region (inclusive) + * @param handler_pc Where handling is done + * @param catch_type which exception is handled, null for ANY + */ + public CodeExceptionGen(InstructionHandle start_pc, InstructionHandle end_pc, + InstructionHandle handler_pc, ObjectType catch_type) { + setStartPC(start_pc); + setEndPC(end_pc); + setHandlerPC(handler_pc); + this.catch_type = catch_type; + } + + /** + * Get CodeException object.
          + * + * This relies on that the instruction list has already been dumped + * to byte code or or that the `setPositions' methods has been + * called for the instruction list. + * + * @param cp constant pool + */ + public CodeException getCodeException(ConstantPool cp) { + return new CodeException(start_pc.getPosition(), + end_pc.getPosition() + end_pc.getInstruction().getLength(), + handler_pc.getPosition(), + (catch_type == null)? 0 : cp.addClass(catch_type)); + } + + /* Set start of handler + * @param start_pc Start of handled region (inclusive) + */ + public void setStartPC(InstructionHandle start_pc) { + InstructionBranch.notifyTarget(this.start_pc, start_pc, this); + this.start_pc = start_pc; + } + + /* Set end of handler + * @param end_pc End of handled region (inclusive) + */ + public void setEndPC(InstructionHandle end_pc) { + InstructionBranch.notifyTarget(this.end_pc, end_pc, this); + this.end_pc = end_pc; + } + + /* Set handler code + * @param handler_pc Start of handler + */ + public void setHandlerPC(InstructionHandle handler_pc) { + InstructionBranch.notifyTarget(this.handler_pc, handler_pc, this); + this.handler_pc = handler_pc; + } + + /** + * @param old_ih old target, either start or end + * @param new_ih new target + */ + public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { + boolean targeted = false; + + if(start_pc == old_ih) { + targeted = true; + setStartPC(new_ih); + } + + if(end_pc == old_ih) { + targeted = true; + setEndPC(new_ih); + } + + if(handler_pc == old_ih) { + targeted = true; + setHandlerPC(new_ih); + } + + if(!targeted) + throw new ClassGenException("Not targeting " + old_ih + ", but {" + start_pc + ", " + + end_pc + ", " + handler_pc + "}"); + } + + /** + * @return true, if ih is target of this handler + */ + public boolean containsTarget(InstructionHandle ih) { + return (start_pc == ih) || (end_pc == ih) || (handler_pc == ih); + } + + /** Sets the type of the Exception to catch. Set 'null' for ANY. */ + public void setCatchType(ObjectType catch_type) { this.catch_type = catch_type; } + /** Gets the type of the Exception to catch, 'null' for ANY. */ + public ObjectType getCatchType() { return catch_type; } + + /** @return start of handled region (inclusive) + */ + public InstructionHandle getStartPC() { return start_pc; } + + /** @return end of handled region (inclusive) + */ + public InstructionHandle getEndPC() { return end_pc; } + + /** @return start of handler + */ + public InstructionHandle getHandlerPC() { return handler_pc; } + + public String toString() { + return "CodeExceptionGen(" + start_pc + ", " + end_pc + ", " + handler_pc + ")"; + } + + public Object clone() { + try { + return super.clone(); + } catch(CloneNotSupportedException e) { + System.err.println(e); + return null; + } + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/CompoundInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/CompoundInstruction.java deleted file mode 100644 index 480560d04..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/CompoundInstruction.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Wrapper class for `compound' operations, virtual instructions that - * don't exist as byte code, but give a useful meaning. For example, - * the (virtual) PUSH instruction takes an arbitray argument and produces the - * appropiate code at dump time (ICONST, LDC, BIPUSH, ...). Also you can use the - * SWITCH instruction as a useful template for either LOOKUPSWITCH or - * TABLESWITCH. - * - * The interface provides the possibilty for the user to write - * `templates' or `macros' for such reuseable code patterns. - * - * @version $Id: CompoundInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - * @see PUSH - * @see SWITCH - */ -public interface CompoundInstruction { - public InstructionList getInstructionList(); -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ConstantPoolGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ConstantPoolGen.java deleted file mode 100644 index 686f54e25..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ConstantPoolGen.java +++ /dev/null @@ -1,802 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.HashMap; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.Constant; -import org.aspectj.apache.bcel.classfile.ConstantCP; -import org.aspectj.apache.bcel.classfile.ConstantClass; -import org.aspectj.apache.bcel.classfile.ConstantDouble; -import org.aspectj.apache.bcel.classfile.ConstantFieldref; -import org.aspectj.apache.bcel.classfile.ConstantFloat; -import org.aspectj.apache.bcel.classfile.ConstantInteger; -import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref; -import org.aspectj.apache.bcel.classfile.ConstantLong; -import org.aspectj.apache.bcel.classfile.ConstantMethodref; -import org.aspectj.apache.bcel.classfile.ConstantNameAndType; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.ConstantString; -import org.aspectj.apache.bcel.classfile.ConstantUtf8; - -/** - * This class is used to build up a constant pool. The user adds - * constants via `addXXX' methods, `addString', `addClass', - * etc.. These methods return an index into the constant - * pool. Finally, `getFinalConstantPool()' returns the constant pool - * built up. Intermediate versions of the constant pool can be - * obtained with `getConstantPool()'. A constant pool has capacity for - * Constants.MAX_SHORT entries. Note that the first (0) is used by the - * JVM and that Double and Long constants need two slots. - * - * @version $Id: ConstantPoolGen.java,v 1.3 2004/11/22 08:31:27 aclement Exp $ - * @author M. Dahm - * @see Constant - */ -public class ConstantPoolGen implements java.io.Serializable { - protected int size = 1024; // Inital size, sufficient in most cases - protected Constant[] constants = new Constant[size]; - protected int index = 1; // First entry (0) used by JVM - - private static final String METHODREF_DELIM = ":"; - private static final String IMETHODREF_DELIM = "#"; - private static final String FIELDREF_DELIM = "&"; - private static final String NAT_DELIM = "%"; - - private static class Index implements java.io.Serializable { - int index; - Index(int i) { index = i; } - } - - /** - * Initialize with given array of constants. - * - * @param c array of given constants, new ones will be appended - */ - public ConstantPoolGen(Constant[] cs) { - if(cs.length > size) { - size = cs.length; - constants = new Constant[size]; - } - - System.arraycopy(cs, 0, constants, 0, cs.length); - - if(cs.length > 0) - index = cs.length; - - for(int i=1; i < index; i++) { - Constant c = constants[i]; - - if(c instanceof ConstantString) { - ConstantString s = (ConstantString)c; - ConstantUtf8 u8 = (ConstantUtf8)constants[s.getStringIndex()]; - - string_table.put(u8.getBytes(), new Index(i)); - } else if(c instanceof ConstantClass) { - ConstantClass s = (ConstantClass)c; - ConstantUtf8 u8 = (ConstantUtf8)constants[s.getNameIndex()]; - - class_table.put(u8.getBytes(), new Index(i)); - } else if(c instanceof ConstantNameAndType) { - ConstantNameAndType n = (ConstantNameAndType)c; - ConstantUtf8 u8 = (ConstantUtf8)constants[n.getNameIndex()]; - ConstantUtf8 u8_2 = (ConstantUtf8)constants[n.getSignatureIndex()]; - - n_a_t_table.put(u8.getBytes() + NAT_DELIM + u8_2.getBytes(), new Index(i)); - } else if(c instanceof ConstantUtf8) { - ConstantUtf8 u = (ConstantUtf8)c; - - utf8_table.put(u.getBytes(), new Index(i)); - } else if(c instanceof ConstantCP) { - ConstantCP m = (ConstantCP)c; - ConstantClass clazz = (ConstantClass)constants[m.getClassIndex()]; - ConstantNameAndType n = (ConstantNameAndType)constants[m.getNameAndTypeIndex()]; - - ConstantUtf8 u8 = (ConstantUtf8)constants[clazz.getNameIndex()]; - String class_name = u8.getBytes().replace('/', '.'); - - u8 = (ConstantUtf8)constants[n.getNameIndex()]; - String method_name = u8.getBytes(); - - u8 = (ConstantUtf8)constants[n.getSignatureIndex()]; - String signature = u8.getBytes(); - - String delim = METHODREF_DELIM; - - if(c instanceof ConstantInterfaceMethodref) - delim = IMETHODREF_DELIM; - else if(c instanceof ConstantFieldref) - delim = FIELDREF_DELIM; - - cp_table.put(class_name + delim + method_name + delim + signature, new Index(i)); - } - } - } - - /** - * Initialize with given constant pool. - */ - public ConstantPoolGen(ConstantPool cp) { - this(cp.getConstantPool()); - } - - /** - * Create empty constant pool. - */ - public ConstantPoolGen() {} - - /** Resize internal array of constants. - */ - protected void adjustSize() { - if(index + 3 >= size) { - Constant[] cs = constants; - - size *= 2; - constants = new Constant[size]; - System.arraycopy(cs, 0, constants, 0, index); - } - } - - private HashMap string_table = new HashMap(); - - /** - * Look for ConstantString in ConstantPool containing String `str'. - * - * @param str String to search for - * @return index on success, -1 otherwise - */ - public int lookupString(String str) { - Index index = (Index)string_table.get(str); - return (index != null)? index.index : -1; - } - - /** - * Add a new String constant to the ConstantPool, if it is not already in there. - * - * @param str String to add - * @return index of entry - */ - public int addString(String str) { - int ret; - - if((ret = lookupString(str)) != -1) - return ret; // Already in CP - - int utf8 = addUtf8(str); - - adjustSize(); - - ConstantString s = new ConstantString(utf8); - - ret = index; - constants[index++] = s; - - string_table.put(str, new Index(ret)); - - return ret; - } - - private HashMap class_table = new HashMap(); - - /** - * Look for ConstantClass in ConstantPool named `str'. - * - * @param str String to search for - * @return index on success, -1 otherwise - */ - public int lookupClass(String str) { - Index index = (Index)class_table.get(str.replace('.', '/')); - return (index != null)? index.index : -1; - } - - private int addClass_(String clazz) { - int ret; - - if((ret = lookupClass(clazz)) != -1) - return ret; // Already in CP - - adjustSize(); - - ConstantClass c = new ConstantClass(addUtf8(clazz)); - - ret = index; - constants[index++] = c; - - class_table.put(clazz, new Index(ret)); - - return ret; - } - - /** - * Add a new Class reference to the ConstantPool, if it is not already in there. - * - * @param str Class to add - * @return index of entry - */ - public int addClass(String str) { - return addClass_(str.replace('.', '/')); - } - - /** - * Add a new Class reference to the ConstantPool for a given type. - * - * @param str Class to add - * @return index of entry - */ - public int addClass(ObjectType type) { - //BCELBUG:? Should this we getClassName() - perhaps it should be getSignature() ?!? - return addClass(type.getClassName()); -// return addClass(type.getSignature()); - } - - /** - * Add a reference to an array class (e.g. String[][]) as needed by MULTIANEWARRAY - * instruction, e.g. to the ConstantPool. - * - * @param type type of array class - * @return index of entry - */ - public int addArrayClass(ArrayType type) { - return addClass_(type.getSignature()); - } - - /** - * Look for ConstantInteger in ConstantPool. - * - * @param n integer number to look for - * @return index on success, -1 otherwise - */ - public int lookupInteger(int n) { - for(int i=1; i < index; i++) { - if(constants[i] instanceof ConstantInteger) { - ConstantInteger c = (ConstantInteger)constants[i]; - - if(c.getBytes() == n) - return i; - } - } - - return -1; - } - - /** - * Add a new Integer constant to the ConstantPool, if it is not already in there. - * - * @param n integer number to add - * @return index of entry - */ - public int addInteger(int n) { - int ret; - - if((ret = lookupInteger(n)) != -1) - return ret; // Already in CP - - adjustSize(); - - ret = index; - constants[index++] = new ConstantInteger(n); - - return ret; - } - - /** - * Look for ConstantFloat in ConstantPool. - * - * @param n Float number to look for - * @return index on success, -1 otherwise - */ - public int lookupFloat(float n) { - int bits = Float.floatToIntBits(n); - - for(int i=1; i < index; i++) { - if(constants[i] instanceof ConstantFloat) { - ConstantFloat c = (ConstantFloat)constants[i]; - - if(Float.floatToIntBits(c.getBytes()) == bits) - return i; - } - } - - return -1; - } - - /** - * Add a new Float constant to the ConstantPool, if it is not already in there. - * - * @param n Float number to add - * @return index of entry - */ - public int addFloat(float n) { - int ret; - - if((ret = lookupFloat(n)) != -1) - return ret; // Already in CP - - adjustSize(); - - ret = index; - constants[index++] = new ConstantFloat(n); - - return ret; - } - - private HashMap utf8_table = new HashMap(); - - /** - * Look for ConstantUtf8 in ConstantPool. - * - * @param n Utf8 string to look for - * @return index on success, -1 otherwise - */ - public int lookupUtf8(String n) { - Index index = (Index)utf8_table.get(n); - - return (index != null)? index.index : -1; - } - - /** - * Add a new Utf8 constant to the ConstantPool, if it is not already in there. - * - * @param n Utf8 string to add - * @return index of entry - */ - public int addUtf8(String n) { - int ret; - - if((ret = lookupUtf8(n)) != -1) - return ret; // Already in CP - - adjustSize(); - - ret = index; - constants[index++] = new ConstantUtf8(n); - - utf8_table.put(n, new Index(ret)); - - return ret; - } - - /** - * Look for ConstantLong in ConstantPool. - * - * @param n Long number to look for - * @return index on success, -1 otherwise - */ - public int lookupLong(long n) { - for(int i=1; i < index; i++) { - if(constants[i] instanceof ConstantLong) { - ConstantLong c = (ConstantLong)constants[i]; - - if(c.getBytes() == n) - return i; - } - } - - return -1; - } - - /** - * Add a new long constant to the ConstantPool, if it is not already in there. - * - * @param n Long number to add - * @return index of entry - */ - public int addLong(long n) { - int ret; - - if((ret = lookupLong(n)) != -1) - return ret; // Already in CP - - adjustSize(); - - ret = index; - constants[index] = new ConstantLong(n); - index += 2; // Wastes one entry according to spec - - return ret; - } - - /** - * Look for ConstantDouble in ConstantPool. - * - * @param n Double number to look for - * @return index on success, -1 otherwise - */ - public int lookupDouble(double n) { - long bits = Double.doubleToLongBits(n); - - for(int i=1; i < index; i++) { - if(constants[i] instanceof ConstantDouble) { - ConstantDouble c = (ConstantDouble)constants[i]; - - if(Double.doubleToLongBits(c.getBytes()) == bits) - return i; - } - } - - return -1; - } - - /** - * Add a new double constant to the ConstantPool, if it is not already in there. - * - * @param n Double number to add - * @return index of entry - */ - public int addDouble(double n) { - int ret; - - if((ret = lookupDouble(n)) != -1) - return ret; // Already in CP - - adjustSize(); - - ret = index; - constants[index] = new ConstantDouble(n); - index += 2; // Wastes one entry according to spec - - return ret; - } - - private HashMap n_a_t_table = new HashMap(); - - /** - * Look for ConstantNameAndType in ConstantPool. - * - * @param name of variable/method - * @param signature of variable/method - * @return index on success, -1 otherwise - */ - public int lookupNameAndType(String name, String signature) { - Index index = (Index)n_a_t_table.get(name + NAT_DELIM + signature); - return (index != null)? index.index : -1; - } - - /** - * Add a new NameAndType constant to the ConstantPool if it is not already - * in there. - * - * @param n NameAndType string to add - * @return index of entry - */ - public int addNameAndType(String name, String signature) { - int ret; - int name_index, signature_index; - - if((ret = lookupNameAndType(name, signature)) != -1) - return ret; // Already in CP - - adjustSize(); - - name_index = addUtf8(name); - signature_index = addUtf8(signature); - ret = index; - constants[index++] = new ConstantNameAndType(name_index, signature_index); - - n_a_t_table.put(name + NAT_DELIM + signature, new Index(ret)); - return ret; - } - - private HashMap cp_table = new HashMap(); - - /** - * Look for ConstantMethodref in ConstantPool. - * - * @param class_name Where to find method - * @param method_name Guess what - * @param signature return and argument types - * @return index on success, -1 otherwise - */ - public int lookupMethodref(String class_name, String method_name, String signature) { - Index index = (Index)cp_table.get(class_name + METHODREF_DELIM + method_name + - METHODREF_DELIM + signature); - return (index != null)? index.index : -1; - } - - public int lookupMethodref(MethodGen method) { - return lookupMethodref(method.getClassName(), method.getName(), - method.getSignature()); - } - - /** - * Add a new Methodref constant to the ConstantPool, if it is not already - * in there. - * - * @param n Methodref string to add - * @return index of entry - */ - public int addMethodref(String class_name, String method_name, String signature) { - int ret, class_index, name_and_type_index; - - if((ret = lookupMethodref(class_name, method_name, signature)) != -1) - return ret; // Already in CP - - adjustSize(); - - name_and_type_index = addNameAndType(method_name, signature); - class_index = addClass(class_name); - ret = index; - constants[index++] = new ConstantMethodref(class_index, name_and_type_index); - - cp_table.put(class_name + METHODREF_DELIM + method_name + - METHODREF_DELIM + signature, new Index(ret)); - - return ret; - } - - public int addMethodref(MethodGen method) { - return addMethodref(method.getClassName(), method.getName(), - method.getSignature()); - } - - /** - * Look for ConstantInterfaceMethodref in ConstantPool. - * - * @param class_name Where to find method - * @param method_name Guess what - * @param signature return and argument types - * @return index on success, -1 otherwise - */ - public int lookupInterfaceMethodref(String class_name, String method_name, String signature) { - Index index = (Index)cp_table.get(class_name + IMETHODREF_DELIM + method_name + - IMETHODREF_DELIM + signature); - return (index != null)? index.index : -1; - } - - public int lookupInterfaceMethodref(MethodGen method) { - return lookupInterfaceMethodref(method.getClassName(), method.getName(), - method.getSignature()); - } - - /** - * Add a new InterfaceMethodref constant to the ConstantPool, if it is not already - * in there. - * - * @param n InterfaceMethodref string to add - * @return index of entry - */ - public int addInterfaceMethodref(String class_name, String method_name, String signature) { - int ret, class_index, name_and_type_index; - - if((ret = lookupInterfaceMethodref(class_name, method_name, signature)) != -1) - return ret; // Already in CP - - adjustSize(); - - class_index = addClass(class_name); - name_and_type_index = addNameAndType(method_name, signature); - ret = index; - constants[index++] = new ConstantInterfaceMethodref(class_index, name_and_type_index); - - cp_table.put(class_name + IMETHODREF_DELIM + method_name + - IMETHODREF_DELIM + signature, new Index(ret)); - - return ret; - } - - public int addInterfaceMethodref(MethodGen method) { - return addInterfaceMethodref(method.getClassName(), method.getName(), - method.getSignature()); - } - - /** - * Look for ConstantFieldref in ConstantPool. - * - * @param class_name Where to find method - * @param field_name Guess what - * @param signature return and argument types - * @return index on success, -1 otherwise - */ - public int lookupFieldref(String class_name, String field_name, String signature) { - Index index = (Index)cp_table.get(class_name + FIELDREF_DELIM + field_name + - FIELDREF_DELIM + signature); - return (index != null)? index.index : -1; - } - - /** - * Add a new Fieldref constant to the ConstantPool, if it is not already - * in there. - * - * @param n Fieldref string to add - * @return index of entry - */ - public int addFieldref(String class_name, String field_name, String signature) { - int ret; - int class_index, name_and_type_index; - - if((ret = lookupFieldref(class_name, field_name, signature)) != -1) - return ret; // Already in CP - - adjustSize(); - - class_index = addClass(class_name); - name_and_type_index = addNameAndType(field_name, signature); - ret = index; - constants[index++] = new ConstantFieldref(class_index, name_and_type_index); - - cp_table.put(class_name + FIELDREF_DELIM + field_name + FIELDREF_DELIM + signature, new Index(ret)); - - return ret; - } - - /** - * @param i index in constant pool - * @return constant pool entry at index i - */ - public Constant getConstant(int i) { return constants[i]; } - - /** - * Use with care! - * - * @param i index in constant pool - * @param c new constant pool entry at index i - */ - public void setConstant(int i, Constant c) { constants[i] = c; } - - /** - * @return intermediate constant pool - */ - public ConstantPool getConstantPool() { - return new ConstantPool(constants); - } - - /** - * @return current size of constant pool - */ - public int getSize() { - return index; - } - - /** - * @return constant pool with proper length - */ - public ConstantPool getFinalConstantPool() { - Constant[] cs = new Constant[index]; - - System.arraycopy(constants, 0, cs, 0, index); - - return new ConstantPool(cs); - } - - /** - * @return String representation. - */ - public String toString() { - StringBuffer buf = new StringBuffer(); - - for(int i=1; i < index; i++) - buf.append(i + ")" + constants[i] + "\n"); - - return buf.toString(); - } - - /** Import constant from another ConstantPool and return new index. - */ - public int addConstant(Constant c, ConstantPoolGen cp) { - Constant[] constants = cp.getConstantPool().getConstantPool(); - - switch(c.getTag()) { - case Constants.CONSTANT_String: { - ConstantString s = (ConstantString)c; - ConstantUtf8 u8 = (ConstantUtf8)constants[s.getStringIndex()]; - - return addString(u8.getBytes()); - } - - case Constants.CONSTANT_Class: { - ConstantClass s = (ConstantClass)c; - ConstantUtf8 u8 = (ConstantUtf8)constants[s.getNameIndex()]; - - return addClass(u8.getBytes()); - } - - case Constants.CONSTANT_NameAndType: { - ConstantNameAndType n = (ConstantNameAndType)c; - ConstantUtf8 u8 = (ConstantUtf8)constants[n.getNameIndex()]; - ConstantUtf8 u8_2 = (ConstantUtf8)constants[n.getSignatureIndex()]; - - return addNameAndType(u8.getBytes(), u8_2.getBytes()); - } - - case Constants.CONSTANT_Utf8: - return addUtf8(((ConstantUtf8)c).getBytes()); - - case Constants.CONSTANT_Double: - return addDouble(((ConstantDouble)c).getBytes()); - - case Constants.CONSTANT_Float: - return addFloat(((ConstantFloat)c).getBytes()); - - case Constants.CONSTANT_Long: - return addLong(((ConstantLong)c).getBytes()); - - case Constants.CONSTANT_Integer: - return addInteger(((ConstantInteger)c).getBytes()); - - case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref: - case Constants.CONSTANT_Fieldref: { - ConstantCP m = (ConstantCP)c; - ConstantClass clazz = (ConstantClass)constants[m.getClassIndex()]; - ConstantNameAndType n = (ConstantNameAndType)constants[m.getNameAndTypeIndex()]; - ConstantUtf8 u8 = (ConstantUtf8)constants[clazz.getNameIndex()]; - String class_name = u8.getBytes().replace('/', '.'); - - u8 = (ConstantUtf8)constants[n.getNameIndex()]; - String name = u8.getBytes(); - - u8 = (ConstantUtf8)constants[n.getSignatureIndex()]; - String signature = u8.getBytes(); - - switch(c.getTag()) { - case Constants.CONSTANT_InterfaceMethodref: - return addInterfaceMethodref(class_name, name, signature); - - case Constants.CONSTANT_Methodref: - return addMethodref(class_name, name, signature); - - case Constants.CONSTANT_Fieldref: - return addFieldref(class_name, name, signature); - - default: // Never reached - throw new RuntimeException("Unknown constant type " + c); - } - } - - default: // Never reached - throw new RuntimeException("Unknown constant type " + c); - } - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ConstantPushInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ConstantPushInstruction.java deleted file mode 100644 index ca4a9ae3b..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ConstantPushInstruction.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denotes a push instruction that produces a literal on the stack - * such as SIPUSH, BIPUSH, ICONST, etc. - * - * @version $Id: ConstantPushInstruction.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - - * @see ICONST - * @see SIPUSH - */ -public interface ConstantPushInstruction extends PushInstruction, TypedInstruction { - public Number getValue(); -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ConversionInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ConversionInstruction.java deleted file mode 100644 index e1504b1ff..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ConversionInstruction.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; -/** - * Super class for the x2y family of instructions. - * - * @version $Id: ConversionInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public abstract class ConversionInstruction extends Instruction - implements TypedInstruction, StackProducer, StackConsumer { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - ConversionInstruction() {} - - /** - * @param opcode opcode of instruction - */ - protected ConversionInstruction(short opcode) { - super(opcode, (short)1); - } - - /** @return type associated with the instruction - */ - public Type getType(ConstantPoolGen cp) { - switch(opcode) { - case Constants.D2I: case Constants.F2I: case Constants.L2I: - return Type.INT; - case Constants.D2F: case Constants.I2F: case Constants.L2F: - return Type.FLOAT; - case Constants.D2L: case Constants.F2L: case Constants.I2L: - return Type.LONG; - case Constants.F2D: case Constants.I2D: case Constants.L2D: - return Type.DOUBLE; - case Constants.I2B: - return Type.BYTE; - case Constants.I2C: - return Type.CHAR; - case Constants.I2S: - return Type.SHORT; - - default: // Never reached - throw new ClassGenException("Unknown type " + opcode); - } - } -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/D2F.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/D2F.java deleted file mode 100644 index 73c49e031..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/D2F.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * D2F - Convert double to float - *
          Stack: ..., value.word1, value.word2 -> ..., result
          - * - * @version $Id: D2F.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class D2F extends ConversionInstruction { - /** Convert double to float - */ - public D2F() { - super(org.aspectj.apache.bcel.Constants.D2F); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitD2F(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/D2I.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/D2I.java deleted file mode 100644 index 9be3cd61c..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/D2I.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * D2I - Convert double to int - *
          Stack: ..., value.word1, value.word2 -> ..., result
          - * - * @version $Id: D2I.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class D2I extends ConversionInstruction { - /** Convert double to int - */ - public D2I() { - super(org.aspectj.apache.bcel.Constants.D2I); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitD2I(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/D2L.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/D2L.java deleted file mode 100644 index 4c939c895..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/D2L.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * D2L - Convert double to long - *
          Stack: ..., value.word1, value.word2 -> ..., result.word1, result.word2
          - * - * @version $Id: D2L.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class D2L extends ConversionInstruction { - /** Convert double to long - */ - public D2L() { - super(org.aspectj.apache.bcel.Constants.D2L); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitD2L(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DADD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DADD.java deleted file mode 100644 index b43164aea..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DADD.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DADD - Add doubles - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result.word1, result1.word2 - * - * @version $Id: DADD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DADD extends ArithmeticInstruction { - /** Add doubles - */ - public DADD() { - super(org.aspectj.apache.bcel.Constants.DADD); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitDADD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DALOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DALOAD.java deleted file mode 100644 index 6af53ea90..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DALOAD.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DALOAD - Load double from array - *
          Stack: ..., arrayref, index -> ..., result.word1, result.word2
          - * - * @version $Id: DALOAD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DALOAD extends ArrayInstruction implements StackProducer { - /** Load double from array - */ - public DALOAD() { - super(org.aspectj.apache.bcel.Constants.DALOAD); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitDALOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DASTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DASTORE.java deleted file mode 100644 index 6b1ced1d6..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DASTORE.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DASTORE - Store into double array - *
          Stack: ..., arrayref, index, value.word1, value.word2 -> ...
          - * - * @version $Id: DASTORE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DASTORE extends ArrayInstruction implements StackConsumer { - /** Store double into array - */ - public DASTORE() { - super(org.aspectj.apache.bcel.Constants.DASTORE); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitDASTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DCMPG.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DCMPG.java deleted file mode 100644 index bd176508d..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DCMPG.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DCMPG - Compare doubles: value1 > value2 - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result - * - * @version $Id: DCMPG.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DCMPG extends Instruction - implements TypedInstruction, StackProducer, StackConsumer { - - public DCMPG() { - super(org.aspectj.apache.bcel.Constants.DCMPG, (short)1); - } - - /** @return Type.DOUBLE - */ - public Type getType(ConstantPoolGen cp) { - return Type.DOUBLE; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitDCMPG(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DCMPL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DCMPL.java deleted file mode 100644 index 32374a021..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DCMPL.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DCMPL - Compare doubles: value1 < value2 - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result - * - * @version $Id: DCMPL.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class DCMPL extends Instruction - implements TypedInstruction, StackProducer, StackConsumer { - public DCMPL() { - super(org.aspectj.apache.bcel.Constants.DCMPL, (short)1); - } - - /** @return Type.DOUBLE - */ - public Type getType(ConstantPoolGen cp) { - return Type.DOUBLE; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitDCMPL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DCONST.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DCONST.java deleted file mode 100644 index c875af8ee..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DCONST.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DCONST - Push 0.0 or 1.0, other values cause an exception - * - *
          Stack: ... -> ..., 
          - * - * @version $Id: DCONST.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DCONST extends Instruction - implements ConstantPushInstruction, TypedInstruction { - private double value; - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - DCONST() {} - - public DCONST(double f) { - super(org.aspectj.apache.bcel.Constants.DCONST_0, (short)1); - - if(f == 0.0) - opcode = org.aspectj.apache.bcel.Constants.DCONST_0; - else if(f == 1.0) - opcode = org.aspectj.apache.bcel.Constants.DCONST_1; - else - throw new ClassGenException("DCONST can be used only for 0.0 and 1.0: " + f); - - value = f; - } - - public Number getValue() { return new Double(value); } - - /** @return Type.DOUBLE - */ - public Type getType(ConstantPoolGen cp) { - return Type.DOUBLE; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitPushInstruction(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitConstantPushInstruction(this); - v.visitDCONST(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DDIV.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DDIV.java deleted file mode 100644 index f7f312333..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DDIV.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DDIV - Divide doubles - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result.word1, result.word2 - * - * @version $Id: DDIV.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class DDIV extends ArithmeticInstruction { - /** Divide doubles - */ - public DDIV() { - super(org.aspectj.apache.bcel.Constants.DDIV); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitDDIV(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DLOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DLOAD.java deleted file mode 100644 index 873020cd8..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DLOAD.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DLOAD - Load double from local variable - *
          Stack ... -> ..., result.word1, result.word2
          - * - * @version $Id: DLOAD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DLOAD extends LoadInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - DLOAD() { - super(org.aspectj.apache.bcel.Constants.DLOAD, org.aspectj.apache.bcel.Constants.DLOAD_0); - } - - /** Load double from local variable - * @param n index of local variable - */ - public DLOAD(int n) { - super(org.aspectj.apache.bcel.Constants.DLOAD, org.aspectj.apache.bcel.Constants.DLOAD_0, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - super.accept(v); - v.visitDLOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DMUL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DMUL.java deleted file mode 100644 index b45981d8b..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DMUL.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DMUL - Multiply doubles - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result.word1, result.word2 - * - * @version $Id: DMUL.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class DMUL extends ArithmeticInstruction { - /** Multiply doubles - */ - public DMUL() { - super(org.aspectj.apache.bcel.Constants.DMUL); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitDMUL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DNEG.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DNEG.java deleted file mode 100644 index 89fc8dbed..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DNEG.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DNEG - Negate double - *
          Stack: ..., value.word1, value.word2 -> ..., result.word1, result.word2
          - * - * @version $Id: DNEG.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DNEG extends ArithmeticInstruction { - public DNEG() { - super(org.aspectj.apache.bcel.Constants.DNEG); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitDNEG(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DREM.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DREM.java deleted file mode 100644 index fc99c493d..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DREM.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DREM - Remainder of doubles - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result.word1, result.word2 - * - * @version $Id: DREM.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DREM extends ArithmeticInstruction { - /** Remainder of doubles - */ - public DREM() { - super(org.aspectj.apache.bcel.Constants.DREM); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitDREM(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DRETURN.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DRETURN.java deleted file mode 100644 index 01460af4a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DRETURN.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DRETURN - Return double from method - *
          Stack: ..., value.word1, value.word2 -> <empty>
          - * - * @version $Id: DRETURN.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DRETURN extends ReturnInstruction { - /** Return double from method - */ - public DRETURN() { - super(org.aspectj.apache.bcel.Constants.DRETURN); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackConsumer(this); - v.visitReturnInstruction(this); - v.visitDRETURN(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DSTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DSTORE.java deleted file mode 100644 index 6e4d600b1..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DSTORE.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DSTORE - Store double into local variable - *
          Stack: ..., value.word1, value.word2 -> ... 
          - * - * @version $Id: DSTORE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DSTORE extends StoreInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - DSTORE() { - super(org.aspectj.apache.bcel.Constants.DSTORE, org.aspectj.apache.bcel.Constants.DSTORE_0); - } - - /** Store double into local variable - * @param n index of local variable - */ - public DSTORE(int n) { - super(org.aspectj.apache.bcel.Constants.DSTORE, org.aspectj.apache.bcel.Constants.DSTORE_0, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - super.accept(v); - v.visitDSTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DSUB.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DSUB.java deleted file mode 100644 index 5beb0ca73..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DSUB.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DSUB - Substract doubles - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result.word1, result.word2 - * - * @version $Id: DSUB.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DSUB extends ArithmeticInstruction { - /** Substract doubles - */ - public DSUB() { - super(org.aspectj.apache.bcel.Constants.DSUB); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitDSUB(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP.java deleted file mode 100644 index 98ec90424..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DUP - Duplicate top operand stack word - *
          Stack: ..., word -> ..., word, word
          - * - * @version $Id: DUP.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class DUP extends StackInstruction implements PushInstruction { - public DUP() { - super(org.aspectj.apache.bcel.Constants.DUP); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitStackInstruction(this); - v.visitDUP(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP2.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP2.java deleted file mode 100644 index a4d84dacc..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP2.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DUP2 - Duplicate two top operand stack words - *
          Stack: ..., word2, word1 -> ..., word2, word1, word2, word1
          - * - * @version $Id: DUP2.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DUP2 extends StackInstruction implements PushInstruction { - public DUP2() { - super(org.aspectj.apache.bcel.Constants.DUP2); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitStackInstruction(this); - v.visitDUP2(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP2_X1.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP2_X1.java deleted file mode 100644 index 047c2fd41..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP2_X1.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DUP2_X1 - Duplicate two top operand stack words and put three down - *
          Stack: ..., word3, word2, word1 -> ..., word2, word1, word3, word2, word1
          - * - * @version $Id: DUP2_X1.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DUP2_X1 extends StackInstruction { - public DUP2_X1() { - super(org.aspectj.apache.bcel.Constants.DUP2_X1); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackInstruction(this); - v.visitDUP2_X1(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP2_X2.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP2_X2.java deleted file mode 100644 index ed62fa4ab..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP2_X2.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DUP2_X2 - Duplicate two top operand stack words and put four down - *
          Stack: ..., word4, word3, word2, word1 -> ..., word2, word1, word4, word3, word2, word1
          - * - * @version $Id: DUP2_X2.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class DUP2_X2 extends StackInstruction { - public DUP2_X2() { - super(org.aspectj.apache.bcel.Constants.DUP2_X2); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackInstruction(this); - v.visitDUP2_X2(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP_X1.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP_X1.java deleted file mode 100644 index 46494c028..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP_X1.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DUP_X1 - Duplicate top operand stack word and put two down - *
          Stack: ..., word2, word1 -> ..., word1, word2, word1
          - * - * @version $Id: DUP_X1.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DUP_X1 extends StackInstruction { - public DUP_X1() { - super(org.aspectj.apache.bcel.Constants.DUP_X1); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackInstruction(this); - v.visitDUP_X1(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP_X2.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP_X2.java deleted file mode 100644 index 5042b8815..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/DUP_X2.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * DUP_X2 - Duplicate top operand stack word and put three down - *
          Stack: ..., word3, word2, word1 -> ..., word1, word3, word2, word1
          - * - * @version $Id: DUP_X2.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class DUP_X2 extends StackInstruction { - public DUP_X2() { - super(org.aspectj.apache.bcel.Constants.DUP_X2); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackInstruction(this); - v.visitDUP_X2(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ExceptionThrower.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ExceptionThrower.java deleted file mode 100644 index 5e94141b2..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ExceptionThrower.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denote an instruction that may throw a run-time or a linking - * exception (or both) during execution. This is not quite the truth - * as such; because all instructions may throw an - * java.lang.VirtualMachineError. These exceptions are omitted. - * - * The Lava Language Specification specifies exactly which - * RUN-TIME and which LINKING exceptions each - * instruction may throw which is reflected by the implementers. Due - * to the structure of the JVM specification, it may be possible that - * an Instruction implementing this interface returns a Class[] of - * size 0. - * - * Please note that we speak of an "exception" here when we mean any - * "Throwable" object; so this term is equally used for "Exception" - * and "Error" objects. - * - * @version $Id: ExceptionThrower.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author Enver Haase - */ -public interface ExceptionThrower { - public java.lang.Class[] getExceptions(); -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/F2D.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/F2D.java deleted file mode 100644 index 165c02b49..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/F2D.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * F2D - Convert float to double - *
          Stack: ..., value -> ..., result.word1, result.word2
          - * - * @version $Id: F2D.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class F2D extends ConversionInstruction { - /** Convert float to double - */ - public F2D() { - super(org.aspectj.apache.bcel.Constants.F2D); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitF2D(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/F2I.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/F2I.java deleted file mode 100644 index 3f478a7f0..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/F2I.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * F2I - Convert float to int - *
          Stack: ..., value -> ..., result
          - * - * @version $Id: F2I.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class F2I extends ConversionInstruction { - /** Convert float to int - */ - public F2I() { - super(org.aspectj.apache.bcel.Constants.F2I); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitF2I(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/F2L.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/F2L.java deleted file mode 100644 index 6541ff49a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/F2L.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * F2L - Convert float to long - *
          Stack: ..., value -> ..., result.word1, result.word2
          - * - * @version $Id: F2L.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class F2L extends ConversionInstruction { - /** Convert float to long - */ - public F2L() { - super(org.aspectj.apache.bcel.Constants.F2L); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitF2L(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FADD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FADD.java deleted file mode 100644 index 7c97cf714..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FADD.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FADD - Add floats - *
          Stack: ..., value1, value2 -> result
          - * - * @version $Id: FADD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class FADD extends ArithmeticInstruction { - /** Add floats - */ - public FADD() { - super(org.aspectj.apache.bcel.Constants.FADD); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitFADD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FALOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FALOAD.java deleted file mode 100644 index 7814d971d..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FALOAD.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FALOAD - Load float from array - *
          Stack: ..., arrayref, index -> ..., value
          - * - * @version $Id: FALOAD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class FALOAD extends ArrayInstruction implements StackProducer { - /** Load float from array - */ - public FALOAD() { - super(org.aspectj.apache.bcel.Constants.FALOAD); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitFALOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FASTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FASTORE.java deleted file mode 100644 index e27ffecae..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FASTORE.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FASTORE - Store into float array - *
          Stack: ..., arrayref, index, value -> ...
          - * - * @version $Id: FASTORE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class FASTORE extends ArrayInstruction implements StackConsumer { - /** Store float into array - */ - public FASTORE() { - super(org.aspectj.apache.bcel.Constants.FASTORE); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitFASTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FCMPG.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FCMPG.java deleted file mode 100644 index 606d1fac2..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FCMPG.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FCMPG - Compare floats: value1 > value2 - *
          Stack: ..., value1, value2 -> ..., result
          - * - * @version $Id: FCMPG.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class FCMPG extends Instruction - implements TypedInstruction, StackProducer, StackConsumer { - public FCMPG() { - super(org.aspectj.apache.bcel.Constants.FCMPG, (short)1); - } - - /** @return Type.FLOAT - */ - public Type getType(ConstantPoolGen cp) { - return Type.FLOAT; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitFCMPG(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FCMPL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FCMPL.java deleted file mode 100644 index 5e53952cc..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FCMPL.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FCMPL - Compare floats: value1 < value2 - *
          Stack: ..., value1, value2 -> ..., result
          - * - * @version $Id: FCMPL.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class FCMPL extends Instruction - implements TypedInstruction, StackProducer, StackConsumer { - public FCMPL() { - super(org.aspectj.apache.bcel.Constants.FCMPL, (short)1); - } - - /** @return Type.FLOAT - */ - public Type getType(ConstantPoolGen cp) { - return Type.FLOAT; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitFCMPL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FCONST.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FCONST.java deleted file mode 100644 index c6fa0c03a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FCONST.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FCONST - Push 0.0, 1.0 or 2.0, other values cause an exception - * - *
          Stack: ... -> ..., 
          - * - * @version $Id: FCONST.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class FCONST extends Instruction - implements ConstantPushInstruction, TypedInstruction { - private float value; - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - FCONST() {} - - public FCONST(float f) { - super(org.aspectj.apache.bcel.Constants.FCONST_0, (short)1); - - if(f == 0.0) - opcode = org.aspectj.apache.bcel.Constants.FCONST_0; - else if(f == 1.0) - opcode = org.aspectj.apache.bcel.Constants.FCONST_1; - else if(f == 2.0) - opcode = org.aspectj.apache.bcel.Constants.FCONST_2; - else - throw new ClassGenException("FCONST can be used only for 0.0, 1.0 and 2.0: " + f); - - value = f; - } - - public Number getValue() { return new Float(value); } - - /** @return Type.FLOAT - */ - public Type getType(ConstantPoolGen cp) { - return Type.FLOAT; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitPushInstruction(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitConstantPushInstruction(this); - v.visitFCONST(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FDIV.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FDIV.java deleted file mode 100644 index 3abe077dd..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FDIV.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FDIV - Divide floats - *
          Stack: ..., value1, value2 -> result
          - * - * @version $Id: FDIV.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class FDIV extends ArithmeticInstruction { - /** Divide floats - */ - public FDIV() { - super(org.aspectj.apache.bcel.Constants.FDIV); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitFDIV(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FLOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FLOAD.java deleted file mode 100644 index 8ba53ed45..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FLOAD.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FLOAD - Load float from local variable - *
          Stack ... -> ..., result
          - * - * @version $Id: FLOAD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class FLOAD extends LoadInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - FLOAD() { - super(org.aspectj.apache.bcel.Constants.FLOAD, org.aspectj.apache.bcel.Constants.FLOAD_0); - } - - /** Load float from local variable - * @param n index of local variable - */ - public FLOAD(int n) { - super(org.aspectj.apache.bcel.Constants.FLOAD, org.aspectj.apache.bcel.Constants.FLOAD_0, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - super.accept(v); - v.visitFLOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FMUL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FMUL.java deleted file mode 100644 index 066e211f8..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FMUL.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FMUL - Multiply floats - *
          Stack: ..., value1, value2 -> result
          - * - * @version $Id: FMUL.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class FMUL extends ArithmeticInstruction { - /** Multiply floats - */ - public FMUL() { - super(org.aspectj.apache.bcel.Constants.FMUL); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitFMUL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FNEG.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FNEG.java deleted file mode 100644 index 3fa6addc0..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FNEG.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FNEG - Negate float - *
          Stack: ..., value -> ..., result
          - * - * @version $Id: FNEG.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class FNEG extends ArithmeticInstruction { - public FNEG() { - super(org.aspectj.apache.bcel.Constants.FNEG); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitFNEG(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FREM.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FREM.java deleted file mode 100644 index a32dd7f06..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FREM.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FREM - Remainder of floats - *
          Stack: ..., value1, value2 -> result
          - * - * @version $Id: FREM.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class FREM extends ArithmeticInstruction { - /** Remainder of floats - */ - public FREM() { - super(org.aspectj.apache.bcel.Constants.FREM); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitFREM(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FRETURN.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FRETURN.java deleted file mode 100644 index e2f996410..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FRETURN.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FRETURN - Return float from method - *
          Stack: ..., value -> <empty>
          - * - * @version $Id: FRETURN.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class FRETURN extends ReturnInstruction { - /** Return float from method - */ - public FRETURN() { - super(org.aspectj.apache.bcel.Constants.FRETURN); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackConsumer(this); - v.visitReturnInstruction(this); - v.visitFRETURN(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FSTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FSTORE.java deleted file mode 100644 index f56bba38a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FSTORE.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FSTORE - Store float into local variable - *
          Stack: ..., value -> ... 
          - * - * @version $Id: FSTORE.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class FSTORE extends StoreInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - FSTORE() { - super(org.aspectj.apache.bcel.Constants.FSTORE, org.aspectj.apache.bcel.Constants.FSTORE_0); - } - - /** Store float into local variable - * @param n index of local variable - */ - public FSTORE(int n) { - super(org.aspectj.apache.bcel.Constants.FSTORE, org.aspectj.apache.bcel.Constants.FSTORE_0, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - super.accept(v); - v.visitFSTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FSUB.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FSUB.java deleted file mode 100644 index 00534a42f..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FSUB.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * FSUB - Substract floats - *
          Stack: ..., value1, value2 -> result
          - * - * @version $Id: FSUB.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class FSUB extends ArithmeticInstruction { - /** Substract floats - */ - public FSUB() { - super(org.aspectj.apache.bcel.Constants.FSUB); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitFSUB(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGen.java index 18e52802b..27fae095d 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGen.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGen.java @@ -1,314 +1,236 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.Iterator; -import java.util.List; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.Attribute; -import org.aspectj.apache.bcel.classfile.Constant; -import org.aspectj.apache.bcel.classfile.ConstantObject; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.ConstantValue; -import org.aspectj.apache.bcel.classfile.Field; -import org.aspectj.apache.bcel.classfile.Utility; -import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations; - -/** - * Template class for building up a field. The only extraordinary thing - * one can do is to add a constant value attribute to a field (which must of - * course be compatible with to the declared type). - * - * @version $Id: FieldGen.java,v 1.4.8.2 2008/04/25 17:55:34 aclement Exp $ - * @author M. Dahm - * @see Field - */ -public class FieldGen extends FieldGenOrMethodGen { - private Object value = null; - - /** - * Declare a field. If it is static (isStatic() == true) and has a - * basic type like int or String it may have an initial value - * associated with it as defined by setInitValue(). - * - * @param access_flags access qualifiers - * @param type field type - * @param name field name - * @param cp constant pool - */ - public FieldGen(int access_flags, Type type, String name, ConstantPool cp) { - setAccessFlags(access_flags); - setType(type); - setName(name); - setConstantPool(cp); - } - - /** - * Instantiate from existing field. - * - * @param field Field object - * @param cp constant pool (must contain the same entries as the field's constant pool) - */ - public FieldGen(Field field, ConstantPool cp) { - this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp); - - Attribute[] attrs = field.getAttributes(); - - for(int i=0; i < attrs.length; i++) { - if(attrs[i] instanceof ConstantValue) { - setValue(((ConstantValue)attrs[i]).getConstantValueIndex()); - } else if (attrs[i] instanceof RuntimeAnnotations) { - RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations)attrs[i]; - List l = runtimeAnnotations.getAnnotations(); - for (Iterator it = l.iterator(); it.hasNext();) { - AnnotationGen element = (AnnotationGen) it.next(); - addAnnotation(new AnnotationGen(element,cp,false)); - } - } else { - addAttribute(attrs[i]); - } - } - } - - private void setValue(int index) { - ConstantPool cp = this.cp; - Constant c = cp.getConstant(index); - value = ((ConstantObject)c).getConstantValue(cp); - } - - /** - * Set (optional) initial value of field, otherwise it will be set to null/0/false - * by the JVM automatically. - */ - public void setInitValue(String str) { - checkType(new ObjectType("java.lang.String")); - - if(str != null) - value = str; - } - - public void setInitValue(long l) { - checkType(Type.LONG); - - if(l != 0L) - value = new Long(l); - } - - public void setInitValue(int i) { - checkType(Type.INT); - - if(i != 0) - value = new Integer(i); - } - - public void setInitValue(short s) { - checkType(Type.SHORT); - - if(s != 0) - value = new Integer(s); - } - - public void setInitValue(char c) { - checkType(Type.CHAR); - - if(c != 0) - value = new Integer(c); - } - - public void setInitValue(byte b) { - checkType(Type.BYTE); - - if(b != 0) - value = new Integer(b); - } - - public void setInitValue(boolean b) { - checkType(Type.BOOLEAN); - - if(b) - value = new Integer(1); - } - - public void setInitValue(float f) { - checkType(Type.FLOAT); - - if(f != 0.0) - value = new Float(f); - } - - public void setInitValue(double d) { - checkType(Type.DOUBLE); - - if(d != 0.0) - value = new Double(d); - } - - /** Remove any initial value. - */ - public void cancelInitValue() { - value = null; - } - - private void checkType(Type atype) { - if(type == null) - throw new ClassGenException("You haven't defined the type of the field yet"); - - if(!isFinal()) - throw new ClassGenException("Only final fields may have an initial value!"); - - if(!type.equals(atype)) - throw new ClassGenException("Types are not compatible: " + type + " vs. " + atype); - } - - /** - * Get field object after having set up all necessary values. - */ - public Field getField() { - String signature = getSignature(); - int name_index = cp.addUtf8(name); - int signature_index = cp.addUtf8(signature); - - if(value != null) { - checkType(type); - int index = addConstant(); - addAttribute(new ConstantValue(cp.addUtf8("ConstantValue"), - 2, index, cp)); - } - - addAnnotationsAsAttribute(cp); - - return new Field(accessflags, name_index, signature_index,getAttributes(), - cp); - } - - private void addAnnotationsAsAttribute(ConstantPool cp) { - Attribute[] attrs = Utility.getAnnotationAttributes(cp,annotation_vec); - if (attrs!=null) { - for (int i = 0; i < attrs.length; i++) { - addAttribute(attrs[i]); - } - } - } - - private int addConstant() { - switch(type.getType()) { - case Constants.T_INT: case Constants.T_CHAR: case Constants.T_BYTE: - case Constants.T_BOOLEAN: case Constants.T_SHORT: - return cp.addInteger(((Integer)value).intValue()); - - case Constants.T_FLOAT: - return cp.addFloat(((Float)value).floatValue()); - - case Constants.T_DOUBLE: - return cp.addDouble(((Double)value).doubleValue()); - - case Constants.T_LONG: - return cp.addLong(((Long)value).longValue()); - - case Constants.T_REFERENCE: - return cp.addString(((String)value)); - - default: - throw new RuntimeException("Oops: Unhandled : " + type.getType()); - } - } - - public String getSignature() { return type.getSignature(); } - - - public String getInitValue() { - if(value != null) { - return value.toString(); - } else - return null; - } - - /** - * Return string representation close to declaration format, - * `public static final short MAX = 100', e.g.. - * - * @return String representation of field - */ - public final String toString() { - String name, signature, access; // Short cuts to constant pool - - access = Utility.accessToString(accessflags); - access = access.equals("")? "" : (access + " "); - signature = type.toString(); - name = getName(); - - StringBuffer buf = new StringBuffer(access + signature + " " + name); - String value = getInitValue(); - - if(value != null) - buf.append(" = " + value); - - - // J5TODO: Add attributes and annotations to the string - - return buf.toString(); - } - - /** @return deep copy of this field - */ - public FieldGen copy(ConstantPool cp) { - FieldGen fg = (FieldGen)clone(); - - fg.setConstantPool(cp); - return fg; - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.util.Iterator; +import java.util.List; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.Attribute; +import org.aspectj.apache.bcel.classfile.Constant; +import org.aspectj.apache.bcel.classfile.ConstantObject; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.classfile.ConstantValue; +import org.aspectj.apache.bcel.classfile.Field; +import org.aspectj.apache.bcel.classfile.Utility; +import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations; + +/** + * Template class for building up a field. The only extraordinary thing + * one can do is to add a constant value attribute to a field (which must of + * course be compatible with the declared type). + * + * @version $Id: FieldGen.java,v 1.4.8.3 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + * @see Field + */ +public class FieldGen extends FieldGenOrMethodGen { + private Object value = null; + + /** + * Declare a field. If it is static (isStatic() == true) and has a + * basic type like int or String it may have an initial value + * associated with it as defined by setInitValue(). + * + * @param access_flags access qualifiers + * @param type field type + * @param name field name + * @param cp constant pool + */ + public FieldGen(int access_flags, Type type, String name, ConstantPool cp) { + setModifiers(access_flags); + setType(type); + setName(name); + setConstantPool(cp); + } + + /** + * Instantiate from existing field. + * + * @param field Field object + * @param cp constant pool (must contain the same entries as the field's constant pool) + */ + public FieldGen(Field field, ConstantPool cp) { + this(field.getModifiers(), Type.getType(field.getSignature()), field.getName(), cp); + + Attribute[] attrs = field.getAttributes(); + + for(int i=0; i < attrs.length; i++) { + if(attrs[i] instanceof ConstantValue) { + setValue(((ConstantValue)attrs[i]).getConstantValueIndex()); + } else if (attrs[i] instanceof RuntimeAnnotations) { + RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations)attrs[i]; + List l = runtimeAnnotations.getAnnotations(); + for (Iterator it = l.iterator(); it.hasNext();) { + AnnotationGen element = (AnnotationGen) it.next(); + addAnnotation(new AnnotationGen(element,cp,false)); + } + } else { + addAttribute(attrs[i]); + } + } + } + + private void setValue(int index) { + ConstantPool cp = this.cp; + Constant c = cp.getConstant(index); + value = ((ConstantObject)c).getConstantValue(cp); + } + + + public void wipeValue() { + value = null; + } + + private void checkType(Type atype) { + if(type == null) + throw new ClassGenException("You haven't defined the type of the field yet"); + + if(!isFinal()) + throw new ClassGenException("Only final fields may have an initial value!"); + + if(!type.equals(atype)) + throw new ClassGenException("Types are not compatible: " + type + " vs. " + atype); + } + + /** + * Get field object after having set up all necessary values. + */ + public Field getField() { + String signature = getSignature(); + int name_index = cp.addUtf8(name); + int signature_index = cp.addUtf8(signature); + + if(value != null) { + checkType(type); + int index = addConstant(); + addAttribute(new ConstantValue(cp.addUtf8("ConstantValue"), + 2, index, cp)); + } + + addAnnotationsAsAttribute(cp); + + return new Field(modifiers, name_index, signature_index, getAttributesImmutable(), cp); + } + + private int addConstant() { + switch(type.getType()) { + case Constants.T_INT: case Constants.T_CHAR: case Constants.T_BYTE: + case Constants.T_BOOLEAN: case Constants.T_SHORT: + return cp.addInteger(((Integer)value).intValue()); + + case Constants.T_FLOAT: + return cp.addFloat(((Float)value).floatValue()); + + case Constants.T_DOUBLE: + return cp.addDouble(((Double)value).doubleValue()); + + case Constants.T_LONG: + return cp.addLong(((Long)value).longValue()); + + case Constants.T_REFERENCE: + return cp.addString(((String)value)); + + default: + throw new RuntimeException("Oops: Unhandled : " + type.getType()); + } + } + + public String getSignature() { return type.getSignature(); } + + + public String getInitialValue() { + if(value != null) { + return value.toString(); + } else + return null; + } + + /** + * Return string representation close to declaration format, + * `public static final short MAX = 100', e.g.. + * + * @return String representation of field + */ + public final String toString() { + String name, signature, access; // Short cuts to constant pool + + access = Utility.accessToString(modifiers); + access = access.equals("")? "" : (access + " "); + signature = type.toString(); + name = getName(); + + StringBuffer buf = new StringBuffer(access + signature + " " + name); + String value = getInitialValue(); + + if(value != null) + buf.append(" = " + value); + + + // TODO: Add attributes and annotations to the string + + return buf.toString(); + } + + /** @return deep copy of this field + */ + public FieldGen copy(ConstantPool cp) { + FieldGen fg = (FieldGen)clone(); + + fg.setConstantPool(cp); + return fg; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java index b091a975c..49fcef740 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java @@ -1,149 +1,168 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.ArrayList; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.AccessFlags; -import org.aspectj.apache.bcel.classfile.Attribute; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; - -/** - * Super class for FieldGen and MethodGen objects, since they have - * some methods in common! - * - * @version $Id: FieldGenOrMethodGen.java,v 1.3.10.2 2008/04/25 17:55:34 aclement Exp $ - * @author M. Dahm - */ -public abstract class FieldGenOrMethodGen extends AccessFlags - implements NamedAndTyped, Cloneable -{ - protected String name; - protected Type type; - protected ConstantPool cp; - private ArrayList attribute_vec = new ArrayList(); - protected ArrayList annotation_vec= new ArrayList(); - - protected FieldGenOrMethodGen() {} - - public void setType(Type type) { - if(type.getType() == Constants.T_ADDRESS) - throw new IllegalArgumentException("Type can not be " + type); - - this.type = type; - } - public Type getType() { return type; } - - /** @return name of method/field. - */ - public String getName() { return name; } - public void setName(String name) { this.name = name; } - - public ConstantPool getConstantPool() { return cp; } - public void setConstantPool(ConstantPool cp) { this.cp = cp; } - - /** - * Add an attribute to this method. Currently, the JVM knows about - * the `Code', `ConstantValue', `Synthetic' and `Exceptions' - * attributes. Other attributes will be ignored by the JVM but do no - * harm. - * - * @param a attribute to be added - */ - public void addAttribute(Attribute a) { attribute_vec.add(a); } - public void addAnnotation(AnnotationGen ag) { annotation_vec.add(ag);} - - /** - * Remove an attribute. - */ - public void removeAttribute(Attribute a) { attribute_vec.remove(a); } - public void removeAnnotation(AnnotationGen ag) { annotation_vec.remove(ag);} - - /** - * Remove all attributes. - */ - public void removeAttributes() { attribute_vec.clear(); } - public void removeAnnotations(){ annotation_vec.clear();} - - /** - * @return all attributes of this method. - */ - public Attribute[] getAttributes() { - Attribute[] attributes = new Attribute[attribute_vec.size()]; - attribute_vec.toArray(attributes); - return attributes; - } - - public AnnotationGen[] getAnnotations() { - AnnotationGen[] annotations = new AnnotationGen[annotation_vec.size()]; - annotation_vec.toArray(annotations); - return annotations; - } - - /** @return signature of method/field. - */ - public abstract String getSignature(); - - public Object clone() { - try { - return super.clone(); - } catch(CloneNotSupportedException e) { - System.err.println(e); - return null; - } - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.util.ArrayList; +import java.util.List; + +import org.aspectj.apache.bcel.classfile.Modifiers; +import org.aspectj.apache.bcel.classfile.Attribute; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.classfile.Utility; +import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; + +/** + * Super class for FieldGen and MethodGen objects, since they have some methods + * in common! + * + * @version $Id: FieldGenOrMethodGen.java,v 1.3.10.3 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + */ +public abstract class FieldGenOrMethodGen extends Modifiers implements Cloneable { + + protected String name; + protected Type type; + protected ConstantPool cp; + private ArrayList/**/ attributeList = new ArrayList(); + private ArrayList annotationList = new ArrayList(); + + protected FieldGenOrMethodGen() { + } + + public void setType(Type type) { + this.type = type; + } + + public Type getType() { + return type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public ConstantPool getConstantPool() { + return cp; + } + + public void setConstantPool(ConstantPool cp) { + this.cp = cp; + } + + public void addAttribute(Attribute a) { + attributeList.add(a); + } + + public void removeAttribute(Attribute a) { + attributeList.remove(a); + } + + public void removeAttributes() { + attributeList.clear(); + } + + public void addAnnotation(AnnotationGen ag) { + annotationList.add(ag); + } + + public void removeAnnotation(AnnotationGen ag) { + annotationList.remove(ag); + } + + public void removeAnnotations() { + annotationList.clear(); + } + + public List/**/ getAttributes() { + return attributeList; + } + + public Attribute[] getAttributesImmutable() { + Attribute[] attributes = new Attribute[attributeList.size()]; + attributeList.toArray(attributes); + return attributes; + } + + protected void addAnnotationsAsAttribute(ConstantPool cp) { + Attribute[] attrs = Utility.getAnnotationAttributes(cp,annotationList); + if (attrs!=null) { + for (int i = 0; i < attrs.length; i++) { + addAttribute(attrs[i]); + } + } + } + + public AnnotationGen[] getAnnotations() { + AnnotationGen[] annotations = new AnnotationGen[annotationList.size()]; + annotationList.toArray(annotations); + return annotations; + } + + public abstract String getSignature(); + + // OPTIMIZE clone any use??? + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + System.err.println(e); + return null; + } + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldInstruction.java index 1470d7b97..ec27b8c12 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldInstruction.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldInstruction.java @@ -1,107 +1,107 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.classfile.ConstantPool; - -/** - * Super class for the GET/PUTxxx family of instructions. - * - * @version $Id: FieldInstruction.java,v 1.5.4.2 2008/04/25 17:55:35 aclement Exp $ - * @author M. Dahm - */ -public class FieldInstruction extends FieldOrMethod { - - public FieldInstruction(short opcode, int index) { - super(opcode, index); - } - - public String toString(ConstantPool cp) { - return org.aspectj.apache.bcel.Constants.OPCODE_NAMES[opcode] + " " + - cp.constantToString(index, org.aspectj.apache.bcel.Constants.CONSTANT_Fieldref); - } - - /** @return size of field (1 or 2) - */ - protected int getFieldSize(ConstantPool cpg) { - return Type.getTypeSize(getSignature(cpg)); - } - - public Type getType(ConstantPool cpg) { - return getFieldType(cpg); - } - - public Type getFieldType(ConstantPool cpg) { - return Type.getType(getSignature(cpg)); - } - - - public String getFieldName(ConstantPool cpg) { - return getName(cpg); - } - - public int produceStack(ConstantPool cpg) { - if (!isStackProducer()) return 0; - - return getFieldSize(cpg); // SAME FOR GETFIELD/GETSTATIC - } - - public int consumeStack(ConstantPool cpg) { - if (!isStackConsumer()) return 0; - if (opcode==GETFIELD) return 1; - return getFieldSize(cpg)+(opcode==PUTFIELD?1:0); - } -} - +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.classfile.ConstantPool; + +/** + * Super class for the GET/PUTxxx family of instructions. + * + * @version $Id: FieldInstruction.java,v 1.5.4.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public class FieldInstruction extends FieldOrMethod { + + public FieldInstruction(short opcode, int index) { + super(opcode, index); + } + + public String toString(ConstantPool cp) { + return org.aspectj.apache.bcel.Constants.OPCODE_NAMES[opcode] + " " + + cp.constantToString(index, org.aspectj.apache.bcel.Constants.CONSTANT_Fieldref); + } + + /** @return size of field (1 or 2) + */ + protected int getFieldSize(ConstantPool cpg) { + return Type.getTypeSize(getSignature(cpg)); + } + + public Type getType(ConstantPool cpg) { + return getFieldType(cpg); + } + + public Type getFieldType(ConstantPool cpg) { + return Type.getType(getSignature(cpg)); + } + + + public String getFieldName(ConstantPool cpg) { + return getName(cpg); + } + + public int produceStack(ConstantPool cpg) { + if (!isStackProducer()) return 0; + + return getFieldSize(cpg); // SAME FOR GETFIELD/GETSTATIC + } + + public int consumeStack(ConstantPool cpg) { + if (!isStackConsumer()) return 0; + if (opcode==GETFIELD) return 1; + return getFieldSize(cpg)+(opcode==PUTFIELD?1:0); + } +} + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldObserver.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldObserver.java deleted file mode 100644 index 1a454db6a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldObserver.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Imnplement this interface if you're interested in changes to a FieldGen object - * and register yourself with addObserver(). - * - * @version $Id: FieldObserver.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public interface FieldObserver { - public void notify(FieldGen field); -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldOrMethod.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldOrMethod.java index f4e54f0be..cdfc3a73f 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldOrMethod.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldOrMethod.java @@ -1,134 +1,134 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.classfile.ConstantCP; -import org.aspectj.apache.bcel.classfile.ConstantNameAndType; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.ConstantUtf8; - -/** - * Super class for InvokeInstruction and FieldInstruction, since they have - * some methods in common! - * - * @version $Id: FieldOrMethod.java,v 1.5.6.2 2008/04/25 17:55:32 aclement Exp $ - * @author M. Dahm - */ -public abstract class FieldOrMethod extends InstructionCP { - -// private boolean dontKnowSignature=true; - private String signature; - -// private boolean dontKnowName =true; - private String name; - -// private boolean dontKnowClassname =true; - private String classname; - - /** - * @param index to constant pool - */ - protected FieldOrMethod(short opcode, int index) { - super(opcode, index); - } - - /** @return signature of referenced method/field. - */ - public String getSignature(ConstantPool cp) { - if (signature==null) { - ConstantCP cmr = (ConstantCP)cp.getConstant(index); - ConstantNameAndType cnat = (ConstantNameAndType)cp.getConstant(cmr.getNameAndTypeIndex()); - - signature = ((ConstantUtf8)cp.getConstant(cnat.getSignatureIndex())).getBytes(); -// dontKnowSignature=false; - } - return signature; - } - - /** @return name of referenced method/field. - */ - public String getName(ConstantPool cp) { - if (name==null) { - ConstantCP cmr = (ConstantCP)cp.getConstant(index); - ConstantNameAndType cnat = (ConstantNameAndType)cp.getConstant(cmr.getNameAndTypeIndex()); - name = ((ConstantUtf8)cp.getConstant(cnat.getNameIndex())).getBytes(); -// dontKnowName = false; - } - return name; - } - - /** @return name of the referenced class/interface - */ - public String getClassName(ConstantPool cp) { - if (classname==null) { - ConstantCP cmr = (ConstantCP)cp.getConstant(index); - String str = cp.getConstantString(cmr.getClassIndex(), CONSTANT_Class); - if (str.charAt(0)=='[') classname= str; else classname= str.replace('/', '.'); -// dontKnowClassname = false; - } - return classname; - } - - /** @return type of the referenced class/interface - */ - public ObjectType getClassType(ConstantPool cpg) { - return new ObjectType(getClassName(cpg)); - } - - /** @return type of the referenced class/interface - */ - public ObjectType getLoadClassType(ConstantPool cpg) { - return getClassType(cpg); - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import org.aspectj.apache.bcel.classfile.ConstantCP; +import org.aspectj.apache.bcel.classfile.ConstantNameAndType; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.classfile.ConstantUtf8; + +/** + * Super class for InvokeInstruction and FieldInstruction, since they have + * some methods in common! + * + * @version $Id: FieldOrMethod.java,v 1.5.6.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public abstract class FieldOrMethod extends InstructionCP { + +// private boolean dontKnowSignature=true; + private String signature; + +// private boolean dontKnowName =true; + private String name; + +// private boolean dontKnowClassname =true; + private String classname; + + /** + * @param index to constant pool + */ + protected FieldOrMethod(short opcode, int index) { + super(opcode, index); + } + + /** @return signature of referenced method/field. + */ + public String getSignature(ConstantPool cp) { + if (signature==null) { + ConstantCP cmr = (ConstantCP)cp.getConstant(index); + ConstantNameAndType cnat = (ConstantNameAndType)cp.getConstant(cmr.getNameAndTypeIndex()); + + signature = ((ConstantUtf8)cp.getConstant(cnat.getSignatureIndex())).getBytes(); +// dontKnowSignature=false; + } + return signature; + } + + /** @return name of referenced method/field. + */ + public String getName(ConstantPool cp) { + if (name==null) { + ConstantCP cmr = (ConstantCP)cp.getConstant(index); + ConstantNameAndType cnat = (ConstantNameAndType)cp.getConstant(cmr.getNameAndTypeIndex()); + name = ((ConstantUtf8)cp.getConstant(cnat.getNameIndex())).getBytes(); +// dontKnowName = false; + } + return name; + } + + /** @return name of the referenced class/interface + */ + public String getClassName(ConstantPool cp) { + if (classname==null) { + ConstantCP cmr = (ConstantCP)cp.getConstant(index); + String str = cp.getConstantString(cmr.getClassIndex(), CONSTANT_Class); + if (str.charAt(0)=='[') classname= str; else classname= str.replace('/', '.'); +// dontKnowClassname = false; + } + return classname; + } + + /** @return type of the referenced class/interface + */ + public ObjectType getClassType(ConstantPool cpg) { + return new ObjectType(getClassName(cpg)); + } + + /** @return type of the referenced class/interface + */ + public ObjectType getLoadClassType(ConstantPool cpg) { + return getClassType(cpg); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/GETFIELD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/GETFIELD.java deleted file mode 100644 index a8f3f01b4..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/GETFIELD.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.ExceptionConstants; - -/** - * GETFIELD - Fetch field from object - *
          Stack: ..., objectref -> ..., value
          - * OR - *
          Stack: ..., objectref -> ..., value.word1, value.word2
          - * - * @version $Id: GETFIELD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class GETFIELD extends FieldInstruction - implements ExceptionThrower, StackConsumer, StackProducer { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - GETFIELD() {} - - public GETFIELD(int index) { - super(Constants.GETFIELD, index); - } - - public int produceStack(ConstantPoolGen cpg) { return getFieldSize(cpg); } - - public Class[] getExceptions() { - Class[] cs = new Class[2 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length]; - - System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, - cs, 0, ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length); - - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length+1] = - ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR; - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = - ExceptionConstants.NULL_POINTER_EXCEPTION; - - return cs; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitStackConsumer(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitLoadClass(this); - v.visitCPInstruction(this); - v.visitFieldOrMethod(this); - v.visitFieldInstruction(this); - v.visitGETFIELD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/GETSTATIC.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/GETSTATIC.java deleted file mode 100644 index 49c7f3f76..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/GETSTATIC.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.ExceptionConstants; - -/** - * GETSTATIC - Fetch static field from class - *
          Stack: ..., -> ..., value
          - * OR - *
          Stack: ..., -> ..., value.word1, value.word2
          - * - * @version $Id: GETSTATIC.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class GETSTATIC extends FieldInstruction implements PushInstruction, ExceptionThrower { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - GETSTATIC() {} - - public GETSTATIC(int index) { - super(Constants.GETSTATIC, index); - } - - public int produceStack(ConstantPoolGen cpg) { return getFieldSize(cpg); } - - public Class[] getExceptions() { - Class[] cs = new Class[1 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length]; - - System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, - cs, 0, ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length); - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = - ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR; - - return cs; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitLoadClass(this); - v.visitCPInstruction(this); - v.visitFieldOrMethod(this); - v.visitFieldInstruction(this); - v.visitGETSTATIC(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/GOTO.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/GOTO.java deleted file mode 100644 index ecebd4bfe..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/GOTO.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; - -/** - * GOTO - Branch always (to relative offset, not absolute address) - * - * @version $Id: GOTO.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class GOTO extends GotoInstruction implements VariableLengthInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - GOTO() {} - - public GOTO(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.GOTO, target); - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - index = getTargetOffset(); - if(opcode == org.aspectj.apache.bcel.Constants.GOTO) - super.dump(out); - else { // GOTO_W - index = getTargetOffset(); - out.writeByte(opcode); - out.writeInt(index); - } - } - - /** Called in pass 2 of InstructionList.setPositions() in order to update - * the branch target, that may shift due to variable length instructions. - */ - protected int updatePosition(int offset, int max_offset) { - int i = getTargetOffset(); // Depending on old position value - - position += offset; // Position may be shifted by preceding expansions - - if(Math.abs(i) >= (32767 - max_offset)) { // to large for short (estimate) - opcode = org.aspectj.apache.bcel.Constants.GOTO_W; - length = 5; - return 2; // 5 - 3 - } - - return 0; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitVariableLengthInstruction(this); - v.visitUnconditionalBranch(this); - v.visitBranchInstruction(this); - v.visitGotoInstruction(this); - v.visitGOTO(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/GOTO_W.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/GOTO_W.java deleted file mode 100644 index 0c040b8bd..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/GOTO_W.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * GOTO_W - Branch always (to relative offset, not absolute address) - * - * @version $Id: GOTO_W.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class GOTO_W extends GotoInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - GOTO_W() {} - - public GOTO_W(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.GOTO_W, target); - length = 5; - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - index = getTargetOffset(); - out.writeByte(opcode); - out.writeInt(index); - } - - /** - * Read needed data (e.g. index) from file. - */ - protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException - { - index = bytes.readInt(); - length = 5; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitUnconditionalBranch(this); - v.visitBranchInstruction(this); - v.visitGotoInstruction(this); - v.visitGOTO_W(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/GotoInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/GotoInstruction.java deleted file mode 100644 index 1e10a02aa..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/GotoInstruction.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Super class for GOTO - * - * @version $Id: GotoInstruction.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public abstract class GotoInstruction extends BranchInstruction - implements UnconditionalBranch -{ - GotoInstruction(short opcode, InstructionHandle target) { - super(opcode, target); - } - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - GotoInstruction(){} -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/I2B.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/I2B.java deleted file mode 100644 index 1c29c3406..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/I2B.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * I2B - Convert int to byte - *
          Stack: ..., value -> ..., result
          - * - * @version $Id: I2B.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class I2B extends ConversionInstruction { - /** Convert int to byte - */ - public I2B() { - super(org.aspectj.apache.bcel.Constants.I2B); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitI2B(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/I2C.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/I2C.java deleted file mode 100644 index ecd13015d..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/I2C.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * I2C - Convert int to char - *
          Stack: ..., value -> ..., result
          - * - * @version $Id: I2C.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class I2C extends ConversionInstruction { - /** Convert int to char - */ - public I2C() { - super(org.aspectj.apache.bcel.Constants.I2C); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitI2C(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/I2D.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/I2D.java deleted file mode 100644 index 869817d6d..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/I2D.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * I2D - Convert int to double - *
          Stack: ..., value -> ..., result.word1, result.word2
          - * - * @version $Id: I2D.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class I2D extends ConversionInstruction { - /** Convert int to double - */ - public I2D() { - super(org.aspectj.apache.bcel.Constants.I2D); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitI2D(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/I2F.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/I2F.java deleted file mode 100644 index 26a7a5fac..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/I2F.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * I2F - Convert int to float - *
          Stack: ..., value -> ..., result
          - * - * @version $Id: I2F.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class I2F extends ConversionInstruction { - /** Convert int to float - */ - public I2F() { - super(org.aspectj.apache.bcel.Constants.I2F); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitI2F(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/I2L.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/I2L.java deleted file mode 100644 index d5f85955f..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/I2L.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * I2L - Convert int to long - *
          Stack: ..., value -> ..., result.word1, result.word2
          - * - * @version $Id: I2L.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class I2L extends ConversionInstruction { - /** Convert int to long - */ - public I2L() { - super(org.aspectj.apache.bcel.Constants.I2L); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitI2L(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/I2S.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/I2S.java deleted file mode 100644 index 40d24221a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/I2S.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * I2S - Convert int to short - *
          Stack: ..., value -> ..., result
          - * - * @version $Id: I2S.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class I2S extends ConversionInstruction { - public I2S() { - super(org.aspectj.apache.bcel.Constants.I2S); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitI2S(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IADD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IADD.java deleted file mode 100644 index 5333cba1f..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IADD.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IADD - Add ints - *
          Stack: ..., value1, value2 -> result
          - * - * @version $Id: IADD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IADD extends ArithmeticInstruction { - /** Add ints - */ - public IADD() { - super(org.aspectj.apache.bcel.Constants.IADD); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitIADD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IALOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IALOAD.java deleted file mode 100644 index c772e017e..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IALOAD.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IALOAD - Load int from array - *
          Stack: ..., arrayref, index -> ..., value
          - * - * @version $Id: IALOAD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IALOAD extends ArrayInstruction implements StackProducer { - /** - * Load int from array - */ - public IALOAD() { - super(org.aspectj.apache.bcel.Constants.IALOAD); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitIALOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IAND.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IAND.java deleted file mode 100644 index 1613ea697..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IAND.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IAND - Bitwise AND int - *
          Stack: ..., value1, value2 -> ..., result
          - * - * @version $Id: IAND.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class IAND extends ArithmeticInstruction { - public IAND() { - super(org.aspectj.apache.bcel.Constants.IAND); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitIAND(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IASTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IASTORE.java deleted file mode 100644 index 422e22206..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IASTORE.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IASTORE - Store into int array - *
          Stack: ..., arrayref, index, value -> ...
          - * - * @version $Id: IASTORE.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class IASTORE extends ArrayInstruction implements StackConsumer { - /** - * Store into int array - */ - public IASTORE() { - super(org.aspectj.apache.bcel.Constants.IASTORE); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitIASTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ICONST.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ICONST.java deleted file mode 100644 index 00bc3172b..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ICONST.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * ICONST - Push value between -1, ..., 5, other values cause an exception - * - *
          Stack: ... -> ..., 
          - * - * @version $Id: ICONST.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class ICONST extends Instruction - implements ConstantPushInstruction, TypedInstruction { - private int value; - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - ICONST() {} - - public ICONST(int i) { - super(org.aspectj.apache.bcel.Constants.ICONST_0, (short)1); - - if((i >= -1) && (i <= 5)) - opcode = (short)(org.aspectj.apache.bcel.Constants.ICONST_0 + i); // Even works for i == -1 - else - throw new ClassGenException("ICONST can be used only for value between -1 and 5: " + - i); - value = i; - } - - public Number getValue() { return new Integer(value); } - - /** @return Type.INT - */ - public Type getType(ConstantPoolGen cp) { - return Type.INT; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitPushInstruction(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitConstantPushInstruction(this); - v.visitICONST(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IDIV.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IDIV.java deleted file mode 100644 index e3953c0a3..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IDIV.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IDIV - Divide ints - *
          Stack: ..., value1, value2 -> result
          - * - * @version $Id: IDIV.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IDIV extends ArithmeticInstruction implements ExceptionThrower { - /** Divide ints - */ - public IDIV() { - super(org.aspectj.apache.bcel.Constants.IDIV); - } - - /** @return exceptions this instruction may cause - */ - public Class[] getExceptions() { - return new Class[] { org.aspectj.apache.bcel.ExceptionConstants.ARITHMETIC_EXCEPTION }; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitIDIV(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFEQ.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IFEQ.java deleted file mode 100644 index 470eb7613..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFEQ.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IFEQ - Branch if int comparison with zero succeeds - * - *
          Stack: ..., value -> ...
          - * - * @version $Id: IFEQ.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IFEQ extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IFEQ() {} - - public IFEQ(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IFEQ, target); - } - - /** - * @return negation of instruction, e.g. IFEQ.negate() == IFNE - */ - public IfInstruction negate() { - return new IFNE(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIFEQ(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFGE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IFGE.java deleted file mode 100644 index c183608be..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFGE.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IFGE - Branch if int comparison with zero succeeds - * - *
          Stack: ..., value -> ...
          - * - * @version $Id: IFGE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IFGE extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IFGE() {} - - public IFGE(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IFGE, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IFLT(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIFGE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFGT.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IFGT.java deleted file mode 100644 index 5fb8a7275..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFGT.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IFGT - Branch if int comparison with zero succeeds - * - *
          Stack: ..., value -> ...
          - * - * @version $Id: IFGT.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IFGT extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IFGT() {} - - public IFGT(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IFGT, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IFLE(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIFGT(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFLE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IFLE.java deleted file mode 100644 index 15e5fac6a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFLE.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IFLE - Branch if int comparison with zero succeeds - * - *
          Stack: ..., value -> ...
          - * - * @version $Id: IFLE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IFLE extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IFLE() {} - - public IFLE(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IFLE, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IFGT(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIFLE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFLT.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IFLT.java deleted file mode 100644 index 59f1c5e66..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFLT.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IFLT - Branch if int comparison with zero succeeds - * - *
          Stack: ..., value -> ...
          - * - * @version $Id: IFLT.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IFLT extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IFLT() {} - - public IFLT(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IFLT, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IFGE(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIFLT(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFNE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IFNE.java deleted file mode 100644 index f5ec78482..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFNE.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IFNE - Branch if int comparison with zero succeeds - * - *
          Stack: ..., value -> ...
          - * - * @version $Id: IFNE.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class IFNE extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IFNE() {} - - public IFNE(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IFNE, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IFEQ(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIFNE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFNONNULL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IFNONNULL.java deleted file mode 100644 index af6766e3a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFNONNULL.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IFNONNULL - Branch if reference is not null - * - *
          Stack: ..., reference -> ...
          - * - * @version $Id: IFNONNULL.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IFNONNULL extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IFNONNULL() {} - - public IFNONNULL(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IFNONNULL, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IFNULL(target); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIFNONNULL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFNULL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IFNULL.java deleted file mode 100644 index 6d6fcdd6f..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IFNULL.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IFNULL - Branch if reference is not null - * - *
          Stack: ..., reference -> ...
          - * - * @version $Id: IFNULL.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class IFNULL extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IFNULL() {} - - public IFNULL(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IFNULL, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IFNONNULL(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIFNULL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ACMPEQ.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ACMPEQ.java deleted file mode 100644 index 32246589d..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ACMPEQ.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IF_ACMPEQ - Branch if reference comparison succeeds - * - *
          Stack: ..., value1, value2 -> ...
          - * - * @version $Id: IF_ACMPEQ.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class IF_ACMPEQ extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IF_ACMPEQ() {} - - public IF_ACMPEQ(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IF_ACMPEQ, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IF_ACMPNE(target); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIF_ACMPEQ(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ACMPNE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ACMPNE.java deleted file mode 100644 index 984079381..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ACMPNE.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IF_ACMPNE - Branch if reference comparison doesn't succeed - * - *
          Stack: ..., value1, value2 -> ...
          - * - * @version $Id: IF_ACMPNE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IF_ACMPNE extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IF_ACMPNE() {} - - public IF_ACMPNE(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IF_ACMPNE, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IF_ACMPEQ(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIF_ACMPNE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPEQ.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPEQ.java deleted file mode 100644 index 06a8a3b21..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPEQ.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IF_ICMPEQ - Branch if int comparison succeeds - * - *
          Stack: ..., value1, value2 -> ...
          - * - * @version $Id: IF_ICMPEQ.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IF_ICMPEQ extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IF_ICMPEQ() {} - - public IF_ICMPEQ(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IF_ICMPEQ, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IF_ICMPNE(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIF_ICMPEQ(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPGE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPGE.java deleted file mode 100644 index dd1e98215..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPGE.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IF_ICMPGE - Branch if int comparison succeeds - * - *
          Stack: ..., value1, value2 -> ...
          - * - * @version $Id: IF_ICMPGE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IF_ICMPGE extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IF_ICMPGE() {} - - public IF_ICMPGE(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IF_ICMPGE, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IF_ICMPLT(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIF_ICMPGE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPGT.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPGT.java deleted file mode 100644 index 1abe80e6d..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPGT.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IF_ICMPGT - Branch if int comparison succeeds - * - *
          Stack: ..., value1, value2 -> ...
          - * - * @version $Id: IF_ICMPGT.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IF_ICMPGT extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IF_ICMPGT() {} - - public IF_ICMPGT(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IF_ICMPGT, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IF_ICMPLE(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIF_ICMPGT(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPLE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPLE.java deleted file mode 100644 index ffcdd6954..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPLE.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IF_ICMPLE - Branch if int comparison succeeds - * - *
          Stack: ..., value1, value2 -> ...
          - * - * @version $Id: IF_ICMPLE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IF_ICMPLE extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IF_ICMPLE() {} - - public IF_ICMPLE(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IF_ICMPLE, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IF_ICMPGT(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIF_ICMPLE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPLT.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPLT.java deleted file mode 100644 index c9b6449c9..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPLT.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IF_ICMPLT - Branch if int comparison succeeds - * - *
          Stack: ..., value1, value2 -> ...
          - * - * @version $Id: IF_ICMPLT.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IF_ICMPLT extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IF_ICMPLT() {} - - public IF_ICMPLT(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IF_ICMPLT, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IF_ICMPGE(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIF_ICMPLT(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPNE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPNE.java deleted file mode 100644 index 7d2ed208e..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IF_ICMPNE.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IF_ICMPNE - Branch if int comparison doesn't succeed - * - *
          Stack: ..., value1, value2 -> ...
          - * - * @version $Id: IF_ICMPNE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IF_ICMPNE extends IfInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IF_ICMPNE() {} - - public IF_ICMPNE(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.IF_ICMPNE, target); - } - - /** - * @return negation of instruction - */ - public IfInstruction negate() { - return new IF_ICMPEQ(target); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitBranchInstruction(this); - v.visitIfInstruction(this); - v.visitIF_ICMPNE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IINC.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IINC.java index 5977e9b14..2ae5f5672 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IINC.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/IINC.java @@ -1,108 +1,108 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; - -import org.aspectj.apache.bcel.Constants; - -/** - * IINC - Increment local variable by constant - * - * @version $Id: IINC.java,v 1.3.8.2 2008/04/25 17:55:33 aclement Exp $ - * @author M. Dahm - */ -public class IINC extends InstructionLV { - private int c; - - public IINC(int n, int c,boolean w) { - super(Constants.IINC,n); - this.c=c; -// this.wide = w;//((n > org.aspectj.apache.bcel.Constants.MAX_BYTE) || (Math.abs(c) > Byte.MAX_VALUE)); - } - - private boolean wide() { - return ((lvar > org.aspectj.apache.bcel.Constants.MAX_BYTE) || (Math.abs(c) > Byte.MAX_VALUE)); - } - - public void dump(DataOutputStream out) throws IOException { - if (wide()) { - out.writeByte(WIDE); - out.writeByte(opcode); - out.writeShort(lvar); - out.writeShort(c); - } else { - out.writeByte(opcode); - out.writeByte(lvar); - out.writeByte(c); - } - } - - - public int getLength() { - if (wide()) return 6; else return 3; // includes wide byte - } - - public String toString(boolean verbose) { - return super.toString(verbose) + " " + c; - } - - public final int getIncrement() { return c; } - -// //fixme promote or stick in a table -// public Type getType(ConstantPoolGen cp) { -// return Type.INT; -// } - -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.io.*; + +import org.aspectj.apache.bcel.Constants; + +/** + * IINC - Increment local variable by constant + * + * @version $Id: IINC.java,v 1.3.8.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public class IINC extends InstructionLV { + private int c; + + public IINC(int n, int c,boolean w) { + super(Constants.IINC,n); + this.c=c; +// this.wide = w;//((n > org.aspectj.apache.bcel.Constants.MAX_BYTE) || (Math.abs(c) > Byte.MAX_VALUE)); + } + + private boolean wide() { + return ((lvar > org.aspectj.apache.bcel.Constants.MAX_BYTE) || (Math.abs(c) > Byte.MAX_VALUE)); + } + + public void dump(DataOutputStream out) throws IOException { + if (wide()) { + out.writeByte(WIDE); + out.writeByte(opcode); + out.writeShort(lvar); + out.writeShort(c); + } else { + out.writeByte(opcode); + out.writeByte(lvar); + out.writeByte(c); + } + } + + + public int getLength() { + if (wide()) return 6; else return 3; // includes wide byte + } + + public String toString(boolean verbose) { + return super.toString(verbose) + " " + c; + } + + public final int getIncrement() { return c; } + +// //fixme promote or stick in a table +// public Type getType(ConstantPoolGen cp) { +// return Type.INT; +// } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ILOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ILOAD.java deleted file mode 100644 index d85a157f4..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ILOAD.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * ILOAD - Load int from local variable onto stack - *
          Stack: ... -> ..., result
          - * - * @version $Id: ILOAD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class ILOAD extends LoadInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - ILOAD() { - super(org.aspectj.apache.bcel.Constants.ILOAD, org.aspectj.apache.bcel.Constants.ILOAD_0); - } - - /** Load int from local variable - * @param n index of local variable - */ - public ILOAD(int n) { - super(org.aspectj.apache.bcel.Constants.ILOAD, org.aspectj.apache.bcel.Constants.ILOAD_0, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - super.accept(v); - v.visitILOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IMPDEP1.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IMPDEP1.java deleted file mode 100644 index 7051b05ab..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IMPDEP1.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IMPDEP1 - Implementation dependent - * - * @version $Id: IMPDEP1.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IMPDEP1 extends Instruction { - public IMPDEP1() { - super(org.aspectj.apache.bcel.Constants.IMPDEP1, (short)1); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitIMPDEP1(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IMPDEP2.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IMPDEP2.java deleted file mode 100644 index 303e06fed..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IMPDEP2.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IMPDEP2 - Implementation dependent - * - * @version $Id: IMPDEP2.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IMPDEP2 extends Instruction { - public IMPDEP2() { - super(org.aspectj.apache.bcel.Constants.IMPDEP2, (short)1); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitIMPDEP2(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IMUL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IMUL.java deleted file mode 100644 index 47776fcd7..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IMUL.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IMUL - Multiply ints - *
          Stack: ..., value1, value2 -> result
          - * - * @version $Id: IMUL.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IMUL extends ArithmeticInstruction { - /** Multiply ints - */ - public IMUL() { - super(org.aspectj.apache.bcel.Constants.IMUL); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitIMUL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/INEG.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/INEG.java deleted file mode 100644 index f8738efc5..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/INEG.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * INEG - Negate int - *
          Stack: ..., value -> ..., result
          - * - * @version $Id: INEG.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class INEG extends ArithmeticInstruction { - public INEG() { - super(org.aspectj.apache.bcel.Constants.INEG); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitINEG(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/INSTANCEOF.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/INSTANCEOF.java deleted file mode 100644 index 0d5be0711..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/INSTANCEOF.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * INSTANCEOF - Determine if object is of given type - *
          Stack: ..., objectref -> ..., result
          - * - * @version $Id: INSTANCEOF.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class INSTANCEOF extends CPInstruction - implements LoadClass, ExceptionThrower, StackProducer, StackConsumer { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - INSTANCEOF() {} - - public INSTANCEOF(int index) { - super(org.aspectj.apache.bcel.Constants.INSTANCEOF, index); - } - - public Class[] getExceptions() { - return org.aspectj.apache.bcel.ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION; - } - - public ObjectType getLoadClassType(ConstantPoolGen cpg) { - Type t = getType(cpg); - - if(t instanceof ArrayType) - t = ((ArrayType) t).getBasicType(); - - return (t instanceof ObjectType)? (ObjectType) t : null; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitLoadClass(this); - v.visitExceptionThrower(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitTypedInstruction(this); - v.visitCPInstruction(this); - v.visitINSTANCEOF(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKEINTERFACE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKEINTERFACE.java index 741c22045..a19cc7777 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKEINTERFACE.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKEINTERFACE.java @@ -1,110 +1,110 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.Constants; - -import java.io.*; - -/** - * INVOKEINTERFACE - Invoke interface method - *
          Stack: ..., objectref, [arg1, [arg2 ...]] -> ...
          - * - * @version $Id: INVOKEINTERFACE.java,v 1.2.10.2 2008/04/25 17:55:35 aclement Exp $ - * @author M. Dahm - */ -public final class INVOKEINTERFACE extends InvokeInstruction { - private int nargs; // Number of arguments on stack (number of stack slots), called "count" in vmspec2 - - - public INVOKEINTERFACE(int index, int nargs,int zerobyte) { - super(Constants.INVOKEINTERFACE, index); - - if(nargs < 1) - throw new ClassGenException("Number of arguments must be > 0 " + nargs); - - this.nargs = nargs; - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - out.writeByte(opcode); - out.writeShort(index); - out.writeByte(nargs); - out.writeByte(0); - } - - /** - * The count argument according to the Java Language Specification, - * Second Edition. - */ - public int getCount() { return nargs; } - - - /** - * @return mnemonic for instruction with symbolic references resolved - */ - public String toString(ConstantPool cp) { - return super.toString(cp) + " " + nargs; - } - - public int consumeStack(ConstantPool cpg) { // nargs is given in byte-code - return nargs; // nargs includes this reference - } - -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.Constants; + +import java.io.*; + +/** + * INVOKEINTERFACE - Invoke interface method + *
          Stack: ..., objectref, [arg1, [arg2 ...]] -> ...
          + * + * @version $Id: INVOKEINTERFACE.java,v 1.2.10.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public final class INVOKEINTERFACE extends InvokeInstruction { + private int nargs; // Number of arguments on stack (number of stack slots), called "count" in vmspec2 + + + public INVOKEINTERFACE(int index, int nargs,int zerobyte) { + super(Constants.INVOKEINTERFACE, index); + + if(nargs < 1) + throw new ClassGenException("Number of arguments must be > 0 " + nargs); + + this.nargs = nargs; + } + + /** + * Dump instruction as byte code to stream out. + * @param out Output stream + */ + public void dump(DataOutputStream out) throws IOException { + out.writeByte(opcode); + out.writeShort(index); + out.writeByte(nargs); + out.writeByte(0); + } + + /** + * The count argument according to the Java Language Specification, + * Second Edition. + */ + public int getCount() { return nargs; } + + + /** + * @return mnemonic for instruction with symbolic references resolved + */ + public String toString(ConstantPool cp) { + return super.toString(cp) + " " + nargs; + } + + public int consumeStack(ConstantPool cpg) { // nargs is given in byte-code + return nargs; // nargs includes this reference + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKESPECIAL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKESPECIAL.java deleted file mode 100644 index 2180ef030..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKESPECIAL.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.ExceptionConstants; - -/** - * INVOKESPECIAL - Invoke instance method; special handling for superclass, private - * and instance initialization method invocations - * - *
          Stack: ..., objectref, [arg1, [arg2 ...]] -> ...
          - * - * @version $Id: INVOKESPECIAL.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class INVOKESPECIAL extends InvokeInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - INVOKESPECIAL() {} - - public INVOKESPECIAL(int index) { - super(Constants.INVOKESPECIAL, index); - } - - public Class[] getExceptions() { - Class[] cs = new Class[4 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length]; - - System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, - cs, 0, ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length); - - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length+3] = ExceptionConstants.UNSATISFIED_LINK_ERROR; - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length+2] = ExceptionConstants.ABSTRACT_METHOD_ERROR; - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length+1] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR; - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = ExceptionConstants.NULL_POINTER_EXCEPTION; - - return cs; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackConsumer(this); - v.visitStackProducer(this); - v.visitLoadClass(this); - v.visitCPInstruction(this); - v.visitFieldOrMethod(this); - v.visitInvokeInstruction(this); - v.visitINVOKESPECIAL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKESTATIC.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKESTATIC.java deleted file mode 100644 index dafd0b2b4..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKESTATIC.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.ExceptionConstants; - -/** - * INVOKESTATIC - Invoke a class (static) method - * - *
          Stack: ..., [arg1, [arg2 ...]] -> ...
          - * - * @version $Id: INVOKESTATIC.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class INVOKESTATIC extends InvokeInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - INVOKESTATIC() {} - - public INVOKESTATIC(int index) { - super(Constants.INVOKESTATIC, index); - } - - public Class[] getExceptions() { - Class[] cs = new Class[2 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length]; - - System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, - cs, 0, ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length); - - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = ExceptionConstants.UNSATISFIED_LINK_ERROR; - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length+1] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR; - - return cs; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackConsumer(this); - v.visitStackProducer(this); - v.visitLoadClass(this); - v.visitCPInstruction(this); - v.visitFieldOrMethod(this); - v.visitInvokeInstruction(this); - v.visitINVOKESTATIC(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKEVIRTUAL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKEVIRTUAL.java deleted file mode 100644 index de1250ac0..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/INVOKEVIRTUAL.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.ExceptionConstants; - -/** - * INVOKEVIRTUAL - Invoke instance method; dispatch based on class - * - *
          Stack: ..., objectref, [arg1, [arg2 ...]] -> ...
          - * - * @version $Id: INVOKEVIRTUAL.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class INVOKEVIRTUAL extends InvokeInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - INVOKEVIRTUAL() {} - - public INVOKEVIRTUAL(int index) { - super(Constants.INVOKEVIRTUAL, index); - } - - public Class[] getExceptions() { - Class[] cs = new Class[4 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length]; - - System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, - cs, 0, ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length); - - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length+3] = ExceptionConstants.UNSATISFIED_LINK_ERROR; - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length+2] = ExceptionConstants.ABSTRACT_METHOD_ERROR; - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length+1] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR; - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = ExceptionConstants.NULL_POINTER_EXCEPTION; - - return cs; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackConsumer(this); - v.visitStackProducer(this); - v.visitLoadClass(this); - v.visitCPInstruction(this); - v.visitFieldOrMethod(this); - v.visitInvokeInstruction(this); - v.visitINVOKEVIRTUAL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IOR.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IOR.java deleted file mode 100644 index 775c32954..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IOR.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IOR - Bitwise OR int - *
          Stack: ..., value1, value2 -> ..., result
          - * - * @version $Id: IOR.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IOR extends ArithmeticInstruction { - public IOR() { - super(org.aspectj.apache.bcel.Constants.IOR); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitIOR(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IREM.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IREM.java deleted file mode 100644 index 33b9b3c1e..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IREM.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IREM - Remainder of int - *
          Stack: ..., value1, value2 -> result
          - * - * @version $Id: IREM.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IREM extends ArithmeticInstruction implements ExceptionThrower { - /** Remainder of ints - */ - public IREM() { - super(org.aspectj.apache.bcel.Constants.IREM); - } - - /** @return exceptions this instruction may cause - */ - public Class[] getExceptions() { - return new Class[] { org.aspectj.apache.bcel.ExceptionConstants.ARITHMETIC_EXCEPTION }; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitIREM(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IRETURN.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IRETURN.java deleted file mode 100644 index 5579fa937..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IRETURN.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IRETURN - Return int from method - *
          Stack: ..., value -> <empty>
          - * - * @version $Id: IRETURN.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IRETURN extends ReturnInstruction { - /** Return int from method - */ - public IRETURN() { - super(org.aspectj.apache.bcel.Constants.IRETURN); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackConsumer(this); - v.visitReturnInstruction(this); - v.visitIRETURN(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ISHL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ISHL.java deleted file mode 100644 index f7b0ca880..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ISHL.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * ISHL - Arithmetic shift left int - *
          Stack: ..., value1, value2 -> ..., result
          - * - * @version $Id: ISHL.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class ISHL extends ArithmeticInstruction { - public ISHL() { - super(org.aspectj.apache.bcel.Constants.ISHL); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitISHL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ISHR.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ISHR.java deleted file mode 100644 index e610b1c74..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ISHR.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * ISHR - Arithmetic shift right int - *
          Stack: ..., value1, value2 -> ..., result
          - * - * @version $Id: ISHR.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class ISHR extends ArithmeticInstruction { - public ISHR() { - super(org.aspectj.apache.bcel.Constants.ISHR); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitISHR(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ISTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ISTORE.java deleted file mode 100644 index 9afdb0f3a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ISTORE.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * ISTORE - Store int from stack into local variable - *
          Stack: ..., value -> ... 
          - * - * @version $Id: ISTORE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class ISTORE extends StoreInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - ISTORE() { - super(org.aspectj.apache.bcel.Constants.ISTORE, org.aspectj.apache.bcel.Constants.ISTORE_0); - } - - /** Store int into local variable - * @param n index of local variable - */ - public ISTORE(int n) { - super(org.aspectj.apache.bcel.Constants.ISTORE, org.aspectj.apache.bcel.Constants.ISTORE_0, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - super.accept(v); - v.visitISTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ISUB.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ISUB.java deleted file mode 100644 index 4211994cb..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ISUB.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * ISUB - Substract ints - *
          Stack: ..., value1, value2 -> result
          - * - * @version $Id: ISUB.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class ISUB extends ArithmeticInstruction { - /** Substract ints - */ - public ISUB() { - super(org.aspectj.apache.bcel.Constants.ISUB); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitISUB(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IUSHR.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IUSHR.java deleted file mode 100644 index b910f82cf..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IUSHR.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IUSHR - Logical shift right int - *
          Stack: ..., value1, value2 -> ..., result
          - * - * @version $Id: IUSHR.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IUSHR extends ArithmeticInstruction { - public IUSHR() { - super(org.aspectj.apache.bcel.Constants.IUSHR); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitIUSHR(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IXOR.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IXOR.java deleted file mode 100644 index 4ec89f6d6..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IXOR.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * IXOR - Bitwise XOR int - *
          Stack: ..., value1, value2 -> ..., result
          - * - * @version $Id: IXOR.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class IXOR extends ArithmeticInstruction { - public IXOR() { - super(org.aspectj.apache.bcel.Constants.IXOR); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitIXOR(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IfInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IfInstruction.java deleted file mode 100644 index ee0ca3346..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IfInstruction.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Super class for the IFxxx family of instructions. - * - * @version $Id: IfInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public abstract class IfInstruction extends BranchInstruction implements StackConsumer { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - IfInstruction() {} - - /** - * @param instruction Target instruction to branch to - */ - protected IfInstruction(short opcode, InstructionHandle target) { - super(opcode, target); - } - - /** - * @return negation of instruction, e.g. IFEQ.negate() == IFNE - */ - public abstract IfInstruction negate(); -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/IndexedInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/IndexedInstruction.java deleted file mode 100644 index 5e7e460a9..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/IndexedInstruction.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denote entity that refers to an index, e.g. local variable instructions, - * RET, CPInstruction, etc. - * - * @version $Id: IndexedInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public interface IndexedInstruction { - public int getIndex(); - public void setIndex(int index); -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/Visitor.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstVisitor.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/generic/Visitor.java rename to bcel-builder/src/org/aspectj/apache/bcel/generic/InstVisitor.java index fc8f04290..f8ca38b10 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/Visitor.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstVisitor.java @@ -1,247 +1,247 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Interface implementing the Visitor pattern programming style. - * I.e., a class that implements this interface can handle all types of - * instructions with the properly typed methods just by calling the accept() - * method. - * - * @version $Id: Visitor.java,v 1.2.10.2 2008/04/25 17:55:34 aclement Exp $ - * @author M. Dahm - */ -public interface Visitor { - public void visitStackInstruction(Instruction obj); - public void visitLocalVariableInstruction(InstructionLV obj); - public void visitBranchInstruction(InstructionBranch obj); - public void visitLoadClass(Instruction obj); - public void visitFieldInstruction(Instruction obj); - public void visitIfInstruction(Instruction obj); - public void visitConversionInstruction(Instruction obj); - public void visitPopInstruction(Instruction obj); - public void visitStoreInstruction(Instruction obj); - public void visitTypedInstruction(Instruction obj); - public void visitSelect(InstructionSelect obj); - public void visitJsrInstruction(InstructionBranch obj); - public void visitGotoInstruction(Instruction obj); - public void visitUnconditionalBranch(Instruction obj); - public void visitPushInstruction(Instruction obj); - public void visitArithmeticInstruction(Instruction obj); - public void visitCPInstruction(Instruction obj); - public void visitInvokeInstruction(InvokeInstruction obj); - public void visitArrayInstruction(Instruction obj); - public void visitAllocationInstruction(Instruction obj); - public void visitReturnInstruction(Instruction obj); - public void visitFieldOrMethod(Instruction obj); - public void visitConstantPushInstruction(Instruction obj); - public void visitExceptionThrower(Instruction obj); - public void visitLoadInstruction(Instruction obj); - public void visitVariableLengthInstruction(Instruction obj); - public void visitStackProducer(Instruction obj); - public void visitStackConsumer(Instruction obj); - public void visitACONST_NULL(Instruction obj); - public void visitGETSTATIC(FieldInstruction obj); - public void visitIF_ICMPLT(Instruction obj); - public void visitMONITOREXIT(Instruction obj); - public void visitIFLT(Instruction obj); - public void visitLSTORE(Instruction obj); - public void visitPOP2(Instruction obj); - public void visitBASTORE(Instruction obj); - public void visitISTORE(Instruction obj); - public void visitCHECKCAST(Instruction obj); - public void visitFCMPG(Instruction obj); - public void visitI2F(Instruction obj); - public void visitATHROW(Instruction obj); - public void visitDCMPL(Instruction obj); - public void visitARRAYLENGTH(Instruction obj); - public void visitDUP(Instruction obj); - public void visitINVOKESTATIC(InvokeInstruction obj); - public void visitLCONST(Instruction obj); - public void visitDREM(Instruction obj); - public void visitIFGE(Instruction obj); - public void visitCALOAD(Instruction obj); - public void visitLASTORE(Instruction obj); - public void visitI2D(Instruction obj); - public void visitDADD(Instruction obj); - public void visitINVOKESPECIAL(InvokeInstruction obj); - public void visitIAND(Instruction obj); - public void visitPUTFIELD(FieldInstruction obj); - public void visitILOAD(Instruction obj); - public void visitDLOAD(Instruction obj); - public void visitDCONST(Instruction obj); - public void visitNEW(Instruction obj); - public void visitIFNULL(Instruction obj); - public void visitLSUB(Instruction obj); - public void visitL2I(Instruction obj); - public void visitISHR(Instruction obj); - public void visitTABLESWITCH(TABLESWITCH obj); - public void visitIINC(IINC obj); - public void visitDRETURN(Instruction obj); - public void visitFSTORE(Instruction obj); - public void visitDASTORE(Instruction obj); - public void visitIALOAD(Instruction obj); - public void visitDDIV(Instruction obj); - public void visitIF_ICMPGE(Instruction obj); - public void visitLAND(Instruction obj); - public void visitIDIV(Instruction obj); - public void visitLOR(Instruction obj); - public void visitCASTORE(Instruction obj); - public void visitFREM(Instruction obj); - public void visitLDC(Instruction obj); - public void visitBIPUSH(Instruction obj); - public void visitDSTORE(Instruction obj); - public void visitF2L(Instruction obj); - public void visitFMUL(Instruction obj); - public void visitLLOAD(Instruction obj); - public void visitJSR(InstructionBranch obj); - public void visitFSUB(Instruction obj); - public void visitSASTORE(Instruction obj); - public void visitALOAD(Instruction obj); - public void visitDUP2_X2(Instruction obj); - public void visitRETURN(Instruction obj); - public void visitDALOAD(Instruction obj); - public void visitSIPUSH(Instruction obj); - public void visitDSUB(Instruction obj); - public void visitL2F(Instruction obj); - public void visitIF_ICMPGT(Instruction obj); - public void visitF2D(Instruction obj); - public void visitI2L(Instruction obj); - public void visitIF_ACMPNE(Instruction obj); - public void visitPOP(Instruction obj); - public void visitI2S(Instruction obj); - public void visitIFEQ(Instruction obj); - public void visitSWAP(Instruction obj); - public void visitIOR(Instruction obj); - public void visitIREM(Instruction obj); - public void visitIASTORE(Instruction obj); - public void visitNEWARRAY(Instruction obj); - public void visitINVOKEINTERFACE(INVOKEINTERFACE obj); - public void visitINEG(Instruction obj); - public void visitLCMP(Instruction obj); - public void visitJSR_W(InstructionBranch obj); - public void visitMULTIANEWARRAY(MULTIANEWARRAY obj); - public void visitDUP_X2(Instruction obj); - public void visitSALOAD(Instruction obj); - public void visitIFNONNULL(Instruction obj); - public void visitDMUL(Instruction obj); - public void visitIFNE(Instruction obj); - public void visitIF_ICMPLE(Instruction obj); - public void visitLDC2_W(Instruction obj); - public void visitGETFIELD(FieldInstruction obj); - public void visitLADD(Instruction obj); - public void visitNOP(Instruction obj); - public void visitFALOAD(Instruction obj); - public void visitINSTANCEOF(Instruction obj); - public void visitIFLE(Instruction obj); - public void visitLXOR(Instruction obj); - public void visitLRETURN(Instruction obj); - public void visitFCONST(Instruction obj); - public void visitIUSHR(Instruction obj); - public void visitBALOAD(Instruction obj); - public void visitDUP2(Instruction obj); - public void visitIF_ACMPEQ(Instruction obj); - public void visitIMPDEP1(Instruction obj); - public void visitMONITORENTER(Instruction obj); - public void visitLSHL(Instruction obj); - public void visitDCMPG(Instruction obj); - public void visitD2L(Instruction obj); - public void visitIMPDEP2(Instruction obj); - public void visitL2D(Instruction obj); - public void visitRET(RET obj); - public void visitIFGT(Instruction obj); - public void visitIXOR(Instruction obj); - public void visitINVOKEVIRTUAL(InvokeInstruction obj); - public void visitFASTORE(Instruction obj); - public void visitIRETURN(Instruction obj); - public void visitIF_ICMPNE(Instruction obj); - public void visitFLOAD(Instruction obj); - public void visitLDIV(Instruction obj); - public void visitPUTSTATIC(FieldInstruction obj); - public void visitAALOAD(Instruction obj); - public void visitD2I(Instruction obj); - public void visitIF_ICMPEQ(Instruction obj); - public void visitAASTORE(Instruction obj); - public void visitARETURN(Instruction obj); - public void visitDUP2_X1(Instruction obj); - public void visitFNEG(Instruction obj); - public void visitGOTO_W(Instruction obj); - public void visitD2F(Instruction obj); - public void visitGOTO(Instruction obj); - public void visitISUB(Instruction obj); - public void visitF2I(Instruction obj); - public void visitDNEG(Instruction obj); - public void visitICONST(Instruction obj); - public void visitFDIV(Instruction obj); - public void visitI2B(Instruction obj); - public void visitLNEG(Instruction obj); - public void visitLREM(Instruction obj); - public void visitIMUL(Instruction obj); - public void visitIADD(Instruction obj); - public void visitLSHR(Instruction obj); - public void visitLOOKUPSWITCH(LOOKUPSWITCH obj); - public void visitDUP_X1(Instruction obj); - public void visitFCMPL(Instruction obj); - public void visitI2C(Instruction obj); - public void visitLMUL(Instruction obj); - public void visitLUSHR(Instruction obj); - public void visitISHL(Instruction obj); - public void visitLALOAD(Instruction obj); - public void visitASTORE(Instruction obj); - public void visitANEWARRAY(Instruction obj); - public void visitFRETURN(Instruction obj); - public void visitFADD(Instruction obj); - public void visitBREAKPOINT(Instruction obj); -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Interface implementing the Visitor pattern programming style. + * I.e., a class that implements this interface can handle all types of + * instructions with the properly typed methods just by calling the accept() + * method. + * + * @version $Id: InstVisitor.java,v 1.1.2.1 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + */ +public interface InstVisitor { + public void visitStackInstruction(Instruction obj); + public void visitLocalVariableInstruction(InstructionLV obj); + public void visitBranchInstruction(InstructionBranch obj); + public void visitLoadClass(Instruction obj); + public void visitFieldInstruction(Instruction obj); + public void visitIfInstruction(Instruction obj); + public void visitConversionInstruction(Instruction obj); + public void visitPopInstruction(Instruction obj); + public void visitStoreInstruction(Instruction obj); + public void visitTypedInstruction(Instruction obj); + public void visitSelect(InstructionSelect obj); + public void visitJsrInstruction(InstructionBranch obj); + public void visitGotoInstruction(Instruction obj); + public void visitUnconditionalBranch(Instruction obj); + public void visitPushInstruction(Instruction obj); + public void visitArithmeticInstruction(Instruction obj); + public void visitCPInstruction(Instruction obj); + public void visitInvokeInstruction(InvokeInstruction obj); + public void visitArrayInstruction(Instruction obj); + public void visitAllocationInstruction(Instruction obj); + public void visitReturnInstruction(Instruction obj); + public void visitFieldOrMethod(Instruction obj); + public void visitConstantPushInstruction(Instruction obj); + public void visitExceptionThrower(Instruction obj); + public void visitLoadInstruction(Instruction obj); + public void visitVariableLengthInstruction(Instruction obj); + public void visitStackProducer(Instruction obj); + public void visitStackConsumer(Instruction obj); + public void visitACONST_NULL(Instruction obj); + public void visitGETSTATIC(FieldInstruction obj); + public void visitIF_ICMPLT(Instruction obj); + public void visitMONITOREXIT(Instruction obj); + public void visitIFLT(Instruction obj); + public void visitLSTORE(Instruction obj); + public void visitPOP2(Instruction obj); + public void visitBASTORE(Instruction obj); + public void visitISTORE(Instruction obj); + public void visitCHECKCAST(Instruction obj); + public void visitFCMPG(Instruction obj); + public void visitI2F(Instruction obj); + public void visitATHROW(Instruction obj); + public void visitDCMPL(Instruction obj); + public void visitARRAYLENGTH(Instruction obj); + public void visitDUP(Instruction obj); + public void visitINVOKESTATIC(InvokeInstruction obj); + public void visitLCONST(Instruction obj); + public void visitDREM(Instruction obj); + public void visitIFGE(Instruction obj); + public void visitCALOAD(Instruction obj); + public void visitLASTORE(Instruction obj); + public void visitI2D(Instruction obj); + public void visitDADD(Instruction obj); + public void visitINVOKESPECIAL(InvokeInstruction obj); + public void visitIAND(Instruction obj); + public void visitPUTFIELD(FieldInstruction obj); + public void visitILOAD(Instruction obj); + public void visitDLOAD(Instruction obj); + public void visitDCONST(Instruction obj); + public void visitNEW(Instruction obj); + public void visitIFNULL(Instruction obj); + public void visitLSUB(Instruction obj); + public void visitL2I(Instruction obj); + public void visitISHR(Instruction obj); + public void visitTABLESWITCH(TABLESWITCH obj); + public void visitIINC(IINC obj); + public void visitDRETURN(Instruction obj); + public void visitFSTORE(Instruction obj); + public void visitDASTORE(Instruction obj); + public void visitIALOAD(Instruction obj); + public void visitDDIV(Instruction obj); + public void visitIF_ICMPGE(Instruction obj); + public void visitLAND(Instruction obj); + public void visitIDIV(Instruction obj); + public void visitLOR(Instruction obj); + public void visitCASTORE(Instruction obj); + public void visitFREM(Instruction obj); + public void visitLDC(Instruction obj); + public void visitBIPUSH(Instruction obj); + public void visitDSTORE(Instruction obj); + public void visitF2L(Instruction obj); + public void visitFMUL(Instruction obj); + public void visitLLOAD(Instruction obj); + public void visitJSR(InstructionBranch obj); + public void visitFSUB(Instruction obj); + public void visitSASTORE(Instruction obj); + public void visitALOAD(Instruction obj); + public void visitDUP2_X2(Instruction obj); + public void visitRETURN(Instruction obj); + public void visitDALOAD(Instruction obj); + public void visitSIPUSH(Instruction obj); + public void visitDSUB(Instruction obj); + public void visitL2F(Instruction obj); + public void visitIF_ICMPGT(Instruction obj); + public void visitF2D(Instruction obj); + public void visitI2L(Instruction obj); + public void visitIF_ACMPNE(Instruction obj); + public void visitPOP(Instruction obj); + public void visitI2S(Instruction obj); + public void visitIFEQ(Instruction obj); + public void visitSWAP(Instruction obj); + public void visitIOR(Instruction obj); + public void visitIREM(Instruction obj); + public void visitIASTORE(Instruction obj); + public void visitNEWARRAY(Instruction obj); + public void visitINVOKEINTERFACE(INVOKEINTERFACE obj); + public void visitINEG(Instruction obj); + public void visitLCMP(Instruction obj); + public void visitJSR_W(InstructionBranch obj); + public void visitMULTIANEWARRAY(MULTIANEWARRAY obj); + public void visitDUP_X2(Instruction obj); + public void visitSALOAD(Instruction obj); + public void visitIFNONNULL(Instruction obj); + public void visitDMUL(Instruction obj); + public void visitIFNE(Instruction obj); + public void visitIF_ICMPLE(Instruction obj); + public void visitLDC2_W(Instruction obj); + public void visitGETFIELD(FieldInstruction obj); + public void visitLADD(Instruction obj); + public void visitNOP(Instruction obj); + public void visitFALOAD(Instruction obj); + public void visitINSTANCEOF(Instruction obj); + public void visitIFLE(Instruction obj); + public void visitLXOR(Instruction obj); + public void visitLRETURN(Instruction obj); + public void visitFCONST(Instruction obj); + public void visitIUSHR(Instruction obj); + public void visitBALOAD(Instruction obj); + public void visitDUP2(Instruction obj); + public void visitIF_ACMPEQ(Instruction obj); + public void visitIMPDEP1(Instruction obj); + public void visitMONITORENTER(Instruction obj); + public void visitLSHL(Instruction obj); + public void visitDCMPG(Instruction obj); + public void visitD2L(Instruction obj); + public void visitIMPDEP2(Instruction obj); + public void visitL2D(Instruction obj); + public void visitRET(RET obj); + public void visitIFGT(Instruction obj); + public void visitIXOR(Instruction obj); + public void visitINVOKEVIRTUAL(InvokeInstruction obj); + public void visitFASTORE(Instruction obj); + public void visitIRETURN(Instruction obj); + public void visitIF_ICMPNE(Instruction obj); + public void visitFLOAD(Instruction obj); + public void visitLDIV(Instruction obj); + public void visitPUTSTATIC(FieldInstruction obj); + public void visitAALOAD(Instruction obj); + public void visitD2I(Instruction obj); + public void visitIF_ICMPEQ(Instruction obj); + public void visitAASTORE(Instruction obj); + public void visitARETURN(Instruction obj); + public void visitDUP2_X1(Instruction obj); + public void visitFNEG(Instruction obj); + public void visitGOTO_W(Instruction obj); + public void visitD2F(Instruction obj); + public void visitGOTO(Instruction obj); + public void visitISUB(Instruction obj); + public void visitF2I(Instruction obj); + public void visitDNEG(Instruction obj); + public void visitICONST(Instruction obj); + public void visitFDIV(Instruction obj); + public void visitI2B(Instruction obj); + public void visitLNEG(Instruction obj); + public void visitLREM(Instruction obj); + public void visitIMUL(Instruction obj); + public void visitIADD(Instruction obj); + public void visitLSHR(Instruction obj); + public void visitLOOKUPSWITCH(LOOKUPSWITCH obj); + public void visitDUP_X1(Instruction obj); + public void visitFCMPL(Instruction obj); + public void visitI2C(Instruction obj); + public void visitLMUL(Instruction obj); + public void visitLUSHR(Instruction obj); + public void visitISHL(Instruction obj); + public void visitLALOAD(Instruction obj); + public void visitASTORE(Instruction obj); + public void visitANEWARRAY(Instruction obj); + public void visitFRETURN(Instruction obj); + public void visitFADD(Instruction obj); + public void visitBREAKPOINT(Instruction obj); +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/Instruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/Instruction.java index 580063297..5650832a6 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/Instruction.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/Instruction.java @@ -1,897 +1,896 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.Serializable; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.util.ByteSequence; - - -/** - * Abstract super class for all Java byte codes. - * - * @version $Id: Instruction.java,v 1.4.10.2 2008/04/25 17:55:33 aclement Exp $ - * @author M. Dahm - */ -public class Instruction implements Cloneable, Serializable, Constants { - public short opcode = -1; - - private static InstructionComparator cmp = InstructionComparator.DEFAULT; - - Instruction() {} - - public Instruction(short opcode) { this.opcode = opcode; } - - public void dump(DataOutputStream out) throws IOException { out.writeByte(opcode); } - - public String getName() { return Constants.OPCODE_NAMES[opcode]; } - - /** - * Long output format: - * 'name of opcode' "[" 'opcode number' "]" "(" 'length of instruction' ")" - */ - public String toString(boolean verbose) { - if (verbose) { - StringBuffer sb = new StringBuffer(); - sb.append(getName()).append("[").append(opcode).append("](size").append(Constants.iLen[opcode]).append(")"); - return sb.toString(); - } else { - return getName(); - } - } - - public String toString() { return toString(true); } - - public String toString(ConstantPool cp) { return toString(false); } - - /** - * Use with caution, since `BranchInstruction's have a `target' reference which - * is not copied correctly (only basic types are). This also applies for - * `Select' instructions with their multiple branch targets. - * - * @see BranchInstruction - * @return (shallow) copy of an instruction - */ - public Instruction copy() { - Instruction i = null; - // "Constant" instruction, no need to duplicate - if (InstructionConstants.INSTRUCTIONS[opcode] != null) { - i = this; - } else { - try { - i = (Instruction)clone(); - } catch(CloneNotSupportedException e) { - System.err.println(e); - } - } - return i; - } - - - /** - * Read an instruction from (byte code) input stream and return the - * appropiate object. - * - * @param file file to read from - * @return instruction object being read - */ - public static final Instruction readInstruction(ByteSequence bytes) throws IOException { - boolean wide = false; - short opcode = (short)bytes.readUnsignedByte(); - Instruction obj = null; - - if (opcode == Constants.WIDE) { - wide = true; - opcode = (short)bytes.readUnsignedByte(); - } - - Instruction constantInstruction = InstructionConstants.INSTRUCTIONS[opcode]; - if (constantInstruction != null) return constantInstruction; - - try { - switch (opcode) { - case Constants.BIPUSH : obj = new InstructionByte(Constants.BIPUSH,bytes.readByte()); break; - case Constants.SIPUSH : obj = new InstructionShort(Constants.SIPUSH,bytes.readShort()); break; - case Constants.LDC : obj = new InstructionCP(Constants.LDC,bytes.readUnsignedByte()); break; - case Constants.LDC_W : obj = new InstructionCP(Constants.LDC_W,bytes.readUnsignedShort()); break; - case Constants.LDC2_W: obj = new InstructionCP(Constants.LDC2_W,bytes.readUnsignedShort()); break; - case Constants.ILOAD : obj = new InstructionLV(Constants.ILOAD,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; - case Constants.LLOAD : obj = new InstructionLV(Constants.LLOAD,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; - case Constants.FLOAD : obj = new InstructionLV(Constants.FLOAD,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; - case Constants.DLOAD : obj = new InstructionLV(Constants.DLOAD,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; - case Constants.ALOAD : obj = new InstructionLV(Constants.ALOAD,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; - - // move these to InstructionConstants - case Constants.ILOAD_0: obj = new InstructionLV(Constants.ILOAD_0);break; - case Constants.ILOAD_1: obj = new InstructionLV(Constants.ILOAD_1);break; - case Constants.ILOAD_2: obj = new InstructionLV(Constants.ILOAD_2);break; - case Constants.ILOAD_3: obj = new InstructionLV(Constants.ILOAD_3);break; - case Constants.LLOAD_0: obj = new InstructionLV(Constants.LLOAD_0);break; - case Constants.LLOAD_1: obj = new InstructionLV(Constants.LLOAD_1);break; - case Constants.LLOAD_2: obj = new InstructionLV(Constants.LLOAD_2);break; - case Constants.LLOAD_3: obj = new InstructionLV(Constants.LLOAD_3);break; - case Constants.FLOAD_0: obj = new InstructionLV(Constants.FLOAD_0);break; - case Constants.FLOAD_1: obj = new InstructionLV(Constants.FLOAD_1);break; - case Constants.FLOAD_2: obj = new InstructionLV(Constants.FLOAD_2);break; - case Constants.FLOAD_3: obj = new InstructionLV(Constants.FLOAD_3);break; - case Constants.DLOAD_0: obj = new InstructionLV(Constants.DLOAD_0);break; - case Constants.DLOAD_1: obj = new InstructionLV(Constants.DLOAD_1);break; - case Constants.DLOAD_2: obj = new InstructionLV(Constants.DLOAD_2);break; - case Constants.DLOAD_3: obj = new InstructionLV(Constants.DLOAD_3);break; - case Constants.ALOAD_0: obj = new InstructionLV(Constants.ALOAD_0);break; - case Constants.ALOAD_1: obj = new InstructionLV(Constants.ALOAD_1);break; - case Constants.ALOAD_2: obj = new InstructionLV(Constants.ALOAD_2);break; - case Constants.ALOAD_3: obj = new InstructionLV(Constants.ALOAD_3);break; - - // move to constants? - case Constants.ISTORE_0: obj = new InstructionLV(Constants.ISTORE_0);break; - case Constants.ISTORE_1: obj = new InstructionLV(Constants.ISTORE_1);break; - case Constants.ISTORE_2: obj = new InstructionLV(Constants.ISTORE_2);break; - case Constants.ISTORE_3: obj = new InstructionLV(Constants.ISTORE_3);break; - case Constants.LSTORE_0: obj = new InstructionLV(Constants.LSTORE_0);break; - case Constants.LSTORE_1: obj = new InstructionLV(Constants.LSTORE_1);break; - case Constants.LSTORE_2: obj = new InstructionLV(Constants.LSTORE_2);break; - case Constants.LSTORE_3: obj = new InstructionLV(Constants.LSTORE_3);break; - case Constants.FSTORE_0: obj = new InstructionLV(Constants.FSTORE_0);break; - case Constants.FSTORE_1: obj = new InstructionLV(Constants.FSTORE_1);break; - case Constants.FSTORE_2: obj = new InstructionLV(Constants.FSTORE_2);break; - case Constants.FSTORE_3: obj = new InstructionLV(Constants.FSTORE_3);break; - case Constants.DSTORE_0: obj = new InstructionLV(Constants.DSTORE_0);break; - case Constants.DSTORE_1: obj = new InstructionLV(Constants.DSTORE_1);break; - case Constants.DSTORE_2: obj = new InstructionLV(Constants.DSTORE_2);break; - case Constants.DSTORE_3: obj = new InstructionLV(Constants.DSTORE_3);break; - case Constants.ASTORE_0: obj = new InstructionLV(Constants.ASTORE_0);break; - case Constants.ASTORE_1: obj = new InstructionLV(Constants.ASTORE_1);break; - case Constants.ASTORE_2: obj = new InstructionLV(Constants.ASTORE_2);break; - case Constants.ASTORE_3: obj = new InstructionLV(Constants.ASTORE_3);break; -// case Constants.IALOAD : obj = new IALOAD(); break; -// case Constants.LALOAD : obj = new LALOAD(); break; -// case Constants.FALOAD : obj = new FALOAD(); break; -// case Constants.DALOAD : obj = new DALOAD(); break; -// case Constants.AALOAD : obj = new AALOAD(); break; -// case Constants.BALOAD : obj = new BALOAD(); break; -// case Constants.CALOAD : obj = new CALOAD(); break; -// case Constants.SALOAD : obj = new SALOAD(); break; - - case Constants.ISTORE : obj = new InstructionLV(Constants.ISTORE,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; - case Constants.LSTORE : obj = new InstructionLV(Constants.LSTORE,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; - case Constants.FSTORE : obj = new InstructionLV(Constants.FSTORE,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; - case Constants.DSTORE : obj = new InstructionLV(Constants.DSTORE,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; - case Constants.ASTORE : obj = new InstructionLV(Constants.ASTORE,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; - - -// case Constants.IASTORE : obj = new IASTORE(); break; -// case Constants.LASTORE : obj = new LASTORE(); break; -// case Constants.FASTORE : obj = new FASTORE(); break; -// case Constants.DASTORE : obj = new DASTORE(); break; -// case Constants.AASTORE : obj = new AASTORE(); break; -// case Constants.BASTORE : obj = new BASTORE(); break; -// case Constants.CASTORE : obj = new CASTORE(); break; -// case Constants.SASTORE : obj = new SASTORE(); break; - -// case Constants.POP : obj = new POP(); break; -// case Constants.POP2 : obj = new POP2(); break; -// case Constants.DUP : obj = new DUP(); break; -// case Constants.DUP_X1: obj = new DUP_X1(); break; -// case Constants.DUP_X2: obj = new DUP_X2(); break; -// case Constants.DUP2 : obj = new DUP2(); break; -// case Constants.DUP2_X1: obj = new DUP2_X1(); break; -// case Constants.DUP2_X2: obj = new DUP2_X2(); break; -// case Constants.SWAP : obj = new SWAP(); break; - - case Constants.IINC : obj = new IINC(wide?bytes.readUnsignedShort():bytes.readUnsignedByte(), - wide?bytes.readShort():bytes.readByte(),wide); break; - -// case Constants.LCMP : obj = new LCMP(); break; -// case Constants.FCMPL : obj = new FCMPL(); break; -// case Constants.FCMPG : obj = new FCMPG(); break; -// case Constants.DCMPL : obj = new DCMPL(); break; -// case Constants.DCMPG : obj = new DCMPG(); break; -// case Constants.ARRAYLENGTH : obj = new Instruction(Constants.ARRAYLENGTH); break; -// case Constants.ATHROW : obj = new ATHROW(); break; -// case Constants.MONITORENTER : obj = new MONITORENTER(); break; -// case Constants.MONITOREXIT : obj = new MONITOREXIT(); break; - case Constants.IFNULL : obj = new InstructionBranch(Constants.IFNULL,bytes.readShort()); break; - case Constants.IFNONNULL : obj = new InstructionBranch(Constants.IFNONNULL,bytes.readShort()); break; - case Constants.IFEQ : obj = new InstructionBranch(Constants.IFEQ,bytes.readShort()); break; - case Constants.IFNE : obj = new InstructionBranch(Constants.IFNE,bytes.readShort()); break; - case Constants.IFLT : obj = new InstructionBranch(Constants.IFLT,bytes.readShort()); break; - case Constants.IFGE : obj = new InstructionBranch(Constants.IFGE,bytes.readShort()); break; - case Constants.IFGT : obj = new InstructionBranch(Constants.IFGT,bytes.readShort()); break; - case Constants.IFLE : obj = new InstructionBranch(Constants.IFLE,bytes.readShort()); break; - case Constants.IF_ICMPEQ: obj = new InstructionBranch(Constants.IF_ICMPEQ,bytes.readShort()); break; - case Constants.IF_ICMPNE: obj = new InstructionBranch(Constants.IF_ICMPNE,bytes.readShort()); break; - case Constants.IF_ICMPLT: obj = new InstructionBranch(Constants.IF_ICMPLT,bytes.readShort()); break; - case Constants.IF_ICMPGE: obj = new InstructionBranch(Constants.IF_ICMPGE,bytes.readShort()); break; - case Constants.IF_ICMPGT: obj = new InstructionBranch(Constants.IF_ICMPGT,bytes.readShort()); break; - case Constants.IF_ICMPLE: obj = new InstructionBranch(Constants.IF_ICMPLE,bytes.readShort()); break; - case Constants.IF_ACMPEQ: obj = new InstructionBranch(Constants.IF_ACMPEQ,bytes.readShort()); break; - case Constants.IF_ACMPNE : obj = new InstructionBranch(Constants.IF_ACMPNE,bytes.readShort()); break; - case Constants.GOTO : obj = new InstructionBranch(Constants.GOTO,bytes.readShort()); break; - case Constants.GOTO_W : obj = new InstructionBranch(Constants.GOTO_W,bytes.readInt()); break; - case Constants.JSR : obj = new InstructionBranch(Constants.JSR,bytes.readShort()); break; - case Constants.JSR_W : obj = new InstructionBranch(Constants.JSR_W,bytes.readInt()); break; - - case Constants.TABLESWITCH : obj = new TABLESWITCH(bytes); break; - case Constants.LOOKUPSWITCH : obj = new LOOKUPSWITCH(bytes); break; - - case Constants.RET : obj = new RET(wide?bytes.readUnsignedShort():bytes.readUnsignedByte(),wide); break; - -// case Constants.IRETURN : obj = new IRETURN(); break; -// case Constants.LRETURN : obj = new LRETURN(); break; -// case Constants.FRETURN : obj = new FRETURN(); break; -// case Constants.DRETURN : obj = new DRETURN(); break; -// case Constants.ARETURN : obj = new ARETURN(); break; -// case Constants.RETURN : obj = new RETURN(); break; - case Constants.NEW : obj = new InstructionCP(Constants.NEW,bytes.readUnsignedShort()); break; - - case Constants.GETSTATIC : obj = new FieldInstruction(Constants.GETSTATIC,bytes.readUnsignedShort()); break; - case Constants.PUTSTATIC : obj = new FieldInstruction(Constants.PUTSTATIC,bytes.readUnsignedShort()); break; - case Constants.GETFIELD : obj = new FieldInstruction(Constants.GETFIELD,bytes.readUnsignedShort()); break; - case Constants.PUTFIELD : obj = new FieldInstruction(Constants.PUTFIELD,bytes.readUnsignedShort()); break; - case Constants.INVOKEVIRTUAL : obj = new InvokeInstruction(Constants.INVOKEVIRTUAL,bytes.readUnsignedShort()); break; - case Constants.INVOKESPECIAL : obj = new InvokeInstruction(Constants.INVOKESPECIAL,bytes.readUnsignedShort()); break; - case Constants.INVOKESTATIC : obj = new InvokeInstruction(Constants.INVOKESTATIC,bytes.readUnsignedShort()); break; - case Constants.INVOKEINTERFACE : obj = new INVOKEINTERFACE(bytes.readUnsignedShort(),bytes.readUnsignedByte(),bytes.readByte());break; - case Constants.NEWARRAY : obj = new InstructionByte(Constants.NEWARRAY,bytes.readByte()); break; - case Constants.ANEWARRAY : obj = new InstructionCP(Constants.ANEWARRAY,bytes.readUnsignedShort()); break; - case Constants.CHECKCAST : obj = new InstructionCP(Constants.CHECKCAST,bytes.readUnsignedShort()); break; - case Constants.INSTANCEOF : obj = new InstructionCP(Constants.INSTANCEOF,bytes.readUnsignedShort()); break; - case Constants.MULTIANEWARRAY : obj = new MULTIANEWARRAY(bytes.readUnsignedShort(),bytes.readByte()); break; - default: - throw new ClassGenException("Illegal opcode detected"); - } - } catch (ClassGenException e) { - throw e; - } catch (Exception e) { - throw new ClassGenException(e.toString()); - } - - return obj; - } - - /** - * This method also gives right results for instructions whose - * effect on the stack depends on the constant pool entry they - * reference. - * @return Number of words consumed from stack by this instruction, - * or Constants.UNPREDICTABLE, if this can not be computed statically - */ - public int consumeStack(ConstantPool cpg) { - return Constants.CONSUME_STACK[opcode]; - } - - /** - * This method also gives right results for instructions whose - * effect on the stack depends on the constant pool entry they - * reference. - * @return Number of words produced onto stack by this instruction, - * or Constants.UNPREDICTABLE, if this can not be computed statically - */ - public int produceStack(ConstantPool cpg) { - return Constants.stackEntriesProduced[opcode]; - } - - /** - * @return this instructions opcode - */ - public short getOpcode() { return opcode; } - - public int getLength() { - // if it is zero, it should have been provided by an overriding implementation of getLength() - int len = Constants.iLen[opcode]; - if (len==0) throw new IllegalStateException("Length not right for "+getName().toUpperCase()); - return len; - } - - /** Some instructions may be reused, so don't do anything by default */ - void dispose() {} - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - switch (opcode) { - case IMPDEP1:v.visitIMPDEP1(this);break; - case IMPDEP2:v.visitIMPDEP2(this);break; - case MONITORENTER: - v.visitExceptionThrower(this); - v.visitStackConsumer(this); - v.visitMONITORENTER(this); - break; - case MONITOREXIT: - v.visitExceptionThrower(this); - v.visitStackConsumer(this); - v.visitMONITOREXIT(this); - break; - case LCMP: - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitLCMP(this); - break; - case FCMPL: - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitFCMPL(this); - break; - case FCMPG: - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitFCMPG(this); - break; - case DCMPL: - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitDCMPL(this); - break; - case DCMPG: - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitDCMPG(this); - break; - case NOP: - v.visitNOP(this); - break; - case BREAKPOINT: - v.visitBREAKPOINT(this); - break; - case SWAP: - v.visitStackConsumer(this); - v.visitStackProducer(this); - v.visitStackInstruction(this); - v.visitSWAP(this); - break; - case POP: - v.visitStackConsumer(this); - v.visitPopInstruction(this); - v.visitStackInstruction(this); - v.visitPOP(this); - break; - case POP2: - v.visitStackConsumer(this); - v.visitPopInstruction(this); - v.visitStackInstruction(this); - v.visitPOP2(this); - break; - case DUP2_X1: - v.visitStackInstruction(this); - v.visitDUP2_X1(this); - break; - case DUP2_X2: - v.visitStackInstruction(this); - v.visitDUP2_X2(this); - break; - case DUP2: - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitStackInstruction(this); - v.visitDUP2(this); - break; - case DUP_X1: - v.visitStackInstruction(this); - v.visitDUP_X1(this); - break; - case DUP_X2: - v.visitStackInstruction(this); - v.visitDUP_X2(this); - break; - case DUP: - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitStackInstruction(this); - v.visitDUP(this); - break; - case BASTORE: - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitBASTORE(this); - break; - case CASTORE: - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitCASTORE(this); - break; - case SASTORE: - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitSASTORE(this); - break; - case DASTORE: - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitDASTORE(this); - break; - case FASTORE: - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitFASTORE(this); - break; - case LASTORE: - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitLASTORE(this); - break; - case IASTORE: - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitIASTORE(this); - break; - case AASTORE: - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitAASTORE(this); - break; - case SALOAD: - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitSALOAD(this); - break; - case CALOAD: - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitCALOAD(this); - break; - case DALOAD: - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitDALOAD(this); - break; - case FALOAD: - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitFALOAD(this); - break; - case LALOAD: - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitLALOAD(this); - break; - case AALOAD: - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitAALOAD(this); - break; - case ATHROW: - v.visitUnconditionalBranch(this); - v.visitExceptionThrower(this); - v.visitATHROW(this); - break; - case ACONST_NULL: - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitTypedInstruction(this); - v.visitACONST_NULL(this); - break; - case ICONST_M1:case ICONST_0:case ICONST_1:case ICONST_2:case ICONST_3:case ICONST_4:case ICONST_5: - v.visitPushInstruction(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitConstantPushInstruction(this); - v.visitICONST(this); - break; - case LCONST_0:case LCONST_1: - v.visitPushInstruction(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitConstantPushInstruction(this); - v.visitLCONST(this); - break; - case FCONST_0:case FCONST_1:case FCONST_2: - v.visitPushInstruction(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitConstantPushInstruction(this); - v.visitFCONST(this); - break; - case DCONST_0:case DCONST_1: - v.visitPushInstruction(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitConstantPushInstruction(this); - v.visitDCONST(this); - case BALOAD: - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitBALOAD(this); - break; - case IALOAD: - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitIALOAD(this); - case BIPUSH: - v.visitPushInstruction(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitConstantPushInstruction(this); - v.visitBIPUSH(this); - break; - case SIPUSH: - v.visitPushInstruction(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitConstantPushInstruction(this); - v.visitSIPUSH(this); - break; - case LDC:case LDC_W: - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitCPInstruction(this); - v.visitLDC(this); - break; - case LDC2_W: - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitTypedInstruction(this); - v.visitCPInstruction(this); - v.visitLDC2_W(this); - break; - case ARRAYLENGTH: - v.visitExceptionThrower(this); - v.visitStackProducer(this); - v.visitARRAYLENGTH(this); - break; - case ASTORE_0: - v.visitStackConsumer(this); - v.visitPopInstruction(this); - v.visitStoreInstruction(this); - v.visitTypedInstruction(this); - v.visitLocalVariableInstruction((InstructionLV)this); - v.visitStoreInstruction(this); - v.visitASTORE(this); - break; - case ALOAD_0: - v.visitStackConsumer(this); - v.visitPopInstruction(this); - v.visitStoreInstruction(this); - v.visitTypedInstruction(this); - v.visitLocalVariableInstruction((InstructionLV)this); - v.visitStoreInstruction(this); - v.visitALOAD(this); - break; - // for store instructions: ISTORE > ASTORE_3 - needs to visit the instruction too -// v.visitStackConsumer(this); -// v.visitPopInstruction(this); -// v.visitStoreInstruction(this); -// v.visitTypedInstruction(this); -// v.visitLocalVariableInstruction(this); -// v.visitStoreInstruction(this); - // for load instructions: ILOAD > ALOAD_3 - needs to visit the instruction too -// v.visitStackProducer(this); -// v.visitPushInstruction(this); -// v.visitTypedInstruction(this); -// v.visitLocalVariableInstruction(this); -// v.visitLoadInstruction(this); - - // for conversion instructions: (all 15 of them) - needs to visit conversion instruction too -// v.visitTypedInstruction(this); -// v.visitStackProducer(this); -// v.visitStackConsumer(this); -// v.visitConversionInstruction(this); - - // arithmetic instructions - need to visit the instructions too (iadd etc) -// v.visitTypedInstruction(this); -// v.visitStackProducer(this); -// v.visitStackConsumer(this); -// v.visitArithmeticInstruction(this); - - case INVOKESTATIC: - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackConsumer(this); - v.visitStackProducer(this); - v.visitLoadClass(this); - v.visitCPInstruction(this); - v.visitFieldOrMethod(this); - v.visitInvokeInstruction((InvokeInstruction)this); - v.visitINVOKESTATIC((InvokeInstruction)this); - break; - - case GOTO: - v.visitVariableLengthInstruction(this); - v.visitUnconditionalBranch(this); - v.visitBranchInstruction((InstructionBranch)this); - v.visitGotoInstruction(this); - v.visitGOTO(this); - break; - case PUTSTATIC: - v.visitExceptionThrower(this); - v.visitStackConsumer(this); - v.visitPopInstruction(this); - v.visitTypedInstruction(this); - v.visitLoadClass(this); - v.visitCPInstruction(this); - v.visitFieldOrMethod(this); - v.visitFieldInstruction(this); - v.visitPUTSTATIC((FieldInstruction)this); - break; - case RETURN: - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackConsumer(this); - v.visitReturnInstruction(this); - v.visitRETURN(this); - break; - default: throw new IllegalStateException("visiting not yet implemented for "+getName().toUpperCase()); - } - } - - /** Check for equality, delegated to comparator - * @return true if that is an Instruction and has the same opcode - */ - public boolean equals(Object that) { - return (that instanceof Instruction)? - cmp.equals(this, (Instruction)that) : false; - } - - public Type getType() { return getType(null); } - - public Type getType(ConstantPool cp) { - // if (types[opcode]==null) throw new RuntimeException(getName()+" is not a typed instruction"); - Type t = Constants.types[opcode]; - if (t!=null) return t; - switch (opcode) { - case Constants.IRETURN: return Type.INT; - case Constants.LRETURN: return Type.LONG; - case Constants.FRETURN: return Type.FLOAT; - case Constants.DRETURN: return Type.DOUBLE; - case Constants.ARETURN: return Type.OBJECT; - case Constants.RETURN: return Type.VOID; - case LCMP: return Type.LONG; - case DCMPG: case DCMPL: return Type.DOUBLE; - case FCMPG: case FCMPL: return Type.FLOAT; - case ACONST_NULL: - return Type.NULL; - case ICONST_M1:case ICONST_0:case ICONST_1:case ICONST_2:case ICONST_3:case ICONST_4:case ICONST_5: - return Type.INT; - case IALOAD: case IASTORE: - return Type.INT; - case CALOAD: case CASTORE: - return Type.CHAR; - case BALOAD: case BASTORE: - return Type.BYTE; - case SALOAD: case SASTORE: - return Type.SHORT; - case LALOAD: case LASTORE: - return Type.LONG; - case DALOAD: case DASTORE: - return Type.DOUBLE; - case FALOAD: case FASTORE: - return Type.FLOAT; - case AALOAD: case AASTORE: - return Type.OBJECT; - - case ASTORE: - case ALOAD: - return Type.OBJECT; - - case Constants.D2I: case Constants.F2I: case Constants.L2I: - return Type.INT; - case Constants.D2F: case Constants.I2F: case Constants.L2F: - return Type.FLOAT; - case Constants.D2L: case Constants.F2L: case Constants.I2L: - return Type.LONG; - case Constants.F2D: case Constants.I2D: case Constants.L2D: - return Type.DOUBLE; - case Constants.I2B: - return Type.BYTE; - case Constants.I2C: - return Type.CHAR; - case Constants.I2S: - return Type.SHORT; - - // arithmetic instructions - case Constants.IADD: case Constants.IAND: case Constants.IDIV: case Constants.IMUL: - case Constants.INEG: case Constants.IOR: case Constants.IREM: case Constants.ISHL: - case Constants.ISHR: case Constants.ISUB: case Constants.IUSHR: case Constants.IXOR: - return Type.INT; - - case Constants.DADD: case Constants.DDIV: case Constants.DMUL: case Constants.DNEG: - case Constants.DREM: case Constants.DSUB: - return Type.DOUBLE; - - case Constants.FADD: case Constants.FDIV: case Constants.FMUL: - case Constants.FNEG: case Constants.FREM: case Constants.FSUB: - return Type.FLOAT; - - - case Constants.LADD: case Constants.LAND: case Constants.LDIV: - case Constants.LMUL: case Constants.LNEG: case Constants.LOR: - case Constants.LREM: case Constants.LSHL: case Constants.LSHR: - case Constants.LSUB:case Constants.LUSHR: case Constants.LXOR: - return Type.LONG; - default: - throw new IllegalStateException("Not implemented yet for "+getName().toUpperCase()); - } - } - - public Number getValue() { - if ((instFlags[opcode]&CONSTANT_INST)==0) throw new RuntimeException(getName()+" is not a constant instruction"); - switch (opcode) { - case ICONST_M1:case ICONST_0:case ICONST_1:case ICONST_2:case ICONST_3:case ICONST_4:case ICONST_5: - return new Integer(opcode-ICONST_0); - default: - throw new IllegalStateException("Not implemented yet for "+getName()); - } - } - - public int getIndex() { return -1; } - public void setIndex(int i) { - throw new IllegalStateException("Shouldnt be asking "+getName().toUpperCase()); - } - - public Object getValue(ConstantPool cpg) { - throw new IllegalStateException("Shouldnt be asking "+getName().toUpperCase()); - } - - public boolean isLoadInstruction() { - return (Constants.instFlags[opcode]&LOAD_INST)!=0; - } - - public boolean isALOAD() { - return false; - } - - public boolean isStoreInstruction() { - return (Constants.instFlags[opcode]&STORE_INST)!=0; - } - - public boolean isASTORE() { - return false; - } - public java.lang.Class[] getExceptions() { - // fixme - return Constants.instExcs[opcode]; - } - - public boolean containsTarget(InstructionHandle ih) { throw new IllegalStateException("Dont ask!!");} - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { throw new IllegalStateException("Dont ask!!");} - - public boolean isJsrInstruction() { - return (Constants.instFlags[opcode]&JSR_INSTRUCTION)!=0; - } - - public boolean isConstantInstruction() { - return (Constants.instFlags[opcode]&CONSTANT_INST)!=0; - } - - public boolean isConstantPoolInstruction() { - return (Constants.instFlags[opcode]&CP_INST)!=0; - } - public boolean isStackProducer() { - return (Constants.stackEntriesProduced[opcode]!=0); -// return ((Constants.instFlags[opcode]&STACK_PRODUCER)!=0); - } - public boolean isStackConsumer() { - return (Constants.CONSUME_STACK[opcode]!=0); -// return ((Constants.instFlags[opcode]&STACK_CONSUMER)!=0); - } - - public boolean isIndexedInstruction() { - return (Constants.instFlags[opcode]&INDEXED)!=0; - } - public boolean isArrayCreationInstruction() { - return (opcode==NEWARRAY || opcode==ANEWARRAY || opcode==MULTIANEWARRAY); - } - - // Asserts a property of an instruction - can be commented out after a lot of testing ;) - public void assertSomething(long flag) { - if ((Constants.instFlags[opcode]&flag)==0) throw new IllegalStateException("This opcode "+opcode+" does not have the property "+Long.toHexString(flag)); - } - - public ObjectType getLoadClassType(ConstantPool cpg) { - assertSomething(Constants.LOADCLASS_INST); - Type t = getType(cpg); - if (t instanceof ArrayType) t = ((ArrayType)t).getBasicType(); - return (t instanceof ObjectType)?(ObjectType)t:null; - } - - public boolean isReturnInstruction() { - return (Constants.instFlags[opcode]&RET_INST)!=0; - } - public boolean isGoto() { - return opcode==GOTO || opcode==GOTO_W; - } - public boolean isLocalVariableInstruction() { - return (Constants.instFlags[opcode]&LV_INST)!=0; - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.Serializable; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.util.ByteSequence; + + +/** + * Abstract super class for all Java byte codes. + * + * @version $Id: Instruction.java,v 1.4.10.3 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + */ +public class Instruction implements Cloneable, Serializable, Constants { + public short opcode = -1; + + private static InstructionComparator cmp = InstructionComparator.DEFAULT; + + Instruction() {} + + public Instruction(short opcode) { this.opcode = opcode; } + + public void dump(DataOutputStream out) throws IOException { out.writeByte(opcode); } + + public String getName() { return Constants.OPCODE_NAMES[opcode]; } + + /** + * Long output format: + * 'name of opcode' "[" 'opcode number' "]" "(" 'length of instruction' ")" + */ + public String toString(boolean verbose) { + if (verbose) { + StringBuffer sb = new StringBuffer(); + sb.append(getName()).append("[").append(opcode).append("](size").append(Constants.iLen[opcode]).append(")"); + return sb.toString(); + } else { + return getName(); + } + } + + public String toString() { return toString(true); } + + public String toString(ConstantPool cp) { return toString(false); } + + /** + * Use with caution, since `BranchInstruction's have a `target' reference which + * is not copied correctly (only basic types are). This also applies for + * `Select' instructions with their multiple branch targets. + * + * @see BranchInstruction + * @return (shallow) copy of an instruction + */ + final public Instruction copy() { + if (InstructionConstants.INSTRUCTIONS[opcode] != null) { // immutable instructions do not need copying + return this; + } else { + Instruction i = null; + try {//OPTIMIZE is clone the right thing to do here? it is horrible + i = (Instruction)clone(); + } catch(CloneNotSupportedException e) { + System.err.println(e); + } + return i; + } + } + + + /** + * Read an instruction from (byte code) input stream and return the + * appropiate object. + * + * @param file file to read from + * @return instruction object being read + */ + public static final Instruction readInstruction(ByteSequence bytes) throws IOException { + boolean wide = false; + short opcode = (short)bytes.readUnsignedByte(); + Instruction obj = null; + + if (opcode == Constants.WIDE) { + wide = true; + opcode = (short)bytes.readUnsignedByte(); + } + + Instruction constantInstruction = InstructionConstants.INSTRUCTIONS[opcode]; + if (constantInstruction != null) return constantInstruction; + + try { + switch (opcode) { + case Constants.BIPUSH : obj = new InstructionByte(Constants.BIPUSH,bytes.readByte()); break; + case Constants.SIPUSH : obj = new InstructionShort(Constants.SIPUSH,bytes.readShort()); break; + case Constants.LDC : obj = new InstructionCP(Constants.LDC,bytes.readUnsignedByte()); break; + case Constants.LDC_W : obj = new InstructionCP(Constants.LDC_W,bytes.readUnsignedShort()); break; + case Constants.LDC2_W: obj = new InstructionCP(Constants.LDC2_W,bytes.readUnsignedShort()); break; + case Constants.ILOAD : obj = new InstructionLV(Constants.ILOAD,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; + case Constants.LLOAD : obj = new InstructionLV(Constants.LLOAD,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; + case Constants.FLOAD : obj = new InstructionLV(Constants.FLOAD,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; + case Constants.DLOAD : obj = new InstructionLV(Constants.DLOAD,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; + case Constants.ALOAD : obj = new InstructionLV(Constants.ALOAD,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; + + // move these to InstructionConstants + case Constants.ILOAD_0: obj = new InstructionLV(Constants.ILOAD_0);break; + case Constants.ILOAD_1: obj = new InstructionLV(Constants.ILOAD_1);break; + case Constants.ILOAD_2: obj = new InstructionLV(Constants.ILOAD_2);break; + case Constants.ILOAD_3: obj = new InstructionLV(Constants.ILOAD_3);break; + case Constants.LLOAD_0: obj = new InstructionLV(Constants.LLOAD_0);break; + case Constants.LLOAD_1: obj = new InstructionLV(Constants.LLOAD_1);break; + case Constants.LLOAD_2: obj = new InstructionLV(Constants.LLOAD_2);break; + case Constants.LLOAD_3: obj = new InstructionLV(Constants.LLOAD_3);break; + case Constants.FLOAD_0: obj = new InstructionLV(Constants.FLOAD_0);break; + case Constants.FLOAD_1: obj = new InstructionLV(Constants.FLOAD_1);break; + case Constants.FLOAD_2: obj = new InstructionLV(Constants.FLOAD_2);break; + case Constants.FLOAD_3: obj = new InstructionLV(Constants.FLOAD_3);break; + case Constants.DLOAD_0: obj = new InstructionLV(Constants.DLOAD_0);break; + case Constants.DLOAD_1: obj = new InstructionLV(Constants.DLOAD_1);break; + case Constants.DLOAD_2: obj = new InstructionLV(Constants.DLOAD_2);break; + case Constants.DLOAD_3: obj = new InstructionLV(Constants.DLOAD_3);break; + case Constants.ALOAD_0: obj = new InstructionLV(Constants.ALOAD_0);break; + case Constants.ALOAD_1: obj = new InstructionLV(Constants.ALOAD_1);break; + case Constants.ALOAD_2: obj = new InstructionLV(Constants.ALOAD_2);break; + case Constants.ALOAD_3: obj = new InstructionLV(Constants.ALOAD_3);break; + + // move to constants? + case Constants.ISTORE_0: obj = new InstructionLV(Constants.ISTORE_0);break; + case Constants.ISTORE_1: obj = new InstructionLV(Constants.ISTORE_1);break; + case Constants.ISTORE_2: obj = new InstructionLV(Constants.ISTORE_2);break; + case Constants.ISTORE_3: obj = new InstructionLV(Constants.ISTORE_3);break; + case Constants.LSTORE_0: obj = new InstructionLV(Constants.LSTORE_0);break; + case Constants.LSTORE_1: obj = new InstructionLV(Constants.LSTORE_1);break; + case Constants.LSTORE_2: obj = new InstructionLV(Constants.LSTORE_2);break; + case Constants.LSTORE_3: obj = new InstructionLV(Constants.LSTORE_3);break; + case Constants.FSTORE_0: obj = new InstructionLV(Constants.FSTORE_0);break; + case Constants.FSTORE_1: obj = new InstructionLV(Constants.FSTORE_1);break; + case Constants.FSTORE_2: obj = new InstructionLV(Constants.FSTORE_2);break; + case Constants.FSTORE_3: obj = new InstructionLV(Constants.FSTORE_3);break; + case Constants.DSTORE_0: obj = new InstructionLV(Constants.DSTORE_0);break; + case Constants.DSTORE_1: obj = new InstructionLV(Constants.DSTORE_1);break; + case Constants.DSTORE_2: obj = new InstructionLV(Constants.DSTORE_2);break; + case Constants.DSTORE_3: obj = new InstructionLV(Constants.DSTORE_3);break; + case Constants.ASTORE_0: obj = new InstructionLV(Constants.ASTORE_0);break; + case Constants.ASTORE_1: obj = new InstructionLV(Constants.ASTORE_1);break; + case Constants.ASTORE_2: obj = new InstructionLV(Constants.ASTORE_2);break; + case Constants.ASTORE_3: obj = new InstructionLV(Constants.ASTORE_3);break; +// case Constants.IALOAD : obj = new IALOAD(); break; +// case Constants.LALOAD : obj = new LALOAD(); break; +// case Constants.FALOAD : obj = new FALOAD(); break; +// case Constants.DALOAD : obj = new DALOAD(); break; +// case Constants.AALOAD : obj = new AALOAD(); break; +// case Constants.BALOAD : obj = new BALOAD(); break; +// case Constants.CALOAD : obj = new CALOAD(); break; +// case Constants.SALOAD : obj = new SALOAD(); break; + + case Constants.ISTORE : obj = new InstructionLV(Constants.ISTORE,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; + case Constants.LSTORE : obj = new InstructionLV(Constants.LSTORE,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; + case Constants.FSTORE : obj = new InstructionLV(Constants.FSTORE,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; + case Constants.DSTORE : obj = new InstructionLV(Constants.DSTORE,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; + case Constants.ASTORE : obj = new InstructionLV(Constants.ASTORE,wide?bytes.readUnsignedShort():bytes.readUnsignedByte()); break; + + +// case Constants.IASTORE : obj = new IASTORE(); break; +// case Constants.LASTORE : obj = new LASTORE(); break; +// case Constants.FASTORE : obj = new FASTORE(); break; +// case Constants.DASTORE : obj = new DASTORE(); break; +// case Constants.AASTORE : obj = new AASTORE(); break; +// case Constants.BASTORE : obj = new BASTORE(); break; +// case Constants.CASTORE : obj = new CASTORE(); break; +// case Constants.SASTORE : obj = new SASTORE(); break; + +// case Constants.POP : obj = new POP(); break; +// case Constants.POP2 : obj = new POP2(); break; +// case Constants.DUP : obj = new DUP(); break; +// case Constants.DUP_X1: obj = new DUP_X1(); break; +// case Constants.DUP_X2: obj = new DUP_X2(); break; +// case Constants.DUP2 : obj = new DUP2(); break; +// case Constants.DUP2_X1: obj = new DUP2_X1(); break; +// case Constants.DUP2_X2: obj = new DUP2_X2(); break; +// case Constants.SWAP : obj = new SWAP(); break; + + case Constants.IINC : obj = new IINC(wide?bytes.readUnsignedShort():bytes.readUnsignedByte(), + wide?bytes.readShort():bytes.readByte(),wide); break; + +// case Constants.LCMP : obj = new LCMP(); break; +// case Constants.FCMPL : obj = new FCMPL(); break; +// case Constants.FCMPG : obj = new FCMPG(); break; +// case Constants.DCMPL : obj = new DCMPL(); break; +// case Constants.DCMPG : obj = new DCMPG(); break; +// case Constants.ARRAYLENGTH : obj = new Instruction(Constants.ARRAYLENGTH); break; +// case Constants.ATHROW : obj = new ATHROW(); break; +// case Constants.MONITORENTER : obj = new MONITORENTER(); break; +// case Constants.MONITOREXIT : obj = new MONITOREXIT(); break; + case Constants.IFNULL : obj = new InstructionBranch(Constants.IFNULL,bytes.readShort()); break; + case Constants.IFNONNULL : obj = new InstructionBranch(Constants.IFNONNULL,bytes.readShort()); break; + case Constants.IFEQ : obj = new InstructionBranch(Constants.IFEQ,bytes.readShort()); break; + case Constants.IFNE : obj = new InstructionBranch(Constants.IFNE,bytes.readShort()); break; + case Constants.IFLT : obj = new InstructionBranch(Constants.IFLT,bytes.readShort()); break; + case Constants.IFGE : obj = new InstructionBranch(Constants.IFGE,bytes.readShort()); break; + case Constants.IFGT : obj = new InstructionBranch(Constants.IFGT,bytes.readShort()); break; + case Constants.IFLE : obj = new InstructionBranch(Constants.IFLE,bytes.readShort()); break; + case Constants.IF_ICMPEQ: obj = new InstructionBranch(Constants.IF_ICMPEQ,bytes.readShort()); break; + case Constants.IF_ICMPNE: obj = new InstructionBranch(Constants.IF_ICMPNE,bytes.readShort()); break; + case Constants.IF_ICMPLT: obj = new InstructionBranch(Constants.IF_ICMPLT,bytes.readShort()); break; + case Constants.IF_ICMPGE: obj = new InstructionBranch(Constants.IF_ICMPGE,bytes.readShort()); break; + case Constants.IF_ICMPGT: obj = new InstructionBranch(Constants.IF_ICMPGT,bytes.readShort()); break; + case Constants.IF_ICMPLE: obj = new InstructionBranch(Constants.IF_ICMPLE,bytes.readShort()); break; + case Constants.IF_ACMPEQ: obj = new InstructionBranch(Constants.IF_ACMPEQ,bytes.readShort()); break; + case Constants.IF_ACMPNE : obj = new InstructionBranch(Constants.IF_ACMPNE,bytes.readShort()); break; + case Constants.GOTO : obj = new InstructionBranch(Constants.GOTO,bytes.readShort()); break; + case Constants.GOTO_W : obj = new InstructionBranch(Constants.GOTO_W,bytes.readInt()); break; + case Constants.JSR : obj = new InstructionBranch(Constants.JSR,bytes.readShort()); break; + case Constants.JSR_W : obj = new InstructionBranch(Constants.JSR_W,bytes.readInt()); break; + + case Constants.TABLESWITCH : obj = new TABLESWITCH(bytes); break; + case Constants.LOOKUPSWITCH : obj = new LOOKUPSWITCH(bytes); break; + + case Constants.RET : obj = new RET(wide?bytes.readUnsignedShort():bytes.readUnsignedByte(),wide); break; + +// case Constants.IRETURN : obj = new IRETURN(); break; +// case Constants.LRETURN : obj = new LRETURN(); break; +// case Constants.FRETURN : obj = new FRETURN(); break; +// case Constants.DRETURN : obj = new DRETURN(); break; +// case Constants.ARETURN : obj = new ARETURN(); break; +// case Constants.RETURN : obj = new RETURN(); break; + case Constants.NEW : obj = new InstructionCP(Constants.NEW,bytes.readUnsignedShort()); break; + + case Constants.GETSTATIC : obj = new FieldInstruction(Constants.GETSTATIC,bytes.readUnsignedShort()); break; + case Constants.PUTSTATIC : obj = new FieldInstruction(Constants.PUTSTATIC,bytes.readUnsignedShort()); break; + case Constants.GETFIELD : obj = new FieldInstruction(Constants.GETFIELD,bytes.readUnsignedShort()); break; + case Constants.PUTFIELD : obj = new FieldInstruction(Constants.PUTFIELD,bytes.readUnsignedShort()); break; + case Constants.INVOKEVIRTUAL : obj = new InvokeInstruction(Constants.INVOKEVIRTUAL,bytes.readUnsignedShort()); break; + case Constants.INVOKESPECIAL : obj = new InvokeInstruction(Constants.INVOKESPECIAL,bytes.readUnsignedShort()); break; + case Constants.INVOKESTATIC : obj = new InvokeInstruction(Constants.INVOKESTATIC,bytes.readUnsignedShort()); break; + case Constants.INVOKEINTERFACE : obj = new INVOKEINTERFACE(bytes.readUnsignedShort(),bytes.readUnsignedByte(),bytes.readByte());break; + case Constants.NEWARRAY : obj = new InstructionByte(Constants.NEWARRAY,bytes.readByte()); break; + case Constants.ANEWARRAY : obj = new InstructionCP(Constants.ANEWARRAY,bytes.readUnsignedShort()); break; + case Constants.CHECKCAST : obj = new InstructionCP(Constants.CHECKCAST,bytes.readUnsignedShort()); break; + case Constants.INSTANCEOF : obj = new InstructionCP(Constants.INSTANCEOF,bytes.readUnsignedShort()); break; + case Constants.MULTIANEWARRAY : obj = new MULTIANEWARRAY(bytes.readUnsignedShort(),bytes.readByte()); break; + default: + throw new ClassGenException("Illegal opcode detected"); + } + } catch (ClassGenException e) { + throw e; + } catch (Exception e) { + throw new ClassGenException(e.toString()); + } + + return obj; + } + + /** + * This method also gives right results for instructions whose + * effect on the stack depends on the constant pool entry they + * reference. + * @return Number of words consumed from stack by this instruction, + * or Constants.UNPREDICTABLE, if this can not be computed statically + */ + public int consumeStack(ConstantPool cpg) { + return Constants.CONSUME_STACK[opcode]; + } + + /** + * This method also gives right results for instructions whose + * effect on the stack depends on the constant pool entry they + * reference. + * @return Number of words produced onto stack by this instruction, + * or Constants.UNPREDICTABLE, if this can not be computed statically + */ + public int produceStack(ConstantPool cpg) { + return Constants.stackEntriesProduced[opcode]; + } + + /** + * @return this instructions opcode + */ + public short getOpcode() { return opcode; } + + public int getLength() { + // if it is zero, it should have been provided by an overriding implementation of getLength() + int len = Constants.iLen[opcode]; + if (len==0) throw new IllegalStateException("Length not right for "+getName().toUpperCase()); + return len; + } + + /** Some instructions may be reused, so don't do anything by default */ + void dispose() {} + + /** + * Call corresponding visitor method(s). The order is: + * Call visitor methods of implemented interfaces first, then + * call methods according to the class hierarchy in descending order, + * i.e., the most specific visitXXX() call comes last. + * + * @param v Visitor object + */ + public void accept(InstVisitor v) { + switch (opcode) { + case IMPDEP1:v.visitIMPDEP1(this);break; + case IMPDEP2:v.visitIMPDEP2(this);break; + case MONITORENTER: + v.visitExceptionThrower(this); + v.visitStackConsumer(this); + v.visitMONITORENTER(this); + break; + case MONITOREXIT: + v.visitExceptionThrower(this); + v.visitStackConsumer(this); + v.visitMONITOREXIT(this); + break; + case LCMP: + v.visitTypedInstruction(this); + v.visitStackProducer(this); + v.visitStackConsumer(this); + v.visitLCMP(this); + break; + case FCMPL: + v.visitTypedInstruction(this); + v.visitStackProducer(this); + v.visitStackConsumer(this); + v.visitFCMPL(this); + break; + case FCMPG: + v.visitTypedInstruction(this); + v.visitStackProducer(this); + v.visitStackConsumer(this); + v.visitFCMPG(this); + break; + case DCMPL: + v.visitTypedInstruction(this); + v.visitStackProducer(this); + v.visitStackConsumer(this); + v.visitDCMPL(this); + break; + case DCMPG: + v.visitTypedInstruction(this); + v.visitStackProducer(this); + v.visitStackConsumer(this); + v.visitDCMPG(this); + break; + case NOP: + v.visitNOP(this); + break; + case BREAKPOINT: + v.visitBREAKPOINT(this); + break; + case SWAP: + v.visitStackConsumer(this); + v.visitStackProducer(this); + v.visitStackInstruction(this); + v.visitSWAP(this); + break; + case POP: + v.visitStackConsumer(this); + v.visitPopInstruction(this); + v.visitStackInstruction(this); + v.visitPOP(this); + break; + case POP2: + v.visitStackConsumer(this); + v.visitPopInstruction(this); + v.visitStackInstruction(this); + v.visitPOP2(this); + break; + case DUP2_X1: + v.visitStackInstruction(this); + v.visitDUP2_X1(this); + break; + case DUP2_X2: + v.visitStackInstruction(this); + v.visitDUP2_X2(this); + break; + case DUP2: + v.visitStackProducer(this); + v.visitPushInstruction(this); + v.visitStackInstruction(this); + v.visitDUP2(this); + break; + case DUP_X1: + v.visitStackInstruction(this); + v.visitDUP_X1(this); + break; + case DUP_X2: + v.visitStackInstruction(this); + v.visitDUP_X2(this); + break; + case DUP: + v.visitStackProducer(this); + v.visitPushInstruction(this); + v.visitStackInstruction(this); + v.visitDUP(this); + break; + case BASTORE: + v.visitStackConsumer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitBASTORE(this); + break; + case CASTORE: + v.visitStackConsumer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitCASTORE(this); + break; + case SASTORE: + v.visitStackConsumer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitSASTORE(this); + break; + case DASTORE: + v.visitStackConsumer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitDASTORE(this); + break; + case FASTORE: + v.visitStackConsumer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitFASTORE(this); + break; + case LASTORE: + v.visitStackConsumer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitLASTORE(this); + break; + case IASTORE: + v.visitStackConsumer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitIASTORE(this); + break; + case AASTORE: + v.visitStackConsumer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitAASTORE(this); + break; + case SALOAD: + v.visitStackProducer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitSALOAD(this); + break; + case CALOAD: + v.visitStackProducer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitCALOAD(this); + break; + case DALOAD: + v.visitStackProducer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitDALOAD(this); + break; + case FALOAD: + v.visitStackProducer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitFALOAD(this); + break; + case LALOAD: + v.visitStackProducer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitLALOAD(this); + break; + case AALOAD: + v.visitStackProducer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitAALOAD(this); + break; + case ATHROW: + v.visitUnconditionalBranch(this); + v.visitExceptionThrower(this); + v.visitATHROW(this); + break; + case ACONST_NULL: + v.visitStackProducer(this); + v.visitPushInstruction(this); + v.visitTypedInstruction(this); + v.visitACONST_NULL(this); + break; + case ICONST_M1:case ICONST_0:case ICONST_1:case ICONST_2:case ICONST_3:case ICONST_4:case ICONST_5: + v.visitPushInstruction(this); + v.visitStackProducer(this); + v.visitTypedInstruction(this); + v.visitConstantPushInstruction(this); + v.visitICONST(this); + break; + case LCONST_0:case LCONST_1: + v.visitPushInstruction(this); + v.visitStackProducer(this); + v.visitTypedInstruction(this); + v.visitConstantPushInstruction(this); + v.visitLCONST(this); + break; + case FCONST_0:case FCONST_1:case FCONST_2: + v.visitPushInstruction(this); + v.visitStackProducer(this); + v.visitTypedInstruction(this); + v.visitConstantPushInstruction(this); + v.visitFCONST(this); + break; + case DCONST_0:case DCONST_1: + v.visitPushInstruction(this); + v.visitStackProducer(this); + v.visitTypedInstruction(this); + v.visitConstantPushInstruction(this); + v.visitDCONST(this); + case BALOAD: + v.visitStackProducer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitBALOAD(this); + break; + case IALOAD: + v.visitStackProducer(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitArrayInstruction(this); + v.visitIALOAD(this); + case BIPUSH: + v.visitPushInstruction(this); + v.visitStackProducer(this); + v.visitTypedInstruction(this); + v.visitConstantPushInstruction(this); + v.visitBIPUSH(this); + break; + case SIPUSH: + v.visitPushInstruction(this); + v.visitStackProducer(this); + v.visitTypedInstruction(this); + v.visitConstantPushInstruction(this); + v.visitSIPUSH(this); + break; + case LDC:case LDC_W: + v.visitStackProducer(this); + v.visitPushInstruction(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitCPInstruction(this); + v.visitLDC(this); + break; + case LDC2_W: + v.visitStackProducer(this); + v.visitPushInstruction(this); + v.visitTypedInstruction(this); + v.visitCPInstruction(this); + v.visitLDC2_W(this); + break; + case ARRAYLENGTH: + v.visitExceptionThrower(this); + v.visitStackProducer(this); + v.visitARRAYLENGTH(this); + break; + case ASTORE_0: + v.visitStackConsumer(this); + v.visitPopInstruction(this); + v.visitStoreInstruction(this); + v.visitTypedInstruction(this); + v.visitLocalVariableInstruction((InstructionLV)this); + v.visitStoreInstruction(this); + v.visitASTORE(this); + break; + case ALOAD_0: + v.visitStackConsumer(this); + v.visitPopInstruction(this); + v.visitStoreInstruction(this); + v.visitTypedInstruction(this); + v.visitLocalVariableInstruction((InstructionLV)this); + v.visitStoreInstruction(this); + v.visitALOAD(this); + break; + // for store instructions: ISTORE > ASTORE_3 - needs to visit the instruction too +// v.visitStackConsumer(this); +// v.visitPopInstruction(this); +// v.visitStoreInstruction(this); +// v.visitTypedInstruction(this); +// v.visitLocalVariableInstruction(this); +// v.visitStoreInstruction(this); + // for load instructions: ILOAD > ALOAD_3 - needs to visit the instruction too +// v.visitStackProducer(this); +// v.visitPushInstruction(this); +// v.visitTypedInstruction(this); +// v.visitLocalVariableInstruction(this); +// v.visitLoadInstruction(this); + + // for conversion instructions: (all 15 of them) - needs to visit conversion instruction too +// v.visitTypedInstruction(this); +// v.visitStackProducer(this); +// v.visitStackConsumer(this); +// v.visitConversionInstruction(this); + + // arithmetic instructions - need to visit the instructions too (iadd etc) +// v.visitTypedInstruction(this); +// v.visitStackProducer(this); +// v.visitStackConsumer(this); +// v.visitArithmeticInstruction(this); + + case INVOKESTATIC: + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitStackConsumer(this); + v.visitStackProducer(this); + v.visitLoadClass(this); + v.visitCPInstruction(this); + v.visitFieldOrMethod(this); + v.visitInvokeInstruction((InvokeInstruction)this); + v.visitINVOKESTATIC((InvokeInstruction)this); + break; + + case GOTO: + v.visitVariableLengthInstruction(this); + v.visitUnconditionalBranch(this); + v.visitBranchInstruction((InstructionBranch)this); + v.visitGotoInstruction(this); + v.visitGOTO(this); + break; + case PUTSTATIC: + v.visitExceptionThrower(this); + v.visitStackConsumer(this); + v.visitPopInstruction(this); + v.visitTypedInstruction(this); + v.visitLoadClass(this); + v.visitCPInstruction(this); + v.visitFieldOrMethod(this); + v.visitFieldInstruction(this); + v.visitPUTSTATIC((FieldInstruction)this); + break; + case RETURN: + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitStackConsumer(this); + v.visitReturnInstruction(this); + v.visitRETURN(this); + break; + default: throw new IllegalStateException("visiting not yet implemented for "+getName().toUpperCase()); + } + } + + /** Check for equality, delegated to comparator + * @return true if that is an Instruction and has the same opcode + */ + public boolean equals(Object that) { + return (that instanceof Instruction)? + cmp.equals(this, (Instruction)that) : false; + } + + public Type getType() { return getType(null); } + + public Type getType(ConstantPool cp) { + // if (types[opcode]==null) throw new RuntimeException(getName()+" is not a typed instruction"); + Type t = Constants.types[opcode]; + if (t!=null) return t; + switch (opcode) { + case Constants.IRETURN: return Type.INT; + case Constants.LRETURN: return Type.LONG; + case Constants.FRETURN: return Type.FLOAT; + case Constants.DRETURN: return Type.DOUBLE; + case Constants.ARETURN: return Type.OBJECT; + case Constants.RETURN: return Type.VOID; + case LCMP: return Type.LONG; + case DCMPG: case DCMPL: return Type.DOUBLE; + case FCMPG: case FCMPL: return Type.FLOAT; + case ACONST_NULL: + return Type.NULL; + case ICONST_M1:case ICONST_0:case ICONST_1:case ICONST_2:case ICONST_3:case ICONST_4:case ICONST_5: + return Type.INT; + case IALOAD: case IASTORE: + return Type.INT; + case CALOAD: case CASTORE: + return Type.CHAR; + case BALOAD: case BASTORE: + return Type.BYTE; + case SALOAD: case SASTORE: + return Type.SHORT; + case LALOAD: case LASTORE: + return Type.LONG; + case DALOAD: case DASTORE: + return Type.DOUBLE; + case FALOAD: case FASTORE: + return Type.FLOAT; + case AALOAD: case AASTORE: + return Type.OBJECT; + + case ASTORE: + case ALOAD: + return Type.OBJECT; + + case Constants.D2I: case Constants.F2I: case Constants.L2I: + return Type.INT; + case Constants.D2F: case Constants.I2F: case Constants.L2F: + return Type.FLOAT; + case Constants.D2L: case Constants.F2L: case Constants.I2L: + return Type.LONG; + case Constants.F2D: case Constants.I2D: case Constants.L2D: + return Type.DOUBLE; + case Constants.I2B: + return Type.BYTE; + case Constants.I2C: + return Type.CHAR; + case Constants.I2S: + return Type.SHORT; + + // arithmetic instructions + case Constants.IADD: case Constants.IAND: case Constants.IDIV: case Constants.IMUL: + case Constants.INEG: case Constants.IOR: case Constants.IREM: case Constants.ISHL: + case Constants.ISHR: case Constants.ISUB: case Constants.IUSHR: case Constants.IXOR: + return Type.INT; + + case Constants.DADD: case Constants.DDIV: case Constants.DMUL: case Constants.DNEG: + case Constants.DREM: case Constants.DSUB: + return Type.DOUBLE; + + case Constants.FADD: case Constants.FDIV: case Constants.FMUL: + case Constants.FNEG: case Constants.FREM: case Constants.FSUB: + return Type.FLOAT; + + + case Constants.LADD: case Constants.LAND: case Constants.LDIV: + case Constants.LMUL: case Constants.LNEG: case Constants.LOR: + case Constants.LREM: case Constants.LSHL: case Constants.LSHR: + case Constants.LSUB:case Constants.LUSHR: case Constants.LXOR: + return Type.LONG; + default: + throw new IllegalStateException("Not implemented yet for "+getName().toUpperCase()); + } + } + + public Number getValue() { + if ((instFlags[opcode]&CONSTANT_INST)==0) throw new RuntimeException(getName()+" is not a constant instruction"); + switch (opcode) { + case ICONST_M1:case ICONST_0:case ICONST_1:case ICONST_2:case ICONST_3:case ICONST_4:case ICONST_5: + return new Integer(opcode-ICONST_0); + default: + throw new IllegalStateException("Not implemented yet for "+getName()); + } + } + + public int getIndex() { return -1; } + public void setIndex(int i) { + throw new IllegalStateException("Shouldnt be asking "+getName().toUpperCase()); + } + + public Object getValue(ConstantPool cpg) { + throw new IllegalStateException("Shouldnt be asking "+getName().toUpperCase()); + } + + public boolean isLoadInstruction() { + return (Constants.instFlags[opcode]&LOAD_INST)!=0; + } + + public boolean isALOAD() { + return false; + } + + public boolean isStoreInstruction() { + return (Constants.instFlags[opcode]&STORE_INST)!=0; + } + + public boolean isASTORE() { + return false; + } + public java.lang.Class[] getExceptions() { + // fixme + return Constants.instExcs[opcode]; + } + + public boolean containsTarget(InstructionHandle ih) { throw new IllegalStateException("Dont ask!!");} + public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { throw new IllegalStateException("Dont ask!!");} + + public boolean isJsrInstruction() { + return (Constants.instFlags[opcode]&JSR_INSTRUCTION)!=0; + } + + public boolean isConstantInstruction() { + return (Constants.instFlags[opcode]&CONSTANT_INST)!=0; + } + + public boolean isConstantPoolInstruction() { + return (Constants.instFlags[opcode]&CP_INST)!=0; + } + public boolean isStackProducer() { + return (Constants.stackEntriesProduced[opcode]!=0); +// return ((Constants.instFlags[opcode]&STACK_PRODUCER)!=0); + } + public boolean isStackConsumer() { + return (Constants.CONSUME_STACK[opcode]!=0); +// return ((Constants.instFlags[opcode]&STACK_CONSUMER)!=0); + } + + public boolean isIndexedInstruction() { + return (Constants.instFlags[opcode]&INDEXED)!=0; + } + public boolean isArrayCreationInstruction() { + return (opcode==NEWARRAY || opcode==ANEWARRAY || opcode==MULTIANEWARRAY); + } + + // Asserts a property of an instruction - can be commented out after a lot of testing ;) + public void assertSomething(long flag) { + if ((Constants.instFlags[opcode]&flag)==0) throw new IllegalStateException("This opcode "+opcode+" does not have the property "+Long.toHexString(flag)); + } + + public ObjectType getLoadClassType(ConstantPool cpg) { + assertSomething(Constants.LOADCLASS_INST); + Type t = getType(cpg); + if (t instanceof ArrayType) t = ((ArrayType)t).getBasicType(); + return (t instanceof ObjectType)?(ObjectType)t:null; + } + + public boolean isReturnInstruction() { + return (Constants.instFlags[opcode]&RET_INST)!=0; + } + public boolean isGoto() { + return opcode==GOTO || opcode==GOTO_W; + } + public boolean isLocalVariableInstruction() { + return (Constants.instFlags[opcode]&LV_INST)!=0; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionBranch.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionBranch.java index f76075bd3..ffdabd111 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionBranch.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionBranch.java @@ -1,339 +1,340 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.*; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.ConstantPool; - -/** - * Abstract super class for branching instructions like GOTO, IFEQ, etc.. - * Branch instructions may have a variable length, namely GOTO, JSR, - * LOOKUPSWITCH and TABLESWITCH. - * - * @see InstructionList - * @version $Id: InstructionBranch.java,v 1.1.2.2 2008/04/25 17:55:34 aclement Exp $ - * @author M. Dahm - */ -/** - * A branch instruction may be talking in terms of absolute destination (targetIndex) or about an instruction it - * doesnt yet know the position if (targetInstruction). targetInstruction (if set) overrides targetIndex - */ -public class InstructionBranch extends Instruction implements InstructionTargeter { - private static final int UNSET = -1; - - protected int targetIndex = UNSET; // Branch target relative to this instruction - protected InstructionHandle targetInstruction; // Target object in instruction list - protected int positionOfThisInstruction; // for calculating relative branch destinations! - - /** - * Constructor if building an instruction branch that targets a handle (ie. we don't need to actual targetIndex in the bytecode yet) - */ - public InstructionBranch(short opcode, InstructionHandle target) { -// if (opcode == GOTO ) System.err.println("building GOTO"); - this.opcode = opcode; - setTarget(target); - } - - public InstructionBranch(short opcode, int index) { -// if (opcode == GOTO ) System.err.println("targetIndex set to "+index); - this.opcode = opcode; - this.targetIndex = index; - } - - // used when we know nothing - public InstructionBranch(short opcode) { - this.opcode = opcode; - } - - public void dump(DataOutputStream out) throws IOException { - out.writeByte(opcode); - int target = getTargetOffset(); -// System.err.println("Writing out target for branch instruction "+getName()); - switch (opcode) { - case GOTO: -// System.err.println("Writing out target "+target); - out.writeShort(target); - break; - case GOTO_W: -// System.err.println("Writing out target "+target); - out.writeInt(target); - break; - - case IF_ACMPEQ: - case IF_ACMPNE: - case IF_ICMPEQ: - case IF_ICMPGE: - case IF_ICMPGT: - case IF_ICMPLE: - case IF_ICMPLT: - case IF_ICMPNE: - case IFEQ: - case IFLE: - case IFLT: - case IFGT: - case IFNE: - case IFGE: - case IFNULL: - case IFNONNULL: - out.writeShort(target); - break; - - case JSR: - out.writeShort(target); - break; - case JSR_W: - out.writeInt(target); - break; - - default: - throw new IllegalStateException("Don't know how to write out "+getName().toUpperCase()); - } - - if(Math.abs(target) >= 32767) // too large for short - throw new ClassGenException("Branch target offset too large for short"); - } - - protected int getTargetOffset() { - if(targetInstruction == null && targetIndex==UNSET) - throw new ClassGenException("Target of " + super.toString(true) + " is unknown"); - - if (targetInstruction==null) { - return targetIndex; - } else { - return targetInstruction.getPosition()-positionOfThisInstruction; - } - } - - - /** - * Called by InstructionList.setPositions when setting the position for every - * instruction. In the presence of variable length instructions `setPositions' - * performs multiple passes over the instruction list to calculate the - * correct (byte) positions and offsets by calling this function. - * - * @param offset additional offset caused by preceding (variable length) instructions - * @param max_offset the maximum offset that may be caused by these instructions - * @return additional offset caused by possible change of this instruction's length - */ - protected int updatePosition(int offset, int max_offset) { - int i = getTargetOffset(); - - positionOfThisInstruction += offset; - - if (Math.abs(i)>=(32767-max_offset)) { // too larget for short (we think) - throw new IllegalStateException("Argh!"); - } - - return 0; - } - - /** - * Long output format: - * - * <position in byte code> - * <name of opcode> "["<opcode number>"]" - * "("<length of instruction>")" - * "<"<target instruction>">" "@"<branch target offset> - * - * @param verbose long/short format switch - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - String s = super.toString(verbose); - String t = "null"; - - if(verbose) { - if(targetInstruction != null) { - if(targetInstruction.getInstruction() == this) - t = ""; - else if(targetInstruction.getInstruction() == null) - t = ""; - else - t = targetInstruction.getInstruction().toString(false); // Avoid circles - } - } else { - if(targetInstruction != null) { - targetIndex = getTargetOffset(); - t = "" + (targetIndex + positionOfThisInstruction); - } - } - - return s + " -> " + t; - } - - - /** - * @return target offset in byte code - */ - public final int getIndex() { return targetIndex; } - - /** - * @return target of branch instruction - */ - public InstructionHandle getTarget() { return targetInstruction; } - - /** - * Set branch target - * @param target branch target - */ - public void setTarget(InstructionHandle target) { -// if (opcode==GOTO) System.err.println("Set target to "+target); - notifyTarget(this.targetInstruction, target, this); - this.targetInstruction = target; - } - - /** - * Used by BranchInstruction, LocalVariableGen, CodeExceptionGen - */ - static final void notifyTarget(InstructionHandle old_ih, InstructionHandle new_ih, - InstructionTargeter t) { - if(old_ih != null) - old_ih.removeTargeter(t); - if(new_ih != null) - new_ih.addTargeter(t); - } - - /** - * @param old_ih old target - * @param new_ih new target - */ - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { - if(targetInstruction == old_ih) - setTarget(new_ih); - else - throw new ClassGenException("Not targeting " + old_ih + ", but " + targetInstruction); - } - - /** - * @return true, if ih is target of this instruction - */ - public boolean containsTarget(InstructionHandle ih) { - return (targetInstruction == ih); - } - - /** - * Inform target that it's not targeted anymore. - */ - void dispose() { - setTarget(null); - targetIndex=-1; - positionOfThisInstruction=-1; - } - - public InstructionBranch negate() { - if ((Constants.instFlags[opcode]&Constants.NEGATABLE)==0) throw new IllegalStateException("Operation is not negatable"); - switch (opcode) { - case IFGT: return copy(Constants.IFNE); - case IFLE: return copy(Constants.IFGT); - default: - throw new IllegalStateException("Dunno:"+opcode); - } - } - - private InstructionBranch copy(short opcode) { - InstructionBranch ib = null; - if (targetInstruction!=null) { - ib = new InstructionBranch(opcode,targetInstruction); - } else { - ib = new InstructionBranch(opcode,targetIndex); - } - ib.positionOfThisInstruction = positionOfThisInstruction; - return ib; - } - public Type getType(ConstantPool cp) { - if ((Constants.instFlags[opcode]&Constants.JSR_INSTRUCTION)!=0) return new ReturnaddressType(physicalSuccessor()); - return super.getType(cp); - } - - /** - * Returns an InstructionHandle to the physical successor - * of this JsrInstruction. For this method to work, - * this JsrInstruction object must not be shared between - * multiple InstructionHandle objects! - * Formally, there must not be InstructionHandle objects - * i, j where i != j and i.getInstruction() == this == - * j.getInstruction(). - * @return an InstructionHandle to the "next" instruction that - * will be executed when RETurned from a subroutine. - */ - public InstructionHandle physicalSuccessor(){ - InstructionHandle ih = this.targetInstruction; - - // Rewind! - while(ih.getPrev() != null) - ih = ih.getPrev(); - - // Find the handle for "this" JsrInstruction object. - while(ih.getInstruction() != this) - ih = ih.getNext(); - - InstructionHandle toThis = ih; - - while(ih != null){ - ih = ih.getNext(); - if ((ih != null) && (ih.getInstruction() == this)) - throw new RuntimeException("physicalSuccessor() called on a shared JsrInstruction."); - } - - // Return the physical successor - return toThis.getNext(); - } - - public boolean isIfInstruction() { - return ((Constants.instFlags[opcode]&Constants.IF_INST)!=0); - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.*; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.ConstantPool; + +/** + * Abstract super class for branching instructions like GOTO, IFEQ, etc.. + * Branch instructions may have a variable length, namely GOTO, JSR, + * LOOKUPSWITCH and TABLESWITCH. + * + * @see InstructionList + * @version $Id: InstructionBranch.java,v 1.1.2.3 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + */ +/** + * A branch instruction may be talking in terms of absolute destination (targetIndex) or about an instruction it + * doesnt yet know the position if (targetInstruction). targetInstruction (if set) overrides targetIndex + */ +public class InstructionBranch extends Instruction implements InstructionTargeter { + private static final int UNSET = -1; + + protected int targetIndex = UNSET; // Branch target relative to this instruction + protected InstructionHandle targetInstruction; // Target object in instruction list + protected int positionOfThisInstruction; // for calculating relative branch destinations! + + /** + * Constructor if building an instruction branch that targets a handle (ie. we don't need to actual targetIndex in the bytecode yet) + */ + public InstructionBranch(short opcode, InstructionHandle target) { +// if (opcode == GOTO ) System.err.println("building GOTO"); + this.opcode = opcode; + setTarget(target); + } + + public InstructionBranch(short opcode, int index) { +// if (opcode == GOTO ) System.err.println("targetIndex set to "+index); + this.opcode = opcode; + this.targetIndex = index; + } + + // used when we know nothing + public InstructionBranch(short opcode) { + this.opcode = opcode; + } + + public void dump(DataOutputStream out) throws IOException { + out.writeByte(opcode); + int target = getTargetOffset(); +// System.err.println("Writing out target for branch instruction "+getName()); + switch (opcode) { + case GOTO: +// System.err.println("Writing out target "+target); + out.writeShort(target); + break; + case GOTO_W: +// System.err.println("Writing out target "+target); + out.writeInt(target); + break; + + case IF_ACMPEQ: + case IF_ACMPNE: + case IF_ICMPEQ: + case IF_ICMPGE: + case IF_ICMPGT: + case IF_ICMPLE: + case IF_ICMPLT: + case IF_ICMPNE: + case IFEQ: + case IFLE: + case IFLT: + case IFGT: + case IFNE: + case IFGE: + case IFNULL: + case IFNONNULL: + out.writeShort(target); + break; + + case JSR: + out.writeShort(target); + break; + case JSR_W: + out.writeInt(target); + break; + + default: + throw new IllegalStateException("Don't know how to write out "+getName().toUpperCase()); + } + + if(Math.abs(target) >= 32767) // too large for short + throw new ClassGenException("Branch target offset too large for short"); + } + + protected int getTargetOffset() { + if(targetInstruction == null && targetIndex==UNSET) + throw new ClassGenException("Target of " + super.toString(true) + " is unknown"); + + if (targetInstruction==null) { + return targetIndex; + } else { + return targetInstruction.getPosition()-positionOfThisInstruction; + } + } + + + /** + * Called by InstructionList.setPositions when setting the position for every + * instruction. In the presence of variable length instructions `setPositions' + * performs multiple passes over the instruction list to calculate the + * correct (byte) positions and offsets by calling this function. + * + * @param offset additional offset caused by preceding (variable length) instructions + * @param max_offset the maximum offset that may be caused by these instructions + * @return additional offset caused by possible change of this instruction's length + */ + protected int updatePosition(int offset, int max_offset) { + int i = getTargetOffset(); + + positionOfThisInstruction += offset; + + if (Math.abs(i)>=(32767-max_offset)) { // too larget for short (we think) + throw new IllegalStateException("Argh!"); + } + + return 0; + } + + /** + * Long output format: + * + * <position in byte code> + * <name of opcode> "["<opcode number>"]" + * "("<length of instruction>")" + * "<"<target instruction>">" "@"<branch target offset> + * + * @param verbose long/short format switch + * @return mnemonic for instruction + */ + public String toString(boolean verbose) { + String s = super.toString(verbose); + String t = "null"; + + if(verbose) { + if(targetInstruction != null) { + if(targetInstruction.getInstruction() == this) + t = ""; + else if(targetInstruction.getInstruction() == null) + t = ""; + else + t = targetInstruction.getInstruction().toString(false); // Avoid circles + } + } else { + if(targetInstruction != null) { + targetIndex = getTargetOffset(); + t = "" + (targetIndex + positionOfThisInstruction); + } + } + + return s + " -> " + t; + } + + + /** + * @return target offset in byte code + */ + public final int getIndex() { return targetIndex; } + + /** + * @return target of branch instruction + */ + public InstructionHandle getTarget() { return targetInstruction; } + + /** + * Set branch target + * @param target branch target + */ + public void setTarget(InstructionHandle target) { +// if (opcode==GOTO) System.err.println("Set target to "+target); + notifyTarget(this.targetInstruction, target, this); + this.targetInstruction = target; + } + + /** + * Used by BranchInstruction, LocalVariableGen, CodeExceptionGen + */ + static final void notifyTarget(InstructionHandle old_ih, InstructionHandle new_ih, + InstructionTargeter t) { + if(old_ih != null) + old_ih.removeTargeter(t); + if(new_ih != null) + new_ih.addTargeter(t); + } + + /** + * @param old_ih old target + * @param new_ih new target + */ + public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { + if(targetInstruction == old_ih) + setTarget(new_ih); + else + throw new ClassGenException("Not targeting " + old_ih + ", but " + targetInstruction); + } + + /** + * @return true, if ih is target of this instruction + */ + public boolean containsTarget(InstructionHandle ih) { + return (targetInstruction == ih); + } + + /** + * Inform target that it's not targeted anymore. + */ + void dispose() { + setTarget(null); + targetIndex=-1; + positionOfThisInstruction=-1; + } + + // OPTIMIZE why bother with this? +// public InstructionBranch negate() { +// if ((Constants.instFlags[opcode]&Constants.NEGATABLE)==0) throw new IllegalStateException("Operation is not negatable"); +// switch (opcode) { +// case IFGT: return copy(Constants.IFNE); +// case IFLE: return copy(Constants.IFGT); +// default: +// throw new IllegalStateException("Dunno:"+opcode); +// } +// } +// +// private InstructionBranch copy(short opcode) { +// InstructionBranch ib = null; +// if (targetInstruction!=null) { +// ib = new InstructionBranch(opcode,targetInstruction); +// } else { +// ib = new InstructionBranch(opcode,targetIndex); +// } +// ib.positionOfThisInstruction = positionOfThisInstruction; +// return ib; +// } + public Type getType(ConstantPool cp) { + if ((Constants.instFlags[opcode]&Constants.JSR_INSTRUCTION)!=0) return new ReturnaddressType(physicalSuccessor()); + return super.getType(cp); + } + + /** + * Returns an InstructionHandle to the physical successor + * of this JsrInstruction. For this method to work, + * this JsrInstruction object must not be shared between + * multiple InstructionHandle objects! + * Formally, there must not be InstructionHandle objects + * i, j where i != j and i.getInstruction() == this == + * j.getInstruction(). + * @return an InstructionHandle to the "next" instruction that + * will be executed when RETurned from a subroutine. + */ + public InstructionHandle physicalSuccessor(){ + InstructionHandle ih = this.targetInstruction; + + // Rewind! + while(ih.getPrev() != null) + ih = ih.getPrev(); + + // Find the handle for "this" JsrInstruction object. + while(ih.getInstruction() != this) + ih = ih.getNext(); + + InstructionHandle toThis = ih; + + while(ih != null){ + ih = ih.getNext(); + if ((ih != null) && (ih.getInstruction() == this)) + throw new RuntimeException("physicalSuccessor() called on a shared JsrInstruction."); + } + + // Return the physical successor + return toThis.getNext(); + } + + public boolean isIfInstruction() { + return ((Constants.instFlags[opcode]&Constants.IF_INST)!=0); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionCP.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionCP.java index f09f40ccf..7b0c3d19b 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionCP.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionCP.java @@ -1,196 +1,196 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.DataOutputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.classfile.Constant; -import org.aspectj.apache.bcel.classfile.ConstantClass; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.Constants; - -/** - * Slass for instructions that use an index into the - * constant pool such as LDC, INVOKEVIRTUAL, etc. - * - * @see ConstantPoolGen - * @see LDC - * @see INVOKEVIRTUAL - * - * @version $Id: InstructionCP.java,v 1.1.2.2 2008/04/25 17:55:32 aclement Exp $ - * @author M. Dahm - */ -public class InstructionCP extends Instruction { - protected int index; // index to constant pool - - public InstructionCP(short opcode, int index) { - this.opcode = opcode; - this.index = index; - } - - public void dump(DataOutputStream out) throws IOException { - if (opcode==LDC_W && index<256) { - out.writeByte(LDC); - out.writeByte(index); - } else { - out.writeByte(opcode); - if(Constants.iLen[opcode] == 2) { - if (index>255) { - throw new IllegalStateException(); - } - out.writeByte(index); - } else - out.writeShort(index); - } - } - - public int getLength() { - if (opcode==LDC_W && index<256) return 2; else return super.getLength(); - } - - /** - * Long output format: - * - * <name of opcode> "["<opcode number>"]" - * "("<length of instruction>")" "<"< constant pool index>">" - * - * @param verbose long/short format switch - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - return super.toString(verbose) + " " + index; - } - - /** - * @return mnemonic for instruction with symbolic references resolved - */ - public String toString(ConstantPool cp) { - Constant c = cp.getConstant(index); - String str = cp.constantToString(c); - - if(c instanceof ConstantClass) - str = str.replace('.', '/'); - - return org.aspectj.apache.bcel.Constants.OPCODE_NAMES[opcode] + " " + str; - } - - /** - * @return index in constant pool referred by this instruction. - */ - public final int getIndex() { return index; } - - public void setIndex(int index) { - this.index = index; - if (this.index>255 && opcode==LDC) { - // promote it - opcode = LDC_W; - } - } - - public Type getType(ConstantPool cpg) { - switch (cpg.getConstant(index).getTag()) { - case CONSTANT_String: return Type.STRING; - case CONSTANT_Float: return Type.FLOAT; - case CONSTANT_Integer: return Type.INT; - case CONSTANT_Long: return Type.LONG; - case CONSTANT_Double: return Type.DOUBLE; - case CONSTANT_Class: - String name = cpg.getConstantString_CONSTANTClass(index); -// ConstantPool cp = cpg.getConstantPool(); -// String name = cp.getConstantString(index, CONSTANT_Class); - if(!name.startsWith("[")) { - StringBuffer sb = new StringBuffer(); - sb.append("L").append(name).append(";"); - return Type.getType(sb.toString()); - } else { - return Type.getType(name); - } - default: // Never reached - throw new RuntimeException("Unknown or invalid constant type at " + index); - } - } - - public Object getValue(ConstantPool cpg) { - org.aspectj.apache.bcel.classfile.Constant c = cpg.getConstant(index); - - switch(c.getTag()) { - case org.aspectj.apache.bcel.Constants.CONSTANT_String: - int i = ((org.aspectj.apache.bcel.classfile.ConstantString)c).getStringIndex(); - c = cpg.getConstant(i); - return ((org.aspectj.apache.bcel.classfile.ConstantUtf8)c).getBytes(); - - case org.aspectj.apache.bcel.Constants.CONSTANT_Float: - return new Float(((org.aspectj.apache.bcel.classfile.ConstantFloat)c).getBytes()); - - case org.aspectj.apache.bcel.Constants.CONSTANT_Integer: - return new Integer(((org.aspectj.apache.bcel.classfile.ConstantInteger)c).getBytes()); - - // from ldc2_w: - case org.aspectj.apache.bcel.Constants.CONSTANT_Long: - return new Long(((org.aspectj.apache.bcel.classfile.ConstantLong)c).getBytes()); - - case org.aspectj.apache.bcel.Constants.CONSTANT_Double: - return new Double(((org.aspectj.apache.bcel.classfile.ConstantDouble)c).getBytes()); - default: // Never reached - throw new RuntimeException("Unknown or invalid constant type at " + index); - } - } - - - public Class[] getExceptions() { - return org.aspectj.apache.bcel.ExceptionConstants.EXCS_STRING_RESOLUTION; - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.DataOutputStream; +import java.io.IOException; + +import org.aspectj.apache.bcel.classfile.Constant; +import org.aspectj.apache.bcel.classfile.ConstantClass; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.Constants; + +/** + * Slass for instructions that use an index into the + * constant pool such as LDC, INVOKEVIRTUAL, etc. + * + * @see ConstantPoolGen + * @see LDC + * @see INVOKEVIRTUAL + * + * @version $Id: InstructionCP.java,v 1.1.2.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public class InstructionCP extends Instruction { + protected int index; // index to constant pool + + public InstructionCP(short opcode, int index) { + this.opcode = opcode; + this.index = index; + } + + public void dump(DataOutputStream out) throws IOException { + if (opcode==LDC_W && index<256) { + out.writeByte(LDC); + out.writeByte(index); + } else { + out.writeByte(opcode); + if(Constants.iLen[opcode] == 2) { + if (index>255) { + throw new IllegalStateException(); + } + out.writeByte(index); + } else + out.writeShort(index); + } + } + + public int getLength() { + if (opcode==LDC_W && index<256) return 2; else return super.getLength(); + } + + /** + * Long output format: + * + * <name of opcode> "["<opcode number>"]" + * "("<length of instruction>")" "<"< constant pool index>">" + * + * @param verbose long/short format switch + * @return mnemonic for instruction + */ + public String toString(boolean verbose) { + return super.toString(verbose) + " " + index; + } + + /** + * @return mnemonic for instruction with symbolic references resolved + */ + public String toString(ConstantPool cp) { + Constant c = cp.getConstant(index); + String str = cp.constantToString(c); + + if(c instanceof ConstantClass) + str = str.replace('.', '/'); + + return org.aspectj.apache.bcel.Constants.OPCODE_NAMES[opcode] + " " + str; + } + + /** + * @return index in constant pool referred by this instruction. + */ + public final int getIndex() { return index; } + + public void setIndex(int index) { + this.index = index; + if (this.index>255 && opcode==LDC) { + // promote it + opcode = LDC_W; + } + } + + public Type getType(ConstantPool cpg) { + switch (cpg.getConstant(index).getTag()) { + case CONSTANT_String: return Type.STRING; + case CONSTANT_Float: return Type.FLOAT; + case CONSTANT_Integer: return Type.INT; + case CONSTANT_Long: return Type.LONG; + case CONSTANT_Double: return Type.DOUBLE; + case CONSTANT_Class: + String name = cpg.getConstantString_CONSTANTClass(index); +// ConstantPool cp = cpg.getConstantPool(); +// String name = cp.getConstantString(index, CONSTANT_Class); + if(!name.startsWith("[")) { + StringBuffer sb = new StringBuffer(); + sb.append("L").append(name).append(";"); + return Type.getType(sb.toString()); + } else { + return Type.getType(name); + } + default: // Never reached + throw new RuntimeException("Unknown or invalid constant type at " + index); + } + } + + public Object getValue(ConstantPool cpg) { + org.aspectj.apache.bcel.classfile.Constant c = cpg.getConstant(index); + + switch(c.getTag()) { + case org.aspectj.apache.bcel.Constants.CONSTANT_String: + int i = ((org.aspectj.apache.bcel.classfile.ConstantString)c).getStringIndex(); + c = cpg.getConstant(i); + return ((org.aspectj.apache.bcel.classfile.ConstantUtf8)c).getBytes(); + + case org.aspectj.apache.bcel.Constants.CONSTANT_Float: + return new Float(((org.aspectj.apache.bcel.classfile.ConstantFloat)c).getBytes()); + + case org.aspectj.apache.bcel.Constants.CONSTANT_Integer: + return new Integer(((org.aspectj.apache.bcel.classfile.ConstantInteger)c).getBytes()); + + // from ldc2_w: + case org.aspectj.apache.bcel.Constants.CONSTANT_Long: + return new Long(((org.aspectj.apache.bcel.classfile.ConstantLong)c).getBytes()); + + case org.aspectj.apache.bcel.Constants.CONSTANT_Double: + return new Double(((org.aspectj.apache.bcel.classfile.ConstantDouble)c).getBytes()); + default: // Never reached + throw new RuntimeException("Unknown or invalid constant type at " + index); + } + } + + + public Class[] getExceptions() { + return org.aspectj.apache.bcel.ExceptionConstants.EXCS_STRING_RESOLUTION; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionComparator.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionComparator.java index e6fc623d6..97ce931df 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionComparator.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionComparator.java @@ -1,112 +1,112 @@ -package org.aspectj.apache.bcel.generic; - -import org.aspectj.apache.bcel.Constants; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Equality of instructions isn't clearly to be defined. You might - * wish, for example, to compare whether instructions have the same - * meaning. E.g., whether two INVOKEVIRTUALs describe the same - * call.
          The DEFAULT comparator however, considers two instructions - * to be equal if they have same opcode and point to the same indexes - * (if any) in the constant pool or the same local variable index. Branch - * instructions must have the same target. - * - * @see Instruction - * @version $Id: InstructionComparator.java,v 1.3.8.2 2008/04/25 17:55:33 aclement Exp $ - * @author M. Dahm - */ -public interface InstructionComparator { - public static final InstructionComparator DEFAULT = new InstructionComparator() { - public boolean equals(Instruction i1, Instruction i2) { - if (i1.opcode == i2.opcode) { - if (i1 instanceof InstructionSelect) { - InstructionHandle[] t1 = ((InstructionSelect) i1).getTargets(); - InstructionHandle[] t2 = ((InstructionSelect) i2).getTargets(); - - // See AspectJ bug 104957 - if (t1 == null && t2 == null) return true; - if (t1 == null || t2 == null) return false; - - if (t1.length == t2.length) { - for (int i = 0; i < t1.length; i++) { - if (t1[i] != t2[i]) { - return false; - } - } - - return true; - } - } else if (i1 instanceof InstructionBranch) { - return ((InstructionBranch) i1).targetInstruction == ((InstructionBranch) i2).targetInstruction; - } else if (i1.isConstantInstruction()) { - return i1.getValue().equals(i2.getValue()); - } else if (i1.isIndexedInstruction()) { - return i1.getIndex() == i2.getIndex(); - } else if (i1.opcode==Constants.NEWARRAY) { - return ((InstructionByte) i1).getTypecode() == ((InstructionByte) i2) - .getTypecode(); - } else { - return true; - } - } - - return false; - } - }; - - public boolean equals(Instruction i1, Instruction i2); -} +package org.aspectj.apache.bcel.generic; + +import org.aspectj.apache.bcel.Constants; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Equality of instructions isn't clearly to be defined. You might + * wish, for example, to compare whether instructions have the same + * meaning. E.g., whether two INVOKEVIRTUALs describe the same + * call.
          The DEFAULT comparator however, considers two instructions + * to be equal if they have same opcode and point to the same indexes + * (if any) in the constant pool or the same local variable index. Branch + * instructions must have the same target. + * + * @see Instruction + * @version $Id: InstructionComparator.java,v 1.3.8.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public interface InstructionComparator { + public static final InstructionComparator DEFAULT = new InstructionComparator() { + public boolean equals(Instruction i1, Instruction i2) { + if (i1.opcode == i2.opcode) { + if (i1 instanceof InstructionSelect) { + InstructionHandle[] t1 = ((InstructionSelect) i1).getTargets(); + InstructionHandle[] t2 = ((InstructionSelect) i2).getTargets(); + + // See AspectJ bug 104957 + if (t1 == null && t2 == null) return true; + if (t1 == null || t2 == null) return false; + + if (t1.length == t2.length) { + for (int i = 0; i < t1.length; i++) { + if (t1[i] != t2[i]) { + return false; + } + } + + return true; + } + } else if (i1 instanceof InstructionBranch) { + return ((InstructionBranch) i1).targetInstruction == ((InstructionBranch) i2).targetInstruction; + } else if (i1.isConstantInstruction()) { + return i1.getValue().equals(i2.getValue()); + } else if (i1.isIndexedInstruction()) { + return i1.getIndex() == i2.getIndex(); + } else if (i1.opcode==Constants.NEWARRAY) { + return ((InstructionByte) i1).getTypecode() == ((InstructionByte) i2) + .getTypecode(); + } else { + return true; + } + } + + return false; + } + }; + + public boolean equals(Instruction i1, Instruction i2); +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionConstants.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionConstants.java index 6b7ee6bd2..af3c15980 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionConstants.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionConstants.java @@ -1,367 +1,367 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; - -/** - * This interface contains shareable instruction objects. - * - * In order to save memory you can use some instructions multiply, - * since they have an immutable state and are directly derived from - * Instruction. I.e. they have no instance fields that could be - * changed. Since some of these instructions like ICONST_0 occur - * very frequently this can save a lot of time and space. This - * feature is an adaptation of the FlyWeight design pattern, we - * just use an array instead of a factory. - * - * The Instructions can also accessed directly under their names, so - * it's possible to write il.append(Instruction.ICONST_0); - * - * @version $Id: InstructionConstants.java,v 1.2.10.2 2008/04/25 17:55:32 aclement Exp $ - * @author M. Dahm - */ -public interface InstructionConstants { - /** Predefined instruction objects - */ - public static final Instruction NOP = new Instruction(Constants.NOP); - public static final Instruction ACONST_NULL = new Instruction(Constants.ACONST_NULL); - public static final Instruction ICONST_M1 = new Instruction(Constants.ICONST_M1); - public static final Instruction ICONST_0 = new Instruction(Constants.ICONST_0); - public static final Instruction ICONST_1 = new Instruction(Constants.ICONST_1); - public static final Instruction ICONST_2 = new Instruction(Constants.ICONST_2); - public static final Instruction ICONST_3 = new Instruction(Constants.ICONST_3); - public static final Instruction ICONST_4 = new Instruction(Constants.ICONST_4); - public static final Instruction ICONST_5 = new Instruction(Constants.ICONST_5); - public static final Instruction LCONST_0 = new Instruction(Constants.LCONST_0); - public static final Instruction LCONST_1 = new Instruction(Constants.LCONST_1); - public static final Instruction FCONST_0 = new Instruction(Constants.FCONST_0); - public static final Instruction FCONST_1 = new Instruction(Constants.FCONST_1); - public static final Instruction FCONST_2 = new Instruction(Constants.FCONST_2); - public static final Instruction DCONST_0 = new Instruction(Constants.DCONST_0); - public static final Instruction DCONST_1 = new Instruction(Constants.DCONST_1); - public static final Instruction IALOAD = new Instruction(Constants.IALOAD); - public static final Instruction LALOAD = new Instruction(Constants.LALOAD); - public static final Instruction FALOAD = new Instruction(Constants.FALOAD); - public static final Instruction DALOAD = new Instruction(Constants.DALOAD); - public static final Instruction AALOAD = new Instruction(Constants.AALOAD); - public static final Instruction BALOAD = new Instruction(Constants.BALOAD); - public static final Instruction CALOAD = new Instruction(Constants.CALOAD); - public static final Instruction SALOAD = new Instruction(Constants.SALOAD); - public static final Instruction IASTORE = new Instruction(Constants.IASTORE); - public static final Instruction LASTORE = new Instruction(Constants.LASTORE); - public static final Instruction FASTORE = new Instruction(Constants.FASTORE); - public static final Instruction DASTORE = new Instruction(Constants.DASTORE); - public static final Instruction AASTORE = new Instruction(Constants.AASTORE); - public static final Instruction BASTORE = new Instruction(Constants.BASTORE); - public static final Instruction CASTORE = new Instruction(Constants.CASTORE); - public static final Instruction SASTORE = new Instruction(Constants.SASTORE); - public static final Instruction POP = new Instruction(Constants.POP); - public static final Instruction POP2 = new Instruction(Constants.POP2); - public static final Instruction DUP = new Instruction(Constants.DUP); - public static final Instruction DUP_X1 = new Instruction(Constants.DUP_X1); - public static final Instruction DUP_X2 = new Instruction(Constants.DUP_X2); - public static final Instruction DUP2 = new Instruction(Constants.DUP2); - public static final Instruction DUP2_X1 = new Instruction(Constants.DUP2_X1); - public static final Instruction DUP2_X2 = new Instruction(Constants.DUP2_X2); - public static final Instruction SWAP = new Instruction(Constants.SWAP); - public static final Instruction IADD = new Instruction(Constants.IADD); - public static final Instruction LADD = new Instruction(Constants.LADD); - public static final Instruction FADD = new Instruction(Constants.FADD); - public static final Instruction DADD = new Instruction(Constants.DADD); - public static final Instruction ISUB = new Instruction(Constants.ISUB); - public static final Instruction LSUB = new Instruction(Constants.LSUB); - public static final Instruction FSUB = new Instruction(Constants.FSUB); - public static final Instruction DSUB = new Instruction(Constants.DSUB); - public static final Instruction IMUL = new Instruction(Constants.IMUL); - public static final Instruction LMUL = new Instruction(Constants.LMUL); - public static final Instruction FMUL = new Instruction(Constants.FMUL); - public static final Instruction DMUL = new Instruction(Constants.DMUL); - public static final Instruction IDIV = new Instruction(Constants.IDIV); - public static final Instruction LDIV = new Instruction(Constants.LDIV); - public static final Instruction FDIV = new Instruction(Constants.FDIV); - public static final Instruction DDIV = new Instruction(Constants.DDIV); - public static final Instruction IREM = new Instruction(Constants.IREM); - public static final Instruction LREM = new Instruction(Constants.LREM); - public static final Instruction FREM = new Instruction(Constants.FREM); - public static final Instruction DREM = new Instruction(Constants.DREM); - public static final Instruction INEG = new Instruction(Constants.INEG); - public static final Instruction LNEG = new Instruction(Constants.LNEG); - public static final Instruction FNEG = new Instruction(Constants.FNEG); - public static final Instruction DNEG = new Instruction(Constants.DNEG); - public static final Instruction ISHL = new Instruction(Constants.ISHL); - public static final Instruction LSHL = new Instruction(Constants.LSHL); - public static final Instruction ISHR = new Instruction(Constants.ISHR); - public static final Instruction LSHR = new Instruction(Constants.LSHR); - public static final Instruction IUSHR = new Instruction(Constants.IUSHR); - public static final Instruction LUSHR = new Instruction(Constants.LUSHR); - public static final Instruction IAND = new Instruction(Constants.IAND); - public static final Instruction LAND = new Instruction(Constants.LAND); - public static final Instruction IOR = new Instruction(Constants.IOR); - public static final Instruction LOR = new Instruction(Constants.LOR); - public static final Instruction IXOR = new Instruction(Constants.IXOR); - public static final Instruction LXOR = new Instruction(Constants.LXOR); - public static final Instruction I2L = new Instruction(Constants.I2L); - public static final Instruction I2F = new Instruction(Constants.I2F); - public static final Instruction I2D = new Instruction(Constants.I2D); - public static final Instruction L2I = new Instruction(Constants.L2I); - public static final Instruction L2F = new Instruction(Constants.L2F); - public static final Instruction L2D = new Instruction(Constants.L2D); - public static final Instruction F2I = new Instruction(Constants.F2I); - public static final Instruction F2L = new Instruction(Constants.F2L); - public static final Instruction F2D = new Instruction(Constants.F2D); - public static final Instruction D2I = new Instruction(Constants.D2I); - public static final Instruction D2L = new Instruction(Constants.D2L); - public static final Instruction D2F = new Instruction(Constants.D2F); - public static final Instruction I2B = new Instruction(Constants.I2B); - public static final Instruction I2C = new Instruction(Constants.I2C); - public static final Instruction I2S = new Instruction(Constants.I2S); - public static final Instruction LCMP = new Instruction(Constants.LCMP); - public static final Instruction FCMPL = new Instruction(Constants.FCMPL); - public static final Instruction FCMPG = new Instruction(Constants.FCMPG); - public static final Instruction DCMPL = new Instruction(Constants.DCMPL); - public static final Instruction DCMPG = new Instruction(Constants.DCMPG); - public static final Instruction IRETURN = new Instruction(Constants.IRETURN); - public static final Instruction LRETURN = new Instruction(Constants.LRETURN); - public static final Instruction FRETURN = new Instruction(Constants.FRETURN); - public static final Instruction DRETURN = new Instruction(Constants.DRETURN); - public static final Instruction ARETURN = new Instruction(Constants.ARETURN); - public static final Instruction RETURN = new Instruction(Constants.RETURN); - public static final Instruction ARRAYLENGTH = new Instruction(Constants.ARRAYLENGTH); - public static final Instruction ATHROW = new Instruction(Constants.ATHROW); - public static final Instruction MONITORENTER = new Instruction(Constants.MONITORENTER); - public static final Instruction MONITOREXIT = new Instruction(Constants.MONITOREXIT); - public static final Instruction IMPDEP1 = new Instruction(Constants.IMPDEP1); - public static final Instruction IMPDEP2 = new Instruction(Constants.IMPDEP2); - - // You can use these constants in multiple places safely, any attempt to change the index - // for these constants will cause an exception - public static final InstructionLV THIS = new InstructionCLV(Constants.ALOAD,0); - public static final InstructionLV ALOAD_0 = new InstructionCLV(Constants.ALOAD_0); - public static final InstructionLV ALOAD_1 = new InstructionCLV(Constants.ALOAD_1); - public static final InstructionLV ALOAD_2 = new InstructionCLV(Constants.ALOAD_2); - public static final InstructionLV ALOAD_3 = new InstructionCLV(Constants.ALOAD_3); - public static final InstructionLV ILOAD_0 = new InstructionCLV(Constants.ILOAD_0); - public static final InstructionLV ILOAD_1 = new InstructionCLV(Constants.ILOAD_1); - public static final InstructionLV ILOAD_2 = new InstructionCLV(Constants.ILOAD_2); - public static final InstructionLV ILOAD_3 = new InstructionCLV(Constants.ILOAD_3); - public static final InstructionLV DLOAD_0 = new InstructionCLV(Constants.DLOAD_0); - public static final InstructionLV DLOAD_1 = new InstructionCLV(Constants.DLOAD_1); - public static final InstructionLV DLOAD_2 = new InstructionCLV(Constants.DLOAD_2); - public static final InstructionLV DLOAD_3 = new InstructionCLV(Constants.DLOAD_3); - public static final InstructionLV FLOAD_0 = new InstructionCLV(Constants.FLOAD_0); - public static final InstructionLV FLOAD_1 = new InstructionCLV(Constants.FLOAD_1); - public static final InstructionLV FLOAD_2 = new InstructionCLV(Constants.FLOAD_2); - public static final InstructionLV FLOAD_3 = new InstructionCLV(Constants.FLOAD_3); - public static final InstructionLV LLOAD_0 = new InstructionCLV(Constants.LLOAD_0); - public static final InstructionLV LLOAD_1 = new InstructionCLV(Constants.LLOAD_1); - public static final InstructionLV LLOAD_2 = new InstructionCLV(Constants.LLOAD_2); - public static final InstructionLV LLOAD_3 = new InstructionCLV(Constants.LLOAD_3); - public static final InstructionLV ASTORE_0 = new InstructionCLV(Constants.ASTORE_0); - public static final InstructionLV ASTORE_1 = new InstructionCLV(Constants.ASTORE_1); - public static final InstructionLV ASTORE_2 = new InstructionCLV(Constants.ASTORE_2); - public static final InstructionLV ASTORE_3 = new InstructionCLV(Constants.ASTORE_3); - public static final InstructionLV ISTORE_0 = new InstructionCLV(Constants.ISTORE_0); - public static final InstructionLV ISTORE_1 = new InstructionCLV(Constants.ISTORE_1); - public static final InstructionLV ISTORE_2 = new InstructionCLV(Constants.ISTORE_2); - public static final InstructionLV ISTORE_3 = new InstructionCLV(Constants.ISTORE_3); - public static final InstructionLV LSTORE_0 = new InstructionCLV(Constants.LSTORE_0); - public static final InstructionLV LSTORE_1 = new InstructionCLV(Constants.LSTORE_1); - public static final InstructionLV LSTORE_2 = new InstructionCLV(Constants.LSTORE_2); - public static final InstructionLV LSTORE_3 = new InstructionCLV(Constants.LSTORE_3); - public static final InstructionLV FSTORE_0 = new InstructionCLV(Constants.FSTORE_0); - public static final InstructionLV FSTORE_1 = new InstructionCLV(Constants.FSTORE_1); - public static final InstructionLV FSTORE_2 = new InstructionCLV(Constants.FSTORE_2); - public static final InstructionLV FSTORE_3 = new InstructionCLV(Constants.FSTORE_3); - public static final InstructionLV DSTORE_0 = new InstructionCLV(Constants.DSTORE_0); - public static final InstructionLV DSTORE_1 = new InstructionCLV(Constants.DSTORE_1); - public static final InstructionLV DSTORE_2 = new InstructionCLV(Constants.DSTORE_2); - public static final InstructionLV DSTORE_3 = new InstructionCLV(Constants.DSTORE_3); - - - /** Get object via its opcode, for immutable instructions like - * branch instructions entries are set to null. - */ - public static final Instruction[] INSTRUCTIONS = new Instruction[256]; - - /** Interfaces may have no static initializers, so we simulate this - * with an inner class. - */ - static final Clinit bla = new Clinit(); - - static class Clinit { - Clinit() { - INSTRUCTIONS[Constants.NOP] = NOP; - INSTRUCTIONS[Constants.ACONST_NULL] = ACONST_NULL; - INSTRUCTIONS[Constants.ICONST_M1] = ICONST_M1; - INSTRUCTIONS[Constants.ICONST_0] = ICONST_0; - INSTRUCTIONS[Constants.ICONST_1] = ICONST_1; - INSTRUCTIONS[Constants.ICONST_2] = ICONST_2; - INSTRUCTIONS[Constants.ICONST_3] = ICONST_3; - INSTRUCTIONS[Constants.ICONST_4] = ICONST_4; - INSTRUCTIONS[Constants.ICONST_5] = ICONST_5; - INSTRUCTIONS[Constants.LCONST_0] = LCONST_0; - INSTRUCTIONS[Constants.LCONST_1] = LCONST_1; - INSTRUCTIONS[Constants.FCONST_0] = FCONST_0; - INSTRUCTIONS[Constants.FCONST_1] = FCONST_1; - INSTRUCTIONS[Constants.FCONST_2] = FCONST_2; - INSTRUCTIONS[Constants.DCONST_0] = DCONST_0; - INSTRUCTIONS[Constants.DCONST_1] = DCONST_1; - INSTRUCTIONS[Constants.IALOAD] = IALOAD; - INSTRUCTIONS[Constants.LALOAD] = LALOAD; - INSTRUCTIONS[Constants.FALOAD] = FALOAD; - INSTRUCTIONS[Constants.DALOAD] = DALOAD; - INSTRUCTIONS[Constants.AALOAD] = AALOAD; - INSTRUCTIONS[Constants.BALOAD] = BALOAD; - INSTRUCTIONS[Constants.CALOAD] = CALOAD; - INSTRUCTIONS[Constants.SALOAD] = SALOAD; - INSTRUCTIONS[Constants.IASTORE] = IASTORE; - INSTRUCTIONS[Constants.LASTORE] = LASTORE; - INSTRUCTIONS[Constants.FASTORE] = FASTORE; - INSTRUCTIONS[Constants.DASTORE] = DASTORE; - INSTRUCTIONS[Constants.AASTORE] = AASTORE; - INSTRUCTIONS[Constants.BASTORE] = BASTORE; - INSTRUCTIONS[Constants.CASTORE] = CASTORE; - INSTRUCTIONS[Constants.SASTORE] = SASTORE; - INSTRUCTIONS[Constants.POP] = POP; - INSTRUCTIONS[Constants.POP2] = POP2; - INSTRUCTIONS[Constants.DUP] = DUP; - INSTRUCTIONS[Constants.DUP_X1] = DUP_X1; - INSTRUCTIONS[Constants.DUP_X2] = DUP_X2; - INSTRUCTIONS[Constants.DUP2] = DUP2; - INSTRUCTIONS[Constants.DUP2_X1] = DUP2_X1; - INSTRUCTIONS[Constants.DUP2_X2] = DUP2_X2; - INSTRUCTIONS[Constants.SWAP] = SWAP; - INSTRUCTIONS[Constants.IADD] = IADD; - INSTRUCTIONS[Constants.LADD] = LADD; - INSTRUCTIONS[Constants.FADD] = FADD; - INSTRUCTIONS[Constants.DADD] = DADD; - INSTRUCTIONS[Constants.ISUB] = ISUB; - INSTRUCTIONS[Constants.LSUB] = LSUB; - INSTRUCTIONS[Constants.FSUB] = FSUB; - INSTRUCTIONS[Constants.DSUB] = DSUB; - INSTRUCTIONS[Constants.IMUL] = IMUL; - INSTRUCTIONS[Constants.LMUL] = LMUL; - INSTRUCTIONS[Constants.FMUL] = FMUL; - INSTRUCTIONS[Constants.DMUL] = DMUL; - INSTRUCTIONS[Constants.IDIV] = IDIV; - INSTRUCTIONS[Constants.LDIV] = LDIV; - INSTRUCTIONS[Constants.FDIV] = FDIV; - INSTRUCTIONS[Constants.DDIV] = DDIV; - INSTRUCTIONS[Constants.IREM] = IREM; - INSTRUCTIONS[Constants.LREM] = LREM; - INSTRUCTIONS[Constants.FREM] = FREM; - INSTRUCTIONS[Constants.DREM] = DREM; - INSTRUCTIONS[Constants.INEG] = INEG; - INSTRUCTIONS[Constants.LNEG] = LNEG; - INSTRUCTIONS[Constants.FNEG] = FNEG; - INSTRUCTIONS[Constants.DNEG] = DNEG; - INSTRUCTIONS[Constants.ISHL] = ISHL; - INSTRUCTIONS[Constants.LSHL] = LSHL; - INSTRUCTIONS[Constants.ISHR] = ISHR; - INSTRUCTIONS[Constants.LSHR] = LSHR; - INSTRUCTIONS[Constants.IUSHR] = IUSHR; - INSTRUCTIONS[Constants.LUSHR] = LUSHR; - INSTRUCTIONS[Constants.IAND] = IAND; - INSTRUCTIONS[Constants.LAND] = LAND; - INSTRUCTIONS[Constants.IOR] = IOR; - INSTRUCTIONS[Constants.LOR] = LOR; - INSTRUCTIONS[Constants.IXOR] = IXOR; - INSTRUCTIONS[Constants.LXOR] = LXOR; - INSTRUCTIONS[Constants.I2L] = I2L; - INSTRUCTIONS[Constants.I2F] = I2F; - INSTRUCTIONS[Constants.I2D] = I2D; - INSTRUCTIONS[Constants.L2I] = L2I; - INSTRUCTIONS[Constants.L2F] = L2F; - INSTRUCTIONS[Constants.L2D] = L2D; - INSTRUCTIONS[Constants.F2I] = F2I; - INSTRUCTIONS[Constants.F2L] = F2L; - INSTRUCTIONS[Constants.F2D] = F2D; - INSTRUCTIONS[Constants.D2I] = D2I; - INSTRUCTIONS[Constants.D2L] = D2L; - INSTRUCTIONS[Constants.D2F] = D2F; - INSTRUCTIONS[Constants.I2B] = I2B; - INSTRUCTIONS[Constants.I2C] = I2C; - INSTRUCTIONS[Constants.I2S] = I2S; - INSTRUCTIONS[Constants.LCMP] = LCMP; - INSTRUCTIONS[Constants.FCMPL] = FCMPL; - INSTRUCTIONS[Constants.FCMPG] = FCMPG; - INSTRUCTIONS[Constants.DCMPL] = DCMPL; - INSTRUCTIONS[Constants.DCMPG] = DCMPG; - INSTRUCTIONS[Constants.IRETURN] = IRETURN; - INSTRUCTIONS[Constants.LRETURN] = LRETURN; - INSTRUCTIONS[Constants.FRETURN] = FRETURN; - INSTRUCTIONS[Constants.DRETURN] = DRETURN; - INSTRUCTIONS[Constants.ARETURN] = ARETURN; - INSTRUCTIONS[Constants.RETURN] = RETURN; - INSTRUCTIONS[Constants.ARRAYLENGTH] = ARRAYLENGTH; - INSTRUCTIONS[Constants.ATHROW] = ATHROW; - INSTRUCTIONS[Constants.MONITORENTER] = MONITORENTER; - INSTRUCTIONS[Constants.MONITOREXIT] = MONITOREXIT; - INSTRUCTIONS[Constants.IMPDEP1] = IMPDEP1; - INSTRUCTIONS[Constants.IMPDEP2] = IMPDEP2; -// INSTRUCTIONS[Constants.ALOAD_0] = ALOAD_0;INSTRUCTIONS[Constants.ALOAD_1] = ALOAD_1; -// INSTRUCTIONS[Constants.ALOAD_2] = ALOAD_2;INSTRUCTIONS[Constants.ALOAD_3] = ALOAD_3; -// INSTRUCTIONS[Constants.LLOAD_0] = LLOAD_0;INSTRUCTIONS[Constants.LLOAD_1] = LLOAD_1; -// INSTRUCTIONS[Constants.LLOAD_2] = LLOAD_2;INSTRUCTIONS[Constants.LLOAD_3] = LLOAD_3; -// INSTRUCTIONS[Constants.DLOAD_0] = DLOAD_0;INSTRUCTIONS[Constants.DLOAD_1] = DLOAD_1; -// INSTRUCTIONS[Constants.DLOAD_2] = DLOAD_2;INSTRUCTIONS[Constants.DLOAD_3] = DLOAD_3; -// INSTRUCTIONS[Constants.FLOAD_0] = FLOAD_0;INSTRUCTIONS[Constants.FLOAD_1] = FLOAD_1; -// INSTRUCTIONS[Constants.FLOAD_2] = FLOAD_2;INSTRUCTIONS[Constants.FLOAD_3] = FLOAD_3; -// INSTRUCTIONS[Constants.ILOAD_0] = ILOAD_0;INSTRUCTIONS[Constants.ILOAD_1] = ILOAD_1; -// INSTRUCTIONS[Constants.ILOAD_2] = ILOAD_2;INSTRUCTIONS[Constants.ILOAD_3] = ILOAD_3; - } - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; + +/** + * This interface contains shareable instruction objects. + * + * In order to save memory you can use some instructions multiply, + * since they have an immutable state and are directly derived from + * Instruction. I.e. they have no instance fields that could be + * changed. Since some of these instructions like ICONST_0 occur + * very frequently this can save a lot of time and space. This + * feature is an adaptation of the FlyWeight design pattern, we + * just use an array instead of a factory. + * + * The Instructions can also accessed directly under their names, so + * it's possible to write il.append(Instruction.ICONST_0); + * + * @version $Id: InstructionConstants.java,v 1.2.10.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public interface InstructionConstants { + /** Predefined instruction objects + */ + public static final Instruction NOP = new Instruction(Constants.NOP); + public static final Instruction ACONST_NULL = new Instruction(Constants.ACONST_NULL); + public static final Instruction ICONST_M1 = new Instruction(Constants.ICONST_M1); + public static final Instruction ICONST_0 = new Instruction(Constants.ICONST_0); + public static final Instruction ICONST_1 = new Instruction(Constants.ICONST_1); + public static final Instruction ICONST_2 = new Instruction(Constants.ICONST_2); + public static final Instruction ICONST_3 = new Instruction(Constants.ICONST_3); + public static final Instruction ICONST_4 = new Instruction(Constants.ICONST_4); + public static final Instruction ICONST_5 = new Instruction(Constants.ICONST_5); + public static final Instruction LCONST_0 = new Instruction(Constants.LCONST_0); + public static final Instruction LCONST_1 = new Instruction(Constants.LCONST_1); + public static final Instruction FCONST_0 = new Instruction(Constants.FCONST_0); + public static final Instruction FCONST_1 = new Instruction(Constants.FCONST_1); + public static final Instruction FCONST_2 = new Instruction(Constants.FCONST_2); + public static final Instruction DCONST_0 = new Instruction(Constants.DCONST_0); + public static final Instruction DCONST_1 = new Instruction(Constants.DCONST_1); + public static final Instruction IALOAD = new Instruction(Constants.IALOAD); + public static final Instruction LALOAD = new Instruction(Constants.LALOAD); + public static final Instruction FALOAD = new Instruction(Constants.FALOAD); + public static final Instruction DALOAD = new Instruction(Constants.DALOAD); + public static final Instruction AALOAD = new Instruction(Constants.AALOAD); + public static final Instruction BALOAD = new Instruction(Constants.BALOAD); + public static final Instruction CALOAD = new Instruction(Constants.CALOAD); + public static final Instruction SALOAD = new Instruction(Constants.SALOAD); + public static final Instruction IASTORE = new Instruction(Constants.IASTORE); + public static final Instruction LASTORE = new Instruction(Constants.LASTORE); + public static final Instruction FASTORE = new Instruction(Constants.FASTORE); + public static final Instruction DASTORE = new Instruction(Constants.DASTORE); + public static final Instruction AASTORE = new Instruction(Constants.AASTORE); + public static final Instruction BASTORE = new Instruction(Constants.BASTORE); + public static final Instruction CASTORE = new Instruction(Constants.CASTORE); + public static final Instruction SASTORE = new Instruction(Constants.SASTORE); + public static final Instruction POP = new Instruction(Constants.POP); + public static final Instruction POP2 = new Instruction(Constants.POP2); + public static final Instruction DUP = new Instruction(Constants.DUP); + public static final Instruction DUP_X1 = new Instruction(Constants.DUP_X1); + public static final Instruction DUP_X2 = new Instruction(Constants.DUP_X2); + public static final Instruction DUP2 = new Instruction(Constants.DUP2); + public static final Instruction DUP2_X1 = new Instruction(Constants.DUP2_X1); + public static final Instruction DUP2_X2 = new Instruction(Constants.DUP2_X2); + public static final Instruction SWAP = new Instruction(Constants.SWAP); + public static final Instruction IADD = new Instruction(Constants.IADD); + public static final Instruction LADD = new Instruction(Constants.LADD); + public static final Instruction FADD = new Instruction(Constants.FADD); + public static final Instruction DADD = new Instruction(Constants.DADD); + public static final Instruction ISUB = new Instruction(Constants.ISUB); + public static final Instruction LSUB = new Instruction(Constants.LSUB); + public static final Instruction FSUB = new Instruction(Constants.FSUB); + public static final Instruction DSUB = new Instruction(Constants.DSUB); + public static final Instruction IMUL = new Instruction(Constants.IMUL); + public static final Instruction LMUL = new Instruction(Constants.LMUL); + public static final Instruction FMUL = new Instruction(Constants.FMUL); + public static final Instruction DMUL = new Instruction(Constants.DMUL); + public static final Instruction IDIV = new Instruction(Constants.IDIV); + public static final Instruction LDIV = new Instruction(Constants.LDIV); + public static final Instruction FDIV = new Instruction(Constants.FDIV); + public static final Instruction DDIV = new Instruction(Constants.DDIV); + public static final Instruction IREM = new Instruction(Constants.IREM); + public static final Instruction LREM = new Instruction(Constants.LREM); + public static final Instruction FREM = new Instruction(Constants.FREM); + public static final Instruction DREM = new Instruction(Constants.DREM); + public static final Instruction INEG = new Instruction(Constants.INEG); + public static final Instruction LNEG = new Instruction(Constants.LNEG); + public static final Instruction FNEG = new Instruction(Constants.FNEG); + public static final Instruction DNEG = new Instruction(Constants.DNEG); + public static final Instruction ISHL = new Instruction(Constants.ISHL); + public static final Instruction LSHL = new Instruction(Constants.LSHL); + public static final Instruction ISHR = new Instruction(Constants.ISHR); + public static final Instruction LSHR = new Instruction(Constants.LSHR); + public static final Instruction IUSHR = new Instruction(Constants.IUSHR); + public static final Instruction LUSHR = new Instruction(Constants.LUSHR); + public static final Instruction IAND = new Instruction(Constants.IAND); + public static final Instruction LAND = new Instruction(Constants.LAND); + public static final Instruction IOR = new Instruction(Constants.IOR); + public static final Instruction LOR = new Instruction(Constants.LOR); + public static final Instruction IXOR = new Instruction(Constants.IXOR); + public static final Instruction LXOR = new Instruction(Constants.LXOR); + public static final Instruction I2L = new Instruction(Constants.I2L); + public static final Instruction I2F = new Instruction(Constants.I2F); + public static final Instruction I2D = new Instruction(Constants.I2D); + public static final Instruction L2I = new Instruction(Constants.L2I); + public static final Instruction L2F = new Instruction(Constants.L2F); + public static final Instruction L2D = new Instruction(Constants.L2D); + public static final Instruction F2I = new Instruction(Constants.F2I); + public static final Instruction F2L = new Instruction(Constants.F2L); + public static final Instruction F2D = new Instruction(Constants.F2D); + public static final Instruction D2I = new Instruction(Constants.D2I); + public static final Instruction D2L = new Instruction(Constants.D2L); + public static final Instruction D2F = new Instruction(Constants.D2F); + public static final Instruction I2B = new Instruction(Constants.I2B); + public static final Instruction I2C = new Instruction(Constants.I2C); + public static final Instruction I2S = new Instruction(Constants.I2S); + public static final Instruction LCMP = new Instruction(Constants.LCMP); + public static final Instruction FCMPL = new Instruction(Constants.FCMPL); + public static final Instruction FCMPG = new Instruction(Constants.FCMPG); + public static final Instruction DCMPL = new Instruction(Constants.DCMPL); + public static final Instruction DCMPG = new Instruction(Constants.DCMPG); + public static final Instruction IRETURN = new Instruction(Constants.IRETURN); + public static final Instruction LRETURN = new Instruction(Constants.LRETURN); + public static final Instruction FRETURN = new Instruction(Constants.FRETURN); + public static final Instruction DRETURN = new Instruction(Constants.DRETURN); + public static final Instruction ARETURN = new Instruction(Constants.ARETURN); + public static final Instruction RETURN = new Instruction(Constants.RETURN); + public static final Instruction ARRAYLENGTH = new Instruction(Constants.ARRAYLENGTH); + public static final Instruction ATHROW = new Instruction(Constants.ATHROW); + public static final Instruction MONITORENTER = new Instruction(Constants.MONITORENTER); + public static final Instruction MONITOREXIT = new Instruction(Constants.MONITOREXIT); + public static final Instruction IMPDEP1 = new Instruction(Constants.IMPDEP1); + public static final Instruction IMPDEP2 = new Instruction(Constants.IMPDEP2); + + // You can use these constants in multiple places safely, any attempt to change the index + // for these constants will cause an exception + public static final InstructionLV THIS = new InstructionCLV(Constants.ALOAD,0); + public static final InstructionLV ALOAD_0 = new InstructionCLV(Constants.ALOAD_0); + public static final InstructionLV ALOAD_1 = new InstructionCLV(Constants.ALOAD_1); + public static final InstructionLV ALOAD_2 = new InstructionCLV(Constants.ALOAD_2); + public static final InstructionLV ALOAD_3 = new InstructionCLV(Constants.ALOAD_3); + public static final InstructionLV ILOAD_0 = new InstructionCLV(Constants.ILOAD_0); + public static final InstructionLV ILOAD_1 = new InstructionCLV(Constants.ILOAD_1); + public static final InstructionLV ILOAD_2 = new InstructionCLV(Constants.ILOAD_2); + public static final InstructionLV ILOAD_3 = new InstructionCLV(Constants.ILOAD_3); + public static final InstructionLV DLOAD_0 = new InstructionCLV(Constants.DLOAD_0); + public static final InstructionLV DLOAD_1 = new InstructionCLV(Constants.DLOAD_1); + public static final InstructionLV DLOAD_2 = new InstructionCLV(Constants.DLOAD_2); + public static final InstructionLV DLOAD_3 = new InstructionCLV(Constants.DLOAD_3); + public static final InstructionLV FLOAD_0 = new InstructionCLV(Constants.FLOAD_0); + public static final InstructionLV FLOAD_1 = new InstructionCLV(Constants.FLOAD_1); + public static final InstructionLV FLOAD_2 = new InstructionCLV(Constants.FLOAD_2); + public static final InstructionLV FLOAD_3 = new InstructionCLV(Constants.FLOAD_3); + public static final InstructionLV LLOAD_0 = new InstructionCLV(Constants.LLOAD_0); + public static final InstructionLV LLOAD_1 = new InstructionCLV(Constants.LLOAD_1); + public static final InstructionLV LLOAD_2 = new InstructionCLV(Constants.LLOAD_2); + public static final InstructionLV LLOAD_3 = new InstructionCLV(Constants.LLOAD_3); + public static final InstructionLV ASTORE_0 = new InstructionCLV(Constants.ASTORE_0); + public static final InstructionLV ASTORE_1 = new InstructionCLV(Constants.ASTORE_1); + public static final InstructionLV ASTORE_2 = new InstructionCLV(Constants.ASTORE_2); + public static final InstructionLV ASTORE_3 = new InstructionCLV(Constants.ASTORE_3); + public static final InstructionLV ISTORE_0 = new InstructionCLV(Constants.ISTORE_0); + public static final InstructionLV ISTORE_1 = new InstructionCLV(Constants.ISTORE_1); + public static final InstructionLV ISTORE_2 = new InstructionCLV(Constants.ISTORE_2); + public static final InstructionLV ISTORE_3 = new InstructionCLV(Constants.ISTORE_3); + public static final InstructionLV LSTORE_0 = new InstructionCLV(Constants.LSTORE_0); + public static final InstructionLV LSTORE_1 = new InstructionCLV(Constants.LSTORE_1); + public static final InstructionLV LSTORE_2 = new InstructionCLV(Constants.LSTORE_2); + public static final InstructionLV LSTORE_3 = new InstructionCLV(Constants.LSTORE_3); + public static final InstructionLV FSTORE_0 = new InstructionCLV(Constants.FSTORE_0); + public static final InstructionLV FSTORE_1 = new InstructionCLV(Constants.FSTORE_1); + public static final InstructionLV FSTORE_2 = new InstructionCLV(Constants.FSTORE_2); + public static final InstructionLV FSTORE_3 = new InstructionCLV(Constants.FSTORE_3); + public static final InstructionLV DSTORE_0 = new InstructionCLV(Constants.DSTORE_0); + public static final InstructionLV DSTORE_1 = new InstructionCLV(Constants.DSTORE_1); + public static final InstructionLV DSTORE_2 = new InstructionCLV(Constants.DSTORE_2); + public static final InstructionLV DSTORE_3 = new InstructionCLV(Constants.DSTORE_3); + + + /** Get object via its opcode, for immutable instructions like + * branch instructions entries are set to null. + */ + public static final Instruction[] INSTRUCTIONS = new Instruction[256]; + + /** Interfaces may have no static initializers, so we simulate this + * with an inner class. + */ + static final Clinit bla = new Clinit(); + + static class Clinit { + Clinit() { + INSTRUCTIONS[Constants.NOP] = NOP; + INSTRUCTIONS[Constants.ACONST_NULL] = ACONST_NULL; + INSTRUCTIONS[Constants.ICONST_M1] = ICONST_M1; + INSTRUCTIONS[Constants.ICONST_0] = ICONST_0; + INSTRUCTIONS[Constants.ICONST_1] = ICONST_1; + INSTRUCTIONS[Constants.ICONST_2] = ICONST_2; + INSTRUCTIONS[Constants.ICONST_3] = ICONST_3; + INSTRUCTIONS[Constants.ICONST_4] = ICONST_4; + INSTRUCTIONS[Constants.ICONST_5] = ICONST_5; + INSTRUCTIONS[Constants.LCONST_0] = LCONST_0; + INSTRUCTIONS[Constants.LCONST_1] = LCONST_1; + INSTRUCTIONS[Constants.FCONST_0] = FCONST_0; + INSTRUCTIONS[Constants.FCONST_1] = FCONST_1; + INSTRUCTIONS[Constants.FCONST_2] = FCONST_2; + INSTRUCTIONS[Constants.DCONST_0] = DCONST_0; + INSTRUCTIONS[Constants.DCONST_1] = DCONST_1; + INSTRUCTIONS[Constants.IALOAD] = IALOAD; + INSTRUCTIONS[Constants.LALOAD] = LALOAD; + INSTRUCTIONS[Constants.FALOAD] = FALOAD; + INSTRUCTIONS[Constants.DALOAD] = DALOAD; + INSTRUCTIONS[Constants.AALOAD] = AALOAD; + INSTRUCTIONS[Constants.BALOAD] = BALOAD; + INSTRUCTIONS[Constants.CALOAD] = CALOAD; + INSTRUCTIONS[Constants.SALOAD] = SALOAD; + INSTRUCTIONS[Constants.IASTORE] = IASTORE; + INSTRUCTIONS[Constants.LASTORE] = LASTORE; + INSTRUCTIONS[Constants.FASTORE] = FASTORE; + INSTRUCTIONS[Constants.DASTORE] = DASTORE; + INSTRUCTIONS[Constants.AASTORE] = AASTORE; + INSTRUCTIONS[Constants.BASTORE] = BASTORE; + INSTRUCTIONS[Constants.CASTORE] = CASTORE; + INSTRUCTIONS[Constants.SASTORE] = SASTORE; + INSTRUCTIONS[Constants.POP] = POP; + INSTRUCTIONS[Constants.POP2] = POP2; + INSTRUCTIONS[Constants.DUP] = DUP; + INSTRUCTIONS[Constants.DUP_X1] = DUP_X1; + INSTRUCTIONS[Constants.DUP_X2] = DUP_X2; + INSTRUCTIONS[Constants.DUP2] = DUP2; + INSTRUCTIONS[Constants.DUP2_X1] = DUP2_X1; + INSTRUCTIONS[Constants.DUP2_X2] = DUP2_X2; + INSTRUCTIONS[Constants.SWAP] = SWAP; + INSTRUCTIONS[Constants.IADD] = IADD; + INSTRUCTIONS[Constants.LADD] = LADD; + INSTRUCTIONS[Constants.FADD] = FADD; + INSTRUCTIONS[Constants.DADD] = DADD; + INSTRUCTIONS[Constants.ISUB] = ISUB; + INSTRUCTIONS[Constants.LSUB] = LSUB; + INSTRUCTIONS[Constants.FSUB] = FSUB; + INSTRUCTIONS[Constants.DSUB] = DSUB; + INSTRUCTIONS[Constants.IMUL] = IMUL; + INSTRUCTIONS[Constants.LMUL] = LMUL; + INSTRUCTIONS[Constants.FMUL] = FMUL; + INSTRUCTIONS[Constants.DMUL] = DMUL; + INSTRUCTIONS[Constants.IDIV] = IDIV; + INSTRUCTIONS[Constants.LDIV] = LDIV; + INSTRUCTIONS[Constants.FDIV] = FDIV; + INSTRUCTIONS[Constants.DDIV] = DDIV; + INSTRUCTIONS[Constants.IREM] = IREM; + INSTRUCTIONS[Constants.LREM] = LREM; + INSTRUCTIONS[Constants.FREM] = FREM; + INSTRUCTIONS[Constants.DREM] = DREM; + INSTRUCTIONS[Constants.INEG] = INEG; + INSTRUCTIONS[Constants.LNEG] = LNEG; + INSTRUCTIONS[Constants.FNEG] = FNEG; + INSTRUCTIONS[Constants.DNEG] = DNEG; + INSTRUCTIONS[Constants.ISHL] = ISHL; + INSTRUCTIONS[Constants.LSHL] = LSHL; + INSTRUCTIONS[Constants.ISHR] = ISHR; + INSTRUCTIONS[Constants.LSHR] = LSHR; + INSTRUCTIONS[Constants.IUSHR] = IUSHR; + INSTRUCTIONS[Constants.LUSHR] = LUSHR; + INSTRUCTIONS[Constants.IAND] = IAND; + INSTRUCTIONS[Constants.LAND] = LAND; + INSTRUCTIONS[Constants.IOR] = IOR; + INSTRUCTIONS[Constants.LOR] = LOR; + INSTRUCTIONS[Constants.IXOR] = IXOR; + INSTRUCTIONS[Constants.LXOR] = LXOR; + INSTRUCTIONS[Constants.I2L] = I2L; + INSTRUCTIONS[Constants.I2F] = I2F; + INSTRUCTIONS[Constants.I2D] = I2D; + INSTRUCTIONS[Constants.L2I] = L2I; + INSTRUCTIONS[Constants.L2F] = L2F; + INSTRUCTIONS[Constants.L2D] = L2D; + INSTRUCTIONS[Constants.F2I] = F2I; + INSTRUCTIONS[Constants.F2L] = F2L; + INSTRUCTIONS[Constants.F2D] = F2D; + INSTRUCTIONS[Constants.D2I] = D2I; + INSTRUCTIONS[Constants.D2L] = D2L; + INSTRUCTIONS[Constants.D2F] = D2F; + INSTRUCTIONS[Constants.I2B] = I2B; + INSTRUCTIONS[Constants.I2C] = I2C; + INSTRUCTIONS[Constants.I2S] = I2S; + INSTRUCTIONS[Constants.LCMP] = LCMP; + INSTRUCTIONS[Constants.FCMPL] = FCMPL; + INSTRUCTIONS[Constants.FCMPG] = FCMPG; + INSTRUCTIONS[Constants.DCMPL] = DCMPL; + INSTRUCTIONS[Constants.DCMPG] = DCMPG; + INSTRUCTIONS[Constants.IRETURN] = IRETURN; + INSTRUCTIONS[Constants.LRETURN] = LRETURN; + INSTRUCTIONS[Constants.FRETURN] = FRETURN; + INSTRUCTIONS[Constants.DRETURN] = DRETURN; + INSTRUCTIONS[Constants.ARETURN] = ARETURN; + INSTRUCTIONS[Constants.RETURN] = RETURN; + INSTRUCTIONS[Constants.ARRAYLENGTH] = ARRAYLENGTH; + INSTRUCTIONS[Constants.ATHROW] = ATHROW; + INSTRUCTIONS[Constants.MONITORENTER] = MONITORENTER; + INSTRUCTIONS[Constants.MONITOREXIT] = MONITOREXIT; + INSTRUCTIONS[Constants.IMPDEP1] = IMPDEP1; + INSTRUCTIONS[Constants.IMPDEP2] = IMPDEP2; +// INSTRUCTIONS[Constants.ALOAD_0] = ALOAD_0;INSTRUCTIONS[Constants.ALOAD_1] = ALOAD_1; +// INSTRUCTIONS[Constants.ALOAD_2] = ALOAD_2;INSTRUCTIONS[Constants.ALOAD_3] = ALOAD_3; +// INSTRUCTIONS[Constants.LLOAD_0] = LLOAD_0;INSTRUCTIONS[Constants.LLOAD_1] = LLOAD_1; +// INSTRUCTIONS[Constants.LLOAD_2] = LLOAD_2;INSTRUCTIONS[Constants.LLOAD_3] = LLOAD_3; +// INSTRUCTIONS[Constants.DLOAD_0] = DLOAD_0;INSTRUCTIONS[Constants.DLOAD_1] = DLOAD_1; +// INSTRUCTIONS[Constants.DLOAD_2] = DLOAD_2;INSTRUCTIONS[Constants.DLOAD_3] = DLOAD_3; +// INSTRUCTIONS[Constants.FLOAD_0] = FLOAD_0;INSTRUCTIONS[Constants.FLOAD_1] = FLOAD_1; +// INSTRUCTIONS[Constants.FLOAD_2] = FLOAD_2;INSTRUCTIONS[Constants.FLOAD_3] = FLOAD_3; +// INSTRUCTIONS[Constants.ILOAD_0] = ILOAD_0;INSTRUCTIONS[Constants.ILOAD_1] = ILOAD_1; +// INSTRUCTIONS[Constants.ILOAD_2] = ILOAD_2;INSTRUCTIONS[Constants.ILOAD_3] = ILOAD_3; + } + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionFactory.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionFactory.java index a8a13546b..08c27e46f 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionFactory.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionFactory.java @@ -1,777 +1,646 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.ConstantPool; -/** - * Instances of this class may be used, e.g., to generate typed - * versions of instructions. Its main purpose is to be used as the - * byte code generating backend of a compiler. You can subclass it to - * add your own create methods. - * - * @version $Id: InstructionFactory.java,v 1.3.10.2 2008/04/25 17:55:35 aclement Exp $ - * @author M. Dahm - * @see Constants - */ -public class InstructionFactory - implements InstructionConstants, java.io.Serializable -{ - protected ClassGen cg; - protected ConstantPool cp; - - public InstructionFactory(ClassGen cg, ConstantPool cp) { - this.cg = cg; - this.cp = cp; - } - - /** Initialize with ClassGen object - */ - public InstructionFactory(ClassGen cg) { - this(cg, cg.getConstantPool()); - } - - /** Initialize just with ConstantPool object - */ - public InstructionFactory(ConstantPool cp) { - this(null, cp); - } - - /** Create an invoke instruction. - * - * @param class_name name of the called class - * @param name name of the called method - * @param ret_type return type of method - * @param arg_types argument types of method - * @param kind how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, - * or INVOKESPECIAL - * @see Constants - */ - public InvokeInstruction createInvoke(String class_name, String name, Type ret_type, - Type[] arg_types, short kind) { - int index; - int nargs = 0; - String signature = Type.getMethodSignature(ret_type, arg_types); - - for(int i=0; i < arg_types.length; i++) // Count size of arguments - nargs += arg_types[i].getSize(); - - if(kind == Constants.INVOKEINTERFACE) - index = cp.addInterfaceMethodref(class_name, name, signature); - else - index = cp.addMethodref(class_name, name, signature); - - switch(kind) { - case Constants.INVOKESPECIAL: return new InvokeInstruction(Constants.INVOKESPECIAL,index); - case Constants.INVOKEVIRTUAL: return new InvokeInstruction(Constants.INVOKEVIRTUAL,index); - case Constants.INVOKESTATIC: return new InvokeInstruction(Constants.INVOKESTATIC,index); - case Constants.INVOKEINTERFACE: return new INVOKEINTERFACE(index, nargs + 1,0); - default: - throw new RuntimeException("Oops: Unknown invoke kind:" + kind); - } - } - - public static Instruction createALOAD(int n) { - if (n<4) { - switch (n) { - case 0: new InstructionLV(Constants.ALOAD_0); - case 1: new InstructionLV(Constants.ALOAD_0); - case 2: new InstructionLV(Constants.ALOAD_0); - case 3: new InstructionLV(Constants.ALOAD_0); - } - } - return new InstructionLV(Constants.ALOAD,n); - } - - public static Instruction createASTORE(int n) { - if (n<4) { - switch (n) { - case 0: new InstructionLV(Constants.ASTORE_0); - case 1: new InstructionLV(Constants.ASTORE_0); - case 2: new InstructionLV(Constants.ASTORE_0); - case 3: new InstructionLV(Constants.ASTORE_0); - } - } - return new InstructionLV(Constants.ASTORE,n); - } - - /** Create a call to the most popular System.out.println() method. - * - * @param s the string to print - */ - public InstructionList createPrintln(String s) { - InstructionList il = new InstructionList(); - int out = cp.addFieldref("java.lang.System", "out", - "Ljava/io/PrintStream;"); - int println = cp.addMethodref("java.io.PrintStream", "println", - "(Ljava/lang/String;)V"); - - il.append(new FieldInstruction(Constants.GETSTATIC,out)); - il.append(InstructionFactory.PUSH(cp, s)); - il.append(new InvokeInstruction(Constants.INVOKEVIRTUAL,println)); - - return il; - } - - /** Uses PUSH to push a constant value onto the stack. - * @param value must be of type Number, Boolean, Character or String - */ - public Instruction createConstant(Object value) { - Instruction instruction; - - if(value instanceof Number) - instruction = InstructionFactory.PUSH(cp, (Number)value); - else if(value instanceof String) - instruction = InstructionFactory.PUSH(cp, (String)value); - else if(value instanceof Boolean) - instruction = InstructionFactory.PUSH(cp, (Boolean)value); - else if(value instanceof Character) - instruction = InstructionFactory.PUSH(cp, (Character)value); - else if (value instanceof ObjectType) - instruction = InstructionFactory.PUSH(cp, (ObjectType)value); - else - throw new ClassGenException("Illegal type: " + value.getClass()); - - return instruction; - } - - private static class MethodObject { - Type[] arg_types; - Type result_type; - String[] arg_names; - String class_name; - String name; - int access; - - MethodObject(String c, String n, Type r, Type[] a, int acc) { - class_name = c; - name = n; - result_type = r; - arg_types = a; - access = acc; - } - } - - private InvokeInstruction createInvoke(MethodObject m, short kind) { - return createInvoke(m.class_name, m.name, m.result_type, m.arg_types, kind); - } - - private static MethodObject[] append_mos = { - new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, - new Type[] { Type.STRING }, Constants.ACC_PUBLIC), - new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, - new Type[] { Type.OBJECT }, Constants.ACC_PUBLIC), - null, null, // indices 2, 3 - new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, - new Type[] { Type.BOOLEAN }, Constants.ACC_PUBLIC), - new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, - new Type[] { Type.CHAR }, Constants.ACC_PUBLIC), - new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, - new Type[] { Type.FLOAT }, Constants.ACC_PUBLIC), - new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, - new Type[] { Type.DOUBLE }, Constants.ACC_PUBLIC), - new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, - new Type[] { Type.INT }, Constants.ACC_PUBLIC), - new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, // No append(byte) - new Type[] { Type.INT }, Constants.ACC_PUBLIC), - new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, // No append(short) - new Type[] { Type.INT }, Constants.ACC_PUBLIC), - new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, - new Type[] { Type.LONG }, Constants.ACC_PUBLIC) - }; - - private static final boolean isString(Type type) { - return ((type instanceof ObjectType) && - ((ObjectType)type).getClassName().equals("java.lang.String")); - } - - public Instruction createAppend(Type type) { - byte t = type.getType(); - - if(isString(type)) - return createInvoke(append_mos[0], Constants.INVOKEVIRTUAL); - - switch(t) { - case Constants.T_BOOLEAN: - case Constants.T_CHAR: - case Constants.T_FLOAT: - case Constants.T_DOUBLE: - case Constants.T_BYTE: - case Constants.T_SHORT: - case Constants.T_INT: - case Constants.T_LONG - : return createInvoke(append_mos[t], Constants.INVOKEVIRTUAL); - case Constants.T_ARRAY: - case Constants.T_OBJECT: - return createInvoke(append_mos[1], Constants.INVOKEVIRTUAL); - default: - throw new RuntimeException("Oops: No append for this type? " + type); - } - } - - /** Create a field instruction. - * - * @param class_name name of the accessed class - * @param name name of the referenced field - * @param type type of field - * @param kind how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC - * @see Constants - */ - public FieldInstruction createFieldAccess(String class_name, String name, Type type, short kind) { - int index; - String signature = type.getSignature(); - - index = cp.addFieldref(class_name, name, signature); - - switch(kind) { - case Constants.GETFIELD: return new FieldInstruction(Constants.GETFIELD,index); - case Constants.PUTFIELD: return new FieldInstruction(Constants.PUTFIELD,index); - case Constants.GETSTATIC: return new FieldInstruction(Constants.GETSTATIC,index); - case Constants.PUTSTATIC: return new FieldInstruction(Constants.PUTSTATIC,index); - - default: - throw new RuntimeException("Oops: Unknown getfield kind:" + kind); - } - } - - /** Create reference to `this' - */ - public static Instruction createThis() { - return new InstructionLV(Constants.ALOAD,0); - } - - /** Create typed return - */ - public static Instruction createReturn(Type type) { - switch(type.getType()) { - case Constants.T_ARRAY: - case Constants.T_OBJECT: return ARETURN; - case Constants.T_INT: - case Constants.T_SHORT: - case Constants.T_BOOLEAN: - case Constants.T_CHAR: - case Constants.T_BYTE: return IRETURN; - case Constants.T_FLOAT: return FRETURN; - case Constants.T_DOUBLE: return DRETURN; - case Constants.T_LONG: return LRETURN; - case Constants.T_VOID: return RETURN; - - default: - throw new RuntimeException("Invalid type: " + type); - } - } - - private static final Instruction createBinaryIntOp(char first, String op) { - switch(first) { - case '-' : return InstructionConstants.ISUB; - case '+' : return InstructionConstants.IADD; - case '%' : return InstructionConstants.IREM; - case '*' : return InstructionConstants.IMUL; - case '/' : return InstructionConstants.IDIV; - case '&' : return InstructionConstants.IAND; - case '|' : return InstructionConstants.IOR; - case '^' : return InstructionConstants.IXOR; - case '<' : return InstructionConstants.ISHL; - case '>' : return op.equals(">>>")? InstructionConstants.IUSHR : InstructionConstants.ISHR; - default: throw new RuntimeException("Invalid operand " + op); - } - } - - private static final Instruction createBinaryLongOp(char first, String op) { - switch(first) { - case '-' : return InstructionConstants.LSUB; - case '+' : return InstructionConstants.LADD; - case '%' : return InstructionConstants.LREM; - case '*' : return InstructionConstants.LMUL; - case '/' : return InstructionConstants.LDIV; - case '&' : return InstructionConstants.LAND; - case '|' : return InstructionConstants.LOR; - case '^' : return InstructionConstants.LXOR; - case '<' : return InstructionConstants.LSHL; - case '>' : return op.equals(">>>")? InstructionConstants.LUSHR : InstructionConstants.LSHR; - default: throw new RuntimeException("Invalid operand " + op); - } - } - - private static final Instruction createBinaryFloatOp(char op) { - switch(op) { - case '-' : return InstructionConstants.FSUB; - case '+' : return InstructionConstants.FADD; - case '*' : return InstructionConstants.FMUL; - case '/' : return FDIV; - default: throw new RuntimeException("Invalid operand " + op); - } - } - - private static final Instruction createBinaryDoubleOp(char op) { - switch(op) { - case '-' : return DSUB; - case '+' : return DADD; - case '*' : return DMUL; - case '/' : return DDIV; - default: throw new RuntimeException("Invalid operand " + op); - } - } - - /** - * Create binary operation for simple basic types, such as int and float. - * - * @param op operation, such as "+", "*", "<<", etc. - */ - public static Instruction createBinaryOperation(String op, Type type) { - char first = op.toCharArray()[0]; - - switch(type.getType()) { - case Constants.T_BYTE: - case Constants.T_SHORT: - case Constants.T_INT: - case Constants.T_CHAR: return createBinaryIntOp(first, op); - case Constants.T_LONG: return createBinaryLongOp(first, op); - case Constants.T_FLOAT: return createBinaryFloatOp(first); - case Constants.T_DOUBLE: return createBinaryDoubleOp(first); - default: throw new RuntimeException("Invalid type " + type); - } - } - - /** - * @param size size of operand, either 1 (int, e.g.) or 2 (double) - */ - public static Instruction createPop(int size) { - return (size == 2)? POP2 : POP; - } - - /** - * @param size size of operand, either 1 (int, e.g.) or 2 (double) - */ - public static Instruction createDup(int size) { - return (size == 2)? DUP2:DUP; - } - - /** - * @param size size of operand, either 1 (int, e.g.) or 2 (double) - */ - public static Instruction createDup_2(int size) { - return (size == 2)? DUP2_X2 :DUP_X2; - } - - /** - * @param size size of operand, either 1 (int, e.g.) or 2 (double) - */ - public static Instruction createDup_1(int size) { - return (size == 2)? DUP2_X1 : DUP_X1; - } - - /** - * @param index index of local variable - */ - public static InstructionLV createStore(Type type, int index) { - switch(type.getType()) { - case Constants.T_BOOLEAN: - case Constants.T_CHAR: - case Constants.T_BYTE: - case Constants.T_SHORT: - case Constants.T_INT: return new InstructionLV(Constants.ISTORE,index); - case Constants.T_FLOAT: return new InstructionLV(Constants.FSTORE,index); - case Constants.T_DOUBLE: return new InstructionLV(Constants.DSTORE,index); - case Constants.T_LONG: return new InstructionLV(Constants.LSTORE,index); - case Constants.T_ARRAY: - case Constants.T_OBJECT: return new InstructionLV(Constants.ASTORE,index); - default: throw new RuntimeException("Invalid type " + type); - } - } - - /** - * @param index index of local variable - */ - public static InstructionLV createLoad(Type type, int index) { - switch(type.getType()) { - case Constants.T_BOOLEAN: - case Constants.T_CHAR: - case Constants.T_BYTE: - case Constants.T_SHORT: - case Constants.T_INT: return new InstructionLV(Constants.ILOAD,index); - case Constants.T_FLOAT: return new InstructionLV(Constants.FLOAD,index); - case Constants.T_DOUBLE: return new InstructionLV(Constants.DLOAD,index); - case Constants.T_LONG: return new InstructionLV(Constants.LLOAD,index); - case Constants.T_ARRAY: - case Constants.T_OBJECT: return new InstructionLV(Constants.ALOAD,index); - default: throw new RuntimeException("Invalid type " + type); - } - } - - /** - * @param type type of elements of array, i.e., array.getElementType() - */ - public static Instruction createArrayLoad(Type type) { - switch(type.getType()) { - case Constants.T_BOOLEAN: - case Constants.T_BYTE: return BALOAD; - case Constants.T_CHAR: return CALOAD; - case Constants.T_SHORT: return SALOAD; - case Constants.T_INT: return IALOAD; - case Constants.T_FLOAT: return FALOAD; - case Constants.T_DOUBLE: return DALOAD; - case Constants.T_LONG: return LALOAD; - case Constants.T_ARRAY: - case Constants.T_OBJECT: return AALOAD; - default: throw new RuntimeException("Invalid type " + type); - } - } - - /** - * @param type type of elements of array, i.e., array.getElementType() - */ - public static Instruction createArrayStore(Type type) { - switch(type.getType()) { - case Constants.T_BOOLEAN: - case Constants.T_BYTE: return BASTORE; - case Constants.T_CHAR: return CASTORE; - case Constants.T_SHORT: return SASTORE; - case Constants.T_INT: return IASTORE; - case Constants.T_FLOAT: return FASTORE; - case Constants.T_DOUBLE: return DASTORE; - case Constants.T_LONG: return LASTORE; - case Constants.T_ARRAY: - case Constants.T_OBJECT: return AASTORE; - default: throw new RuntimeException("Invalid type " + type); - } - } - - private static final char[] shortNames = { 'C', 'F', 'D', 'B', 'S', 'I', 'L' }; - /** Create conversion operation for two stack operands, this may be an I2C, instruction, e.g., - * if the operands are basic types and CHECKCAST if they are reference types. - */ - public Instruction createCast(Type src_type, Type dest_type) { - if((src_type instanceof BasicType) && (dest_type instanceof BasicType)) { - byte dest = dest_type.getType(); - byte src = src_type.getType(); - - if (dest == Constants.T_LONG && (src == Constants.T_CHAR || src == Constants.T_BYTE || src == Constants.T_SHORT)) - src = Constants.T_INT; - - if (src==Constants.T_DOUBLE) { - switch (dest) { - case Constants.T_FLOAT: return InstructionConstants.D2F; - case Constants.T_INT: return InstructionConstants.D2I; - case Constants.T_LONG: return InstructionConstants.D2L; - } - } else if (src==Constants.T_FLOAT) { - switch (dest) { - case Constants.T_DOUBLE: return InstructionConstants.F2D; - case Constants.T_INT: return InstructionConstants.F2I; - case Constants.T_LONG: return InstructionConstants.F2L; - } - } else if (src==Constants.T_INT) { - switch (dest) { - case Constants.T_BYTE: return InstructionConstants.I2B; - case Constants.T_CHAR: return InstructionConstants.I2C; - case Constants.T_DOUBLE: return InstructionConstants.I2D; - case Constants.T_FLOAT: return InstructionConstants.I2F; - case Constants.T_LONG: return InstructionConstants.I2L; - case Constants.T_SHORT: return InstructionConstants.I2S; - } - } else if (src==Constants.T_LONG) { - switch (dest) { - case Constants.T_DOUBLE: return InstructionConstants.L2D; - case Constants.T_FLOAT: return InstructionConstants.L2F; - case Constants.T_INT: return InstructionConstants.L2I; - } - } - -// String name = "org.aspectj.apache.bcel.generic." + short_names[src - Constants.T_CHAR] + -// "2" + short_names[dest - Constants.T_CHAR]; - -// Instruction i = null; -// try { -// i = (Instruction)java.lang.Class.forName(name).newInstance(); -// } catch(Exception e) { -// throw new RuntimeException("Could not find instruction: " + name); -// } - - return null; -// return i; - } else if((src_type instanceof ReferenceType) && (dest_type instanceof ReferenceType)) { - if(dest_type instanceof ArrayType) - return new InstructionCP(Constants.CHECKCAST,cp.addArrayClass((ArrayType)dest_type)); - else - return new InstructionCP(Constants.CHECKCAST,cp.addClass(((ObjectType)dest_type).getClassName())); - } - else - throw new RuntimeException("Can not cast " + src_type + " to " + dest_type); - } - - public FieldInstruction createGetField(String class_name, String name, Type t) { - return new FieldInstruction(Constants.GETFIELD,cp.addFieldref(class_name, name, t.getSignature())); - } - - public FieldInstruction createGetStatic(String class_name, String name, Type t) { - return new FieldInstruction(Constants.GETSTATIC,cp.addFieldref(class_name, name, t.getSignature())); - } - - public FieldInstruction createPutField(String class_name, String name, Type t) { - return new FieldInstruction(Constants.PUTFIELD,cp.addFieldref(class_name, name, t.getSignature())); - } - - public FieldInstruction createPutStatic(String class_name, String name, Type t) { - return new FieldInstruction(Constants.PUTSTATIC,cp.addFieldref(class_name, name, t.getSignature())); - } - - public Instruction createCheckCast(ReferenceType t) { - if(t instanceof ArrayType) - return new InstructionCP(Constants.CHECKCAST,cp.addArrayClass((ArrayType)t)); - else - return new InstructionCP(Constants.CHECKCAST,cp.addClass((ObjectType)t)); - } - - public Instruction createInstanceOf(ReferenceType t) { - if(t instanceof ArrayType) - return new InstructionCP(Constants.INSTANCEOF,cp.addArrayClass((ArrayType)t)); - else - return new InstructionCP(Constants.INSTANCEOF,cp.addClass((ObjectType)t)); - } - - public Instruction createNew(ObjectType t) { - return new InstructionCP(Constants.NEW,cp.addClass(t)); - } - - public Instruction createNew(String s) { - return createNew(new ObjectType(s)); - } - - /** Create new array of given size and type. - * @return an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction - */ - public Instruction createNewArray(Type t, short dim) { - if(dim == 1) { - if(t instanceof ObjectType) - return new InstructionCP(Constants.ANEWARRAY,cp.addClass((ObjectType)t)); - else if(t instanceof ArrayType) - return new InstructionCP(Constants.ANEWARRAY,cp.addArrayClass((ArrayType)t)); - else - return new InstructionByte(Constants.NEWARRAY,((BasicType)t).getType()); - } else { - ArrayType at; - - if(t instanceof ArrayType) - at = (ArrayType)t; - else - at = new ArrayType(t, dim); - - return new MULTIANEWARRAY(cp.addArrayClass(at), dim); - } - } - - /** Create "null" value for reference types, 0 for basic types like int - */ - public static Instruction createNull(Type type) { - switch(type.getType()) { - case Constants.T_ARRAY: - case Constants.T_OBJECT: return ACONST_NULL; - case Constants.T_INT: - case Constants.T_SHORT: - case Constants.T_BOOLEAN: - case Constants.T_CHAR: - case Constants.T_BYTE: return ICONST_0; - case Constants.T_FLOAT: return FCONST_0; - case Constants.T_DOUBLE: return DCONST_0; - case Constants.T_LONG: return LCONST_0; - case Constants.T_VOID: return NOP; - - default: - throw new RuntimeException("Invalid type: " + type); - } - } - - /** Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH. - * For those you should use the SWITCH compound instruction. - */ - public static InstructionBranch createBranchInstruction(short opcode, InstructionHandle target) { - switch(opcode) { - case Constants.IFEQ: return new InstructionBranch(Constants.IFEQ,target); - case Constants.IFNE: return new InstructionBranch(Constants.IFNE,target); - case Constants.IFLT: return new InstructionBranch(Constants.IFLT,target); - case Constants.IFGE: return new InstructionBranch(Constants.IFGE,target); - case Constants.IFGT: return new InstructionBranch(Constants.IFGT,target); - case Constants.IFLE: return new InstructionBranch(Constants.IFLE,target); - case Constants.IF_ICMPEQ: return new InstructionBranch(Constants.IF_ICMPEQ,target); - case Constants.IF_ICMPNE: return new InstructionBranch(Constants.IF_ICMPNE,target); - case Constants.IF_ICMPLT: return new InstructionBranch(Constants.IF_ICMPLT,target); - case Constants.IF_ICMPGE: return new InstructionBranch(Constants.IF_ICMPGE,target); - case Constants.IF_ICMPGT: return new InstructionBranch(Constants.IF_ICMPGT,target); - case Constants.IF_ICMPLE: return new InstructionBranch(Constants.IF_ICMPLE,target); - case Constants.IF_ACMPEQ: return new InstructionBranch(Constants.IF_ACMPEQ,target); - case Constants.IF_ACMPNE: return new InstructionBranch(Constants.IF_ACMPNE,target); - case Constants.GOTO: return new InstructionBranch(Constants.GOTO,target); - case Constants.JSR: return new InstructionBranch(Constants.JSR,target); - case Constants.IFNULL: return new InstructionBranch(Constants.IFNULL,target); - case Constants.IFNONNULL: return new InstructionBranch(Constants.IFNONNULL,target); - case Constants.GOTO_W: return new InstructionBranch(Constants.GOTO_W,target); - case Constants.JSR_W: return new InstructionBranch(Constants.JSR_W,target); - default: - throw new RuntimeException("Invalid opcode: " + opcode); - } - } - - public void setClassGen(ClassGen c) { cg = c; } - public ClassGen getClassGen() { return cg; } - public void setConstantPool(ConstantPool c) { cp = c; } - public ConstantPool getConstantPool() { return cp; } - - - /** - * Returns the right instruction for putting whatever you want onto the stack - */ - public static Instruction PUSH(ConstantPool cp, int value) { - Instruction instruction = null; - if((value >= -1) && (value <= 5)) // Use ICONST_n - instruction = INSTRUCTIONS[Constants.ICONST_0 + value]; - else if((value >= -128) && (value <= 127)) // Use BIPUSH - instruction = new InstructionByte(Constants.BIPUSH,(byte)value); - else if((value >= -32768) && (value <= 32767)) // Use SIPUSH - instruction = new InstructionShort(Constants.SIPUSH,(short)value); - else // If everything fails create a Constant pool entry - { - int pos = cp.addInteger(value); - if (pos<=Constants.MAX_BYTE) { - instruction = new InstructionCP(Constants.LDC,pos); - } else { - instruction = new InstructionCP(Constants.LDC_W,pos); - } - } - return instruction; - } - - public static Instruction PUSH(ConstantPool cp, ObjectType t) { - return new InstructionCP(Constants.LDC_W,cp.addClass(t)); - } - - public static Instruction PUSH(ConstantPool cp, boolean value) { - return INSTRUCTIONS[Constants.ICONST_0 + (value? 1 : 0)]; - } - - public static Instruction PUSH(ConstantPool cp, float value) { - Instruction instruction = null; - if(value == 0.0) - instruction = FCONST_0; - else if(value == 1.0) - instruction = FCONST_1; - else if(value == 2.0) - instruction = FCONST_2; - else { - // Create a Constant pool entry - int i = cp.addFloat(value); - instruction = new InstructionCP(i<=Constants.MAX_BYTE?Constants.LDC:Constants.LDC_W,i); - } - return instruction; - } - - public static Instruction PUSH(ConstantPool cp, long value) { - Instruction instruction = null; - if(value == 0) - instruction = LCONST_0; - else if(value == 1) - instruction = LCONST_1; - else // Create a Constant pool entry - instruction = new InstructionCP(Constants.LDC2_W,cp.addLong(value)); - return instruction; - } - - public static Instruction PUSH(ConstantPool cp, double value) { - Instruction instruction = null; - if(value == 0.0) - instruction = DCONST_0; - else if(value == 1.0) - instruction = DCONST_1; - else { - // Create a Constant pool entry - instruction = new InstructionCP(Constants.LDC2_W,cp.addDouble(value)); - } - return instruction; - } - - public static Instruction PUSH(ConstantPool cp, String value) { - Instruction instruction = null; - if(value == null) - instruction = ACONST_NULL; - else { - int i = cp.addString(value); - instruction = new InstructionCP(i<=Constants.MAX_BYTE?Constants.LDC:Constants.LDC_W,i); - } - return instruction; - } - - public static Instruction PUSH(ConstantPool cp, Number value) { - Instruction instruction = null; - if((value instanceof Integer) || (value instanceof Short) || (value instanceof Byte)) - instruction = PUSH(cp, value.intValue()); - else if(value instanceof Double) - instruction = PUSH(cp, value.doubleValue()); - else if(value instanceof Float) - instruction = PUSH(cp, value.floatValue()); - else if(value instanceof Long) - instruction = PUSH(cp, value.longValue()); - else - throw new ClassGenException("What's this: " + value); - return instruction; - } - - public static Instruction PUSH(ConstantPool cp, Character value) { - return PUSH(cp, (int)value.charValue()); - } - - public static Instruction PUSH(ConstantPool cp, Boolean value) { - return PUSH(cp, value.booleanValue()); - } - -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.ConstantPool; + +/** + * Instances of this class may be used, e.g., to generate typed + * versions of instructions. Its main purpose is to be used as the + * byte code generating backend of a compiler. You can subclass it to + * add your own create methods. + * + * @version $Id: InstructionFactory.java,v 1.3.10.3 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + * @see Constants + */ +public class InstructionFactory implements InstructionConstants, java.io.Serializable { + protected ClassGen cg; + protected ConstantPool cp; + + public InstructionFactory(ClassGen cg, ConstantPool cp) { + this.cg = cg; + this.cp = cp; + } + + public InstructionFactory(ClassGen cg) { + this(cg, cg.getConstantPool()); + } + + public InstructionFactory(ConstantPool cp) { + this(null, cp); + } + + /** Create an invoke instruction. + * @param class_name name of the called class + * @param name name of the called method + * @param ret_type return type of method + * @param arg_types argument types of method + * @param kind how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, + * or INVOKESPECIAL + * @see Constants + */ + public InvokeInstruction createInvoke(String class_name, String name, Type ret_type, + Type[] arg_types, short kind) { + + String signature = Type.getMethodSignature(ret_type, arg_types); + + int index; + if (kind == Constants.INVOKEINTERFACE) + index = cp.addInterfaceMethodref(class_name, name, signature); + else + index = cp.addMethodref(class_name, name, signature); + + switch(kind) { + case Constants.INVOKESPECIAL: return new InvokeInstruction(Constants.INVOKESPECIAL,index); + case Constants.INVOKEVIRTUAL: return new InvokeInstruction(Constants.INVOKEVIRTUAL,index); + case Constants.INVOKESTATIC: return new InvokeInstruction(Constants.INVOKESTATIC,index); + case Constants.INVOKEINTERFACE: + int nargs = 0; + for(int i=0; i < arg_types.length; i++) // Count size of arguments + nargs += arg_types[i].getSize(); + return new INVOKEINTERFACE(index, nargs + 1,0); + default: + throw new RuntimeException("Oops: Unknown invoke kind:" + kind); + } + } + + public InvokeInstruction createInvoke(String class_name, String name, String signature, short kind) { + int index; + if(kind == Constants.INVOKEINTERFACE) { + index = cp.addInterfaceMethodref(class_name, name, signature); + } else { + index = cp.addMethodref(class_name, name, signature); + } + + switch(kind) { + case Constants.INVOKESPECIAL: return new InvokeInstruction(Constants.INVOKESPECIAL,index); + case Constants.INVOKEVIRTUAL: return new InvokeInstruction(Constants.INVOKEVIRTUAL,index); + case Constants.INVOKESTATIC: return new InvokeInstruction(Constants.INVOKESTATIC,index); + case Constants.INVOKEINTERFACE: + Type[] argumentTypes = Type.getArgumentTypes(signature); + int nargs = 0; + for(int i=0; i < argumentTypes.length; i++) {// Count size of arguments + nargs += argumentTypes[i].getSize(); + } + return new INVOKEINTERFACE(index, nargs + 1,0); + default: + throw new RuntimeException("Oops: Unknown invoke kind:" + kind); + } + } + + public static Instruction createALOAD(int n) { + if (n<4) { + return new InstructionLV((short)(Constants.ALOAD_0+n)); + } + return new InstructionLV(Constants.ALOAD,n); + } + + public static Instruction createASTORE(int n) { + if (n<4) { + return new InstructionLV((short)(Constants.ASTORE_0+n)); + } + return new InstructionLV(Constants.ASTORE,n); + } + + + /** Uses PUSH to push a constant value onto the stack. + * @param value must be of type Number, Boolean, Character or String + */ + // OPTIMIZE callers should use the PUSH methods where possible if they know the types + public Instruction createConstant(Object value) { + Instruction instruction; + + if(value instanceof Number) + instruction = InstructionFactory.PUSH(cp, (Number)value); + else if(value instanceof String) + instruction = InstructionFactory.PUSH(cp, (String)value); + else if(value instanceof Boolean) + instruction = InstructionFactory.PUSH(cp, (Boolean)value); + else if(value instanceof Character) + instruction = InstructionFactory.PUSH(cp, (Character)value); + else if (value instanceof ObjectType) + instruction = InstructionFactory.PUSH(cp, (ObjectType)value); + else + throw new ClassGenException("Illegal type: " + value.getClass()); + + return instruction; + } + + private static class MethodObject { + Type[] arg_types; + Type result_type; + String[] arg_names; + String class_name; + String name; + int access; + + MethodObject(String c, String n, Type r, Type[] a, int acc) { + class_name = c; + name = n; + result_type = r; + arg_types = a; + access = acc; + } + } + + private InvokeInstruction createInvoke(MethodObject m, short kind) { + return createInvoke(m.class_name, m.name, m.result_type, m.arg_types, kind); + } + + + /** Create a field instruction. + * + * @param class_name name of the accessed class + * @param name name of the referenced field + * @param type type of field + * @param kind how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC + * @see Constants + */ + public FieldInstruction createFieldAccess(String class_name, String name, Type type, short kind) { + int index; + String signature = type.getSignature(); + + index = cp.addFieldref(class_name, name, signature); + + switch(kind) { + case Constants.GETFIELD: return new FieldInstruction(Constants.GETFIELD,index); + case Constants.PUTFIELD: return new FieldInstruction(Constants.PUTFIELD,index); + case Constants.GETSTATIC: return new FieldInstruction(Constants.GETSTATIC,index); + case Constants.PUTSTATIC: return new FieldInstruction(Constants.PUTSTATIC,index); + + default: + throw new RuntimeException("Oops: Unknown getfield kind:" + kind); + } + } + + /** Create reference to `this' + */ + public static Instruction createThis() { + return new InstructionLV(Constants.ALOAD,0); + } + + /** Create typed return + */ + public static Instruction createReturn(Type type) { + switch(type.getType()) { + case Constants.T_ARRAY: + case Constants.T_OBJECT: return ARETURN; + case Constants.T_INT: + case Constants.T_SHORT: + case Constants.T_BOOLEAN: + case Constants.T_CHAR: + case Constants.T_BYTE: return IRETURN; + case Constants.T_FLOAT: return FRETURN; + case Constants.T_DOUBLE: return DRETURN; + case Constants.T_LONG: return LRETURN; + case Constants.T_VOID: return RETURN; + + default: + throw new RuntimeException("Invalid type: " + type); + } + } + + /** + * @param size size of operand, either 1 (int, e.g.) or 2 (double) + */ + public static Instruction createPop(int size) { + return (size == 2)? POP2 : POP; + } + + /** + * @param size size of operand, either 1 (int, e.g.) or 2 (double) + */ + public static Instruction createDup(int size) { + return (size == 2)? DUP2:DUP; + } + + /** + * @param size size of operand, either 1 (int, e.g.) or 2 (double) + */ + public static Instruction createDup_2(int size) { + return (size == 2)? DUP2_X2 :DUP_X2; + } + + /** + * @param size size of operand, either 1 (int, e.g.) or 2 (double) + */ + public static Instruction createDup_1(int size) { + return (size == 2)? DUP2_X1 : DUP_X1; + } + + /** + * @param index index of local variable + */ + public static InstructionLV createStore(Type type, int index) { + switch(type.getType()) { + case Constants.T_BOOLEAN: + case Constants.T_CHAR: + case Constants.T_BYTE: + case Constants.T_SHORT: + case Constants.T_INT: return new InstructionLV(Constants.ISTORE,index); + case Constants.T_FLOAT: return new InstructionLV(Constants.FSTORE,index); + case Constants.T_DOUBLE: return new InstructionLV(Constants.DSTORE,index); + case Constants.T_LONG: return new InstructionLV(Constants.LSTORE,index); + case Constants.T_ARRAY: + case Constants.T_OBJECT: return new InstructionLV(Constants.ASTORE,index); + default: throw new RuntimeException("Invalid type " + type); + } + } + + /** + * @param index index of local variable + */ + public static InstructionLV createLoad(Type type, int index) { + switch(type.getType()) { + case Constants.T_BOOLEAN: + case Constants.T_CHAR: + case Constants.T_BYTE: + case Constants.T_SHORT: + case Constants.T_INT: return new InstructionLV(Constants.ILOAD,index); + case Constants.T_FLOAT: return new InstructionLV(Constants.FLOAD,index); + case Constants.T_DOUBLE: return new InstructionLV(Constants.DLOAD,index); + case Constants.T_LONG: return new InstructionLV(Constants.LLOAD,index); + case Constants.T_ARRAY: + case Constants.T_OBJECT: return new InstructionLV(Constants.ALOAD,index); + default: throw new RuntimeException("Invalid type " + type); + } + } + + /** + * @param type type of elements of array, i.e., array.getElementType() + */ + public static Instruction createArrayLoad(Type type) { + switch(type.getType()) { + case Constants.T_BOOLEAN: + case Constants.T_BYTE: return BALOAD; + case Constants.T_CHAR: return CALOAD; + case Constants.T_SHORT: return SALOAD; + case Constants.T_INT: return IALOAD; + case Constants.T_FLOAT: return FALOAD; + case Constants.T_DOUBLE: return DALOAD; + case Constants.T_LONG: return LALOAD; + case Constants.T_ARRAY: + case Constants.T_OBJECT: return AALOAD; + default: throw new RuntimeException("Invalid type " + type); + } + } + + /** + * @param type type of elements of array, i.e., array.getElementType() + */ + public static Instruction createArrayStore(Type type) { + switch(type.getType()) { + case Constants.T_BOOLEAN: + case Constants.T_BYTE: return BASTORE; + case Constants.T_CHAR: return CASTORE; + case Constants.T_SHORT: return SASTORE; + case Constants.T_INT: return IASTORE; + case Constants.T_FLOAT: return FASTORE; + case Constants.T_DOUBLE: return DASTORE; + case Constants.T_LONG: return LASTORE; + case Constants.T_ARRAY: + case Constants.T_OBJECT: return AASTORE; + default: throw new RuntimeException("Invalid type " + type); + } + } + + private static final char[] shortNames = { 'C', 'F', 'D', 'B', 'S', 'I', 'L' }; + /** Create conversion operation for two stack operands, this may be an I2C, instruction, e.g., + * if the operands are basic types and CHECKCAST if they are reference types. + */ + public Instruction createCast(Type src_type, Type dest_type) { + if((src_type instanceof BasicType) && (dest_type instanceof BasicType)) { + byte dest = dest_type.getType(); + byte src = src_type.getType(); + + if (dest == Constants.T_LONG && (src == Constants.T_CHAR || src == Constants.T_BYTE || src == Constants.T_SHORT)) + src = Constants.T_INT; + + if (src==Constants.T_DOUBLE) { + switch (dest) { + case Constants.T_FLOAT: return InstructionConstants.D2F; + case Constants.T_INT: return InstructionConstants.D2I; + case Constants.T_LONG: return InstructionConstants.D2L; + } + } else if (src==Constants.T_FLOAT) { + switch (dest) { + case Constants.T_DOUBLE: return InstructionConstants.F2D; + case Constants.T_INT: return InstructionConstants.F2I; + case Constants.T_LONG: return InstructionConstants.F2L; + } + } else if (src==Constants.T_INT) { + switch (dest) { + case Constants.T_BYTE: return InstructionConstants.I2B; + case Constants.T_CHAR: return InstructionConstants.I2C; + case Constants.T_DOUBLE: return InstructionConstants.I2D; + case Constants.T_FLOAT: return InstructionConstants.I2F; + case Constants.T_LONG: return InstructionConstants.I2L; + case Constants.T_SHORT: return InstructionConstants.I2S; + } + } else if (src==Constants.T_LONG) { + switch (dest) { + case Constants.T_DOUBLE: return InstructionConstants.L2D; + case Constants.T_FLOAT: return InstructionConstants.L2F; + case Constants.T_INT: return InstructionConstants.L2I; + } + } + +// String name = "org.aspectj.apache.bcel.generic." + short_names[src - Constants.T_CHAR] + +// "2" + short_names[dest - Constants.T_CHAR]; + +// Instruction i = null; +// try { +// i = (Instruction)java.lang.Class.forName(name).newInstance(); +// } catch(Exception e) { +// throw new RuntimeException("Could not find instruction: " + name); +// } + + return null; +// return i; + } else if((src_type instanceof ReferenceType) && (dest_type instanceof ReferenceType)) { + if(dest_type instanceof ArrayType) + return new InstructionCP(Constants.CHECKCAST,cp.addArrayClass((ArrayType)dest_type)); + else + return new InstructionCP(Constants.CHECKCAST,cp.addClass(((ObjectType)dest_type).getClassName())); + } + else + throw new RuntimeException("Can not cast " + src_type + " to " + dest_type); + } + + public FieldInstruction createGetField(String class_name, String name, Type t) { + return new FieldInstruction(Constants.GETFIELD,cp.addFieldref(class_name, name, t.getSignature())); + } + + public FieldInstruction createGetStatic(String class_name, String name, Type t) { + return new FieldInstruction(Constants.GETSTATIC,cp.addFieldref(class_name, name, t.getSignature())); + } + + public FieldInstruction createPutField(String class_name, String name, Type t) { + return new FieldInstruction(Constants.PUTFIELD,cp.addFieldref(class_name, name, t.getSignature())); + } + + public FieldInstruction createPutStatic(String class_name, String name, Type t) { + return new FieldInstruction(Constants.PUTSTATIC,cp.addFieldref(class_name, name, t.getSignature())); + } + + public Instruction createCheckCast(ReferenceType t) { + if(t instanceof ArrayType) + return new InstructionCP(Constants.CHECKCAST,cp.addArrayClass((ArrayType)t)); + else + return new InstructionCP(Constants.CHECKCAST,cp.addClass((ObjectType)t)); + } + + public Instruction createInstanceOf(ReferenceType t) { + if(t instanceof ArrayType) + return new InstructionCP(Constants.INSTANCEOF,cp.addArrayClass((ArrayType)t)); + else + return new InstructionCP(Constants.INSTANCEOF,cp.addClass((ObjectType)t)); + } + + public Instruction createNew(ObjectType t) { + return new InstructionCP(Constants.NEW,cp.addClass(t)); + } + + public Instruction createNew(String s) { + return createNew(new ObjectType(s)); + } + + /** Create new array of given size and type. + * @return an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction + */ + public Instruction createNewArray(Type t, short dim) { + if(dim == 1) { + if(t instanceof ObjectType) + return new InstructionCP(Constants.ANEWARRAY,cp.addClass((ObjectType)t)); + else if(t instanceof ArrayType) + return new InstructionCP(Constants.ANEWARRAY,cp.addArrayClass((ArrayType)t)); + else + return new InstructionByte(Constants.NEWARRAY,((BasicType)t).getType()); + } else { + ArrayType at; + + if(t instanceof ArrayType) + at = (ArrayType)t; + else + at = new ArrayType(t, dim); + + return new MULTIANEWARRAY(cp.addArrayClass(at), dim); + } + } + + /** Create "null" value for reference types, 0 for basic types like int + */ + public static Instruction createNull(Type type) { + switch(type.getType()) { + case Constants.T_ARRAY: + case Constants.T_OBJECT: return ACONST_NULL; + case Constants.T_INT: + case Constants.T_SHORT: + case Constants.T_BOOLEAN: + case Constants.T_CHAR: + case Constants.T_BYTE: return ICONST_0; + case Constants.T_FLOAT: return FCONST_0; + case Constants.T_DOUBLE: return DCONST_0; + case Constants.T_LONG: return LCONST_0; + case Constants.T_VOID: return NOP; + + default: + throw new RuntimeException("Invalid type: " + type); + } + } + + /** Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH. + * For those you should use the SWITCH compound instruction. + */ + public static InstructionBranch createBranchInstruction(short opcode, InstructionHandle target) { + switch(opcode) { + case Constants.IFEQ: return new InstructionBranch(Constants.IFEQ,target); + case Constants.IFNE: return new InstructionBranch(Constants.IFNE,target); + case Constants.IFLT: return new InstructionBranch(Constants.IFLT,target); + case Constants.IFGE: return new InstructionBranch(Constants.IFGE,target); + case Constants.IFGT: return new InstructionBranch(Constants.IFGT,target); + case Constants.IFLE: return new InstructionBranch(Constants.IFLE,target); + case Constants.IF_ICMPEQ: return new InstructionBranch(Constants.IF_ICMPEQ,target); + case Constants.IF_ICMPNE: return new InstructionBranch(Constants.IF_ICMPNE,target); + case Constants.IF_ICMPLT: return new InstructionBranch(Constants.IF_ICMPLT,target); + case Constants.IF_ICMPGE: return new InstructionBranch(Constants.IF_ICMPGE,target); + case Constants.IF_ICMPGT: return new InstructionBranch(Constants.IF_ICMPGT,target); + case Constants.IF_ICMPLE: return new InstructionBranch(Constants.IF_ICMPLE,target); + case Constants.IF_ACMPEQ: return new InstructionBranch(Constants.IF_ACMPEQ,target); + case Constants.IF_ACMPNE: return new InstructionBranch(Constants.IF_ACMPNE,target); + case Constants.GOTO: return new InstructionBranch(Constants.GOTO,target); + case Constants.JSR: return new InstructionBranch(Constants.JSR,target); + case Constants.IFNULL: return new InstructionBranch(Constants.IFNULL,target); + case Constants.IFNONNULL: return new InstructionBranch(Constants.IFNONNULL,target); + case Constants.GOTO_W: return new InstructionBranch(Constants.GOTO_W,target); + case Constants.JSR_W: return new InstructionBranch(Constants.JSR_W,target); + default: + throw new RuntimeException("Invalid opcode: " + opcode); + } + } + + public void setClassGen(ClassGen c) { cg = c; } + public ClassGen getClassGen() { return cg; } + public void setConstantPool(ConstantPool c) { cp = c; } + public ConstantPool getConstantPool() { return cp; } + + + /** + * Returns the right instruction for putting whatever you want onto the stack + */ + public static Instruction PUSH(ConstantPool cp, int value) { + Instruction instruction = null; + if ((value >= -1) && (value <= 5)) { + return INSTRUCTIONS[Constants.ICONST_0 + value]; + } else if ((value >= -128) && (value <= 127)) // Use BIPUSH + instruction = new InstructionByte(Constants.BIPUSH,(byte)value); + else if((value >= -32768) && (value <= 32767)) // Use SIPUSH + instruction = new InstructionShort(Constants.SIPUSH,(short)value); + else // If everything fails create a Constant pool entry + { + int pos = cp.addInteger(value); + if (pos<=Constants.MAX_BYTE) { + instruction = new InstructionCP(Constants.LDC,pos); + } else { + instruction = new InstructionCP(Constants.LDC_W,pos); + } + } + return instruction; + } + + public static Instruction PUSH(ConstantPool cp, ObjectType t) { + return new InstructionCP(Constants.LDC_W,cp.addClass(t)); + } + + public static Instruction PUSH(ConstantPool cp, boolean value) { + return INSTRUCTIONS[Constants.ICONST_0 + (value? 1 : 0)]; + } + + public static Instruction PUSH(ConstantPool cp, float value) { + Instruction instruction = null; + if(value == 0.0) + instruction = FCONST_0; + else if(value == 1.0) + instruction = FCONST_1; + else if(value == 2.0) + instruction = FCONST_2; + else { + // Create a Constant pool entry + int i = cp.addFloat(value); + instruction = new InstructionCP(i<=Constants.MAX_BYTE?Constants.LDC:Constants.LDC_W,i); + } + return instruction; + } + + public static Instruction PUSH(ConstantPool cp, long value) { + Instruction instruction = null; + if(value == 0) + instruction = LCONST_0; + else if(value == 1) + instruction = LCONST_1; + else // Create a Constant pool entry + instruction = new InstructionCP(Constants.LDC2_W,cp.addLong(value)); + return instruction; + } + + public static Instruction PUSH(ConstantPool cp, double value) { + Instruction instruction = null; + if(value == 0.0) + instruction = DCONST_0; + else if(value == 1.0) + instruction = DCONST_1; + else { + // Create a Constant pool entry + instruction = new InstructionCP(Constants.LDC2_W,cp.addDouble(value)); + } + return instruction; + } + + public static Instruction PUSH(ConstantPool cp, String value) { + Instruction instruction = null; + if(value == null) + instruction = ACONST_NULL; + else { + int i = cp.addString(value); + instruction = new InstructionCP(i<=Constants.MAX_BYTE?Constants.LDC:Constants.LDC_W,i); + } + return instruction; + } + + public static Instruction PUSH(ConstantPool cp, Number value) { + Instruction instruction = null; + if((value instanceof Integer) || (value instanceof Short) || (value instanceof Byte)) + instruction = PUSH(cp, value.intValue()); + else if(value instanceof Double) + instruction = PUSH(cp, value.doubleValue()); + else if(value instanceof Float) + instruction = PUSH(cp, value.floatValue()); + else if(value instanceof Long) + instruction = PUSH(cp, value.longValue()); + else + throw new ClassGenException("What's this: " + value); + return instruction; + } + + public static Instruction PUSH(ConstantPool cp, Character value) { + return PUSH(cp, (int)value.charValue()); + } + + public static Instruction PUSH(ConstantPool cp, Boolean value) { + return PUSH(cp, value.booleanValue()); + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionHandle.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionHandle.java index 6a4469cbf..472b87b37 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionHandle.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionHandle.java @@ -1,267 +1,229 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.classfile.Utility; -import java.util.HashSet; -import java.util.Collection; -import java.util.HashMap; - -/** - * Instances of this class give users a handle to the instructions contained in - * an InstructionList. Instruction objects may be used more than once within a - * list, this is useful because it saves memory and may be much faster. - * - * Within an InstructionList an InstructionHandle object is wrapped - * around all instructions, i.e., it implements a cell in a - * doubly-linked list. From the outside only the next and the - * previous instruction (handle) are accessible. One - * can traverse the list via an Enumeration returned by - * InstructionList.elements(). - * - * @version $Id: InstructionHandle.java,v 1.2.10.2 2008/04/25 17:55:35 aclement Exp $ - * @author M. Dahm - * @see Instruction - * @see BranchHandle - * @see InstructionList - */ -public class InstructionHandle implements java.io.Serializable { - InstructionHandle next, prev; // Will be set from the outside - Instruction instruction; - protected int i_position = -1; // byte code offset of instruction - private HashSet targeters; - private HashMap attributes; - - public final InstructionHandle getNext() { return next; } - public final InstructionHandle getPrev() { return prev; } - public final Instruction getInstruction() { return instruction; } - - /** - * Replace current instruction contained in this handle. - * Old instruction is disposed using Instruction.dispose(). - */ - public void setInstruction(Instruction i) { // Overridden in BranchHandle - if(i == null) - throw new ClassGenException("Assigning null to handle"); - - if((this.getClass() != BranchHandle.class) && (i instanceof InstructionBranch)) - throw new ClassGenException("Assigning branch instruction " + i + " to plain handle"); - - if(instruction != null) - instruction.dispose(); - - instruction = i; - } - - /** - * Temporarily swap the current instruction, without disturbing - * anything. Meant to be used by a debugger, implementing - * breakpoints. Current instruction is returned. - */ - public Instruction swapInstruction(Instruction i) { - Instruction oldInstruction = instruction; - instruction = i; - return oldInstruction; - } - - /*private*/ protected InstructionHandle(Instruction i) { - setInstruction(i); - } - - - /** Factory method. - */ - static final InstructionHandle getInstructionHandle(Instruction i) { - return new InstructionHandle(i); - } - - /** - * Called by InstructionList.setPositions when setting the position for every - * instruction. In the presence of variable length instructions `setPositions()' - * performs multiple passes over the instruction list to calculate the - * correct (byte) positions and offsets by calling this function. - * - * @param offset additional offset caused by preceding (variable length) instructions - * @param max_offset the maximum offset that may be caused by these instructions - * @return additional offset caused by possible change of this instruction's length - */ - protected int updatePosition(int offset, int max_offset) { - i_position += offset; - return 0; - } - - /** @return the position, i.e., the byte code offset of the contained - * instruction. This is accurate only after - * InstructionList.setPositions() has been called. - */ - public int getPosition() { return i_position; } - - /** Set the position, i.e., the byte code offset of the contained - * instruction. - */ - void setPosition(int pos) { i_position = pos; } - - - /** - * Delete contents, i.e., remove user access and make handle reusable. - */ - void dispose() { - next = prev = null; - instruction.dispose(); - instruction = null; - i_position = -1; - attributes = null; - removeAllTargeters(); - } - - /** Remove all targeters, if any. - */ - public void removeAllTargeters() { - if(targeters != null) - targeters.clear(); - } - - /** - * Denote this handle isn't referenced anymore by t. - */ - public void removeTargeter(InstructionTargeter t) { - targeters.remove(t); - } - - /** - * Denote this handle is being referenced by t. - */ - public void addTargeter(InstructionTargeter t) { - if(targeters == null) - targeters = new HashSet(); - - //if(!targeters.contains(t)) - targeters.add(t); - } - - public boolean hasTargeters() { - return (targeters != null) && (targeters.size() > 0); - } - - /** - * @return null, if there are no targeters - */ - public InstructionTargeter[] getTargeters() { - if(!hasTargeters()) - return null; - - InstructionTargeter[] t = new InstructionTargeter[targeters.size()]; - targeters.toArray(t); - return t; - } - - /** @return a (verbose) string representation of the contained instruction. - */ - public String toString(boolean verbose) { - return Utility.format(i_position, 4, false, ' ') + ": " + instruction.toString(verbose); - } - - /** @return a string representation of the contained instruction. - */ - public String toString() { - return toString(true); - } - - /** Add an attribute to an instruction handle. - * - * @param key the key object to store/retrieve the attribute - * @param attr the attribute to associate with this handle - */ - public void addAttribute(Object key, Object attr) { - if(attributes == null) - attributes = new HashMap(3); - - attributes.put(key, attr); - } - - /** Delete an attribute of an instruction handle. - * - * @param key the key object to retrieve the attribute - */ - public void removeAttribute(Object key) { - if(attributes != null) - attributes.remove(key); - } - - /** Get attribute of an instruction handle. - * - * @param key the key object to store/retrieve the attribute - */ - public Object getAttribute(Object key) { - if(attributes != null) - return attributes.get(key); - - return null; - } - - /** @return all attributes associated with this handle - */ - public Collection getAttributes() { - return attributes.values(); - } - - /** Convenience method, simply calls accept() on the contained instruction. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - instruction.accept(v); - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.classfile.Utility; +import java.util.HashSet; +import java.util.Collection; +import java.util.HashMap; + +/** + * Instances of this class give users a handle to the instructions contained in + * an InstructionList. Instruction objects may be used more than once within a + * list, this is useful because it saves memory and may be much faster. + * + * Within an InstructionList an InstructionHandle object is wrapped + * around all instructions, i.e., it implements a cell in a + * doubly-linked list. From the outside only the next and the + * previous instruction (handle) are accessible. One + * can traverse the list via an Enumeration returned by + * InstructionList.elements(). + * + * @version $Id: InstructionHandle.java,v 1.2.10.3 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + * @see Instruction + * @see BranchHandle + * @see InstructionList + */ +public class InstructionHandle implements java.io.Serializable { + InstructionHandle next, prev; // Will be set from the outside + Instruction instruction; + protected int i_position = -1; // byte code offset of instruction + private HashSet targeters; + + public final InstructionHandle getNext() { return next; } + public final InstructionHandle getPrev() { return prev; } + public final Instruction getInstruction() { return instruction; } + + /** + * Replace current instruction contained in this handle. + * Old instruction is disposed using Instruction.dispose(). + */ + public void setInstruction(Instruction i) { // Overridden in BranchHandle +// if(i == null) +// throw new ClassGenException("Assigning null to handle"); +// +// if((this.getClass() != BranchHandle.class) && (i instanceof InstructionBranch)) +// throw new ClassGenException("Assigning branch instruction " + i + " to plain handle"); + + if(instruction != null) + instruction.dispose(); + + instruction = i; + } + + /** + * Temporarily swap the current instruction, without disturbing + * anything. Meant to be used by a debugger, implementing + * breakpoints. Current instruction is returned. + */ + public Instruction swapInstruction(Instruction i) { + Instruction oldInstruction = instruction; + instruction = i; + return oldInstruction; + } + + /*private*/ protected InstructionHandle(Instruction i) { + setInstruction(i); + } + + + /** + * Factory method. + */ + static final InstructionHandle getInstructionHandle(Instruction i) { + return new InstructionHandle(i); + } + + /** + * Called by InstructionList.setPositions when setting the position for every + * instruction. In the presence of variable length instructions `setPositions()' + * performs multiple passes over the instruction list to calculate the + * correct (byte) positions and offsets by calling this function. + * + * @param offset additional offset caused by preceding (variable length) instructions + * @param max_offset the maximum offset that may be caused by these instructions + * @return additional offset caused by possible change of this instruction's length + */ + protected int updatePosition(int offset, int max_offset) { + i_position += offset; + return 0; + } + + /** @return the position, i.e., the byte code offset of the contained + * instruction. This is accurate only after + * InstructionList.setPositions() has been called. + */ + public int getPosition() { return i_position; } + + /** Set the position, i.e., the byte code offset of the contained + * instruction. + */ + void setPosition(int pos) { i_position = pos; } + + + /** + * Delete contents, i.e., remove user access and make handle reusable. + */ + // OPTIMIZE get rid of this? why do we need it + void dispose() { + next = prev = null; + instruction.dispose(); + instruction = null; + i_position = -1; + removeAllTargeters(); + } + + /** Remove all targeters, if any. + */ + public void removeAllTargeters() { + if(targeters != null) + targeters.clear(); + } + + /** + * Denote this handle isn't referenced anymore by t. + */ + public void removeTargeter(InstructionTargeter t) { + targeters.remove(t); + } + + /** + * Denote this handle is being referenced by t. + */ + public void addTargeter(InstructionTargeter t) { + if(targeters == null) + targeters = new HashSet(); + + //if(!targeters.contains(t)) + targeters.add(t); + } + + public boolean hasTargeters() { + return (targeters != null) && (targeters.size() > 0); + } + + /** + * @return null, if there are no targeters + */ + public InstructionTargeter[] getTargeters() { + if(!hasTargeters()) + return null; + + InstructionTargeter[] t = new InstructionTargeter[targeters.size()]; + targeters.toArray(t); + return t; + } + + /** @return a (verbose) string representation of the contained instruction. + */ + public String toString(boolean verbose) { + return Utility.format(i_position, 4, false, ' ') + ": " + instruction.toString(verbose); + } + + /** @return a string representation of the contained instruction. + */ + public String toString() { + return toString(true); + } + + /** Convenience method, simply calls accept() on the contained instruction. + * + * @param v Visitor object + */ + public void accept(InstVisitor v) { + instruction.accept(v); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionLV.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionLV.java index fa760708d..d9874bae9 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionLV.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionLV.java @@ -1,183 +1,183 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.DataOutputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.Constants; - -/** - * Abstract super class for instructions dealing with local variables. - * - * @version $Id: InstructionLV.java,v 1.1.2.2 2008/04/25 17:55:34 aclement Exp $ - * @author M. Dahm - */ -public class InstructionLV extends Instruction { - protected int lvar = -1; - - - public InstructionLV(short opcode, int lvar) { - this.opcode = opcode; - this.lvar = lvar; - } - - public InstructionLV(short opcode) { - this.opcode = opcode; - } - - public void dump(DataOutputStream out) throws IOException { - if (lvar==-1) { - out.writeByte(opcode); - } else { - if (lvar<4) { - if (opcode==ALOAD) { out.writeByte(ALOAD_0+lvar); - } else if (opcode==ASTORE) { out.writeByte(ASTORE_0+lvar); - } else if (opcode==ILOAD) { out.writeByte(ILOAD_0+lvar); - } else if (opcode==ISTORE) { out.writeByte(ISTORE_0+lvar); - } else if (opcode==DLOAD) { out.writeByte(DLOAD_0+lvar); - } else if (opcode==DSTORE) { out.writeByte(DSTORE_0+lvar); - } else if (opcode==FLOAD) { out.writeByte(FLOAD_0+lvar); - } else if (opcode==FSTORE) { out.writeByte(FSTORE_0+lvar); - } else if (opcode==LLOAD) { out.writeByte(LLOAD_0+lvar); - } else if (opcode==LSTORE) { out.writeByte(LSTORE_0+lvar); - } else { - if (wide()) out.writeByte(Constants.WIDE); - out.writeByte(opcode); - if (wide()) out.writeShort(lvar); - else out.writeByte(lvar); - } - } else { - if (wide()) out.writeByte(Constants.WIDE); - out.writeByte(opcode); - if (wide()) out.writeShort(lvar); - else out.writeByte(lvar); - } - } - } - - /** - * Long output format: - * - * 'name of opcode' "[" 'opcode number' "]" - * "(" 'length of instruction' ")" "<" 'local variable index' ">" - */ - public String toString(boolean verbose) { - if(((opcode >= Constants.ILOAD_0) && (opcode <= Constants.ALOAD_3)) || - ((opcode >= Constants.ISTORE_0) && (opcode <= Constants.ASTORE_3))) - return super.toString(verbose); - else - return super.toString(verbose) + ((lvar!=-1&&lvar<4)?"_":" ") + lvar; - } - - public boolean isALOAD() { - return opcode==ALOAD || (opcode>=ALOAD_0 && opcode<=ALOAD_3); - } - - public boolean isASTORE() { - return opcode==ASTORE || (opcode>=ASTORE_0 && opcode<=ASTORE_3); - } - - /** - * @return local variable index referred by this instruction. - */ - // optimize! - public final int getIndex() { - if (lvar!=-1) return lvar; - if (opcode>= Constants.ILOAD_0 && opcode <= Constants.ALOAD_3) { - return (opcode - Constants.ILOAD_0) % 4; - } else if (opcode>= Constants.ISTORE_0 && opcode <= Constants.ASTORE_3) { - return (opcode - Constants.ISTORE_0) % 4; - } - return -1; - } - - public void setIndex(int i) { - // Switching the index for a load/store without a current index specified (ie. an aload_1 or istore_2) - // means we need to should adjust to a normal aload/istore opcode - if (getIndex()!=i) { - if(opcode>= Constants.ILOAD_0 && opcode <= Constants.ALOAD_3) { - opcode = (short)(ILOAD + (opcode-ILOAD_0)/4); - } else if (opcode>= Constants.ISTORE_0 && opcode <= Constants.ASTORE_3) { - opcode = (short)(ISTORE+ (opcode-ISTORE_0)/4); - } - this.lvar = i; - } - } - - public int getLength() { - int size=Constants.iLen[opcode]; - if (lvar==-1) { - return size; - } else { - if (lvar<4) { - if (opcode==ALOAD || opcode==ASTORE) return 1; - else if (opcode==ILOAD || opcode==ISTORE) return 1; - else if (opcode==DLOAD || opcode==DSTORE) return 1; - else if (opcode==FLOAD || opcode==FSTORE) return 1; - else if (opcode==LLOAD || opcode==LSTORE) return 1; - else { - if (wide()) return size +2; - return size; - } - } else { - if (wide()) return size +2; - return size; - } - } - } - - private final boolean wide() { return lvar > Constants.MAX_BYTE; } - -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.io.DataOutputStream; +import java.io.IOException; + +import org.aspectj.apache.bcel.Constants; + +/** + * Abstract super class for instructions dealing with local variables. + * + * @version $Id: InstructionLV.java,v 1.1.2.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public class InstructionLV extends Instruction { + protected int lvar = -1; + + + public InstructionLV(short opcode, int lvar) { + this.opcode = opcode; + this.lvar = lvar; + } + + public InstructionLV(short opcode) { + this.opcode = opcode; + } + + public void dump(DataOutputStream out) throws IOException { + if (lvar==-1) { + out.writeByte(opcode); + } else { + if (lvar<4) { + if (opcode==ALOAD) { out.writeByte(ALOAD_0+lvar); + } else if (opcode==ASTORE) { out.writeByte(ASTORE_0+lvar); + } else if (opcode==ILOAD) { out.writeByte(ILOAD_0+lvar); + } else if (opcode==ISTORE) { out.writeByte(ISTORE_0+lvar); + } else if (opcode==DLOAD) { out.writeByte(DLOAD_0+lvar); + } else if (opcode==DSTORE) { out.writeByte(DSTORE_0+lvar); + } else if (opcode==FLOAD) { out.writeByte(FLOAD_0+lvar); + } else if (opcode==FSTORE) { out.writeByte(FSTORE_0+lvar); + } else if (opcode==LLOAD) { out.writeByte(LLOAD_0+lvar); + } else if (opcode==LSTORE) { out.writeByte(LSTORE_0+lvar); + } else { + if (wide()) out.writeByte(Constants.WIDE); + out.writeByte(opcode); + if (wide()) out.writeShort(lvar); + else out.writeByte(lvar); + } + } else { + if (wide()) out.writeByte(Constants.WIDE); + out.writeByte(opcode); + if (wide()) out.writeShort(lvar); + else out.writeByte(lvar); + } + } + } + + /** + * Long output format: + * + * 'name of opcode' "[" 'opcode number' "]" + * "(" 'length of instruction' ")" "<" 'local variable index' ">" + */ + public String toString(boolean verbose) { + if(((opcode >= Constants.ILOAD_0) && (opcode <= Constants.ALOAD_3)) || + ((opcode >= Constants.ISTORE_0) && (opcode <= Constants.ASTORE_3))) + return super.toString(verbose); + else + return super.toString(verbose) + ((lvar!=-1&&lvar<4)?"_":" ") + lvar; + } + + public boolean isALOAD() { + return opcode==ALOAD || (opcode>=ALOAD_0 && opcode<=ALOAD_3); + } + + public boolean isASTORE() { + return opcode==ASTORE || (opcode>=ASTORE_0 && opcode<=ASTORE_3); + } + + /** + * @return local variable index referred by this instruction. + */ + // optimize! + public final int getIndex() { + if (lvar!=-1) return lvar; + if (opcode>= Constants.ILOAD_0 && opcode <= Constants.ALOAD_3) { + return (opcode - Constants.ILOAD_0) % 4; + } else if (opcode>= Constants.ISTORE_0 && opcode <= Constants.ASTORE_3) { + return (opcode - Constants.ISTORE_0) % 4; + } + return -1; + } + + public void setIndex(int i) { + // Switching the index for a load/store without a current index specified (ie. an aload_1 or istore_2) + // means we need to should adjust to a normal aload/istore opcode + if (getIndex()!=i) { + if(opcode>= Constants.ILOAD_0 && opcode <= Constants.ALOAD_3) { + opcode = (short)(ILOAD + (opcode-ILOAD_0)/4); + } else if (opcode>= Constants.ISTORE_0 && opcode <= Constants.ASTORE_3) { + opcode = (short)(ISTORE+ (opcode-ISTORE_0)/4); + } + this.lvar = i; + } + } + + public int getLength() { + int size=Constants.iLen[opcode]; + if (lvar==-1) { + return size; + } else { + if (lvar<4) { + if (opcode==ALOAD || opcode==ASTORE) return 1; + else if (opcode==ILOAD || opcode==ISTORE) return 1; + else if (opcode==DLOAD || opcode==DSTORE) return 1; + else if (opcode==FLOAD || opcode==FSTORE) return 1; + else if (opcode==LLOAD || opcode==LSTORE) return 1; + else { + if (wide()) return size +2; + return size; + } + } else { + if (wide()) return size +2; + return size; + } + } + } + + private final boolean wide() { return lvar > Constants.MAX_BYTE; } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java index 96ea3f41f..c791a72dc 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java @@ -1,1209 +1,1220 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.Constant; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.util.ByteSequence; -import java.io.*; -import java.util.Iterator; -import java.util.HashMap; -import java.util.ArrayList; - -/** - * This class is a container for a list of Instruction objects. Instructions can - * be appended, inserted, moved, deleted, etc.. Instructions are being - * wrapped into InstructionHandles objects that - * are returned upon append/insert operations. They give the user - * (read only) access to the list structure, such that it can be traversed and - * manipulated in a controlled way. - * - * A list is finally dumped to a byte code array with getByteCode. - * - * @version $Id: InstructionList.java,v 1.4.6.2 2008/04/25 17:55:33 aclement Exp $ - * @author M. Dahm - * @see Instruction - * @see InstructionHandle - * @see BranchHandle - */ -public class InstructionList implements Serializable { - private InstructionHandle start = null, end = null; - private int length = 0; // number of elements in list - private int[] byte_positions; // byte code offsets corresponding to instructions - - /** - * Create (empty) instruction list. - */ - public InstructionList() {} - - /** - * Create instruction list containing one instruction. - * @param i initial instruction - */ - public InstructionList(Instruction i) { - append(i); - } - - /** - * Create instruction list containing one instruction. - * @param i initial instruction - */ - public InstructionList(InstructionBranch i) { - append(i); - } - - - /** - * Test for empty list. - */ - public boolean isEmpty() { return start == null; } // && end == null - +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.Constant; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.util.ByteSequence; +import java.io.*; +import java.util.Iterator; +import java.util.HashMap; +import java.util.ArrayList; + +/** + * This class is a container for a list of Instruction objects. Instructions can + * be appended, inserted, moved, deleted, etc.. Instructions are being + * wrapped into InstructionHandles objects that + * are returned upon append/insert operations. They give the user + * (read only) access to the list structure, such that it can be traversed and + * manipulated in a controlled way. + * + * A list is finally dumped to a byte code array with getByteCode. + * + * @version $Id: InstructionList.java,v 1.4.6.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + * @see Instruction + * @see InstructionHandle + * @see BranchHandle + */ +public class InstructionList implements Serializable { + private InstructionHandle start = null, end = null; + private int length = 0; // number of elements in list + private int[] byte_positions; // byte code offsets corresponding to instructions + + /** + * Create (empty) instruction list. + */ + public InstructionList() {} + + /** + * Create instruction list containing one instruction. + * @param i initial instruction + */ + public InstructionList(Instruction i) { + append(i); + } + + /** + * Create instruction list containing one instruction. + * @param i initial instruction + */ + public InstructionList(InstructionBranch i) { + append(i); + } + + + /** + * Test for empty list. + */ + public boolean isEmpty() { return start == null; } // && end == null + public static InstructionHandle findHandle(InstructionHandle[] ihs,int[] pos,int count,int target) { return findHandle(ihs,pos,count,target,false); } - /** - * Find the target instruction (handle) that corresponds to the given target - * position (byte code offset). - * - * @param ihs array of instruction handles, i.e. il.getInstructionHandles() - * @param pos array of positions corresponding to ihs, i.e. il.getInstructionPositions() - * @param count length of arrays - * @param target target position to search for - * @return target position's instruction handle if available - */ + /** + * Find the target instruction (handle) that corresponds to the given target + * position (byte code offset). + * + * @param ihs array of instruction handles, i.e. il.getInstructionHandles() + * @param pos array of positions corresponding to ihs, i.e. il.getInstructionPositions() + * @param count length of arrays + * @param target target position to search for + * @return target position's instruction handle if available + */ public static InstructionHandle findHandle(InstructionHandle[] ihs, int[] pos, int count,int target,boolean returnClosestIfNoExactMatch) { - int l=0, r = count - 1; - // Do a binary search since the pos array is ordered - int i,j; - do { - i = (l + r) / 2; - j = pos[i]; - if (j == target) return ihs[i]; // found it - else if (target < j) r=i-1; // else constrain search area - else l=i+1; // target > j - } while (l <= r); + int l=0, r = count - 1; + // Do a binary search since the pos array is ordered + int i,j; + do { + i = (l + r) / 2; + j = pos[i]; + if (j == target) return ihs[i]; // found it + else if (target < j) r=i-1; // else constrain search area + else l=i+1; // target > j + } while (l <= r); if (returnClosestIfNoExactMatch) { i = (l+r)/2; if (i<0) i=0; return ihs[i]; } - return null; - } - - /** - * Get instruction handle for instruction at byte code position pos. - * This only works properly, if the list is freshly initialized from a byte array or - * setPositions() has been called before this method. - * - * @param pos byte code position to search for - * @return target position's instruction handle if available - */ - public InstructionHandle findHandle(int pos) { - InstructionHandle[] ihs = getInstructionHandles(); - return findHandle(ihs, byte_positions, length, pos); - } - - public InstructionHandle[] getInstructionsAsArray() { - return getInstructionHandles(); - } - - public InstructionHandle findHandle(int pos,InstructionHandle[] instructionArray) { - return findHandle(instructionArray,byte_positions,length,pos); - } - + return null; + } + + /** + * Get instruction handle for instruction at byte code position pos. + * This only works properly, if the list is freshly initialized from a byte array or + * setPositions() has been called before this method. + * + * @param pos byte code position to search for + * @return target position's instruction handle if available + */ + public InstructionHandle findHandle(int pos) { + InstructionHandle[] ihs = getInstructionHandles(); + return findHandle(ihs, byte_positions, length, pos); + } + + public InstructionHandle[] getInstructionsAsArray() { + return getInstructionHandles(); + } + + public InstructionHandle findHandle(int pos,InstructionHandle[] instructionArray) { + return findHandle(instructionArray,byte_positions,length,pos); + } + public InstructionHandle findHandle(int pos,InstructionHandle[] instructionArray,boolean useClosestApproximationIfNoExactFound) { return findHandle(instructionArray,byte_positions,length,pos,useClosestApproximationIfNoExactFound); } - /** - * Initialize instruction list from byte array. - * - * @param code byte array containing the instructions - */ - public InstructionList(byte[] code) { - ByteSequence bytes = new ByteSequence(code); - InstructionHandle[] ihs = new InstructionHandle[code.length]; - int[] pos = new int[code.length]; // Can't be more than that - int count = 0; // Contains actual length - - /* Pass 1: Create an object for each byte code and append them - * to the list. - */ - try { - while(bytes.available() > 0) { - // Remember byte offset and associate it with the instruction - int off = bytes.getIndex(); - pos[count] = off; - - /* Read one instruction from the byte stream, the byte position is set - * accordingly. - */ - Instruction i = Instruction.readInstruction(bytes); - InstructionHandle ih; - if(i instanceof InstructionBranch) // Use proper append() method - ih = append((InstructionBranch)i); - else - ih = append(i); - - ih.setPosition(off); - ihs[count] = ih; - - count++; - } - } catch(IOException e) { throw new ClassGenException(e.toString()); } - - byte_positions = new int[count]; // Trim to proper size - System.arraycopy(pos, 0, byte_positions, 0, count); - - /* Pass 2: Look for BranchInstruction and update their targets, i.e., - * convert offsets to instruction handles. - */ - for(int i=0; i < count; i++) { - if(ihs[i] instanceof BranchHandle) { - InstructionBranch bi = (InstructionBranch)ihs[i].instruction; - int target = bi.positionOfThisInstruction + bi.getIndex(); /* Byte code position: - * relative -> absolute. */ - // Search for target position - InstructionHandle ih = findHandle(ihs, pos, count, target); - - if(ih == null) // Search failed - throw new ClassGenException("Couldn't find target for branch: " + bi); - - bi.setTarget(ih); // Update target - - // If it is a Select instruction, update all branch targets - if(bi instanceof InstructionSelect) { // Either LOOKUPSWITCH or TABLESWITCH - InstructionSelect s = (InstructionSelect)bi; - int[] indices = s.getIndices(); - - for(int j=0; j < indices.length; j++) { - target = bi.positionOfThisInstruction + indices[j]; - ih = findHandle(ihs, pos, count, target); - - if(ih == null) // Search failed - throw new ClassGenException("Couldn't find target for switch: " + bi); - - s.setTarget(j, ih); // Update target - } - } - } - } - } - - /** - * Append another list after instruction (handle) ih contained in this list. - * Consumes argument list, i.e., it becomes empty. - * - * @param ih where to append the instruction list - * @param il Instruction list to append to this one - * @return instruction handle pointing to the first appended instruction - */ - public InstructionHandle append(InstructionHandle ih, InstructionList il) { - if(il == null) - throw new ClassGenException("Appending null InstructionList"); - - if(il.isEmpty()) // Nothing to do - return ih; - - InstructionHandle next = ih.next, ret = il.start; - - ih.next = il.start; - il.start.prev = ih; - - il.end.next = next; - - if(next != null) // i == end ? - next.prev = il.end; - else - end = il.end; // Update end ... - - length += il.length; // Update length - - il.clear(); - - return ret; - } - - /** - * Append another list after instruction i contained in this list. - * Consumes argument list, i.e., it becomes empty. - * - * @param i where to append the instruction list - * @param il Instruction list to append to this one - * @return instruction handle pointing to the first appended instruction - */ - public InstructionHandle append(Instruction i, InstructionList il) { - InstructionHandle ih; - - if((ih = findInstruction2(i)) == null) // Also applies for empty list - throw new ClassGenException("Instruction " + i + - " is not contained in this list."); - - return append(ih, il); - } - - /** - * Append another list to this one. - * Consumes argument list, i.e., it becomes empty. - * - * @param il list to append to end of this list - * @return instruction handle of the first appended instruction - */ - public InstructionHandle append(InstructionList il) { - if(il == null) - throw new ClassGenException("Appending null InstructionList"); - - if(il.isEmpty()) // Nothing to do - return null; - - if(isEmpty()) { - start = il.start; - end = il.end; - length = il.length; - - il.clear(); - - return start; - } else - return append(end, il); // was end.instruction - } - - /** - * Append an instruction to the end of this list. - * - * @param ih instruction to append - */ - private void append(InstructionHandle ih) { - if(isEmpty()) { - start = end = ih; - ih.next = ih.prev = null; - } - else { - end.next = ih; - ih.prev = end; - ih.next = null; - end = ih; - } - - length++; // Update length - } - - /** - * Append an instruction to the end of this list. - * - * @param i instruction to append - * @return instruction handle of the appended instruction - */ - public InstructionHandle append(Instruction i) { - InstructionHandle ih = InstructionHandle.getInstructionHandle(i); - append(ih); - - return ih; - } - - /** - * Append a branch instruction to the end of this list. - * - * @param i branch instruction to append - * @return branch instruction handle of the appended instruction - */ - public BranchHandle append(InstructionBranch i) { - BranchHandle ih = BranchHandle.getBranchHandle(i); - append(ih); - - return ih; - } - - /** - * Append a single instruction j after another instruction i, which - * must be in this list of course! - * - * @param i Instruction in list - * @param j Instruction to append after i in list - * @return instruction handle of the first appended instruction - */ - public InstructionHandle append(Instruction i, Instruction j) { - return append(i, new InstructionList(j)); - } - - - /** - * Append an instruction after instruction (handle) ih contained in this list. - * - * @param ih where to append the instruction list - * @param i Instruction to append - * @return instruction handle pointing to the first appended instruction - */ - public InstructionHandle append(InstructionHandle ih, Instruction i) { - return append(ih, new InstructionList(i)); - } - - /** - * Append an instruction after instruction (handle) ih contained in this list. - * - * @param ih where to append the instruction list - * @param i Instruction to append - * @return instruction handle pointing to the first appended instruction - */ - public BranchHandle append(InstructionHandle ih, InstructionBranch i) { - BranchHandle bh = BranchHandle.getBranchHandle(i); - InstructionList il = new InstructionList(); - il.append(bh); - - append(ih, il); - - return bh; - } - - /** - * Insert another list before Instruction handle ih contained in this list. - * Consumes argument list, i.e., it becomes empty. - * - * @param i where to append the instruction list - * @param il Instruction list to insert - * @return instruction handle of the first inserted instruction - */ - public InstructionHandle insert(InstructionHandle ih, InstructionList il) { - if(il == null) - throw new ClassGenException("Inserting null InstructionList"); - - if(il.isEmpty()) // Nothing to do - return ih; - - InstructionHandle prev = ih.prev, ret = il.start; - - ih.prev = il.end; - il.end.next = ih; - - il.start.prev = prev; - - if(prev != null) // ih == start ? - prev.next = il.start; - else - start = il.start; // Update start ... - - length += il.length; // Update length - - il.clear(); - - return ret; - } - - /** - * Insert another list. - * - * @param il list to insert before start of this list - * @return instruction handle of the first inserted instruction - */ - public InstructionHandle insert(InstructionList il) { - if(isEmpty()) { - append(il); // Code is identical for this case - return start; - } - else - return insert(start, il); - } - - /** - * Insert an instruction at start of this list. - * - * @param ih instruction to insert - */ - private void insert(InstructionHandle ih) { - if(isEmpty()) { - start = end = ih; - ih.next = ih.prev = null; - } else { - start.prev = ih; - ih.next = start; - ih.prev = null; - start = ih; - } - - length++; - } - - /** - * Insert another list before Instruction i contained in this list. - * Consumes argument list, i.e., it becomes empty. - * - * @param i where to append the instruction list - * @param il Instruction list to insert - * @return instruction handle pointing to the first inserted instruction, - * i.e., il.getStart() - */ - public InstructionHandle insert(Instruction i, InstructionList il) { - InstructionHandle ih; - - if((ih = findInstruction1(i)) == null) - throw new ClassGenException("Instruction " + i + - " is not contained in this list."); - - return insert(ih, il); - } - - /** - * Insert an instruction at start of this list. - * - * @param i instruction to insert - * @return instruction handle of the inserted instruction - */ - public InstructionHandle insert(Instruction i) { - InstructionHandle ih = InstructionHandle.getInstructionHandle(i); - insert(ih); - - return ih; - } - - /** - * Insert a branch instruction at start of this list. - * - * @param i branch instruction to insert - * @return branch instruction handle of the appended instruction - */ - public BranchHandle insert(InstructionBranch i) { - BranchHandle ih = BranchHandle.getBranchHandle(i); - insert(ih); - return ih; - } - - /** - * Insert a single instruction j before another instruction i, which - * must be in this list of course! - * - * @param i Instruction in list - * @param j Instruction to insert before i in list - * @return instruction handle of the first inserted instruction - */ - public InstructionHandle insert(Instruction i, Instruction j) { - return insert(i, new InstructionList(j)); - } - - - /** - * Insert an instruction before instruction (handle) ih contained in this list. - * - * @param ih where to insert to the instruction list - * @param i Instruction to insert - * @return instruction handle of the first inserted instruction - */ - public InstructionHandle insert(InstructionHandle ih, Instruction i) { - return insert(ih, new InstructionList(i)); - } - - /** - * Insert an instruction before instruction (handle) ih contained in this list. - * - * @param ih where to insert to the instruction list - * @param i Instruction to insert - * @return instruction handle of the first inserted instruction - */ - public BranchHandle insert(InstructionHandle ih, InstructionBranch i) { - BranchHandle bh = BranchHandle.getBranchHandle(i); - InstructionList il = new InstructionList(); - il.append(bh); - - insert(ih, il); - - return bh; - } - - /** - * Take all instructions (handles) from "start" to "end" and append them after the - * new location "target". Of course, "end" must be after "start" and target must - * not be located withing this range. If you want to move something to the start of - * the list use null as value for target.
          - * Any instruction targeters pointing to handles within the block, keep their targets. - * - * @param start of moved block - * @param end of moved block - * @param target of moved block - */ - public void move(InstructionHandle start, InstructionHandle end, InstructionHandle target) { - // Step 1: Check constraints - - if((start == null) || (end == null)) - throw new ClassGenException("Invalid null handle: From " + start + " to " + end); - - if((target == start) || (target == end)) - throw new ClassGenException("Invalid range: From " + start + " to " + end + - " contains target " + target); - - for(InstructionHandle ih = start; ih != end.next; ih = ih.next) { - if(ih == null) // At end of list, end not found yet - throw new ClassGenException("Invalid range: From " + start + " to " + end); - else if(ih == target) // target may be null - throw new ClassGenException("Invalid range: From " + start + " to " + end + - " contains target " + target); - } - - // Step 2: Temporarily remove the given instructions from the list - - InstructionHandle prev = start.prev, next = end.next; - - if(prev != null) - prev.next = next; - else // start == this.start! - this.start = next; - - if(next != null) - next.prev = prev; - else // end == this.end! - this.end = prev; - - start.prev = end.next = null; - - // Step 3: append after target - - if(target == null) { // append to start of list - end.next = this.start; - this.start = start; - } else { - next = target.next; - - target.next = start; - start.prev = target; - end.next = next; - - if(next != null) - next.prev = end; - } - } - - /** - * Move a single instruction (handle) to a new location. - * - * @param ih moved instruction - * @param target new location of moved instruction - */ - public void move(InstructionHandle ih, InstructionHandle target) { - move(ih, ih, target); - } - - /** - * Remove from instruction `prev' to instruction `next' both contained - * in this list. Throws TargetLostException when one of the removed instruction handles - * is still being targeted. - * - * @param prev where to start deleting (predecessor, exclusive) - * @param next where to end deleting (successor, exclusive) - */ - private void remove(InstructionHandle prev, InstructionHandle next) - throws TargetLostException - { - InstructionHandle first, last; // First and last deleted instruction - - if((prev == null) && (next == null)) { // singleton list - first = last = start; - start = end = null; - } else { - if(prev == null) { // At start of list - first = start; - start = next; - } else { - first = prev.next; - prev.next = next; - } - - if(next == null) { // At end of list - last = end; - end = prev; - } else { - last = next.prev; - next.prev = prev; - } - } - - first.prev = null; // Completely separated from rest of list - last.next = null; - - ArrayList target_vec = new ArrayList(); - - for(InstructionHandle ih=first; ih != null; ih = ih.next) - ih.getInstruction().dispose(); // e.g. BranchInstructions release their targets - - StringBuffer buf = new StringBuffer("{ "); - for(InstructionHandle ih=first; ih != null; ih = next) { - next = ih.next; - length--; - - if(ih.hasTargeters()) { // Still got targeters? - target_vec.add(ih); - buf.append(ih.toString(true) + " "); - ih.next = ih.prev = null; - } else - ih.dispose(); - } - - buf.append("}"); - - if(!target_vec.isEmpty()) { - InstructionHandle[] targeted = new InstructionHandle[target_vec.size()]; - target_vec.toArray(targeted); - throw new TargetLostException(targeted, buf.toString()); - } - } - - /** - * Remove instruction from this list. The corresponding Instruction - * handles must not be reused! - * - * @param ih instruction (handle) to remove - */ - public void delete(InstructionHandle ih) throws TargetLostException { - remove(ih.prev, ih.next); - } - - /** - * Remove instruction from this list. The corresponding Instruction - * handles must not be reused! - * - * @param i instruction to remove - */ - public void delete(Instruction i) throws TargetLostException { - InstructionHandle ih; - - if((ih = findInstruction1(i)) == null) - throw new ClassGenException("Instruction " + i + - " is not contained in this list."); - delete(ih); - } - - /** - * Remove instructions from instruction `from' to instruction `to' contained - * in this list. The user must ensure that `from' is an instruction before - * `to', or risk havoc. The corresponding Instruction handles must not be reused! - * - * @param from where to start deleting (inclusive) - * @param to where to end deleting (inclusive) - */ - public void delete(InstructionHandle from, InstructionHandle to) - throws TargetLostException - { - remove(from.prev, to.next); - } - - /** - * Remove instructions from instruction `from' to instruction `to' contained - * in this list. The user must ensure that `from' is an instruction before - * `to', or risk havoc. The corresponding Instruction handles must not be reused! - * - * @param from where to start deleting (inclusive) - * @param to where to end deleting (inclusive) - */ - public void delete(Instruction from, Instruction to) throws TargetLostException { - InstructionHandle from_ih, to_ih; - - if((from_ih = findInstruction1(from)) == null) - throw new ClassGenException("Instruction " + from + - " is not contained in this list."); - - if((to_ih = findInstruction2(to)) == null) - throw new ClassGenException("Instruction " + to + - " is not contained in this list."); - delete(from_ih, to_ih); - } - - /** - * Search for given Instruction reference, start at beginning of list. - * - * @param i instruction to search for - * @return instruction found on success, null otherwise - */ - private InstructionHandle findInstruction1(Instruction i) { - for(InstructionHandle ih=start; ih != null; ih = ih.next) - if(ih.instruction == i) - return ih; - - return null; - } - - /** - * Search for given Instruction reference, start at end of list - * - * @param i instruction to search for - * @return instruction found on success, null otherwise - */ - private InstructionHandle findInstruction2(Instruction i) { - for(InstructionHandle ih=end; ih != null; ih = ih.prev) - if(ih.instruction == i) - return ih; - - return null; - } - - public boolean contains(InstructionHandle i) { - if(i == null) - return false; - - for(InstructionHandle ih=start; ih != null; ih = ih.next) - if(ih == i) - return true; - - return false; - } - - public boolean contains(Instruction i) { - return findInstruction1(i) != null; - } - - public void setPositions() { - setPositions(false); - } - - /** - * Give all instructions their position number (offset in byte stream), i.e., - * make the list ready to be dumped. - * - * @param check Perform sanity checks, e.g. if all targeted instructions really belong - * to this list - */ - public void setPositions(boolean check) { - int max_additional_bytes = 0, additional_bytes = 0; - int index = 0, count = 0; - int[] pos = new int[length]; - - /* Pass 0: Sanity checks - */ - if(check) { - for(InstructionHandle ih=start; ih != null; ih = ih.next) { - Instruction i = ih.instruction; - - if(i instanceof InstructionBranch) { // target instruction within list? - Instruction inst = ((InstructionBranch)i).getTarget().instruction; - if(!contains(inst)) - throw new ClassGenException("Branch target of " + - Constants.OPCODE_NAMES[i.opcode] + ":" + - inst + " not in instruction list"); - - if(i instanceof InstructionSelect) { - InstructionHandle[] targets = ((InstructionSelect)i).getTargets(); - - for(int j=0; j < targets.length; j++) { - inst = targets[j].instruction; - if(!contains(inst)) - throw new ClassGenException("Branch target of " + - Constants.OPCODE_NAMES[i.opcode] + ":" + - inst + " not in instruction list"); - } - } - - if(!(ih instanceof BranchHandle)) - throw new ClassGenException("Branch instruction " + - Constants.OPCODE_NAMES[i.opcode] + ":" + - inst + " not contained in BranchHandle."); - - } - } - } - - /* Pass 1: Set position numbers and sum up the maximum number of bytes an - * instruction may be shifted. - */ - for(InstructionHandle ih=start; ih != null; ih = ih.next) { - Instruction i = ih.instruction; - - ih.setPosition(index); - pos[count++] = index; - - /* Get an estimate about how many additional bytes may be added, because - * BranchInstructions may have variable length depending on the target - * offset (short vs. int) or alignment issues (TABLESWITCH and - * LOOKUPSWITCH). - */ - switch(i.opcode) { - case Constants.JSR: case Constants.GOTO: - max_additional_bytes += 2; - break; - - case Constants.TABLESWITCH: case Constants.LOOKUPSWITCH: - max_additional_bytes += 3; - break; - } - - index += i.getLength(); - } - - /* Pass 2: Expand the variable-length (Branch)Instructions depending on - * the target offset (short or int) and ensure that branch targets are - * within this list. - */ - for(InstructionHandle ih=start; ih != null; ih = ih.next) { - - additional_bytes += ih.updatePosition(additional_bytes, max_additional_bytes); - } - - /* Pass 3: Update position numbers (which may have changed due to the - * preceding expansions), like pass 1. - */ - index=count=0; - for(InstructionHandle ih=start; ih != null; ih = ih.next) { - Instruction i = ih.instruction; - - ih.setPosition(index); - pos[count++] = index; - index += i.getLength(); - } - - byte_positions = new int[count]; // Trim to proper size - System.arraycopy(pos, 0, byte_positions, 0, count); - } - - /** - * When everything is finished, use this method to convert the instruction - * list into an array of bytes. - * - * @return the byte code ready to be dumped - */ - public byte[] getByteCode() { - // Update position indices of instructions - setPositions(); - - ByteArrayOutputStream b = new ByteArrayOutputStream(); - DataOutputStream out = new DataOutputStream(b); - - try { - for(InstructionHandle ih=start; ih != null; ih = ih.next) { - Instruction i = ih.instruction; - i.dump(out); // Traverse list - } - } catch(IOException e) { - System.err.println(e); - return null; - } - byte[] byteCode = b.toByteArray(); - if (byteCode.length > Constants.MAX_CODE_SIZE) - throw new ClassGenException("Code size too big: " + byteCode.length); - - return byteCode; - } - - /** - * @return an array of instructions without target information for branch instructions. - */ - public Instruction[] getInstructions() { - ByteSequence bytes = new ByteSequence(getByteCode()); - ArrayList instructions = new ArrayList(); - - try { - while(bytes.available() > 0) { - instructions.add(Instruction.readInstruction(bytes)); - } - } catch(IOException e) { throw new ClassGenException(e.toString()); } - - Instruction[] result = new Instruction[instructions.size()]; - instructions.toArray(result); - return result; - } - - public String toString() { - return toString(true); - } - - /** - * @param verbose toggle output format - * @return String containing all instructions in this list. - */ - public String toString(boolean verbose) { - StringBuffer buf = new StringBuffer(); - - for(InstructionHandle ih=start; ih != null; ih = ih.next) { - buf.append(ih.toString(verbose) + "\n"); - } - - return buf.toString(); - } - - /** - * @return Enumeration that lists all instructions (handles) - */ - public Iterator iterator() { - return new Iterator() { - private InstructionHandle ih = start; - - public Object next() { - InstructionHandle i = ih; - ih = ih.next; - return i; - } - - public void remove() { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() { return ih != null; } - }; - } - - /** - * @return array containing all instructions (handles) - */ - public InstructionHandle[] getInstructionHandles() { - InstructionHandle[] ihs = new InstructionHandle[length]; - InstructionHandle ih = start; - - for(int i=0; i < length; i++) { - ihs[i] = ih; - ih = ih.next; - } - - return ihs; - } - - /** - * Get positions (offsets) of all instructions in the list. This relies on that - * the list has been freshly created from an byte code array, or that setPositions() - * has been called. Otherwise this may be inaccurate. - * - * @return array containing all instruction's offset in byte code - */ - public int[] getInstructionPositions() { return byte_positions; } - - /** - * @return complete, i.e., deep copy of this list - */ - public InstructionList copy() { - HashMap map = new HashMap(); - InstructionList il = new InstructionList(); - - /* Pass 1: Make copies of all instructions, append them to the new list - * and associate old instruction references with the new ones, i.e., - * a 1:1 mapping. - */ - for(InstructionHandle ih=start; ih != null; ih = ih.next) { - Instruction i = ih.instruction; - Instruction c = i.copy(); // Use clone for shallow copy - - if(c instanceof InstructionBranch) - map.put(ih, il.append((InstructionBranch)c)); - else - map.put(ih, il.append(c)); - } - - /* Pass 2: Update branch targets. - */ - InstructionHandle ih=start; - InstructionHandle ch=il.start; - - while(ih != null) { - Instruction i = ih.instruction; - Instruction c = ch.instruction; - - if(i instanceof InstructionBranch) { - InstructionBranch bi = (InstructionBranch)i; - InstructionBranch bc = (InstructionBranch)c; - InstructionHandle itarget = bi.getTarget(); // old target - - // New target is in hash map - bc.setTarget((InstructionHandle)map.get(itarget)); - - if(bi instanceof InstructionSelect) { // Either LOOKUPSWITCH or TABLESWITCH - InstructionHandle[] itargets = ((InstructionSelect)bi).getTargets(); - InstructionHandle[] ctargets = ((InstructionSelect)bc).getTargets(); - - for(int j=0; j < itargets.length; j++) { // Update all targets - ctargets[j] = (InstructionHandle)map.get(itargets[j]); - } - } - } - - ih = ih.next; - ch = ch.next; - } - - return il; - } - - /** Replace all references to the old constant pool with references to the new - * constant pool - */ - public void replaceConstantPool(ConstantPool old_cp, ConstantPool new_cp) { - for(InstructionHandle ih=start; ih != null; ih = ih.next) { - Instruction i = ih.instruction; - - if(i.isConstantPoolInstruction()) { - InstructionCP ci = (InstructionCP)i; - Constant c = old_cp.getConstant(ci.getIndex()); - ci.setIndex(new_cp.addConstant(c, old_cp)); - } - } - } - - private void clear() { - start = end = null; - length = 0; - } - - /** - * Delete contents of list. Provides besser memory utilization, - * because the system then may reuse the instruction handles. This - * method is typically called right after - * MethodGen.getMethod(). - */ - public void dispose() { - // Traverse in reverse order, because ih.next is overwritten - for(InstructionHandle ih=end; ih != null; ih = ih.prev) - /* Causes BranchInstructions to release target and targeters, because it - * calls dispose() on the contained instruction. - */ - ih.dispose(); - - clear(); - } - - /** - * @return start of list - */ - public InstructionHandle getStart() { return start; } - - /** - * @return end of list - */ - public InstructionHandle getEnd() { return end; } - - /** - * @return length of list (Number of instructions, not bytes) - */ - public int getLength() { return length; } - - /** - * @return length of list (Number of instructions, not bytes) - */ - public int size() { return length; } - - /** - * Redirect all references from old_target to new_target, i.e., update targets - * of branch instructions. - * - * @param old_target the old target instruction handle - * @param new_target the new target instruction handle - */ - public void redirectBranches(InstructionHandle old_target, - InstructionHandle new_target) { - for(InstructionHandle ih = start; ih != null; ih = ih.next) { - Instruction i = ih.getInstruction(); - - if(i instanceof InstructionBranch) { - InstructionBranch b = (InstructionBranch)i; - InstructionHandle target = b.getTarget(); - - if(target == old_target) - b.setTarget(new_target); - - if(b instanceof InstructionSelect) { // Either LOOKUPSWITCH or TABLESWITCH - InstructionHandle[] targets = ((InstructionSelect)b).getTargets(); - - for(int j=0; j < targets.length; j++) // Update targets - if(targets[j] == old_target) - ((InstructionSelect)b).setTarget(j, new_target); - } - } - } - } - - /** - * Redirect all references of local variables from old_target to new_target. - * - * @param lg array of local variables - * @param old_target the old target instruction handle - * @param new_target the new target instruction handle - * @see MethodGen - */ - public void redirectLocalVariables(LocalVariableGen[] lg, - InstructionHandle old_target, - InstructionHandle new_target) { - for(int i=0; i < lg.length; i++) { - InstructionHandle start = lg[i].getStart(); - InstructionHandle end = lg[i].getEnd(); - - if(start == old_target) - lg[i].setStart(new_target); - - if(end == old_target) - lg[i].setEnd(new_target); - } - } - - /** - * Redirect all references of exception handlers from old_target to new_target. - * - * @param exceptions array of exception handlers - * @param old_target the old target instruction handle - * @param new_target the new target instruction handle - * @see MethodGen - */ - public void redirectExceptionHandlers(CodeExceptionGen[] exceptions, - InstructionHandle old_target, - InstructionHandle new_target) { - for(int i=0; i < exceptions.length; i++) { - if(exceptions[i].getStartPC() == old_target) - exceptions[i].setStartPC(new_target); - - if(exceptions[i].getEndPC() == old_target) - exceptions[i].setEndPC(new_target); - - if(exceptions[i].getHandlerPC() == old_target) - exceptions[i].setHandlerPC(new_target); - } - } - - -} - + /** + * Initialize instruction list from byte array. + * + * @param code byte array containing the instructions + */ + public InstructionList(byte[] code) { + ByteSequence bytes = new ByteSequence(code); + InstructionHandle[] ihs = new InstructionHandle[code.length]; + int[] pos = new int[code.length]; // Can't be more than that + int count = 0; // Contains actual length + + /* Pass 1: Create an object for each byte code and append them + * to the list. + */ + try { + while(bytes.available() > 0) { + // Remember byte offset and associate it with the instruction + int off = bytes.getIndex(); + pos[count] = off; + + /* Read one instruction from the byte stream, the byte position is set + * accordingly. + */ + Instruction i = Instruction.readInstruction(bytes); + InstructionHandle ih; + if (i instanceof InstructionBranch) // Use proper append() method + ih = append((InstructionBranch)i); + else + ih = append(i); + + ih.setPosition(off); + ihs[count] = ih; + + count++; + } + } catch(IOException e) { throw new ClassGenException(e.toString()); } + + byte_positions = new int[count]; // Trim to proper size + System.arraycopy(pos, 0, byte_positions, 0, count); + + /* Pass 2: Look for BranchInstruction and update their targets, i.e., + * convert offsets to instruction handles. + */ + // OPTIMIZE better way of doing this? keep little map from earlier from pos -> instruction handle? + for(int i=0; i < count; i++) { + if(ihs[i] instanceof BranchHandle) { + InstructionBranch bi = (InstructionBranch)ihs[i].instruction; + int target = bi.positionOfThisInstruction + bi.getIndex(); /* Byte code position: + * relative -> absolute. */ + // Search for target position + InstructionHandle ih = findHandle(ihs, pos, count, target); + + if(ih == null) // Search failed + throw new ClassGenException("Couldn't find target for branch: " + bi); + + bi.setTarget(ih); // Update target + + // If it is a Select instruction, update all branch targets + if(bi instanceof InstructionSelect) { // Either LOOKUPSWITCH or TABLESWITCH + InstructionSelect s = (InstructionSelect)bi; + int[] indices = s.getIndices(); + + for(int j=0; j < indices.length; j++) { + target = bi.positionOfThisInstruction + indices[j]; + ih = findHandle(ihs, pos, count, target); + + if(ih == null) // Search failed + throw new ClassGenException("Couldn't find target for switch: " + bi); + + s.setTarget(j, ih); // Update target + } + } + } + } + } + + /** + * Append another list after instruction (handle) ih contained in this list. + * Consumes argument list, i.e., it becomes empty. + * + * @param ih where to append the instruction list + * @param il Instruction list to append to this one + * @return instruction handle pointing to the first appended instruction + */ + public InstructionHandle append(InstructionHandle ih, InstructionList il) { + if(il == null) + throw new ClassGenException("Appending null InstructionList"); + + if(il.isEmpty()) // Nothing to do + return ih; + + InstructionHandle next = ih.next, ret = il.start; + + ih.next = il.start; + il.start.prev = ih; + + il.end.next = next; + + if(next != null) // i == end ? + next.prev = il.end; + else + end = il.end; // Update end ... + + length += il.length; // Update length + + il.clear(); + + return ret; + } + + /** + * Append another list after instruction i contained in this list. + * Consumes argument list, i.e., it becomes empty. + * + * @param i where to append the instruction list + * @param il Instruction list to append to this one + * @return instruction handle pointing to the first appended instruction + */ + public InstructionHandle append(Instruction i, InstructionList il) { + InstructionHandle ih; + + if((ih = findInstruction2(i)) == null) // Also applies for empty list + throw new ClassGenException("Instruction " + i + + " is not contained in this list."); + + return append(ih, il); + } + + /** + * Append another list to this one. + * Consumes argument list, i.e., it becomes empty. + * + * @param il list to append to end of this list + * @return instruction handle of the first appended instruction + */ + public InstructionHandle append(InstructionList il) { + if(il == null) + throw new ClassGenException("Appending null InstructionList"); + + if(il.isEmpty()) // Nothing to do + return null; + + if(isEmpty()) { + start = il.start; + end = il.end; + length = il.length; + + il.clear(); + + return start; + } else + return append(end, il); // was end.instruction + } + + /** + * Append an instruction to the end of this list. + * + * @param ih instruction to append + */ + private void append(InstructionHandle ih) { + if(isEmpty()) { + start = end = ih; + ih.next = ih.prev = null; + } + else { + end.next = ih; + ih.prev = end; + ih.next = null; + end = ih; + } + + length++; // Update length + } + + /** + * Append an instruction to the end of this list. + * + * @param i instruction to append + * @return instruction handle of the appended instruction + */ + public InstructionHandle append(Instruction i) { + InstructionHandle ih = InstructionHandle.getInstructionHandle(i); + append(ih); + + return ih; + } + + /** + * Append a branch instruction to the end of this list. + * + * @param i branch instruction to append + * @return branch instruction handle of the appended instruction + */ + public BranchHandle append(InstructionBranch i) { + BranchHandle ih = BranchHandle.getBranchHandle(i); + append(ih); + + return ih; + } + + /** + * Append a single instruction j after another instruction i, which + * must be in this list of course! + * + * @param i Instruction in list + * @param j Instruction to append after i in list + * @return instruction handle of the first appended instruction + */ + public InstructionHandle append(Instruction i, Instruction j) { + return append(i, new InstructionList(j)); + } + + + /** + * Append an instruction after instruction (handle) ih contained in this list. + * + * @param ih where to append the instruction list + * @param i Instruction to append + * @return instruction handle pointing to the first appended instruction + */ + public InstructionHandle append(InstructionHandle ih, Instruction i) { + return append(ih, new InstructionList(i)); + } + + /** + * Append an instruction after instruction (handle) ih contained in this list. + * + * @param ih where to append the instruction list + * @param i Instruction to append + * @return instruction handle pointing to the first appended instruction + */ + public BranchHandle append(InstructionHandle ih, InstructionBranch i) { + BranchHandle bh = BranchHandle.getBranchHandle(i); + InstructionList il = new InstructionList(); + il.append(bh); + + append(ih, il); + + return bh; + } + + /** + * Insert another list before Instruction handle ih contained in this list. + * Consumes argument list, i.e., it becomes empty. + * + * @param i where to append the instruction list + * @param il Instruction list to insert + * @return instruction handle of the first inserted instruction + */ + public InstructionHandle insert(InstructionHandle ih, InstructionList il) { + if(il == null) + throw new ClassGenException("Inserting null InstructionList"); + + if(il.isEmpty()) // Nothing to do + return ih; + + InstructionHandle prev = ih.prev, ret = il.start; + + ih.prev = il.end; + il.end.next = ih; + + il.start.prev = prev; + + if(prev != null) // ih == start ? + prev.next = il.start; + else + start = il.start; // Update start ... + + length += il.length; // Update length + + il.clear(); + + return ret; + } + + /** + * Insert another list. + * + * @param il list to insert before start of this list + * @return instruction handle of the first inserted instruction + */ + public InstructionHandle insert(InstructionList il) { + if(isEmpty()) { + append(il); // Code is identical for this case + return start; + } + else + return insert(start, il); + } + + /** + * Insert an instruction at start of this list. + * + * @param ih instruction to insert + */ + private void insert(InstructionHandle ih) { + if(isEmpty()) { + start = end = ih; + ih.next = ih.prev = null; + } else { + start.prev = ih; + ih.next = start; + ih.prev = null; + start = ih; + } + + length++; + } + + /** + * Insert another list before Instruction i contained in this list. + * Consumes argument list, i.e., it becomes empty. + * + * @param i where to append the instruction list + * @param il Instruction list to insert + * @return instruction handle pointing to the first inserted instruction, + * i.e., il.getStart() + */ + public InstructionHandle insert(Instruction i, InstructionList il) { + InstructionHandle ih; + + if((ih = findInstruction1(i)) == null) + throw new ClassGenException("Instruction " + i + + " is not contained in this list."); + + return insert(ih, il); + } + + /** + * Insert an instruction at start of this list. + * + * @param i instruction to insert + * @return instruction handle of the inserted instruction + */ + public InstructionHandle insert(Instruction i) { + InstructionHandle ih = InstructionHandle.getInstructionHandle(i); + insert(ih); + + return ih; + } + + /** + * Insert a branch instruction at start of this list. + * + * @param i branch instruction to insert + * @return branch instruction handle of the appended instruction + */ + public BranchHandle insert(InstructionBranch i) { + BranchHandle ih = BranchHandle.getBranchHandle(i); + insert(ih); + return ih; + } + + /** + * Insert a single instruction j before another instruction i, which + * must be in this list of course! + * + * @param i Instruction in list + * @param j Instruction to insert before i in list + * @return instruction handle of the first inserted instruction + */ + public InstructionHandle insert(Instruction i, Instruction j) { + return insert(i, new InstructionList(j)); + } + + + /** + * Insert an instruction before instruction (handle) ih contained in this list. + * + * @param ih where to insert to the instruction list + * @param i Instruction to insert + * @return instruction handle of the first inserted instruction + */ + public InstructionHandle insert(InstructionHandle ih, Instruction i) { + return insert(ih, new InstructionList(i)); + } + + /** + * Insert an instruction before instruction (handle) ih contained in this list. + * + * @param ih where to insert to the instruction list + * @param i Instruction to insert + * @return instruction handle of the first inserted instruction + */ + public BranchHandle insert(InstructionHandle ih, InstructionBranch i) { + BranchHandle bh = BranchHandle.getBranchHandle(i); + InstructionList il = new InstructionList(); + il.append(bh); + + insert(ih, il); + + return bh; + } + + /** + * Take all instructions (handles) from "start" to "end" and append them after the + * new location "target". Of course, "end" must be after "start" and target must + * not be located withing this range. If you want to move something to the start of + * the list use null as value for target.
          + * Any instruction targeters pointing to handles within the block, keep their targets. + * + * @param start of moved block + * @param end of moved block + * @param target of moved block + */ + public void move(InstructionHandle start, InstructionHandle end, InstructionHandle target) { + // Step 1: Check constraints + + if((start == null) || (end == null)) + throw new ClassGenException("Invalid null handle: From " + start + " to " + end); + + if((target == start) || (target == end)) + throw new ClassGenException("Invalid range: From " + start + " to " + end + + " contains target " + target); + + for(InstructionHandle ih = start; ih != end.next; ih = ih.next) { + if(ih == null) // At end of list, end not found yet + throw new ClassGenException("Invalid range: From " + start + " to " + end); + else if(ih == target) // target may be null + throw new ClassGenException("Invalid range: From " + start + " to " + end + + " contains target " + target); + } + + // Step 2: Temporarily remove the given instructions from the list + + InstructionHandle prev = start.prev, next = end.next; + + if(prev != null) + prev.next = next; + else // start == this.start! + this.start = next; + + if(next != null) + next.prev = prev; + else // end == this.end! + this.end = prev; + + start.prev = end.next = null; + + // Step 3: append after target + + if(target == null) { // append to start of list + end.next = this.start; + this.start = start; + } else { + next = target.next; + + target.next = start; + start.prev = target; + end.next = next; + + if(next != null) + next.prev = end; + } + } + + /** + * Move a single instruction (handle) to a new location. + * + * @param ih moved instruction + * @param target new location of moved instruction + */ + public void move(InstructionHandle ih, InstructionHandle target) { + move(ih, ih, target); + } + + /** + * Remove from instruction 'prev' to instruction 'next' both contained + * in this list. + * + * If careAboutLostTargeters is true then this method will throw a + * TargetLostException when one of the removed instruction handles + * is still being targeted. + * + * @param prev where to start deleting (predecessor, exclusive) + * @param next where to end deleting (successor, exclusive) + */ + private void remove(InstructionHandle prev, InstructionHandle next, boolean careAboutLostTargeters) throws TargetLostException { + InstructionHandle first, last; // First and last deleted instruction + + if ((prev == null) && (next == null)) { // singleton list + first = last = start; + start = end = null; + } else { + if (prev == null) { // At start of list + first = start; + start = next; + } else { + first = prev.next; + prev.next = next; + } + if (next == null) { // At end of list + last = end; + end = prev; + } else { + last = next.prev; + next.prev = prev; + } + } + + first.prev = null; // Completely separated from rest of list + last.next = null; + + if (!careAboutLostTargeters) return; + + ArrayList target_vec = new ArrayList(); + + for(InstructionHandle ih=first; ih != null; ih = ih.next) + ih.getInstruction().dispose(); // e.g. BranchInstructions release their targets + + StringBuffer buf = new StringBuffer("{ "); + for(InstructionHandle ih=first; ih != null; ih = next) { + next = ih.next; + length--; + + if(ih.hasTargeters()) { // Still got targeters? + InstructionTargeter[] targeters = ih.getTargeters(); + boolean isOK = false; + for (int i = 0; i < targeters.length; i++) { + InstructionTargeter instructionTargeter = targeters[i]; + if (instructionTargeter.getClass().getName().endsWith("ShadowRange") || + instructionTargeter.getClass().getName().endsWith("ExceptionRange") || + instructionTargeter.getClass().getName().endsWith("LineNumberTag") ) isOK=true; + else System.out.println(instructionTargeter.getClass()); + } + if (!isOK) { + + target_vec.add(ih); + buf.append(ih.toString(true) + " "); + ih.next = ih.prev = null; + } else { + ih.dispose(); + } + } else { + ih.dispose(); + } + } + + buf.append("}"); + + if(!target_vec.isEmpty()) { + InstructionHandle[] targeted = new InstructionHandle[target_vec.size()]; + target_vec.toArray(targeted); + throw new TargetLostException(targeted, buf.toString()); + } + } + + /** + * Remove instruction from this list. The corresponding Instruction + * handles must not be reused! + * + * @param ih instruction (handle) to remove + */ + public void delete(InstructionHandle ih) throws TargetLostException { + remove(ih.prev, ih.next,false); + } + + /** + * Remove instruction from this list. The corresponding Instruction + * handles must not be reused! + * + * @param i instruction to remove + */ +// public void delete(Instruction i) throws TargetLostException { +// InstructionHandle ih; +// +// if((ih = findInstruction1(i)) == null) +// throw new ClassGenException("Instruction " + i + +// " is not contained in this list."); +// delete(ih); +// } + + /** + * Remove instructions from instruction `from' to instruction `to' contained + * in this list. The user must ensure that `from' is an instruction before + * `to', or risk havoc. The corresponding Instruction handles must not be reused! + * + * @param from where to start deleting (inclusive) + * @param to where to end deleting (inclusive) + */ + public void delete(InstructionHandle from, InstructionHandle to) + throws TargetLostException + { + remove(from.prev, to.next,false); + } + + /** + * Remove instructions from instruction `from' to instruction `to' contained + * in this list. The user must ensure that `from' is an instruction before + * `to', or risk havoc. The corresponding Instruction handles must not be reused! + * + * @param from where to start deleting (inclusive) + * @param to where to end deleting (inclusive) + */ + public void delete(Instruction from, Instruction to) throws TargetLostException { + InstructionHandle from_ih, to_ih; + + if((from_ih = findInstruction1(from)) == null) + throw new ClassGenException("Instruction " + from + + " is not contained in this list."); + + if((to_ih = findInstruction2(to)) == null) + throw new ClassGenException("Instruction " + to + + " is not contained in this list."); + delete(from_ih, to_ih); + } + + /** + * Search for given Instruction reference, start at beginning of list. + * + * @param i instruction to search for + * @return instruction found on success, null otherwise + */ + private InstructionHandle findInstruction1(Instruction i) { + for(InstructionHandle ih=start; ih != null; ih = ih.next) + if(ih.instruction == i) + return ih; + + return null; + } + + /** + * Search for given Instruction reference, start at end of list + * + * @param i instruction to search for + * @return instruction found on success, null otherwise + */ + private InstructionHandle findInstruction2(Instruction i) { + for(InstructionHandle ih=end; ih != null; ih = ih.prev) + if(ih.instruction == i) + return ih; + + return null; + } + + public boolean contains(InstructionHandle i) { + if(i == null) + return false; + + for(InstructionHandle ih=start; ih != null; ih = ih.next) + if(ih == i) + return true; + + return false; + } + + public boolean contains(Instruction i) { + return findInstruction1(i) != null; + } + + public void setPositions() { + setPositions(false); + } + + /** + * Give all instructions their position number (offset in byte stream), i.e., + * make the list ready to be dumped. + * + * @param check Perform sanity checks, e.g. if all targeted instructions really belong + * to this list + */ + public void setPositions(boolean check) { + int max_additional_bytes = 0, additional_bytes = 0; + int index = 0, count = 0; + int[] pos = new int[length]; + + // Pass 0: Sanity checks + if (check) { + for (InstructionHandle ih=start; ih != null; ih = ih.next) { + Instruction i = ih.instruction; + + if (i instanceof InstructionBranch) { // target instruction within list? + Instruction inst = ((InstructionBranch)i).getTarget().instruction; + if(!contains(inst)) + throw new ClassGenException("Branch target of " + + Constants.OPCODE_NAMES[i.opcode] + ":" + + inst + " not in instruction list"); + + if(i instanceof InstructionSelect) { + InstructionHandle[] targets = ((InstructionSelect)i).getTargets(); + + for(int j=0; j < targets.length; j++) { + inst = targets[j].instruction; + if(!contains(inst)) + throw new ClassGenException("Branch target of " + + Constants.OPCODE_NAMES[i.opcode] + ":" + + inst + " not in instruction list"); + } + } + + if(!(ih instanceof BranchHandle)) + throw new ClassGenException("Branch instruction " + + Constants.OPCODE_NAMES[i.opcode] + ":" + + inst + " not contained in BranchHandle."); + + } + } + } + + // Pass 1: Set position numbers and sum up the maximum number of bytes an + // instruction may be shifted. + for (InstructionHandle ih=start; ih != null; ih = ih.next) { + Instruction i = ih.instruction; + ih.setPosition(index); + pos[count++] = index; + + /* Get an estimate about how many additional bytes may be added, because + * BranchInstructions may have variable length depending on the target + * offset (short vs. int) or alignment issues (TABLESWITCH and + * LOOKUPSWITCH). + */ + switch(i.opcode) { + case Constants.JSR: + case Constants.GOTO: + max_additional_bytes += 2; + break; + + case Constants.TABLESWITCH: + case Constants.LOOKUPSWITCH: + max_additional_bytes += 3; + break; + } + index += i.getLength(); + } + + /* Pass 2: Expand the variable-length (Branch)Instructions depending on + * the target offset (short or int) and ensure that branch targets are + * within this list. + */ + for (InstructionHandle ih=start; ih != null; ih = ih.next) { + additional_bytes += ih.updatePosition(additional_bytes, max_additional_bytes); + } + + /* Pass 3: Update position numbers (which may have changed due to the + * preceding expansions), like pass 1. + */ + index=count=0; + for(InstructionHandle ih=start; ih != null; ih = ih.next) { + Instruction i = ih.instruction; + ih.setPosition(index); + pos[count++] = index; + index += i.getLength(); + } + + byte_positions = new int[count]; // Trim to proper size + System.arraycopy(pos, 0, byte_positions, 0, count); + } + + /** + * When everything is finished, use this method to convert the instruction + * list into an array of bytes. + * + * @return the byte code ready to be dumped + */ + public byte[] getByteCode() { + // Update position indices of instructions + setPositions(); + + ByteArrayOutputStream b = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(b); + + try { + for(InstructionHandle ih=start; ih != null; ih = ih.next) { + Instruction i = ih.instruction; + i.dump(out); // Traverse list + } + } catch(IOException e) { + System.err.println(e); + return null; + } + byte[] byteCode = b.toByteArray(); + if (byteCode.length > Constants.MAX_CODE_SIZE) + throw new ClassGenException("Code size too big: " + byteCode.length); + + return byteCode; + } + + /** + * @return an array of instructions without target information for branch instructions. + */ + public Instruction[] getInstructions() { + ByteSequence bytes = new ByteSequence(getByteCode()); + ArrayList instructions = new ArrayList(); + + try { + while(bytes.available() > 0) { + instructions.add(Instruction.readInstruction(bytes)); + } + } catch(IOException e) { throw new ClassGenException(e.toString()); } + + Instruction[] result = new Instruction[instructions.size()]; + instructions.toArray(result); + return result; + } + + public String toString() { + return toString(true); + } + + /** + * @param verbose toggle output format + * @return String containing all instructions in this list. + */ + public String toString(boolean verbose) { + StringBuffer buf = new StringBuffer(); + + for(InstructionHandle ih=start; ih != null; ih = ih.next) { + buf.append(ih.toString(verbose) + "\n"); + } + + return buf.toString(); + } + + /** + * @return Enumeration that lists all instructions (handles) + */ + public Iterator iterator() { + return new Iterator() { + private InstructionHandle ih = start; + + public Object next() { + InstructionHandle i = ih; + ih = ih.next; + return i; + } + + public void remove() { + throw new UnsupportedOperationException(); + } + + public boolean hasNext() { return ih != null; } + }; + } + + /** + * @return array containing all instructions (handles) + */ + public InstructionHandle[] getInstructionHandles() { + InstructionHandle[] ihs = new InstructionHandle[length]; + InstructionHandle ih = start; + + for(int i=0; i < length; i++) { + ihs[i] = ih; + ih = ih.next; + } + + return ihs; + } + + /** + * Get positions (offsets) of all instructions in the list. This relies on that + * the list has been freshly created from an byte code array, or that setPositions() + * has been called. Otherwise this may be inaccurate. + * + * @return array containing all instruction's offset in byte code + */ + public int[] getInstructionPositions() { return byte_positions; } + + /** + * @return complete, i.e., deep copy of this list + */ + public InstructionList copy() { + HashMap map = new HashMap(); + InstructionList il = new InstructionList(); + + /* Pass 1: Make copies of all instructions, append them to the new list + * and associate old instruction references with the new ones, i.e., + * a 1:1 mapping. + */ + for(InstructionHandle ih=start; ih != null; ih = ih.next) { + Instruction i = ih.instruction; + Instruction c = i.copy(); // Use clone for shallow copy + + if(c instanceof InstructionBranch) + map.put(ih, il.append((InstructionBranch)c)); + else + map.put(ih, il.append(c)); + } + + /* Pass 2: Update branch targets. + */ + InstructionHandle ih=start; + InstructionHandle ch=il.start; + + while(ih != null) { + Instruction i = ih.instruction; + Instruction c = ch.instruction; + + if(i instanceof InstructionBranch) { + InstructionBranch bi = (InstructionBranch)i; + InstructionBranch bc = (InstructionBranch)c; + InstructionHandle itarget = bi.getTarget(); // old target + + // New target is in hash map + bc.setTarget((InstructionHandle)map.get(itarget)); + + if(bi instanceof InstructionSelect) { // Either LOOKUPSWITCH or TABLESWITCH + InstructionHandle[] itargets = ((InstructionSelect)bi).getTargets(); + InstructionHandle[] ctargets = ((InstructionSelect)bc).getTargets(); + + for(int j=0; j < itargets.length; j++) { // Update all targets + ctargets[j] = (InstructionHandle)map.get(itargets[j]); + } + } + } + + ih = ih.next; + ch = ch.next; + } + + return il; + } + + /** Replace all references to the old constant pool with references to the new + * constant pool + */ + public void replaceConstantPool(ConstantPool old_cp, ConstantPool new_cp) { + for(InstructionHandle ih=start; ih != null; ih = ih.next) { + Instruction i = ih.instruction; + + if(i.isConstantPoolInstruction()) { + InstructionCP ci = (InstructionCP)i; + Constant c = old_cp.getConstant(ci.getIndex()); + ci.setIndex(new_cp.addConstant(c, old_cp)); + } + } + } + + private void clear() { + start = end = null; + length = 0; + } + + /** + * Delete contents of list. Provides besser memory utilization, + * because the system then may reuse the instruction handles. This + * method is typically called right after + * MethodGen.getMethod(). + */ + public void dispose() { + // Traverse in reverse order, because ih.next is overwritten + for(InstructionHandle ih=end; ih != null; ih = ih.prev) + /* Causes BranchInstructions to release target and targeters, because it + * calls dispose() on the contained instruction. + */ + ih.dispose(); + + clear(); + } + + /** + * @return start of list + */ + public InstructionHandle getStart() { return start; } + + /** + * @return end of list + */ + public InstructionHandle getEnd() { return end; } + + /** + * @return length of list (Number of instructions, not bytes) + */ + public int getLength() { return length; } + + /** + * @return length of list (Number of instructions, not bytes) + */ + public int size() { return length; } + + /** + * Redirect all references from old_target to new_target, i.e., update targets + * of branch instructions. + * + * @param old_target the old target instruction handle + * @param new_target the new target instruction handle + */ + public void redirectBranches(InstructionHandle old_target, + InstructionHandle new_target) { + for(InstructionHandle ih = start; ih != null; ih = ih.next) { + Instruction i = ih.getInstruction(); + + if(i instanceof InstructionBranch) { + InstructionBranch b = (InstructionBranch)i; + InstructionHandle target = b.getTarget(); + + if(target == old_target) + b.setTarget(new_target); + + if(b instanceof InstructionSelect) { // Either LOOKUPSWITCH or TABLESWITCH + InstructionHandle[] targets = ((InstructionSelect)b).getTargets(); + + for(int j=0; j < targets.length; j++) // Update targets + if(targets[j] == old_target) + ((InstructionSelect)b).setTarget(j, new_target); + } + } + } + } + + /** + * Redirect all references of local variables from old_target to new_target. + * + * @param lg array of local variables + * @param old_target the old target instruction handle + * @param new_target the new target instruction handle + * @see MethodGen + */ + public void redirectLocalVariables(LocalVariableGen[] lg, + InstructionHandle old_target, + InstructionHandle new_target) { + for(int i=0; i < lg.length; i++) { + InstructionHandle start = lg[i].getStart(); + InstructionHandle end = lg[i].getEnd(); + + if (start == old_target) lg[i].setStart(new_target); + if (end == old_target) lg[i].setEnd(new_target); + } + } + + /** + * Redirect all references of exception handlers from old_target to new_target. + * + * @param exceptions array of exception handlers + * @param old_target the old target instruction handle + * @param new_target the new target instruction handle + * @see MethodGen + */ + public void redirectExceptionHandlers(CodeExceptionGen[] exceptions, + InstructionHandle old_target, + InstructionHandle new_target) { + for(int i=0; i < exceptions.length; i++) { + if(exceptions[i].getStartPC() == old_target) + exceptions[i].setStartPC(new_target); + + if(exceptions[i].getEndPC() == old_target) + exceptions[i].setEndPC(new_target); + + if(exceptions[i].getHandlerPC() == old_target) + exceptions[i].setHandlerPC(new_target); + } + } + + +} + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionListObserver.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionListObserver.java deleted file mode 100644 index c6a28bc69..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionListObserver.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Implement this interface if you're interested in changes to an InstructionList object - * and register yourself with addObserver(). - * - * @version $Id: InstructionListObserver.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public interface InstructionListObserver { - public void notify(InstructionList list); -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionSelect.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionSelect.java index 449b6d6a8..700fca09b 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionSelect.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionSelect.java @@ -1,273 +1,273 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * Select - Abstract super class for LOOKUPSWITCH and TABLESWITCH instructions. - * - * @version $Id: InstructionSelect.java,v 1.1.2.2 2008/04/25 17:55:32 aclement Exp $ - * @author M. Dahm - * @see LOOKUPSWITCH - * @see TABLESWITCH - * @see InstructionList - */ -public abstract class InstructionSelect extends InstructionBranch { - protected int[] match; // matches, i.e., case 1: ... - protected int[] indices; // target offsets - protected InstructionHandle[] targets; // target objects in instruction list - protected int fixed_length; // fixed length defined by subclasses - protected int match_length; // number of cases - protected int padding = 0; // number of pad bytes for alignment - - protected short length; - public int getLength() { return length; } - /** - * (Match, target) pairs for switch. - * `Match' and `targets' must have the same length of course. - * - * @param match array of matching values - * @param targets instruction targets - * @param target default instruction target - */ - InstructionSelect(short opcode, int[] match, InstructionHandle[] targets, - InstructionHandle target) { - super(opcode, target); - - this.targets = targets; - for(int i=0; i < targets.length; i++) - notifyTarget(null, targets[i], this); - - this.match = match; - - if((match_length = match.length) != targets.length) - throw new ClassGenException("Match and target array have not the same length"); - - indices = new int[match_length]; - } - - protected int getTargetOffset(InstructionHandle target) { - if(target == null) - throw new ClassGenException("Target of " + super.toString(true) + - " is invalid null handle"); - - int t = target.getPosition(); - - if(t < 0) - throw new ClassGenException("Invalid branch target position offset for " + - super.toString(true) + ":" + t + ":" + target); - - return t - positionOfThisInstruction; - } - /** - * Since this is a variable length instruction, it may shift the following - * instructions which then need to update their position. - * - * Called by InstructionList.setPositions when setting the position for every - * instruction. In the presence of variable length instructions `setPositions' - * performs multiple passes over the instruction list to calculate the - * correct (byte) positions and offsets by calling this function. - * - * @param offset additional offset caused by preceding (variable length) instructions - * @param max_offset the maximum offset that may be caused by these instructions - * @return additional offset caused by possible change of this instruction's length - */ - protected int updatePosition(int offset, int max_offset) { - positionOfThisInstruction += offset; // Additional offset caused by preceding SWITCHs, GOTOs, etc. - - short old_length = length; - - /* Alignment on 4-byte-boundary, + 1, because of tag byte. - */ - padding = (4 - ((positionOfThisInstruction + 1) % 4)) % 4; - length = (short)(fixed_length + padding); // Update length - - return length - old_length; - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - out.writeByte(opcode); - - for(int i=0; i < padding; i++) // Padding bytes - out.writeByte(0); - - targetIndex = getTargetOffset(); // Write default target offset - out.writeInt(targetIndex); - } - -// /** -// * Read needed data (e.g. index) from file. -// */ -// protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException -// { -// padding = (4 - (bytes.getIndex() % 4)) % 4; // Compute number of pad bytes -// -// for(int i=0; i < padding; i++) { -// bytes.readByte(); -// } -// -// // Default branch target common for both cases (TABLESWITCH, LOOKUPSWITCH) -// targetIndex = bytes.readInt(); -// } - - public InstructionSelect(short opcode, ByteSequence bytes) throws IOException { - super(opcode); - padding = (4 - (bytes.getIndex() % 4)) % 4; // Compute number of pad bytes - - for(int i=0; i < padding; i++) { - bytes.readByte(); - } - - // Default branch target common for both cases (TABLESWITCH, LOOKUPSWITCH) - targetIndex = bytes.readInt(); - } - - /** - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - StringBuffer buf = new StringBuffer(super.toString(verbose)); - - if(verbose) { - for(int i=0; i < match_length; i++) { - String s = "null"; - - if(targets[i] != null) - s = targets[i].getInstruction().toString(); - - buf.append("(" + match[i] + ", " + s + " = {" + indices[i] + "})"); - } - } - else - buf.append(" ..."); - - return buf.toString(); - } - - /** - * Set branch target for `i'th case - */ - public void setTarget(int i, InstructionHandle target) { - notifyTarget(targets[i], target, this); - targets[i] = target; - } - - /** - * @param old_ih old target - * @param new_ih new target - */ - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { - boolean targeted = false; - - if(targetInstruction == old_ih) { - targeted = true; - setTarget(new_ih); - } - - for(int i=0; i < targets.length; i++) { - if(targets[i] == old_ih) { - targeted = true; - setTarget(i, new_ih); - } - } - - if(!targeted) - throw new ClassGenException("Not targeting " + old_ih); - } - - /** - * @return true, if ih is target of this instruction - */ - public boolean containsTarget(InstructionHandle ih) { - if(targetInstruction == ih) - return true; - - for(int i=0; i < targets.length; i++) - if(targets[i] == ih) - return true; - - return false; - } - - /** - * Inform targets that they're not targeted anymore. - */ - void dispose() { - super.dispose(); - - for(int i=0; i < targets.length; i++) - targets[i].removeTargeter(this); - } - - /** - * @return array of match indices - */ - public int[] getMatchs() { return match; } - - /** - * @return array of match target offsets - */ - public int[] getIndices() { return indices; } - - /** - * @return array of match targets - */ - public InstructionHandle[] getTargets() { return targets; } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.io.*; +import org.aspectj.apache.bcel.util.ByteSequence; + +/** + * Select - Abstract super class for LOOKUPSWITCH and TABLESWITCH instructions. + * + * @version $Id: InstructionSelect.java,v 1.1.2.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + * @see LOOKUPSWITCH + * @see TABLESWITCH + * @see InstructionList + */ +public abstract class InstructionSelect extends InstructionBranch { + protected int[] match; // matches, i.e., case 1: ... + protected int[] indices; // target offsets + protected InstructionHandle[] targets; // target objects in instruction list + protected int fixedLength; // fixed length defined by subclasses + protected int matchLength; // number of cases + protected int padding = 0; // number of pad bytes for alignment + + protected short length; + public int getLength() { return length; } + /** + * (Match, target) pairs for switch. + * `Match' and `targets' must have the same length of course. + * + * @param match array of matching values + * @param targets instruction targets + * @param target default instruction target + */ + InstructionSelect(short opcode, int[] match, InstructionHandle[] targets, + InstructionHandle target) { + super(opcode, target); + + this.targets = targets; + for(int i=0; i < targets.length; i++) + notifyTarget(null, targets[i], this); + + this.match = match; + + if((matchLength = match.length) != targets.length) + throw new ClassGenException("Match and target array have not the same length"); + + indices = new int[matchLength]; + } + + protected int getTargetOffset(InstructionHandle target) { + if(target == null) + throw new ClassGenException("Target of " + super.toString(true) + + " is invalid null handle"); + + int t = target.getPosition(); + + if(t < 0) + throw new ClassGenException("Invalid branch target position offset for " + + super.toString(true) + ":" + t + ":" + target); + + return t - positionOfThisInstruction; + } + /** + * Since this is a variable length instruction, it may shift the following + * instructions which then need to update their position. + * + * Called by InstructionList.setPositions when setting the position for every + * instruction. In the presence of variable length instructions `setPositions' + * performs multiple passes over the instruction list to calculate the + * correct (byte) positions and offsets by calling this function. + * + * @param offset additional offset caused by preceding (variable length) instructions + * @param max_offset the maximum offset that may be caused by these instructions + * @return additional offset caused by possible change of this instruction's length + */ + protected int updatePosition(int offset, int max_offset) { + positionOfThisInstruction += offset; // Additional offset caused by preceding SWITCHs, GOTOs, etc. + + short old_length = length; + + /* Alignment on 4-byte-boundary, + 1, because of tag byte. + */ + padding = (4 - ((positionOfThisInstruction + 1) % 4)) % 4; + length = (short)(fixedLength + padding); // Update length + + return length - old_length; + } + + /** + * Dump instruction as byte code to stream out. + * @param out Output stream + */ + public void dump(DataOutputStream out) throws IOException { + out.writeByte(opcode); + + for(int i=0; i < padding; i++) // Padding bytes + out.writeByte(0); + + targetIndex = getTargetOffset(); // Write default target offset + out.writeInt(targetIndex); + } + +// /** +// * Read needed data (e.g. index) from file. +// */ +// protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException +// { +// padding = (4 - (bytes.getIndex() % 4)) % 4; // Compute number of pad bytes +// +// for(int i=0; i < padding; i++) { +// bytes.readByte(); +// } +// +// // Default branch target common for both cases (TABLESWITCH, LOOKUPSWITCH) +// targetIndex = bytes.readInt(); +// } + + public InstructionSelect(short opcode, ByteSequence bytes) throws IOException { + super(opcode); + padding = (4 - (bytes.getIndex() % 4)) % 4; // Compute number of pad bytes + + for(int i=0; i < padding; i++) { + bytes.readByte(); + } + + // Default branch target common for both cases (TABLESWITCH, LOOKUPSWITCH) + targetIndex = bytes.readInt(); + } + + /** + * @return mnemonic for instruction + */ + public String toString(boolean verbose) { + StringBuffer buf = new StringBuffer(super.toString(verbose)); + + if(verbose) { + for(int i=0; i < matchLength; i++) { + String s = "null"; + + if(targets[i] != null) + s = targets[i].getInstruction().toString(); + + buf.append("(" + match[i] + ", " + s + " = {" + indices[i] + "})"); + } + } + else + buf.append(" ..."); + + return buf.toString(); + } + + /** + * Set branch target for `i'th case + */ + public void setTarget(int i, InstructionHandle target) { + notifyTarget(targets[i], target, this); + targets[i] = target; + } + + /** + * @param old_ih old target + * @param new_ih new target + */ + public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { + boolean targeted = false; + + if(targetInstruction == old_ih) { + targeted = true; + setTarget(new_ih); + } + + for(int i=0; i < targets.length; i++) { + if(targets[i] == old_ih) { + targeted = true; + setTarget(i, new_ih); + } + } + + if(!targeted) + throw new ClassGenException("Not targeting " + old_ih); + } + + /** + * @return true, if ih is target of this instruction + */ + public boolean containsTarget(InstructionHandle ih) { + if(targetInstruction == ih) + return true; + + for(int i=0; i < targets.length; i++) + if(targets[i] == ih) + return true; + + return false; + } + + /** + * Inform targets that they're not targeted anymore. + */ + void dispose() { + super.dispose(); + + for(int i=0; i < targets.length; i++) + targets[i].removeTargeter(this); + } + + /** + * @return array of match indices + */ + public int[] getMatchs() { return match; } + + /** + * @return array of match target offsets + */ + public int[] getIndices() { return indices; } + + /** + * @return array of match targets + */ + public InstructionHandle[] getTargets() { return targets; } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionTargeter.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionTargeter.java index d0e882b3c..67a13842a 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionTargeter.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionTargeter.java @@ -1,70 +1,70 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denote that a class targets InstructionHandles within an InstructionList. Namely - * the following implementers: - * - * @see BranchHandle - * @see LocalVariableGen - * @see CodeExceptionGen - * @version $Id: InstructionTargeter.java,v 1.2.10.1 2008/04/25 17:55:35 aclement Exp $ - * @author M. Dahm - */ -public interface InstructionTargeter { - public boolean containsTarget(InstructionHandle ih); - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih); -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Denote that a class targets InstructionHandles within an InstructionList. Namely + * the following implementers: + * + * @see BranchHandle + * @see LocalVariableGen + * @see CodeExceptionGen + * @version $Id: InstructionTargeter.java,v 1.2.10.2 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public interface InstructionTargeter { + public boolean containsTarget(InstructionHandle ih); + public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih); +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InvokeInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InvokeInstruction.java index e1c8b1e9f..23c5ac243 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InvokeInstruction.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InvokeInstruction.java @@ -1,132 +1,132 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.util.StringTokenizer; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.Constant; -import org.aspectj.apache.bcel.classfile.ConstantPool; - -/** - * Super class for the INVOKExxx family of instructions. - * - * @version $Id: InvokeInstruction.java,v 1.4.4.2 2008/04/25 17:55:32 aclement Exp $ - * @author M. Dahm - */ -public class InvokeInstruction extends FieldOrMethod { - - /** - * @param index to constant pool - */ - public InvokeInstruction(short opcode, int index) { - super(opcode, index); - } - - /** - * @return mnemonic for instruction with symbolic references resolved - */ - public String toString(ConstantPool cp) { - Constant c = cp.getConstant(index); - StringTokenizer tok = new StringTokenizer(cp.constantToString(c)); - - return Constants.OPCODE_NAMES[opcode] + " " + - tok.nextToken().replace('.', '/') + tok.nextToken(); - } - - /** - * Also works for instructions whose stack effect depends on the - * constant pool entry they reference. - * @return Number of words consumed from stack by this instruction - */ - public int consumeStack(ConstantPool cpg) { - String signature = getSignature(cpg); - int sum = Type.getArgumentSizes(signature); - if (opcode!=Constants.INVOKESTATIC) sum+=1; - return sum; - } - - /** - * Also works for instructions whose stack effect depends on the - * constant pool entry they reference. - * @return Number of words produced onto stack by this instruction - */ - public int produceStack(ConstantPool cpg) { - return getReturnType(cpg).getSize(); - } - - /** @return return type of referenced method. - */ - public Type getType(ConstantPool cpg) { - return getReturnType(cpg); - } - - /** @return name of referenced method. - */ - public String getMethodName(ConstantPool cpg) { - return getName(cpg); - } - - /** @return return type of referenced method. - */ - public Type getReturnType(ConstantPool cpg) { - return Type.getReturnType(getSignature(cpg)); - } - - /** @return argument types of referenced method. - */ - public Type[] getArgumentTypes(ConstantPool cpg) { - return Type.getArgumentTypes(getSignature(cpg)); - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.util.StringTokenizer; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.Constant; +import org.aspectj.apache.bcel.classfile.ConstantPool; + +/** + * Super class for the INVOKExxx family of instructions. + * + * @version $Id: InvokeInstruction.java,v 1.4.4.3 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + */ +public class InvokeInstruction extends FieldOrMethod { + + /** + * @param index to constant pool + */ + public InvokeInstruction(short opcode, int index) { + super(opcode, index); + } + + /** + * @return mnemonic for instruction with symbolic references resolved + */ + public String toString(ConstantPool cp) { + Constant c = cp.getConstant(index); + StringTokenizer tok = new StringTokenizer(cp.constantToString(c)); + + return Constants.OPCODE_NAMES[opcode] + " " + + tok.nextToken().replace('.', '/') + tok.nextToken(); + } + + /** + * Also works for instructions whose stack effect depends on the + * constant pool entry they reference. + * @return Number of words consumed from stack by this instruction + */ + public int consumeStack(ConstantPool cpg) { + String signature = getSignature(cpg); + int sum = Type.getArgumentSizes(signature); + if (opcode!=Constants.INVOKESTATIC) sum+=1; + return sum; + } + + /** + * Also works for instructions whose stack effect depends on the + * constant pool entry they reference. + * @return Number of words produced onto stack by this instruction + */ + public int produceStack(ConstantPool cpg) { + return getReturnType(cpg).getSize(); + } + + /** @return return type of referenced method. + */ + public Type getType(ConstantPool cpg) { + return getReturnType(cpg); + } + + /** @return name of referenced method. + */ + public String getMethodName(ConstantPool cpg) { + return getName(cpg); + } + + /** @return return type of referenced method. + */ + public Type getReturnType(ConstantPool cpg) { + return Type.getReturnType(getSignature(cpg)); + } + + /** @return argument types of referenced method. + */ + public Type[] getArgumentTypes(ConstantPool cpg) { + return Type.getArgumentTypes(getSignature(cpg)); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/JSR.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/JSR.java deleted file mode 100644 index bf338e8f1..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/JSR.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; - -/** - * JSR - Jump to subroutine - * - * @version $Id: JSR.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class JSR extends JsrInstruction implements VariableLengthInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - JSR() {} - - public JSR(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.JSR, target); - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - index = getTargetOffset(); - if(opcode == org.aspectj.apache.bcel.Constants.JSR) - super.dump(out); - else { // JSR_W - index = getTargetOffset(); - out.writeByte(opcode); - out.writeInt(index); - } - } - - protected int updatePosition(int offset, int max_offset) { - int i = getTargetOffset(); // Depending on old position value - - position += offset; // Position may be shifted by preceding expansions - - if(Math.abs(i) >= (32767 - max_offset)) { // to large for short (estimate) - opcode = org.aspectj.apache.bcel.Constants.JSR_W; - length = 5; - return 2; // 5 - 3 - } - - return 0; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitVariableLengthInstruction(this); - v.visitBranchInstruction(this); - v.visitJsrInstruction(this); - v.visitJSR(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/JSR_W.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/JSR_W.java deleted file mode 100644 index ccaab667b..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/JSR_W.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * JSR_W - Jump to subroutine - * - * @version $Id: JSR_W.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class JSR_W extends JsrInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - JSR_W() {} - - public JSR_W(InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.JSR_W, target); - length = 5; - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - index = getTargetOffset(); - out.writeByte(opcode); - out.writeInt(index); - } - - /** - * Read needed data (e.g. index) from file. - */ - protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException - { - index = bytes.readInt(); - length = 5; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitBranchInstruction(this); - v.visitJsrInstruction(this); - v.visitJSR_W(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/JsrInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/JsrInstruction.java deleted file mode 100644 index 75c39160d..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/JsrInstruction.java +++ /dev/null @@ -1,115 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Super class for JSR - Jump to subroutine - * - * @version $Id: JsrInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public abstract class JsrInstruction extends BranchInstruction - implements UnconditionalBranch, TypedInstruction, StackProducer -{ - JsrInstruction(short opcode, InstructionHandle target) { - super(opcode, target); - } - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - JsrInstruction(){} - - /** @return return address type - */ - public Type getType(ConstantPoolGen cp) { - return new ReturnaddressType(physicalSuccessor()); - } - - /** - * Returns an InstructionHandle to the physical successor - * of this JsrInstruction. For this method to work, - * this JsrInstruction object must not be shared between - * multiple InstructionHandle objects! - * Formally, there must not be InstructionHandle objects - * i, j where i != j and i.getInstruction() == this == - * j.getInstruction(). - * @return an InstructionHandle to the "next" instruction that - * will be executed when RETurned from a subroutine. - */ - public InstructionHandle physicalSuccessor(){ - InstructionHandle ih = this.target; - - // Rewind! - while(ih.getPrev() != null) - ih = ih.getPrev(); - - // Find the handle for "this" JsrInstruction object. - while(ih.getInstruction() != this) - ih = ih.getNext(); - - InstructionHandle toThis = ih; - - while(ih != null){ - ih = ih.getNext(); - if ((ih != null) && (ih.getInstruction() == this)) - throw new RuntimeException("physicalSuccessor() called on a shared JsrInstruction."); - } - - // Return the physical successor - return toThis.getNext(); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/L2D.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/L2D.java deleted file mode 100644 index 41df9bf41..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/L2D.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * L2D - Convert long to double - *
          Stack: ..., value.word1, value.word2 -> ..., result.word1, result.word2
          - * - * @version $Id: L2D.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class L2D extends ConversionInstruction { - public L2D() { - super(org.aspectj.apache.bcel.Constants.L2D); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitL2D(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/L2F.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/L2F.java deleted file mode 100644 index af8c53556..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/L2F.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * L2F - Convert long to float - *
          Stack: ..., value.word1, value.word2 -> ..., result
          - * - * @version $Id: L2F.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class L2F extends ConversionInstruction { - public L2F() { - super(org.aspectj.apache.bcel.Constants.L2F); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitL2F(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/L2I.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/L2I.java deleted file mode 100644 index 6cbfcf13c..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/L2I.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * L2I - Convert long to int - *
          Stack: ..., value.word1, value.word2 -> ..., result
          - * - * @version $Id: L2I.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class L2I extends ConversionInstruction { - public L2I() { - super(org.aspectj.apache.bcel.Constants.L2I); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitConversionInstruction(this); - v.visitL2I(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LADD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LADD.java deleted file mode 100644 index e1bc63860..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LADD.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LADD - Add longs - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result.word1, result.word2 - * - * @version $Id: LADD.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class LADD extends ArithmeticInstruction { - public LADD() { - super(org.aspectj.apache.bcel.Constants.LADD); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitLADD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LALOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LALOAD.java deleted file mode 100644 index cfa21bd69..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LALOAD.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LALOAD - Load long from array - *
          Stack: ..., arrayref, index -> ..., value1, value2
          - * - * @version $Id: LALOAD.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class LALOAD extends ArrayInstruction implements StackProducer { - /** Load long from array - */ - public LALOAD() { - super(org.aspectj.apache.bcel.Constants.LALOAD); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitLALOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LAND.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LAND.java deleted file mode 100644 index 03770b364..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LAND.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LAND - Bitwise AND longs - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result.word1, result.word2 - * - * @version $Id: LAND.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LAND extends ArithmeticInstruction { - public LAND() { - super(org.aspectj.apache.bcel.Constants.LAND); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitLAND(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LASTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LASTORE.java deleted file mode 100644 index ae5637864..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LASTORE.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LASTORE - Store into long array - *
          Stack: ..., arrayref, index, value.word1, value.word2 -> ...
          - * - * @version $Id: LASTORE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LASTORE extends ArrayInstruction implements StackConsumer { - /** Store long into array - */ - public LASTORE() { - super(org.aspectj.apache.bcel.Constants.LASTORE); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitLASTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LCMP.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LCMP.java deleted file mode 100644 index d77a723ce..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LCMP.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LCMP - Compare longs: - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result <= -1, 0, 1> - * - * @version $Id: LCMP.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LCMP extends Instruction - implements TypedInstruction, StackProducer, StackConsumer -{ - public LCMP() { - super(org.aspectj.apache.bcel.Constants.LCMP, (short)1); - } - - /** @return Type.LONG - */ - public Type getType(ConstantPoolGen cp) { - return Type.LONG; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitLCMP(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LCONST.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LCONST.java deleted file mode 100644 index 76aeb5b0a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LCONST.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LCONST - Push 0 or 1, other values cause an exception - * - *
          Stack: ... -> ..., 
          - * - * @version $Id: LCONST.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LCONST extends Instruction - implements ConstantPushInstruction, TypedInstruction { - private long value; - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - LCONST() {} - - public LCONST(long l) { - super(org.aspectj.apache.bcel.Constants.LCONST_0, (short)1); - - if(l == 0) - opcode = org.aspectj.apache.bcel.Constants.LCONST_0; - else if(l == 1) - opcode = org.aspectj.apache.bcel.Constants.LCONST_1; - else - throw new ClassGenException("LCONST can be used only for 0 and 1: " + l); - - value = l; - } - - public Number getValue() { return new Long(value); } - - /** @return Type.LONG - */ - public Type getType(ConstantPoolGen cp) { - return Type.LONG; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitPushInstruction(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitConstantPushInstruction(this); - v.visitLCONST(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LDC.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LDC.java deleted file mode 100644 index dfe293e14..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LDC.java +++ /dev/null @@ -1,172 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * LDC - Push item from constant pool. - * - *
          Stack: ... -> ..., item
          - * - * @version $Id: LDC.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class LDC extends CPInstruction - implements PushInstruction, ExceptionThrower, TypedInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - LDC() {} - - public LDC(int index) { - super(org.aspectj.apache.bcel.Constants.LDC_W, index); - setSize(); - } - - // Adjust to proper size - protected final void setSize() { - if(index <= org.aspectj.apache.bcel.Constants.MAX_BYTE) { // Fits in one byte? - opcode = org.aspectj.apache.bcel.Constants.LDC; - length = 2; - } else { - opcode = org.aspectj.apache.bcel.Constants.LDC_W; - length = 3; - } - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - out.writeByte(opcode); - - if(length == 2) - out.writeByte(index); - else // Applies for LDC_W - out.writeShort(index); - } - - /** - * Set the index to constant pool and adjust size. - */ - public final void setIndex(int index) { - super.setIndex(index); - setSize(); - } - - /** - * Read needed data (e.g. index) from file. - */ - protected void initFromFile(ByteSequence bytes, boolean wide) - throws IOException - { - length = 2; - index = bytes.readUnsignedByte(); - } - - public Object getValue(ConstantPoolGen cpg) { - org.aspectj.apache.bcel.classfile.Constant c = cpg.getConstantPool().getConstant(index); - - switch(c.getTag()) { - case org.aspectj.apache.bcel.Constants.CONSTANT_String: - int i = ((org.aspectj.apache.bcel.classfile.ConstantString)c).getStringIndex(); - c = cpg.getConstantPool().getConstant(i); - return ((org.aspectj.apache.bcel.classfile.ConstantUtf8)c).getBytes(); - - case org.aspectj.apache.bcel.Constants.CONSTANT_Float: - return new Float(((org.aspectj.apache.bcel.classfile.ConstantFloat)c).getBytes()); - - case org.aspectj.apache.bcel.Constants.CONSTANT_Integer: - return new Integer(((org.aspectj.apache.bcel.classfile.ConstantInteger)c).getBytes()); - - default: // Never reached - throw new RuntimeException("Unknown or invalid constant type at " + index); - } - } - - public Type getType(ConstantPoolGen cpg) { - switch(cpg.getConstantPool().getConstant(index).getTag()) { - case org.aspectj.apache.bcel.Constants.CONSTANT_String: return Type.STRING; - case org.aspectj.apache.bcel.Constants.CONSTANT_Float: return Type.FLOAT; - case org.aspectj.apache.bcel.Constants.CONSTANT_Integer: return Type.INT; - default: // Never reached - throw new RuntimeException("Unknown or invalid constant type at " + index); - } - } - - public Class[] getExceptions() { - return org.aspectj.apache.bcel.ExceptionConstants.EXCS_STRING_RESOLUTION; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitCPInstruction(this); - v.visitLDC(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LDC2_W.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LDC2_W.java deleted file mode 100644 index 3f44a4f08..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LDC2_W.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LDC2_W - Push long or double from constant pool - * - *
          Stack: ... -> ..., item.word1, item.word2
          - * - * @version $Id: LDC2_W.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LDC2_W extends CPInstruction - implements PushInstruction, TypedInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - LDC2_W() {} - - public LDC2_W(int index) { - super(org.aspectj.apache.bcel.Constants.LDC2_W, index); - } - - public Type getType(ConstantPoolGen cpg) { - switch(cpg.getConstantPool().getConstant(index).getTag()) { - case org.aspectj.apache.bcel.Constants.CONSTANT_Long: return Type.LONG; - case org.aspectj.apache.bcel.Constants.CONSTANT_Double: return Type.DOUBLE; - default: // Never reached - throw new RuntimeException("Unknown constant type " + opcode); - } - } - - public Number getValue(ConstantPoolGen cpg) { - org.aspectj.apache.bcel.classfile.Constant c = cpg.getConstantPool().getConstant(index); - - switch(c.getTag()) { - case org.aspectj.apache.bcel.Constants.CONSTANT_Long: - return new Long(((org.aspectj.apache.bcel.classfile.ConstantLong)c).getBytes()); - - case org.aspectj.apache.bcel.Constants.CONSTANT_Double: - return new Double(((org.aspectj.apache.bcel.classfile.ConstantDouble)c).getBytes()); - - default: // Never reached - throw new RuntimeException("Unknown or invalid constant type at " + index); - } - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitTypedInstruction(this); - v.visitCPInstruction(this); - v.visitLDC2_W(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LDC_W.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LDC_W.java deleted file mode 100644 index 0269c1b7a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LDC_W.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.IOException; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * LDC_W - Push item from constant pool (wide index) - * - *
          Stack: ... -> ..., item.word1, item.word2
          - * - * @version $Id: LDC_W.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LDC_W extends LDC { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - LDC_W() {} - - public LDC_W(int index) { - super(index); - } - - /** - * Read needed data (i.e., index) from file. - */ - protected void initFromFile(ByteSequence bytes, boolean wide) - throws IOException - { - setIndex(bytes.readUnsignedShort()); - // Override just in case it has been changed - // opcode = org.aspectj.apache.bcel.Constants.LDC_W; - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LDIV.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LDIV.java deleted file mode 100644 index dd3ec5764..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LDIV.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LDIV - Divide longs - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result.word1, result.word2 - * - * @version $Id: LDIV.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LDIV extends ArithmeticInstruction implements ExceptionThrower { - public LDIV() { - super(org.aspectj.apache.bcel.Constants.LDIV); - } - - public Class[] getExceptions() { - return new Class[] { org.aspectj.apache.bcel.ExceptionConstants.ARITHMETIC_EXCEPTION }; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitLDIV(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LLOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LLOAD.java deleted file mode 100644 index ebd528d36..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LLOAD.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LLOAD - Load long from local variable - *
          Stack ... -> ..., result.word1, result.word2
          - * - * @version $Id: LLOAD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LLOAD extends LoadInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - LLOAD() { - super(org.aspectj.apache.bcel.Constants.LLOAD, org.aspectj.apache.bcel.Constants.LLOAD_0); - } - - public LLOAD(int n) { - super(org.aspectj.apache.bcel.Constants.LLOAD, org.aspectj.apache.bcel.Constants.LLOAD_0, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - super.accept(v); - v.visitLLOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LMUL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LMUL.java deleted file mode 100644 index 8a257f0c2..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LMUL.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LMUL - Multiply longs - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result.word1, result.word2 - * - * @version $Id: LMUL.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LMUL extends ArithmeticInstruction { - public LMUL() { - super(org.aspectj.apache.bcel.Constants.LMUL); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitLMUL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LNEG.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LNEG.java deleted file mode 100644 index a9535ea81..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LNEG.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LNEG - Negate long - *
          Stack: ..., value.word1, value.word2 -> ..., result.word1, result.word2
          - * - * @version $Id: LNEG.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LNEG extends ArithmeticInstruction { - public LNEG() { - super(org.aspectj.apache.bcel.Constants.LNEG); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitLNEG(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LOOKUPSWITCH.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LOOKUPSWITCH.java index c0540bd1e..14e0499dc 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LOOKUPSWITCH.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/LOOKUPSWITCH.java @@ -1,115 +1,115 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * LOOKUPSWITCH - Switch with unordered set of values - * - * @version $Id: LOOKUPSWITCH.java,v 1.2.10.2 2008/04/25 17:55:34 aclement Exp $ - * @author M. Dahm - * @see SWITCH - */ -public class LOOKUPSWITCH extends InstructionSelect { - - - public LOOKUPSWITCH(int[] match, InstructionHandle[] targets, - InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.LOOKUPSWITCH, match, targets, target); - - length = (short)(9 + match_length * 8); /* alignment remainder assumed - * 0 here, until dump time. */ - fixed_length = length; - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - super.dump(out); - out.writeInt(match_length); // npairs - - for(int i=0; i < match_length; i++) { - out.writeInt(match[i]); // match-offset pairs - out.writeInt(indices[i] = getTargetOffset(targets[i])); - } - } - - /** - * Read needed data (e.g. index) from file. - */ - public LOOKUPSWITCH(ByteSequence bytes) throws IOException - { - super(Constants.LOOKUPSWITCH,bytes); // reads padding - - match_length = bytes.readInt(); - fixed_length = (short)(9 + match_length * 8); - length = (short)(fixed_length + padding); - - match = new int[match_length]; - indices = new int[match_length]; - targets = new InstructionHandle[match_length]; - - for(int i=0; i < match_length; i++) { - match[i] = bytes.readInt(); - indices[i] = bytes.readInt(); - } - } - -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.io.*; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.util.ByteSequence; + +/** + * LOOKUPSWITCH - Switch with unordered set of values + * + * @version $Id: LOOKUPSWITCH.java,v 1.2.10.3 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + * @see SWITCH + */ +public class LOOKUPSWITCH extends InstructionSelect { + + + public LOOKUPSWITCH(int[] match, InstructionHandle[] targets, + InstructionHandle target) { + super(org.aspectj.apache.bcel.Constants.LOOKUPSWITCH, match, targets, target); + + length = (short)(9 + matchLength * 8); /* alignment remainder assumed + * 0 here, until dump time. */ + fixedLength = length; + } + + /** + * Dump instruction as byte code to stream out. + * @param out Output stream + */ + public void dump(DataOutputStream out) throws IOException { + super.dump(out); + out.writeInt(matchLength); // npairs + + for(int i=0; i < matchLength; i++) { + out.writeInt(match[i]); // match-offset pairs + out.writeInt(indices[i] = getTargetOffset(targets[i])); + } + } + + /** + * Read needed data (e.g. index) from file. + */ + public LOOKUPSWITCH(ByteSequence bytes) throws IOException + { + super(Constants.LOOKUPSWITCH,bytes); // reads padding + + matchLength = bytes.readInt(); + fixedLength = (short)(9 + matchLength * 8); + length = (short)(fixedLength + padding); + + match = new int[matchLength]; + indices = new int[matchLength]; + targets = new InstructionHandle[matchLength]; + + for(int i=0; i < matchLength; i++) { + match[i] = bytes.readInt(); + indices[i] = bytes.readInt(); + } + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LOR.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LOR.java deleted file mode 100644 index 0a2675cd0..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LOR.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LOR - Bitwise OR long - *
          Stack: ..., value1, value2 -> ..., result
          - * - * @version $Id: LOR.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LOR extends ArithmeticInstruction { - public LOR() { - super(org.aspectj.apache.bcel.Constants.LOR); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitLOR(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LREM.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LREM.java deleted file mode 100644 index c435cd118..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LREM.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LREM - Remainder of long - *
          Stack: ..., value1, value2 -> result
          - * - * @version $Id: LREM.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LREM extends ArithmeticInstruction implements ExceptionThrower { - public LREM() { - super(org.aspectj.apache.bcel.Constants.LREM); - } - - public Class[] getExceptions() { return new Class[] { org.aspectj.apache.bcel.ExceptionConstants.ARITHMETIC_EXCEPTION }; } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitLREM(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LRETURN.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LRETURN.java deleted file mode 100644 index f8562dca7..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LRETURN.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LRETURN - Return long from method - *
          Stack: ..., value.word1, value.word2 -> <empty>
          - * - * @version $Id: LRETURN.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LRETURN extends ReturnInstruction { - public LRETURN() { - super(org.aspectj.apache.bcel.Constants.LRETURN); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackConsumer(this); - v.visitReturnInstruction(this); - v.visitLRETURN(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LSHL.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LSHL.java deleted file mode 100644 index 90fbaba48..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LSHL.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LSHL - Arithmetic shift left long - *
          Stack: ..., value1.word1, value1.word2, value2 -> ..., result.word1, result.word2
          - * - * @version $Id: LSHL.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LSHL extends ArithmeticInstruction { - public LSHL() { - super(org.aspectj.apache.bcel.Constants.LSHL); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitLSHL(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LSHR.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LSHR.java deleted file mode 100644 index 002986e21..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LSHR.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LSHR - Arithmetic shift right long - *
          Stack: ..., value1.word1, value1.word2, value2 -> ..., result.word1, result.word2
          - * - * @version $Id: LSHR.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LSHR extends ArithmeticInstruction { - public LSHR() { - super(org.aspectj.apache.bcel.Constants.LSHR); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitLSHR(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LSTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LSTORE.java deleted file mode 100644 index cfa54370a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LSTORE.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LSTORE - Store long into local variable - *
          Stack: ..., value.word1, value.word2 -> ... 
          - * - * @version $Id: LSTORE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LSTORE extends StoreInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - LSTORE() { - super(org.aspectj.apache.bcel.Constants.LSTORE, org.aspectj.apache.bcel.Constants.LSTORE_0); - } - - public LSTORE(int n) { - super(org.aspectj.apache.bcel.Constants.LSTORE, org.aspectj.apache.bcel.Constants.LSTORE_0, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - super.accept(v); - v.visitLSTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LSUB.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LSUB.java deleted file mode 100644 index 6a8b92601..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LSUB.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LSUB - Substract longs - *
          Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 ->
          - * ..., result.word1, result.word2 - * - * @version $Id: LSUB.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class LSUB extends ArithmeticInstruction { - public LSUB() { - super(org.aspectj.apache.bcel.Constants.LSUB); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitLSUB(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LUSHR.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LUSHR.java deleted file mode 100644 index b3ba61c8e..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LUSHR.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LUSHR - Logical shift right long - *
          Stack: ..., value1, value2 -> ..., result
          - * - * @version $Id: LUSHR.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class LUSHR extends ArithmeticInstruction { - public LUSHR() { - super(org.aspectj.apache.bcel.Constants.LUSHR); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitLUSHR(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LXOR.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LXOR.java deleted file mode 100644 index a8304ec26..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LXOR.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * LXOR - Bitwise XOR long - *
          Stack: ..., value1, value2 -> ..., result
          - * - * @version $Id: LXOR.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class LXOR extends ArithmeticInstruction { - public LXOR() { - super(org.aspectj.apache.bcel.Constants.LXOR); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitTypedInstruction(this); - v.visitStackProducer(this); - v.visitStackConsumer(this); - v.visitArithmeticInstruction(this); - v.visitLXOR(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LineNumberGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LineNumberGen.java index 76e1fa8d2..a7f191a59 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LineNumberGen.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/LineNumberGen.java @@ -1,130 +1,130 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.classfile.LineNumber; - -/** - * This class represents a line number within a method, i.e., give an instruction - * a line number corresponding to the source code line. - * - * @version $Id: LineNumberGen.java,v 1.4.10.2 2008/04/25 17:55:32 aclement Exp $ - * @author M. Dahm - * @see LineNumber - * @see MethodGen - */ -public class LineNumberGen - implements InstructionTargeter, Cloneable, java.io.Serializable -{ - private InstructionHandle ih; - private int src_line; - - /** - * Create a line number. - * - * @param ih instruction handle to reference - */ - public LineNumberGen(InstructionHandle ih, int src_line) { - setInstruction(ih); - setSourceLine(src_line); - } - - /** - * @return true, if ih is target of this line number - */ - public boolean containsTarget(InstructionHandle ih) { - return this.ih == ih; - } - - /** - * @param old_ih old target - * @param new_ih new target - */ - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { - if(old_ih != ih) - throw new ClassGenException("Not targeting " + old_ih + ", but " + ih + "}"); - else - setInstruction(new_ih); - } - - /** - * Get LineNumber attribute . - * - * This relies on that the instruction list has already been dumped to byte code or - * or that the `setPositions' methods has been called for the instruction list. - */ - public LineNumber getLineNumber() { - return new LineNumber(ih.getPosition(), src_line); - } - - public void setInstruction(InstructionHandle ih) { - InstructionBranch.notifyTarget(this.ih, ih, this); - - this.ih = ih; - } - - public Object clone() { - try { - return super.clone(); - } catch(CloneNotSupportedException e) { - System.err.println(e); - return null; - } - } - - public InstructionHandle getInstruction() { return ih; } - public void setSourceLine(int src_line) { this.src_line = src_line; } - public int getSourceLine() { return src_line; } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.classfile.LineNumber; + +/** + * This class represents a line number within a method, i.e., give an instruction + * a line number corresponding to the source code line. + * + * @version $Id: LineNumberGen.java,v 1.4.10.3 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + * @see LineNumber + * @see MethodGen + */ +public class LineNumberGen + implements InstructionTargeter, Cloneable, java.io.Serializable +{ + private InstructionHandle ih; + private int src_line; + + /** + * Create a line number. + * + * @param ih instruction handle to reference + */ + public LineNumberGen(InstructionHandle ih, int src_line) { + setInstruction(ih); + setSourceLine(src_line); + } + + /** + * @return true, if ih is target of this line number + */ + public boolean containsTarget(InstructionHandle ih) { + return this.ih == ih; + } + + /** + * @param old_ih old target + * @param new_ih new target + */ + public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { + if(old_ih != ih) + throw new ClassGenException("Not targeting " + old_ih + ", but " + ih + "}"); + else + setInstruction(new_ih); + } + + /** + * Get LineNumber attribute . + * + * This relies on that the instruction list has already been dumped to byte code or + * or that the `setPositions' methods has been called for the instruction list. + */ + public LineNumber getLineNumber() { + return new LineNumber(ih.getPosition(), src_line); + } + + public void setInstruction(InstructionHandle ih) { + InstructionBranch.notifyTarget(this.ih, ih, this); + + this.ih = ih; + } + + public Object clone() { + try { + return super.clone(); + } catch(CloneNotSupportedException e) { + System.err.println(e); + return null; + } + } + + public InstructionHandle getInstruction() { return ih; } + public void setSourceLine(int src_line) { this.src_line = src_line; } + public int getSourceLine() { return src_line; } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LineNumberTag.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LineNumberTag.java index eaa564f96..fe1d56c27 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LineNumberTag.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/LineNumberTag.java @@ -1,40 +1,44 @@ -/* ******************************************************************* - * Copyright (c) 2002 Contributors - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * PARC initial implementation - * Andy Clement pushed down into bcel module - * ******************************************************************/ - - -package org.aspectj.apache.bcel.generic; - -/** we don't actually target instructions, but instructions target us. */ -public class LineNumberTag extends Tag { - - private final int lineNumber; - - public LineNumberTag(int lineNumber) { - this.lineNumber = lineNumber; - } - - public int getLineNumber() { return lineNumber; } - - // ---- from Object - - public String toString() { - return "line " + lineNumber; - } - public boolean equals(Object other) { - if (! (other instanceof LineNumberTag)) return false; - return lineNumber == ((LineNumberTag)other).lineNumber; - } - public int hashCode() { - return lineNumber; - } -} +/* ******************************************************************* + * Copyright (c) 2002 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * PARC initial implementation + * Andy Clement pushed down into bcel module + * ******************************************************************/ + + +package org.aspectj.apache.bcel.generic; + +/** + * we don't actually target instructions, but instructions target us. + */ +public class LineNumberTag extends Tag { + + private final int lineNumber; + + public LineNumberTag(int lineNumber) { + this.lineNumber = lineNumber; + } + + public int getLineNumber() { + return lineNumber; + } + + public String toString() { + return "line " + lineNumber; + } + + public boolean equals(Object other) { + if (!(other instanceof LineNumberTag)) return false; + return lineNumber == ((LineNumberTag)other).lineNumber; + } + + public int hashCode() { + return lineNumber; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LoadClass.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LoadClass.java deleted file mode 100644 index 8f2679db1..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LoadClass.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denotes that an instruction may start the process of loading and resolving - * the referenced class in the Virtual Machine. - * - * @version $Id: LoadClass.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public interface LoadClass { - /** - * Returns the ObjectType of the referenced class or interface - * that may be loaded and resolved. - * @return object type that may be loaded or null if a primitive is - * referenced - */ - public ObjectType getLoadClassType(ConstantPoolGen cpg); - - /** - * Returns the type associated with this instruction. - * LoadClass instances are always typed, but this type - * does not always refer to the type of the class or interface - * that it possibly forces to load. For example, GETFIELD would - * return the type of the field and not the type of the class - * where the field is defined. - * If no class is forced to be loaded, null is returned. - * An example for this is an ANEWARRAY instruction that creates - * an int[][]. - * @see #getLoadClassType(ConstantPoolGen) - */ - public Type getType(ConstantPoolGen cpg); -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LocalVariableGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LocalVariableGen.java index 3638224f7..c7bcb4af3 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LocalVariableGen.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/LocalVariableGen.java @@ -1,206 +1,206 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.LocalVariable; -import org.aspectj.apache.bcel.classfile.ConstantPool; - -/** - * This class represents a local variable within a method. It contains its - * scope, name and type. The generated LocalVariable object can be obtained - * with getLocalVariable which needs the instruction list and the constant - * pool as parameters. - * - * @version $Id: LocalVariableGen.java,v 1.5.8.2 2008/04/25 17:55:33 aclement Exp $ - * @author M. Dahm - * @see LocalVariable - * @see MethodGen - */ -public class LocalVariableGen - implements InstructionTargeter, NamedAndTyped, Cloneable, - java.io.Serializable -{ - private int index; - private String name; - private Type type; - private InstructionHandle start, end; - - /** - * Generate a local variable that with index `index'. Note that double and long - * variables need two indexs. Index indices have to be provided by the user. - * - * @param index index of local variable - * @param name its name - * @param type its type - * @param start from where the instruction is valid (null means from the start) - * @param end until where the instruction is valid (null means to the end) - */ - public LocalVariableGen(int index, String name, Type type, - InstructionHandle start, InstructionHandle end) { - if((index < 0) || (index > Constants.MAX_SHORT)) - throw new ClassGenException("Invalid index index: " + index); - - this.name = name; - this.type = type; - this.index = index; - setStart(start); - setEnd(end); - } - - /** - * Get LocalVariable object. - * - * This relies on that the instruction list has already been dumped to byte code or - * or that the `setPositions' methods has been called for the instruction list. - * - * Note that for local variables whose scope end at the last - * instruction of the method's code, the JVM specification is ambiguous: - * both a start_pc+length ending at the last instruction and - * start_pc+length ending at first index beyond the end of the code are - * valid. - * - * @param il instruction list (byte code) which this variable belongs to - * @param cp constant pool - */ - public LocalVariable getLocalVariable(ConstantPool cp) { - int start_pc = start.getPosition(); - int length = end.getPosition() - start_pc; - - if(length > 0) { - length += end.getInstruction().getLength(); - } - - int name_index = cp.addUtf8(name); - int signature_index = cp.addUtf8(type.getSignature()); - - return new LocalVariable(start_pc, length, name_index, - signature_index, index, cp); - } - - public void setIndex(int index) { this.index = index; } - public int getIndex() { return index; } - public void setName(String name) { this.name = name; } - public String getName() { return name; } - public void setType(Type type) { this.type = type; } - public Type getType() { return type; } - - public InstructionHandle getStart() { return start; } - public InstructionHandle getEnd() { return end; } - - public void setStart(InstructionHandle start) { - InstructionBranch.notifyTarget(this.start, start, this); - this.start = start; - } - - public void setEnd(InstructionHandle end) { - InstructionBranch.notifyTarget(this.end, end, this); - this.end = end; - } - - /** - * @param old_ih old target, either start or end - * @param new_ih new target - */ - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { - boolean targeted = false; - - if(start == old_ih) { - targeted = true; - setStart(new_ih); - } - - if(end == old_ih) { - targeted = true; - setEnd(new_ih); - } - - if(!targeted) - throw new ClassGenException("Not targeting " + old_ih + ", but {" + start + ", " + - end + "}"); - } - - /** - * @return true, if ih is target of this variable - */ - public boolean containsTarget(InstructionHandle ih) { - return (start == ih) || (end == ih); - } - - /** - * We consider to local variables to be equal, if the use the same index and - * are valid in the same range. - */ - public boolean equals(Object o) { - if(!(o instanceof LocalVariableGen)) - return false; - - LocalVariableGen l = (LocalVariableGen)o; - return (l.index == index) && (l.start == start) && (l.end == end); - } - - public String toString() { - return "LocalVariableGen(" + name + ", " + type + ", " + start + ", " + end + ")"; - } - - public Object clone() { - try { - return super.clone(); - } catch(CloneNotSupportedException e) { - System.err.println(e); - return null; - } - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.LocalVariable; +import org.aspectj.apache.bcel.classfile.ConstantPool; + +/** + * This class represents a local variable within a method. It contains its + * scope, name and type. The generated LocalVariable object can be obtained + * with getLocalVariable which needs the instruction list and the constant + * pool as parameters. + * + * @version $Id: LocalVariableGen.java,v 1.5.8.3 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + * @see LocalVariable + * @see MethodGen + */ +public class LocalVariableGen + implements InstructionTargeter, /*NamedAndTyped,*/ Cloneable, + java.io.Serializable +{ + private int index; + private String name; + private Type type; + private InstructionHandle start, end; + + /** + * Generate a local variable that with index `index'. Note that double and long + * variables need two indexs. Index indices have to be provided by the user. + * + * @param index index of local variable + * @param name its name + * @param type its type + * @param start from where the instruction is valid (null means from the start) + * @param end until where the instruction is valid (null means to the end) + */ + public LocalVariableGen(int index, String name, Type type, + InstructionHandle start, InstructionHandle end) { + if((index < 0) || (index > Constants.MAX_SHORT)) + throw new ClassGenException("Invalid index index: " + index); + + this.name = name; + this.type = type; + this.index = index; + setStart(start); + setEnd(end); + } + + /** + * Get LocalVariable object. + * + * This relies on that the instruction list has already been dumped to byte code or + * or that the `setPositions' methods has been called for the instruction list. + * + * Note that for local variables whose scope end at the last + * instruction of the method's code, the JVM specification is ambiguous: + * both a start_pc+length ending at the last instruction and + * start_pc+length ending at first index beyond the end of the code are + * valid. + * + * @param il instruction list (byte code) which this variable belongs to + * @param cp constant pool + */ + public LocalVariable getLocalVariable(ConstantPool cp) { + int start_pc = start.getPosition(); + int length = end.getPosition() - start_pc; + + if(length > 0) { + length += end.getInstruction().getLength(); + } + + int name_index = cp.addUtf8(name); + int signature_index = cp.addUtf8(type.getSignature()); + + return new LocalVariable(start_pc, length, name_index, + signature_index, index, cp); + } + + public void setIndex(int index) { this.index = index; } + public int getIndex() { return index; } + public void setName(String name) { this.name = name; } + public String getName() { return name; } + public void setType(Type type) { this.type = type; } + public Type getType() { return type; } + + public InstructionHandle getStart() { return start; } + public InstructionHandle getEnd() { return end; } + + public void setStart(InstructionHandle start) { + InstructionBranch.notifyTarget(this.start, start, this); + this.start = start; + } + + public void setEnd(InstructionHandle end) { + InstructionBranch.notifyTarget(this.end, end, this); + this.end = end; + } + + /** + * @param old_ih old target, either start or end + * @param new_ih new target + */ + public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { + boolean targeted = false; + + if(start == old_ih) { + targeted = true; + setStart(new_ih); + } + + if(end == old_ih) { + targeted = true; + setEnd(new_ih); + } + + if(!targeted) + throw new ClassGenException("Not targeting " + old_ih + ", but {" + start + ", " + + end + "}"); + } + + /** + * @return true, if ih is target of this variable + */ + public boolean containsTarget(InstructionHandle ih) { + return (start == ih) || (end == ih); + } + + /** + * We consider to local variables to be equal, if the use the same index and + * are valid in the same range. + */ + public boolean equals(Object o) { + if(!(o instanceof LocalVariableGen)) + return false; + + LocalVariableGen l = (LocalVariableGen)o; + return (l.index == index) && (l.start == start) && (l.end == end); + } + + public String toString() { + return "LocalVariableGen(" + name + ", " + type + ", " + start + ", " + end + ")"; + } + + public Object clone() { + try { + return super.clone(); + } catch(CloneNotSupportedException e) { + System.err.println(e); + return null; + } + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LocalVariableInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LocalVariableInstruction.java deleted file mode 100644 index 128231cf2..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LocalVariableInstruction.java +++ /dev/null @@ -1,224 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.DataOutputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * Abstract super class for instructions dealing with local variables. - * - * @version $Id: LocalVariableInstruction.java,v 1.5 2006/11/29 13:43:01 aclement Exp $ - * @author M. Dahm - */ -public abstract class LocalVariableInstruction extends Instruction - implements TypedInstruction, IndexedInstruction { - protected int n = -1; // index of referenced variable - private short c_tag = -1; // compact version, such as ILOAD_0 - private short canon_tag = -1; // canonical tag such as ILOAD - - private final boolean wide() { return n > Constants.MAX_BYTE; } - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - * tag and length are defined in readInstruction and initFromFile, respectively. - */ - LocalVariableInstruction(short canon_tag, short c_tag) { - super(); - this.canon_tag = canon_tag; - this.c_tag = c_tag; - } - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Also used by IINC()! - */ - LocalVariableInstruction() { - } - - /** - * @param opcode Instruction opcode - * @param c_tag Instruction number for compact version, ALOAD_0, e.g. - * @param n local variable index (unsigned short) - */ - protected LocalVariableInstruction(short opcode, short c_tag, int n) { - super(opcode, (short)2); - - this.c_tag = c_tag; - canon_tag = opcode; - - setIndex(n); - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - if(wide()) // Need WIDE prefix ? - out.writeByte(Constants.WIDE); - - out.writeByte(opcode); - - if(length > 1) { // Otherwise ILOAD_n, instruction, e.g. - if(wide()) - out.writeShort(n); - else - out.writeByte(n); - } - } - - /** - * Long output format: - * - * <name of opcode> "["<opcode number>"]" - * "("<length of instruction>")" "<"< local variable index>">" - * - * @param verbose long/short format switch - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - if(((opcode >= Constants.ILOAD_0) && - (opcode <= Constants.ALOAD_3)) || - ((opcode >= Constants.ISTORE_0) && - (opcode <= Constants.ASTORE_3))) - return super.toString(verbose); - else - return super.toString(verbose) + " " + n; - } - - /** - * Read needed data (e.g. index) from file. - * PRE: (ILOAD <= tag <= ALOAD_3) || (ISTORE <= tag <= ASTORE_3) - */ - protected void initFromFile(ByteSequence bytes, boolean wide) - throws IOException - { - if(wide) { - n = bytes.readUnsignedShort(); - } else if(((opcode >= Constants.ILOAD) && - (opcode <= Constants.ALOAD)) || - ((opcode >= Constants.ISTORE) && - (opcode <= Constants.ASTORE))) { - n = bytes.readUnsignedByte(); - } else if(opcode <= Constants.ALOAD_3) { // compact load instruction such as ILOAD_2 - n = (opcode - Constants.ILOAD_0) % 4; - } else { // Assert ISTORE_0 <= tag <= ASTORE_3 - n = (opcode - Constants.ISTORE_0) % 4; - } - workOutLength(); - } - - private void workOutLength() { - if(n >= 0 && n <= 3) { // Use more compact instruction xLOAD_n - opcode = (short)(c_tag + n); - length = 1; - } else { - opcode = canon_tag; - if(wide()) length = 4; - else length = 2; - } - } - - /** - * @return local variable index referred by this instruction. - */ - public final int getIndex() { return n; } - - /** - * Set the local variable index - */ - public void setIndex(int n) { - if((n < 0) || (n > Constants.MAX_SHORT)) - throw new ClassGenException("Illegal value: " + n); - - this.n = n; - workOutLength(); - } - - /** @return canonical tag for instruction, e.g., ALOAD for ALOAD_0 - */ - public short getCanonicalTag() { - return canon_tag; - } - - /** - * Returns the type associated with the instruction - - * in case of ALOAD or ASTORE Type.OBJECT is returned. - * This is just a bit incorrect, because ALOAD and ASTORE - * may work on every ReferenceType (including Type.NULL) and - * ASTORE may even work on a ReturnaddressType . - * @return type associated with the instruction - */ - public Type getType(ConstantPoolGen cp) { - switch(canon_tag) { - case Constants.ILOAD: case Constants.ISTORE: - return Type.INT; - case Constants.LLOAD: case Constants.LSTORE: - return Type.LONG; - case Constants.DLOAD: case Constants.DSTORE: - return Type.DOUBLE; - case Constants.FLOAD: case Constants.FSTORE: - return Type.FLOAT; - case Constants.ALOAD: case Constants.ASTORE: - return Type.OBJECT; - - default: throw new ClassGenException("Oops: unknown case in switch" + canon_tag); - } - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/LocalVariableTag.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/LocalVariableTag.java index 34db9fd5f..ffe857079 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/LocalVariableTag.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/LocalVariableTag.java @@ -1,79 +1,77 @@ -/* ******************************************************************* - * Copyright (c) 2002 Contributors - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * PARC initial implementation - * Andy Clement pushed down into bcel module - * ******************************************************************/ - - -package org.aspectj.apache.bcel.generic; - -public final class LocalVariableTag extends Tag { - private Type type; // not always known, in which case signature has to be used - private final String signature; - private final String name; - private int slot; - private final int startPos; - boolean remapped = false; - - // AMC - pr101047, two local vars with the same name can share the same slot, but must in that case - // have different start positions. - public LocalVariableTag(String sig, String name, int slot, int startPosition) { - this.signature = sig; - this.name = name; - this.slot = slot; - this.startPos = startPosition; - } - - public LocalVariableTag(Type t,String sig, String name, int slot, int startPosition) { - this.type = t; - this.signature = sig; - this.name = name; - this.slot = slot; - this.startPos = startPosition; - } - - - public String getName() {return name;} - public int getSlot() {return slot;} - public String getType() {return signature;} - public Type getRealType() {return type;} - - public void updateSlot(int newSlot) { - this.slot = newSlot; - this.remapped = true; - } - - public boolean isRemapped() { return this.remapped; } - - // ---- from Object - - public String toString() { - return "local " + slot + ": " + signature + " " + name; - } - - public boolean equals(Object other) { - if (!(other instanceof LocalVariableTag)) return false; - LocalVariableTag o = (LocalVariableTag)other; - return o.slot == slot && o.startPos == startPos && o.signature.equals(signature) && o.name.equals(name); - } - - private int hashCode = 0; - public int hashCode() { - if (hashCode == 0) { - int ret = 17; - ret = 37*ret + signature.hashCode(); - ret = 37*ret + name.hashCode(); - ret = 37*ret + slot; - ret = 37*ret + startPos; - hashCode = ret; - } - return hashCode; - } -} +/* ******************************************************************* + * Copyright (c) 2002 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * PARC initial implementation + * Andy Clement pushed down into bcel module + * ******************************************************************/ + + +package org.aspectj.apache.bcel.generic; + +public final class LocalVariableTag extends Tag { + private Type type; // not always known, in which case signature has to be used + private final String signature; + private final String name; + private int slot; + private final int startPos; + boolean remapped = false; + + // AMC - pr101047, two local vars with the same name can share the same slot, but must in that case + // have different start positions. + public LocalVariableTag(String sig, String name, int slot, int startPosition) { + this.signature = sig; + this.name = name; + this.slot = slot; + this.startPos = startPosition; + } + + public LocalVariableTag(Type t,String sig, String name, int slot, int startPosition) { + this.type = t; + this.signature = sig; + this.name = name; + this.slot = slot; + this.startPos = startPosition; + } + + + public String getName() {return name;} + public int getSlot() {return slot;} + public String getType() {return signature;} + public Type getRealType() {return type;} + + public void updateSlot(int newSlot) { + this.slot = newSlot; + this.remapped = true; + } + + public boolean isRemapped() { return this.remapped; } + + public String toString() { + return "local " + slot + ": " + signature + " " + name; + } + + public boolean equals(Object other) { + if (!(other instanceof LocalVariableTag)) return false; + LocalVariableTag o = (LocalVariableTag)other; + return o.slot == slot && o.startPos == startPos && o.signature.equals(signature) && o.name.equals(name); + } + + private int hashCode = 0; + public int hashCode() { + if (hashCode == 0) { + int ret = 17; + ret = 37*ret + signature.hashCode(); + ret = 37*ret + name.hashCode(); + ret = 37*ret + slot; + ret = 37*ret + startPos; + hashCode = ret; + } + return hashCode; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/MONITORENTER.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/MONITORENTER.java deleted file mode 100644 index 26dbc258b..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/MONITORENTER.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * MONITORENTER - Enter monitor for object - *
          Stack: ..., objectref -> ...
          - * - * @version $Id: MONITORENTER.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class MONITORENTER extends Instruction - implements ExceptionThrower, StackConsumer { - public MONITORENTER() { - super(org.aspectj.apache.bcel.Constants.MONITORENTER, (short)1); - } - - public Class[] getExceptions() { - return new Class[] { org.aspectj.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION }; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitStackConsumer(this); - v.visitMONITORENTER(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/MONITOREXIT.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/MONITOREXIT.java deleted file mode 100644 index 986eb4ea9..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/MONITOREXIT.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * MONITOREXIT - Exit monitor for object - *
          Stack: ..., objectref -> ...
          - * - * @version $Id: MONITOREXIT.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class MONITOREXIT extends Instruction - implements ExceptionThrower, StackConsumer { - public MONITOREXIT() { - super(org.aspectj.apache.bcel.Constants.MONITOREXIT, (short)1); - } - - public Class[] getExceptions() { - return new Class[] { org.aspectj.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION }; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitStackConsumer(this); - v.visitMONITOREXIT(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/MULTIANEWARRAY.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/MULTIANEWARRAY.java index ddaf89044..2774b3de8 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/MULTIANEWARRAY.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/MULTIANEWARRAY.java @@ -1,161 +1,161 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.ExceptionConstants; - -/** - * MULTIANEWARRAY - Create new mutidimensional array of references - *
          Stack: ..., count1, [count2, ...] -> ..., arrayref
          - * - * @version $Id: MULTIANEWARRAY.java,v 1.2.10.2 2008/04/25 17:55:33 aclement Exp $ - * @author M. Dahm - */ -public class MULTIANEWARRAY extends InstructionCP { - private short dimensions; - - public MULTIANEWARRAY(int index, short dimensions) { - super(Constants.MULTIANEWARRAY, index); - this.dimensions = dimensions; - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - out.writeByte(opcode); - out.writeShort(index); - out.writeByte(dimensions); - } - - /** - * Read needed data (i.e., no. dimension) from file. - */ -// protected void initFromFile(ByteSequence bytes, boolean wide) -// throws IOException -// { -// super.initFromFile(bytes, wide); -// dimensions = bytes.readByte(); -//// length = 4; -// } - - /** - * @return number of dimensions to be created - */ - public final short getDimensions() { return dimensions; } - - /** - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - return super.toString(verbose) + " " + index + " " + dimensions; - } - - /** - * @return mnemonic for instruction with symbolic references resolved - */ - public String toString(ConstantPool cp) { - return super.toString(cp) + " " + dimensions; - } - - /** - * Also works for instructions whose stack effect depends on the - * constant pool entry they reference. - * @return Number of words consumed from stack by this instruction - */ - public int consumeStack(ConstantPool cpg) { return dimensions; } - - public Class[] getExceptions() { - Class[] cs = new Class[2 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length]; - - System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, - cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length); - - cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length+1] = ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION; - cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.ILLEGAL_ACCESS_ERROR; - - return cs; - } - - public ObjectType getLoadClassType(ConstantPool cpg) { - Type t = getType(cpg); - - if (t instanceof ArrayType){ - t = ((ArrayType) t).getBasicType(); - } - - return (t instanceof ObjectType)? (ObjectType) t : null; - } - -// /** -// * Call corresponding visitor method(s). The order is: -// * Call visitor methods of implemented interfaces first, then -// * call methods according to the class hierarchy in descending order, -// * i.e., the most specific visitXXX() call comes last. -// * -// * @param v Visitor object -// */ -// public void accept(Visitor v) { -// v.visitLoadClass(this); -// v.visitAllocationInstruction(this); -// v.visitExceptionThrower(this); -// v.visitTypedInstruction(this); -// v.visitCPInstruction(this); -// v.visitMULTIANEWARRAY(this); -// } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.io.*; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.ExceptionConstants; + +/** + * MULTIANEWARRAY - Create new mutidimensional array of references + *
          Stack: ..., count1, [count2, ...] -> ..., arrayref
          + * + * @version $Id: MULTIANEWARRAY.java,v 1.2.10.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public class MULTIANEWARRAY extends InstructionCP { + private short dimensions; + + public MULTIANEWARRAY(int index, short dimensions) { + super(Constants.MULTIANEWARRAY, index); + this.dimensions = dimensions; + } + + /** + * Dump instruction as byte code to stream out. + * @param out Output stream + */ + public void dump(DataOutputStream out) throws IOException { + out.writeByte(opcode); + out.writeShort(index); + out.writeByte(dimensions); + } + + /** + * Read needed data (i.e., no. dimension) from file. + */ +// protected void initFromFile(ByteSequence bytes, boolean wide) +// throws IOException +// { +// super.initFromFile(bytes, wide); +// dimensions = bytes.readByte(); +//// length = 4; +// } + + /** + * @return number of dimensions to be created + */ + public final short getDimensions() { return dimensions; } + + /** + * @return mnemonic for instruction + */ + public String toString(boolean verbose) { + return super.toString(verbose) + " " + index + " " + dimensions; + } + + /** + * @return mnemonic for instruction with symbolic references resolved + */ + public String toString(ConstantPool cp) { + return super.toString(cp) + " " + dimensions; + } + + /** + * Also works for instructions whose stack effect depends on the + * constant pool entry they reference. + * @return Number of words consumed from stack by this instruction + */ + public int consumeStack(ConstantPool cpg) { return dimensions; } + + public Class[] getExceptions() { + Class[] cs = new Class[2 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length]; + + System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, + cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length); + + cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length+1] = ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION; + cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.ILLEGAL_ACCESS_ERROR; + + return cs; + } + + public ObjectType getLoadClassType(ConstantPool cpg) { + Type t = getType(cpg); + + if (t instanceof ArrayType){ + t = ((ArrayType) t).getBasicType(); + } + + return (t instanceof ObjectType)? (ObjectType) t : null; + } + +// /** +// * Call corresponding visitor method(s). The order is: +// * Call visitor methods of implemented interfaces first, then +// * call methods according to the class hierarchy in descending order, +// * i.e., the most specific visitXXX() call comes last. +// * +// * @param v Visitor object +// */ +// public void accept(Visitor v) { +// v.visitLoadClass(this); +// v.visitAllocationInstruction(this); +// v.visitExceptionThrower(this); +// v.visitTypedInstruction(this); +// v.visitCPInstruction(this); +// v.visitMULTIANEWARRAY(this); +// } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java index fc66eb02b..b351a985c 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java @@ -1,1122 +1,1083 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Stack; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.Attribute; -import org.aspectj.apache.bcel.classfile.Code; -import org.aspectj.apache.bcel.classfile.CodeException; -import org.aspectj.apache.bcel.classfile.ExceptionTable; -import org.aspectj.apache.bcel.classfile.LineNumber; -import org.aspectj.apache.bcel.classfile.LineNumberTable; -import org.aspectj.apache.bcel.classfile.LocalVariable; -import org.aspectj.apache.bcel.classfile.LocalVariableTable; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.classfile.Utility; -import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeParameterAnnotations; - -/** - * Template class for building up a method. This is done by defining exception - * handlers, adding thrown exceptions, local variables and attributes, whereas - * the `LocalVariableTable' and `LineNumberTable' attributes will be set - * automatically for the code. Use stripAttributes() if you don't like this. - * - * While generating code it may be necessary to insert NOP operations. You can - * use the `removeNOPs' method to get rid off them. - * The resulting method object can be obtained via the `getMethod()' method. - * - * @version $Id: MethodGen.java,v 1.7.6.2 2008/04/25 17:55:34 aclement Exp $ - * @author M. Dahm - * @author Patrick C. Beard [setMaxStack()] - * @see InstructionList - * @see Method - */ -public class MethodGen extends FieldGenOrMethodGen { - private String class_name; - private Type[] arg_types; - private String[] arg_names; - private int max_locals; - private int max_stack; - private InstructionList il; - private boolean strip_attributes; - private int highestLineNumber = 0; - - private ArrayList variable_vec = new ArrayList(); - private ArrayList line_number_vec = new ArrayList(); - private ArrayList exception_vec = new ArrayList(); - private ArrayList throws_vec = new ArrayList(); - private ArrayList code_attrs_vec = new ArrayList(); - private List[] param_annotations; // Array of lists containing AnnotationGen objects - private boolean hasParameterAnnotations = false; - private boolean haveUnpackedParameterAnnotations = false; - - /** - * Declare method. If the method is non-static the constructor - * automatically declares a local variable `$this' in slot 0. The - * actual code is contained in the `il' parameter, which may further - * manipulated by the user. But he must take care not to remove any - * instruction (handles) that are still referenced from this object. - * - * For example one may not add a local variable and later remove the - * instructions it refers to without causing havoc. It is safe - * however if you remove that local variable, too. - * - * @param access_flags access qualifiers - * @param return_type method type - * @param arg_types argument types - * @param arg_names argument names (if this is null, default names will be provided - * for them) - * @param method_name name of method - * @param class_name class name containing this method (may be null, if you don't care) - * @param il instruction list associated with this method, may be null only for - * abstract or native methods - * @param cp constant pool - */ - public MethodGen(int access_flags, Type return_type, Type[] arg_types, - String[] arg_names, String method_name, String class_name, - InstructionList il, ConstantPool cp) { - setAccessFlags(access_flags); - setType(return_type); - setArgumentTypes(arg_types); - setArgumentNames(arg_names); - setName(method_name); - setClassName(class_name); - setInstructionList(il); - setConstantPool(cp); - - boolean abstract_ = isAbstract() || isNative(); - InstructionHandle start = null; - InstructionHandle end = null; - - if(!abstract_) { - start = il.getStart(); - end = il.getEnd(); - - /* Add local variables, namely the implicit `this' and the arguments - */ -// if(!isStatic() && (class_name != null)) { // Instance method -> `this' is local var 0 -// addLocalVariable("this", new ObjectType(class_name), start, end); -// } - } - - if(arg_types != null) { - int size = arg_types.length; - - for(int i=0; i < size; i++) { - if(Type.VOID == arg_types[i]) { - throw new ClassGenException("'void' is an illegal argument type for a method"); - } - } - - if(arg_names != null) { // Names for variables provided? - if(size != arg_names.length) - throw new ClassGenException("Mismatch in argument array lengths: " + - size + " vs. " + arg_names.length); - } else { // Give them dummy names -// arg_names = new String[size]; -// -// for(int i=0; i < size; i++) -// arg_names[i] = "arg" + i; -// -// setArgumentNames(arg_names); - } - - if(!abstract_) { - for(int i=0; i < size; i++) { -// addLocalVariable(arg_names[i], arg_types[i], start, end); - } - } - } - } - - public int getHighestlinenumber() { return highestLineNumber; } - - /** - * Instantiate from existing method. - * - * @param m method - * @param class_name class name containing this method - * @param cp constant pool - */ - - public MethodGen(Method m, String class_name, ConstantPool cp) { - this(m,class_name,cp,false); - } - - public MethodGen(Method m, String class_name, ConstantPool cp,boolean useTags) { - - this( - m.getAccessFlags(), - Type.getReturnType(m.getSignature()), - Type.getArgumentTypes(m.getSignature()), - null /* may be overridden anyway */, - m.getName(), - class_name, - ((m.getAccessFlags() & (Constants.ACC_ABSTRACT | Constants.ACC_NATIVE)) == 0)? new InstructionList(m.getCode().getCode()) : null, - cp); - - Attribute[] attributes = m.getAttributes(); - for (int i=0; i < attributes.length; i++) { - Attribute a = attributes[i]; - - if (a instanceof Code) { - Code c = (Code)a; - setMaxStack(c.getMaxStack()); - setMaxLocals(c.getMaxLocals()); - - CodeException[] ces = c.getExceptionTable(); - - InstructionHandle[] arrayOfInstructions = il.getInstructionsAsArray(); - - // process the exception table - // - - if (ces != null) { - for (int j = 0; j < ces.length; j++) { - CodeException ce = ces[j]; - int type = ce.getCatchType(); - ObjectType c_type = null; - - if (type > 0) { - String cen = m.getConstantPool().getConstantString_CONSTANTClass(type); - c_type = new ObjectType(cen); - } - - int end_pc = ce.getEndPC(); - int length = m.getCode().getCode().length; - - InstructionHandle end; - - if (length == end_pc) { // May happen, because end_pc is exclusive - end = il.getEnd(); - } else { - end = il.findHandle(end_pc, arrayOfInstructions);// il.findHandle(end_pc); - end = end.getPrev(); // Make it inclusive - } - - addExceptionHandler( - il.findHandle(ce.getStartPC(),arrayOfInstructions), - end, - il.findHandle(ce.getHandlerPC(),arrayOfInstructions), - c_type); - } - } - - Attribute[] codeAttrs = c.getAttributes(); - for (int j = 0; j < codeAttrs.length; j++) { - a = codeAttrs[j]; - - if (a instanceof LineNumberTable) { - LineNumber[] ln = ((LineNumberTable) a).getLineNumberTable(); - if (useTags) { - // abracadabra, lets create tags rather than linenumbergens. - for (int k = 0; k < ln.length; k++) { - LineNumber l = ln[k]; - int lnum = l.getLineNumber(); - if (lnum>highestLineNumber) highestLineNumber=lnum; - LineNumberTag lt = new LineNumberTag(lnum); +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Stack; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.Attribute; +import org.aspectj.apache.bcel.classfile.Code; +import org.aspectj.apache.bcel.classfile.CodeException; +import org.aspectj.apache.bcel.classfile.ExceptionTable; +import org.aspectj.apache.bcel.classfile.LineNumber; +import org.aspectj.apache.bcel.classfile.LineNumberTable; +import org.aspectj.apache.bcel.classfile.LocalVariable; +import org.aspectj.apache.bcel.classfile.LocalVariableTable; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.classfile.Utility; +import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeParameterAnnotations; + +/** + * Template class for building up a method. This is done by defining exception + * handlers, adding thrown exceptions, local variables and attributes, whereas + * the 'LocalVariableTable' and 'LineNumberTable' attributes will be set + * automatically for the code. Use stripAttributes() if you don't like this. + * + * While generating code it may be necessary to insert NOP operations. You can + * use the `removeNOPs' method to get rid off them. + * The resulting method object can be obtained via the `getMethod()' method. + * + * @version $Id: MethodGen.java,v 1.7.6.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + * @author Patrick C. Beard [setMaxStack()] + * @see InstructionList + * @see Method + */ +public class MethodGen extends FieldGenOrMethodGen { + private String classname; + private Type[] parameterTypes; + private String[] parameterNames; + private int maxLocals; + private int maxStack; + private InstructionList il; + + // Indicates whether to produce code attributes for LineNumberTable and LocalVariableTable, like javac -O + private boolean stripAttributes; + + private int highestLineNumber = 0; + + private ArrayList localVariablesList = new ArrayList(); + private ArrayList lineNumbersList = new ArrayList(); + private ArrayList exceptionsList = new ArrayList(); + private ArrayList throws_vec = new ArrayList(); + private ArrayList codeAttributesList = new ArrayList(); + private List[] param_annotations; // Array of lists containing AnnotationGen objects + private boolean hasParameterAnnotations = false; + private boolean haveUnpackedParameterAnnotations = false; + + /** + * Declare method. If the method is non-static the constructor + * automatically declares a local variable `$this' in slot 0. The + * actual code is contained in the `il' parameter, which may further + * manipulated by the user. But he must take care not to remove any + * instruction (handles) that are still referenced from this object. + * + * For example one may not add a local variable and later remove the + * instructions it refers to without causing havoc. It is safe + * however if you remove that local variable, too. + * + * @param access_flags access qualifiers + * @param return_type method type + * @param arg_types argument types + * @param arg_names argument names (if this is null, default names will be provided + * for them) + * @param method_name name of method + * @param class_name class name containing this method (may be null, if you don't care) + * @param il instruction list associated with this method, may be null only for + * abstract or native methods + * @param cp constant pool + */ + public MethodGen(int access_flags, Type return_type, Type[] arg_types, + String[] arg_names, String method_name, String class_name, + InstructionList il, ConstantPool cp) { + + this.modifiers = access_flags; + this.type = return_type; + this.parameterTypes = arg_types; + this.parameterNames = arg_names; + this.name = method_name; + this.classname = class_name; + this.il = il; + this.cp = cp; + + // OPTIMIZE this code messes with the local variables - do we need it? +// boolean abstract_ = isAbstract() || isNative(); +// InstructionHandle start = null; +// InstructionHandle end = null; +// +// if (!abstract_) { +// start = il.getStart(); +// end = il.getEnd(); +// +// /* Add local variables, namely the implicit `this' and the arguments +// */ +//// if(!isStatic() && (class_name != null)) { // Instance method -> `this' is local var 0 +//// addLocalVariable("this", new ObjectType(class_name), start, end); +//// } +// } + +// if(arg_types != null) { +// int size = arg_types.length; +// +// for(int i=0; i < size; i++) { +// if(Type.VOID == arg_types[i]) { +// throw new ClassGenException("'void' is an illegal argument type for a method"); +// } +// } +// +// if(arg_names != null) { // Names for variables provided? +// if(size != arg_names.length) +// throw new ClassGenException("Mismatch in argument array lengths: " + +// size + " vs. " + arg_names.length); +// } else { // Give them dummy names +//// arg_names = new String[size]; +//// +//// for(int i=0; i < size; i++) +//// arg_names[i] = "arg" + i; +//// +//// setArgumentNames(arg_names); +// } + +// if(!abstract_) { +// for(int i=0; i < size; i++) { +//// addLocalVariable(arg_names[i], arg_types[i], start, end); +// } +// } +// } + } + + public int getHighestlinenumber() { return highestLineNumber; } + + /** + * Instantiate from existing method. + * + * @param m method + * @param class_name class name containing this method + * @param cp constant pool + */ + + public MethodGen(Method m, String class_name, ConstantPool cp) { + this(m,class_name,cp,false); + } + + public MethodGen(Method m, String class_name, ConstantPool cp,boolean useTags) { + this( + m.getModifiers(), + // OPTIMIZE implementation of getReturnType() and getArgumentTypes() on Method seems weak + m.getReturnType(), + m.getArgumentTypes(), + null /* may be overridden anyway */, + m.getName(), + class_name, + ((m.getModifiers() & (Constants.ACC_ABSTRACT | Constants.ACC_NATIVE)) == 0)? new InstructionList(m.getCode().getCode()) : null, + cp); + + Attribute[] attributes = m.getAttributes(); + for (int i=0; i < attributes.length; i++) { + Attribute a = attributes[i]; + + if (a instanceof Code) { + Code c = (Code)a; + setMaxStack(c.getMaxStack()); + setMaxLocals(c.getMaxLocals()); + + CodeException[] ces = c.getExceptionTable(); + + InstructionHandle[] arrayOfInstructions = il.getInstructionsAsArray(); + + // process the exception table + // - + if (ces != null) { + for (int j = 0; j < ces.length; j++) { + CodeException ce = ces[j]; + int type = ce.getCatchType(); + ObjectType c_type = null; + + if (type > 0) { + String cen = m.getConstantPool().getConstantString_CONSTANTClass(type); + c_type = new ObjectType(cen); + } + + int end_pc = ce.getEndPC(); + int length = m.getCode().getCode().length; + + InstructionHandle end; + + if (length == end_pc) { // May happen, because end_pc is exclusive + end = il.getEnd(); + } else { + end = il.findHandle(end_pc, arrayOfInstructions);// il.findHandle(end_pc); + end = end.getPrev(); // Make it inclusive + } + + addExceptionHandler( + il.findHandle(ce.getStartPC(),arrayOfInstructions), + end, + il.findHandle(ce.getHandlerPC(),arrayOfInstructions), + c_type); + } + } + + Attribute[] codeAttrs = c.getAttributes(); + for (int j = 0; j < codeAttrs.length; j++) { + a = codeAttrs[j]; + + if (a instanceof LineNumberTable) { + LineNumber[] ln = ((LineNumberTable) a).getLineNumberTable(); + if (useTags) { + // abracadabra, lets create tags rather than linenumbergens. + for (int k = 0; k < ln.length; k++) { + LineNumber l = ln[k]; + int lnum = l.getLineNumber(); + if (lnum>highestLineNumber) highestLineNumber=lnum; + LineNumberTag lt = new LineNumberTag(lnum); il.findHandle(l.getStartPC(),arrayOfInstructions,true).addTargeter(lt); - } - } else { - for (int k = 0; k < ln.length; k++) { - LineNumber l = ln[k]; + } + } else { + for (int k = 0; k < ln.length; k++) { + LineNumber l = ln[k]; addLineNumber(il.findHandle(l.getStartPC(),arrayOfInstructions,true), - l.getLineNumber()); - } - } - } else if (a instanceof LocalVariableTable) { - - // Lets have a go at creating Tags directly - if (useTags) { - LocalVariable[] lv = ((LocalVariableTable) a).getLocalVariableTable(); - - for (int k = 0; k < lv.length; k++) { - LocalVariable l = lv[k]; - Type t = Type.getType(l.getSignature()); - LocalVariableTag lvt = new LocalVariableTag(t,l.getSignature(),l.getName(),l.getIndex(),l.getStartPC()); + l.getLineNumber()); + } + } + } else if (a instanceof LocalVariableTable) { + + // Lets have a go at creating Tags directly + if (useTags) { + LocalVariable[] lv = ((LocalVariableTable) a).getLocalVariableTable(); + + for (int k = 0; k < lv.length; k++) { + LocalVariable l = lv[k]; + Type t = Type.getType(l.getSignature()); + LocalVariableTag lvt = new LocalVariableTag(t,l.getSignature(),l.getName(),l.getIndex(),l.getStartPC()); InstructionHandle start = il.findHandle(l.getStartPC(), arrayOfInstructions,true); - byte b = t.getType(); - if (b!= Constants.T_ADDRESS) { - int increment = t.getSize(); - if (l.getIndex()+increment>max_locals) max_locals = l.getIndex()+increment; - } - int end = l.getStartPC()+l.getLength(); - do { - start.addTargeter(lvt); - start = start.getNext(); - } while (start!=null && start.getPosition() max_locals) max_locals = slot + add; - LocalVariableGen l = new LocalVariableGen(slot, name, type, start, end); - int i; - if ((i = variable_vec.indexOf(l)) >= 0) variable_vec.set(i, l); // Overwrite if necessary - else variable_vec.add(l); - return l; - } else { - throw new IllegalArgumentException("Can not use " + type + - " as type for local variable"); - - } - } - - /** - * Adds a local variable to this method and assigns an index automatically. - * - * @param name variable name - * @param type variable type - * @param start from where the variable is valid, if this is null, - * it is valid from the start - * @param end until where the variable is valid, if this is null, - * it is valid to the end - * @return new local variable object - * @see LocalVariable - */ - public LocalVariableGen addLocalVariable(String name, Type type, - InstructionHandle start, - InstructionHandle end) { - return addLocalVariable(name, type, max_locals, start, end); - } - - /** - * Remove a local variable, its slot will not be reused, if you do not use addLocalVariable - * with an explicit index argument. - */ - public void removeLocalVariable(LocalVariableGen l) { - variable_vec.remove(l); - } - - /** - * Remove all local variables. - */ - public void removeLocalVariables() { - variable_vec.clear(); - } - - /** - * Sort local variables by index - */ - private static final void sort(LocalVariableGen[] vars, int l, int r) { - int i = l, j = r; - int m = vars[(l + r) / 2].getIndex(); - LocalVariableGen h; - - do { - while(vars[i].getIndex() < m) i++; - while(m < vars[j].getIndex()) j--; - - if(i <= j) { - h=vars[i]; vars[i]=vars[j]; vars[j]=h; // Swap elements - i++; j--; - } - } while(i <= j); - - if(l < j) sort(vars, l, j); - if(i < r) sort(vars, i, r); - } - - /* - * If the range of the variable has not been set yet, it will be set to be valid from - * the start to the end of the instruction list. - * - * @return array of declared local variables sorted by index - */ - public LocalVariableGen[] getLocalVariables() { - int size = variable_vec.size(); - LocalVariableGen[] lg = new LocalVariableGen[size]; - variable_vec.toArray(lg); - - for(int i=0; i < size; i++) { - if(lg[i].getStart() == null) - lg[i].setStart(il.getStart()); - - if(lg[i].getEnd() == null) - lg[i].setEnd(il.getEnd()); - } - - if(size > 1) - sort(lg, 0, size - 1); - - return lg; - } - - /** - * @return `LocalVariableTable' attribute of all the local variables of this method. - */ - public LocalVariableTable getLocalVariableTable(ConstantPool cp) { - LocalVariableGen[] lg = getLocalVariables(); - int size = lg.length; - LocalVariable[] lv = new LocalVariable[size]; - - for(int i=0; i < size; i++) - lv[i] = lg[i].getLocalVariable(cp); - - return new LocalVariableTable(cp.addUtf8("LocalVariableTable"), - 2 + lv.length * 10, lv, cp); - } - - /** - * Give an instruction a line number corresponding to the source code line. - * - * @param ih instruction to tag - * @return new line number object - * @see LineNumber - */ - public LineNumberGen addLineNumber(InstructionHandle ih, int src_line) { - LineNumberGen l = new LineNumberGen(ih, src_line); - line_number_vec.add(l); - return l; - } - - /** - * Remove a line number. - */ - public void removeLineNumber(LineNumberGen l) { - line_number_vec.remove(l); - } - - /** - * Remove all line numbers. - */ - public void removeLineNumbers() { - line_number_vec.clear(); - } - - /* - * @return array of line numbers - */ - public LineNumberGen[] getLineNumbers() { - LineNumberGen[] lg = new LineNumberGen[line_number_vec.size()]; - line_number_vec.toArray(lg); - return lg; - } - - /** - * @return `LineNumberTable' attribute of all the local variables of this method. - */ - public LineNumberTable getLineNumberTable(ConstantPool cp) { - int size = line_number_vec.size(); - LineNumber[] ln = new LineNumber[size]; - - try { - for(int i=0; i < size; i++) - ln[i] = ((LineNumberGen)line_number_vec.get(i)).getLineNumber(); - } catch(ArrayIndexOutOfBoundsException e) {} // Never occurs - - return new LineNumberTable(cp.addUtf8("LineNumberTable"), - 2 + ln.length * 4, ln, cp); - } - - /** - * Add an exception handler, i.e., specify region where a handler is active and an - * instruction where the actual handling is done. - * - * @param start_pc Start of region (inclusive) - * @param end_pc End of region (inclusive) - * @param handler_pc Where handling is done - * @param catch_type class type of handled exception or null if any - * exception is handled - * @return new exception handler object - */ - public CodeExceptionGen addExceptionHandler(InstructionHandle start_pc, - InstructionHandle end_pc, - InstructionHandle handler_pc, - ObjectType catch_type) { - if((start_pc == null) || (end_pc == null) || (handler_pc == null)) - throw new ClassGenException("Exception handler target is null instruction"); - - CodeExceptionGen c = new CodeExceptionGen(start_pc, end_pc, - handler_pc, catch_type); - exception_vec.add(c); - return c; - } - - /** - * Remove an exception handler. - */ - public void removeExceptionHandler(CodeExceptionGen c) { - exception_vec.remove(c); - } - - /** - * Remove all line numbers. - */ - public void removeExceptionHandlers() { - exception_vec.clear(); - } - - /* - * @return array of declared exception handlers - */ - public CodeExceptionGen[] getExceptionHandlers() { - CodeExceptionGen[] cg = new CodeExceptionGen[exception_vec.size()]; - exception_vec.toArray(cg); - return cg; - } - - /** - * @return code exceptions for `Code' attribute - */ - private CodeException[] getCodeExceptions() { - int size = exception_vec.size(); - CodeException[] c_exc = new CodeException[size]; - - try { - for(int i=0; i < size; i++) { - CodeExceptionGen c = (CodeExceptionGen)exception_vec.get(i); - c_exc[i] = c.getCodeException(cp); - } - } catch(ArrayIndexOutOfBoundsException e) {} - - return c_exc; - } - - /** - * Add an exception possibly thrown by this method. - * - * @param class_name (fully qualified) name of exception - */ - public void addException(String class_name) { - throws_vec.add(class_name); - } - - /** - * Remove an exception. - */ - public void removeException(String c) { - throws_vec.remove(c); - } - - /** - * Remove all exceptions. - */ - public void removeExceptions() { - throws_vec.clear(); - } - - /* - * @return array of thrown exceptions - */ - public String[] getExceptions() { - String[] e = new String[throws_vec.size()]; - throws_vec.toArray(e); - return e; - } - - /** - * @return `Exceptions' attribute of all the exceptions thrown by this method. - */ - private ExceptionTable getExceptionTable(ConstantPool cp) { - int size = throws_vec.size(); - int[] ex = new int[size]; - - try { - for(int i=0; i < size; i++) - ex[i] = cp.addClass((String)throws_vec.get(i)); - } catch(ArrayIndexOutOfBoundsException e) {} - - return new ExceptionTable(cp.addUtf8("Exceptions"), - 2 + 2 * size, ex, cp); - } - - /** - * Add an attribute to the code. Currently, the JVM knows about the - * LineNumberTable, LocalVariableTable and StackMap attributes, - * where the former two will be generated automatically and the - * latter is used for the MIDP only. Other attributes will be - * ignored by the JVM but do no harm. - * - * @param a attribute to be added - */ - public void addCodeAttribute(Attribute a) { code_attrs_vec.add(a); } - - public void addAnnotationsAsAttribute(ConstantPool cp) { - Attribute[] attrs = Utility.getAnnotationAttributes(cp,annotation_vec); - if (attrs!=null) { - for (int i = 0; i < attrs.length; i++) { - addAttribute(attrs[i]); - } - } - } - - public void addParameterAnnotationsAsAttribute(ConstantPool cp) { - if (!hasParameterAnnotations) return; - Attribute[] attrs = Utility.getParameterAnnotationAttributes(cp,param_annotations); - if (attrs!=null) { - for (int i = 0; i < attrs.length; i++) { - addAttribute(attrs[i]); - } - } - } - - /** - * Remove a code attribute. - */ - public void removeCodeAttribute(Attribute a) { code_attrs_vec.remove(a); } - - /** - * Remove all code attributes. - */ - public void removeCodeAttributes() { - code_attrs_vec.clear(); - } - - /** - * @return all attributes of this method. - */ - public Attribute[] getCodeAttributes() { - Attribute[] attributes = new Attribute[code_attrs_vec.size()]; - code_attrs_vec.toArray(attributes); - return attributes; - } - - /** - * Get method object. Never forget to call setMaxStack() or setMaxStack(max), respectively, - * before calling this method (the same applies for max locals). - * - * @return method object - */ - public Method getMethod() { - String signature = getSignature(); - int name_index = cp.addUtf8(name); - int signature_index = cp.addUtf8(signature); - - /* Also updates positions of instructions, i.e., their indices - */ - byte[] byte_code = null; - - if(il != null) - byte_code = il.getByteCode(); - - LineNumberTable lnt = null; - LocalVariableTable lvt = null; - //J5TODO: LocalVariableTypeTable support! - - /* Create LocalVariableTable and LineNumberTable attributes (for debuggers, e.g.) - */ - if((variable_vec.size() > 0) && !strip_attributes) - addCodeAttribute(lvt = getLocalVariableTable(cp)); - - if((line_number_vec.size() > 0) && !strip_attributes) - addCodeAttribute(lnt = getLineNumberTable(cp)); - - Attribute[] code_attrs = getCodeAttributes(); - - /* Each attribute causes 6 additional header bytes - */ - int attrs_len = 0; - for(int i=0; i < code_attrs.length; i++) - attrs_len += (code_attrs[i].getLength() + 6); - - CodeException[] c_exc = getCodeExceptions(); - int exc_len = c_exc.length * 8; // Every entry takes 8 bytes - - Code code = null; - - if((il != null) && !isAbstract()) { - // Remove any stale code attribute - Attribute[] attributes = getAttributes(); - for(int i=0; i < attributes.length; i++) { - Attribute a = attributes[i]; - if(a instanceof Code) - removeAttribute(a); - } - - code = new Code(cp.addUtf8("Code"), - 8 + byte_code.length + // prologue byte code - 2 + exc_len + // exceptions - 2 + attrs_len, // attributes - max_stack, max_locals, - byte_code, c_exc, - code_attrs, - cp); - - addAttribute(code); - } - - - addAnnotationsAsAttribute(cp); - addParameterAnnotationsAsAttribute(cp); - - ExceptionTable et = null; - - if(throws_vec.size() > 0) - addAttribute(et = getExceptionTable(cp)); // Add `Exceptions' if there are "throws" clauses - - Method m = new Method(accessflags, name_index, signature_index, - getAttributes(), cp); - - // Undo effects of adding attributes - if(lvt != null) removeCodeAttribute(lvt); - if(lnt != null) removeCodeAttribute(lnt); - if(code != null) removeAttribute(code); - if(et != null) removeAttribute(et); -//J5TODO: Remove the annotation attributes that may have been added - return m; - } - - /** - * Remove all NOPs from the instruction list (if possible) and update every - * object refering to them, i.e., branch instructions, local variables and - * exception handlers. - */ - public void removeNOPs() { - if(il != null) { - InstructionHandle next; - /* Check branch instructions. - */ - for(InstructionHandle ih = il.getStart(); ih != null; ih = next) { - next = ih.next; - - if((next != null) && (ih.getInstruction().opcode==Constants.NOP)) { - try { - il.delete(ih); - } catch(TargetLostException e) { - InstructionHandle[] targets = e.getTargets(); - - for(int i=0; i < targets.length; i++) { - InstructionTargeter[] targeters = targets[i].getTargeters(); - - for(int j=0; j < targeters.length; j++) - targeters[j].updateTarget(targets[i], next); - } - } - } - } - } - } - - /** - * Set maximum number of local variables. - */ - public void setMaxLocals(int m) { max_locals = m; } - public int getMaxLocals() { return max_locals; } - - /** - * Set maximum stack size for this method. - */ - public void setMaxStack(int m) { max_stack = m; } - public int getMaxStack() { return max_stack; } - - /** @return class that contains this method - */ - public String getClassName() { return class_name; } - public void setClassName(String class_name) { this.class_name = class_name; } - - public void setReturnType(Type return_type) { setType(return_type); } - public Type getReturnType() { return getType(); } - - public void setArgumentTypes(Type[] arg_types) { this.arg_types = arg_types; } - public Type[] getArgumentTypes() { return (Type[])arg_types.clone(); } - public void setArgumentType(int i, Type type) { arg_types[i] = type; } - public Type getArgumentType(int i) { return arg_types[i]; } - - public void setArgumentNames(String[] arg_names) { this.arg_names = arg_names; } - public String[] getArgumentNames() { - if (arg_names!=null) return (String[])arg_names.clone(); - else return new String[0]; - } - public void setArgumentName(int i, String name) { arg_names[i] = name; } - public String getArgumentName(int i) { return arg_names[i]; } - - public InstructionList getInstructionList() { return il; } - public void setInstructionList(InstructionList il) { this.il = il; } - - public String getSignature() { - return Type.getMethodSignature(type, arg_types); - } - - /** - * Computes max. stack size by performing control flow analysis. - */ - public void setMaxStack() { - if(il != null) - max_stack = getMaxStack(cp, il, getExceptionHandlers()); - else - max_stack = 0; - } - - /** - * Compute maximum number of local variables. - */ - public void setMaxLocals() { - if(il != null) { - int max = isStatic()? 0 : 1; - - if(arg_types != null) - for(int i=0; i < arg_types.length; i++) - max += arg_types[i].getSize(); - - for(InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) { - Instruction ins = ih.getInstruction(); - - if((ins instanceof InstructionLV) || - (ins instanceof RET)) - { - int index = ins.getIndex() + - ins.getType(cp).getSize(); - - if(index > max) - max = index; - } - } - - max_locals = max; - } else - max_locals = 0; - } - - /** Do not/Do produce attributes code attributesLineNumberTable and - * LocalVariableTable, like javac -O - */ - public void stripAttributes(boolean flag) { strip_attributes = flag; } - - static final class BranchTarget { - InstructionHandle target; - int stackDepth; - - BranchTarget(InstructionHandle target, int stackDepth) { - this.target = target; - this.stackDepth = stackDepth; - } - } - - static final class BranchStack { - Stack branchTargets = new Stack(); - Hashtable visitedTargets = new Hashtable(); - - public void push(InstructionHandle target, int stackDepth) { - if(visited(target)) - return; - - branchTargets.push(visit(target, stackDepth)); - } - - public BranchTarget pop() { - if(!branchTargets.empty()) { - BranchTarget bt = (BranchTarget) branchTargets.pop(); - return bt; - } - - return null; - } - - private final BranchTarget visit(InstructionHandle target, int stackDepth) { - BranchTarget bt = new BranchTarget(target, stackDepth); - visitedTargets.put(target, bt); - - return bt; - } - - private final boolean visited(InstructionHandle target) { - return (visitedTargets.get(target) != null); - } - } - - /** - * Computes stack usage of an instruction list by performing control flow analysis. - * - * @return maximum stack depth used by method - */ - public static int getMaxStack(ConstantPool cp, InstructionList il, CodeExceptionGen[] et) { - BranchStack branchTargets = new BranchStack(); - - /* Initially, populate the branch stack with the exception - * handlers, because these aren't (necessarily) branched to - * explicitly. in each case, the stack will have depth 1, - * containing the exception object. - */ - for (int i = 0; i < et.length; i++) { - InstructionHandle handler_pc = et[i].getHandlerPC(); - if (handler_pc != null) - branchTargets.push(handler_pc, 1); - } - - int stackDepth = 0, maxStackDepth = 0; - InstructionHandle ih = il.getStart(); - while(ih != null) { - Instruction instruction = ih.getInstruction(); - short opcode = instruction.opcode; - int prod = instruction.produceStack(cp); - int con = instruction.consumeStack(cp); - int delta = prod-con; - - stackDepth += delta; - if(stackDepth > maxStackDepth) - maxStackDepth = stackDepth; - - // choose the next instruction based on whether current is a branch. - if(instruction instanceof InstructionBranch) { - InstructionBranch branch = (InstructionBranch) instruction; - if(instruction instanceof InstructionSelect) { - // explore all of the select's targets. the default target is handled below. - InstructionSelect select = (InstructionSelect) branch; - InstructionHandle[] targets = select.getTargets(); - for (int i = 0; i < targets.length; i++) - branchTargets.push(targets[i], stackDepth); - // nothing to fall through to. - ih = null; - } else if(!(branch.isIfInstruction())) { - // if an instruction that comes back to following PC, - // push next instruction, with stack depth reduced by 1. - if(opcode == Constants.JSR || opcode == Constants.JSR_W) - branchTargets.push(ih.getNext(), stackDepth - 1); - ih = null; - } - // for all branches, the target of the branch is pushed on the branch stack. - // conditional branches have a fall through case, selects don't, and - // jsr/jsr_w return to the next instruction. - branchTargets.push(branch.getTarget(), stackDepth); - } else { - // check for instructions that terminate the method. - if(opcode == Constants.ATHROW || opcode == Constants.RET || - (opcode >= Constants.IRETURN && opcode <= Constants.RETURN)) - ih = null; - } - // normal case, go to the next instruction. - if(ih != null) - ih = ih.getNext(); - // if we have no more instructions, see if there are any deferred branches to explore. - if(ih == null) { - BranchTarget bt = branchTargets.pop(); - if (bt != null) { - ih = bt.target; - stackDepth = bt.stackDepth; - } - } - } - - return maxStackDepth; - } - - - /** - * Return string representation close to declaration format, - * `public static void main(String[]) throws IOException', e.g. - * - * @return String representation of the method. - */ - public final String toString() { - String access = Utility.accessToString(accessflags); - String signature = Type.getMethodSignature(type, arg_types); - - signature = Utility.methodSignatureToString(signature, name, access, - true, getLocalVariableTable(cp)); - - StringBuffer buf = new StringBuffer(signature); - - if(throws_vec.size() > 0) { - for(Iterator e = throws_vec.iterator(); e.hasNext(); ) - buf.append("\n\t\tthrows " + e.next()); - } - - return buf.toString(); - } - - /** @return deep copy of this method - */ - public MethodGen copy(String class_name, ConstantPool cp) { - Method m = ((MethodGen)clone()).getMethod(); - MethodGen mg = new MethodGen(m, class_name, this.cp); - - if(this.cp != cp) { - mg.setConstantPool(cp); - mg.getInstructionList().replaceConstantPool(this.cp, cp); - } - - return mg; - } - - //J5TODO: Should param_annotations be an array of arrays? Rather than an array of lists, this - // is more likely to suggest to the caller it is readonly (which a List does not). - /** - * Return a list of AnnotationGen objects representing parameter annotations - */ - public List getAnnotationsOnParameter(int i) { - ensureExistingParameterAnnotationsUnpacked(); - if (!hasParameterAnnotations || i>arg_types.length) return null; - return param_annotations[i]; - } - - /** - * Goes through the attributes on the method and identifies any that are RuntimeParameterAnnotations, - * extracting their contents and storing them as parameter annotations. There are two kinds of - * parameter annotation - visible and invisible. Once they have been unpacked, these attributes are - * deleted. (The annotations will be rebuilt as attributes when someone builds a Method object out - * of this MethodGen object). - */ - private void ensureExistingParameterAnnotationsUnpacked() { - if (haveUnpackedParameterAnnotations) return; - // Find attributes that contain parameter annotation data - Attribute[] attrs = getAttributes(); - RuntimeParameterAnnotations paramAnnVisAttr = null; - RuntimeParameterAnnotations paramAnnInvisAttr=null; - List accumulatedAnnotations = new ArrayList(); - for (int i = 0; i < attrs.length; i++) { - Attribute attribute = attrs[i]; - if (attribute instanceof RuntimeParameterAnnotations) { - - // Initialize param_annotations - if (!hasParameterAnnotations) { - param_annotations = new List[arg_types.length]; - for (int j=0;jmaxLocals) maxLocals = l.getIndex()+increment; + } + int end = l.getStartPC()+l.getLength(); + do { + start.addTargeter(lvt); + start = start.getNext(); + } while (start!=null && start.getPosition() maxLocals) maxLocals = slot + size; + LocalVariableGen l = new LocalVariableGen(slot, name, type, start, end); + int i = localVariablesList.indexOf(l); + if (i >= 0) localVariablesList.set(i, l); // Overwrite if necessary + else localVariablesList.add(l); + return l; +// } else { +// throw new IllegalArgumentException("Can not use " + type + +// " as type for local variable"); +// +// } + } + + /** + * Adds a local variable to this method and assigns an index automatically. + * + * @param name variable name + * @param type variable type + * @param start from where the variable is valid, if this is null, + * it is valid from the start + * @param end until where the variable is valid, if this is null, + * it is valid to the end + * @return new local variable object + * @see LocalVariable + */ + public LocalVariableGen addLocalVariable(String name, Type type, + InstructionHandle start, + InstructionHandle end) { + return addLocalVariable(name, type, maxLocals, start, end); + } + + /** + * Remove a local variable, its slot will not be reused, if you do not use addLocalVariable + * with an explicit index argument. + */ + public void removeLocalVariable(LocalVariableGen l) { + localVariablesList.remove(l); + } + + /** + * Remove all local variables. + */ + public void removeLocalVariables() { + localVariablesList.clear(); + } + + /** + * Sort local variables by index + */ + private static final void sort(LocalVariableGen[] vars, int l, int r) { + int i = l, j = r; + int m = vars[(l + r) / 2].getIndex(); + LocalVariableGen h; + + do { + while(vars[i].getIndex() < m) i++; + while(m < vars[j].getIndex()) j--; + + if(i <= j) { + h=vars[i]; vars[i]=vars[j]; vars[j]=h; // Swap elements + i++; j--; + } + } while(i <= j); + + if(l < j) sort(vars, l, j); + if(i < r) sort(vars, i, r); + } + + /* + * If the range of the variable has not been set yet, it will be set to be valid from + * the start to the end of the instruction list. + * + * @return array of declared local variables sorted by index + */ + public LocalVariableGen[] getLocalVariables() { + int size = localVariablesList.size(); + LocalVariableGen[] lg = new LocalVariableGen[size]; + localVariablesList.toArray(lg); + + for(int i=0; i < size; i++) { + if(lg[i].getStart() == null) + lg[i].setStart(il.getStart()); + + if(lg[i].getEnd() == null) + lg[i].setEnd(il.getEnd()); + } + + if(size > 1) + sort(lg, 0, size - 1); + + return lg; + } + + /** + * @return `LocalVariableTable' attribute of all the local variables of this method. + */ + public LocalVariableTable getLocalVariableTable(ConstantPool cp) { + LocalVariableGen[] lg = getLocalVariables(); + int size = lg.length; + LocalVariable[] lv = new LocalVariable[size]; + + for(int i=0; i < size; i++) + lv[i] = lg[i].getLocalVariable(cp); + + return new LocalVariableTable(cp.addUtf8("LocalVariableTable"), + 2 + lv.length * 10, lv, cp); + } + + /** + * Give an instruction a line number corresponding to the source code line. + * + * @param ih instruction to tag + * @return new line number object + * @see LineNumber + */ + public LineNumberGen addLineNumber(InstructionHandle ih, int src_line) { + LineNumberGen l = new LineNumberGen(ih, src_line); + lineNumbersList.add(l); + return l; + } + + /** + * Remove a line number. + */ + public void removeLineNumber(LineNumberGen l) { + lineNumbersList.remove(l); + } + + /** + * Remove all line numbers. + */ + public void removeLineNumbers() { + lineNumbersList.clear(); + } + + /* + * @return array of line numbers + */ + public LineNumberGen[] getLineNumbers() { + LineNumberGen[] lg = new LineNumberGen[lineNumbersList.size()]; + lineNumbersList.toArray(lg); + return lg; + } + + /** + * @return 'LineNumberTable' attribute for all the local variables of this method. + */ + public LineNumberTable getLineNumberTable(ConstantPool cp) { + int size = lineNumbersList.size(); + LineNumber[] ln = new LineNumber[size]; + + for(int i=0; i < size; i++) { + ln[i] = ((LineNumberGen)lineNumbersList.get(i)).getLineNumber(); + } + + return new LineNumberTable(cp.addUtf8("LineNumberTable"), 2 + ln.length * 4, ln, cp); + } + + /** + * Add an exception handler, i.e., specify region where a handler is active and an + * instruction where the actual handling is done. + * + * @param start_pc Start of region (inclusive) + * @param end_pc End of region (inclusive) + * @param handler_pc Where handling is done + * @param catch_type class type of handled exception or null if any + * exception is handled + * @return new exception handler object + */ + public CodeExceptionGen addExceptionHandler(InstructionHandle start_pc, + InstructionHandle end_pc, + InstructionHandle handler_pc, + ObjectType catch_type) { + if((start_pc == null) || (end_pc == null) || (handler_pc == null)) + throw new ClassGenException("Exception handler target is null instruction"); + + CodeExceptionGen c = new CodeExceptionGen(start_pc, end_pc, + handler_pc, catch_type); + exceptionsList.add(c); + return c; + } + + /** + * Remove an exception handler. + */ + public void removeExceptionHandler(CodeExceptionGen c) { + exceptionsList.remove(c); + } + + /** + * Remove all line numbers. + */ + public void removeExceptionHandlers() { + exceptionsList.clear(); + } + + /* + * @return array of declared exception handlers + */ + public CodeExceptionGen[] getExceptionHandlers() { + CodeExceptionGen[] cg = new CodeExceptionGen[exceptionsList.size()]; + exceptionsList.toArray(cg); + return cg; + } + + /** + * @return code exceptions for `Code' attribute + */ + private CodeException[] getCodeExceptions() { + int size = exceptionsList.size(); + CodeException[] c_exc = new CodeException[size]; + + try { + for(int i=0; i < size; i++) { + CodeExceptionGen c = (CodeExceptionGen)exceptionsList.get(i); + c_exc[i] = c.getCodeException(cp); + } + } catch(ArrayIndexOutOfBoundsException e) {} + + return c_exc; + } + + /** + * Add an exception possibly thrown by this method. + * + * @param class_name (fully qualified) name of exception + */ + public void addException(String class_name) { + throws_vec.add(class_name); + } + + /** + * Remove an exception. + */ + public void removeException(String c) { + throws_vec.remove(c); + } + + /** + * Remove all exceptions. + */ + public void removeExceptions() { + throws_vec.clear(); + } + + /* + * @return array of thrown exceptions + */ + public String[] getExceptions() { + String[] e = new String[throws_vec.size()]; + throws_vec.toArray(e); + return e; + } + + /** + * @return `Exceptions' attribute of all the exceptions thrown by this method. + */ + private ExceptionTable getExceptionTable(ConstantPool cp) { + int size = throws_vec.size(); + int[] ex = new int[size]; + + try { + for(int i=0; i < size; i++) + ex[i] = cp.addClass((String)throws_vec.get(i)); + } catch(ArrayIndexOutOfBoundsException e) {} + + return new ExceptionTable(cp.addUtf8("Exceptions"), + 2 + 2 * size, ex, cp); + } + + /** + * Add an attribute to the code. Currently, the JVM knows about the + * LineNumberTable, LocalVariableTable and StackMap attributes, + * where the former two will be generated automatically and the + * latter is used for the MIDP only. Other attributes will be + * ignored by the JVM but do no harm. + * + * @param a attribute to be added + */ + public void addCodeAttribute(Attribute a) { codeAttributesList.add(a); } + + + public void addParameterAnnotationsAsAttribute(ConstantPool cp) { + if (!hasParameterAnnotations) return; + Attribute[] attrs = Utility.getParameterAnnotationAttributes(cp,param_annotations); + if (attrs!=null) { + for (int i = 0; i < attrs.length; i++) { + addAttribute(attrs[i]); + } + } + } + + /** + * Remove a code attribute. + */ + public void removeCodeAttribute(Attribute a) { codeAttributesList.remove(a); } + + /** + * Remove all code attributes. + */ + public void removeCodeAttributes() { + codeAttributesList.clear(); + } + + /** + * @return all attributes of this method. + */ + public Attribute[] getCodeAttributes() { + Attribute[] attributes = new Attribute[codeAttributesList.size()]; + codeAttributesList.toArray(attributes); + return attributes; + } + + /** + * Get method object. Never forget to call setMaxStack() or setMaxStack(max), respectively, + * before calling this method (the same applies for max locals). + * + * @return method object + */ + public Method getMethod() { + String signature = getSignature(); + int name_index = cp.addUtf8(name); + int signature_index = cp.addUtf8(signature); + + /* Also updates positions of instructions, i.e., their indices + */ + byte[] byte_code = null; + + if(il != null) + byte_code = il.getByteCode(); + + LineNumberTable lnt = null; + LocalVariableTable lvt = null; + //J5TODO: LocalVariableTypeTable support! + + /* Create LocalVariableTable and LineNumberTable attributes (for debuggers, e.g.) + */ + if((localVariablesList.size() > 0) && !stripAttributes) + addCodeAttribute(lvt = getLocalVariableTable(cp)); + + if((lineNumbersList.size() > 0) && !stripAttributes) + addCodeAttribute(lnt = getLineNumberTable(cp)); + + Attribute[] code_attrs = getCodeAttributes(); + + /* Each attribute causes 6 additional header bytes + */ + int attrs_len = 0; + for(int i=0; i < code_attrs.length; i++) + attrs_len += (code_attrs[i].getLength() + 6); + + CodeException[] c_exc = getCodeExceptions(); + int exc_len = c_exc.length * 8; // Every entry takes 8 bytes + + Code code = null; + + if((il != null) && !isAbstract()) { + // Remove any stale code attribute + List attributes = getAttributes(); + for(int i=0; i < attributes.size(); i++) { + Attribute a = (Attribute) attributes.get(i); + if(a instanceof Code) + removeAttribute(a); + } + + code = new Code(cp.addUtf8("Code"), + 8 + byte_code.length + // prologue byte code + 2 + exc_len + // exceptions + 2 + attrs_len, // attributes + maxStack, maxLocals, + byte_code, c_exc, + code_attrs, + cp); + + addAttribute(code); + } + + + addAnnotationsAsAttribute(cp); + addParameterAnnotationsAsAttribute(cp); + + ExceptionTable et = null; + + if(throws_vec.size() > 0) + addAttribute(et = getExceptionTable(cp)); // Add `Exceptions' if there are "throws" clauses + + Method m = new Method(modifiers, name_index, signature_index, + getAttributesImmutable(), cp); + + // Undo effects of adding attributes + // OPTIMIZE why redo this? is there a better way to clean up? + if(lvt != null) removeCodeAttribute(lvt); + if(lnt != null) removeCodeAttribute(lnt); + if(code != null) removeAttribute(code); + if(et != null) removeAttribute(et); +//J5TODO: Remove the annotation attributes that may have been added + return m; + } + + /** + * Set maximum number of local variables. + */ + public void setMaxLocals(int m) { maxLocals = m; } + public int getMaxLocals() { return maxLocals; } + + /** + * Set maximum stack size for this method. + */ + public void setMaxStack(int m) { maxStack = m; } + public int getMaxStack() { return maxStack; } + + /** @return class that contains this method + */ + public String getClassName() { return classname; } + public void setClassName(String class_name) { this.classname = class_name; } + + public void setReturnType(Type return_type) { setType(return_type); } + public Type getReturnType() { return getType(); } + + public void setArgumentTypes(Type[] arg_types) { this.parameterTypes = arg_types; } + public Type[] getArgumentTypes() { return this.parameterTypes;}// OPTIMIZE dont need clone here? (Type[])arg_types.clone(); } + public void setArgumentType(int i, Type type) { parameterTypes[i] = type; } + public Type getArgumentType(int i) { return parameterTypes[i]; } + + public void setArgumentNames(String[] arg_names) { this.parameterNames = arg_names; } + public String[] getArgumentNames() { + if (parameterNames!=null) return (String[])parameterNames.clone(); + else return new String[0]; + } + public void setArgumentName(int i, String name) { parameterNames[i] = name; } + public String getArgumentName(int i) { return parameterNames[i]; } + + public InstructionList getInstructionList() { return il; } + public void setInstructionList(InstructionList il) { this.il = il; } + + public String getSignature() { + return Type.getMethodSignature(type, parameterTypes); + } + + /** + * Computes max. stack size by performing control flow analysis. + */ + public void setMaxStack() { + if(il != null) + maxStack = getMaxStack(cp, il, getExceptionHandlers()); + else + maxStack = 0; + } + + /** + * Compute maximum number of local variables. + */ + public void setMaxLocals() { + if(il != null) { + int max = isStatic()? 0 : 1; + + if(parameterTypes != null) + for(int i=0; i < parameterTypes.length; i++) + max += parameterTypes[i].getSize(); + + for(InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) { + Instruction ins = ih.getInstruction(); + + if((ins instanceof InstructionLV) || + (ins instanceof RET)) + { + int index = ins.getIndex() + + ins.getType(cp).getSize(); + + if(index > max) + max = index; + } + } + + maxLocals = max; + } else + maxLocals = 0; + } + + public void stripAttributes(boolean flag) { stripAttributes = flag; } + + static final class BranchTarget { + InstructionHandle target; + int stackDepth; + + BranchTarget(InstructionHandle target, int stackDepth) { + this.target = target; + this.stackDepth = stackDepth; + } + } + + static final class BranchStack { + Stack branchTargets = new Stack(); + Hashtable visitedTargets = new Hashtable(); + + public void push(InstructionHandle target, int stackDepth) { + if(visited(target)) + return; + + branchTargets.push(visit(target, stackDepth)); + } + + public BranchTarget pop() { + if(!branchTargets.empty()) { + BranchTarget bt = (BranchTarget) branchTargets.pop(); + return bt; + } + + return null; + } + + private final BranchTarget visit(InstructionHandle target, int stackDepth) { + BranchTarget bt = new BranchTarget(target, stackDepth); + visitedTargets.put(target, bt); + + return bt; + } + + private final boolean visited(InstructionHandle target) { + return (visitedTargets.get(target) != null); + } + } + + /** + * Computes stack usage of an instruction list by performing control flow analysis. + * + * @return maximum stack depth used by method + */ + public static int getMaxStack(ConstantPool cp, InstructionList il, CodeExceptionGen[] et) { + BranchStack branchTargets = new BranchStack(); + + /* Initially, populate the branch stack with the exception + * handlers, because these aren't (necessarily) branched to + * explicitly. in each case, the stack will have depth 1, + * containing the exception object. + */ + for (int i = 0; i < et.length; i++) { + InstructionHandle handler_pc = et[i].getHandlerPC(); + if (handler_pc != null) + branchTargets.push(handler_pc, 1); + } + + int stackDepth = 0, maxStackDepth = 0; + InstructionHandle ih = il.getStart(); + while(ih != null) { + Instruction instruction = ih.getInstruction(); + short opcode = instruction.opcode; + int prod = instruction.produceStack(cp); + int con = instruction.consumeStack(cp); + int delta = prod-con; + + stackDepth += delta; + if(stackDepth > maxStackDepth) + maxStackDepth = stackDepth; + + // choose the next instruction based on whether current is a branch. + if(instruction instanceof InstructionBranch) { + InstructionBranch branch = (InstructionBranch) instruction; + if(instruction instanceof InstructionSelect) { + // explore all of the select's targets. the default target is handled below. + InstructionSelect select = (InstructionSelect) branch; + InstructionHandle[] targets = select.getTargets(); + for (int i = 0; i < targets.length; i++) + branchTargets.push(targets[i], stackDepth); + // nothing to fall through to. + ih = null; + } else if(!(branch.isIfInstruction())) { + // if an instruction that comes back to following PC, + // push next instruction, with stack depth reduced by 1. + if(opcode == Constants.JSR || opcode == Constants.JSR_W) + branchTargets.push(ih.getNext(), stackDepth - 1); + ih = null; + } + // for all branches, the target of the branch is pushed on the branch stack. + // conditional branches have a fall through case, selects don't, and + // jsr/jsr_w return to the next instruction. + branchTargets.push(branch.getTarget(), stackDepth); + } else { + // check for instructions that terminate the method. + if(opcode == Constants.ATHROW || opcode == Constants.RET || + (opcode >= Constants.IRETURN && opcode <= Constants.RETURN)) + ih = null; + } + // normal case, go to the next instruction. + if(ih != null) + ih = ih.getNext(); + // if we have no more instructions, see if there are any deferred branches to explore. + if(ih == null) { + BranchTarget bt = branchTargets.pop(); + if (bt != null) { + ih = bt.target; + stackDepth = bt.stackDepth; + } + } + } + + return maxStackDepth; + } + + + /** + * Return string representation close to declaration format, + * `public static void main(String[]) throws IOException', e.g. + * + * @return String representation of the method. + */ + public final String toString() { + String access = Utility.accessToString(modifiers); + String signature = Type.getMethodSignature(type, parameterTypes); + + signature = Utility.methodSignatureToString(signature, name, access, + true, getLocalVariableTable(cp)); + + StringBuffer buf = new StringBuffer(signature); + + if(throws_vec.size() > 0) { + for(Iterator e = throws_vec.iterator(); e.hasNext(); ) + buf.append("\n\t\tthrows " + e.next()); + } + + return buf.toString(); + } + + /** @return deep copy of this method + */ + public MethodGen copy(String class_name, ConstantPool cp) { + Method m = ((MethodGen)clone()).getMethod(); + MethodGen mg = new MethodGen(m, class_name, this.cp); + + if(this.cp != cp) { + mg.setConstantPool(cp); + mg.getInstructionList().replaceConstantPool(this.cp, cp); + } + + return mg; + } + + //J5TODO: Should param_annotations be an array of arrays? Rather than an array of lists, this + // is more likely to suggest to the caller it is readonly (which a List does not). + /** + * Return a list of AnnotationGen objects representing parameter annotations + */ + public List getAnnotationsOnParameter(int i) { + ensureExistingParameterAnnotationsUnpacked(); + if (!hasParameterAnnotations || i>parameterTypes.length) return null; + return param_annotations[i]; + } + + /** + * Goes through the attributes on the method and identifies any that are RuntimeParameterAnnotations, + * extracting their contents and storing them as parameter annotations. There are two kinds of + * parameter annotation - visible and invisible. Once they have been unpacked, these attributes are + * deleted. (The annotations will be rebuilt as attributes when someone builds a Method object out + * of this MethodGen object). + */ + private void ensureExistingParameterAnnotationsUnpacked() { + if (haveUnpackedParameterAnnotations) return; + // Find attributes that contain parameter annotation data + List attrs = getAttributes(); + RuntimeParameterAnnotations paramAnnVisAttr = null; + RuntimeParameterAnnotations paramAnnInvisAttr=null; + List accumulatedAnnotations = new ArrayList(); + for (int i = 0; i < attrs.size(); i++) { + Attribute attribute = (Attribute)attrs.get(i); + if (attribute instanceof RuntimeParameterAnnotations) { + + // Initialize param_annotations + if (!hasParameterAnnotations) { + param_annotations = new List[parameterTypes.length]; + for (int j=0;j. - */ - -/** - * Implement this interface if you're interested in changes to a MethodGen object - * and register yourself with addObserver(). - * - * @version $Id: MethodObserver.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public interface MethodObserver { - public void notify(MethodGen method); -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/NEW.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/NEW.java deleted file mode 100644 index d9798050c..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/NEW.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.ExceptionConstants; - -/** - * NEW - Create new object - *
          Stack: ... -> ..., objectref
          - * - * @version $Id: NEW.java,v 1.4 2004/11/22 08:31:27 aclement Exp $ - * @author M. Dahm - */ -public class NEW extends CPInstruction - implements LoadClass, AllocationInstruction, ExceptionThrower, StackProducer { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - NEW() {} - - public NEW(int index) { - super(org.aspectj.apache.bcel.Constants.NEW, index); - } - - public Class[] getExceptions(){ - Class[] cs = new Class[2 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length]; - - System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, - cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length); - - cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length+1] = ExceptionConstants.INSTANTIATION_ERROR; - cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.ILLEGAL_ACCESS_ERROR; - - return cs; - } - - public ObjectType getLoadClassType(ConstantPoolGen cpg) { - return (ObjectType)getType(cpg); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitLoadClass(this); - v.visitAllocationInstruction(this); - v.visitExceptionThrower(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitCPInstruction(this); - v.visitNEW(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/NEWARRAY.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/NEWARRAY.java deleted file mode 100644 index ba1c1b468..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/NEWARRAY.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * NEWARRAY - Create new array of basic type (int, short, ...) - *
          Stack: ..., count -> ..., arrayref
          - * type must be one of T_INT, T_SHORT, ... - * - * @version $Id: NEWARRAY.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class NEWARRAY extends Instruction - implements AllocationInstruction, ExceptionThrower, StackProducer { - private byte type; - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - NEWARRAY() {} - - public NEWARRAY(byte type) { - super(org.aspectj.apache.bcel.Constants.NEWARRAY, (short)2); - this.type = type; - } - - public NEWARRAY(BasicType type) { - this(type.getType()); - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - out.writeByte(opcode); - out.writeByte(type); - } - - /** - * @return numeric code for basic element type - */ - public final byte getTypecode() { return type; } - - /** - * @return type of constructed array - */ - public final Type getType() { - return new ArrayType(BasicType.getType(type), 1); - } - - /** - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - return super.toString(verbose) + " " + org.aspectj.apache.bcel.Constants.TYPE_NAMES[type]; - } - /** - * Read needed data (e.g. index) from file. - */ - protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException - { - type = bytes.readByte(); - length = 2; - } - - public Class[] getExceptions() { - return new Class[] { org.aspectj.apache.bcel.ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION }; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitAllocationInstruction(this); - v.visitExceptionThrower(this); - v.visitStackProducer(this); - v.visitNEWARRAY(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/NOP.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/NOP.java deleted file mode 100644 index 3fc5ae1bf..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/NOP.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * NOP - Do nothing - * - * @version $Id: NOP.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class NOP extends Instruction { - public NOP() { - super(org.aspectj.apache.bcel.Constants.NOP, (short)1); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitNOP(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/NamedAndTyped.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/NamedAndTyped.java deleted file mode 100644 index 1a5cba1a5..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/NamedAndTyped.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denote entity that has both name and type. This is true for local variables, - * methods and fields. - * - * @version $Id: NamedAndTyped.java,v 1.2.10.1 2008/04/25 17:55:34 aclement Exp $ - * @author M. Dahm - */ -public interface NamedAndTyped { - public String getName(); - public Type getType(); - public void setName(String name); - public void setType(Type type); - -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ObjectType.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ObjectType.java index bac901bbd..f5b8ad8b2 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ObjectType.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/ObjectType.java @@ -1,143 +1,143 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * Denotes reference such as java.lang.String. - * - * @version $Id: ObjectType.java,v 1.3.4.1 2008/04/25 17:55:32 aclement Exp $ - * @author M. Dahm - */ -public final class ObjectType extends ReferenceType { - private String class_name; // Class name of type - - /** - * @param class_name fully qualified class name, e.g. java.lang.String - */ - public ObjectType(String class_name) { - super(Constants.T_REFERENCE, toSignature(class_name));//"L" + class_name.replace('.', '/') + ";"); - this.class_name = class_name.replace('/', '.'); - } - - private static String toSignature(String classname) { - StringBuffer sig = new StringBuffer(); - sig.append("L").append(classname.replace('.','/')); - sig.append(";"); - return sig.toString(); - } - - /** @return name of referenced class - */ - public String getClassName() { return class_name; } - - /** @return a hash code value for the object. - */ - public int hashCode() { return class_name.hashCode(); } - - /** @return true if both type objects refer to the same class. - */ - public boolean equals(Object type) { - return (type instanceof ObjectType)? - ((ObjectType)type).class_name.equals(class_name) : false; - } - - /** - * If "this" doesn't reference a class, it references an interface - * or a non-existant entity. - */ - public boolean referencesClass(){ - JavaClass jc = Repository.lookupClass(class_name); - if (jc == null) - return false; - else - return jc.isClass(); - } - - /** - * If "this" doesn't reference an interface, it references a class - * or a non-existant entity. - */ - public boolean referencesInterface(){ - JavaClass jc = Repository.lookupClass(class_name); - if (jc == null) - return false; - else - return !jc.isClass(); - } - - public boolean subclassOf(ObjectType superclass){ - if (this.referencesInterface() || superclass.referencesInterface()) - return false; - - return Repository.instanceOf(this.class_name, superclass.class_name); - } - - /** - * Java Virtual Machine Specification edition 2, § 5.4.4 Access Control - */ - public boolean accessibleTo(ObjectType accessor) { - JavaClass jc = Repository.lookupClass(class_name); - - if(jc.isPublic()) { - return true; - } else { - JavaClass acc = Repository.lookupClass(accessor.class_name); - return acc.getPackageName().equals(jc.getPackageName()); - } - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.Repository; +import org.aspectj.apache.bcel.classfile.JavaClass; + +/** + * Denotes reference such as java.lang.String. + * + * @version $Id: ObjectType.java,v 1.3.4.2 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public final class ObjectType extends ReferenceType { + private String class_name; // Class name of type + + /** + * @param class_name fully qualified class name, e.g. java.lang.String + */ + public ObjectType(String class_name) { + super(Constants.T_REFERENCE, toSignature(class_name));//"L" + class_name.replace('.', '/') + ";"); + this.class_name = class_name.replace('/', '.'); + } + + private static String toSignature(String classname) { + StringBuffer sig = new StringBuffer(); + sig.append("L").append(classname.replace('.','/')); + sig.append(";"); + return sig.toString(); + } + + /** @return name of referenced class + */ + public String getClassName() { return class_name; } + + /** @return a hash code value for the object. + */ + public int hashCode() { return class_name.hashCode(); } + + /** @return true if both type objects refer to the same class. + */ + public boolean equals(Object type) { + return (type instanceof ObjectType)? + ((ObjectType)type).class_name.equals(class_name) : false; + } + + /** + * If "this" doesn't reference a class, it references an interface + * or a non-existant entity. + */ + public boolean referencesClass(){ + JavaClass jc = Repository.lookupClass(class_name); + if (jc == null) + return false; + else + return jc.isClass(); + } + + /** + * If "this" doesn't reference an interface, it references a class + * or a non-existant entity. + */ + public boolean referencesInterface(){ + JavaClass jc = Repository.lookupClass(class_name); + if (jc == null) + return false; + else + return !jc.isClass(); + } + + public boolean subclassOf(ObjectType superclass){ + if (this.referencesInterface() || superclass.referencesInterface()) + return false; + + return Repository.instanceOf(this.class_name, superclass.class_name); + } + + /** + * Java Virtual Machine Specification edition 2, § 5.4.4 Access Control + */ + public boolean accessibleTo(ObjectType accessor) { + JavaClass jc = Repository.lookupClass(class_name); + + if(jc.isPublic()) { + return true; + } else { + JavaClass acc = Repository.lookupClass(accessor.class_name); + return acc.getPackageName().equals(jc.getPackageName()); + } + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/POP.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/POP.java deleted file mode 100644 index 948e4c7e2..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/POP.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * POP - Pop top operand stack word - * - *
          Stack: ..., word -> ...
          - * - * @version $Id: POP.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class POP extends StackInstruction implements PopInstruction { - public POP() { - super(org.aspectj.apache.bcel.Constants.POP); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitPopInstruction(this); - v.visitStackInstruction(this); - v.visitPOP(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/POP2.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/POP2.java deleted file mode 100644 index fb50175a9..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/POP2.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * POP2 - Pop two top operand stack words - * - *
          Stack: ..., word2, word1 -> ...
          - * - * @version $Id: POP2.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class POP2 extends StackInstruction implements PopInstruction { - public POP2() { - super(org.aspectj.apache.bcel.Constants.POP2); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitPopInstruction(this); - v.visitStackInstruction(this); - v.visitPOP2(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/PUSH.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/PUSH.java deleted file mode 100644 index 16e5fdf1e..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/PUSH.java +++ /dev/null @@ -1,199 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; - -/** - * Wrapper class for push operations, which are implemented either as BIPUSH, - * LDC or xCONST_n instructions. - * - * @version $Id: PUSH.java,v 1.5 2005/01/31 11:32:21 aclement Exp $ - * @author M. Dahm - */ -public final class PUSH - implements CompoundInstruction, VariableLengthInstruction, InstructionConstants -{ - private Instruction instruction; - - /** - * This constructor also applies for values of type short, char, byte - * - * @param cp Constant pool - * @param value to be pushed - */ - public PUSH(ConstantPoolGen cp, int value) { - if((value >= -1) && (value <= 5)) // Use ICONST_n - instruction = INSTRUCTIONS[Constants.ICONST_0 + value]; - else if((value >= -128) && (value <= 127)) // Use BIPUSH - instruction = new BIPUSH((byte)value); - else if((value >= -32768) && (value <= 32767)) // Use SIPUSH - instruction = new SIPUSH((short)value); - else // If everything fails create a Constant pool entry - instruction = new LDC(cp.addInteger(value)); - } - - public PUSH(ConstantPoolGen cp, ObjectType t) { - instruction = new LDC_W(cp.addClass(t)); - } - - /** - * @param cp Constant pool - * @param value to be pushed - */ - public PUSH(ConstantPoolGen cp, boolean value) { - instruction = INSTRUCTIONS[Constants.ICONST_0 + (value? 1 : 0)]; - } - - /** - * @param cp Constant pool - * @param value to be pushed - */ - public PUSH(ConstantPoolGen cp, float value) { - if(value == 0.0) - instruction = FCONST_0; - else if(value == 1.0) - instruction = FCONST_1; - else if(value == 2.0) - instruction = FCONST_2; - else // Create a Constant pool entry - instruction = new LDC(cp.addFloat(value)); - } - - /** - * @param cp Constant pool - * @param value to be pushed - */ - public PUSH(ConstantPoolGen cp, long value) { - if(value == 0) - instruction = LCONST_0; - else if(value == 1) - instruction = LCONST_1; - else // Create a Constant pool entry - instruction = new LDC2_W(cp.addLong(value)); - } - - /** - * @param cp Constant pool - * @param value to be pushed - */ - public PUSH(ConstantPoolGen cp, double value) { - if(value == 0.0) - instruction = DCONST_0; - else if(value == 1.0) - instruction = DCONST_1; - else // Create a Constant pool entry - instruction = new LDC2_W(cp.addDouble(value)); - } - - /** - * @param cp Constant pool - * @param value to be pushed - */ - public PUSH(ConstantPoolGen cp, String value) { - if(value == null) - instruction = ACONST_NULL; - else // Create a Constant pool entry - instruction = new LDC(cp.addString(value)); - } - - /** - * @param cp Constant pool - * @param value to be pushed - */ - public PUSH(ConstantPoolGen cp, Number value) { - if((value instanceof Integer) || (value instanceof Short) || (value instanceof Byte)) - instruction = new PUSH(cp, value.intValue()).instruction; - else if(value instanceof Double) - instruction = new PUSH(cp, value.doubleValue()).instruction; - else if(value instanceof Float) - instruction = new PUSH(cp, value.floatValue()).instruction; - else if(value instanceof Long) - instruction = new PUSH(cp, value.longValue()).instruction; - else - throw new ClassGenException("What's this: " + value); - } - - /** - * @param cp Constant pool - * @param value to be pushed - */ - public PUSH(ConstantPoolGen cp, Character value) { - this(cp, (int)value.charValue()); - } - - /** - * @param cp Constant pool - * @param value to be pushed - */ - public PUSH(ConstantPoolGen cp, Boolean value) { - this(cp, value.booleanValue()); - } - - public final InstructionList getInstructionList() { - return new InstructionList(instruction); - } - - public final Instruction getInstruction() { - return instruction; - } - - /** - * @return mnemonic for instruction - */ - public String toString() { - return instruction.toString() + " (PUSH)"; - } -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/PUTFIELD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/PUTFIELD.java deleted file mode 100644 index 916c573ec..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/PUTFIELD.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.ExceptionConstants; - -/** - * PUTFIELD - Put field in object - *
          Stack: ..., objectref, value -> ...
          - * OR - *
          Stack: ..., objectref, value.word1, value.word2 -> ...
          - * - * @version $Id: PUTFIELD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class PUTFIELD - extends FieldInstruction - implements PopInstruction,ExceptionThrower{ - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - PUTFIELD() {} - - public PUTFIELD(int index) { - super(Constants.PUTFIELD, index); - } - - public int consumeStack(ConstantPoolGen cpg) { return getFieldSize(cpg) + 1; } - - public Class[] getExceptions() { - Class[] cs = new Class[2 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length]; - - System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, - cs, 0, ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length); - - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length+1] = - ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR; - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = - ExceptionConstants.NULL_POINTER_EXCEPTION; - - return cs; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitStackConsumer(this); - v.visitPopInstruction(this); - v.visitTypedInstruction(this); - v.visitLoadClass(this); - v.visitCPInstruction(this); - v.visitFieldOrMethod(this); - v.visitFieldInstruction(this); - v.visitPUTFIELD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/PUTSTATIC.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/PUTSTATIC.java deleted file mode 100644 index abe4447eb..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/PUTSTATIC.java +++ /dev/null @@ -1,114 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.ExceptionConstants; - -/** - * PUTSTATIC - Put static field in class - *
          Stack: ..., value -> ...
          - * OR - *
          Stack: ..., value.word1, value.word2 -> ...
          - * - * @version $Id: PUTSTATIC.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class PUTSTATIC extends FieldInstruction - implements ExceptionThrower, PopInstruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - PUTSTATIC() {} - - public PUTSTATIC(int index) { - super(Constants.PUTSTATIC, index); - } - - public int consumeStack(ConstantPoolGen cpg) { return getFieldSize(cpg); } - - public Class[] getExceptions() { - Class[] cs = new Class[1 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length]; - - System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, - cs, 0, ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length); - cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = - ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR; - - return cs; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitStackConsumer(this); - v.visitPopInstruction(this); - v.visitTypedInstruction(this); - v.visitLoadClass(this); - v.visitCPInstruction(this); - v.visitFieldOrMethod(this); - v.visitFieldInstruction(this); - v.visitPUTSTATIC(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/PopInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/PopInstruction.java deleted file mode 100644 index 4f93f975a..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/PopInstruction.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denotes an unparameterized instruction to pop a value on top from the stack, - * such as ISTORE, POP, PUTSTATIC. - * - * @version $Id: PopInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - * @see ISTORE - * @see POP - */ -public interface PopInstruction extends StackConsumer { -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/PushInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/PushInstruction.java deleted file mode 100644 index c9a997265..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/PushInstruction.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denotes an unparameterized instruction to produce a value on top of the stack, - * such as ILOAD, LDC, SIPUSH, DUP, ICONST, etc. - * - * @version $Id: PushInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - - * @see ILOAD - * @see ICONST - * @see LDC - * @see DUP - * @see SIPUSH - * @see GETSTATIC - */ -public interface PushInstruction extends StackProducer { -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/RET.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/RET.java index 0f0196ea0..6e4bf1e53 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/RET.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/RET.java @@ -1,106 +1,106 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.ConstantPool; - -/** - * RET - Return from subroutine - * - *
          Stack: ..., -> ..., address
          - * - * @version $Id: RET.java,v 1.2.10.2 2008/04/25 17:55:35 aclement Exp $ - * @author M. Dahm - */ -public class RET extends Instruction { - private boolean wide; - private int index; // index to local variable containg the return address - - - public RET(int index,boolean wide) { - super(Constants.RET); - this.index = index; - this.wide = wide; - //this.wide = index > org.aspectj.apache.bcel.Constants.MAX_BYTE; - } - - public void dump(DataOutputStream out) throws IOException { - if (wide) out.writeByte(org.aspectj.apache.bcel.Constants.WIDE); - out.writeByte(opcode); - if(wide) out.writeShort(index); - else out.writeByte(index); - } - - public int getLength() { - if (wide) return 4; else return 2; - } - - public final int getIndex() { return index; } - public final void setIndex(int index) { - this.index = index; - this.wide = index > org.aspectj.apache.bcel.Constants.MAX_BYTE; - } - - public String toString(boolean verbose) { - return super.toString(verbose) + " " + index; - } - - public Type getType(ConstantPool cp) { - return ReturnaddressType.NO_TARGET; - } - -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.io.*; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.ConstantPool; + +/** + * RET - Return from subroutine + * + *
          Stack: ..., -> ..., address
          + * + * @version $Id: RET.java,v 1.2.10.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public class RET extends Instruction { + private boolean wide; + private int index; // index to local variable containg the return address + + + public RET(int index,boolean wide) { + super(Constants.RET); + this.index = index; + this.wide = wide; + //this.wide = index > org.aspectj.apache.bcel.Constants.MAX_BYTE; + } + + public void dump(DataOutputStream out) throws IOException { + if (wide) out.writeByte(org.aspectj.apache.bcel.Constants.WIDE); + out.writeByte(opcode); + if(wide) out.writeShort(index); + else out.writeByte(index); + } + + public int getLength() { + if (wide) return 4; else return 2; + } + + public final int getIndex() { return index; } + public final void setIndex(int index) { + this.index = index; + this.wide = index > org.aspectj.apache.bcel.Constants.MAX_BYTE; + } + + public String toString(boolean verbose) { + return super.toString(verbose) + " " + index; + } + + public Type getType(ConstantPool cp) { + return ReturnaddressType.NO_TARGET; + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/RETURN.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/RETURN.java deleted file mode 100644 index ce7449dd4..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/RETURN.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * RETURN - Return from void method - *
          Stack: ... -> <empty>
          - * - * @version $Id: RETURN.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class RETURN extends ReturnInstruction { - public RETURN() { - super(org.aspectj.apache.bcel.Constants.RETURN); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitStackConsumer(this); - v.visitReturnInstruction(this); - v.visitRETURN(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ReferenceType.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ReferenceType.java index 3726840cd..2baf9fa2e 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ReferenceType.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/ReferenceType.java @@ -1,349 +1,349 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * Super class for object and array types. - * - * @version $Id: ReferenceType.java,v 1.2.10.1 2008/04/25 17:55:34 aclement Exp $ - * @author M. Dahm - */ -public abstract class ReferenceType extends Type { - protected ReferenceType(byte t, String s) { - super(t, s); - } - - /** Class is non-abstract but not instantiable from the outside - */ - ReferenceType() { - super(Constants.T_OBJECT, ""); - } - - /** - * Return true iff this type is castable to another type t as defined in - * the JVM specification. The case where this is Type.NULL is not - * defined (see the CHECKCAST definition in the JVM specification). - * However, because e.g. CHECKCAST doesn't throw a - * ClassCastException when casting a null reference to any Object, - * true is returned in this case. - */ - public boolean isCastableTo(Type t) { - if (this.equals(Type.NULL)) - return true; // If this is ever changed in isAssignmentCompatible() - - return isAssignmentCompatibleWith(t); - /* Yes, it's true: It's the same definition. - * See vmspec2 AASTORE / CHECKCAST definitions. - */ - } - - /** - * Return true iff this is assignment compatible with another type t - * as defined in the JVM specification; see the AASTORE definition - * there. - */ - public boolean isAssignmentCompatibleWith(Type t) { - if (!(t instanceof ReferenceType)) - return false; - - ReferenceType T = (ReferenceType) t; - - if (this.equals(Type.NULL)) - return true; // This is not explicitely stated, but clear. Isn't it? - - /* If this is a class type then - */ - if ((this instanceof ObjectType) && (((ObjectType) this).referencesClass())) { - /* If T is a class type, then this must be the same class as T, - or this must be a subclass of T; - */ - if ((T instanceof ObjectType) && (((ObjectType) T).referencesClass())) { - if (this.equals(T)) - return true; - - if (Repository.instanceOf(((ObjectType) this).getClassName(), - ((ObjectType) T).getClassName())) - return true; - } - - /* If T is an interface type, this must implement interface T. - */ - if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterface())) { - if (Repository.implementationOf(((ObjectType) this).getClassName(), - ((ObjectType) T).getClassName())) - return true; - } - } - - /* If this is an interface type, then: - */ - if ((this instanceof ObjectType) && (((ObjectType) this).referencesInterface())) { - /* If T is a class type, then T must be Object (§2.4.7). - */ - if ((T instanceof ObjectType) && (((ObjectType) T).referencesClass())) { - if (T.equals(Type.OBJECT)) return true; - } - - /* If T is an interface type, then T must be the same interface - * as this or a superinterface of this (§2.13.2). - */ - if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterface())) { - if (this.equals(T)) return true; - if (Repository.implementationOf(((ObjectType) this).getClassName(), - ((ObjectType) T).getClassName())) - return true; - } - } - - /* If this is an array type, namely, the type SC[], that is, an - * array of components of type SC, then: - */ - if (this instanceof ArrayType) { - /* If T is a class type, then T must be Object (§2.4.7). - */ - if ((T instanceof ObjectType) && (((ObjectType) T).referencesClass())) { - if (T.equals(Type.OBJECT)) return true; - } - - /* If T is an array type TC[], that is, an array of components - * of type TC, then one of the following must be true: - */ - if (T instanceof ArrayType) { - /* TC and SC are the same primitive type (§2.4.1). - */ - Type sc = ((ArrayType) this).getElementType(); - Type tc = ((ArrayType) this).getElementType(); - - if (sc instanceof BasicType && tc instanceof BasicType && sc.equals(tc)) - return true; - - /* TC and SC are reference types (§2.4.6), and type SC is - * assignable to TC by these runtime rules. - */ - if (tc instanceof ReferenceType && sc instanceof ReferenceType && - ((ReferenceType) sc).isAssignmentCompatibleWith((ReferenceType) tc)) - return true; - } - - /* If T is an interface type, T must be one of the interfaces implemented by arrays (§2.15). */ - // TODO: Check if this is still valid or find a way to dynamically find out which - // interfaces arrays implement. However, as of the JVM specification edition 2, there - // are at least two different pages where assignment compatibility is defined and - // on one of them "interfaces implemented by arrays" is exchanged with "'Cloneable' or - // 'java.io.Serializable'" - if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterface())) { - for (int ii = 0; ii < Constants.INTERFACES_IMPLEMENTED_BY_ARRAYS.length; ii++) { - if (T.equals(new ObjectType(Constants.INTERFACES_IMPLEMENTED_BY_ARRAYS[ii]))) return true; - } - } - } - return false; // default. - } - - /** - * This commutative operation returns the first common superclass (narrowest ReferenceType - * referencing a class, not an interface). - * If one of the types is a superclass of the other, the former is returned. - * If "this" is Type.NULL, then t is returned. - * If t is Type.NULL, then "this" is returned. - * If "this" equals t ['this.equals(t)'] "this" is returned. - * If "this" or t is an ArrayType, then Type.OBJECT is returned; - * unless their dimensions match. Then an ArrayType of the same - * number of dimensions is returned, with its basic type being the - * first common super class of the basic types of "this" and t. - * If "this" or t is a ReferenceType referencing an interface, then Type.OBJECT is returned. - * If not all of the two classes' superclasses cannot be found, "null" is returned. - * See the JVM specification edition 2, "§4.9.2 The Bytecode Verifier". - */ - public ReferenceType getFirstCommonSuperclass(ReferenceType t) { - if (this.equals(Type.NULL)) return t; - if (t.equals(Type.NULL)) return this; - if (this.equals(t)) return this; - /* - * TODO: Above sounds a little arbitrary. On the other hand, there is - * no object referenced by Type.NULL so we can also say all the objects - * referenced by Type.NULL were derived from java.lang.Object. - * However, the Java Language's "instanceof" operator proves us wrong: - * "null" is not referring to an instance of java.lang.Object :) - */ - - /* This code is from a bug report by Konstantin Shagin */ - - if ((this instanceof ArrayType) && (t instanceof ArrayType)) { - ArrayType arrType1 = (ArrayType) this; - ArrayType arrType2 = (ArrayType) t; - if ( - (arrType1.getDimensions() == arrType2.getDimensions()) && - arrType1.getBasicType() instanceof ObjectType && - arrType2.getBasicType() instanceof ObjectType) { - return new ArrayType( - ((ObjectType) arrType1.getBasicType()).getFirstCommonSuperclass((ObjectType) arrType2.getBasicType()), - arrType1.getDimensions() - ); - - } - } - - if ((this instanceof ArrayType) || (t instanceof ArrayType)) - return Type.OBJECT; - // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType? - - if (((this instanceof ObjectType) && ((ObjectType) this).referencesInterface()) || - ((t instanceof ObjectType) && ((ObjectType) t).referencesInterface())) - return Type.OBJECT; - // TODO: The above line is correct comparing to the vmspec2. But one could - // make class file verification a bit stronger here by using the notion of - // superinterfaces or even castability or assignment compatibility. - - - // this and t are ObjectTypes, see above. - ObjectType thiz = (ObjectType) this; - ObjectType other = (ObjectType) t; - JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName()); - JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName()); - - if ((thiz_sups == null) || (other_sups == null)) { - return null; - } - - // Waaahh... - JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1]; - JavaClass[] t_sups = new JavaClass[other_sups.length + 1]; - System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length); - System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length); - this_sups[0] = Repository.lookupClass(thiz.getClassName()); - t_sups[0] = Repository.lookupClass(other.getClassName()); - - for (int i = 0; i < t_sups.length; i++) { - for (int j = 0; j < this_sups.length; j++) { - if (this_sups[j].equals(t_sups[i])) return new ObjectType(this_sups[j].getClassName()); - } - } - - // Huh? Did you ask for Type.OBJECT's superclass?? - return null; - } - - /** - * This commutative operation returns the first common superclass (narrowest ReferenceType - * referencing a class, not an interface). - * If one of the types is a superclass of the other, the former is returned. - * If "this" is Type.NULL, then t is returned. - * If t is Type.NULL, then "this" is returned. - * If "this" equals t ['this.equals(t)'] "this" is returned. - * If "this" or t is an ArrayType, then Type.OBJECT is returned. - * If "this" or t is a ReferenceType referencing an interface, then Type.OBJECT is returned. - * If not all of the two classes' superclasses cannot be found, "null" is returned. - * See the JVM specification edition 2, "§4.9.2 The Bytecode Verifier". - * - * @deprecated use getFirstCommonSuperclass(ReferenceType t) which has - * slightly changed semantics. - */ - public ReferenceType firstCommonSuperclass(ReferenceType t) { - if (this.equals(Type.NULL)) return t; - if (t.equals(Type.NULL)) return this; - if (this.equals(t)) return this; - /* - * TODO: Above sounds a little arbitrary. On the other hand, there is - * no object referenced by Type.NULL so we can also say all the objects - * referenced by Type.NULL were derived from java.lang.Object. - * However, the Java Language's "instanceof" operator proves us wrong: - * "null" is not referring to an instance of java.lang.Object :) - */ - - if ((this instanceof ArrayType) || (t instanceof ArrayType)) - return Type.OBJECT; - // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType? - - if (((this instanceof ObjectType) && ((ObjectType) this).referencesInterface()) || - ((t instanceof ObjectType) && ((ObjectType) t).referencesInterface())) - return Type.OBJECT; - // TODO: The above line is correct comparing to the vmspec2. But one could - // make class file verification a bit stronger here by using the notion of - // superinterfaces or even castability or assignment compatibility. - - - // this and t are ObjectTypes, see above. - ObjectType thiz = (ObjectType) this; - ObjectType other = (ObjectType) t; - JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName()); - JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName()); - - if ((thiz_sups == null) || (other_sups == null)) { - return null; - } - - // Waaahh... - JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1]; - JavaClass[] t_sups = new JavaClass[other_sups.length + 1]; - System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length); - System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length); - this_sups[0] = Repository.lookupClass(thiz.getClassName()); - t_sups[0] = Repository.lookupClass(other.getClassName()); - - for (int i = 0; i < t_sups.length; i++) { - for (int j = 0; j < this_sups.length; j++) { - if (this_sups[j].equals(t_sups[i])) return new ObjectType(this_sups[j].getClassName()); - } - } - - // Huh? Did you ask for Type.OBJECT's superclass?? - return null; - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.Repository; +import org.aspectj.apache.bcel.classfile.JavaClass; + +/** + * Super class for object and array types. + * + * @version $Id: ReferenceType.java,v 1.2.10.2 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + */ +public abstract class ReferenceType extends Type { + protected ReferenceType(byte t, String s) { + super(t, s); + } + + /** Class is non-abstract but not instantiable from the outside + */ + ReferenceType() { + super(Constants.T_OBJECT, ""); + } + + /** + * Return true iff this type is castable to another type t as defined in + * the JVM specification. The case where this is Type.NULL is not + * defined (see the CHECKCAST definition in the JVM specification). + * However, because e.g. CHECKCAST doesn't throw a + * ClassCastException when casting a null reference to any Object, + * true is returned in this case. + */ + public boolean isCastableTo(Type t) { + if (this.equals(Type.NULL)) + return true; // If this is ever changed in isAssignmentCompatible() + + return isAssignmentCompatibleWith(t); + /* Yes, it's true: It's the same definition. + * See vmspec2 AASTORE / CHECKCAST definitions. + */ + } + + /** + * Return true iff this is assignment compatible with another type t + * as defined in the JVM specification; see the AASTORE definition + * there. + */ + public boolean isAssignmentCompatibleWith(Type t) { + if (!(t instanceof ReferenceType)) + return false; + + ReferenceType T = (ReferenceType) t; + + if (this.equals(Type.NULL)) + return true; // This is not explicitely stated, but clear. Isn't it? + + /* If this is a class type then + */ + if ((this instanceof ObjectType) && (((ObjectType) this).referencesClass())) { + /* If T is a class type, then this must be the same class as T, + or this must be a subclass of T; + */ + if ((T instanceof ObjectType) && (((ObjectType) T).referencesClass())) { + if (this.equals(T)) + return true; + + if (Repository.instanceOf(((ObjectType) this).getClassName(), + ((ObjectType) T).getClassName())) + return true; + } + + /* If T is an interface type, this must implement interface T. + */ + if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterface())) { + if (Repository.implementationOf(((ObjectType) this).getClassName(), + ((ObjectType) T).getClassName())) + return true; + } + } + + /* If this is an interface type, then: + */ + if ((this instanceof ObjectType) && (((ObjectType) this).referencesInterface())) { + /* If T is a class type, then T must be Object (§2.4.7). + */ + if ((T instanceof ObjectType) && (((ObjectType) T).referencesClass())) { + if (T.equals(Type.OBJECT)) return true; + } + + /* If T is an interface type, then T must be the same interface + * as this or a superinterface of this (§2.13.2). + */ + if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterface())) { + if (this.equals(T)) return true; + if (Repository.implementationOf(((ObjectType) this).getClassName(), + ((ObjectType) T).getClassName())) + return true; + } + } + + /* If this is an array type, namely, the type SC[], that is, an + * array of components of type SC, then: + */ + if (this instanceof ArrayType) { + /* If T is a class type, then T must be Object (§2.4.7). + */ + if ((T instanceof ObjectType) && (((ObjectType) T).referencesClass())) { + if (T.equals(Type.OBJECT)) return true; + } + + /* If T is an array type TC[], that is, an array of components + * of type TC, then one of the following must be true: + */ + if (T instanceof ArrayType) { + /* TC and SC are the same primitive type (§2.4.1). + */ + Type sc = ((ArrayType) this).getElementType(); + Type tc = ((ArrayType) this).getElementType(); + + if (sc instanceof BasicType && tc instanceof BasicType && sc.equals(tc)) + return true; + + /* TC and SC are reference types (§2.4.6), and type SC is + * assignable to TC by these runtime rules. + */ + if (tc instanceof ReferenceType && sc instanceof ReferenceType && + ((ReferenceType) sc).isAssignmentCompatibleWith((ReferenceType) tc)) + return true; + } + + /* If T is an interface type, T must be one of the interfaces implemented by arrays (§2.15). */ + // TODO: Check if this is still valid or find a way to dynamically find out which + // interfaces arrays implement. However, as of the JVM specification edition 2, there + // are at least two different pages where assignment compatibility is defined and + // on one of them "interfaces implemented by arrays" is exchanged with "'Cloneable' or + // 'java.io.Serializable'" + if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterface())) { + for (int ii = 0; ii < Constants.INTERFACES_IMPLEMENTED_BY_ARRAYS.length; ii++) { + if (T.equals(new ObjectType(Constants.INTERFACES_IMPLEMENTED_BY_ARRAYS[ii]))) return true; + } + } + } + return false; // default. + } + + /** + * This commutative operation returns the first common superclass (narrowest ReferenceType + * referencing a class, not an interface). + * If one of the types is a superclass of the other, the former is returned. + * If "this" is Type.NULL, then t is returned. + * If t is Type.NULL, then "this" is returned. + * If "this" equals t ['this.equals(t)'] "this" is returned. + * If "this" or t is an ArrayType, then Type.OBJECT is returned; + * unless their dimensions match. Then an ArrayType of the same + * number of dimensions is returned, with its basic type being the + * first common super class of the basic types of "this" and t. + * If "this" or t is a ReferenceType referencing an interface, then Type.OBJECT is returned. + * If not all of the two classes' superclasses cannot be found, "null" is returned. + * See the JVM specification edition 2, "§4.9.2 The Bytecode Verifier". + */ + public ReferenceType getFirstCommonSuperclass(ReferenceType t) { + if (this.equals(Type.NULL)) return t; + if (t.equals(Type.NULL)) return this; + if (this.equals(t)) return this; + /* + * TODO: Above sounds a little arbitrary. On the other hand, there is + * no object referenced by Type.NULL so we can also say all the objects + * referenced by Type.NULL were derived from java.lang.Object. + * However, the Java Language's "instanceof" operator proves us wrong: + * "null" is not referring to an instance of java.lang.Object :) + */ + + /* This code is from a bug report by Konstantin Shagin */ + + if ((this instanceof ArrayType) && (t instanceof ArrayType)) { + ArrayType arrType1 = (ArrayType) this; + ArrayType arrType2 = (ArrayType) t; + if ( + (arrType1.getDimensions() == arrType2.getDimensions()) && + arrType1.getBasicType() instanceof ObjectType && + arrType2.getBasicType() instanceof ObjectType) { + return new ArrayType( + ((ObjectType) arrType1.getBasicType()).getFirstCommonSuperclass((ObjectType) arrType2.getBasicType()), + arrType1.getDimensions() + ); + + } + } + + if ((this instanceof ArrayType) || (t instanceof ArrayType)) + return Type.OBJECT; + // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType? + + if (((this instanceof ObjectType) && ((ObjectType) this).referencesInterface()) || + ((t instanceof ObjectType) && ((ObjectType) t).referencesInterface())) + return Type.OBJECT; + // TODO: The above line is correct comparing to the vmspec2. But one could + // make class file verification a bit stronger here by using the notion of + // superinterfaces or even castability or assignment compatibility. + + + // this and t are ObjectTypes, see above. + ObjectType thiz = (ObjectType) this; + ObjectType other = (ObjectType) t; + JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName()); + JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName()); + + if ((thiz_sups == null) || (other_sups == null)) { + return null; + } + + // Waaahh... + JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1]; + JavaClass[] t_sups = new JavaClass[other_sups.length + 1]; + System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length); + System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length); + this_sups[0] = Repository.lookupClass(thiz.getClassName()); + t_sups[0] = Repository.lookupClass(other.getClassName()); + + for (int i = 0; i < t_sups.length; i++) { + for (int j = 0; j < this_sups.length; j++) { + if (this_sups[j].equals(t_sups[i])) return new ObjectType(this_sups[j].getClassName()); + } + } + + // Huh? Did you ask for Type.OBJECT's superclass?? + return null; + } + + /** + * This commutative operation returns the first common superclass (narrowest ReferenceType + * referencing a class, not an interface). + * If one of the types is a superclass of the other, the former is returned. + * If "this" is Type.NULL, then t is returned. + * If t is Type.NULL, then "this" is returned. + * If "this" equals t ['this.equals(t)'] "this" is returned. + * If "this" or t is an ArrayType, then Type.OBJECT is returned. + * If "this" or t is a ReferenceType referencing an interface, then Type.OBJECT is returned. + * If not all of the two classes' superclasses cannot be found, "null" is returned. + * See the JVM specification edition 2, "§4.9.2 The Bytecode Verifier". + * + * @deprecated use getFirstCommonSuperclass(ReferenceType t) which has + * slightly changed semantics. + */ + public ReferenceType firstCommonSuperclass(ReferenceType t) { + if (this.equals(Type.NULL)) return t; + if (t.equals(Type.NULL)) return this; + if (this.equals(t)) return this; + /* + * TODO: Above sounds a little arbitrary. On the other hand, there is + * no object referenced by Type.NULL so we can also say all the objects + * referenced by Type.NULL were derived from java.lang.Object. + * However, the Java Language's "instanceof" operator proves us wrong: + * "null" is not referring to an instance of java.lang.Object :) + */ + + if ((this instanceof ArrayType) || (t instanceof ArrayType)) + return Type.OBJECT; + // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType? + + if (((this instanceof ObjectType) && ((ObjectType) this).referencesInterface()) || + ((t instanceof ObjectType) && ((ObjectType) t).referencesInterface())) + return Type.OBJECT; + // TODO: The above line is correct comparing to the vmspec2. But one could + // make class file verification a bit stronger here by using the notion of + // superinterfaces or even castability or assignment compatibility. + + + // this and t are ObjectTypes, see above. + ObjectType thiz = (ObjectType) this; + ObjectType other = (ObjectType) t; + JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName()); + JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName()); + + if ((thiz_sups == null) || (other_sups == null)) { + return null; + } + + // Waaahh... + JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1]; + JavaClass[] t_sups = new JavaClass[other_sups.length + 1]; + System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length); + System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length); + this_sups[0] = Repository.lookupClass(thiz.getClassName()); + t_sups[0] = Repository.lookupClass(other.getClassName()); + + for (int i = 0; i < t_sups.length; i++) { + for (int j = 0; j < this_sups.length; j++) { + if (this_sups[j].equals(t_sups[i])) return new ObjectType(this_sups[j].getClassName()); + } + } + + // Huh? Did you ask for Type.OBJECT's superclass?? + return null; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ReturnInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ReturnInstruction.java deleted file mode 100644 index 7ed21807d..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ReturnInstruction.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.ExceptionConstants; - -/** - * Super class for the xRETURN family of instructions. - * - * @version $Id: ReturnInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public abstract class ReturnInstruction extends Instruction - implements ExceptionThrower, TypedInstruction, StackConsumer { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - ReturnInstruction() {} - - /** - * @param opcode of instruction - */ - protected ReturnInstruction(short opcode) { - super(opcode, (short)1); - } - - public Type getType() { - switch(opcode) { - case Constants.IRETURN: return Type.INT; - case Constants.LRETURN: return Type.LONG; - case Constants.FRETURN: return Type.FLOAT; - case Constants.DRETURN: return Type.DOUBLE; - case Constants.ARETURN: return Type.OBJECT; - case Constants.RETURN: return Type.VOID; - - default: // Never reached - throw new ClassGenException("Unknown type " + opcode); - } - } - - public Class[] getExceptions() { - return new Class[] { ExceptionConstants.ILLEGAL_MONITOR_STATE }; - } - - /** @return type associated with the instruction - */ - public Type getType(ConstantPoolGen cp) { - return getType(); - } -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ReturnaddressType.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ReturnaddressType.java index d50b68cdb..a4bd067c0 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ReturnaddressType.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/ReturnaddressType.java @@ -1,102 +1,102 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.generic.InstructionHandle; - -/** - * Returnaddress, the type JSR or JSR_W instructions push upon the stack. - * - * see vmspec2 §3.3.3 - * @version $Id: ReturnaddressType.java,v 1.2.10.1 2008/04/25 17:55:35 aclement Exp $ - * @author Enver Haase - */ -public class ReturnaddressType extends Type { - - public static final ReturnaddressType NO_TARGET = new ReturnaddressType(); - private InstructionHandle returnTarget; - - /** - * A Returnaddress [that doesn't know where to return to]. - */ - private ReturnaddressType(){ - super(Constants.T_ADDRESS, ""); - } - - /** - * Creates a ReturnaddressType object with a target. - */ - public ReturnaddressType(InstructionHandle returnTarget) { - super(Constants.T_ADDRESS, ""); - this.returnTarget = returnTarget; - } - - /** - * Returns if the two Returnaddresses refer to the same target. - */ - public boolean equals(Object rat){ - if(!(rat instanceof ReturnaddressType)) - return false; - - return ((ReturnaddressType)rat).returnTarget.equals(this.returnTarget); - } - - /** - * @return the target of this ReturnaddressType - */ - public InstructionHandle getTarget(){ - return returnTarget; - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.generic.InstructionHandle; + +/** + * Returnaddress, the type JSR or JSR_W instructions push upon the stack. + * + * see vmspec2 §3.3.3 + * @version $Id: ReturnaddressType.java,v 1.2.10.2 2008/05/08 19:26:45 aclement Exp $ + * @author Enver Haase + */ +public class ReturnaddressType extends Type { + + public static final ReturnaddressType NO_TARGET = new ReturnaddressType(); + private InstructionHandle returnTarget; + + /** + * A Returnaddress [that doesn't know where to return to]. + */ + private ReturnaddressType(){ + super(Constants.T_ADDRESS, ""); + } + + /** + * Creates a ReturnaddressType object with a target. + */ + public ReturnaddressType(InstructionHandle returnTarget) { + super(Constants.T_ADDRESS, ""); + this.returnTarget = returnTarget; + } + + /** + * Returns if the two Returnaddresses refer to the same target. + */ + public boolean equals(Object rat){ + if(!(rat instanceof ReturnaddressType)) + return false; + + return ((ReturnaddressType)rat).returnTarget.equals(this.returnTarget); + } + + /** + * @return the target of this ReturnaddressType + */ + public InstructionHandle getTarget(){ + return returnTarget; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/SALOAD.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/SALOAD.java deleted file mode 100644 index da41cdfcb..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/SALOAD.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * SALOAD - Load short from array - *
          Stack: ..., arrayref, index -> ..., value
          - * - * @version $Id: SALOAD.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class SALOAD extends ArrayInstruction implements StackProducer { - public SALOAD() { - super(org.aspectj.apache.bcel.Constants.SALOAD); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitSALOAD(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/SASTORE.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/SASTORE.java deleted file mode 100644 index 4c1afb0fb..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/SASTORE.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * SASTORE - Store into short array - *
          Stack: ..., arrayref, index, value -> ...
          - * - * @version $Id: SASTORE.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class SASTORE extends ArrayInstruction implements StackConsumer { - public SASTORE() { - super(org.aspectj.apache.bcel.Constants.SASTORE); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitArrayInstruction(this); - v.visitSASTORE(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/SIPUSH.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/SIPUSH.java deleted file mode 100644 index 717947172..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/SIPUSH.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * SIPUSH - Push short - * - *
          Stack: ... -> ..., value
          - * - * @version $Id: SIPUSH.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public class SIPUSH extends Instruction implements ConstantPushInstruction { - private short b; - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - SIPUSH() {} - - public SIPUSH(short b) { - super(org.aspectj.apache.bcel.Constants.SIPUSH, (short)3); - this.b = b; - } - - /** - * Dump instruction as short code to stream out. - */ - public void dump(DataOutputStream out) throws IOException { - super.dump(out); - out.writeShort(b); - } - - /** - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - return super.toString(verbose) + " " + b; - } - - /** - * Read needed data (e.g. index) from file. - */ - protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException - { - length = 3; - b = bytes.readShort(); - } - - public Number getValue() { return new Integer(b); } - - /** @return Type.SHORT - */ - public Type getType(ConstantPoolGen cp) { - return Type.SHORT; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitPushInstruction(this); - v.visitStackProducer(this); - v.visitTypedInstruction(this); - v.visitConstantPushInstruction(this); - v.visitSIPUSH(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/SWAP.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/SWAP.java deleted file mode 100644 index ee2b4e39b..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/SWAP.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * SWAP - Swa top operand stack word - *
          Stack: ..., word2, word1 -> ..., word1, word2
          - * - * @version $Id: SWAP.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ - * @author M. Dahm - */ -public class SWAP extends StackInstruction implements StackConsumer, StackProducer { - public SWAP() { - super(org.aspectj.apache.bcel.Constants.SWAP); - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitStackProducer(this); - v.visitStackInstruction(this); - v.visitSWAP(this); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/SWITCH.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/SWITCH.java deleted file mode 100644 index 9253e796b..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/SWITCH.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * SWITCH - Branch depending on int value, generates either LOOKUPSWITCH or - * TABLESWITCH instruction, depending on whether the match values (int[]) can be - * sorted with no gaps between the numbers. - * - * @version $Id: SWITCH.java,v 1.4 2005/12/06 11:28:24 aclement Exp $ - * @author M. Dahm - */ -public final class SWITCH implements CompoundInstruction { - private int[] match; - private InstructionHandle[] targets; - private Select instruction; - private int match_length; - - /** - * Template for switch() constructs. If the match array can be - * sorted in ascending order with gaps no larger than max_gap - * between the numbers, a TABLESWITCH instruction is generated, and - * a LOOKUPSWITCH otherwise. The former may be more efficient, but - * needs more space. - * - * Note, that the key array always will be sorted, though we leave - * the original arrays unaltered. - * - * @param match array of match values (case 2: ... case 7: ..., etc.) - * @param targets the instructions to be branched to for each case - * @param target the default target - * @param max_gap maximum gap that may between case branches - */ - public SWITCH(int[] match, InstructionHandle[] targets, - InstructionHandle target, int max_gap) { - this.match = (int[])match.clone(); - this.targets = (InstructionHandle[])targets.clone(); - - if((match_length = match.length) < 2) // (almost) empty switch, or just default - if (match.length==0) { - instruction = new LOOKUPSWITCH(match,targets,target); - } else { - instruction = new TABLESWITCH(match,targets,target); - } - else { - sort(0, match_length - 1); - - if(matchIsOrdered(max_gap)) { - fillup(max_gap, target); - - instruction = new TABLESWITCH(this.match, this.targets, target); - } - else - instruction = new LOOKUPSWITCH(this.match, this.targets, target); - } - } - - public SWITCH(int[] match, InstructionHandle[] targets, - InstructionHandle target) { - this(match, targets, target, 1); - } - - private final void fillup(int max_gap, InstructionHandle target) { - int max_size = match_length + match_length * max_gap; - int[] m_vec = new int[max_size]; - InstructionHandle[] t_vec = new InstructionHandle[max_size]; - int count = 1; - - m_vec[0] = match[0]; - t_vec[0] = targets[0]; - - for(int i=1; i < match_length; i++) { - int prev = match[i-1]; - int gap = match[i] - prev; - - for(int j=1; j < gap; j++) { - m_vec[count] = prev + j; - t_vec[count] = target; - count++; - } - - m_vec[count] = match[i]; - t_vec[count] = targets[i]; - count++; - } - - match = new int[count]; - targets = new InstructionHandle[count]; - - System.arraycopy(m_vec, 0, match, 0, count); - System.arraycopy(t_vec, 0, targets, 0, count); - } - - /** - * Sort match and targets array with QuickSort. - */ - private final void sort(int l, int r) { - int i = l, j = r; - int h, m = match[(l + r) / 2]; - InstructionHandle h2; - - do { - while(match[i] < m) i++; - while(m < match[j]) j--; - - if(i <= j) { - h=match[i]; match[i]=match[j]; match[j]=h; // Swap elements - h2=targets[i]; targets[i]=targets[j]; targets[j]=h2; // Swap instructions, too - i++; j--; - } - } while(i <= j); - - if(l < j) sort(l, j); - if(i < r) sort(i, r); - } - - /** - * @return match is sorted in ascending order with no gap bigger than max_gap? - */ - private final boolean matchIsOrdered(int max_gap) { - for(int i=1; i < match_length; i++) { - int diff = (match[i]-match[i-1]); - if(diff > max_gap || diff<0) return false; - } - return true; - } - - public final InstructionList getInstructionList() { - return new InstructionList(instruction); - } - - public final Instruction getInstruction() { - return instruction; - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/Select.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/Select.java deleted file mode 100644 index 6a8b19d9d..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/Select.java +++ /dev/null @@ -1,254 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * Select - Abstract super class for LOOKUPSWITCH and TABLESWITCH instructions. - * - * @version $Id: Select.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - * @see LOOKUPSWITCH - * @see TABLESWITCH - * @see InstructionList - */ -public abstract class Select extends BranchInstruction - implements VariableLengthInstruction, StackProducer -{ - protected int[] match; // matches, i.e., case 1: ... - protected int[] indices; // target offsets - protected InstructionHandle[] targets; // target objects in instruction list - protected int fixed_length; // fixed length defined by subclasses - protected int match_length; // number of cases - protected int padding = 0; // number of pad bytes for alignment - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - Select() {} - - /** - * (Match, target) pairs for switch. - * `Match' and `targets' must have the same length of course. - * - * @param match array of matching values - * @param targets instruction targets - * @param target default instruction target - */ - Select(short opcode, int[] match, InstructionHandle[] targets, - InstructionHandle target) { - super(opcode, target); - - this.targets = targets; - for(int i=0; i < targets.length; i++) - notifyTarget(null, targets[i], this); - - this.match = match; - - if((match_length = match.length) != targets.length) - throw new ClassGenException("Match and target array have not the same length"); - - indices = new int[match_length]; - } - - /** - * Since this is a variable length instruction, it may shift the following - * instructions which then need to update their position. - * - * Called by InstructionList.setPositions when setting the position for every - * instruction. In the presence of variable length instructions `setPositions' - * performs multiple passes over the instruction list to calculate the - * correct (byte) positions and offsets by calling this function. - * - * @param offset additional offset caused by preceding (variable length) instructions - * @param max_offset the maximum offset that may be caused by these instructions - * @return additional offset caused by possible change of this instruction's length - */ - protected int updatePosition(int offset, int max_offset) { - position += offset; // Additional offset caused by preceding SWITCHs, GOTOs, etc. - - short old_length = length; - - /* Alignment on 4-byte-boundary, + 1, because of tag byte. - */ - padding = (4 - ((position + 1) % 4)) % 4; - length = (short)(fixed_length + padding); // Update length - - return length - old_length; - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - out.writeByte(opcode); - - for(int i=0; i < padding; i++) // Padding bytes - out.writeByte(0); - - index = getTargetOffset(); // Write default target offset - out.writeInt(index); - } - - /** - * Read needed data (e.g. index) from file. - */ - protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException - { - padding = (4 - (bytes.getIndex() % 4)) % 4; // Compute number of pad bytes - - for(int i=0; i < padding; i++) { - bytes.readByte(); - } - - // Default branch target common for both cases (TABLESWITCH, LOOKUPSWITCH) - index = bytes.readInt(); - } - - /** - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - StringBuffer buf = new StringBuffer(super.toString(verbose)); - - if(verbose) { - for(int i=0; i < match_length; i++) { - String s = "null"; - - if(targets[i] != null) - s = targets[i].getInstruction().toString(); - - buf.append("(" + match[i] + ", " + s + " = {" + indices[i] + "})"); - } - } - else - buf.append(" ..."); - - return buf.toString(); - } - - /** - * Set branch target for `i'th case - */ - public void setTarget(int i, InstructionHandle target) { - notifyTarget(targets[i], target, this); - targets[i] = target; - } - - /** - * @param old_ih old target - * @param new_ih new target - */ - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { - boolean targeted = false; - - if(target == old_ih) { - targeted = true; - setTarget(new_ih); - } - - for(int i=0; i < targets.length; i++) { - if(targets[i] == old_ih) { - targeted = true; - setTarget(i, new_ih); - } - } - - if(!targeted) - throw new ClassGenException("Not targeting " + old_ih); - } - - /** - * @return true, if ih is target of this instruction - */ - public boolean containsTarget(InstructionHandle ih) { - if(target == ih) - return true; - - for(int i=0; i < targets.length; i++) - if(targets[i] == ih) - return true; - - return false; - } - - /** - * Inform targets that they're not targeted anymore. - */ - void dispose() { - super.dispose(); - - for(int i=0; i < targets.length; i++) - targets[i].removeTargeter(this); - } - - /** - * @return array of match indices - */ - public int[] getMatchs() { return match; } - - /** - * @return array of match target offsets - */ - public int[] getIndices() { return indices; } - - /** - * @return array of match targets - */ - public InstructionHandle[] getTargets() { return targets; } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/StackConsumer.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/StackConsumer.java deleted file mode 100644 index f302caa35..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/StackConsumer.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denote an instruction that may consume a value from the stack. - * - * @version $Id: StackConsumer.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public interface StackConsumer { - /** @return how many words are consumed from stack - */ - public int consumeStack(ConstantPoolGen cpg); -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/StackInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/StackInstruction.java deleted file mode 100644 index e98f38286..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/StackInstruction.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Super class for stack operations like DUP and POP. - * - * @version $Id: StackInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public abstract class StackInstruction extends Instruction { - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - StackInstruction() {} - - /** - * @param opcode instruction opcode - */ - protected StackInstruction(short opcode) { - super(opcode, (short)1); - } - - /** @return Type.UNKNOWN - */ - public Type getType(ConstantPoolGen cp) { - return Type.UNKNOWN; - } -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/StackProducer.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/StackProducer.java deleted file mode 100644 index 4fc3ea20c..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/StackProducer.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denote an instruction that may produce a value on top of the stack - * (this excludes DUP_X1, e.g.) - * - * @version $Id: StackProducer.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public interface StackProducer { - /** @return how many words are produced on stack - */ - public int produceStack(ConstantPoolGen cpg); -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/StoreInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/StoreInstruction.java deleted file mode 100644 index a069c6e89..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/StoreInstruction.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denotes an unparameterized instruction to store a value into a local variable, - * e.g. ISTORE. - * - * @version $Id: StoreInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public abstract class StoreInstruction extends LocalVariableInstruction - implements PopInstruction -{ - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - * tag and length are defined in readInstruction and initFromFile, respectively. - */ - StoreInstruction(short canon_tag, short c_tag) { - super(canon_tag, c_tag); - } - - /** - * @param opcode Instruction opcode - * @param c_tag Instruction number for compact version, ASTORE_0, e.g. - * @param n local variable index (unsigned short) - */ - protected StoreInstruction(short opcode, short c_tag, int n) { - super(opcode, c_tag, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackConsumer(this); - v.visitPopInstruction(this); - v.visitTypedInstruction(this); - v.visitLocalVariableInstruction(this); - v.visitStoreInstruction(this); - } -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/SwitchBuilder.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/SwitchBuilder.java index 351e33c33..afc6a3bb3 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/SwitchBuilder.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/SwitchBuilder.java @@ -1,181 +1,181 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * SWITCH - Branch depending on int value, generates either LOOKUPSWITCH or - * TABLESWITCH instruction, depending on whether the match values (int[]) can be - * sorted with no gaps between the numbers. - * - * @version $Id: SwitchBuilder.java,v 1.1.2.2 2008/04/25 17:55:33 aclement Exp $ - * @author M. Dahm - */ -public final class SwitchBuilder { - private int[] match; - private InstructionHandle[] targets; - private InstructionSelect instruction; - private int match_length; - - /** - * Template for switch() constructs. If the match array can be - * sorted in ascending order with gaps no larger than max_gap - * between the numbers, a TABLESWITCH instruction is generated, and - * a LOOKUPSWITCH otherwise. The former may be more efficient, but - * needs more space. - * - * Note, that the key array always will be sorted, though we leave - * the original arrays unaltered. - * - * @param match array of match values (case 2: ... case 7: ..., etc.) - * @param targets the instructions to be branched to for each case - * @param target the default target - * @param max_gap maximum gap that may between case branches - */ - public SwitchBuilder(int[] match, InstructionHandle[] targets,InstructionHandle target, int max_gap) { - this.match = (int[])match.clone(); - this.targets = (InstructionHandle[])targets.clone(); - - if((match_length = match.length) < 2) // (almost) empty switch, or just default - if (match.length==0) { - instruction = new LOOKUPSWITCH(match,targets,target); - } else { - instruction = new TABLESWITCH(match,targets,target); - } - else { - sort(0, match_length - 1); - - if(matchIsOrdered(max_gap)) { - fillup(max_gap, target); - - instruction = new TABLESWITCH(this.match, this.targets, target); - } - else - instruction = new LOOKUPSWITCH(this.match, this.targets, target); - } - } - - public SwitchBuilder(int[] match, InstructionHandle[] targets, InstructionHandle target) { - this(match, targets, target, 1); - } - - private final void fillup(int max_gap, InstructionHandle target) { - int max_size = match_length + match_length * max_gap; - int[] m_vec = new int[max_size]; - InstructionHandle[] t_vec = new InstructionHandle[max_size]; - int count = 1; - - m_vec[0] = match[0]; - t_vec[0] = targets[0]; - - for(int i=1; i < match_length; i++) { - int prev = match[i-1]; - int gap = match[i] - prev; - - for(int j=1; j < gap; j++) { - m_vec[count] = prev + j; - t_vec[count] = target; - count++; - } - - m_vec[count] = match[i]; - t_vec[count] = targets[i]; - count++; - } - - match = new int[count]; - targets = new InstructionHandle[count]; - - System.arraycopy(m_vec, 0, match, 0, count); - System.arraycopy(t_vec, 0, targets, 0, count); - } - - /** - * Sort match and targets array with QuickSort. - */ - private final void sort(int l, int r) { - int i = l, j = r; - int h, m = match[(l + r) / 2]; - InstructionHandle h2; - - do { - while(match[i] < m) i++; - while(m < match[j]) j--; - - if(i <= j) { - h=match[i]; match[i]=match[j]; match[j]=h; // Swap elements - h2=targets[i]; targets[i]=targets[j]; targets[j]=h2; // Swap instructions, too - i++; j--; - } - } while(i <= j); - - if(l < j) sort(l, j); - if(i < r) sort(i, r); - } - - /** - * @return match is sorted in ascending order with no gap bigger than max_gap? - */ - private final boolean matchIsOrdered(int max_gap) { - for(int i=1; i < match_length; i++) { - int diff = (match[i]-match[i-1]); - if(diff > max_gap || diff<0) return false; - } - return true; - } - - public final InstructionSelect getInstruction() { - return instruction; - } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * SWITCH - Branch depending on int value, generates either LOOKUPSWITCH or + * TABLESWITCH instruction, depending on whether the match values (int[]) can be + * sorted with no gaps between the numbers. + * + * @version $Id: SwitchBuilder.java,v 1.1.2.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + */ +public final class SwitchBuilder { + private int[] match; + private InstructionHandle[] targets; + private InstructionSelect instruction; + private int match_length; + + /** + * Template for switch() constructs. If the match array can be + * sorted in ascending order with gaps no larger than max_gap + * between the numbers, a TABLESWITCH instruction is generated, and + * a LOOKUPSWITCH otherwise. The former may be more efficient, but + * needs more space. + * + * Note, that the key array always will be sorted, though we leave + * the original arrays unaltered. + * + * @param match array of match values (case 2: ... case 7: ..., etc.) + * @param targets the instructions to be branched to for each case + * @param target the default target + * @param max_gap maximum gap that may between case branches + */ + public SwitchBuilder(int[] match, InstructionHandle[] targets,InstructionHandle target, int max_gap) { + this.match = (int[])match.clone(); + this.targets = (InstructionHandle[])targets.clone(); + + if((match_length = match.length) < 2) // (almost) empty switch, or just default + if (match.length==0) { + instruction = new LOOKUPSWITCH(match,targets,target); + } else { + instruction = new TABLESWITCH(match,targets,target); + } + else { + sort(0, match_length - 1); + + if(matchIsOrdered(max_gap)) { + fillup(max_gap, target); + + instruction = new TABLESWITCH(this.match, this.targets, target); + } + else + instruction = new LOOKUPSWITCH(this.match, this.targets, target); + } + } + + public SwitchBuilder(int[] match, InstructionHandle[] targets, InstructionHandle target) { + this(match, targets, target, 1); + } + + private final void fillup(int max_gap, InstructionHandle target) { + int max_size = match_length + match_length * max_gap; + int[] m_vec = new int[max_size]; + InstructionHandle[] t_vec = new InstructionHandle[max_size]; + int count = 1; + + m_vec[0] = match[0]; + t_vec[0] = targets[0]; + + for(int i=1; i < match_length; i++) { + int prev = match[i-1]; + int gap = match[i] - prev; + + for(int j=1; j < gap; j++) { + m_vec[count] = prev + j; + t_vec[count] = target; + count++; + } + + m_vec[count] = match[i]; + t_vec[count] = targets[i]; + count++; + } + + match = new int[count]; + targets = new InstructionHandle[count]; + + System.arraycopy(m_vec, 0, match, 0, count); + System.arraycopy(t_vec, 0, targets, 0, count); + } + + /** + * Sort match and targets array with QuickSort. + */ + private final void sort(int l, int r) { + int i = l, j = r; + int h, m = match[(l + r) / 2]; + InstructionHandle h2; + + do { + while(match[i] < m) i++; + while(m < match[j]) j--; + + if(i <= j) { + h=match[i]; match[i]=match[j]; match[j]=h; // Swap elements + h2=targets[i]; targets[i]=targets[j]; targets[j]=h2; // Swap instructions, too + i++; j--; + } + } while(i <= j); + + if(l < j) sort(l, j); + if(i < r) sort(i, r); + } + + /** + * @return match is sorted in ascending order with no gap bigger than max_gap? + */ + private final boolean matchIsOrdered(int max_gap) { + for(int i=1; i < match_length; i++) { + int diff = (match[i]-match[i-1]); + if(diff > max_gap || diff<0) return false; + } + return true; + } + + public final InstructionSelect getInstruction() { + return instruction; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/TABLESWITCH.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/TABLESWITCH.java index 41ee2964a..3ac027ba6 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/TABLESWITCH.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/TABLESWITCH.java @@ -1,136 +1,136 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.util.ByteSequence; - -/** - * TABLESWITCH - Switch within given range of values, i.e., low..high - * - * @version $Id: TABLESWITCH.java,v 1.3.8.2 2008/04/25 17:55:34 aclement Exp $ - * @author M. Dahm - * @see SWITCH - */ -public class TABLESWITCH extends InstructionSelect { - - - /** - * @param match sorted array of match values, match[0] must be low value, - * match[match_length - 1] high value - * @param targets where to branch for matched values - * @param target default branch - */ - public TABLESWITCH(int[] match, InstructionHandle[] targets, - InstructionHandle target) { - super(org.aspectj.apache.bcel.Constants.TABLESWITCH, match, targets, target); - -// if (match_length==0) { -// throw new RuntimeException("A tableswitch with no targets should be represented as a LOOKUPSWITCH"); -// } - - length = (short)(13 + match_length * 4); /* Alignment remainder assumed - * 0 here, until dump time */ - fixed_length = length; - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - super.dump(out); - - int low = (match_length > 0)? match[0] : 0; - out.writeInt(low); - - int high = (match_length > 0)? match[match_length - 1] : 0; - out.writeInt(high); - -// See aj bug pr104720 -// if (match_length==0) out.writeInt(0); // following the switch you need to supply "HIGH-LOW+1" entries - - for(int i=0; i < match_length; i++) // jump offsets - out.writeInt(indices[i] = getTargetOffset(targets[i])); - } - - /** - * Read needed data (e.g. index) from file. - */ - public TABLESWITCH(ByteSequence bytes) throws IOException - { - super(Constants.TABLESWITCH,bytes); - - int low = bytes.readInt(); - int high = bytes.readInt(); - - match_length = high - low + 1; - fixed_length = (short)(13 + match_length * 4); - length = (short)(fixed_length + padding); - - match = new int[match_length]; - indices = new int[match_length]; - targets = new InstructionHandle[match_length]; - - for(int i=low; i <= high; i++) - match[i - low] = i; - - for(int i=0; i < match_length; i++) { - indices[i] = bytes.readInt(); - } - } - -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.io.*; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.util.ByteSequence; + +/** + * TABLESWITCH - Switch within given range of values, i.e., low..high + * + * @version $Id: TABLESWITCH.java,v 1.3.8.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + * @see SWITCH + */ +public class TABLESWITCH extends InstructionSelect { + + + /** + * @param match sorted array of match values, match[0] must be low value, + * match[match_length - 1] high value + * @param targets where to branch for matched values + * @param target default branch + */ + public TABLESWITCH(int[] match, InstructionHandle[] targets, + InstructionHandle target) { + super(org.aspectj.apache.bcel.Constants.TABLESWITCH, match, targets, target); + +// if (match_length==0) { +// throw new RuntimeException("A tableswitch with no targets should be represented as a LOOKUPSWITCH"); +// } + + length = (short)(13 + matchLength * 4); /* Alignment remainder assumed + * 0 here, until dump time */ + fixedLength = length; + } + + /** + * Dump instruction as byte code to stream out. + * @param out Output stream + */ + public void dump(DataOutputStream out) throws IOException { + super.dump(out); + + int low = (matchLength > 0)? match[0] : 0; + out.writeInt(low); + + int high = (matchLength > 0)? match[matchLength - 1] : 0; + out.writeInt(high); + +// See aj bug pr104720 +// if (match_length==0) out.writeInt(0); // following the switch you need to supply "HIGH-LOW+1" entries + + for(int i=0; i < matchLength; i++) // jump offsets + out.writeInt(indices[i] = getTargetOffset(targets[i])); + } + + /** + * Read needed data (e.g. index) from file. + */ + public TABLESWITCH(ByteSequence bytes) throws IOException + { + super(Constants.TABLESWITCH,bytes); + + int low = bytes.readInt(); + int high = bytes.readInt(); + + matchLength = high - low + 1; + fixedLength = (short)(13 + matchLength * 4); + length = (short)(fixedLength + padding); + + match = new int[matchLength]; + indices = new int[matchLength]; + targets = new InstructionHandle[matchLength]; + + for(int i=low; i <= high; i++) + match[i - low] = i; + + for(int i=0; i < matchLength; i++) { + indices[i] = bytes.readInt(); + } + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/Tag.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/Tag.java index 957981159..15b39473a 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/Tag.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/Tag.java @@ -1,42 +1,43 @@ -/* ******************************************************************* - * Copyright (c) 2002 Contributors - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * PARC initial implementation - * Andy Clement pushed down into bcel module - * ******************************************************************/ - - -package org.aspectj.apache.bcel.generic; - - -/** A tag is an instruction-targeter that doesn't bother remembering its target(s) */ -public abstract class Tag implements InstructionTargeter, Cloneable { - - public Tag() { - } - - // ---- from InstructionTargeter - public boolean containsTarget(InstructionHandle ih) { - return false; - } - - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { - old_ih.removeTargeter(this); - if (new_ih != null) - new_ih.addTargeter(this); - } - - public Tag copy() { - try { - return (Tag)clone(); - } catch (CloneNotSupportedException e) { - throw new RuntimeException("Sanity check, can't clone me"); - } - } -} +/* ******************************************************************* + * Copyright (c) 2002 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * PARC initial implementation + * Andy Clement pushed down into bcel module + * ******************************************************************/ + +package org.aspectj.apache.bcel.generic; + +/** + * A tag is an instruction-targeter that does not remember its target + */ +public abstract class Tag implements InstructionTargeter, Cloneable { + + public Tag() { + } + + // ---- from InstructionTargeter + public boolean containsTarget(InstructionHandle ih) { + return false; + } + + public void updateTarget(InstructionHandle oldHandle, InstructionHandle newHandle) { + oldHandle.removeTargeter(this); + if (newHandle != null) { + newHandle.addTargeter(this); + } + } + + public Tag copy() { + try { + return (Tag)clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException("Sanity check, can't clone me"); + } + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/TargetLostException.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/TargetLostException.java index a8c8bfc15..7a0957232 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/TargetLostException.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/TargetLostException.java @@ -1,100 +1,101 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Thrown by InstructionList.remove() when one or multiple disposed instruction - * are still being referenced by a InstructionTargeter object. I.e. the - * InstructionTargeter has to be notified that (one of) the InstructionHandle it - * is referencing is being removed from the InstructionList and thus not valid anymore. - * - * Making this an exception instead of a return value forces the user to handle - * these case explicitely in a try { ... } catch. The following code illustrates - * how this may be done: - * - *
          - *     ...
          - *     try {
          - *	il.delete(start_ih, end_ih);
          - *     } catch(TargetLostException e) {
          - *       InstructionHandle[] targets = e.getTargets();
          - *	 for(int i=0; i < targets.length; i++) {
          - *	   InstructionTargeter[] targeters = targets[i].getTargeters();
          - *     
          - *	   for(int j=0; j < targeters.length; j++)
          - *	     targeters[j].updateTarget(targets[i], new_target);
          - *       }
          - *     }
          - * 
          - * - * @see InstructionHandle - * @see InstructionList - * @see InstructionTargeter - * @version $Id: TargetLostException.java,v 1.2.10.1 2008/04/25 17:55:33 aclement Exp $ - * @author M. Dahm - */ -public final class TargetLostException extends Exception { - private InstructionHandle[] targets; - - TargetLostException(InstructionHandle[] t, String mesg) { - super(mesg); - targets = t; - } - - /** - * @return list of instructions still being targeted. - */ - public InstructionHandle[] getTargets() { return targets; } -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Thrown by InstructionList.remove() when one or multiple disposed instruction + * are still being referenced by a InstructionTargeter object. I.e. the + * InstructionTargeter has to be notified that (one of) the InstructionHandle it + * is referencing is being removed from the InstructionList and thus not valid anymore. + * + * Making this an exception instead of a return value forces the user to handle + * these case explicitely in a try { ... } catch. The following code illustrates + * how this may be done: + * + *
          + *     ...
          + *     try {
          + *	il.delete(start_ih, end_ih);
          + *     } catch(TargetLostException e) {
          + *       InstructionHandle[] targets = e.getTargets();
          + *	 for(int i=0; i < targets.length; i++) {
          + *	   InstructionTargeter[] targeters = targets[i].getTargeters();
          + *     
          + *	   for(int j=0; j < targeters.length; j++)
          + *	     targeters[j].updateTarget(targets[i], new_target);
          + *       }
          + *     }
          + * 
          + * + * @see InstructionHandle + * @see InstructionList + * @see InstructionTargeter + * @version $Id: TargetLostException.java,v 1.2.10.2 2008/05/08 19:26:45 aclement Exp $ + * @author M. Dahm + */ +// OPTIMIZE make unchecked, or get rid of it! +public final class TargetLostException extends Exception { + private InstructionHandle[] targets; + + TargetLostException(InstructionHandle[] t, String mesg) { + super(mesg); + targets = t; + } + + /** + * @return list of instructions still being targeted. + */ + public InstructionHandle[] getTargets() { return targets; } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/Type.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/Type.java index 0529774ac..877aa6e0f 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/Type.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/Type.java @@ -1,396 +1,396 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.ArrayList; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.ClassFormatException; -import org.aspectj.apache.bcel.classfile.Utility; - - -/** - * Abstract super class for all possible java types, namely basic types - * such as int, object types like String and array types, e.g. int[] - * - * @version $Id: Type.java,v 1.7.4.2 2008/04/25 17:55:34 aclement Exp $ - * @author M. Dahm - * - * modified: - * AndyClement 2-mar-05: Removed unnecessary static and optimized - */ -public abstract class Type implements java.io.Serializable { - protected byte type; - protected String signature; // signature for the type - - /* Predefined constants */ - public static final BasicType VOID = new BasicType(Constants.T_VOID); - public static final BasicType BOOLEAN = new BasicType(Constants.T_BOOLEAN); - public static final BasicType INT = new BasicType(Constants.T_INT); - public static final BasicType SHORT = new BasicType(Constants.T_SHORT); - public static final BasicType BYTE = new BasicType(Constants.T_BYTE); - public static final BasicType LONG = new BasicType(Constants.T_LONG); - public static final BasicType DOUBLE = new BasicType(Constants.T_DOUBLE); - public static final BasicType FLOAT = new BasicType(Constants.T_FLOAT); - public static final BasicType CHAR = new BasicType(Constants.T_CHAR); - public static final ObjectType OBJECT = new ObjectType("java.lang.Object"); - public static final ObjectType STRING = new ObjectType("java.lang.String"); - public static final ObjectType STRINGBUFFER = new ObjectType("java.lang.StringBuffer"); - public static final ObjectType THROWABLE = new ObjectType("java.lang.Throwable"); - public static final Type[] NO_ARGS = new Type[0]; - public static final ReferenceType NULL = new ReferenceType(){}; - public static final Type UNKNOWN = new Type(Constants.T_UNKNOWN,""){}; - - protected Type(byte t, String s) { - type = t; - signature = s; - } - - /** - * @return signature for given type. - */ - public String getSignature() { return signature; } - - /** - * @return type as defined in Constants - */ - public byte getType() { return type; } - - /** - * @return stack size of this type (2 for long and double, 0 for void, 1 otherwise) - */ - public int getSize() { - switch(type) { - case Constants.T_DOUBLE: case Constants.T_LONG: - return 2; - case Constants.T_VOID: - return 0; - default: - return 1; - } - } - - /** - * @return Type string, e.g. 'int[]' - */ - public String toString() { - return ((this.equals(Type.NULL) || (type >= Constants.T_UNKNOWN)))? signature : - Utility.signatureToString(signature, false); - } - - /** - * Convert type to Java method signature, e.g. int[] f(java.lang.String x) - * becomes (Ljava/lang/String;)[I - * - * @param return_type what the method returns - * @param arg_types what are the argument types - * @return method signature for given type(s). - */ - public static String getMethodSignature(Type return_type, Type[] arg_types) { - StringBuffer buf = new StringBuffer("("); - int length = (arg_types == null)? 0 : arg_types.length; - - for(int i=0; i < length; i++) - buf.append(arg_types[i].getSignature()); - buf.append(')'); - buf.append(return_type.getSignature()); - - return buf.toString(); - } - - public static final Type getType(String signature) { - TypeHolder th = getTypeInternal(signature); - return th.getType(); - } - - /** - * Convert signature to a Type object. - * @param signature signature string such as Ljava/lang/String; - * @return type object - */ - public static final TypeHolder getTypeInternal(String signature) throws StringIndexOutOfBoundsException { - byte type = Utility.typeOfSignature(signature); - - if (type <= Constants.T_VOID) { - return new TypeHolder(BasicType.getType(type),1); - } else if (type == Constants.T_ARRAY) { - int dim=0; - do { dim++; } while(signature.charAt(dim) == '['); - // Recurse, but just once, if the signature is ok - TypeHolder th = getTypeInternal(signature.substring(dim)); - return new TypeHolder(new ArrayType(th.getType(), dim),dim+th.getConsumed()); - } else { // type == T_REFERENCE - // Format is 'Lblahblah;' - int index = signature.indexOf(';'); // Look for closing ';' - if (index < 0) throw new ClassFormatException("Invalid signature: " + signature); - - // generics awareness - int nextAngly = signature.indexOf('<'); - String typeString = null; - if (nextAngly==-1 || nextAngly>index) { - typeString = signature.substring(1,index).replace('/','.'); - } else { - boolean endOfSigReached = false; - int posn = nextAngly; - int genericDepth=0; - while (!endOfSigReached) { - switch (signature.charAt(posn++)) { - case '<': genericDepth++;break; - case '>': genericDepth--;break; - case ';': if (genericDepth==0) endOfSigReached=true;break; - default: - } - } - index=posn-1; - typeString = signature.substring(1,nextAngly).replace('/','.'); - } - // ObjectType doesn't currently store parameterized info - return new TypeHolder(new ObjectType(typeString),index+1); - } - } - - /** - * Convert return value of a method (signature) to a Type object. - * - * @param signature signature string such as (Ljava/lang/String;)V - * @return return type - */ - public static Type getReturnType(String signature) { - try { - // Read return type after `)' - int index = signature.lastIndexOf(')') + 1; - return getType(signature.substring(index)); - } catch(StringIndexOutOfBoundsException e) { // Should never occur - throw new ClassFormatException("Invalid method signature: " + signature); - } - } - - /** - * Convert arguments of a method (signature) to an array of Type objects. - * @param signature signature string such as (Ljava/lang/String;)V - * @return array of argument types - */ - public static Type[] getArgumentTypes(String signature) { - ArrayList vec = new ArrayList(); - int index; - Type[] types; - - try { // Read all declarations between for `(' and `)' - if (signature.charAt(0) != '(') - throw new ClassFormatException("Invalid method signature: " + signature); - - index = 1; // current string position - - while(signature.charAt(index) != ')') { - TypeHolder th = getTypeInternal(signature.substring(index)); - vec.add(th.getType()); - index += th.getConsumed(); // update position - } - } catch(StringIndexOutOfBoundsException e) { // Should never occur - throw new ClassFormatException("Invalid method signature: " + signature); - } - - types = new Type[vec.size()]; - vec.toArray(types); - return types; - } - - /** - * Work out the type of each argument in the signature and return the cumulative sizes of - * all the types (size means number of stack slots it consumes, eg double=2, int=1). - * Unlike the call above, this does minimal unpacking - */ - public static int getArgumentSizes(String signature) { - int size = 0; - if (signature.charAt(0) != '(') - throw new ClassFormatException("Invalid method signature: " + signature); - - int index = 1; // current string position - try { - while (signature.charAt(index) != ')') { - byte type = Utility.typeOfSignature(signature.charAt(index)); - if (type<=Constants.T_VOID) { - size+=BasicType.getType(type).getSize(); - index++; - } else if (type==Constants.T_ARRAY) { - int dim=0; - do { dim++; } while(signature.charAt(dim+index) == '['); - TypeHolder th = getTypeInternal(signature.substring(dim+index)); - size+=1; - index+=dim+th.getConsumed(); - } else { // type == T_REFERENCE - // Format is 'Lblahblah;' - int index2 = signature.indexOf(';',index); // Look for closing ';' - - // generics awareness - int nextAngly = signature.indexOf('<',index); - if (nextAngly==-1 || nextAngly>index2) { - } else { - boolean endOfSigReached = false; - int posn = nextAngly; - int genericDepth=0; - while (!endOfSigReached) { - switch (signature.charAt(posn++)) { - case '<': genericDepth++;break; - case '>': genericDepth--;break; - case ';': if (genericDepth==0) endOfSigReached=true;break; - default: - } - } - index2=posn-1; - } - size++; - index=index2+1; - } - } - } catch(StringIndexOutOfBoundsException e) { // Should never occur - throw new ClassFormatException("Invalid method signature: " + signature); - } - return size; - } - - /** - * Return the size of the type expressed in the signature. The signature should contain only one type. - */ - public static int getTypeSize(String signature) { - byte type = Utility.typeOfSignature(signature.charAt(0)); - if (type<=Constants.T_VOID) { - return BasicType.getType(type).getSize(); - } else if (type==Constants.T_ARRAY) { - return 1; - } else { // type == T_REFERENCE - return 1; - } - } - - /** Convert runtime java.lang.Class to BCEL Type object. - * @param cl Java class - * @return corresponding Type object - */ - public static Type getType(java.lang.Class cl) { - if(cl == null) { - throw new IllegalArgumentException("Class must not be null"); - } - - /* That's an amazingly easy case, because getName() returns - * the signature. That's what we would have liked anyway. - */ - if(cl.isArray()) { - return getType(cl.getName()); - } else if(cl.isPrimitive()) { - if(cl == Integer.TYPE) { - return INT; - } else if(cl == Void.TYPE) { - return VOID; - } else if(cl == Double.TYPE) { - return DOUBLE; - } else if(cl == Float.TYPE) { - return FLOAT; - } else if(cl == Boolean.TYPE) { - return BOOLEAN; - } else if(cl == Byte.TYPE) { - return BYTE; - } else if(cl == Short.TYPE) { - return SHORT; - } else if(cl == Byte.TYPE) { - return BYTE; - } else if(cl == Long.TYPE) { - return LONG; - } else if(cl == Character.TYPE) { - return CHAR; - } else { - throw new IllegalStateException("Ooops, what primitive type is " + cl); - } - } else { // "Real" class - return new ObjectType(cl.getName()); - } - } - - public static String getSignature(java.lang.reflect.Method meth) { - StringBuffer sb = new StringBuffer("("); - Class[] params = meth.getParameterTypes(); // avoid clone - - for(int j = 0; j < params.length; j++) { - sb.append(getType(params[j]).getSignature()); - } - - sb.append(")"); - sb.append(getType(meth.getReturnType()).getSignature()); - return sb.toString(); - } - - public static String getSignature(java.lang.reflect.Constructor cons) { - StringBuffer sb = new StringBuffer("("); - Class[] params = cons.getParameterTypes(); // avoid clone - - for(int j = 0; j < params.length; j++) { - sb.append(getType(params[j]).getSignature()); - } - - sb.append(")V"); - return sb.toString(); - } - - public static class TypeHolder { - private Type t; - private int consumed; - - public Type getType() {return t;} - public int getConsumed() { return consumed;} - - public TypeHolder(Type t,int i) { this.t=t;this.consumed = i;} - } - -} +package org.aspectj.apache.bcel.generic; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.util.ArrayList; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.ClassFormatException; +import org.aspectj.apache.bcel.classfile.Utility; + + +/** + * Abstract super class for all possible java types, namely basic types + * such as int, object types like String and array types, e.g. int[] + * + * @version $Id: Type.java,v 1.7.4.3 2008/05/08 19:26:44 aclement Exp $ + * @author M. Dahm + * + * modified: + * AndyClement 2-mar-05: Removed unnecessary static and optimized + */ +public abstract class Type implements java.io.Serializable { + protected byte type; + protected String signature; // signature for the type + + /* Predefined constants */ + public static final BasicType VOID = new BasicType(Constants.T_VOID); + public static final BasicType BOOLEAN = new BasicType(Constants.T_BOOLEAN); + public static final BasicType INT = new BasicType(Constants.T_INT); + public static final BasicType SHORT = new BasicType(Constants.T_SHORT); + public static final BasicType BYTE = new BasicType(Constants.T_BYTE); + public static final BasicType LONG = new BasicType(Constants.T_LONG); + public static final BasicType DOUBLE = new BasicType(Constants.T_DOUBLE); + public static final BasicType FLOAT = new BasicType(Constants.T_FLOAT); + public static final BasicType CHAR = new BasicType(Constants.T_CHAR); + public static final ObjectType OBJECT = new ObjectType("java.lang.Object"); + public static final ObjectType STRING = new ObjectType("java.lang.String"); + public static final ObjectType STRINGBUFFER = new ObjectType("java.lang.StringBuffer"); + public static final ObjectType THROWABLE = new ObjectType("java.lang.Throwable"); + public static final Type[] NO_ARGS = new Type[0]; + public static final ReferenceType NULL = new ReferenceType(){}; + public static final Type UNKNOWN = new Type(Constants.T_UNKNOWN,""){}; + + protected Type(byte t, String s) { + type = t; + signature = s; + } + + /** + * @return signature for given type. + */ + public String getSignature() { return signature; } + + /** + * @return type as defined in Constants + */ + public byte getType() { return type; } + + /** + * @return stack size of this type (2 for long and double, 0 for void, 1 otherwise) + */ + public int getSize() { + switch(type) { + case Constants.T_DOUBLE: case Constants.T_LONG: + return 2; + case Constants.T_VOID: + return 0; + default: + return 1; + } + } + + /** + * @return Type string, e.g. 'int[]' + */ + public String toString() { + return ((this.equals(Type.NULL) || (type >= Constants.T_UNKNOWN)))? signature : + Utility.signatureToString(signature, false); + } + + /** + * Convert type to Java method signature, e.g. int[] f(java.lang.String x) + * becomes (Ljava/lang/String;)[I + * + * @param return_type what the method returns + * @param arg_types what are the argument types + * @return method signature for given type(s). + */ + public static String getMethodSignature(Type return_type, Type[] arg_types) { + StringBuffer buf = new StringBuffer("("); + int length = (arg_types == null)? 0 : arg_types.length; + for(int i=0; i < length; i++) { + buf.append(arg_types[i].getSignature()); + } + buf.append(')'); + buf.append(return_type.getSignature()); + return buf.toString(); + } + + public static final Type getType(String signature) { + TypeHolder th = getTypeInternal(signature); + return th.getType(); + } + + /** + * Convert signature to a Type object. + * @param signature signature string such as Ljava/lang/String; + * @return type object + */ + public static final TypeHolder getTypeInternal(String signature) throws StringIndexOutOfBoundsException { + byte type = Utility.typeOfSignature(signature); + + if (type <= Constants.T_VOID) { + return new TypeHolder(BasicType.getType(type),1); + } else if (type == Constants.T_ARRAY) { + int dim=0; + do { dim++; } while(signature.charAt(dim) == '['); + // Recurse, but just once, if the signature is ok + TypeHolder th = getTypeInternal(signature.substring(dim)); + return new TypeHolder(new ArrayType(th.getType(), dim),dim+th.getConsumed()); + } else { // type == T_REFERENCE + // Format is 'Lblahblah;' + int index = signature.indexOf(';'); // Look for closing ';' + if (index < 0) throw new ClassFormatException("Invalid signature: " + signature); + + // generics awareness + int nextAngly = signature.indexOf('<'); + String typeString = null; + if (nextAngly==-1 || nextAngly>index) { + typeString = signature.substring(1,index).replace('/','.'); + } else { + boolean endOfSigReached = false; + int posn = nextAngly; + int genericDepth=0; + while (!endOfSigReached) { + switch (signature.charAt(posn++)) { + case '<': genericDepth++;break; + case '>': genericDepth--;break; + case ';': if (genericDepth==0) endOfSigReached=true;break; + default: + } + } + index=posn-1; + typeString = signature.substring(1,nextAngly).replace('/','.'); + } + // ObjectType doesn't currently store parameterized info + return new TypeHolder(new ObjectType(typeString),index+1); + } + } + + /** + * Convert return value of a method (signature) to a Type object. + * + * @param signature signature string such as (Ljava/lang/String;)V + * @return return type + */ + public static Type getReturnType(String signature) { + try { + // Read return type after `)' + int index = signature.lastIndexOf(')') + 1; + return getType(signature.substring(index)); + } catch(StringIndexOutOfBoundsException e) { // Should never occur + throw new ClassFormatException("Invalid method signature: " + signature); + } + } + + /** + * Convert arguments of a method (signature) to an array of Type objects. + * @param signature signature string such as (Ljava/lang/String;)V + * @return array of argument types + */ + // OPTIMIZE crap impl + public static Type[] getArgumentTypes(String signature) { + ArrayList vec = new ArrayList(); + int index; + Type[] types; + + try { // Read all declarations between for `(' and `)' + if (signature.charAt(0) != '(') + throw new ClassFormatException("Invalid method signature: " + signature); + + index = 1; // current string position + + while(signature.charAt(index) != ')') { + TypeHolder th = getTypeInternal(signature.substring(index)); + vec.add(th.getType()); + index += th.getConsumed(); // update position + } + } catch(StringIndexOutOfBoundsException e) { // Should never occur + throw new ClassFormatException("Invalid method signature: " + signature); + } + + types = new Type[vec.size()]; + vec.toArray(types); + return types; + } + + /** + * Work out the type of each argument in the signature and return the cumulative sizes of + * all the types (size means number of stack slots it consumes, eg double=2, int=1). + * Unlike the call above, this does minimal unpacking + */ + public static int getArgumentSizes(String signature) { + int size = 0; + if (signature.charAt(0) != '(') + throw new ClassFormatException("Invalid method signature: " + signature); + + int index = 1; // current string position + try { + while (signature.charAt(index) != ')') { + byte type = Utility.typeOfSignature(signature.charAt(index)); + if (type<=Constants.T_VOID) { + size+=BasicType.getType(type).getSize(); + index++; + } else if (type==Constants.T_ARRAY) { + int dim=0; + do { dim++; } while(signature.charAt(dim+index) == '['); + TypeHolder th = getTypeInternal(signature.substring(dim+index)); + size+=1; + index+=dim+th.getConsumed(); + } else { // type == T_REFERENCE + // Format is 'Lblahblah;' + int index2 = signature.indexOf(';',index); // Look for closing ';' + + // generics awareness + int nextAngly = signature.indexOf('<',index); + if (nextAngly==-1 || nextAngly>index2) { + } else { + boolean endOfSigReached = false; + int posn = nextAngly; + int genericDepth=0; + while (!endOfSigReached) { + switch (signature.charAt(posn++)) { + case '<': genericDepth++;break; + case '>': genericDepth--;break; + case ';': if (genericDepth==0) endOfSigReached=true;break; + default: + } + } + index2=posn-1; + } + size++; + index=index2+1; + } + } + } catch(StringIndexOutOfBoundsException e) { // Should never occur + throw new ClassFormatException("Invalid method signature: " + signature); + } + return size; + } + + /** + * Return the size of the type expressed in the signature. The signature should contain only one type. + */ + public static int getTypeSize(String signature) { + byte type = Utility.typeOfSignature(signature.charAt(0)); + if (type<=Constants.T_VOID) { + return BasicType.getType(type).getSize(); + } else if (type==Constants.T_ARRAY) { + return 1; + } else { // type == T_REFERENCE + return 1; + } + } + + /** Convert runtime java.lang.Class to BCEL Type object. + * @param cl Java class + * @return corresponding Type object + */ + public static Type getType(java.lang.Class cl) { + if(cl == null) { + throw new IllegalArgumentException("Class must not be null"); + } + + /* That's an amazingly easy case, because getName() returns + * the signature. That's what we would have liked anyway. + */ + if(cl.isArray()) { + return getType(cl.getName()); + } else if(cl.isPrimitive()) { + if(cl == Integer.TYPE) { + return INT; + } else if(cl == Void.TYPE) { + return VOID; + } else if(cl == Double.TYPE) { + return DOUBLE; + } else if(cl == Float.TYPE) { + return FLOAT; + } else if(cl == Boolean.TYPE) { + return BOOLEAN; + } else if(cl == Byte.TYPE) { + return BYTE; + } else if(cl == Short.TYPE) { + return SHORT; + } else if(cl == Byte.TYPE) { + return BYTE; + } else if(cl == Long.TYPE) { + return LONG; + } else if(cl == Character.TYPE) { + return CHAR; + } else { + throw new IllegalStateException("Ooops, what primitive type is " + cl); + } + } else { // "Real" class + return new ObjectType(cl.getName()); + } + } + + public static String getSignature(java.lang.reflect.Method meth) { + StringBuffer sb = new StringBuffer("("); + Class[] params = meth.getParameterTypes(); // avoid clone + + for(int j = 0; j < params.length; j++) { + sb.append(getType(params[j]).getSignature()); + } + + sb.append(")"); + sb.append(getType(meth.getReturnType()).getSignature()); + return sb.toString(); + } + + public static String getSignature(java.lang.reflect.Constructor cons) { + StringBuffer sb = new StringBuffer("("); + Class[] params = cons.getParameterTypes(); // avoid clone + + for(int j = 0; j < params.length; j++) { + sb.append(getType(params[j]).getSignature()); + } + + sb.append(")V"); + return sb.toString(); + } + + public static class TypeHolder { + private Type t; + private int consumed; + + public Type getType() {return t;} + public int getConsumed() { return consumed;} + + public TypeHolder(Type t,int i) { this.t=t;this.consumed = i;} + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/TypedInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/TypedInstruction.java deleted file mode 100644 index 98a58719e..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/TypedInstruction.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Get the type associated with an instruction, int for ILOAD, or the type - * of the field of a PUTFIELD instruction, e.g.. - * - * @version $Id: TypedInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - */ -public interface TypedInstruction { - public Type getType(ConstantPoolGen cpg); -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/UnconditionalBranch.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/UnconditionalBranch.java deleted file mode 100644 index 36257b260..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/UnconditionalBranch.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denotes an instruction to perform an unconditional branch, i.e., GOTO, JSR. - * - * @version $Id: UnconditionalBranch.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - - * @see GOTO - * @see JSR - */ -public interface UnconditionalBranch {} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/VariableLengthInstruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/VariableLengthInstruction.java deleted file mode 100644 index 462a3f1d3..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/VariableLengthInstruction.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.aspectj.apache.bcel.generic; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Denotes an instruction to be a variable length instruction, such as - * GOTO, JSR, LOOKUPSWITCH and TABLESWITCH. - * - * @version $Id: VariableLengthInstruction.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - - * @see GOTO - * @see JSR - * @see LOOKUPSWITCH - * @see TABLESWITCH - */ -public interface VariableLengthInstruction {} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/AnnotationElementValueGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/AnnotationElementValueGen.java deleted file mode 100644 index 0ee425de9..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/AnnotationElementValueGen.java +++ /dev/null @@ -1,63 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement - initial implementation {date} - * ******************************************************************/ - -package org.aspectj.apache.bcel.generic.annotation; - -import java.io.DataOutputStream; -import java.io.IOException; - -import org.aspectj.apache.bcel.classfile.annotation.AnnotationElementValue; -import org.aspectj.apache.bcel.classfile.annotation.ElementValue; -import org.aspectj.apache.bcel.generic.ConstantPoolGen; - - -public class AnnotationElementValueGen extends ElementValueGen { - - // For annotation element values, this is the annotation - private AnnotationGen a; - - public AnnotationElementValueGen(AnnotationGen a,ConstantPoolGen cpool) { - super(ANNOTATION,cpool); - this.a = a; - } - - public AnnotationElementValueGen(int type, AnnotationGen annotation, ConstantPoolGen cpool) { - super(type,cpool); - if (type != ANNOTATION) - throw new RuntimeException("Only element values of type annotation can be built with this ctor"); - this.a = annotation; - } - - public AnnotationElementValueGen(AnnotationElementValue value, ConstantPoolGen cpool,boolean copyPoolEntries) { - super(ANNOTATION,cpool); - a = new AnnotationGen(value.getAnnotation(),cpool,copyPoolEntries); - } - - public void dump(DataOutputStream dos) throws IOException { - dos.writeByte(type); // u1 type of value (ANNOTATION == '@') - a.dump(dos); - } - - public String stringifyValue() { - throw new RuntimeException("Not implemented yet"); - } - - /** - * Return immutable variant of this AnnotationElementValueGen - */ - public ElementValue getElementValue() { - return new AnnotationElementValue(this.type,a.getAnnotation(),cpGen.getConstantPool()); - } - - public AnnotationGen getAnnotation() { return a;} - -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/AnnotationGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/AnnotationGen.java deleted file mode 100644 index 7b758c17e..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/annotation/AnnotationGen.java +++ /dev/null @@ -1,166 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * ******************************************************************/ -package org.aspectj.apache.bcel.generic.annotation; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.aspectj.apache.bcel.classfile.ConstantUtf8; -import org.aspectj.apache.bcel.classfile.annotation.Annotation; -import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair; -import org.aspectj.apache.bcel.generic.ConstantPoolGen; -import org.aspectj.apache.bcel.generic.ObjectType; - -public class AnnotationGen { - private int typeIndex; - private List /* ElementNameValuePairGen */ evs; - private ConstantPoolGen cpool; - private boolean isRuntimeVisible = false; - - /** - * Here we are taking a fixed annotation of type Annotation and building a - * modifiable AnnotationGen object. If the pool passed in is for a different - * class file, then copyPoolEntries should have been passed as true as that - * will force us to do a deep copy of the annotation and move the cpool entries - * across. - * We need to copy the type and the element name value pairs and the visibility. - */ - public AnnotationGen(Annotation a,ConstantPoolGen cpool,boolean copyPoolEntries) { - this.cpool = cpool; - - if (copyPoolEntries) { - typeIndex = cpool.addUtf8(a.getTypeSignature()); - } else { - typeIndex = a.getTypeIndex(); - } - - isRuntimeVisible = a.isRuntimeVisible(); - - evs = copyValues(a.getValues(),cpool,copyPoolEntries); - } - - private List copyValues(List in,ConstantPoolGen cpool,boolean copyPoolEntries) { - List out = new ArrayList(); - for (Iterator iter = in.iterator(); iter.hasNext();) { - ElementNameValuePair nvp = (ElementNameValuePair) iter.next(); - out.add(new ElementNameValuePairGen(nvp,cpool,copyPoolEntries)); - } - return out; - } - - private AnnotationGen(ConstantPoolGen cpool) { - this.cpool = cpool; - } - - /** - * Retrieve an immutable version of this AnnotationGen - */ - public Annotation getAnnotation() { - Annotation a = new Annotation(typeIndex,cpool.getConstantPool(),isRuntimeVisible); - for (Iterator iter = evs.iterator(); iter.hasNext();) { - ElementNameValuePairGen element = (ElementNameValuePairGen) iter.next(); - a.addElementNameValuePair(element.getElementNameValuePair()); - } - return a; - } - - public AnnotationGen(ObjectType type,List /*ElementNameValuePairGen*/ elements,boolean vis,ConstantPoolGen cpool) { - this.cpool = cpool; - this.typeIndex = cpool.addUtf8(type.getSignature()); - evs = elements; - isRuntimeVisible = vis; - } - - public static AnnotationGen read(DataInputStream dis,ConstantPoolGen cpool,boolean b) throws IOException { - AnnotationGen a = new AnnotationGen(cpool); - a.typeIndex = dis.readUnsignedShort(); - int elemValuePairCount = dis.readUnsignedShort(); - for (int i=0;i - - - - - -

          -This package contains the "generic" part of the -Byte Code Engineering -Library, i.e., classes to dynamically modify class objects and -byte code instructions. -

          - - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/package.html b/bcel-builder/src/org/aspectj/apache/bcel/package.html deleted file mode 100644 index 9d71a08ee..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/package.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - -

          -This package contains basic classes for the -Byte Code Engineering Library - and constants defined by the - - JVM specification. -

          - - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/AttributeHTML.java b/bcel-builder/src/org/aspectj/apache/bcel/util/AttributeHTML.java deleted file mode 100644 index 6ff7dc6ae..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/AttributeHTML.java +++ /dev/null @@ -1,272 +0,0 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; - -import org.aspectj.apache.bcel.classfile.Attribute; -import org.aspectj.apache.bcel.classfile.Code; -import org.aspectj.apache.bcel.classfile.CodeException; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.ConstantUtf8; -import org.aspectj.apache.bcel.classfile.ConstantValue; -import org.aspectj.apache.bcel.classfile.ExceptionTable; -import org.aspectj.apache.bcel.classfile.InnerClass; -import org.aspectj.apache.bcel.classfile.InnerClasses; -import org.aspectj.apache.bcel.classfile.LineNumber; -import org.aspectj.apache.bcel.classfile.LineNumberTable; -import org.aspectj.apache.bcel.classfile.LocalVariable; -import org.aspectj.apache.bcel.classfile.LocalVariableTable; -import org.aspectj.apache.bcel.classfile.SourceFile; -import org.aspectj.apache.bcel.classfile.Utility; - -/** - * Convert found attributes into HTML file. - * - * @version $Id: AttributeHTML.java,v 1.3 2004/11/22 08:31:27 aclement Exp $ - * @author M. Dahm - * - */ -final class AttributeHTML implements org.aspectj.apache.bcel.Constants { - private String class_name; // name of current class - private PrintWriter file; // file to write to - private int attr_count = 0; - private ConstantHTML constant_html; - private ConstantPool constant_pool; - - AttributeHTML(String dir, String class_name, ConstantPool constant_pool, - ConstantHTML constant_html) throws IOException - { - this.class_name = class_name; - this.constant_pool = constant_pool; - this.constant_html = constant_html; - - file = new PrintWriter(new FileOutputStream(dir + class_name + "_attributes.html")); - file.println(""); - } - - private final String codeLink(int link, int method_number) { - return "" + - link + ""; - } - - final void close() { - file.println("
          "); - file.close(); - } - - final void writeAttribute(Attribute attribute, String anchor) throws IOException { - writeAttribute(attribute, anchor, 0); - } - - final void writeAttribute(Attribute attribute, String anchor, int method_number) throws IOException { - byte tag = attribute.getTag(); - int index; - - if(tag == ATTR_UNKNOWN) // Don't know what to do about this one - return; - - attr_count++; // Increment number of attributes found so far - - if(attr_count % 2 == 0) - file.print(""); - else - file.print(""); - - file.println("

          " + attr_count + " " + ATTRIBUTE_NAMES[tag] + "

          "); - - /* Handle different attributes - */ - switch(tag) { - case ATTR_CODE: - Code c = (Code)attribute; - - // Some directly printable values - file.print("
          • Maximum stack size = " + c.getMaxStack() + - "
          • \n
          • Number of local variables = " + - c.getMaxLocals() + "
          • \n
          • Byte code
          \n"); - - // Get handled exceptions and list them - CodeException[] ce = c.getExceptionTable(); - int len = ce.length; - - if(len > 0) { - file.print("

          Exceptions handled

            "); - - for(int i=0; i < len; i++) { - int catch_type = ce[i].getCatchType(); // Index in constant pool - - file.print("
          • "); - - if(catch_type != 0) - file.print(constant_html.referenceConstant(catch_type)); // Create Link to _cp.html - else - file.print("Any Exception"); - - file.print("
            (Ranging from lines " + codeLink(ce[i].getStartPC(), method_number) + - " to " + codeLink(ce[i].getEndPC(), method_number) + ", handled at line " + - codeLink(ce[i].getHandlerPC(), method_number) + ")
          • "); - } - file.print("
          "); - } - break; - - case ATTR_CONSTANT_VALUE: - index = ((ConstantValue)attribute).getConstantValueIndex(); - - // Reference _cp.html - file.print("\n"); - break; - - case ATTR_SOURCE_FILE: - index = ((SourceFile)attribute).getSourceFileIndex(); - - // Reference _cp.html - file.print("\n"); - break; - - case ATTR_EXCEPTIONS: - // List thrown exceptions - int[] indices = ((ExceptionTable)attribute).getExceptionIndexTable(); - - file.print("\n"); - break; - - case ATTR_LINE_NUMBER_TABLE: - LineNumber[] line_numbers =((LineNumberTable)attribute).getLineNumberTable(); - - // List line number pairs - file.print("

          "); - - for(int i=0; i < line_numbers.length; i++) { - file.print("(" + line_numbers[i].getStartPC() + ", " + line_numbers[i].getLineNumber() + ")"); - - if(i < line_numbers.length - 1) - file.print(", "); // breakable - } - break; - - case ATTR_LOCAL_VARIABLE_TABLE: - LocalVariable[] vars = ((LocalVariableTable)attribute).getLocalVariableTable(); - - // List name, range and type - file.print("

            "); - - for(int i=0; i < vars.length; i++) { - index = vars[i].getSignatureIndex(); - String signature = ((ConstantUtf8)constant_pool.getConstant(index, CONSTANT_Utf8)).getBytes(); - signature = Utility.signatureToString(signature, false); - int start = vars[i].getStartPC(); - int end = (start + vars[i].getLength()); - - file.println("
          • " + Class2HTML.referenceType(signature) + - " " + vars[i].getName() + " in slot %" + vars[i].getIndex() + - "
            Valid from lines " + - "" + - start + " to " + - "" + - end + "
          • "); - } - file.print("
          \n"); - - break; - - case ATTR_INNER_CLASSES: - InnerClass[] classes = ((InnerClasses)attribute).getInnerClasses(); - - // List inner classes - file.print("
            "); - - for(int i=0; i < classes.length; i++) { - String name, access; - - index = classes[i].getInnerNameIndex(); - if(index > 0) - name =((ConstantUtf8)constant_pool.getConstant(index, CONSTANT_Utf8)).getBytes(); - else - name = "<anonymous>"; - - access = Utility.accessToString(classes[i].getInnerAccessFlags()); - - file.print("
          • " + access + " "+ - constant_html.referenceConstant(classes[i].getInnerClassIndex()) + - " in class " + - constant_html.referenceConstant(classes[i].getOuterClassIndex()) + - " named " + name + "
          • \n"); - } - - file.print("
          \n"); - break; - - default: // Such as Unknown attribute or Deprecated - file.print("

          " + attribute.toString()); - } - - file.println(""); - file.flush(); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/ByteSequence.java b/bcel-builder/src/org/aspectj/apache/bcel/util/ByteSequence.java index 8487fa8cb..314755fdd 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/ByteSequence.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/util/ByteSequence.java @@ -1,82 +1,82 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.*; - -/** - * Utility class that implements a sequence of bytes which can be read - * via the `readByte()' method. This is used to implement a wrapper for the - * Java byte code stream to gain some more readability. - * - * @version $Id: ByteSequence.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - */ -public final class ByteSequence extends DataInputStream { - private ByteArrayStream byte_stream; - - public ByteSequence(byte[] bytes) { - super(new ByteArrayStream(bytes)); - byte_stream = (ByteArrayStream)in; - } - - public final int getIndex() { return byte_stream.getPosition(); } - final void unreadByte() { byte_stream.unreadByte(); } - - private static final class ByteArrayStream extends ByteArrayInputStream { - ByteArrayStream(byte[] bytes) { super(bytes); } - final int getPosition() { return pos; } // is protected in ByteArrayInputStream - final void unreadByte() { if(pos > 0) pos--; } - } -} +package org.aspectj.apache.bcel.util; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.io.*; + +/** + * Utility class that implements a sequence of bytes which can be read + * via the `readByte()' method. This is used to implement a wrapper for the + * Java byte code stream to gain some more readability. + * + * @version $Id: ByteSequence.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + */ +public final class ByteSequence extends DataInputStream { + private ByteArrayStream byte_stream; + + public ByteSequence(byte[] bytes) { + super(new ByteArrayStream(bytes)); + byte_stream = (ByteArrayStream)in; + } + + public final int getIndex() { return byte_stream.getPosition(); } + final void unreadByte() { byte_stream.unreadByte(); } + + private static final class ByteArrayStream extends ByteArrayInputStream { + ByteArrayStream(byte[] bytes) { super(bytes); } + final int getPosition() { return pos; } // is protected in ByteArrayInputStream + final void unreadByte() { if(pos > 0) pos--; } + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/Class2HTML.java b/bcel-builder/src/org/aspectj/apache/bcel/util/Class2HTML.java deleted file mode 100644 index 79e0135ef..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/Class2HTML.java +++ /dev/null @@ -1,270 +0,0 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.Attribute; -import org.aspectj.apache.bcel.classfile.ClassParser; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.classfile.Utility; - -/** - * Read class file(s) and convert them into HTML files. - * - * Given a JavaClass object "class" that is in package "package" five files - * will be created in the specified directory. - * - *

            - *
          1. "package"."class".html as the main file which defines the frames for - * the following subfiles. - *
          2. "package"."class"_attributes.html contains all (known) attributes found in the file - *
          3. "package"."class"_cp.html contains the constant pool - *
          4. "package"."class"_code.html contains the byte code - *
          5. "package"."class"_methods.html contains references to all methods and fields of the class - *
          - * - * All subfiles reference each other appropiately, e.g. clicking on a - * method in the Method's frame will jump to the appropiate method in - * the Code frame. - * - * @version $Id: Class2HTML.java,v 1.4 2004/11/22 08:31:27 aclement Exp $ - * @author M. Dahm -*/ -public class Class2HTML implements Constants -{ - private JavaClass java_class; // current class object - private String dir; - - private static String class_package; // name of package, unclean to make it static, but ... - private static String class_name; // name of current class, dito - private static ConstantPool constant_pool; - - /** - * Write contents of the given JavaClass into HTML files. - * - * @param java_class The class to write - * @param dir The directory to put the files in - */ - public Class2HTML(JavaClass java_class, String dir) throws IOException { - Method[] methods = java_class.getMethods(); - - this.java_class = java_class; - this.dir = dir; - class_name = java_class.getClassName(); // Remember full name - constant_pool = java_class.getConstantPool(); - - // Get package name by tacking off everything after the last `.' - int index = class_name.lastIndexOf('.'); - if(index > -1) - class_package = class_name.substring(0, index); - else - class_package = ""; // default package - - ConstantHTML constant_html = new ConstantHTML(dir, class_name, class_package, methods, - constant_pool); - - /* Attributes can't be written in one step, so we just open a file - * which will be written consequently. - */ - AttributeHTML attribute_html = new AttributeHTML(dir, class_name, constant_pool, constant_html); - - MethodHTML method_html = new MethodHTML(dir, class_name, methods, java_class.getFields(), - constant_html, attribute_html); - // Write main file (with frames, yuk) - writeMainHTML(attribute_html); - new CodeHTML(dir, class_name, methods, constant_pool, constant_html); - attribute_html.close(); - } - - public static void main(String argv[]) - { - String[] file_name = new String[argv.length]; - int files=0; - ClassParser parser=null; - JavaClass java_class=null; - String zip_file = null; - char sep = System.getProperty("file.separator").toCharArray()[0]; - String dir = "." + sep; // Where to store HTML files - - try { - /* Parse command line arguments. - */ - for(int i=0; i < argv.length; i++) { - if(argv[i].charAt(0) == '-') { // command line switch - if(argv[i].equals("-d")) { // Specify target directory, default `.´ - dir = argv[++i]; - - if(!dir.endsWith("" + sep)) - dir = dir + sep; - - new File(dir).mkdirs(); // Create target directory if necessary - } - else if(argv[i].equals("-zip")) - zip_file = argv[++i]; - else - System.out.println("Unknown option " + argv[i]); - } - else // add file name to list */ - file_name[files++] = argv[i]; - } - - if(files == 0) - System.err.println("Class2HTML: No input files specified."); - else { // Loop through files ... - for(int i=0; i < files; i++) { - System.out.print("Processing " + file_name[i] + "..."); - if(zip_file == null) - parser = new ClassParser(file_name[i]); // Create parser object from file - else - parser = new ClassParser(zip_file, file_name[i]); // Create parser object from zip file - - java_class = parser.parse(); - new Class2HTML(java_class, dir); - System.out.println("Done."); - } - } - } catch(Exception e) { - System.out.println(e); - e.printStackTrace(System.out); - } - } - - /** - * Utility method that converts a class reference in the constant pool, - * i.e., an index to a string. - */ - static String referenceClass(int index) { - String str = constant_pool.getConstantString(index, CONSTANT_Class); - str = Utility.compactClassName(str); - str = Utility.compactClassName(str, class_package + ".", true); - - return "" + str + ""; - } - - static final String referenceType(String type) { - String short_type = Utility.compactClassName(type); - short_type = Utility.compactClassName(short_type, class_package + ".", true); - - int index = type.indexOf('['); // Type is an array? - if(index > -1) - type = type.substring(0, index); // Tack of the `[' - - // test for basic type - if(type.equals("int") || type.equals("short") || type.equals("boolean") || type.equals("void") || - type.equals("char") || type.equals("byte") || type.equals("long") || type.equals("double") || - type.equals("float")) - return "" + type + ""; - else - return "" + short_type + ""; - } - - static String toHTML(String str) { - StringBuffer buf = new StringBuffer(); - - try { // Filter any characters HTML doesn't like such as < and > in particular - for(int i=0; i < str.length(); i++) { - char ch; - - switch(ch=str.charAt(i)) { - case '<': buf.append("<"); break; - case '>': buf.append(">"); break; - case '\n': buf.append("\\n"); break; - case '\r': buf.append("\\r"); break; - default: buf.append(ch); - } - } - } catch(StringIndexOutOfBoundsException e) {} // Never occurs - - return buf.toString(); - } - - private void writeMainHTML(AttributeHTML attribute_html) throws IOException { - PrintWriter file = new PrintWriter(new FileOutputStream(dir + class_name + ".html")); - Attribute[] attributes = java_class.getAttributes(); - - file.println("\n" + "Documentation for " + class_name + "" + - "\n" + - "\n" + - "\n" + - - "\n" + - "\n" + - "\n" + - - "\n" + - "\n" + - "\n" + - "" - ); - - file.close(); - - for(int i=0; i < attributes.length; i++) - attribute_html.writeAttribute(attributes[i], "class" + i); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassLoader.java b/bcel-builder/src/org/aspectj/apache/bcel/util/ClassLoader.java deleted file mode 100644 index 52012f9ea..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassLoader.java +++ /dev/null @@ -1,227 +0,0 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.ByteArrayInputStream; -import java.util.Hashtable; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.ClassParser; -import org.aspectj.apache.bcel.classfile.ConstantClass; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.ConstantUtf8; -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.classfile.Utility; - -/** - *

          Drop in replacement for the standard class loader of the JVM. You can use it - * in conjunction with the JavaWrapper to dynamically modify/create classes - * as they're requested.

          - * - *

          This class loader recognizes special requests in a distinct - * format, i.e., when the name of the requested class contains with - * "$$BCEL$$" it calls the createClass() method with that name - * (everything bevor the $$BCEL$$ is considered to be the package - * name. You can subclass the class loader and override that - * method. "Normal" classes class can be modified by overriding the - * modifyClass() method which is called just before defineClass().

          - * - *

          There may be a number of packages where you have to use the default - * class loader (which may also be faster). You can define the set of packages - * where to use the system class loader in the constructor. The default value contains - * "java.", "sun.", "javax."

          - * - * @version $Id: ClassLoader.java,v 1.3 2004/11/22 08:31:27 aclement Exp $ - * @author M. Dahm - * @see JavaWrapper - * @see ClassPath - */ -public class ClassLoader extends java.lang.ClassLoader { - private Hashtable classes = new Hashtable(); // Hashtable is synchronized thus thread-safe - private String[] ignored_packages = { - "java.", "javax.", "sun." - }; - private Repository repository = SyntheticRepository.getInstance(); - private java.lang.ClassLoader deferTo = ClassLoader.getSystemClassLoader(); - - public ClassLoader() { - } - - public ClassLoader(java.lang.ClassLoader deferTo) { - this.deferTo = deferTo; - this.repository = new ClassLoaderRepository(deferTo); - } - - /** @param ignored_packages classes contained in these packages will be loaded - * with the system class loader - */ - public ClassLoader(String[] ignored_packages) { - addIgnoredPkgs(ignored_packages); - } - - public ClassLoader(java.lang.ClassLoader deferTo, String [] ignored_packages) { - this.deferTo = deferTo; - this.repository = new ClassLoaderRepository(deferTo); - - addIgnoredPkgs(ignored_packages); - } - - private void addIgnoredPkgs(String[] ignored_packages) { - String[] new_p = new String[ignored_packages.length + this.ignored_packages.length]; - - System.arraycopy(this.ignored_packages, 0, new_p, 0, this.ignored_packages.length); - System.arraycopy(ignored_packages, 0, new_p, this.ignored_packages.length, - ignored_packages.length); - - this.ignored_packages = new_p; - } - - protected Class loadClass(String class_name, boolean resolve) - throws ClassNotFoundException - { - Class cl = null; - - /* First try: lookup hash table. - */ - if((cl=(Class)classes.get(class_name)) == null) { - /* Second try: Load system class using system class loader. You better - * don't mess around with them. - */ - for(int i=0; i < ignored_packages.length; i++) { - if(class_name.startsWith(ignored_packages[i])) { - cl = deferTo.loadClass(class_name); - break; - } - } - - if(cl == null) { - JavaClass clazz = null; - - /* Third try: Special request? - */ - if(class_name.indexOf("$$BCEL$$") >= 0) - clazz = createClass(class_name); - else { // Fourth try: Load classes via repository - if ((clazz = repository.loadClass(class_name)) != null) { - clazz = modifyClass(clazz); - } - else - throw new ClassNotFoundException(class_name); - } - - if(clazz != null) { - byte[] bytes = clazz.getBytes(); - cl = defineClass(class_name, bytes, 0, bytes.length); - } else // Fourth try: Use default class loader - cl = Class.forName(class_name); - } - - if(resolve) - resolveClass(cl); - } - - classes.put(class_name, cl); - - return cl; - } - - /** Override this method if you want to alter a class before it gets actually - * loaded. Does nothing by default. - */ - protected JavaClass modifyClass(JavaClass clazz) { - return clazz; - } - - /** - * Override this method to create you own classes on the fly. The - * name contains the special token $$BCEL$$. Everything before that - * token is consddered to be a package name. You can encode you own - * arguments into the subsequent string. You must regard however not - * to use any "illegal" characters, i.e., characters that may not - * appear in a Java class name too
          - * - * The default implementation interprets the string as a encoded compressed - * Java class, unpacks and decodes it with the Utility.decode() method, and - * parses the resulting byte array and returns the resulting JavaClass object. - * - * @param class_name compressed byte code with "$$BCEL$$" in it - */ - protected JavaClass createClass(String class_name) { - int index = class_name.indexOf("$$BCEL$$"); - String real_name = class_name.substring(index + 8); - - JavaClass clazz = null; - try { - byte[] bytes = Utility.decode(real_name, true); - ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes), "foo"); - - clazz = parser.parse(); - } catch(Throwable e) { - e.printStackTrace(); - return null; - } - - // Adapt the class name to the passed value - ConstantPool cp = clazz.getConstantPool(); - - ConstantClass cl = (ConstantClass)cp.getConstant(clazz.getClassNameIndex(), - Constants.CONSTANT_Class); - ConstantUtf8 name = (ConstantUtf8)cp.getConstant(cl.getNameIndex(), - Constants.CONSTANT_Utf8); - name.setBytes(class_name.replace('.', '/')); - - return clazz; - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassLoaderRepository.java b/bcel-builder/src/org/aspectj/apache/bcel/util/ClassLoaderRepository.java index e6620a611..5ba4757c0 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassLoaderRepository.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/util/ClassLoaderRepository.java @@ -1,368 +1,368 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.IOException; -import java.io.InputStream; -import java.lang.ref.Reference; -import java.lang.ref.ReferenceQueue; -import java.lang.ref.SoftReference; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.AbstractMap; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.WeakHashMap; - -import org.aspectj.apache.bcel.classfile.ClassParser; -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * The repository maintains information about which classes have - * been loaded. - * - * It loads its data from the ClassLoader implementation - * passed into its constructor. - * - * @see org.aspectj.apache.bcel.Repository - * - * @version $Id: ClassLoaderRepository.java,v 1.9.4.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @author David Dixon-Peugh - */ -public class ClassLoaderRepository implements Repository { - private static java.lang.ClassLoader bootClassLoader = null; - private java.lang.ClassLoader loader; - - // Choice of cache... - private WeakHashMap /**/localCache = new WeakHashMap(); - private static SoftHashMap /**/sharedCache = new SoftHashMap(Collections.synchronizedMap(new HashMap())); - - // For fast translation of the classname *intentionally not static* - private SoftHashMap /**/ nameMap = new SoftHashMap(new HashMap(), false); - - public static boolean useSharedCache = - System.getProperty("org.aspectj.apache.bcel.useSharedCache","true").equalsIgnoreCase("true"); - - private static int cacheHitsShared = 0; - private static int missSharedEvicted = 0; // Misses in shared cache access due to reference GC - private long timeManipulatingURLs = 0L; - private long timeSpentLoading = 0L; - private int classesLoadedCount = 0; - private int misses = 0; - private int cacheHitsLocal = 0; - private int missLocalEvicted = 0; // Misses in local cache access due to reference GC - - public ClassLoaderRepository( java.lang.ClassLoader loader ) { - this.loader = (loader != null) ? loader : getBootClassLoader(); - } - - private static synchronized java.lang.ClassLoader getBootClassLoader() { - if (bootClassLoader == null) { - bootClassLoader = new URLClassLoader(new URL[0]); - } - return bootClassLoader; - } - - // Can track back to its key - public static class SoftHashMap extends AbstractMap { - private Map map; - boolean recordMiss = true; // only interested in recording miss stats sometimes - private ReferenceQueue rq = new ReferenceQueue(); - - public SoftHashMap(Map map) { this.map = map; } - public SoftHashMap() { this(new HashMap()); } - public SoftHashMap(Map map, boolean b) { this(map); this.recordMiss=b;} - - class SpecialValue extends SoftReference { - private final Object key; - SpecialValue(Object k,Object v) { - super(v,rq); - this.key = k; - } - } - - private void processQueue() { - SpecialValue sv = null; - while ((sv = (SpecialValue)rq.poll())!=null) { - map.remove(sv.key); - } - } - - public Object get(Object key) { - SpecialValue value = (SpecialValue)map.get(key); - if (value==null) return null; - if (value.get()==null) { - // it got GC'd - map.remove(value.key); - if (recordMiss) missSharedEvicted++; - return null; - } else { - return value.get(); - } - } - - public Object put(Object k, Object v) { - processQueue(); - return map.put(k, new SpecialValue(k,v)); - } - - public Set entrySet() { - return map.entrySet(); - } - - public void clear() { - processQueue(); - map.clear(); - } - - public int size() { - processQueue(); - return map.size(); - } - - public Object remove(Object k) { - processQueue(); - SpecialValue value = (SpecialValue)map.remove(k); - if (value==null) return null; - if (value.get()!=null) { - return value.get(); - } - return null; - } - } - - /** - * Store a new JavaClass into this repository as a soft reference and return the reference - */ - private void storeClassAsReference(URL url, JavaClass clazz ) { - if (useSharedCache) { - clazz.setRepository(null); // can't risk setting repository, we'll get in a pickle! - sharedCache.put(url, clazz); - } else { - clazz.setRepository(this); - localCache.put(url, new SoftReference(clazz)); - } - } - - /** - * Store a new JavaClass into this Repository. - */ - public void storeClass( JavaClass clazz ) { - storeClassAsReference(toURL(clazz.getClassName()),clazz); - } - - /** - * Remove class from repository - */ - public void removeClass(JavaClass clazz) { - if (useSharedCache) sharedCache.remove(toURL(clazz.getClassName())); - else localCache.remove(toURL(clazz.getClassName())); - } - - /** - * Find an already defined JavaClass in the local cache. - */ - public JavaClass findClass( String className ) { - if (useSharedCache) return findClassShared(toURL(className)); - else return findClassLocal(toURL(className)); - } - - private JavaClass findClassLocal( URL url ) { - Object o = localCache.get(url); - if (o != null) { - o = ((Reference)o).get(); - if (o != null) { - return (JavaClass)o; - } else { - missLocalEvicted++; - } - } - return null; - } - - /** - * Find an already defined JavaClass in the shared cache. - */ - private JavaClass findClassShared(URL url) { - return (JavaClass)sharedCache.get(url); - } - - private URL toURL(String className) { - URL url = (URL)nameMap.get(className); - if (url==null) { - String classFile = className.replace('.', '/'); - url = loader.getResource( classFile + ".class" ); - nameMap.put(className, url); - } - return url; - } - - /** - * Lookup a JavaClass object from the Class Name provided. - */ - public JavaClass loadClass( String className ) throws ClassNotFoundException { - - // translate to a URL - long time = System.currentTimeMillis(); - java.net.URL url = toURL(className); - timeManipulatingURLs += (System.currentTimeMillis() - time); - if (url==null) throw new ClassNotFoundException(className + " not found - unable to determine URL"); - - JavaClass clazz = null; - - // Look in the appropriate cache - if (useSharedCache) { - clazz = findClassShared(url); - if (clazz != null) { cacheHitsShared++; return clazz; } - } else { - clazz = findClassLocal(url); - if (clazz != null) { cacheHitsLocal++; return clazz; } - } - - // Didn't find it in either cache - misses++; - - try { - // Load it - String classFile = className.replace('.', '/'); - InputStream is = (useSharedCache?url.openStream():loader.getResourceAsStream( classFile + ".class" )); - if (is == null) { - throw new ClassNotFoundException(className + " not found "+(url==null?"":"- using url "+url)); - } - ClassParser parser = new ClassParser( is, className ); - clazz = parser.parse(); - - // Cache it - storeClassAsReference(url, clazz ); - - timeSpentLoading += (System.currentTimeMillis() - time); - classesLoadedCount++; - return clazz; - } catch (IOException e) { - throw new ClassNotFoundException( e.toString() ); - } - } - - - /** - * Produce a report on cache usage. - */ - public String report() { - StringBuffer sb = new StringBuffer(); - sb.append("BCEL repository report."); - if (useSharedCache) sb.append(" (shared cache)"); - else sb.append(" (local cache)"); - sb.append(" Total time spent loading: "+timeSpentLoading+"ms."); - sb.append(" Time spent manipulating URLs: "+timeManipulatingURLs+"ms."); - sb.append(" Classes loaded: "+classesLoadedCount+"."); - if (useSharedCache) { - sb.append(" Shared cache size: "+sharedCache.size()); - sb.append(" Shared cache (hits/missDueToEviction): ("+cacheHitsShared+"/"+missSharedEvicted+")."); - } else { - sb.append(" Local cache size: "+localCache.size()); - sb.append(" Local cache (hits/missDueToEviction): ("+cacheHitsLocal+"/"+missLocalEvicted+")."); - } - return sb.toString(); - } - - /** - * Returns an array of the stats, for testing, the order is fixed: - * 0=time spent loading (static) - * 1=time spent manipulating URLs (static) - * 2=classes loaded (static) - * 3=cache hits shared (static) - * 4=misses in shared due to eviction (static) - * 5=cache hits local - * 6=misses in local due to eviction - * 7=shared cache size - */ - public long[] reportStats() { - return new long[]{timeSpentLoading,timeManipulatingURLs,classesLoadedCount, - cacheHitsShared,missSharedEvicted,cacheHitsLocal,missLocalEvicted, - sharedCache.size()}; - } - - /** - * Reset statistics and clear all caches - */ - public void reset() { - timeManipulatingURLs = 0L; - timeSpentLoading = 0L; - classesLoadedCount = 0; - cacheHitsLocal = 0; - cacheHitsShared = 0; - missSharedEvicted = 0; - missLocalEvicted = 0; - misses = 0; - clear(); - } - - - public JavaClass loadClass(Class clazz) throws ClassNotFoundException { - return loadClass(clazz.getName()); - } - - /** Clear all entries from the local cache */ - public void clear() { - if (useSharedCache) sharedCache.clear(); - else localCache.clear(); - } - -} - - +package org.aspectj.apache.bcel.util; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.IOException; +import java.io.InputStream; +import java.lang.ref.Reference; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.SoftReference; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.AbstractMap; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.WeakHashMap; + +import org.aspectj.apache.bcel.classfile.ClassParser; +import org.aspectj.apache.bcel.classfile.JavaClass; + +/** + * The repository maintains information about which classes have + * been loaded. + * + * It loads its data from the ClassLoader implementation + * passed into its constructor. + * + * @see org.aspectj.apache.bcel.Repository + * + * @version $Id: ClassLoaderRepository.java,v 1.9.4.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @author David Dixon-Peugh + */ +public class ClassLoaderRepository implements Repository { + private static java.lang.ClassLoader bootClassLoader = null; + private java.lang.ClassLoader loader; + + // Choice of cache... + private WeakHashMap /**/localCache = new WeakHashMap(); + private static SoftHashMap /**/sharedCache = new SoftHashMap(Collections.synchronizedMap(new HashMap())); + + // For fast translation of the classname *intentionally not static* + private SoftHashMap /**/ nameMap = new SoftHashMap(new HashMap(), false); + + public static boolean useSharedCache = + System.getProperty("org.aspectj.apache.bcel.useSharedCache","true").equalsIgnoreCase("true"); + + private static int cacheHitsShared = 0; + private static int missSharedEvicted = 0; // Misses in shared cache access due to reference GC + private long timeManipulatingURLs = 0L; + private long timeSpentLoading = 0L; + private int classesLoadedCount = 0; + private int misses = 0; + private int cacheHitsLocal = 0; + private int missLocalEvicted = 0; // Misses in local cache access due to reference GC + + public ClassLoaderRepository( java.lang.ClassLoader loader ) { + this.loader = (loader != null) ? loader : getBootClassLoader(); + } + + private static synchronized java.lang.ClassLoader getBootClassLoader() { + if (bootClassLoader == null) { + bootClassLoader = new URLClassLoader(new URL[0]); + } + return bootClassLoader; + } + + // Can track back to its key + public static class SoftHashMap extends AbstractMap { + private Map map; + boolean recordMiss = true; // only interested in recording miss stats sometimes + private ReferenceQueue rq = new ReferenceQueue(); + + public SoftHashMap(Map map) { this.map = map; } + public SoftHashMap() { this(new HashMap()); } + public SoftHashMap(Map map, boolean b) { this(map); this.recordMiss=b;} + + class SpecialValue extends SoftReference { + private final Object key; + SpecialValue(Object k,Object v) { + super(v,rq); + this.key = k; + } + } + + private void processQueue() { + SpecialValue sv = null; + while ((sv = (SpecialValue)rq.poll())!=null) { + map.remove(sv.key); + } + } + + public Object get(Object key) { + SpecialValue value = (SpecialValue)map.get(key); + if (value==null) return null; + if (value.get()==null) { + // it got GC'd + map.remove(value.key); + if (recordMiss) missSharedEvicted++; + return null; + } else { + return value.get(); + } + } + + public Object put(Object k, Object v) { + processQueue(); + return map.put(k, new SpecialValue(k,v)); + } + + public Set entrySet() { + return map.entrySet(); + } + + public void clear() { + processQueue(); + map.clear(); + } + + public int size() { + processQueue(); + return map.size(); + } + + public Object remove(Object k) { + processQueue(); + SpecialValue value = (SpecialValue)map.remove(k); + if (value==null) return null; + if (value.get()!=null) { + return value.get(); + } + return null; + } + } + + /** + * Store a new JavaClass into this repository as a soft reference and return the reference + */ + private void storeClassAsReference(URL url, JavaClass clazz ) { + if (useSharedCache) { + clazz.setRepository(null); // can't risk setting repository, we'll get in a pickle! + sharedCache.put(url, clazz); + } else { + clazz.setRepository(this); + localCache.put(url, new SoftReference(clazz)); + } + } + + /** + * Store a new JavaClass into this Repository. + */ + public void storeClass( JavaClass clazz ) { + storeClassAsReference(toURL(clazz.getClassName()),clazz); + } + + /** + * Remove class from repository + */ + public void removeClass(JavaClass clazz) { + if (useSharedCache) sharedCache.remove(toURL(clazz.getClassName())); + else localCache.remove(toURL(clazz.getClassName())); + } + + /** + * Find an already defined JavaClass in the local cache. + */ + public JavaClass findClass( String className ) { + if (useSharedCache) return findClassShared(toURL(className)); + else return findClassLocal(toURL(className)); + } + + private JavaClass findClassLocal( URL url ) { + Object o = localCache.get(url); + if (o != null) { + o = ((Reference)o).get(); + if (o != null) { + return (JavaClass)o; + } else { + missLocalEvicted++; + } + } + return null; + } + + /** + * Find an already defined JavaClass in the shared cache. + */ + private JavaClass findClassShared(URL url) { + return (JavaClass)sharedCache.get(url); + } + + private URL toURL(String className) { + URL url = (URL)nameMap.get(className); + if (url==null) { + String classFile = className.replace('.', '/'); + url = loader.getResource( classFile + ".class" ); + nameMap.put(className, url); + } + return url; + } + + /** + * Lookup a JavaClass object from the Class Name provided. + */ + public JavaClass loadClass( String className ) throws ClassNotFoundException { + + // translate to a URL + long time = System.currentTimeMillis(); + java.net.URL url = toURL(className); + timeManipulatingURLs += (System.currentTimeMillis() - time); + if (url==null) throw new ClassNotFoundException(className + " not found - unable to determine URL"); + + JavaClass clazz = null; + + // Look in the appropriate cache + if (useSharedCache) { + clazz = findClassShared(url); + if (clazz != null) { cacheHitsShared++; return clazz; } + } else { + clazz = findClassLocal(url); + if (clazz != null) { cacheHitsLocal++; return clazz; } + } + + // Didn't find it in either cache + misses++; + + try { + // Load it + String classFile = className.replace('.', '/'); + InputStream is = (useSharedCache?url.openStream():loader.getResourceAsStream( classFile + ".class" )); + if (is == null) { + throw new ClassNotFoundException(className + " not found "+(url==null?"":"- using url "+url)); + } + ClassParser parser = new ClassParser( is, className ); + clazz = parser.parse(); + + // Cache it + storeClassAsReference(url, clazz ); + + timeSpentLoading += (System.currentTimeMillis() - time); + classesLoadedCount++; + return clazz; + } catch (IOException e) { + throw new ClassNotFoundException( e.toString() ); + } + } + + + /** + * Produce a report on cache usage. + */ + public String report() { + StringBuffer sb = new StringBuffer(); + sb.append("BCEL repository report."); + if (useSharedCache) sb.append(" (shared cache)"); + else sb.append(" (local cache)"); + sb.append(" Total time spent loading: "+timeSpentLoading+"ms."); + sb.append(" Time spent manipulating URLs: "+timeManipulatingURLs+"ms."); + sb.append(" Classes loaded: "+classesLoadedCount+"."); + if (useSharedCache) { + sb.append(" Shared cache size: "+sharedCache.size()); + sb.append(" Shared cache (hits/missDueToEviction): ("+cacheHitsShared+"/"+missSharedEvicted+")."); + } else { + sb.append(" Local cache size: "+localCache.size()); + sb.append(" Local cache (hits/missDueToEviction): ("+cacheHitsLocal+"/"+missLocalEvicted+")."); + } + return sb.toString(); + } + + /** + * Returns an array of the stats, for testing, the order is fixed: + * 0=time spent loading (static) + * 1=time spent manipulating URLs (static) + * 2=classes loaded (static) + * 3=cache hits shared (static) + * 4=misses in shared due to eviction (static) + * 5=cache hits local + * 6=misses in local due to eviction + * 7=shared cache size + */ + public long[] reportStats() { + return new long[]{timeSpentLoading,timeManipulatingURLs,classesLoadedCount, + cacheHitsShared,missSharedEvicted,cacheHitsLocal,missLocalEvicted, + sharedCache.size()}; + } + + /** + * Reset statistics and clear all caches + */ + public void reset() { + timeManipulatingURLs = 0L; + timeSpentLoading = 0L; + classesLoadedCount = 0; + cacheHitsLocal = 0; + cacheHitsShared = 0; + missSharedEvicted = 0; + missLocalEvicted = 0; + misses = 0; + clear(); + } + + + public JavaClass loadClass(Class clazz) throws ClassNotFoundException { + return loadClass(clazz.getName()); + } + + /** Clear all entries from the local cache */ + public void clear() { + if (useSharedCache) sharedCache.clear(); + else localCache.clear(); + } + +} + + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassPath.java b/bcel-builder/src/org/aspectj/apache/bcel/util/ClassPath.java index bfb48b01d..9326f8be6 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassPath.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/util/ClassPath.java @@ -1,378 +1,378 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.*; -import java.util.zip.*; -import java.io.*; - -/** - * Responsible for loading (class) files from the CLASSPATH. Inspired by - * sun.tools.ClassPath. - * - * @version $Id: ClassPath.java,v 1.3.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - */ -public class ClassPath implements Serializable { - private static ClassPath SYSTEM_CLASS_PATH = null; - - private PathEntry[] paths; - private String class_path; - - public static ClassPath getSystemClassPath() { - if (SYSTEM_CLASS_PATH == null) { - SYSTEM_CLASS_PATH = new ClassPath(); - } - return SYSTEM_CLASS_PATH; - } - /** - * Search for classes in given path. - */ - public ClassPath(String class_path) { - this.class_path = class_path; - - ArrayList vec = new ArrayList(); - - for(StringTokenizer tok=new StringTokenizer(class_path, - System.getProperty("path.separator")); - tok.hasMoreTokens();) - { - String path = tok.nextToken(); - - if(!path.equals("")) { - File file = new File(path); - - try { - if(file.exists()) { - if(file.isDirectory()) - vec.add(new Dir(path)); - else - vec.add(new Zip(new ZipFile(file))); - } - } catch(IOException e) { - System.err.println("CLASSPATH component " + file + ": " + e); - } - } - } - - paths = new PathEntry[vec.size()]; - vec.toArray(paths); - } - - /** - * Search for classes in CLASSPATH. - * @deprecated Use SYSTEM_CLASS_PATH constant - */ - public ClassPath() { - this(getClassPath()); - } - - /** @return used class path string - */ - public String toString() { - return class_path; - } - - public int hashCode() { - return class_path.hashCode(); - } - - public boolean equals(Object o) { - if(o instanceof ClassPath) { - return class_path.equals(((ClassPath)o).class_path); - } - - return false; - } - - private static final void getPathComponents(String path, ArrayList list) { - if(path != null) { - StringTokenizer tok = new StringTokenizer(path, File.pathSeparator); - - while(tok.hasMoreTokens()) { - String name = tok.nextToken(); - File file = new File(name); - - if(file.exists()) - list.add(name); - } - } - } - - /** Checks for class path components in the following properties: - * "java.class.path", "sun.boot.class.path", "java.ext.dirs" - * - * @return class path as used by default by BCEL - */ - public static final String getClassPath() { - String class_path = System.getProperty("java.class.path"); - String boot_path = System.getProperty("sun.boot.class.path"); - String ext_path = System.getProperty("java.ext.dirs"); - - ArrayList list = new ArrayList(); - - getPathComponents(class_path, list); - getPathComponents(boot_path, list); - - ArrayList dirs = new ArrayList(); - getPathComponents(ext_path, dirs); - - for(Iterator e = dirs.iterator(); e.hasNext(); ) { - File ext_dir = new File((String)e.next()); - String[] extensions = ext_dir.list(new FilenameFilter() { - public boolean accept(File dir, String name) { - name = name.toLowerCase(); - return name.endsWith(".zip") || name.endsWith(".jar"); - } - }); - - if(extensions != null) - for(int i=0; i < extensions.length; i++) - list.add(ext_path + File.separatorChar + extensions[i]); - } - - StringBuffer buf = new StringBuffer(); - - for(Iterator e = list.iterator(); e.hasNext(); ) { - buf.append((String)e.next()); - - if(e.hasNext()) - buf.append(File.pathSeparatorChar); - } - - return buf.toString().intern(); - } - - /** - * @param name fully qualified class name, e.g. java.lang.String - * @return input stream for class - */ - public InputStream getInputStream(String name) throws IOException { - return getInputStream(name, ".class"); - } - - /** - * Return stream for class or resource on CLASSPATH. - * - * @param name fully qualified file name, e.g. java/lang/String - * @param suffix file name ends with suff, e.g. .java - * @return input stream for file on class path - */ - public InputStream getInputStream(String name, String suffix) throws IOException { - InputStream is = null; - - try { - is = getClass().getClassLoader().getResourceAsStream(name + suffix); - } catch(Exception e) { } - - if(is != null) - return is; - - return getClassFile(name, suffix).getInputStream(); - } - - /** - * @param name fully qualified file name, e.g. java/lang/String - * @param suffix file name ends with suff, e.g. .java - * @return class file for the java class - */ - public ClassFile getClassFile(String name, String suffix) throws IOException { - for(int i=0; i < paths.length; i++) { - ClassFile cf; - - if((cf = paths[i].getClassFile(name, suffix)) != null) - return cf; - } - - throw new IOException("Couldn't find: " + name + suffix); - } - - /** - * @param name fully qualified class name, e.g. java.lang.String - * @return input stream for class - */ - public ClassFile getClassFile(String name) throws IOException { - return getClassFile(name, ".class"); - } - - /** - * @param name fully qualified file name, e.g. java/lang/String - * @param suffix file name ends with suffix, e.g. .java - * @return byte array for file on class path - */ - public byte[] getBytes(String name, String suffix) throws IOException { - InputStream is = getInputStream(name, suffix); - - if(is == null) - throw new IOException("Couldn't find: " + name + suffix); - - DataInputStream dis = new DataInputStream(is); - byte[] bytes = new byte[is.available()]; - dis.readFully(bytes); - dis.close(); is.close(); - - return bytes; - } - - /** - * @return byte array for class - */ - public byte[] getBytes(String name) throws IOException { - return getBytes(name, ".class"); - } - - /** - * @param name name of file to search for, e.g. java/lang/String.java - * @return full (canonical) path for file - */ - public String getPath(String name) throws IOException { - int index = name.lastIndexOf('.'); - String suffix = ""; - - if(index > 0) { - suffix = name.substring(index); - name = name.substring(0, index); - } - - return getPath(name, suffix); - } - - /** - * @param name name of file to search for, e.g. java/lang/String - * @param suffix file name suffix, e.g. .java - * @return full (canonical) path for file, if it exists - */ - public String getPath(String name, String suffix) throws IOException { - return getClassFile(name, suffix).getPath(); - } - - private static abstract class PathEntry implements Serializable { - abstract ClassFile getClassFile(String name, String suffix) throws IOException; - } - - /** Contains information about file/ZIP entry of the Java class. - */ - public interface ClassFile { - /** @return input stream for class file. - */ - public abstract InputStream getInputStream() throws IOException; - - /** @return canonical path to class file. - */ - public abstract String getPath(); - - /** @return base path of found class, i.e. class is contained relative - * to that path, which may either denote a directory, or zip file - */ - public abstract String getBase(); - - /** @return modification time of class file. - */ - public abstract long getTime(); - - /** @return size of class file. - */ - public abstract long getSize(); - } - - private static class Dir extends PathEntry { - private String dir; - - Dir(String d) { dir = d; } - - ClassFile getClassFile(String name, String suffix) throws IOException { - final File file = new File(dir + File.separatorChar + - name.replace('.', File.separatorChar) + suffix); - - return file.exists()? new ClassFile() { - public InputStream getInputStream() throws IOException { return new FileInputStream(file); } - - public String getPath() { try { - return file.getCanonicalPath(); - } catch(IOException e) { return null; } - - } - public long getTime() { return file.lastModified(); } - public long getSize() { return file.length(); } - public String getBase() { return dir; } - - } : null; - } - - public String toString() { return dir; } - } - - private static class Zip extends PathEntry { - private ZipFile zip; - - Zip(ZipFile z) { zip = z; } - - ClassFile getClassFile(String name, String suffix) throws IOException { - final ZipEntry entry = zip.getEntry(name.replace('.', '/') + suffix); - - return (entry != null)? new ClassFile() { - public InputStream getInputStream() throws IOException { return zip.getInputStream(entry); } - public String getPath() { return entry.toString(); } - public long getTime() { return entry.getTime(); } - public long getSize() { return entry.getSize(); } - public String getBase() { - return zip.getName(); - } - } : null; - } - } -} - - +package org.aspectj.apache.bcel.util; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.util.*; +import java.util.zip.*; +import java.io.*; + +/** + * Responsible for loading (class) files from the CLASSPATH. Inspired by + * sun.tools.ClassPath. + * + * @version $Id: ClassPath.java,v 1.3.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + */ +public class ClassPath implements Serializable { + private static ClassPath SYSTEM_CLASS_PATH = null; + + private PathEntry[] paths; + private String class_path; + + public static ClassPath getSystemClassPath() { + if (SYSTEM_CLASS_PATH == null) { + SYSTEM_CLASS_PATH = new ClassPath(); + } + return SYSTEM_CLASS_PATH; + } + /** + * Search for classes in given path. + */ + public ClassPath(String class_path) { + this.class_path = class_path; + + ArrayList vec = new ArrayList(); + + for(StringTokenizer tok=new StringTokenizer(class_path, + System.getProperty("path.separator")); + tok.hasMoreTokens();) + { + String path = tok.nextToken(); + + if(!path.equals("")) { + File file = new File(path); + + try { + if(file.exists()) { + if(file.isDirectory()) + vec.add(new Dir(path)); + else + vec.add(new Zip(new ZipFile(file))); + } + } catch(IOException e) { + System.err.println("CLASSPATH component " + file + ": " + e); + } + } + } + + paths = new PathEntry[vec.size()]; + vec.toArray(paths); + } + + /** + * Search for classes in CLASSPATH. + * @deprecated Use SYSTEM_CLASS_PATH constant + */ + public ClassPath() { + this(getClassPath()); + } + + /** @return used class path string + */ + public String toString() { + return class_path; + } + + public int hashCode() { + return class_path.hashCode(); + } + + public boolean equals(Object o) { + if(o instanceof ClassPath) { + return class_path.equals(((ClassPath)o).class_path); + } + + return false; + } + + private static final void getPathComponents(String path, ArrayList list) { + if(path != null) { + StringTokenizer tok = new StringTokenizer(path, File.pathSeparator); + + while(tok.hasMoreTokens()) { + String name = tok.nextToken(); + File file = new File(name); + + if(file.exists()) + list.add(name); + } + } + } + + /** Checks for class path components in the following properties: + * "java.class.path", "sun.boot.class.path", "java.ext.dirs" + * + * @return class path as used by default by BCEL + */ + public static final String getClassPath() { + String class_path = System.getProperty("java.class.path"); + String boot_path = System.getProperty("sun.boot.class.path"); + String ext_path = System.getProperty("java.ext.dirs"); + + ArrayList list = new ArrayList(); + + getPathComponents(class_path, list); + getPathComponents(boot_path, list); + + ArrayList dirs = new ArrayList(); + getPathComponents(ext_path, dirs); + + for(Iterator e = dirs.iterator(); e.hasNext(); ) { + File ext_dir = new File((String)e.next()); + String[] extensions = ext_dir.list(new FilenameFilter() { + public boolean accept(File dir, String name) { + name = name.toLowerCase(); + return name.endsWith(".zip") || name.endsWith(".jar"); + } + }); + + if(extensions != null) + for(int i=0; i < extensions.length; i++) + list.add(ext_path + File.separatorChar + extensions[i]); + } + + StringBuffer buf = new StringBuffer(); + + for(Iterator e = list.iterator(); e.hasNext(); ) { + buf.append((String)e.next()); + + if(e.hasNext()) + buf.append(File.pathSeparatorChar); + } + + return buf.toString().intern(); + } + + /** + * @param name fully qualified class name, e.g. java.lang.String + * @return input stream for class + */ + public InputStream getInputStream(String name) throws IOException { + return getInputStream(name, ".class"); + } + + /** + * Return stream for class or resource on CLASSPATH. + * + * @param name fully qualified file name, e.g. java/lang/String + * @param suffix file name ends with suff, e.g. .java + * @return input stream for file on class path + */ + public InputStream getInputStream(String name, String suffix) throws IOException { + InputStream is = null; + + try { + is = getClass().getClassLoader().getResourceAsStream(name + suffix); + } catch(Exception e) { } + + if(is != null) + return is; + + return getClassFile(name, suffix).getInputStream(); + } + + /** + * @param name fully qualified file name, e.g. java/lang/String + * @param suffix file name ends with suff, e.g. .java + * @return class file for the java class + */ + public ClassFile getClassFile(String name, String suffix) throws IOException { + for(int i=0; i < paths.length; i++) { + ClassFile cf; + + if((cf = paths[i].getClassFile(name, suffix)) != null) + return cf; + } + + throw new IOException("Couldn't find: " + name + suffix); + } + + /** + * @param name fully qualified class name, e.g. java.lang.String + * @return input stream for class + */ + public ClassFile getClassFile(String name) throws IOException { + return getClassFile(name, ".class"); + } + + /** + * @param name fully qualified file name, e.g. java/lang/String + * @param suffix file name ends with suffix, e.g. .java + * @return byte array for file on class path + */ + public byte[] getBytes(String name, String suffix) throws IOException { + InputStream is = getInputStream(name, suffix); + + if(is == null) + throw new IOException("Couldn't find: " + name + suffix); + + DataInputStream dis = new DataInputStream(is); + byte[] bytes = new byte[is.available()]; + dis.readFully(bytes); + dis.close(); is.close(); + + return bytes; + } + + /** + * @return byte array for class + */ + public byte[] getBytes(String name) throws IOException { + return getBytes(name, ".class"); + } + + /** + * @param name name of file to search for, e.g. java/lang/String.java + * @return full (canonical) path for file + */ + public String getPath(String name) throws IOException { + int index = name.lastIndexOf('.'); + String suffix = ""; + + if(index > 0) { + suffix = name.substring(index); + name = name.substring(0, index); + } + + return getPath(name, suffix); + } + + /** + * @param name name of file to search for, e.g. java/lang/String + * @param suffix file name suffix, e.g. .java + * @return full (canonical) path for file, if it exists + */ + public String getPath(String name, String suffix) throws IOException { + return getClassFile(name, suffix).getPath(); + } + + private static abstract class PathEntry implements Serializable { + abstract ClassFile getClassFile(String name, String suffix) throws IOException; + } + + /** Contains information about file/ZIP entry of the Java class. + */ + public interface ClassFile { + /** @return input stream for class file. + */ + public abstract InputStream getInputStream() throws IOException; + + /** @return canonical path to class file. + */ + public abstract String getPath(); + + /** @return base path of found class, i.e. class is contained relative + * to that path, which may either denote a directory, or zip file + */ + public abstract String getBase(); + + /** @return modification time of class file. + */ + public abstract long getTime(); + + /** @return size of class file. + */ + public abstract long getSize(); + } + + private static class Dir extends PathEntry { + private String dir; + + Dir(String d) { dir = d; } + + ClassFile getClassFile(String name, String suffix) throws IOException { + final File file = new File(dir + File.separatorChar + + name.replace('.', File.separatorChar) + suffix); + + return file.exists()? new ClassFile() { + public InputStream getInputStream() throws IOException { return new FileInputStream(file); } + + public String getPath() { try { + return file.getCanonicalPath(); + } catch(IOException e) { return null; } + + } + public long getTime() { return file.lastModified(); } + public long getSize() { return file.length(); } + public String getBase() { return dir; } + + } : null; + } + + public String toString() { return dir; } + } + + private static class Zip extends PathEntry { + private ZipFile zip; + + Zip(ZipFile z) { zip = z; } + + ClassFile getClassFile(String name, String suffix) throws IOException { + final ZipEntry entry = zip.getEntry(name.replace('.', '/') + suffix); + + return (entry != null)? new ClassFile() { + public InputStream getInputStream() throws IOException { return zip.getInputStream(entry); } + public String getPath() { return entry.toString(); } + public long getTime() { return entry.getTime(); } + public long getSize() { return entry.getSize(); } + public String getBase() { + return zip.getName(); + } + } : null; + } + } +} + + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassQueue.java b/bcel-builder/src/org/aspectj/apache/bcel/util/ClassQueue.java index e7992a32a..af2e8677e 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassQueue.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/util/ClassQueue.java @@ -1,81 +1,81 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.util.LinkedList; -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * Utility class implementing a (typesafe) queue of JavaClass - * objects. - * - * @version $Id: ClassQueue.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see ClassVector -*/ -public class ClassQueue implements java.io.Serializable { - protected LinkedList vec = new LinkedList(); - - public void enqueue(JavaClass clazz) { vec.addLast(clazz); } - - public JavaClass dequeue() { - return (JavaClass)vec.removeFirst(); - } - - public boolean empty() { return vec.isEmpty(); } - - public String toString() { - return vec.toString(); - } -} +package org.aspectj.apache.bcel.util; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.util.LinkedList; +import org.aspectj.apache.bcel.classfile.JavaClass; + +/** + * Utility class implementing a (typesafe) queue of JavaClass + * objects. + * + * @version $Id: ClassQueue.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see ClassVector +*/ +public class ClassQueue implements java.io.Serializable { + protected LinkedList vec = new LinkedList(); + + public void enqueue(JavaClass clazz) { vec.addLast(clazz); } + + public JavaClass dequeue() { + return (JavaClass)vec.removeFirst(); + } + + public boolean empty() { return vec.isEmpty(); } + + public String toString() { + return vec.toString(); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassSet.java b/bcel-builder/src/org/aspectj/apache/bcel/util/ClassSet.java deleted file mode 100644 index a647da32c..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassSet.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.util.HashMap; -import java.util.Collection; -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * Utility class implementing a (typesafe) set of JavaClass objects. - * Since JavaClass has no equals() method, the name of the class is - * used for comparison. - * - * @version $Id: ClassSet.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - * @see ClassStack -*/ -public class ClassSet implements java.io.Serializable { - private HashMap _map = new HashMap(); - - public boolean add(JavaClass clazz) { - boolean result = false; - - if(!_map.containsKey(clazz.getClassName())) { - result = true; - _map.put(clazz.getClassName(), clazz); - } - - return result; - } - - public void remove(JavaClass clazz) { _map.remove(clazz.getClassName()); } - public boolean empty() { return _map.isEmpty(); } - - public JavaClass[] toArray() { - Collection values = _map.values(); - JavaClass[] classes = new JavaClass[values.size()]; - values.toArray(classes); - return classes; - } - - public String[] getClassNames() { - return (String[])_map.keySet().toArray(new String[_map.keySet().size()]); - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassStack.java b/bcel-builder/src/org/aspectj/apache/bcel/util/ClassStack.java deleted file mode 100644 index effd38b44..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassStack.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.util.Stack; -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * Utility class implementing a (typesafe) stack of JavaClass objects. - * - * @version $Id: ClassStack.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - * @see Stack -*/ -public class ClassStack implements java.io.Serializable { - private Stack stack = new Stack(); - - public void push(JavaClass clazz) { stack.push(clazz); } - public JavaClass pop() { return (JavaClass)stack.pop(); } - public JavaClass top() { return (JavaClass)stack.peek(); } - public boolean empty() { return stack.empty(); } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassVector.java b/bcel-builder/src/org/aspectj/apache/bcel/util/ClassVector.java index b4b55621d..a06250d9d 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/ClassVector.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/util/ClassVector.java @@ -1,79 +1,79 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.util.ArrayList; -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * Utility class implementing a (typesafe) collection of JavaClass - * objects. Contains the most important methods of a Vector. - * - * @version $Id: ClassVector.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see ClassQueue -*/ -public class ClassVector implements java.io.Serializable { - protected ArrayList vec = new ArrayList(); - - public void addElement(JavaClass clazz) { vec.add(clazz); } - public JavaClass elementAt(int index) { return (JavaClass)vec.get(index); } - public void removeElementAt(int index) { vec.remove(index); } - - public JavaClass[] toArray() { - JavaClass[] classes = new JavaClass[vec.size()]; - vec.toArray(classes); - return classes; - } -} +package org.aspectj.apache.bcel.util; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.util.ArrayList; +import org.aspectj.apache.bcel.classfile.JavaClass; + +/** + * Utility class implementing a (typesafe) collection of JavaClass + * objects. Contains the most important methods of a Vector. + * + * @version $Id: ClassVector.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @see ClassQueue +*/ +public class ClassVector implements java.io.Serializable { + protected ArrayList vec = new ArrayList(); + + public void addElement(JavaClass clazz) { vec.add(clazz); } + public JavaClass elementAt(int index) { return (JavaClass)vec.get(index); } + public void removeElementAt(int index) { vec.remove(index); } + + public JavaClass[] toArray() { + JavaClass[] classes = new JavaClass[vec.size()]; + vec.toArray(classes); + return classes; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/CodeHTML.java b/bcel-builder/src/org/aspectj/apache/bcel/util/CodeHTML.java deleted file mode 100644 index 90662218d..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/CodeHTML.java +++ /dev/null @@ -1,632 +0,0 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.BitSet; - -import org.aspectj.apache.bcel.classfile.Attribute; -import org.aspectj.apache.bcel.classfile.Code; -import org.aspectj.apache.bcel.classfile.CodeException; -import org.aspectj.apache.bcel.classfile.ConstantFieldref; -import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref; -import org.aspectj.apache.bcel.classfile.ConstantMethodref; -import org.aspectj.apache.bcel.classfile.ConstantNameAndType; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.LocalVariable; -import org.aspectj.apache.bcel.classfile.LocalVariableTable; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.classfile.Utility; - -/** - * Convert code into HTML file. - * - * @version $Id: CodeHTML.java,v 1.3 2004/11/22 08:31:27 aclement Exp $ - * @author M. Dahm - * - */ -final class CodeHTML implements org.aspectj.apache.bcel.Constants { - private String class_name; // name of current class - private Method[] methods; // Methods to print - private PrintWriter file; // file to write to - private BitSet goto_set; - private ConstantPool constant_pool; - private ConstantHTML constant_html; - private static boolean wide=false; - - CodeHTML(String dir, String class_name, - Method[] methods, ConstantPool constant_pool, - ConstantHTML constant_html) throws IOException - { - this.class_name = class_name; - this.methods = methods; - this.constant_pool = constant_pool; - this.constant_html = constant_html; - - file = new PrintWriter(new FileOutputStream(dir + class_name + "_code.html")); - file.println(""); - - for(int i=0; i < methods.length; i++) - writeMethod(methods[i], i); - - file.println(""); - file.close(); - } - - /** - * Disassemble a stream of byte codes and return the - * string representation. - * - * @param stream data input stream - * @return String representation of byte code - */ - private final String codeToHTML(ByteSequence bytes, int method_number) - throws IOException - { - short opcode = (short)bytes.readUnsignedByte(); - StringBuffer buf; - String name, signature; - int default_offset=0, low, high; - int index, class_index, vindex, constant; - int[] jump_table; - int no_pad_bytes=0, offset; - - buf = new StringBuffer("" + OPCODE_NAMES[opcode] + ""); - - /* Special case: Skip (0-3) padding bytes, i.e., the - * following bytes are 4-byte-aligned - */ - if((opcode == TABLESWITCH) || (opcode == LOOKUPSWITCH)) { - int remainder = bytes.getIndex() % 4; - no_pad_bytes = (remainder == 0)? 0 : 4 - remainder; - - for(int i=0; i < no_pad_bytes; i++) - bytes.readByte(); - - // Both cases have a field default_offset in common - default_offset = bytes.readInt(); - } - - switch(opcode) { - case TABLESWITCH: - low = bytes.readInt(); - high = bytes.readInt(); - - offset = bytes.getIndex() - 12 - no_pad_bytes - 1; - default_offset += offset; - - buf.append(""); - - // Print switch indices in first row (and default) - jump_table = new int[high - low + 1]; - for(int i=0; i < jump_table.length; i++) { - jump_table[i] = offset + bytes.readInt(); - - buf.append(""); - } - buf.append("\n"); - - // Print target and default indices in second row - for(int i=0; i < jump_table.length; i++) - buf.append(""); - buf.append("\n
          " + (low + i) + "default
          " + jump_table[i] + "" + default_offset + "
          \n"); - - break; - - /* Lookup switch has variable length arguments. - */ - case LOOKUPSWITCH: - int npairs = bytes.readInt(); - offset = bytes.getIndex() - 8 - no_pad_bytes - 1; - jump_table = new int[npairs]; - default_offset += offset; - - buf.append(""); - - // Print switch indices in first row (and default) - for(int i=0; i < npairs; i++) { - int match = bytes.readInt(); - - jump_table[i] = offset + bytes.readInt(); - buf.append(""); - } - buf.append("\n"); - - // Print target and default indices in second row - for(int i=0; i < npairs; i++) - buf.append(""); - buf.append("\n
          " + match + "default
          " + jump_table[i] + "" + default_offset + "
          \n"); - break; - - /* Two address bytes + offset from start of byte stream form the - * jump target. - */ - case GOTO: case IFEQ: case IFGE: case IFGT: - case IFLE: case IFLT: - case IFNE: case IFNONNULL: case IFNULL: case IF_ACMPEQ: - case IF_ACMPNE: case IF_ICMPEQ: case IF_ICMPGE: case IF_ICMPGT: - case IF_ICMPLE: case IF_ICMPLT: case IF_ICMPNE: case JSR: - - index = (int)(bytes.getIndex() + bytes.readShort() - 1); - - buf.append("" + index + ""); - break; - - /* Same for 32-bit wide jumps - */ - case GOTO_W: case JSR_W: - int windex = bytes.getIndex() + bytes.readInt() - 1; - buf.append("" + - windex + ""); - break; - - /* Index byte references local variable (register) - */ - case ALOAD: case ASTORE: case DLOAD: case DSTORE: case FLOAD: - case FSTORE: case ILOAD: case ISTORE: case LLOAD: case LSTORE: - case RET: - if(wide) { - vindex = bytes.readShort(); - wide=false; // Clear flag - } - else - vindex = bytes.readUnsignedByte(); - - buf.append("%" + vindex); - break; - - /* - * Remember wide byte which is used to form a 16-bit address in the - * following instruction. Relies on that the method is called again with - * the following opcode. - */ - case WIDE: - wide = true; - buf.append("(wide)"); - break; - - /* Array of basic type. - */ - case NEWARRAY: - buf.append("" + TYPE_NAMES[bytes.readByte()] + ""); - break; - - /* Access object/class fields. - */ - case GETFIELD: case GETSTATIC: case PUTFIELD: case PUTSTATIC: - index = bytes.readShort(); - ConstantFieldref c1 = (ConstantFieldref)constant_pool.getConstant(index, CONSTANT_Fieldref); - - class_index = c1.getClassIndex(); - name = constant_pool.getConstantString(class_index, CONSTANT_Class); - name = Utility.compactClassName(name, false); - - index = c1.getNameAndTypeIndex(); - String field_name = constant_pool.constantToString(index, CONSTANT_NameAndType); - - if(name.equals(class_name)) { // Local field - buf.append("" + field_name + "\n"); - } - else - buf.append(constant_html.referenceConstant(class_index) + "." + field_name); - - break; - - /* Operands are references to classes in constant pool - */ - case CHECKCAST: case INSTANCEOF: case NEW: - index = bytes.readShort(); - buf.append(constant_html.referenceConstant(index)); - break; - - /* Operands are references to methods in constant pool - */ - case INVOKESPECIAL: case INVOKESTATIC: case INVOKEVIRTUAL: case INVOKEINTERFACE: - int m_index = bytes.readShort(); - String str; - - if(opcode == INVOKEINTERFACE) { // Special treatment needed - int nargs = bytes.readUnsignedByte(); // Redundant - int reserved = bytes.readUnsignedByte(); // Reserved - - ConstantInterfaceMethodref c=(ConstantInterfaceMethodref)constant_pool.getConstant(m_index, CONSTANT_InterfaceMethodref); - - class_index = c.getClassIndex(); - str = constant_pool.constantToString(c); - index = c.getNameAndTypeIndex(); - } - else { - ConstantMethodref c = (ConstantMethodref)constant_pool.getConstant(m_index, CONSTANT_Methodref); - class_index = c.getClassIndex(); - - str = constant_pool.constantToString(c); - index = c.getNameAndTypeIndex(); - } - - name = Class2HTML.referenceClass(class_index); - str = Class2HTML.toHTML(constant_pool.constantToString(constant_pool.getConstant(index, CONSTANT_NameAndType))); - - // Get signature, i.e., types - ConstantNameAndType c2 = (ConstantNameAndType)constant_pool. - getConstant(index, CONSTANT_NameAndType); - signature = constant_pool.constantToString(c2.getSignatureIndex(), - CONSTANT_Utf8); - String[] args = Utility.methodSignatureArgumentTypes(signature, false); - String type = Utility.methodSignatureReturnType(signature, false); - - buf.append(name + "." + str + "" + "("); - - // List arguments - for(int i=0; i < args.length; i++) { - buf.append(Class2HTML.referenceType(args[i])); - - if(i < args.length - 1) - buf.append(", "); - } - // Attach return type - buf.append("):" + Class2HTML.referenceType(type)); - - break; - - /* Operands are references to items in constant pool - */ - case LDC_W: case LDC2_W: - index = bytes.readShort(); - - buf.append("" + - Class2HTML.toHTML(constant_pool.constantToString(index, - constant_pool. - getConstant(index).getTag()))+ - ""); - break; - - case LDC: - index = bytes.readUnsignedByte(); - buf.append("" + - Class2HTML.toHTML(constant_pool.constantToString(index, - constant_pool. - getConstant(index).getTag()))+ - ""); - break; - - /* Array of references. - */ - case ANEWARRAY: - index = bytes.readShort(); - - buf.append(constant_html.referenceConstant(index)); - break; - - /* Multidimensional array of references. - */ - case MULTIANEWARRAY: - index = bytes.readShort(); - int dimensions = bytes.readByte(); - buf.append(constant_html.referenceConstant(index) + ":" + dimensions + "-dimensional"); - break; - - /* Increment local variable. - */ - case IINC: - if(wide) { - vindex = bytes.readShort(); - constant = bytes.readShort(); - wide = false; - } - else { - vindex = bytes.readUnsignedByte(); - constant = bytes.readByte(); - } - buf.append("%" + vindex + " " + constant); - break; - - default: - if(NO_OF_OPERANDS[opcode] > 0) { - for(int i=0; i < TYPE_OF_OPERANDS[opcode].length; i++) { - switch(TYPE_OF_OPERANDS[opcode][i]) { - case T_BYTE: - buf.append(bytes.readUnsignedByte()); - break; - - case T_SHORT: // Either branch or index - buf.append(bytes.readShort()); - break; - - case T_INT: - buf.append(bytes.readInt()); - break; - - default: // Never reached - System.err.println("Unreachable default case reached!"); - System.exit(-1); - } - buf.append(" "); - } - } - } - - buf.append(""); - return buf.toString(); - } - - /** - * Find all target addresses in code, so that they can be marked - * with <A NAME = ...>. Target addresses are kept in an BitSet object. - */ - private final void findGotos(ByteSequence bytes, Method method, Code code) - throws IOException - { - int index; - goto_set = new BitSet(bytes.available()); - int opcode; - - /* First get Code attribute from method and the exceptions handled - * (try .. catch) in this method. We only need the line number here. - */ - - if(code != null) { - CodeException[] ce = code.getExceptionTable(); - int len = ce.length; - - for(int i=0; i < len; i++) { - goto_set.set(ce[i].getStartPC()); - goto_set.set(ce[i].getEndPC()); - goto_set.set(ce[i].getHandlerPC()); - } - - // Look for local variables and their range - Attribute[] attributes = code.getAttributes(); - for(int i=0; i < attributes.length; i++) { - if(attributes[i].getTag() == ATTR_LOCAL_VARIABLE_TABLE) { - LocalVariable[] vars = ((LocalVariableTable)attributes[i]).getLocalVariableTable(); - - for(int j=0; j < vars.length; j++) { - int start = vars[j].getStartPC(); - int end = (int)(start + vars[j].getLength()); - goto_set.set(start); - goto_set.set(end); - } - break; - } - } - } - - // Get target addresses from GOTO, JSR, TABLESWITCH, etc. - for(int i=0; bytes.available() > 0; i++) { - opcode = bytes.readUnsignedByte(); - //System.out.println(OPCODE_NAMES[opcode]); - switch(opcode) { - case TABLESWITCH: case LOOKUPSWITCH: - //bytes.readByte(); // Skip already read byte - - int remainder = bytes.getIndex() % 4; - int no_pad_bytes = (remainder == 0)? 0 : 4 - remainder; - int default_offset, offset; - - for(int j=0; j < no_pad_bytes; j++) - bytes.readByte(); - - // Both cases have a field default_offset in common - default_offset = bytes.readInt(); - - if(opcode == TABLESWITCH) { - int low = bytes.readInt(); - int high = bytes.readInt(); - - offset = bytes.getIndex() - 12 - no_pad_bytes - 1; - default_offset += offset; - goto_set.set(default_offset); - - for(int j=0; j < (high - low + 1); j++) { - index = offset + bytes.readInt(); - goto_set.set(index); - } - } - else { // LOOKUPSWITCH - int npairs = bytes.readInt(); - - offset = bytes.getIndex() - 8 - no_pad_bytes - 1; - default_offset += offset; - goto_set.set(default_offset); - - for(int j=0; j < npairs; j++) { - int match = bytes.readInt(); - - index = offset + bytes.readInt(); - goto_set.set(index); - } - } - break; - - case GOTO: case IFEQ: case IFGE: case IFGT: - case IFLE: case IFLT: - case IFNE: case IFNONNULL: case IFNULL: case IF_ACMPEQ: - case IF_ACMPNE: case IF_ICMPEQ: case IF_ICMPGE: case IF_ICMPGT: - case IF_ICMPLE: case IF_ICMPLT: case IF_ICMPNE: case JSR: - //bytes.readByte(); // Skip already read byte - index = bytes.getIndex() + bytes.readShort() - 1; - - goto_set.set(index); - break; - - case GOTO_W: case JSR_W: - //bytes.readByte(); // Skip already read byte - index = bytes.getIndex() + bytes.readInt() - 1; - goto_set.set(index); - break; - - default: - bytes.unreadByte(); - codeToHTML(bytes, 0); // Ignore output - } - } - } - - /** - * Write a single method with the byte code associated with it. - */ - private void writeMethod(Method method, int method_number) - throws IOException - { - // Get raw signature - String signature = method.getSignature(); - // Get array of strings containing the argument types - String[] args = Utility.methodSignatureArgumentTypes(signature, false); - // Get return type string - String type = Utility.methodSignatureReturnType(signature, false); - // Get method name - String name = method.getName(); - String html_name = Class2HTML.toHTML(name); - // Get method's access flags - String access = Utility.accessToString(method.getAccessFlags()); - access = Utility.replace(access, " ", " "); - // Get the method's attributes, the Code Attribute in particular - Attribute[] attributes= method.getAttributes(); - - file.print("

          " + access + " " + - "" + Class2HTML.referenceType(type) + - " " + html_name + "("); - - for(int i=0; i < args.length; i++) { - file.print(Class2HTML.referenceType(args[i])); - if(i < args.length - 1) - file.print(", "); - } - - file.println(")

          "); - - Code c=null; - byte[] code=null; - - if(attributes.length > 0) { - file.print("

          Attributes

            \n"); - for(int i=0; i < attributes.length; i++) { - byte tag = attributes[i].getTag(); - - if(tag != ATTR_UNKNOWN) - file.print("
          • " + ATTRIBUTE_NAMES[tag] + "
          • \n"); - else - file.print("
          • " + attributes[i] + "
          • "); - - if(tag == ATTR_CODE) { - c = (Code)attributes[i]; - Attribute[] attributes2 = c.getAttributes(); - code = c.getCode(); - - file.print("
              "); - for(int j=0; j < attributes2.length; j++) { - tag = attributes2[j].getTag(); - file.print("
            • " + - ATTRIBUTE_NAMES[tag] + "
            • \n"); - - } - file.print("
            "); - } - } - file.println("
          "); - } - - if(code != null) { // No code, an abstract method, e.g. - //System.out.println(name + "\n" + Utility.codeToString(code, constant_pool, 0, -1)); - - // Print the byte code - ByteSequence stream = new ByteSequence(code); - stream.mark(stream.available()); - findGotos(stream, method, c); - stream.reset(); - - file.println("" + - ""); - - for(int i=0; stream.available() > 0; i++) { - int offset = stream.getIndex(); - String str = codeToHTML(stream, method_number); - String anchor = ""; - - /* Set an anchor mark if this line is targetted by a goto, jsr, etc. - * Defining an anchor for every line is very inefficient! - */ - if(goto_set.get(offset)) - anchor = ""; - - String anchor2; - if(stream.getIndex() == code.length) // last loop - anchor2 = "" + offset + ""; - else - anchor2 = "" + offset; - - file.println(""); - } - - // Mark last line, may be targetted from Attributes window - file.println(""); - file.println("
          Byte
          offset
          InstructionArgument
          " + anchor2 + "" + anchor + str + "
          "); - } - - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/ConstantHTML.java b/bcel-builder/src/org/aspectj/apache/bcel/util/ConstantHTML.java deleted file mode 100644 index 0175c7af6..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/ConstantHTML.java +++ /dev/null @@ -1,274 +0,0 @@ - -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; - -import org.aspectj.apache.bcel.classfile.Constant; -import org.aspectj.apache.bcel.classfile.ConstantClass; -import org.aspectj.apache.bcel.classfile.ConstantFieldref; -import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref; -import org.aspectj.apache.bcel.classfile.ConstantMethodref; -import org.aspectj.apache.bcel.classfile.ConstantNameAndType; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.ConstantString; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.classfile.Utility; - -/** - * Convert constant pool into HTML file. - * - * @version $Id: ConstantHTML.java,v 1.3 2004/11/22 08:31:27 aclement Exp $ - * @author M. Dahm - * - */ -final class ConstantHTML implements org.aspectj.apache.bcel.Constants { - private String class_name; // name of current class - private String class_package; // name of package - private ConstantPool constant_pool; // reference to constant pool - private PrintWriter file; // file to write to - private String[] constant_ref; // String to return for cp[i] - private Constant[] constants; // The constants in the cp - private Method[] methods; - - ConstantHTML(String dir, String class_name, String class_package, Method[] methods, - ConstantPool constant_pool) throws IOException - { - this.class_name = class_name; - this.class_package = class_package; - this.constant_pool = constant_pool; - this.methods = methods; - constants = constant_pool.getConstantPool(); - file = new PrintWriter(new FileOutputStream(dir + class_name + "_cp.html")); - constant_ref = new String[constants.length]; - constant_ref[0] = "<unknown>"; - - file.println(""); - - // Loop through constants, constants[0] is reserved - for(int i=1; i < constants.length; i++) { - if(i % 2 == 0) - file.print("\n"); - } - - file.println("
          "); - else - file.print("
          "); - - if(constants[i] != null) - writeConstant(i); - - file.print("
          "); - file.close(); - } - - String referenceConstant(int index) { - return constant_ref[index]; - } - - private void writeConstant(int index) { - byte tag = constants[index].getTag(); - int class_index, name_index; - String ref; - - // The header is always the same - file.println("

          " + index + " " + CONSTANT_NAMES[tag] + "

          "); - - /* For every constant type get the needed parameters and print them appropiately - */ - switch(tag) { - case CONSTANT_InterfaceMethodref: - case CONSTANT_Methodref: - // Get class_index and name_and_type_index, depending on type - if(tag == CONSTANT_Methodref) { - ConstantMethodref c = (ConstantMethodref)constant_pool.getConstant(index, CONSTANT_Methodref); - class_index = c.getClassIndex(); - name_index = c.getNameAndTypeIndex(); - } - else { - ConstantInterfaceMethodref c1 = (ConstantInterfaceMethodref)constant_pool.getConstant(index, CONSTANT_InterfaceMethodref); - class_index = c1.getClassIndex(); - name_index = c1.getNameAndTypeIndex(); - } - - // Get method name and its class - String method_name = constant_pool.constantToString(name_index, CONSTANT_NameAndType); - String html_method_name = Class2HTML.toHTML(method_name); - - // Partially compacted class name, i.e., / -> . - String method_class = constant_pool.constantToString(class_index, CONSTANT_Class); - String short_method_class = Utility.compactClassName(method_class); // I.e., remove java.lang. - short_method_class = Utility.compactClassName(method_class); // I.e., remove java.lang. - short_method_class = Utility.compactClassName(short_method_class, class_package + ".", true); // Remove class package prefix - - // Get method signature - ConstantNameAndType c2 = (ConstantNameAndType)constant_pool.getConstant(name_index, CONSTANT_NameAndType); - String signature = constant_pool.constantToString(c2.getSignatureIndex(), CONSTANT_Utf8); - // Get array of strings containing the argument types - String[] args = Utility.methodSignatureArgumentTypes(signature, false); - - // Get return type string - String type = Utility.methodSignatureReturnType(signature, false); - String ret_type = Class2HTML.referenceType(type); - - StringBuffer buf = new StringBuffer("("); - for(int i=0; i < args.length; i++) { - buf.append(Class2HTML.referenceType(args[i])); - if(i < args.length - 1) - buf.append(", "); - } - buf.append(")"); - - String arg_types = buf.toString(); - - if(method_class.equals(class_name)) // Method is local to class - ref = "" + html_method_name + ""; - else - ref = "" + short_method_class + - "." + html_method_name; - - constant_ref[index] = ret_type + " " + - short_method_class + "." + html_method_name + " " + arg_types; - - file.println("

          " + ret_type + " " + ref + arg_types + " \n

          "); - break; - - case CONSTANT_Fieldref: - // Get class_index and name_and_type_index - ConstantFieldref c3 = (ConstantFieldref)constant_pool.getConstant(index, CONSTANT_Fieldref); - class_index = c3.getClassIndex(); - name_index = c3.getNameAndTypeIndex(); - - // Get method name and its class (compacted) - String field_class = constant_pool.constantToString(class_index, CONSTANT_Class); - String short_field_class = Utility.compactClassName(field_class); // I.e., remove java.lang. - short_field_class = Utility.compactClassName(short_field_class, class_package + ".", true); // Remove class package prefix - - String field_name = constant_pool.constantToString(name_index, CONSTANT_NameAndType); - - if(field_class.equals(class_name)) // Field is local to class - ref = "" + field_name + ""; - else - ref = "" + - short_field_class + "." + field_name + "\n"; - - constant_ref[index] = "" + - short_field_class + "." + field_name + ""; - - file.println("

          " + ref + "
          \n" + "

          "); - break; - - case CONSTANT_Class: - ConstantClass c4 = (ConstantClass)constant_pool.getConstant(index, CONSTANT_Class); - name_index = c4.getNameIndex(); - String class_name2 = constant_pool.constantToString(index, tag); // / -> . - String short_class_name = Utility.compactClassName(class_name2); // I.e., remove java.lang. - short_class_name = Utility.compactClassName(short_class_name, class_package + ".", true); // Remove class package prefix - - ref = "" + short_class_name + ""; - constant_ref[index] = "" + short_class_name + ""; - - file.println("

          " + ref + "

          \n"); - break; - - case CONSTANT_String: - ConstantString c5 = (ConstantString)constant_pool.getConstant(index, CONSTANT_String); - name_index = c5.getStringIndex(); - - String str = Class2HTML.toHTML(constant_pool.constantToString(index, tag)); - - file.println("

          " + str + "

          \n"); - break; - - case CONSTANT_NameAndType: - ConstantNameAndType c6 = (ConstantNameAndType)constant_pool.getConstant(index, CONSTANT_NameAndType); - name_index = c6.getNameIndex(); - int signature_index = c6.getSignatureIndex(); - - file.println("

          " + Class2HTML.toHTML(constant_pool.constantToString(index, tag)) + "

          \n"); - break; - - default: - file.println("

          " + Class2HTML.toHTML(constant_pool.constantToString(index, tag)) + "\n"); - } // switch - } - - private final int getMethodNumber(String str) { - for(int i=0; i < methods.length; i++) { - String cmp = methods[i].getName() + methods[i].getSignature(); - if(cmp.equals(str)) - return i; - } - return -1; - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/JavaWrapper.java b/bcel-builder/src/org/aspectj/apache/bcel/util/JavaWrapper.java deleted file mode 100644 index 353a000b8..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/JavaWrapper.java +++ /dev/null @@ -1,152 +0,0 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.lang.reflect.*; - -/** - * Java interpreter replacement, i.e., wrapper that uses its own ClassLoader - * to modify/generate classes as they're requested. You can take this as a template - * for your own applications.
          - * Call this wrapper with - *

          java org.aspectj.apache.bcel.util.JavaWrapper <real.class.name> [arguments]
          - *

          - * To use your own class loader you can set the "bcel.classloader" system property - * which defaults to "org.aspectj.apache.bcel.util.ClassLoader", e.g., with - *

          java org.aspectj.apache.bcel.util.JavaWrapper -Dbcel.classloader=foo.MyLoader <real.class.name> [arguments]
          - *

          - * - * @version $Id: JavaWrapper.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ - * @author M. Dahm - * @see ClassLoader - */ -public class JavaWrapper { - private java.lang.ClassLoader loader; - - private static java.lang.ClassLoader getClassLoader() { - String s = System.getProperty("bcel.classloader"); - - if((s == null) || "".equals(s)) - s = "org.aspectj.apache.bcel.util.ClassLoader"; - - try { - return (java.lang.ClassLoader)Class.forName(s).newInstance(); - } catch(Exception e) { - throw new RuntimeException(e.toString()); - } - } - - public JavaWrapper(java.lang.ClassLoader loader) { - this.loader = loader; - } - - public JavaWrapper() { - this(getClassLoader()); - } - - /** Runs the main method of the given class with the arguments passed in argv - * - * @param class_name the fully qualified class name - * @param argv the arguments just as you would pass them directly - */ - public void runMain(String class_name, String[] argv) throws ClassNotFoundException - { - Class cl = loader.loadClass(class_name); - Method method = null; - - try { - method = cl.getMethod("main", new Class[] { argv.getClass() }); - - /* Method main is sane ? - */ - int m = method.getModifiers(); - Class r = method.getReturnType(); - - if(!(Modifier.isPublic(m) && Modifier.isStatic(m)) || - Modifier.isAbstract(m) || (r != Void.TYPE)) - throw new NoSuchMethodException(); - } catch(NoSuchMethodException no) { - System.out.println("In class " + class_name + - ": public static void main(String[] argv) is not defined"); - return; - } - - try { - method.invoke(null, new Object[] { argv }); - } catch(Exception ex) { - ex.printStackTrace(); - } - } - - /** Default main method used as wrapper, expects the fully qualified class name - * of the real class as the first argument. - */ - public static void main(String[] argv) throws Exception { - /* Expects class name as first argument, other arguments are by-passed. - */ - if(argv.length == 0) { - System.out.println("Missing class name."); - return; - } - - String class_name = argv[0]; - String[] new_argv = new String[argv.length - 1]; - System.arraycopy(argv, 1, new_argv, 0, new_argv.length); - - JavaWrapper wrapper = new JavaWrapper(); - wrapper.runMain(class_name, new_argv); - } -} - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/MethodHTML.java b/bcel-builder/src/org/aspectj/apache/bcel/util/MethodHTML.java deleted file mode 100644 index c3b5f924f..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/MethodHTML.java +++ /dev/null @@ -1,208 +0,0 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; - -import org.aspectj.apache.bcel.classfile.Attribute; -import org.aspectj.apache.bcel.classfile.Code; -import org.aspectj.apache.bcel.classfile.ConstantValue; -import org.aspectj.apache.bcel.classfile.ExceptionTable; -import org.aspectj.apache.bcel.classfile.Field; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.classfile.Utility; - -/** - * Convert methods and fields into HTML file. - * - * @version $Id: MethodHTML.java,v 1.3 2004/11/22 08:31:27 aclement Exp $ - * @author M. Dahm - * - */ -final class MethodHTML implements org.aspectj.apache.bcel.Constants { - private String class_name; // name of current class - private PrintWriter file; // file to write to - private ConstantHTML constant_html; - private AttributeHTML attribute_html; - - MethodHTML(String dir, String class_name, - Method[] methods, Field[] fields, - ConstantHTML constant_html, AttributeHTML attribute_html) throws IOException - { - this.class_name = class_name; - this.attribute_html = attribute_html; - this.constant_html = constant_html; - - file = new PrintWriter(new FileOutputStream(dir + class_name + "_methods.html")); - - file.println(""); - file.println("" + - ""); - for(int i=0; i < fields.length; i++) - writeField(fields[i]); - file.println("
          Access flagsTypeField name
          "); - - file.println("" + - "" + - ""); - for(int i=0; i < methods.length; i++) - writeMethod(methods[i], i); - - file.println("
          Access flagsReturn typeMethod nameArguments
          "); - file.close(); - } - - /** - * Print field of class. - * - * @param field field to print - * @exception java.io.IOException - */ - private void writeField(Field field) throws IOException { - String type = Utility.signatureToString(field.getSignature()); - String name = field.getName(); - String access = Utility.accessToString(field.getAccessFlags()); - Attribute[] attributes; - - access = Utility.replace(access, " ", " "); - - file.print("" + access + "\n" + - Class2HTML.referenceType(type) + "" + - name + ""); - - attributes = field.getAttributes(); - - // Write them to the Attributes.html file with anchor "[]" - for(int i=0; i < attributes.length; i++) - attribute_html.writeAttribute(attributes[i], name + "@" + i); - - for(int i=0; i < attributes.length; i++) { - if(attributes[i].getTag() == ATTR_CONSTANT_VALUE) { // Default value - String str = ((ConstantValue)attributes[i]).toString(); - - // Reference attribute in _attributes.html - file.print("= " + str + "\n"); - break; - } - } - - file.println(""); - } - - private final void writeMethod(Method method, int method_number) throws IOException { - // Get raw signature - String signature = method.getSignature(); - // Get array of strings containing the argument types - String[] args = Utility.methodSignatureArgumentTypes(signature, false); - // Get return type string - String type = Utility.methodSignatureReturnType(signature, false); - // Get method name - String name = method.getName(), html_name; - // Get method's access flags - String access = Utility.accessToString(method.getAccessFlags()); - // Get the method's attributes, the Code Attribute in particular - Attribute[] attributes = method.getAttributes(); - - /* HTML doesn't like names like and spaces are places to break - * lines. Both we don't want... - */ - access = Utility.replace(access, " ", " "); - html_name = Class2HTML.toHTML(name); - - file.print("" + - access + ""); - - file.print("" + Class2HTML.referenceType(type) + "" + - "" + html_name + "\n("); - - for(int i=0; i < args.length; i++) { - file.print(Class2HTML.referenceType(args[i])); - if(i < args.length - 1) - file.print(", "); - } - - file.print(")"); - - // Check for thrown exceptions - for(int i=0; i < attributes.length; i++) { - attribute_html.writeAttribute(attributes[i], "method" + method_number + "@" + i, - method_number); - - byte tag = attributes[i].getTag(); - if(tag == ATTR_EXCEPTIONS) { - file.print("throws"); - int[] exceptions = ((ExceptionTable)attributes[i]).getExceptionIndexTable(); - - for(int j=0; j < exceptions.length; j++) { - file.print(constant_html.referenceConstant(exceptions[j])); - - if(j < exceptions.length - 1) - file.print(", "); - } - file.println(""); - } else if(tag == ATTR_CODE) { - Attribute[] c_a = ((Code)attributes[i]).getAttributes(); - - for(int j=0; j < c_a.length; j++) - attribute_html.writeAttribute(c_a[j], "method" + method_number + "@" + i + "@" + j, - method_number); - } - } - } -} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java b/bcel-builder/src/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java index 3d5928a17..acc6f2650 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java @@ -1,241 +1,241 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.IOException; -import java.io.InputStream; -import java.lang.ref.ReferenceQueue; -import java.lang.ref.SoftReference; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.AbstractMap; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.aspectj.apache.bcel.classfile.ClassParser; -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * The repository maintains information about which classes have - * been loaded. - * - * It loads its data from the ClassLoader implementation - * passed into its constructor. - * - * @see org.aspectj.apache.bcel.Repository - * - * @version $Id: NonCachingClassLoaderRepository.java,v 1.1.4.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @author David Dixon-Peugh - * - */ -public class NonCachingClassLoaderRepository - implements Repository -{ - private static java.lang.ClassLoader bootClassLoader = null; - - private java.lang.ClassLoader loader; - private Map loadedClasses = - new SoftHashMap(); // CLASSNAME X JAVACLASS - - public static class SoftHashMap extends AbstractMap { - private Map map; - private ReferenceQueue rq = new ReferenceQueue(); - - public SoftHashMap(Map map) { this.map = map; } - public SoftHashMap() { this(new HashMap()); } - public SoftHashMap(Map map, boolean b) { this(map); } - - class SpecialValue extends SoftReference { - private final Object key; - SpecialValue(Object k,Object v) { - super(v,rq); - this.key = k; - } - } - - private void processQueue() { - SpecialValue sv = null; - while ((sv = (SpecialValue)rq.poll())!=null) { - map.remove(sv.key); - } - } - - public Object get(Object key) { - SpecialValue value = (SpecialValue)map.get(key); - if (value==null) return null; - if (value.get()==null) { - // it got GC'd - map.remove(value.key); - return null; - } else { - return value.get(); - } - } - - public Object put(Object k, Object v) { - processQueue(); - return map.put(k, new SpecialValue(k,v)); - } - - public Set entrySet() { - return map.entrySet(); - } - - public void clear() { - processQueue(); - Set keys = map.keySet(); - for (Iterator iterator = keys.iterator(); iterator.hasNext();) { - Object name = (Object) iterator.next(); - map.remove(name); - } - } - - public int size() { - processQueue(); - return map.size(); - } - - public Object remove(Object k) { - processQueue(); - SpecialValue value = (SpecialValue)map.remove(k); - if (value==null) return null; - if (value.get()!=null) { - return value.get(); - } - return null; - } - } - public NonCachingClassLoaderRepository( java.lang.ClassLoader loader ) { - this.loader = (loader != null) ? loader : getBootClassLoader(); - } - - private static synchronized java.lang.ClassLoader getBootClassLoader() { - if (bootClassLoader == null) { - bootClassLoader = new URLClassLoader(new URL[0]); - } - return bootClassLoader; - } - - /** - * Store a new JavaClass into this Repository. - */ - public void storeClass( JavaClass clazz ) { - loadedClasses.put( clazz.getClassName(), - clazz ); - clazz.setRepository( this ); - } - - /** - * Remove class from repository - */ - public void removeClass(JavaClass clazz) { - loadedClasses.remove(clazz.getClassName()); - } - - /** - * Find an already defined JavaClass. - */ - public JavaClass findClass( String className ) { - if ( loadedClasses.containsKey( className )) { - return (JavaClass) loadedClasses.get( className ); - } else { - return null; - } - } - - /** - * Lookup a JavaClass object from the Class Name provided. - */ - public JavaClass loadClass( String className ) - throws ClassNotFoundException - { - String classFile = className.replace('.', '/'); - - JavaClass RC = findClass( className ); - if (RC != null) { return RC; } - - try { - InputStream is = - loader.getResourceAsStream( classFile + ".class" ); - - if(is == null) { - throw new ClassNotFoundException(className + " not found."); - } - - ClassParser parser = new ClassParser( is, className ); - RC = parser.parse(); - - storeClass( RC ); - - return RC; - } catch (IOException e) { - throw new ClassNotFoundException( e.toString() ); - } - } - - public JavaClass loadClass(Class clazz) throws ClassNotFoundException { - return loadClass(clazz.getName()); - } - - /** Clear all entries from cache. - */ - public void clear() { - loadedClasses.clear(); - } -} - +package org.aspectj.apache.bcel.util; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.IOException; +import java.io.InputStream; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.SoftReference; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.AbstractMap; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.aspectj.apache.bcel.classfile.ClassParser; +import org.aspectj.apache.bcel.classfile.JavaClass; + +/** + * The repository maintains information about which classes have + * been loaded. + * + * It loads its data from the ClassLoader implementation + * passed into its constructor. + * + * @see org.aspectj.apache.bcel.Repository + * + * @version $Id: NonCachingClassLoaderRepository.java,v 1.1.4.3 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @author David Dixon-Peugh + * + */ +public class NonCachingClassLoaderRepository + implements Repository +{ + private static java.lang.ClassLoader bootClassLoader = null; + + private java.lang.ClassLoader loader; + private Map loadedClasses = + new SoftHashMap(); // CLASSNAME X JAVACLASS + + public static class SoftHashMap extends AbstractMap { + private Map map; + private ReferenceQueue rq = new ReferenceQueue(); + + public SoftHashMap(Map map) { this.map = map; } + public SoftHashMap() { this(new HashMap()); } + public SoftHashMap(Map map, boolean b) { this(map); } + + class SpecialValue extends SoftReference { + private final Object key; + SpecialValue(Object k,Object v) { + super(v,rq); + this.key = k; + } + } + + private void processQueue() { + SpecialValue sv = null; + while ((sv = (SpecialValue)rq.poll())!=null) { + map.remove(sv.key); + } + } + + public Object get(Object key) { + SpecialValue value = (SpecialValue)map.get(key); + if (value==null) return null; + if (value.get()==null) { + // it got GC'd + map.remove(value.key); + return null; + } else { + return value.get(); + } + } + + public Object put(Object k, Object v) { + processQueue(); + return map.put(k, new SpecialValue(k,v)); + } + + public Set entrySet() { + return map.entrySet(); + } + + public void clear() { + processQueue(); + Set keys = map.keySet(); + for (Iterator iterator = keys.iterator(); iterator.hasNext();) { + Object name = (Object) iterator.next(); + map.remove(name); + } + } + + public int size() { + processQueue(); + return map.size(); + } + + public Object remove(Object k) { + processQueue(); + SpecialValue value = (SpecialValue)map.remove(k); + if (value==null) return null; + if (value.get()!=null) { + return value.get(); + } + return null; + } + } + public NonCachingClassLoaderRepository( java.lang.ClassLoader loader ) { + this.loader = (loader != null) ? loader : getBootClassLoader(); + } + + private static synchronized java.lang.ClassLoader getBootClassLoader() { + if (bootClassLoader == null) { + bootClassLoader = new URLClassLoader(new URL[0]); + } + return bootClassLoader; + } + + /** + * Store a new JavaClass into this Repository. + */ + public void storeClass( JavaClass clazz ) { + loadedClasses.put( clazz.getClassName(), + clazz ); + clazz.setRepository( this ); + } + + /** + * Remove class from repository + */ + public void removeClass(JavaClass clazz) { + loadedClasses.remove(clazz.getClassName()); + } + + /** + * Find an already defined JavaClass. + */ + public JavaClass findClass( String className ) { + if ( loadedClasses.containsKey( className )) { + return (JavaClass) loadedClasses.get( className ); + } else { + return null; + } + } + + /** + * Lookup a JavaClass object from the Class Name provided. + */ + public JavaClass loadClass( String className ) + throws ClassNotFoundException + { + String classFile = className.replace('.', '/'); + + JavaClass RC = findClass( className ); + if (RC != null) { return RC; } + + try { + InputStream is = + loader.getResourceAsStream( classFile + ".class" ); + + if(is == null) { + throw new ClassNotFoundException(className + " not found."); + } + + ClassParser parser = new ClassParser( is, className ); + RC = parser.parse(); + + storeClass( RC ); + + return RC; + } catch (IOException e) { + throw new ClassNotFoundException( e.toString() ); + } + } + + public JavaClass loadClass(Class clazz) throws ClassNotFoundException { + return loadClass(clazz.getName()); + } + + /** Clear all entries from cache. + */ + public void clear() { + loadedClasses.clear(); + } +} + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/Repository.java b/bcel-builder/src/org/aspectj/apache/bcel/util/Repository.java index 25a87ea60..a1b2bfd73 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/Repository.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/util/Repository.java @@ -1,105 +1,105 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * Abstract definition of a class repository. Instances may be used - * to load classes from different sources and may be used in the - * Repository.setRepository method. - * - * @see org.aspectj.apache.bcel.Repository - * @version $Id: Repository.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @author David Dixon-Peugh - */ -public interface Repository extends java.io.Serializable { - /** - * Store the provided class under "clazz.getClassName()" - */ - public void storeClass(JavaClass clazz); - - /** - * Remove class from repository - */ - public void removeClass(JavaClass clazz); - - /** - * Find the class with the name provided, if the class - * isn't there, return NULL. - */ - public JavaClass findClass(String className); - - /** - * Find the class with the name provided, if the class - * isn't there, make an attempt to load it. - */ - public JavaClass loadClass(String className) - throws java.lang.ClassNotFoundException; - - /** - * Find the JavaClass instance for the given run-time class object - */ - public JavaClass loadClass(Class clazz) - throws java.lang.ClassNotFoundException; - - /** Clear all entries from cache. - */ - public void clear(); -} - - - +package org.aspectj.apache.bcel.util; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.classfile.JavaClass; + +/** + * Abstract definition of a class repository. Instances may be used + * to load classes from different sources and may be used in the + * Repository.setRepository method. + * + * @see org.aspectj.apache.bcel.Repository + * @version $Id: Repository.java,v 1.2.10.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @author David Dixon-Peugh + */ +public interface Repository extends java.io.Serializable { + /** + * Store the provided class under "clazz.getClassName()" + */ + public void storeClass(JavaClass clazz); + + /** + * Remove class from repository + */ + public void removeClass(JavaClass clazz); + + /** + * Find the class with the name provided, if the class + * isn't there, return NULL. + */ + public JavaClass findClass(String className); + + /** + * Find the class with the name provided, if the class + * isn't there, make an attempt to load it. + */ + public JavaClass loadClass(String className) + throws java.lang.ClassNotFoundException; + + /** + * Find the JavaClass instance for the given run-time class object + */ + public JavaClass loadClass(Class clazz) + throws java.lang.ClassNotFoundException; + + /** Clear all entries from cache. + */ + public void clear(); +} + + + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/SyntheticRepository.java b/bcel-builder/src/org/aspectj/apache/bcel/util/SyntheticRepository.java index 8a43e77a1..aa96aed38 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/SyntheticRepository.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/util/SyntheticRepository.java @@ -1,205 +1,205 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.WeakHashMap; - -import org.aspectj.apache.bcel.classfile.ClassParser; -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * This repository is used in situations where a Class is created - * outside the realm of a ClassLoader. Classes are loaded from - * the file systems using the paths specified in the given - * class path. By default, this is the value returned by - * ClassPath.getClassPath(). - *
          - * It is designed to be used as a singleton, however it - * can also be used with custom classpaths. - * -/** - * Abstract definition of a class repository. Instances may be used - * to load classes from different sources and may be used in the - * Repository.setRepository method. - * - * @see org.aspectj.apache.bcel.Repository - * - * @version $Id: SyntheticRepository.java,v 1.6.4.1 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @author David Dixon-Peugh - */ -public class SyntheticRepository implements Repository { - private static final String DEFAULT_PATH = ClassPath.getClassPath(); - - private static HashMap _instances = new HashMap(); // CLASSPATH X REPOSITORY - - private ClassPath _path = null; - private WeakHashMap _loadedClasses = new WeakHashMap(); // CLASSNAME X JAVACLASS - - private SyntheticRepository(ClassPath path) { - _path = path; - } - - public static SyntheticRepository getInstance() { - return getInstance(ClassPath.getSystemClassPath()); - } - - public static SyntheticRepository getInstance(ClassPath classPath) { - SyntheticRepository rep = (SyntheticRepository)_instances.get(classPath); - - if(rep == null) { - rep = new SyntheticRepository(classPath); - _instances.put(classPath, rep); - } - - return rep; - } - - /** - * Store a new JavaClass instance into this Repository. - */ - public void storeClass(JavaClass clazz) { - _loadedClasses.put(clazz.getClassName(), clazz); - clazz.setRepository(this); - } - - /** - * Remove class from repository - */ - public void removeClass(JavaClass clazz) { - _loadedClasses.remove(clazz.getClassName()); - } - - /** - * Find an already defined (cached) JavaClass object by name. - */ - public JavaClass findClass(String className) { - return (JavaClass)_loadedClasses.get(className); - } - - /** - * Load a JavaClass object for the given class name using - * the CLASSPATH environment variable. - */ - public JavaClass loadClass(String className) - throws ClassNotFoundException - { - if(className == null || className.equals("")) { - throw new IllegalArgumentException("Invalid class name " + className); - } - - className = className.replace('/', '.'); // Just in case, canonical form - - try { - return loadClass(_path.getInputStream(className), className); - } catch(IOException e) { - throw new ClassNotFoundException("Exception while looking for class " + - className + ": " + e.toString()); - } - } - - /** - * Try to find class source via getResourceAsStream(). - * @see Class - * @return JavaClass object for given runtime class - */ - public JavaClass loadClass(Class clazz) throws ClassNotFoundException { - String className = clazz.getName(); - String name = className; - int i = name.lastIndexOf('.'); - - if(i > 0) { - name = name.substring(i + 1); - } - - return loadClass(clazz.getResourceAsStream(name + ".class"), className); - } - - private JavaClass loadClass(InputStream is, String className) - throws ClassNotFoundException - { - JavaClass clazz = findClass(className); - - if(clazz != null) { - return clazz; - } - - try { - if(is != null) { - ClassParser parser = new ClassParser(is, className); - clazz = parser.parse(); - - storeClass(clazz); - - return clazz; - } - } catch(IOException e) { - throw new ClassNotFoundException("Exception while looking for class " + - className + ": " + e.toString()); - } - - throw new ClassNotFoundException("SyntheticRepository could not load " + - className); - } - - /** Clear all entries from cache. - */ - public void clear() { - _loadedClasses.clear(); - } -} +package org.aspectj.apache.bcel.util; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.WeakHashMap; + +import org.aspectj.apache.bcel.classfile.ClassParser; +import org.aspectj.apache.bcel.classfile.JavaClass; + +/** + * This repository is used in situations where a Class is created + * outside the realm of a ClassLoader. Classes are loaded from + * the file systems using the paths specified in the given + * class path. By default, this is the value returned by + * ClassPath.getClassPath(). + *
          + * It is designed to be used as a singleton, however it + * can also be used with custom classpaths. + * +/** + * Abstract definition of a class repository. Instances may be used + * to load classes from different sources and may be used in the + * Repository.setRepository method. + * + * @see org.aspectj.apache.bcel.Repository + * + * @version $Id: SyntheticRepository.java,v 1.6.4.2 2008/05/08 19:26:46 aclement Exp $ + * @author M. Dahm + * @author David Dixon-Peugh + */ +public class SyntheticRepository implements Repository { + private static final String DEFAULT_PATH = ClassPath.getClassPath(); + + private static HashMap _instances = new HashMap(); // CLASSPATH X REPOSITORY + + private ClassPath _path = null; + private WeakHashMap _loadedClasses = new WeakHashMap(); // CLASSNAME X JAVACLASS + + private SyntheticRepository(ClassPath path) { + _path = path; + } + + public static SyntheticRepository getInstance() { + return getInstance(ClassPath.getSystemClassPath()); + } + + public static SyntheticRepository getInstance(ClassPath classPath) { + SyntheticRepository rep = (SyntheticRepository)_instances.get(classPath); + + if(rep == null) { + rep = new SyntheticRepository(classPath); + _instances.put(classPath, rep); + } + + return rep; + } + + /** + * Store a new JavaClass instance into this Repository. + */ + public void storeClass(JavaClass clazz) { + _loadedClasses.put(clazz.getClassName(), clazz); + clazz.setRepository(this); + } + + /** + * Remove class from repository + */ + public void removeClass(JavaClass clazz) { + _loadedClasses.remove(clazz.getClassName()); + } + + /** + * Find an already defined (cached) JavaClass object by name. + */ + public JavaClass findClass(String className) { + return (JavaClass)_loadedClasses.get(className); + } + + /** + * Load a JavaClass object for the given class name using + * the CLASSPATH environment variable. + */ + public JavaClass loadClass(String className) + throws ClassNotFoundException + { + if(className == null || className.equals("")) { + throw new IllegalArgumentException("Invalid class name " + className); + } + + className = className.replace('/', '.'); // Just in case, canonical form + + try { + return loadClass(_path.getInputStream(className), className); + } catch(IOException e) { + throw new ClassNotFoundException("Exception while looking for class " + + className + ": " + e.toString()); + } + } + + /** + * Try to find class source via getResourceAsStream(). + * @see Class + * @return JavaClass object for given runtime class + */ + public JavaClass loadClass(Class clazz) throws ClassNotFoundException { + String className = clazz.getName(); + String name = className; + int i = name.lastIndexOf('.'); + + if(i > 0) { + name = name.substring(i + 1); + } + + return loadClass(clazz.getResourceAsStream(name + ".class"), className); + } + + private JavaClass loadClass(InputStream is, String className) + throws ClassNotFoundException + { + JavaClass clazz = findClass(className); + + if(clazz != null) { + return clazz; + } + + try { + if(is != null) { + ClassParser parser = new ClassParser(is, className); + clazz = parser.parse(); + + storeClass(clazz); + + return clazz; + } + } catch(IOException e) { + throw new ClassNotFoundException("Exception while looking for class " + + className + ": " + e.toString()); + } + + throw new ClassNotFoundException("SyntheticRepository could not load " + + className); + } + + /** Clear all entries from cache. + */ + public void clear() { + _loadedClasses.clear(); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/package.html b/bcel-builder/src/org/aspectj/apache/bcel/util/package.html deleted file mode 100644 index 9c2177946..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/package.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - -

          -This package contains utility classes for the -Byte Code Engineering -Library, namely: -

          -

          -

            -
          • Collection classes for JavaClass objects
          • -
          • A converter for class files to HTML
          • -
          • A tool to find instructions patterns via regular expressions
          • -
          • A class to find classes as defined in the CLASSPATH
          • -
          • A class loader that allows to create clases at run time
          • -
          - -

          - - diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/package.html b/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/package.html deleted file mode 100644 index cfd38591b..000000000 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/package.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - -Exception classes used by JustIce, mostly used internally. You don't need to bother with them. - -

          Package Specification

          - -Contained in this package are Exception classes for use with the JustIce verifier. - -

          Related Documentation

          - -For a simple demonstration of JustIce working, please see: - - - - diff --git a/bcel-builder/testfile.txt b/bcel-builder/testfile.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParsingTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParsingTest.java index b4b8dbce3..dbc3ae154 100644 --- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParsingTest.java +++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParsingTest.java @@ -11,11 +11,16 @@ * ******************************************************************/ package org.aspectj.apache.bcel.classfile.tests; +import java.util.ArrayList; + +import org.aspectj.apache.bcel.Constants; import org.aspectj.apache.bcel.classfile.Attribute; +import org.aspectj.apache.bcel.classfile.ClassFormatException; import org.aspectj.apache.bcel.classfile.JavaClass; import org.aspectj.apache.bcel.classfile.Method; import org.aspectj.apache.bcel.classfile.Signature; import org.aspectj.apache.bcel.classfile.Utility; +import org.aspectj.apache.bcel.classfile.Utility.ResultHolder; /** * Generics introduces more complex signature possibilities, they are no longer just @@ -149,27 +154,27 @@ public class GenericSignatureParsingTest extends BcelTestCase { // These routines call BCEL to determine if it can correctly translate from one form to the other. private void checkClassTypeSignature(String sig, String expected) { StringBuffer result = new StringBuffer(); - int p = Utility.readClassTypeSignatureFrom(sig,0,result,false); + int p = GenericSignatureParsingTest.readClassTypeSignatureFrom(sig,0,result,false); assertTrue("Only swallowed "+p+" chars of this sig "+sig+" (len="+sig.length()+")",p==sig.length()); assertTrue("Expected '"+expected+"' but got '"+result.toString()+"'",result.toString().equals(expected)); } private void checkMethodTypeToSignature(String ret,String[] args,String expected) { - String res = Utility.methodTypeToSignature(ret,args); + String res = GenericSignatureParsingTest.methodTypeToSignature(ret,args); if (!res.equals(expected)) { fail("Should match. Got: "+res+" Expected:"+expected); } } private void checkMethodSignatureReturnType(String sig,String expected) { - String result = Utility.methodSignatureReturnType(sig,false); + String result = GenericSignatureParsingTest.methodSignatureReturnType(sig,false); if (!result.equals(expected)) { fail("Should match. Got: "+result+" Expected:"+expected); } } private void checkMethodSignatureArgumentTypes(String in,String[] expected) { - String[] result = Utility.methodSignatureArgumentTypes(in,false); + String[] result = GenericSignatureParsingTest.methodSignatureArgumentTypes(in,false); if (result.length!=expected.length) { fail("Expected "+expected.length+" entries to be returned but only got "+result.length); } @@ -191,5 +196,278 @@ public class GenericSignatureParsingTest extends BcelTestCase { } return null; } + + + /** + * Takes a string and consumes a single complete signature from it, returning + * how many chars it consumed. The chopit flag indicates whether to shorten + * type references ( java/lang/String => String ) + * + * FIXME asc this should also create some kind of object you can query for information about whether its parameterized, what the bounds are, etc... + */ + public static final int readClassTypeSignatureFrom(String signature, int posn, StringBuffer result, boolean chopit) { + int idx = posn; + try { + switch (signature.charAt(idx)) { + case 'B' : result.append("byte"); return 1; + case 'C' : result.append("char"); return 1; + case 'D' : result.append("double"); return 1; + case 'F' : result.append("float"); return 1; + case 'I' : result.append("int"); return 1; + case 'J' : result.append("long"); return 1; + case 'S' : result.append("short"); return 1; + case 'Z' : result.append("boolean");return 1; + case 'V' : result.append("void"); return 1; + + + //FIXME ASC Need a state machine to check we are parsing the right stuff here ! + case 'T' : + idx++; + int nextSemiIdx = signature.indexOf(';',idx); + result.append(signature.substring(idx,nextSemiIdx)); + return nextSemiIdx+1-posn; + + case '+' : + result.append("? extends "); + return readClassTypeSignatureFrom(signature,idx+1,result,chopit)+1; + + case '-' : + result.append("? super "); + return readClassTypeSignatureFrom(signature,idx+1,result,chopit)+1; + + case '*' : + result.append("?"); + return 1; + + case 'L' : // Full class name + boolean parameterized = false; + int idxSemicolon = signature.indexOf(';',idx); // Look for closing ';' or '<' + int idxAngly = signature.indexOf('<',idx); + int endOfSig = idxSemicolon; + if ((idxAngly!=-1) && idxAngly");idx++; + } + if (signature.charAt(idx)!=';') throw new RuntimeException("Did not find ';' at end of signature, found "+signature.charAt(idx)); + idx++; + return idx-posn; + + + case '[' : // Array declaration + int dim = 0; + while (signature.charAt(idx)=='[') {dim++;idx++;} + idx+=readClassTypeSignatureFrom(signature,idx,result,chopit); + while (dim>0) {result.append("[]");dim--;} + return idx-posn; + + default : throw new ClassFormatException("Invalid signature: `" + + signature + "'"); + } + } catch(StringIndexOutOfBoundsException e) { // Should never occur + throw new ClassFormatException("Invalid signature: " + e + ":" + signature); + } + } + + + public static final String readClassTypeSignatureFrom(String signature) { + StringBuffer sb = new StringBuffer(); + GenericSignatureParsingTest.readClassTypeSignatureFrom(signature,0,sb,false); + return sb.toString(); + } + + + public static int countBrackets(String brackets) { + char[] chars = brackets.toCharArray(); + int count = 0; + boolean open = false; + + for(int i=0; i 0) brackets = GenericSignatureParsingTest.countBrackets(type.substring(index)); + + type = buf.toString(); + buf.setLength(0); + + for (int i=0; i < brackets; i++) buf.append('['); + + boolean found = false; + + for(int i=Constants.T_BOOLEAN; (i <= Constants.T_VOID) && !found; i++) { + if (Constants.TYPE_NAMES[i].equals(type)) { + found = true; + buf.append(Constants.SHORT_TYPE_NAMES[i]); + } + } + + // Class name + if (!found) buf.append('L' + type.replace('.', '/') + ';'); + + return buf.toString(); + } + + + /** + * For some method signature (class file format) like '([Ljava/lang/String;)Z' this returns + * the string representing the return type its 'normal' form, e.g. 'boolean' + * + * @param signature Method signature + * @param chopit Shorten class names + * @return return type of method + */ + public static final String methodSignatureReturnType(String signature,boolean chopit) throws ClassFormatException { + int index; + String type; + try { + // Read return type after `)' + index = signature.lastIndexOf(')') + 1; + type = Utility.signatureToString(signature.substring(index), chopit); + } catch (StringIndexOutOfBoundsException e) { + throw new ClassFormatException("Invalid method signature: " + signature); + } + return type; + } + + + /** + * For some method signature (class file format) like '([Ljava/lang/String;)Z' this returns + * the string representing the return type its 'normal' form, e.g. 'boolean' + * + * @param signature Method signature + * @return return type of method + * @throws ClassFormatException + */ + public static final String methodSignatureReturnType(String signature) throws ClassFormatException { + return GenericSignatureParsingTest.methodSignatureReturnType(signature, true); + } + + + /** + * For some method signature (class file format) like '([Ljava/lang/String;Z)V' this returns an array + * of strings representing the arguments in their 'normal' form, e.g. '{java.lang.String[],boolean}' + * + * @param signature Method signature + * @param chopit Shorten class names + * @return Array of argument types + */ + public static final String[] methodSignatureArgumentTypes(String signature,boolean chopit) throws ClassFormatException { + ArrayList vec = new ArrayList(); + int index; + String[] types; + + try { // Read all declarations between for `(' and `)' + if (signature.charAt(0) != '(') + throw new ClassFormatException("Invalid method signature: " + signature); + + index = 1; // current string position + + while(signature.charAt(index) != ')') { + Utility.ResultHolder rh = Utility.signatureToStringInternal(signature.substring(index),chopit); + vec.add(rh.getResult()); + index += rh.getConsumedChars(); + } + } catch(StringIndexOutOfBoundsException e) { + throw new ClassFormatException("Invalid method signature: " + signature); + } + + types = new String[vec.size()]; + vec.toArray(types); + return types; + } + + + /** + * Converts string containing the method return and argument types + * to a byte code method signature. + * + * @param returnType Return type of method (e.g. "char" or "java.lang.String[]") + * @param methodArgs Types of method arguments + * @return Byte code representation of method signature + */ + public final static String methodTypeToSignature(String returnType, String[] methodArgs) throws ClassFormatException { + + StringBuffer buf = new StringBuffer("("); + + if (methodArgs != null) { + for (int i=0; i < methodArgs.length; i++) { + String str = GenericSignatureParsingTest.getSignature(methodArgs[i]); + + if (str.equals("V")) // void can't be a method argument + throw new ClassFormatException("Invalid type: " + methodArgs[i]); + + buf.append(str); + } + } + + buf.append(")" + GenericSignatureParsingTest.getSignature(returnType)); + + return buf.toString(); + } } diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java index 03b32e78f..1ba040ea0 100644 --- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java +++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java @@ -260,12 +260,12 @@ public class ParameterAnnotationsTest extends BcelTestCase { // attributes vanish ! clg = new ClassGen(jc2); mg = new MethodGen(m,clg.getClassName(),clg.getConstantPool()); - Attribute[] as = mg.getAttributes(); - assertTrue("Should be 2 (RIPA and RVPA) but there are "+mg.getAttributes().length,mg.getAttributes().length==2); + List as = mg.getAttributes(); + assertTrue("Should be 2 (RIPA and RVPA) but there are "+mg.getAttributes().size(),mg.getAttributes().size()==2); List l = mg.getAnnotationsOnParameter(0); assertTrue("Should be 2 annotations on first parameter but there is only "+l.size()+":"+l.toString(), l.size()==2); - assertTrue("Should be 0 but there are "+mg.getAttributes().length,mg.getAttributes().length==0); + assertTrue("Should be 0 but there are "+mg.getAttributes().size(),mg.getAttributes().size()==0); } diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleAnnotationAttributeTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleAnnotationAttributeTest.java index 1872aed0f..ac9023f22 100644 --- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleAnnotationAttributeTest.java +++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleAnnotationAttributeTest.java @@ -14,6 +14,7 @@ package org.aspectj.apache.bcel.classfile.tests; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -185,7 +186,7 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase { List l = ann.getValues(); assertTrue("Should be eight values for annotation 'ComplexAnnotation' but found "+l.size(), l.size()==8); - List names = Utility.getListOfAnnotationNames(ann); + List names = RuntimeVisibleAnnotationAttributeTest.getListOfAnnotationNames(ann); assertTrue("Cant find expected element ",names.contains("ival")); assertTrue("Cant find expected element ",names.contains("dval")); assertTrue("Cant find expected element ",names.contains("zval")); @@ -380,5 +381,15 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase { protected void tearDown() throws Exception { super.tearDown(); } + + public static List getListOfAnnotationNames(AnnotationGen a) { + List l = a.getValues(); + List names = new ArrayList(); + for (Iterator i = l.iterator(); i.hasNext();) { + ElementNameValuePairGen element = (ElementNameValuePairGen) i.next(); + names.add(element.getNameString()); + } + return names; + } } diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java index 1ed7e8381..8c9fb5024 100644 --- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java +++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java @@ -12,6 +12,7 @@ package org.aspectj.apache.bcel.classfile.tests; +import org.aspectj.apache.bcel.classfile.ClassFormatException; import org.aspectj.apache.bcel.classfile.Utility; import org.aspectj.apache.bcel.generic.Type; @@ -24,7 +25,7 @@ public class UtilTests extends TestCase { } public void testUtilityClassSignatureManipulation1() { - String[] ss = Utility.methodSignatureArgumentTypes("(Ljava/lang/String;I[Ljava/lang/Integer;)"); + String[] ss = UtilTests.methodSignatureArgumentTypes("(Ljava/lang/String;I[Ljava/lang/Integer;)"); assertTrue("should be 3 not "+ss.length,ss.length==3); assertTrue("first should be 'String', not "+ss[0],ss[0].equals("String")); @@ -53,6 +54,15 @@ public class UtilTests extends TestCase { protected void tearDown() throws Exception { super.tearDown(); } + + /** + * @param signature Method signature + * @return Array of argument types + * @throws ClassFormatException + */ + public static final String[] methodSignatureArgumentTypes(String signature) throws ClassFormatException { + return GenericSignatureParsingTest.methodSignatureArgumentTypes(signature, true); + } } diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/DescendingVisitor.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/DescendingVisitor.java similarity index 82% rename from bcel-builder/src/org/aspectj/apache/bcel/classfile/DescendingVisitor.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/DescendingVisitor.java index 87ec00fb1..9e16fb236 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/DescendingVisitor.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/DescendingVisitor.java @@ -1,401 +1,440 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.util.Stack; - -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; - -/** - * Traverses a JavaClass with another Visitor object 'piggy-backed' - * that is applied to all components of a JavaClass object. I.e. this - * class supplies the traversal strategy, other classes can make use - * of it. - * - * @version $Id: DescendingVisitor.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - */ -public class DescendingVisitor implements Visitor { - private JavaClass clazz; - private Visitor visitor; - private Stack stack = new Stack(); - - /** @return container of current entitity, i.e., predecessor during traversal - */ - public Object predecessor() { - return predecessor(0); - } - - /** - * @param level nesting level, i.e., 0 returns the direct predecessor - * @return container of current entitity, i.e., predecessor during traversal - */ - public Object predecessor(int level) { - int size = stack.size(); - - if((size < 2) || (level < 0)) - return null; - else - return stack.elementAt(size - (level + 2)); // size - 1 == current - } - - /** @return current object - */ - public Object current() { - return stack.peek(); - } - - /** - * @param clazz Class to traverse - * @param visitor visitor object to apply to all components - */ - public DescendingVisitor(JavaClass clazz, Visitor visitor) { - this.clazz = clazz; - this.visitor = visitor; - } - - /** - * Start traversal. - */ - public void visit() { clazz.accept(this); } - - public void visitJavaClass(JavaClass clazz) { - stack.push(clazz); - clazz.accept(visitor); - - Field[] fields = clazz.getFields(); - for(int i=0; i < fields.length; i++) - fields[i].accept(this); - - Method[] methods = clazz.getMethods(); - for(int i=0; i < methods.length; i++) - methods[i].accept(this); - - AttributeUtils.accept(clazz.getAttributes(),visitor); -// clazz.getAttributes().accept(this); - clazz.getConstantPool().accept(this); - stack.pop(); - } - - public void visitField(Field field) { - stack.push(field); - field.accept(visitor); - AttributeUtils.accept(field.getAttributes(),visitor); -// field.getAttributes().accept(this); - stack.pop(); - } - - public void visitConstantValue(ConstantValue cv) { - stack.push(cv); - cv.accept(visitor); - stack.pop(); - } - - public void visitMethod(Method method) { - stack.push(method); - method.accept(visitor); - AttributeUtils.accept(method.getAttributes(),visitor); - stack.pop(); - } - - public void visitExceptionTable(ExceptionTable table) { - stack.push(table); - table.accept(visitor); - stack.pop(); - } - - public void visitCode(Code code) { - stack.push(code); - code.accept(visitor); - - CodeException[] table = code.getExceptionTable(); - for(int i=0; i < table.length; i++) - table[i].accept(this); - - Attribute[] attributes = code.getAttributes(); - for(int i=0; i < attributes.length; i++) - attributes[i].accept(this); - stack.pop(); - } - - public void visitCodeException(CodeException ce) { - stack.push(ce); - ce.accept(visitor); - stack.pop(); - } - - public void visitLineNumberTable(LineNumberTable table) { - stack.push(table); - table.accept(visitor); - - LineNumber[] numbers = table.getLineNumberTable(); - for(int i=0; i < numbers.length; i++) - numbers[i].accept(this); - stack.pop(); - } - - public void visitLineNumber(LineNumber number) { - stack.push(number); - number.accept(visitor); - stack.pop(); - } - - public void visitLocalVariableTable(LocalVariableTable table) { - stack.push(table); - table.accept(visitor); - - LocalVariable[] vars = table.getLocalVariableTable(); - for(int i=0; i < vars.length; i++) - vars[i].accept(this); - stack.pop(); - } - - public void visitStackMap(StackMap table) { - stack.push(table); - table.accept(visitor); - - StackMapEntry[] vars = table.getStackMap(); - - for(int i=0; i < vars.length; i++) - vars[i].accept(this); - stack.pop(); - } - - public void visitStackMapEntry(StackMapEntry var) { - stack.push(var); - var.accept(visitor); - stack.pop(); - } - - public void visitLocalVariable(LocalVariable var) { - stack.push(var); - var.accept(visitor); - stack.pop(); - } - - public void visitConstantPool(ConstantPool cp) { - stack.push(cp); - cp.accept(visitor); - - Constant[] constants = cp.getConstantPool(); - for(int i=1; i < constants.length; i++) { - if(constants[i] != null) - constants[i].accept(this); - } - - stack.pop(); - } - - public void visitConstantClass(ConstantClass constant) { - stack.push(constant); - constant.accept(visitor); - stack.pop(); - } - - public void visitConstantDouble(ConstantDouble constant) { - stack.push(constant); - constant.accept(visitor); - stack.pop(); - } - - public void visitConstantFieldref(ConstantFieldref constant) { - stack.push(constant); - constant.accept(visitor); - stack.pop(); - } - - public void visitConstantFloat(ConstantFloat constant) { - stack.push(constant); - constant.accept(visitor); - stack.pop(); - } - - public void visitConstantInteger(ConstantInteger constant) { - stack.push(constant); - constant.accept(visitor); - stack.pop(); - } - - public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref constant) { - stack.push(constant); - constant.accept(visitor); - stack.pop(); - } - - public void visitConstantLong(ConstantLong constant) { - stack.push(constant); - constant.accept(visitor); - stack.pop(); - } - - public void visitConstantMethodref(ConstantMethodref constant) { - stack.push(constant); - constant.accept(visitor); - stack.pop(); - } - - public void visitConstantNameAndType(ConstantNameAndType constant) { - stack.push(constant); - constant.accept(visitor); - stack.pop(); - } - - public void visitConstantString(ConstantString constant) { - stack.push(constant); - constant.accept(visitor); - stack.pop(); - } - - public void visitConstantUtf8(ConstantUtf8 constant) { - stack.push(constant); - constant.accept(visitor); - stack.pop(); - } - - public void visitInnerClasses(InnerClasses ic) { - stack.push(ic); - ic.accept(visitor); - - InnerClass[] ics = ic.getInnerClasses(); - for(int i=0; i < ics.length; i++) - ics[i].accept(this); - stack.pop(); - } - - public void visitInnerClass(InnerClass inner) { - stack.push(inner); - inner.accept(visitor); - stack.pop(); - } - - public void visitDeprecated(Deprecated attribute) { - stack.push(attribute); - attribute.accept(visitor); - stack.pop(); - } - - public void visitSignature(Signature attribute) { - stack.push(attribute); - attribute.accept(visitor); - stack.pop(); - } - - // J5SUPPORT: - public void visitEnclosingMethod(EnclosingMethod attribute) { - stack.push(attribute); - attribute.accept(visitor); - stack.pop(); - } - - public void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations attribute) { - stack.push(attribute); - attribute.accept(visitor); - stack.pop(); - } - - public void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations attribute) { - stack.push(attribute); - attribute.accept(visitor); - stack.pop(); - } - - public void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations attribute) { - stack.push(attribute); - attribute.accept(visitor); - stack.pop(); - } - - public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations attribute) { - stack.push(attribute); - attribute.accept(visitor); - stack.pop(); - } - - public void visitAnnotationDefault(AnnotationDefault attribute) { - stack.push(attribute); - attribute.accept(visitor); - stack.pop(); - } - - public void visitLocalVariableTypeTable(LocalVariableTypeTable table) { - stack.push(table); - table.accept(visitor); - - LocalVariable[] vars = table.getLocalVariableTypeTable(); - for(int i=0; i < vars.length; i++) - vars[i].accept(this); - stack.pop(); - } - - public void visitSourceFile(SourceFile attribute) { - stack.push(attribute); - attribute.accept(visitor); - stack.pop(); - } - - public void visitSynthetic(Synthetic attribute) { - stack.push(attribute); - attribute.accept(visitor); - stack.pop(); - } - - public void visitUnknown(Unknown attribute) { - stack.push(attribute); - attribute.accept(visitor); - stack.pop(); - } -} +package org.aspectj.apache.bcel.verifier; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.util.Stack; + +import org.aspectj.apache.bcel.classfile.AnnotationDefault; +import org.aspectj.apache.bcel.classfile.Attribute; +import org.aspectj.apache.bcel.classfile.AttributeUtils; +import org.aspectj.apache.bcel.classfile.Code; +import org.aspectj.apache.bcel.classfile.CodeException; +import org.aspectj.apache.bcel.classfile.Constant; +import org.aspectj.apache.bcel.classfile.ConstantClass; +import org.aspectj.apache.bcel.classfile.ConstantDouble; +import org.aspectj.apache.bcel.classfile.ConstantFieldref; +import org.aspectj.apache.bcel.classfile.ConstantFloat; +import org.aspectj.apache.bcel.classfile.ConstantInteger; +import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref; +import org.aspectj.apache.bcel.classfile.ConstantLong; +import org.aspectj.apache.bcel.classfile.ConstantMethodref; +import org.aspectj.apache.bcel.classfile.ConstantNameAndType; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.classfile.ConstantString; +import org.aspectj.apache.bcel.classfile.ConstantUtf8; +import org.aspectj.apache.bcel.classfile.ConstantValue; +import org.aspectj.apache.bcel.classfile.Deprecated; +import org.aspectj.apache.bcel.classfile.EnclosingMethod; +import org.aspectj.apache.bcel.classfile.ExceptionTable; +import org.aspectj.apache.bcel.classfile.Field; +import org.aspectj.apache.bcel.classfile.InnerClass; +import org.aspectj.apache.bcel.classfile.InnerClasses; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.LineNumber; +import org.aspectj.apache.bcel.classfile.LineNumberTable; +import org.aspectj.apache.bcel.classfile.LocalVariable; +import org.aspectj.apache.bcel.classfile.LocalVariableTable; +import org.aspectj.apache.bcel.classfile.LocalVariableTypeTable; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.classfile.Signature; +import org.aspectj.apache.bcel.classfile.SourceFile; +import org.aspectj.apache.bcel.classfile.StackMap; +import org.aspectj.apache.bcel.classfile.StackMapEntry; +import org.aspectj.apache.bcel.classfile.Synthetic; +import org.aspectj.apache.bcel.classfile.Unknown; +import org.aspectj.apache.bcel.classfile.ClassVisitor; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; + +/** + * Traverses a JavaClass with another Visitor object 'piggy-backed' + * that is applied to all components of a JavaClass object. I.e. this + * class supplies the traversal strategy, other classes can make use + * of it. + * + * @version $Id: DescendingVisitor.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + */ +public class DescendingVisitor implements ClassVisitor { + private JavaClass clazz; + private ClassVisitor visitor; + private Stack stack = new Stack(); + + /** @return container of current entitity, i.e., predecessor during traversal + */ + public Object predecessor() { + return predecessor(0); + } + + /** + * @param level nesting level, i.e., 0 returns the direct predecessor + * @return container of current entitity, i.e., predecessor during traversal + */ + public Object predecessor(int level) { + int size = stack.size(); + + if((size < 2) || (level < 0)) + return null; + else + return stack.elementAt(size - (level + 2)); // size - 1 == current + } + + /** @return current object + */ + public Object current() { + return stack.peek(); + } + + /** + * @param clazz Class to traverse + * @param visitor visitor object to apply to all components + */ + public DescendingVisitor(JavaClass clazz, ClassVisitor visitor) { + this.clazz = clazz; + this.visitor = visitor; + } + + /** + * Start traversal. + */ + public void visit() { clazz.accept(this); } + + public void visitJavaClass(JavaClass clazz) { + stack.push(clazz); + clazz.accept(visitor); + + Field[] fields = clazz.getFields(); + for(int i=0; i < fields.length; i++) + fields[i].accept(this); + + Method[] methods = clazz.getMethods(); + for(int i=0; i < methods.length; i++) + methods[i].accept(this); + + AttributeUtils.accept(clazz.getAttributes(),visitor); +// clazz.getAttributes().accept(this); + clazz.getConstantPool().accept(this); + stack.pop(); + } + + public void visitField(Field field) { + stack.push(field); + field.accept(visitor); + AttributeUtils.accept(field.getAttributes(),visitor); +// field.getAttributes().accept(this); + stack.pop(); + } + + public void visitConstantValue(ConstantValue cv) { + stack.push(cv); + cv.accept(visitor); + stack.pop(); + } + + public void visitMethod(Method method) { + stack.push(method); + method.accept(visitor); + AttributeUtils.accept(method.getAttributes(),visitor); + stack.pop(); + } + + public void visitExceptionTable(ExceptionTable table) { + stack.push(table); + table.accept(visitor); + stack.pop(); + } + + public void visitCode(Code code) { + stack.push(code); + code.accept(visitor); + + CodeException[] table = code.getExceptionTable(); + for(int i=0; i < table.length; i++) + table[i].accept(this); + + Attribute[] attributes = code.getAttributes(); + for(int i=0; i < attributes.length; i++) + attributes[i].accept(this); + stack.pop(); + } + + public void visitCodeException(CodeException ce) { + stack.push(ce); + ce.accept(visitor); + stack.pop(); + } + + public void visitLineNumberTable(LineNumberTable table) { + stack.push(table); + table.accept(visitor); + + LineNumber[] numbers = table.getLineNumberTable(); + for(int i=0; i < numbers.length; i++) + numbers[i].accept(this); + stack.pop(); + } + + public void visitLineNumber(LineNumber number) { + stack.push(number); + number.accept(visitor); + stack.pop(); + } + + public void visitLocalVariableTable(LocalVariableTable table) { + stack.push(table); + table.accept(visitor); + + LocalVariable[] vars = table.getLocalVariableTable(); + for(int i=0; i < vars.length; i++) + vars[i].accept(this); + stack.pop(); + } + + public void visitStackMap(StackMap table) { + stack.push(table); + table.accept(visitor); + + StackMapEntry[] vars = table.getStackMap(); + + for(int i=0; i < vars.length; i++) + vars[i].accept(this); + stack.pop(); + } + + public void visitStackMapEntry(StackMapEntry var) { + stack.push(var); + var.accept(visitor); + stack.pop(); + } + + public void visitLocalVariable(LocalVariable var) { + stack.push(var); + var.accept(visitor); + stack.pop(); + } + + public void visitConstantPool(ConstantPool cp) { + stack.push(cp); + cp.accept(visitor); + + Constant[] constants = cp.getConstantPool(); + for(int i=1; i < constants.length; i++) { + if(constants[i] != null) + constants[i].accept(this); + } + + stack.pop(); + } + + public void visitConstantClass(ConstantClass constant) { + stack.push(constant); + constant.accept(visitor); + stack.pop(); + } + + public void visitConstantDouble(ConstantDouble constant) { + stack.push(constant); + constant.accept(visitor); + stack.pop(); + } + + public void visitConstantFieldref(ConstantFieldref constant) { + stack.push(constant); + constant.accept(visitor); + stack.pop(); + } + + public void visitConstantFloat(ConstantFloat constant) { + stack.push(constant); + constant.accept(visitor); + stack.pop(); + } + + public void visitConstantInteger(ConstantInteger constant) { + stack.push(constant); + constant.accept(visitor); + stack.pop(); + } + + public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref constant) { + stack.push(constant); + constant.accept(visitor); + stack.pop(); + } + + public void visitConstantLong(ConstantLong constant) { + stack.push(constant); + constant.accept(visitor); + stack.pop(); + } + + public void visitConstantMethodref(ConstantMethodref constant) { + stack.push(constant); + constant.accept(visitor); + stack.pop(); + } + + public void visitConstantNameAndType(ConstantNameAndType constant) { + stack.push(constant); + constant.accept(visitor); + stack.pop(); + } + + public void visitConstantString(ConstantString constant) { + stack.push(constant); + constant.accept(visitor); + stack.pop(); + } + + public void visitConstantUtf8(ConstantUtf8 constant) { + stack.push(constant); + constant.accept(visitor); + stack.pop(); + } + + public void visitInnerClasses(InnerClasses ic) { + stack.push(ic); + ic.accept(visitor); + + InnerClass[] ics = ic.getInnerClasses(); + for(int i=0; i < ics.length; i++) + ics[i].accept(this); + stack.pop(); + } + + public void visitInnerClass(InnerClass inner) { + stack.push(inner); + inner.accept(visitor); + stack.pop(); + } + + public void visitDeprecated(Deprecated attribute) { + stack.push(attribute); + attribute.accept(visitor); + stack.pop(); + } + + public void visitSignature(Signature attribute) { + stack.push(attribute); + attribute.accept(visitor); + stack.pop(); + } + + // J5SUPPORT: + public void visitEnclosingMethod(EnclosingMethod attribute) { + stack.push(attribute); + attribute.accept(visitor); + stack.pop(); + } + + public void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations attribute) { + stack.push(attribute); + attribute.accept(visitor); + stack.pop(); + } + + public void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations attribute) { + stack.push(attribute); + attribute.accept(visitor); + stack.pop(); + } + + public void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations attribute) { + stack.push(attribute); + attribute.accept(visitor); + stack.pop(); + } + + public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations attribute) { + stack.push(attribute); + attribute.accept(visitor); + stack.pop(); + } + + public void visitAnnotationDefault(AnnotationDefault attribute) { + stack.push(attribute); + attribute.accept(visitor); + stack.pop(); + } + + public void visitLocalVariableTypeTable(LocalVariableTypeTable table) { + stack.push(table); + table.accept(visitor); + + LocalVariable[] vars = table.getLocalVariableTypeTable(); + for(int i=0; i < vars.length; i++) + vars[i].accept(this); + stack.pop(); + } + + public void visitSourceFile(SourceFile attribute) { + stack.push(attribute); + attribute.accept(visitor); + stack.pop(); + } + + public void visitSynthetic(Synthetic attribute) { + stack.push(attribute); + attribute.accept(visitor); + stack.pop(); + } + + public void visitUnknown(Unknown attribute) { + stack.push(attribute); + attribute.accept(visitor); + stack.pop(); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/EmptyVisitor.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/EmptyClassVisitor.java similarity index 71% rename from bcel-builder/src/org/aspectj/apache/bcel/classfile/EmptyVisitor.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/EmptyClassVisitor.java index 491c061c1..c72e157ae 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/EmptyVisitor.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/EmptyClassVisitor.java @@ -1,118 +1,154 @@ -package org.aspectj.apache.bcel.classfile; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; - -/** - * Visitor with empty method bodies, can be extended and used in conjunction with the - * DescendingVisitor class, e.g. - * - * By courtesy of David Spencer. - * - * @see DescendingVisitor - * @version $Id: EmptyVisitor.java,v 1.3.10.1 2008/04/25 17:55:36 aclement Exp $ - * - */ -public class EmptyVisitor implements Visitor { - protected EmptyVisitor() { } - - public void visitCode(Code obj) {} - public void visitCodeException(CodeException obj) {} - public void visitConstantClass(ConstantClass obj) {} - public void visitConstantDouble(ConstantDouble obj) {} - public void visitConstantFieldref(ConstantFieldref obj) {} - public void visitConstantFloat(ConstantFloat obj) {} - public void visitConstantInteger(ConstantInteger obj) {} - public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj) {} - public void visitConstantLong(ConstantLong obj) {} - public void visitConstantMethodref(ConstantMethodref obj) {} - public void visitConstantNameAndType(ConstantNameAndType obj) {} - public void visitConstantPool(ConstantPool obj) {} - public void visitConstantString(ConstantString obj) {} - public void visitConstantUtf8(ConstantUtf8 obj) {} - public void visitConstantValue(ConstantValue obj) {} - public void visitDeprecated(Deprecated obj) {} - public void visitExceptionTable(ExceptionTable obj) {} - public void visitField(Field obj) {} - public void visitInnerClass(InnerClass obj) {} - public void visitInnerClasses(InnerClasses obj) {} - public void visitJavaClass(JavaClass obj) {} - public void visitLineNumber(LineNumber obj) {} - public void visitLineNumberTable(LineNumberTable obj) {} - public void visitLocalVariable(LocalVariable obj) {} - public void visitLocalVariableTable(LocalVariableTable obj) {} - public void visitMethod(Method obj) {} - public void visitSignature(Signature obj) {} - public void visitSourceFile(SourceFile obj) {} - public void visitSynthetic(Synthetic obj) {} - public void visitUnknown(Unknown obj) {} - public void visitStackMap(StackMap obj) {} - public void visitStackMapEntry(StackMapEntry obj) {} - - // J5SUPPORT: - public void visitEnclosingMethod(EnclosingMethod obj) {} - public void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations attribute) {} - public void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations attribute) {} - public void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations attribute) {} - public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations attribute) {} - public void visitAnnotationDefault(AnnotationDefault attribute) {} - public void visitLocalVariableTypeTable(LocalVariableTypeTable obj) {} - - -} +package org.aspectj.apache.bcel.verifier; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.classfile.AnnotationDefault; +import org.aspectj.apache.bcel.classfile.Code; +import org.aspectj.apache.bcel.classfile.CodeException; +import org.aspectj.apache.bcel.classfile.ConstantClass; +import org.aspectj.apache.bcel.classfile.ConstantDouble; +import org.aspectj.apache.bcel.classfile.ConstantFieldref; +import org.aspectj.apache.bcel.classfile.ConstantFloat; +import org.aspectj.apache.bcel.classfile.ConstantInteger; +import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref; +import org.aspectj.apache.bcel.classfile.ConstantLong; +import org.aspectj.apache.bcel.classfile.ConstantMethodref; +import org.aspectj.apache.bcel.classfile.ConstantNameAndType; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.classfile.ConstantString; +import org.aspectj.apache.bcel.classfile.ConstantUtf8; +import org.aspectj.apache.bcel.classfile.ConstantValue; +import org.aspectj.apache.bcel.classfile.Deprecated; +import org.aspectj.apache.bcel.classfile.EnclosingMethod; +import org.aspectj.apache.bcel.classfile.ExceptionTable; +import org.aspectj.apache.bcel.classfile.Field; +import org.aspectj.apache.bcel.classfile.InnerClass; +import org.aspectj.apache.bcel.classfile.InnerClasses; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.LineNumber; +import org.aspectj.apache.bcel.classfile.LineNumberTable; +import org.aspectj.apache.bcel.classfile.LocalVariable; +import org.aspectj.apache.bcel.classfile.LocalVariableTable; +import org.aspectj.apache.bcel.classfile.LocalVariableTypeTable; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.classfile.Signature; +import org.aspectj.apache.bcel.classfile.SourceFile; +import org.aspectj.apache.bcel.classfile.StackMap; +import org.aspectj.apache.bcel.classfile.StackMapEntry; +import org.aspectj.apache.bcel.classfile.Synthetic; +import org.aspectj.apache.bcel.classfile.Unknown; +import org.aspectj.apache.bcel.classfile.ClassVisitor; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; + +/** + * Visitor with empty method bodies, can be extended and used in conjunction with the + * DescendingVisitor class, e.g. + * + * By courtesy of David Spencer. + * + * @see DescendingVisitor + * @version $Id: EmptyClassVisitor.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * + */ +public class EmptyClassVisitor implements ClassVisitor { + protected EmptyClassVisitor() { } + + public void visitCode(Code obj) {} + public void visitCodeException(CodeException obj) {} + public void visitConstantClass(ConstantClass obj) {} + public void visitConstantDouble(ConstantDouble obj) {} + public void visitConstantFieldref(ConstantFieldref obj) {} + public void visitConstantFloat(ConstantFloat obj) {} + public void visitConstantInteger(ConstantInteger obj) {} + public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj) {} + public void visitConstantLong(ConstantLong obj) {} + public void visitConstantMethodref(ConstantMethodref obj) {} + public void visitConstantNameAndType(ConstantNameAndType obj) {} + public void visitConstantPool(ConstantPool obj) {} + public void visitConstantString(ConstantString obj) {} + public void visitConstantUtf8(ConstantUtf8 obj) {} + public void visitConstantValue(ConstantValue obj) {} + public void visitDeprecated(Deprecated obj) {} + public void visitExceptionTable(ExceptionTable obj) {} + public void visitField(Field obj) {} + public void visitInnerClass(InnerClass obj) {} + public void visitInnerClasses(InnerClasses obj) {} + public void visitJavaClass(JavaClass obj) {} + public void visitLineNumber(LineNumber obj) {} + public void visitLineNumberTable(LineNumberTable obj) {} + public void visitLocalVariable(LocalVariable obj) {} + public void visitLocalVariableTable(LocalVariableTable obj) {} + public void visitMethod(Method obj) {} + public void visitSignature(Signature obj) {} + public void visitSourceFile(SourceFile obj) {} + public void visitSynthetic(Synthetic obj) {} + public void visitUnknown(Unknown obj) {} + public void visitStackMap(StackMap obj) {} + public void visitStackMapEntry(StackMapEntry obj) {} + + // J5SUPPORT: + public void visitEnclosingMethod(EnclosingMethod obj) {} + public void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations attribute) {} + public void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations attribute) {} + public void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations attribute) {} + public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations attribute) {} + public void visitAnnotationDefault(AnnotationDefault attribute) {} + public void visitLocalVariableTypeTable(LocalVariableTypeTable obj) {} + + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/EmptyVisitor.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/EmptyInstVisitor.java similarity index 92% rename from bcel-builder/src/org/aspectj/apache/bcel/generic/EmptyVisitor.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/EmptyInstVisitor.java index ab4c262f0..0a4de3ce3 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/EmptyVisitor.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/EmptyInstVisitor.java @@ -1,245 +1,259 @@ -package org.aspectj.apache.bcel.generic; - - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Supplies empty method bodies to be overridden by subclasses. - * - * @version $Id: EmptyVisitor.java,v 1.2.10.2 2008/04/25 17:55:32 aclement Exp $ - * @author M. Dahm - */ -public abstract class EmptyVisitor implements Visitor { - public void visitStackInstruction(Instruction obj) { } - public void visitLocalVariableInstruction(InstructionLV obj) { } - public void visitBranchInstruction(InstructionBranch obj) { } - public void visitLoadClass(Instruction obj) { } - public void visitFieldInstruction(Instruction obj) { } - public void visitIfInstruction(Instruction obj) { } - public void visitConversionInstruction(Instruction obj) { } - public void visitPopInstruction(Instruction obj) { } - public void visitJsrInstruction(InstructionBranch obj) { } - public void visitGotoInstruction(Instruction obj) { } - public void visitStoreInstruction(Instruction obj) { } - public void visitTypedInstruction(Instruction obj) { } - public void visitSelect(InstructionSelect obj) { } - public void visitUnconditionalBranch(Instruction obj) { } - public void visitPushInstruction(Instruction obj) { } - public void visitArithmeticInstruction(Instruction obj) { } - public void visitCPInstruction(Instruction obj) { } - public void visitInvokeInstruction(InvokeInstruction obj) { } - public void visitArrayInstruction(Instruction obj) { } - public void visitAllocationInstruction(Instruction obj) { } - public void visitReturnInstruction(Instruction obj) { } - public void visitFieldOrMethod(Instruction obj) { } - public void visitConstantPushInstruction(Instruction obj) { } - public void visitExceptionThrower(Instruction obj) { } - public void visitLoadInstruction(Instruction obj) { } - public void visitVariableLengthInstruction(Instruction obj) { } - public void visitStackProducer(Instruction obj) { } - public void visitStackConsumer(Instruction obj) { } - public void visitACONST_NULL(Instruction obj) { } - public void visitGETSTATIC(FieldInstruction obj) { } - public void visitIF_ICMPLT(Instruction obj) { } - public void visitMONITOREXIT(Instruction obj) { } - public void visitIFLT(Instruction obj) { } - public void visitLSTORE(Instruction obj) { } - public void visitPOP2(Instruction obj) { } - public void visitBASTORE(Instruction obj) { } - public void visitISTORE(Instruction obj) { } - public void visitCHECKCAST(Instruction obj) { } - public void visitFCMPG(Instruction obj) { } - public void visitI2F(Instruction obj) { } - public void visitATHROW(Instruction obj) { } - public void visitDCMPL(Instruction obj) { } - public void visitARRAYLENGTH(Instruction obj) { } - public void visitDUP(Instruction obj) { } - public void visitINVOKESTATIC(InvokeInstruction obj) { } - public void visitLCONST(Instruction obj) { } - public void visitDREM(Instruction obj) { } - public void visitIFGE(Instruction obj) { } - public void visitCALOAD(Instruction obj) { } - public void visitLASTORE(Instruction obj) { } - public void visitI2D(Instruction obj) { } - public void visitDADD(Instruction obj) { } - public void visitINVOKESPECIAL(InvokeInstruction obj) { } - public void visitIAND(Instruction obj) { } - public void visitPUTFIELD(FieldInstruction obj) { } - public void visitILOAD(Instruction obj) { } - public void visitDLOAD(Instruction obj) { } - public void visitDCONST(Instruction obj) { } - public void visitNEW(Instruction obj) { } - public void visitIFNULL(Instruction obj) { } - public void visitLSUB(Instruction obj) { } - public void visitL2I(Instruction obj) { } - public void visitISHR(Instruction obj) { } - public void visitTABLESWITCH(TABLESWITCH obj) { } - public void visitIINC(IINC obj) { } - public void visitDRETURN(Instruction obj) { } - public void visitFSTORE(Instruction obj) { } - public void visitDASTORE(Instruction obj) { } - public void visitIALOAD(Instruction obj) { } - public void visitDDIV(Instruction obj) { } - public void visitIF_ICMPGE(Instruction obj) { } - public void visitLAND(Instruction obj) { } - public void visitIDIV(Instruction obj) { } - public void visitLOR(Instruction obj) { } - public void visitCASTORE(Instruction obj) { } - public void visitFREM(Instruction obj) { } - public void visitLDC(Instruction obj) { } - public void visitBIPUSH(Instruction obj) { } - public void visitDSTORE(Instruction obj) { } - public void visitF2L(Instruction obj) { } - public void visitFMUL(Instruction obj) { } - public void visitLLOAD(Instruction obj) { } - public void visitJSR(InstructionBranch obj) { } - public void visitFSUB(Instruction obj) { } - public void visitSASTORE(Instruction obj) { } - public void visitALOAD(Instruction obj) { } - public void visitDUP2_X2(Instruction obj) { } - public void visitRETURN(Instruction obj) { } - public void visitDALOAD(Instruction obj) { } - public void visitSIPUSH(Instruction obj) { } - public void visitDSUB(Instruction obj) { } - public void visitL2F(Instruction obj) { } - public void visitIF_ICMPGT(Instruction obj) { } - public void visitF2D(Instruction obj) { } - public void visitI2L(Instruction obj) { } - public void visitIF_ACMPNE(Instruction obj) { } - public void visitPOP(Instruction obj) { } - public void visitI2S(Instruction obj) { } - public void visitIFEQ(Instruction obj) { } - public void visitSWAP(Instruction obj) { } - public void visitIOR(Instruction obj) { } - public void visitIREM(Instruction obj) { } - public void visitIASTORE(Instruction obj) { } - public void visitNEWARRAY(Instruction obj) { } - public void visitINVOKEINTERFACE(INVOKEINTERFACE obj) { } - public void visitINEG(Instruction obj) { } - public void visitLCMP(Instruction obj) { } - public void visitJSR_W(InstructionBranch obj) { } - public void visitMULTIANEWARRAY(MULTIANEWARRAY obj) { } - public void visitDUP_X2(Instruction obj) { } - public void visitSALOAD(Instruction obj) { } - public void visitIFNONNULL(Instruction obj) { } - public void visitDMUL(Instruction obj) { } - public void visitIFNE(Instruction obj) { } - public void visitIF_ICMPLE(Instruction obj) { } - public void visitLDC2_W(Instruction obj) { } - public void visitGETFIELD(FieldInstruction obj) { } - public void visitLADD(Instruction obj) { } - public void visitNOP(Instruction obj) { } - public void visitFALOAD(Instruction obj) { } - public void visitINSTANCEOF(Instruction obj) { } - public void visitIFLE(Instruction obj) { } - public void visitLXOR(Instruction obj) { } - public void visitLRETURN(Instruction obj) { } - public void visitFCONST(Instruction obj) { } - public void visitIUSHR(Instruction obj) { } - public void visitBALOAD(Instruction obj) { } - public void visitDUP2(Instruction obj) { } - public void visitIF_ACMPEQ(Instruction obj) { } - public void visitIMPDEP1(Instruction obj) { } - public void visitMONITORENTER(Instruction obj) { } - public void visitLSHL(Instruction obj) { } - public void visitDCMPG(Instruction obj) { } - public void visitD2L(Instruction obj) { } - public void visitIMPDEP2(Instruction obj) { } - public void visitL2D(Instruction obj) { } - public void visitRET(RET obj) { } - public void visitIFGT(Instruction obj) { } - public void visitIXOR(Instruction obj) { } - public void visitINVOKEVIRTUAL(InvokeInstruction obj) { } - public void visitFASTORE(Instruction obj) { } - public void visitIRETURN(Instruction obj) { } - public void visitIF_ICMPNE(Instruction obj) { } - public void visitFLOAD(Instruction obj) { } - public void visitLDIV(Instruction obj) { } - public void visitPUTSTATIC(FieldInstruction obj) { } - public void visitAALOAD(Instruction obj) { } - public void visitD2I(Instruction obj) { } - public void visitIF_ICMPEQ(Instruction obj) { } - public void visitAASTORE(Instruction obj) { } - public void visitARETURN(Instruction obj) { } - public void visitDUP2_X1(Instruction obj) { } - public void visitFNEG(Instruction obj) { } - public void visitGOTO_W(Instruction obj) { } - public void visitD2F(Instruction obj) { } - public void visitGOTO(Instruction obj) { } - public void visitISUB(Instruction obj) { } - public void visitF2I(Instruction obj) { } - public void visitDNEG(Instruction obj) { } - public void visitICONST(Instruction obj) { } - public void visitFDIV(Instruction obj) { } - public void visitI2B(Instruction obj) { } - public void visitLNEG(Instruction obj) { } - public void visitLREM(Instruction obj) { } - public void visitIMUL(Instruction obj) { } - public void visitIADD(Instruction obj) { } - public void visitLSHR(Instruction obj) { } - public void visitLOOKUPSWITCH(LOOKUPSWITCH obj) { } - public void visitDUP_X1(Instruction obj) { } - public void visitFCMPL(Instruction obj) { } - public void visitI2C(Instruction obj) { } - public void visitLMUL(Instruction obj) { } - public void visitLUSHR(Instruction obj) { } - public void visitISHL(Instruction obj) { } - public void visitLALOAD(Instruction obj) { } - public void visitASTORE(Instruction obj) { } - public void visitANEWARRAY(Instruction obj) { } - public void visitFRETURN(Instruction obj) { } - public void visitFADD(Instruction obj) { } - public void visitBREAKPOINT(Instruction obj) { } -} +package org.aspectj.apache.bcel.verifier; + +import org.aspectj.apache.bcel.generic.FieldInstruction; +import org.aspectj.apache.bcel.generic.IINC; +import org.aspectj.apache.bcel.generic.INVOKEINTERFACE; +import org.aspectj.apache.bcel.generic.InstVisitor; +import org.aspectj.apache.bcel.generic.Instruction; +import org.aspectj.apache.bcel.generic.InstructionBranch; +import org.aspectj.apache.bcel.generic.InstructionLV; +import org.aspectj.apache.bcel.generic.InstructionSelect; +import org.aspectj.apache.bcel.generic.InvokeInstruction; +import org.aspectj.apache.bcel.generic.LOOKUPSWITCH; +import org.aspectj.apache.bcel.generic.MULTIANEWARRAY; +import org.aspectj.apache.bcel.generic.RET; +import org.aspectj.apache.bcel.generic.TABLESWITCH; + + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Supplies empty method bodies to be overridden by subclasses. + * + * @version $Id: EmptyInstVisitor.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author M. Dahm + */ +public abstract class EmptyInstVisitor implements InstVisitor { + public void visitStackInstruction(Instruction obj) { } + public void visitLocalVariableInstruction(InstructionLV obj) { } + public void visitBranchInstruction(InstructionBranch obj) { } + public void visitLoadClass(Instruction obj) { } + public void visitFieldInstruction(Instruction obj) { } + public void visitIfInstruction(Instruction obj) { } + public void visitConversionInstruction(Instruction obj) { } + public void visitPopInstruction(Instruction obj) { } + public void visitJsrInstruction(InstructionBranch obj) { } + public void visitGotoInstruction(Instruction obj) { } + public void visitStoreInstruction(Instruction obj) { } + public void visitTypedInstruction(Instruction obj) { } + public void visitSelect(InstructionSelect obj) { } + public void visitUnconditionalBranch(Instruction obj) { } + public void visitPushInstruction(Instruction obj) { } + public void visitArithmeticInstruction(Instruction obj) { } + public void visitCPInstruction(Instruction obj) { } + public void visitInvokeInstruction(InvokeInstruction obj) { } + public void visitArrayInstruction(Instruction obj) { } + public void visitAllocationInstruction(Instruction obj) { } + public void visitReturnInstruction(Instruction obj) { } + public void visitFieldOrMethod(Instruction obj) { } + public void visitConstantPushInstruction(Instruction obj) { } + public void visitExceptionThrower(Instruction obj) { } + public void visitLoadInstruction(Instruction obj) { } + public void visitVariableLengthInstruction(Instruction obj) { } + public void visitStackProducer(Instruction obj) { } + public void visitStackConsumer(Instruction obj) { } + public void visitACONST_NULL(Instruction obj) { } + public void visitGETSTATIC(FieldInstruction obj) { } + public void visitIF_ICMPLT(Instruction obj) { } + public void visitMONITOREXIT(Instruction obj) { } + public void visitIFLT(Instruction obj) { } + public void visitLSTORE(Instruction obj) { } + public void visitPOP2(Instruction obj) { } + public void visitBASTORE(Instruction obj) { } + public void visitISTORE(Instruction obj) { } + public void visitCHECKCAST(Instruction obj) { } + public void visitFCMPG(Instruction obj) { } + public void visitI2F(Instruction obj) { } + public void visitATHROW(Instruction obj) { } + public void visitDCMPL(Instruction obj) { } + public void visitARRAYLENGTH(Instruction obj) { } + public void visitDUP(Instruction obj) { } + public void visitINVOKESTATIC(InvokeInstruction obj) { } + public void visitLCONST(Instruction obj) { } + public void visitDREM(Instruction obj) { } + public void visitIFGE(Instruction obj) { } + public void visitCALOAD(Instruction obj) { } + public void visitLASTORE(Instruction obj) { } + public void visitI2D(Instruction obj) { } + public void visitDADD(Instruction obj) { } + public void visitINVOKESPECIAL(InvokeInstruction obj) { } + public void visitIAND(Instruction obj) { } + public void visitPUTFIELD(FieldInstruction obj) { } + public void visitILOAD(Instruction obj) { } + public void visitDLOAD(Instruction obj) { } + public void visitDCONST(Instruction obj) { } + public void visitNEW(Instruction obj) { } + public void visitIFNULL(Instruction obj) { } + public void visitLSUB(Instruction obj) { } + public void visitL2I(Instruction obj) { } + public void visitISHR(Instruction obj) { } + public void visitTABLESWITCH(TABLESWITCH obj) { } + public void visitIINC(IINC obj) { } + public void visitDRETURN(Instruction obj) { } + public void visitFSTORE(Instruction obj) { } + public void visitDASTORE(Instruction obj) { } + public void visitIALOAD(Instruction obj) { } + public void visitDDIV(Instruction obj) { } + public void visitIF_ICMPGE(Instruction obj) { } + public void visitLAND(Instruction obj) { } + public void visitIDIV(Instruction obj) { } + public void visitLOR(Instruction obj) { } + public void visitCASTORE(Instruction obj) { } + public void visitFREM(Instruction obj) { } + public void visitLDC(Instruction obj) { } + public void visitBIPUSH(Instruction obj) { } + public void visitDSTORE(Instruction obj) { } + public void visitF2L(Instruction obj) { } + public void visitFMUL(Instruction obj) { } + public void visitLLOAD(Instruction obj) { } + public void visitJSR(InstructionBranch obj) { } + public void visitFSUB(Instruction obj) { } + public void visitSASTORE(Instruction obj) { } + public void visitALOAD(Instruction obj) { } + public void visitDUP2_X2(Instruction obj) { } + public void visitRETURN(Instruction obj) { } + public void visitDALOAD(Instruction obj) { } + public void visitSIPUSH(Instruction obj) { } + public void visitDSUB(Instruction obj) { } + public void visitL2F(Instruction obj) { } + public void visitIF_ICMPGT(Instruction obj) { } + public void visitF2D(Instruction obj) { } + public void visitI2L(Instruction obj) { } + public void visitIF_ACMPNE(Instruction obj) { } + public void visitPOP(Instruction obj) { } + public void visitI2S(Instruction obj) { } + public void visitIFEQ(Instruction obj) { } + public void visitSWAP(Instruction obj) { } + public void visitIOR(Instruction obj) { } + public void visitIREM(Instruction obj) { } + public void visitIASTORE(Instruction obj) { } + public void visitNEWARRAY(Instruction obj) { } + public void visitINVOKEINTERFACE(INVOKEINTERFACE obj) { } + public void visitINEG(Instruction obj) { } + public void visitLCMP(Instruction obj) { } + public void visitJSR_W(InstructionBranch obj) { } + public void visitMULTIANEWARRAY(MULTIANEWARRAY obj) { } + public void visitDUP_X2(Instruction obj) { } + public void visitSALOAD(Instruction obj) { } + public void visitIFNONNULL(Instruction obj) { } + public void visitDMUL(Instruction obj) { } + public void visitIFNE(Instruction obj) { } + public void visitIF_ICMPLE(Instruction obj) { } + public void visitLDC2_W(Instruction obj) { } + public void visitGETFIELD(FieldInstruction obj) { } + public void visitLADD(Instruction obj) { } + public void visitNOP(Instruction obj) { } + public void visitFALOAD(Instruction obj) { } + public void visitINSTANCEOF(Instruction obj) { } + public void visitIFLE(Instruction obj) { } + public void visitLXOR(Instruction obj) { } + public void visitLRETURN(Instruction obj) { } + public void visitFCONST(Instruction obj) { } + public void visitIUSHR(Instruction obj) { } + public void visitBALOAD(Instruction obj) { } + public void visitDUP2(Instruction obj) { } + public void visitIF_ACMPEQ(Instruction obj) { } + public void visitIMPDEP1(Instruction obj) { } + public void visitMONITORENTER(Instruction obj) { } + public void visitLSHL(Instruction obj) { } + public void visitDCMPG(Instruction obj) { } + public void visitD2L(Instruction obj) { } + public void visitIMPDEP2(Instruction obj) { } + public void visitL2D(Instruction obj) { } + public void visitRET(RET obj) { } + public void visitIFGT(Instruction obj) { } + public void visitIXOR(Instruction obj) { } + public void visitINVOKEVIRTUAL(InvokeInstruction obj) { } + public void visitFASTORE(Instruction obj) { } + public void visitIRETURN(Instruction obj) { } + public void visitIF_ICMPNE(Instruction obj) { } + public void visitFLOAD(Instruction obj) { } + public void visitLDIV(Instruction obj) { } + public void visitPUTSTATIC(FieldInstruction obj) { } + public void visitAALOAD(Instruction obj) { } + public void visitD2I(Instruction obj) { } + public void visitIF_ICMPEQ(Instruction obj) { } + public void visitAASTORE(Instruction obj) { } + public void visitARETURN(Instruction obj) { } + public void visitDUP2_X1(Instruction obj) { } + public void visitFNEG(Instruction obj) { } + public void visitGOTO_W(Instruction obj) { } + public void visitD2F(Instruction obj) { } + public void visitGOTO(Instruction obj) { } + public void visitISUB(Instruction obj) { } + public void visitF2I(Instruction obj) { } + public void visitDNEG(Instruction obj) { } + public void visitICONST(Instruction obj) { } + public void visitFDIV(Instruction obj) { } + public void visitI2B(Instruction obj) { } + public void visitLNEG(Instruction obj) { } + public void visitLREM(Instruction obj) { } + public void visitIMUL(Instruction obj) { } + public void visitIADD(Instruction obj) { } + public void visitLSHR(Instruction obj) { } + public void visitLOOKUPSWITCH(LOOKUPSWITCH obj) { } + public void visitDUP_X1(Instruction obj) { } + public void visitFCMPL(Instruction obj) { } + public void visitI2C(Instruction obj) { } + public void visitLMUL(Instruction obj) { } + public void visitLUSHR(Instruction obj) { } + public void visitISHL(Instruction obj) { } + public void visitLALOAD(Instruction obj) { } + public void visitASTORE(Instruction obj) { } + public void visitANEWARRAY(Instruction obj) { } + public void visitFRETURN(Instruction obj) { } + public void visitFADD(Instruction obj) { } + public void visitBREAKPOINT(Instruction obj) { } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/GraphicalVerifier.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/GraphicalVerifier.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/GraphicalVerifier.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/GraphicalVerifier.java index 5b7b3f49b..d7c75a904 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/GraphicalVerifier.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/GraphicalVerifier.java @@ -1,111 +1,111 @@ -package org.aspectj.apache.bcel.verifier; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.awt.Dimension; -import java.awt.Toolkit; - -import javax.swing.UIManager; - -import org.aspectj.apache.bcel.generic.Type; - - -/** - * A graphical user interface application demonstrating JustIce. - * - * @version $Id: GraphicalVerifier.java,v 1.4.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author Enver Haase - */ -public class GraphicalVerifier { - boolean packFrame = false; - - /** Constructor. */ - public GraphicalVerifier() { - VerifierAppFrame frame = new VerifierAppFrame(); - //Frames überprüfen, die voreingestellte Größe haben - //Frames packen, die nutzbare bevorzugte Größeninformationen enthalten, z.B. aus ihrem Layout - if (packFrame) { - frame.pack(); - } - else { - frame.validate(); - } - //Das Fenster zentrieren - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - Dimension frameSize = frame.getSize(); - if (frameSize.height > screenSize.height) { - frameSize.height = screenSize.height; - } - if (frameSize.width > screenSize.width) { - frameSize.width = screenSize.width; - } - frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); - frame.setVisible(true); - - frame.classNamesJList.setModel(new VerifierFactoryListModel()); - VerifierFactory.getVerifier(Type.OBJECT.getClassName()); // Fill list with java.lang.Object - frame.classNamesJList.setSelectedIndex(0); // default, will verify java.lang.Object - } - /** Main method. */ - public static void main(String[] args) { - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } - catch(Exception e) { - e.printStackTrace(); - } - new GraphicalVerifier(); - } -} +package org.aspectj.apache.bcel.verifier; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.awt.Dimension; +import java.awt.Toolkit; + +import javax.swing.UIManager; + +import org.aspectj.apache.bcel.generic.Type; + + +/** + * A graphical user interface application demonstrating JustIce. + * + * @version $Id: GraphicalVerifier.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author Enver Haase + */ +public class GraphicalVerifier { + boolean packFrame = false; + + /** Constructor. */ + public GraphicalVerifier() { + VerifierAppFrame frame = new VerifierAppFrame(); + //Frames überprüfen, die voreingestellte Größe haben + //Frames packen, die nutzbare bevorzugte Größeninformationen enthalten, z.B. aus ihrem Layout + if (packFrame) { + frame.pack(); + } + else { + frame.validate(); + } + //Das Fenster zentrieren + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + Dimension frameSize = frame.getSize(); + if (frameSize.height > screenSize.height) { + frameSize.height = screenSize.height; + } + if (frameSize.width > screenSize.width) { + frameSize.width = screenSize.width; + } + frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); + frame.setVisible(true); + + frame.classNamesJList.setModel(new VerifierFactoryListModel()); + VerifierFactory.getVerifier(Type.OBJECT.getClassName()); // Fill list with java.lang.Object + frame.classNamesJList.setSelectedIndex(0); // default, will verify java.lang.Object + } + /** Main method. */ + public static void main(String[] args) { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } + catch(Exception e) { + e.printStackTrace(); + } + new GraphicalVerifier(); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/NativeVerifier.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/NativeVerifier.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/NativeVerifier.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/NativeVerifier.java index 47038cbcd..6dac24510 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/NativeVerifier.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/NativeVerifier.java @@ -1,116 +1,116 @@ -package org.aspectj.apache.bcel.verifier; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * The NativeVerifier class implements a main(String[] args) method that's - * roughly compatible to the one in the Verifier class, but that uses the - * JVM's internal verifier for its class file verification. - * This can be used for comparison runs between the JVM-internal verifier - * and JustIce. - * - * @version $Id: NativeVerifier.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author Enver Haase - */ -public abstract class NativeVerifier{ - - /** - * This class must not be instantiated. - */ - private NativeVerifier(){ - } - - /** - * Works only on the first argument. - */ - public static void main(String [] args){ - if (args.length != 1){ - System.out.println("Verifier front-end: need exactly one argument."); - System.exit(1); - } - - int dotclasspos = args[0].lastIndexOf(".class"); - if (dotclasspos != -1) args[0] = args[0].substring(0,dotclasspos); - args[0] = args[0].replace('/','.'); - //System.out.println(args[0]); - - - try{ - Class.forName(args[0]); - } - catch(ExceptionInInitializerError eiie){ //subclass of LinkageError! - System.out.println("NativeVerifier: ExceptionInInitializerError encountered on '"+args[0]+"'."); - System.out.println(eiie); - System.exit(1); - } - catch(LinkageError le){ - System.out.println("NativeVerifier: LinkageError encountered on '"+args[0]+"'."); - System.out.println(le); - System.exit(1); - } - catch(ClassNotFoundException cnfe){ - System.out.println("NativeVerifier: FILE NOT FOUND: '"+args[0]+"'."); - System.exit(1); - } - catch(Throwable t){ - System.out.println("NativeVerifier: Unspecified verification error on'"+args[0]+"'."); - System.exit(1); - } - - System.out.println("NativeVerifier: Class file '"+args[0]+"' seems to be okay."); - System.exit(0); - - } -} +package org.aspectj.apache.bcel.verifier; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * The NativeVerifier class implements a main(String[] args) method that's + * roughly compatible to the one in the Verifier class, but that uses the + * JVM's internal verifier for its class file verification. + * This can be used for comparison runs between the JVM-internal verifier + * and JustIce. + * + * @version $Id: NativeVerifier.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author Enver Haase + */ +public abstract class NativeVerifier{ + + /** + * This class must not be instantiated. + */ + private NativeVerifier(){ + } + + /** + * Works only on the first argument. + */ + public static void main(String [] args){ + if (args.length != 1){ + System.out.println("Verifier front-end: need exactly one argument."); + System.exit(1); + } + + int dotclasspos = args[0].lastIndexOf(".class"); + if (dotclasspos != -1) args[0] = args[0].substring(0,dotclasspos); + args[0] = args[0].replace('/','.'); + //System.out.println(args[0]); + + + try{ + Class.forName(args[0]); + } + catch(ExceptionInInitializerError eiie){ //subclass of LinkageError! + System.out.println("NativeVerifier: ExceptionInInitializerError encountered on '"+args[0]+"'."); + System.out.println(eiie); + System.exit(1); + } + catch(LinkageError le){ + System.out.println("NativeVerifier: LinkageError encountered on '"+args[0]+"'."); + System.out.println(le); + System.exit(1); + } + catch(ClassNotFoundException cnfe){ + System.out.println("NativeVerifier: FILE NOT FOUND: '"+args[0]+"'."); + System.exit(1); + } + catch(Throwable t){ + System.out.println("NativeVerifier: Unspecified verification error on'"+args[0]+"'."); + System.exit(1); + } + + System.out.println("NativeVerifier: Class file '"+args[0]+"' seems to be okay."); + System.exit(0); + + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/PassVerifier.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/PassVerifier.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/PassVerifier.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/PassVerifier.java index 575b4cb67..b51aab2da 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/PassVerifier.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/PassVerifier.java @@ -1,143 +1,143 @@ -package org.aspectj.apache.bcel.verifier; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.ArrayList; - -/** - * A PassVerifier actually verifies a class file; it is instantiated - * by a Verifier. - * The verification should conform with a certain pass as described - * in The Java Virtual Machine Specification, 2nd edition. - * This book describes four passes. Pass one means loading the - * class and verifying a few static constraints. Pass two actually - * verifies some other constraints that could enforce loading in - * referenced class files. Pass three is the first pass that actually - * checks constraints in the code array of a method in the class file; - * it has two parts with the first verifying static constraints and - * the second part verifying structural constraints (where a data flow - * analysis is used for). The fourth pass, finally, performs checks - * that can only be done at run-time. - * JustIce does not have a run-time pass, but certain constraints that - * are usually delayed until run-time for performance reasons are also - * checked during the second part of pass three. - * PassVerifier instances perform caching. - * That means, if you really want a new verification run of a certain - * pass you must use a new instance of a given PassVerifier. - * - * @version $Id: PassVerifier.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author Enver Haase - * @see org.aspectj.apache.bcel.verifier.Verifier - * @see #verify() - */ -public abstract class PassVerifier{ - - /** The (warning) messages. */ - private ArrayList messages = new ArrayList(); //Type of elements: String - - /** The VerificationResult cache. */ - private VerificationResult verificationResult = null; - - /** - * This method runs a verification pass conforming to the - * Java Virtual Machine Specification, 2nd edition, on a - * class file. - * PassVerifier instances perform caching; - * i.e. if the verify() method once determined a VerificationResult, - * then this result may be returned after every invocation of this - * method instead of running the verification pass anew; likewise with - * the result of getMessages(). - * - * @see #getMessages() - * @see #addMessage(String) - */ - public VerificationResult verify(){ - if (verificationResult == null){ - verificationResult = do_verify(); - } - return verificationResult; - } - - /** Does the real verification work, uncached. */ - public abstract VerificationResult do_verify(); - - /** - * This method adds a (warning) message to the message pool of this - * PassVerifier. This method is normally only internally used by - * BCEL's class file verifier "JustIce" and should not be used from - * the outside. - * - * @see #getMessages() - */ - public void addMessage(String message){ - messages.add(message); - } - - /** - * Returns the (warning) messages that this PassVerifier accumulated - * during its do_verify()ing work. - * - * @see #addMessage(String) - * @see #do_verify() - */ - public String[] getMessages(){ - verify(); // create messages if not already done (cached!) - String[] ret = new String[messages.size()]; - for (int i=0; i. + */ + +import java.util.ArrayList; + +/** + * A PassVerifier actually verifies a class file; it is instantiated + * by a Verifier. + * The verification should conform with a certain pass as described + * in The Java Virtual Machine Specification, 2nd edition. + * This book describes four passes. Pass one means loading the + * class and verifying a few static constraints. Pass two actually + * verifies some other constraints that could enforce loading in + * referenced class files. Pass three is the first pass that actually + * checks constraints in the code array of a method in the class file; + * it has two parts with the first verifying static constraints and + * the second part verifying structural constraints (where a data flow + * analysis is used for). The fourth pass, finally, performs checks + * that can only be done at run-time. + * JustIce does not have a run-time pass, but certain constraints that + * are usually delayed until run-time for performance reasons are also + * checked during the second part of pass three. + * PassVerifier instances perform caching. + * That means, if you really want a new verification run of a certain + * pass you must use a new instance of a given PassVerifier. + * + * @version $Id: PassVerifier.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author Enver Haase + * @see org.aspectj.apache.bcel.verifier.Verifier + * @see #verify() + */ +public abstract class PassVerifier{ + + /** The (warning) messages. */ + private ArrayList messages = new ArrayList(); //Type of elements: String + + /** The VerificationResult cache. */ + private VerificationResult verificationResult = null; + + /** + * This method runs a verification pass conforming to the + * Java Virtual Machine Specification, 2nd edition, on a + * class file. + * PassVerifier instances perform caching; + * i.e. if the verify() method once determined a VerificationResult, + * then this result may be returned after every invocation of this + * method instead of running the verification pass anew; likewise with + * the result of getMessages(). + * + * @see #getMessages() + * @see #addMessage(String) + */ + public VerificationResult verify(){ + if (verificationResult == null){ + verificationResult = do_verify(); + } + return verificationResult; + } + + /** Does the real verification work, uncached. */ + public abstract VerificationResult do_verify(); + + /** + * This method adds a (warning) message to the message pool of this + * PassVerifier. This method is normally only internally used by + * BCEL's class file verifier "JustIce" and should not be used from + * the outside. + * + * @see #getMessages() + */ + public void addMessage(String message){ + messages.add(message); + } + + /** + * Returns the (warning) messages that this PassVerifier accumulated + * during its do_verify()ing work. + * + * @see #addMessage(String) + * @see #do_verify() + */ + public String[] getMessages(){ + verify(); // create messages if not already done (cached!) + String[] ret = new String[messages.size()]; + for (int i=0; i. - */ - -import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * This class has a main method implementing a demonstration program - * of how to use the VerifierFactoryObserver. It transitively verifies - * all class files encountered; this may take up a lot of time and, - * more notably, memory. - * - * @version $Id: TransitiveHull.java,v 1.4.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author Enver Haase - */ -public class TransitiveHull implements VerifierFactoryObserver{ - - /** Used for indentation. */ - private int indent = 0; - - /** Not publicly instantiable. */ - private TransitiveHull(){ - } - - /* Implementing VerifierFactoryObserver. */ - public void update(String classname){ - - System.gc(); // avoid swapping if possible. - - for (int i=0; i. + */ + +import org.aspectj.apache.bcel.Repository; +import org.aspectj.apache.bcel.classfile.JavaClass; + +/** + * This class has a main method implementing a demonstration program + * of how to use the VerifierFactoryObserver. It transitively verifies + * all class files encountered; this may take up a lot of time and, + * more notably, memory. + * + * @version $Id: TransitiveHull.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author Enver Haase + */ +public class TransitiveHull implements VerifierFactoryObserver{ + + /** Used for indentation. */ + private int indent = 0; + + /** Not publicly instantiable. */ + private TransitiveHull(){ + } + + /* Implementing VerifierFactoryObserver. */ + public void update(String classname){ + + System.gc(); // avoid swapping if possible. + + for (int i=0; i. - */ - -/** - * A VerificationResult is what a PassVerifier returns - * after verifying. - * - * @version $Id: VerificationResult.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author Enver Haase - * - */ -public class VerificationResult{ - - /** - * Constant to indicate verification has not been tried yet. - * This happens if some earlier verification pass did not return VERIFIED_OK. - */ - public static final int VERIFIED_NOTYET = 0; - /** Constant to indicate verification was passed. */ - public static final int VERIFIED_OK = 1; - /** Constant to indicate verfication failed. */ - public static final int VERIFIED_REJECTED = 2; - - /** - * This string is the canonical message for verifications that have not been tried yet. - * This happens if some earlier verification pass did not return VERIFIED_OK. - */ - private static final String VERIFIED_NOTYET_MSG = "Not yet verified."; - /** This string is the canonical message for passed verification passes. */ - private static final String VERIFIED_OK_MSG = "Passed verification."; - - /** - * Canonical VerificationResult for not-yet-tried verifications. - * This happens if some earlier verification pass did not return VERIFIED_OK. - */ - public static final VerificationResult VR_NOTYET = new VerificationResult(VERIFIED_NOTYET, VERIFIED_NOTYET_MSG); - /** Canonical VerificationResult for passed verifications. */ - public static final VerificationResult VR_OK = new VerificationResult(VERIFIED_OK, VERIFIED_OK_MSG); - - /** The numeric status. */ - private int numeric; - - /** The detailed message. */ - private String detailMessage; - - /** The usual constructor. */ - public VerificationResult(int status, String message){ - numeric = status; - detailMessage = message; - } - - /** Returns one one the VERIFIED_OK, VERIFIED_NOTYET, VERIFIED_REJECTED constants. */ - public int getStatus(){ - return numeric; - } - - /** Returns a detailed message. */ - public String getMessage(){ - return detailMessage; - } - - /** - * Returns if two VerificationResult instances are equal. - */ - public boolean equals(Object o){ - if (! (o instanceof VerificationResult)) return false; - VerificationResult other = (VerificationResult) o; - return ((other.numeric == this.numeric) && (other.detailMessage.equals(this.detailMessage))); - } - - /** - * Returns a String representation of the VerificationResult. - */ - public String toString(){ - String ret=""; - if (numeric == VERIFIED_NOTYET) ret = "VERIFIED_NOTYET"; - if (numeric == VERIFIED_OK) ret = "VERIFIED_OK"; - if (numeric == VERIFIED_REJECTED) ret = "VERIFIED_REJECTED"; - ret+="\n"+detailMessage+"\n"; - return ret; - } -} +package org.aspectj.apache.bcel.verifier; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * A VerificationResult is what a PassVerifier returns + * after verifying. + * + * @version $Id: VerificationResult.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author Enver Haase + * + */ +public class VerificationResult{ + + /** + * Constant to indicate verification has not been tried yet. + * This happens if some earlier verification pass did not return VERIFIED_OK. + */ + public static final int VERIFIED_NOTYET = 0; + /** Constant to indicate verification was passed. */ + public static final int VERIFIED_OK = 1; + /** Constant to indicate verfication failed. */ + public static final int VERIFIED_REJECTED = 2; + + /** + * This string is the canonical message for verifications that have not been tried yet. + * This happens if some earlier verification pass did not return VERIFIED_OK. + */ + private static final String VERIFIED_NOTYET_MSG = "Not yet verified."; + /** This string is the canonical message for passed verification passes. */ + private static final String VERIFIED_OK_MSG = "Passed verification."; + + /** + * Canonical VerificationResult for not-yet-tried verifications. + * This happens if some earlier verification pass did not return VERIFIED_OK. + */ + public static final VerificationResult VR_NOTYET = new VerificationResult(VERIFIED_NOTYET, VERIFIED_NOTYET_MSG); + /** Canonical VerificationResult for passed verifications. */ + public static final VerificationResult VR_OK = new VerificationResult(VERIFIED_OK, VERIFIED_OK_MSG); + + /** The numeric status. */ + private int numeric; + + /** The detailed message. */ + private String detailMessage; + + /** The usual constructor. */ + public VerificationResult(int status, String message){ + numeric = status; + detailMessage = message; + } + + /** Returns one one the VERIFIED_OK, VERIFIED_NOTYET, VERIFIED_REJECTED constants. */ + public int getStatus(){ + return numeric; + } + + /** Returns a detailed message. */ + public String getMessage(){ + return detailMessage; + } + + /** + * Returns if two VerificationResult instances are equal. + */ + public boolean equals(Object o){ + if (! (o instanceof VerificationResult)) return false; + VerificationResult other = (VerificationResult) o; + return ((other.numeric == this.numeric) && (other.detailMessage.equals(this.detailMessage))); + } + + /** + * Returns a String representation of the VerificationResult. + */ + public String toString(){ + String ret=""; + if (numeric == VERIFIED_NOTYET) ret = "VERIFIED_NOTYET"; + if (numeric == VERIFIED_OK) ret = "VERIFIED_OK"; + if (numeric == VERIFIED_REJECTED) ret = "VERIFIED_REJECTED"; + ret+="\n"+detailMessage+"\n"; + return ret; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/Verifier.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/Verifier.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/Verifier.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/Verifier.java index 56a63b7bd..7fc2e6fcb 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/Verifier.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/Verifier.java @@ -1,288 +1,288 @@ -package org.aspectj.apache.bcel.verifier; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; - -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.verifier.statics.Pass1Verifier; -import org.aspectj.apache.bcel.verifier.statics.Pass2Verifier; -import org.aspectj.apache.bcel.verifier.statics.Pass3aVerifier; -import org.aspectj.apache.bcel.verifier.structurals.Pass3bVerifier; - -/** - * A Verifier instance is there to verify a class file according to The Java Virtual - * Machine Specification, 2nd Edition. - * - * Pass-3b-verification includes pass-3a-verification; - * pass-3a-verification includes pass-2-verification; - * pass-2-verification includes pass-1-verification. - * - * A Verifier creates PassVerifier instances to perform the actual verification. - * Verifier instances are usually generated by the VerifierFactory. - * - * @version $Id: Verifier.java,v 1.4.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author Enver Haase - * @see org.aspectj.apache.bcel.verifier.VerifierFactory - * @see org.aspectj.apache.bcel.verifier.PassVerifier - */ -public class Verifier{ - /** - * The name of the class this verifier operates on. - */ - private final String classname; - - /** A Pass1Verifier for this Verifier instance. */ - private Pass1Verifier p1v; - /** A Pass2Verifier for this Verifier instance. */ - private Pass2Verifier p2v; - /** The Pass3aVerifiers for this Verifier instance. Key: Interned string specifying the method number. */ - private HashMap p3avs = new HashMap(); - /** The Pass3bVerifiers for this Verifier instance. Key: Interned string specifying the method number. */ - private HashMap p3bvs = new HashMap(); - - /** Returns the VerificationResult for the given pass. */ - public VerificationResult doPass1(){ - if (p1v == null){ - p1v = new Pass1Verifier(this); - } - return p1v.verify(); - } - - /** Returns the VerificationResult for the given pass. */ - public VerificationResult doPass2(){ - if (p2v == null){ - p2v = new Pass2Verifier(this); - } - return p2v.verify(); - } - - /** Returns the VerificationResult for the given pass. */ - public VerificationResult doPass3a(int method_no){ - String key = Integer.toString(method_no); - Pass3aVerifier p3av; - p3av = (Pass3aVerifier) (p3avs.get(key)); - if (p3avs.get(key) == null){ - p3av = new Pass3aVerifier(this, method_no); - p3avs.put(key, p3av); - } - return p3av.verify(); - } - - /** Returns the VerificationResult for the given pass. */ - public VerificationResult doPass3b(int method_no){ - String key = Integer.toString(method_no); - Pass3bVerifier p3bv; - p3bv = (Pass3bVerifier) (p3bvs.get(key)); - if (p3bvs.get(key) == null){ - p3bv = new Pass3bVerifier(this, method_no); - p3bvs.put(key, p3bv); - } - return p3bv.verify(); - } - - - /** - * Instantiation is done by the VerifierFactory. - * - * @see VerifierFactory - */ - Verifier(String fully_qualified_classname){ - classname = fully_qualified_classname; - flush(); - } - - /** - * Returns the name of the class this verifier operates on. - * This is particularly interesting when this verifier was created - * recursively by another Verifier and you got a reference to this - * Verifier by the getVerifiers() method of the VerifierFactory. - * @see VerifierFactory - */ - public final String getClassName(){ - return classname; - } - - /** - * Forget everything known about the class file; that means, really - * start a new verification of a possibly different class file from - * BCEL's repository. - * - */ - public void flush(){ - p1v = null; - p2v = null; - p3avs.clear(); - p3bvs.clear(); - } - - /** - * This returns all the (warning) messages collected during verification. - * A prefix shows from which verifying pass a message originates. - */ - public String[] getMessages(){ - ArrayList messages = new ArrayList(); - - if (p1v != null){ - String[] p1m = p1v.getMessages(); - for (int i=0; i\n\n"); - for(int k=0; k < args.length; k++) { - - if (args[k].endsWith(".class")){ - int dotclasspos = args[k].lastIndexOf(".class"); - if (dotclasspos != -1) args[k] = args[k].substring(0,dotclasspos); - } - - args[k] = args[k].replace('/', '.'); - - System.out.println("Now verifying: "+args[k]+"\n"); - - Verifier v = VerifierFactory.getVerifier(args[k]); - VerificationResult vr; - - vr = v.doPass1(); - System.out.println("Pass 1:\n"+vr); - - vr = v.doPass2(); - System.out.println("Pass 2:\n"+vr); - - if (vr == VerificationResult.VR_OK){ - JavaClass jc = org.aspectj.apache.bcel.Repository - .lookupClass(args[k]); - for (int i=0; i"); - for (int j=0; j. + */ + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; + +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.verifier.statics.Pass1Verifier; +import org.aspectj.apache.bcel.verifier.statics.Pass2Verifier; +import org.aspectj.apache.bcel.verifier.statics.Pass3aVerifier; +import org.aspectj.apache.bcel.verifier.structurals.Pass3bVerifier; + +/** + * A Verifier instance is there to verify a class file according to The Java Virtual + * Machine Specification, 2nd Edition. + * + * Pass-3b-verification includes pass-3a-verification; + * pass-3a-verification includes pass-2-verification; + * pass-2-verification includes pass-1-verification. + * + * A Verifier creates PassVerifier instances to perform the actual verification. + * Verifier instances are usually generated by the VerifierFactory. + * + * @version $Id: Verifier.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author Enver Haase + * @see org.aspectj.apache.bcel.verifier.VerifierFactory + * @see org.aspectj.apache.bcel.verifier.PassVerifier + */ +public class Verifier{ + /** + * The name of the class this verifier operates on. + */ + private final String classname; + + /** A Pass1Verifier for this Verifier instance. */ + private Pass1Verifier p1v; + /** A Pass2Verifier for this Verifier instance. */ + private Pass2Verifier p2v; + /** The Pass3aVerifiers for this Verifier instance. Key: Interned string specifying the method number. */ + private HashMap p3avs = new HashMap(); + /** The Pass3bVerifiers for this Verifier instance. Key: Interned string specifying the method number. */ + private HashMap p3bvs = new HashMap(); + + /** Returns the VerificationResult for the given pass. */ + public VerificationResult doPass1(){ + if (p1v == null){ + p1v = new Pass1Verifier(this); + } + return p1v.verify(); + } + + /** Returns the VerificationResult for the given pass. */ + public VerificationResult doPass2(){ + if (p2v == null){ + p2v = new Pass2Verifier(this); + } + return p2v.verify(); + } + + /** Returns the VerificationResult for the given pass. */ + public VerificationResult doPass3a(int method_no){ + String key = Integer.toString(method_no); + Pass3aVerifier p3av; + p3av = (Pass3aVerifier) (p3avs.get(key)); + if (p3avs.get(key) == null){ + p3av = new Pass3aVerifier(this, method_no); + p3avs.put(key, p3av); + } + return p3av.verify(); + } + + /** Returns the VerificationResult for the given pass. */ + public VerificationResult doPass3b(int method_no){ + String key = Integer.toString(method_no); + Pass3bVerifier p3bv; + p3bv = (Pass3bVerifier) (p3bvs.get(key)); + if (p3bvs.get(key) == null){ + p3bv = new Pass3bVerifier(this, method_no); + p3bvs.put(key, p3bv); + } + return p3bv.verify(); + } + + + /** + * Instantiation is done by the VerifierFactory. + * + * @see VerifierFactory + */ + Verifier(String fully_qualified_classname){ + classname = fully_qualified_classname; + flush(); + } + + /** + * Returns the name of the class this verifier operates on. + * This is particularly interesting when this verifier was created + * recursively by another Verifier and you got a reference to this + * Verifier by the getVerifiers() method of the VerifierFactory. + * @see VerifierFactory + */ + public final String getClassName(){ + return classname; + } + + /** + * Forget everything known about the class file; that means, really + * start a new verification of a possibly different class file from + * BCEL's repository. + * + */ + public void flush(){ + p1v = null; + p2v = null; + p3avs.clear(); + p3bvs.clear(); + } + + /** + * This returns all the (warning) messages collected during verification. + * A prefix shows from which verifying pass a message originates. + */ + public String[] getMessages(){ + ArrayList messages = new ArrayList(); + + if (p1v != null){ + String[] p1m = p1v.getMessages(); + for (int i=0; i\n\n"); + for(int k=0; k < args.length; k++) { + + if (args[k].endsWith(".class")){ + int dotclasspos = args[k].lastIndexOf(".class"); + if (dotclasspos != -1) args[k] = args[k].substring(0,dotclasspos); + } + + args[k] = args[k].replace('/', '.'); + + System.out.println("Now verifying: "+args[k]+"\n"); + + Verifier v = VerifierFactory.getVerifier(args[k]); + VerificationResult vr; + + vr = v.doPass1(); + System.out.println("Pass 1:\n"+vr); + + vr = v.doPass2(); + System.out.println("Pass 2:\n"+vr); + + if (vr == VerificationResult.VR_OK){ + JavaClass jc = org.aspectj.apache.bcel.Repository + .lookupClass(args[k]); + for (int i=0; i"); + for (int j=0; j. - */ - -import java.awt.AWTEvent; -import java.awt.CardLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.WindowEvent; - -import javax.swing.BorderFactory; -import javax.swing.JFrame; -import javax.swing.JList; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTextPane; -import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionEvent; - -import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * This class implements a machine-generated frame for use with - * the GraphicalVerfifier. - * - * @version $Id: VerifierAppFrame.java,v 1.4.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author Enver Haase - * @see GraphicalVerifier - */ -public class VerifierAppFrame extends JFrame { - JPanel contentPane; - JSplitPane jSplitPane1 = new JSplitPane(); - JPanel jPanel1 = new JPanel(); - JPanel jPanel2 = new JPanel(); - JSplitPane jSplitPane2 = new JSplitPane(); - JPanel jPanel3 = new JPanel(); - JList classNamesJList = new JList(); - GridLayout gridLayout1 = new GridLayout(); - JPanel messagesPanel = new JPanel(); - GridLayout gridLayout2 = new GridLayout(); - JMenuBar jMenuBar1 = new JMenuBar(); - JMenu jMenu1 = new JMenu(); - JScrollPane jScrollPane1 = new JScrollPane(); - JScrollPane messagesScrollPane = new JScrollPane(); - JScrollPane jScrollPane3 = new JScrollPane(); - GridLayout gridLayout4 = new GridLayout(); - JScrollPane jScrollPane4 = new JScrollPane(); - CardLayout cardLayout1 = new CardLayout(); - - private String JUSTICE_VERSION = "JustIce by Enver Haase"; - private String current_class; - GridLayout gridLayout3 = new GridLayout(); - JTextPane pass1TextPane = new JTextPane(); - JTextPane pass2TextPane = new JTextPane(); - JTextPane messagesTextPane = new JTextPane(); - JMenuItem newFileMenuItem = new JMenuItem(); - JSplitPane jSplitPane3 = new JSplitPane(); - JSplitPane jSplitPane4 = new JSplitPane(); - JScrollPane jScrollPane2 = new JScrollPane(); - JScrollPane jScrollPane5 = new JScrollPane(); - JScrollPane jScrollPane6 = new JScrollPane(); - JScrollPane jScrollPane7 = new JScrollPane(); - JList pass3aJList = new JList(); - JList pass3bJList = new JList(); - JTextPane pass3aTextPane = new JTextPane(); - JTextPane pass3bTextPane = new JTextPane(); - JMenu jMenu2 = new JMenu(); - JMenuItem whatisMenuItem = new JMenuItem(); - JMenuItem aboutMenuItem = new JMenuItem(); - - /** Constructor. */ - public VerifierAppFrame() { - enableEvents(AWTEvent.WINDOW_EVENT_MASK); - try { - jbInit(); - } - catch(Exception e) { - e.printStackTrace(); - } - } - /** Initizalization of the components. */ - private void jbInit() throws Exception { - //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Ihr Symbol]"))); - contentPane = (JPanel) this.getContentPane(); - contentPane.setLayout(cardLayout1); - this.setJMenuBar(jMenuBar1); - this.setSize(new Dimension(708, 451)); - this.setTitle("JustIce"); - jPanel1.setMinimumSize(new Dimension(100, 100)); - jPanel1.setPreferredSize(new Dimension(100, 100)); - jPanel1.setLayout(gridLayout1); - jSplitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT); - jPanel2.setLayout(gridLayout2); - jPanel3.setMinimumSize(new Dimension(200, 100)); - jPanel3.setPreferredSize(new Dimension(400, 400)); - jPanel3.setLayout(gridLayout4); - messagesPanel.setMinimumSize(new Dimension(100, 100)); - messagesPanel.setLayout(gridLayout3); - jPanel2.setMinimumSize(new Dimension(200, 100)); - jMenu1.setText("File"); - - jScrollPane1.getViewport().setBackground(Color.red); - messagesScrollPane.getViewport().setBackground(Color.red); - messagesScrollPane.setPreferredSize(new Dimension(10, 10)); - classNamesJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { - public void valueChanged(ListSelectionEvent e) { - classNamesJList_valueChanged(e); - } - }); - classNamesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - jScrollPane3.setBorder(BorderFactory.createLineBorder(Color.black)); - jScrollPane3.setPreferredSize(new Dimension(100, 100)); - gridLayout4.setRows(4); - gridLayout4.setColumns(1); - gridLayout4.setHgap(1); - jScrollPane4.setBorder(BorderFactory.createLineBorder(Color.black)); - jScrollPane4.setPreferredSize(new Dimension(100, 100)); - pass1TextPane.setBorder(BorderFactory.createRaisedBevelBorder()); - pass1TextPane.setToolTipText(""); - pass1TextPane.setEditable(false); - pass2TextPane.setBorder(BorderFactory.createRaisedBevelBorder()); - pass2TextPane.setEditable(false); - messagesTextPane.setBorder(BorderFactory.createRaisedBevelBorder()); - messagesTextPane.setEditable(false); - newFileMenuItem.setText("New..."); - newFileMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(78, java.awt.event.KeyEvent.CTRL_MASK, true)); - newFileMenuItem.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - newFileMenuItem_actionPerformed(e); - } - }); - pass3aTextPane.setEditable(false); - pass3bTextPane.setEditable(false); - pass3aJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { - public void valueChanged(ListSelectionEvent e) { - pass3aJList_valueChanged(e); - } - }); - pass3bJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { - public void valueChanged(ListSelectionEvent e) { - pass3bJList_valueChanged(e); - } - }); - jMenu2.setText("Help"); - whatisMenuItem.setText("What is..."); - whatisMenuItem.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - whatisMenuItem_actionPerformed(e); - } - }); - aboutMenuItem.setText("About"); - aboutMenuItem.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - aboutMenuItem_actionPerformed(e); - } - }); - jSplitPane2.add(messagesPanel, JSplitPane.BOTTOM); - messagesPanel.add(messagesScrollPane, null); - messagesScrollPane.getViewport().add(messagesTextPane, null); - jSplitPane2.add(jPanel3, JSplitPane.TOP); - jPanel3.add(jScrollPane3, null); - jScrollPane3.getViewport().add(pass1TextPane, null); - jPanel3.add(jScrollPane4, null); - jPanel3.add(jSplitPane3, null); - jSplitPane3.add(jScrollPane2, JSplitPane.LEFT); - jScrollPane2.getViewport().add(pass3aJList, null); - jSplitPane3.add(jScrollPane5, JSplitPane.RIGHT); - jScrollPane5.getViewport().add(pass3aTextPane, null); - jPanel3.add(jSplitPane4, null); - jSplitPane4.add(jScrollPane6, JSplitPane.LEFT); - jScrollPane6.getViewport().add(pass3bJList, null); - jSplitPane4.add(jScrollPane7, JSplitPane.RIGHT); - jScrollPane7.getViewport().add(pass3bTextPane, null); - jScrollPane4.getViewport().add(pass2TextPane, null); - jSplitPane1.add(jPanel2, JSplitPane.TOP); - jPanel2.add(jScrollPane1, null); - jSplitPane1.add(jPanel1, JSplitPane.BOTTOM); - jPanel1.add(jSplitPane2, null); - jScrollPane1.getViewport().add(classNamesJList, null); - jMenuBar1.add(jMenu1); - jMenuBar1.add(jMenu2); - contentPane.add(jSplitPane1, "jSplitPane1"); - jMenu1.add(newFileMenuItem); - jMenu2.add(whatisMenuItem); - jMenu2.add(aboutMenuItem); - jSplitPane2.setDividerLocation(300); - jSplitPane3.setDividerLocation(150); - jSplitPane4.setDividerLocation(150); - } - - /** Overridden to stop the application on a closing window. */ - protected void processWindowEvent(WindowEvent e) { - super.processWindowEvent(e); - if (e.getID() == WindowEvent.WINDOW_CLOSING) { - System.exit(0); - } - } - - synchronized void classNamesJList_valueChanged(ListSelectionEvent e) { - if (e.getValueIsAdjusting()) return; - current_class = classNamesJList.getSelectedValue().toString(); - verify(); - classNamesJList.setSelectedValue(current_class, true); - } - - private void verify(){ - setTitle("PLEASE WAIT"); - - Verifier v = VerifierFactory.getVerifier(current_class); - v.flush(); // Don't cache the verification result for this class. - - VerificationResult vr; - - vr = v.doPass1(); - if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ - pass1TextPane.setText(vr.getMessage()); - pass1TextPane.setBackground(Color.red); - - pass2TextPane.setText(""); - pass2TextPane.setBackground(Color.yellow); - pass3aTextPane.setText(""); - pass3aJList.setListData(new Object[0]); - pass3aTextPane.setBackground(Color.yellow); - - pass3bTextPane.setText(""); - pass3bJList.setListData(new Object[0]); - pass3bTextPane.setBackground(Color.yellow); - - } - else{ // Must be VERIFIED_OK, Pass 1 does not know VERIFIED_NOTYET - pass1TextPane.setBackground(Color.green); - pass1TextPane.setText(vr.getMessage()); - - vr = v.doPass2(); - if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ - pass2TextPane.setText(vr.getMessage()); - pass2TextPane.setBackground(Color.red); - - pass3aTextPane.setText(""); - pass3aTextPane.setBackground(Color.yellow); - pass3aJList.setListData(new Object[0]); - pass3bTextPane.setText(""); - pass3bTextPane.setBackground(Color.yellow); - pass3bJList.setListData(new Object[0]); - } - else{ // must be Verified_OK, because Pass1 was OK (cannot be Verified_NOTYET). - pass2TextPane.setText(vr.getMessage()); - pass2TextPane.setBackground(Color.green); - - JavaClass jc = Repository.lookupClass(current_class); - /* - boolean all3aok = true; - boolean all3bok = true; - String all3amsg = ""; - String all3bmsg = ""; - */ - - String[] methodnames = new String[jc.getMethods().length]; - for (int i=0; i", - JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE); - } - - void whatisMenuItem_actionPerformed(ActionEvent e) { - JOptionPane.showMessageDialog(this, - "The upper four boxes to the right reflect verification passes according to The Java Virtual Machine Specification.\nThese are (in that order): Pass one, Pass two, Pass three (before data flow analysis), Pass three (data flow analysis).\nThe bottom box to the right shows (warning) messages; warnings do not cause a class to be rejected.", - JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE); - } -} +package org.aspectj.apache.bcel.verifier; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.awt.AWTEvent; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.WindowEvent; + +import javax.swing.BorderFactory; +import javax.swing.JFrame; +import javax.swing.JList; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTextPane; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; + +import org.aspectj.apache.bcel.Repository; +import org.aspectj.apache.bcel.classfile.JavaClass; + +/** + * This class implements a machine-generated frame for use with + * the GraphicalVerfifier. + * + * @version $Id: VerifierAppFrame.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author Enver Haase + * @see GraphicalVerifier + */ +public class VerifierAppFrame extends JFrame { + JPanel contentPane; + JSplitPane jSplitPane1 = new JSplitPane(); + JPanel jPanel1 = new JPanel(); + JPanel jPanel2 = new JPanel(); + JSplitPane jSplitPane2 = new JSplitPane(); + JPanel jPanel3 = new JPanel(); + JList classNamesJList = new JList(); + GridLayout gridLayout1 = new GridLayout(); + JPanel messagesPanel = new JPanel(); + GridLayout gridLayout2 = new GridLayout(); + JMenuBar jMenuBar1 = new JMenuBar(); + JMenu jMenu1 = new JMenu(); + JScrollPane jScrollPane1 = new JScrollPane(); + JScrollPane messagesScrollPane = new JScrollPane(); + JScrollPane jScrollPane3 = new JScrollPane(); + GridLayout gridLayout4 = new GridLayout(); + JScrollPane jScrollPane4 = new JScrollPane(); + CardLayout cardLayout1 = new CardLayout(); + + private String JUSTICE_VERSION = "JustIce by Enver Haase"; + private String current_class; + GridLayout gridLayout3 = new GridLayout(); + JTextPane pass1TextPane = new JTextPane(); + JTextPane pass2TextPane = new JTextPane(); + JTextPane messagesTextPane = new JTextPane(); + JMenuItem newFileMenuItem = new JMenuItem(); + JSplitPane jSplitPane3 = new JSplitPane(); + JSplitPane jSplitPane4 = new JSplitPane(); + JScrollPane jScrollPane2 = new JScrollPane(); + JScrollPane jScrollPane5 = new JScrollPane(); + JScrollPane jScrollPane6 = new JScrollPane(); + JScrollPane jScrollPane7 = new JScrollPane(); + JList pass3aJList = new JList(); + JList pass3bJList = new JList(); + JTextPane pass3aTextPane = new JTextPane(); + JTextPane pass3bTextPane = new JTextPane(); + JMenu jMenu2 = new JMenu(); + JMenuItem whatisMenuItem = new JMenuItem(); + JMenuItem aboutMenuItem = new JMenuItem(); + + /** Constructor. */ + public VerifierAppFrame() { + enableEvents(AWTEvent.WINDOW_EVENT_MASK); + try { + jbInit(); + } + catch(Exception e) { + e.printStackTrace(); + } + } + /** Initizalization of the components. */ + private void jbInit() throws Exception { + //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Ihr Symbol]"))); + contentPane = (JPanel) this.getContentPane(); + contentPane.setLayout(cardLayout1); + this.setJMenuBar(jMenuBar1); + this.setSize(new Dimension(708, 451)); + this.setTitle("JustIce"); + jPanel1.setMinimumSize(new Dimension(100, 100)); + jPanel1.setPreferredSize(new Dimension(100, 100)); + jPanel1.setLayout(gridLayout1); + jSplitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT); + jPanel2.setLayout(gridLayout2); + jPanel3.setMinimumSize(new Dimension(200, 100)); + jPanel3.setPreferredSize(new Dimension(400, 400)); + jPanel3.setLayout(gridLayout4); + messagesPanel.setMinimumSize(new Dimension(100, 100)); + messagesPanel.setLayout(gridLayout3); + jPanel2.setMinimumSize(new Dimension(200, 100)); + jMenu1.setText("File"); + + jScrollPane1.getViewport().setBackground(Color.red); + messagesScrollPane.getViewport().setBackground(Color.red); + messagesScrollPane.setPreferredSize(new Dimension(10, 10)); + classNamesJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) { + classNamesJList_valueChanged(e); + } + }); + classNamesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + jScrollPane3.setBorder(BorderFactory.createLineBorder(Color.black)); + jScrollPane3.setPreferredSize(new Dimension(100, 100)); + gridLayout4.setRows(4); + gridLayout4.setColumns(1); + gridLayout4.setHgap(1); + jScrollPane4.setBorder(BorderFactory.createLineBorder(Color.black)); + jScrollPane4.setPreferredSize(new Dimension(100, 100)); + pass1TextPane.setBorder(BorderFactory.createRaisedBevelBorder()); + pass1TextPane.setToolTipText(""); + pass1TextPane.setEditable(false); + pass2TextPane.setBorder(BorderFactory.createRaisedBevelBorder()); + pass2TextPane.setEditable(false); + messagesTextPane.setBorder(BorderFactory.createRaisedBevelBorder()); + messagesTextPane.setEditable(false); + newFileMenuItem.setText("New..."); + newFileMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(78, java.awt.event.KeyEvent.CTRL_MASK, true)); + newFileMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + newFileMenuItem_actionPerformed(e); + } + }); + pass3aTextPane.setEditable(false); + pass3bTextPane.setEditable(false); + pass3aJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) { + pass3aJList_valueChanged(e); + } + }); + pass3bJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) { + pass3bJList_valueChanged(e); + } + }); + jMenu2.setText("Help"); + whatisMenuItem.setText("What is..."); + whatisMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + whatisMenuItem_actionPerformed(e); + } + }); + aboutMenuItem.setText("About"); + aboutMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + aboutMenuItem_actionPerformed(e); + } + }); + jSplitPane2.add(messagesPanel, JSplitPane.BOTTOM); + messagesPanel.add(messagesScrollPane, null); + messagesScrollPane.getViewport().add(messagesTextPane, null); + jSplitPane2.add(jPanel3, JSplitPane.TOP); + jPanel3.add(jScrollPane3, null); + jScrollPane3.getViewport().add(pass1TextPane, null); + jPanel3.add(jScrollPane4, null); + jPanel3.add(jSplitPane3, null); + jSplitPane3.add(jScrollPane2, JSplitPane.LEFT); + jScrollPane2.getViewport().add(pass3aJList, null); + jSplitPane3.add(jScrollPane5, JSplitPane.RIGHT); + jScrollPane5.getViewport().add(pass3aTextPane, null); + jPanel3.add(jSplitPane4, null); + jSplitPane4.add(jScrollPane6, JSplitPane.LEFT); + jScrollPane6.getViewport().add(pass3bJList, null); + jSplitPane4.add(jScrollPane7, JSplitPane.RIGHT); + jScrollPane7.getViewport().add(pass3bTextPane, null); + jScrollPane4.getViewport().add(pass2TextPane, null); + jSplitPane1.add(jPanel2, JSplitPane.TOP); + jPanel2.add(jScrollPane1, null); + jSplitPane1.add(jPanel1, JSplitPane.BOTTOM); + jPanel1.add(jSplitPane2, null); + jScrollPane1.getViewport().add(classNamesJList, null); + jMenuBar1.add(jMenu1); + jMenuBar1.add(jMenu2); + contentPane.add(jSplitPane1, "jSplitPane1"); + jMenu1.add(newFileMenuItem); + jMenu2.add(whatisMenuItem); + jMenu2.add(aboutMenuItem); + jSplitPane2.setDividerLocation(300); + jSplitPane3.setDividerLocation(150); + jSplitPane4.setDividerLocation(150); + } + + /** Overridden to stop the application on a closing window. */ + protected void processWindowEvent(WindowEvent e) { + super.processWindowEvent(e); + if (e.getID() == WindowEvent.WINDOW_CLOSING) { + System.exit(0); + } + } + + synchronized void classNamesJList_valueChanged(ListSelectionEvent e) { + if (e.getValueIsAdjusting()) return; + current_class = classNamesJList.getSelectedValue().toString(); + verify(); + classNamesJList.setSelectedValue(current_class, true); + } + + private void verify(){ + setTitle("PLEASE WAIT"); + + Verifier v = VerifierFactory.getVerifier(current_class); + v.flush(); // Don't cache the verification result for this class. + + VerificationResult vr; + + vr = v.doPass1(); + if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ + pass1TextPane.setText(vr.getMessage()); + pass1TextPane.setBackground(Color.red); + + pass2TextPane.setText(""); + pass2TextPane.setBackground(Color.yellow); + pass3aTextPane.setText(""); + pass3aJList.setListData(new Object[0]); + pass3aTextPane.setBackground(Color.yellow); + + pass3bTextPane.setText(""); + pass3bJList.setListData(new Object[0]); + pass3bTextPane.setBackground(Color.yellow); + + } + else{ // Must be VERIFIED_OK, Pass 1 does not know VERIFIED_NOTYET + pass1TextPane.setBackground(Color.green); + pass1TextPane.setText(vr.getMessage()); + + vr = v.doPass2(); + if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ + pass2TextPane.setText(vr.getMessage()); + pass2TextPane.setBackground(Color.red); + + pass3aTextPane.setText(""); + pass3aTextPane.setBackground(Color.yellow); + pass3aJList.setListData(new Object[0]); + pass3bTextPane.setText(""); + pass3bTextPane.setBackground(Color.yellow); + pass3bJList.setListData(new Object[0]); + } + else{ // must be Verified_OK, because Pass1 was OK (cannot be Verified_NOTYET). + pass2TextPane.setText(vr.getMessage()); + pass2TextPane.setBackground(Color.green); + + JavaClass jc = Repository.lookupClass(current_class); + /* + boolean all3aok = true; + boolean all3bok = true; + String all3amsg = ""; + String all3bmsg = ""; + */ + + String[] methodnames = new String[jc.getMethods().length]; + for (int i=0; i", + JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE); + } + + void whatisMenuItem_actionPerformed(ActionEvent e) { + JOptionPane.showMessageDialog(this, + "The upper four boxes to the right reflect verification passes according to The Java Virtual Machine Specification.\nThese are (in that order): Pass one, Pass two, Pass three (before data flow analysis), Pass three (data flow analysis).\nThe bottom box to the right shows (warning) messages; warnings do not cause a class to be rejected.", + JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/VerifierFactory.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/VerifierFactory.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/VerifierFactory.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/VerifierFactory.java index 4a78b3fe4..ab2db3ae8 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/VerifierFactory.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/VerifierFactory.java @@ -1,143 +1,143 @@ -package org.aspectj.apache.bcel.verifier; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Vector; - -/** - * This class produces instances of the Verifier class. Its purpose is to make - * sure that they are singleton instances with respect to the class name they - * operate on. That means, for every class (represented by a unique fully qualified - * class name) there is exactly one Verifier. - * - * @version $Id: VerifierFactory.java,v 1.4.8.1 2008/04/25 17:55:36 aclement Exp $ - * @author Enver Haase - * @see org.aspectj.apache.bcel.verifier.Verifier - */ -public class VerifierFactory{ - - /** - * The HashMap that holds the data about the already-constructed Verifier instances. - */ - private static HashMap hashMap = new HashMap(); - - /** - * The VerifierFactoryObserver instances that observe the VerifierFactory. - */ - private static Vector observers = new Vector(); - - /** - * The VerifierFactory is not instantiable. - */ - private VerifierFactory(){} - - /** - * Returns the (only) verifier responsible for the class with the given name. - * Possibly a new Verifier object is transparently created. - * @return the (only) verifier responsible for the class with the given name. - */ - public static Verifier getVerifier(String fully_qualified_classname){ - // fully_qualified_classname = fully_qualified_classname; - - Verifier v = (Verifier) (hashMap.get(fully_qualified_classname)); - if (v==null){ - v = new Verifier(fully_qualified_classname); - hashMap.put(fully_qualified_classname, v); - notify(fully_qualified_classname); - } - - return v; - } - - /** - * Notifies the observers of a newly generated Verifier. - */ - private static void notify(String fully_qualified_classname){ - // notify the observers - Iterator i = observers.iterator(); - while (i.hasNext()){ - VerifierFactoryObserver vfo = (VerifierFactoryObserver) i.next(); - vfo.update(fully_qualified_classname); - } - } - - /** - * Returns all Verifier instances created so far. - * This is useful when a Verifier recursively lets - * the VerifierFactory create other Verifier instances - * and if you want to verify the transitive hull of - * referenced class files. - */ - public static Verifier[] getVerifiers(){ - Verifier[] vs = new Verifier[hashMap.values().size()]; - return (Verifier[]) (hashMap.values().toArray(vs)); // Because vs is big enough, vs is used to store the values into and returned! - } - - /** - * Adds the VerifierFactoryObserver o to the list of observers. - */ - public static void attach(VerifierFactoryObserver o){ - observers.addElement(o); - } - - /** - * Removes the VerifierFactoryObserver o from the list of observers. - */ - public static void detach(VerifierFactoryObserver o){ - observers.removeElement(o); - } -} +package org.aspectj.apache.bcel.verifier; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Vector; + +/** + * This class produces instances of the Verifier class. Its purpose is to make + * sure that they are singleton instances with respect to the class name they + * operate on. That means, for every class (represented by a unique fully qualified + * class name) there is exactly one Verifier. + * + * @version $Id: VerifierFactory.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author Enver Haase + * @see org.aspectj.apache.bcel.verifier.Verifier + */ +public class VerifierFactory{ + + /** + * The HashMap that holds the data about the already-constructed Verifier instances. + */ + private static HashMap hashMap = new HashMap(); + + /** + * The VerifierFactoryObserver instances that observe the VerifierFactory. + */ + private static Vector observers = new Vector(); + + /** + * The VerifierFactory is not instantiable. + */ + private VerifierFactory(){} + + /** + * Returns the (only) verifier responsible for the class with the given name. + * Possibly a new Verifier object is transparently created. + * @return the (only) verifier responsible for the class with the given name. + */ + public static Verifier getVerifier(String fully_qualified_classname){ + // fully_qualified_classname = fully_qualified_classname; + + Verifier v = (Verifier) (hashMap.get(fully_qualified_classname)); + if (v==null){ + v = new Verifier(fully_qualified_classname); + hashMap.put(fully_qualified_classname, v); + notify(fully_qualified_classname); + } + + return v; + } + + /** + * Notifies the observers of a newly generated Verifier. + */ + private static void notify(String fully_qualified_classname){ + // notify the observers + Iterator i = observers.iterator(); + while (i.hasNext()){ + VerifierFactoryObserver vfo = (VerifierFactoryObserver) i.next(); + vfo.update(fully_qualified_classname); + } + } + + /** + * Returns all Verifier instances created so far. + * This is useful when a Verifier recursively lets + * the VerifierFactory create other Verifier instances + * and if you want to verify the transitive hull of + * referenced class files. + */ + public static Verifier[] getVerifiers(){ + Verifier[] vs = new Verifier[hashMap.values().size()]; + return (Verifier[]) (hashMap.values().toArray(vs)); // Because vs is big enough, vs is used to store the values into and returned! + } + + /** + * Adds the VerifierFactoryObserver o to the list of observers. + */ + public static void attach(VerifierFactoryObserver o){ + observers.addElement(o); + } + + /** + * Removes the VerifierFactoryObserver o from the list of observers. + */ + public static void detach(VerifierFactoryObserver o){ + observers.removeElement(o); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/VerifierFactoryListModel.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/VerifierFactoryListModel.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/VerifierFactoryListModel.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/VerifierFactoryListModel.java index 75e8a6eae..6d95612fc 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/VerifierFactoryListModel.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/VerifierFactoryListModel.java @@ -1,106 +1,106 @@ -package org.aspectj.apache.bcel.verifier; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import javax.swing.event.ListDataEvent; -/** - * This class implements an adapter; it implements both a Swing ListModel and - * a VerifierFactoryObserver. - * - * @version $Id: VerifierFactoryListModel.java,v 1.4.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author Enver Haase - */ -public class VerifierFactoryListModel implements org.aspectj.apache.bcel.verifier.VerifierFactoryObserver, javax.swing.ListModel{ - - private java.util.ArrayList listeners = new java.util.ArrayList(); - - private java.util.TreeSet cache = new java.util.TreeSet(); - - public VerifierFactoryListModel() { - VerifierFactory.attach(this); - update(null); // fill cache. - } - - public synchronized void update(String s){ - int size = listeners.size(); - - Verifier[] verifiers = VerifierFactory.getVerifiers(); - int num_of_verifiers = verifiers.length; - cache.clear(); - for (int i=0; i. + */ +import javax.swing.event.ListDataEvent; +/** + * This class implements an adapter; it implements both a Swing ListModel and + * a VerifierFactoryObserver. + * + * @version $Id: VerifierFactoryListModel.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author Enver Haase + */ +public class VerifierFactoryListModel implements org.aspectj.apache.bcel.verifier.VerifierFactoryObserver, javax.swing.ListModel{ + + private java.util.ArrayList listeners = new java.util.ArrayList(); + + private java.util.TreeSet cache = new java.util.TreeSet(); + + public VerifierFactoryListModel() { + VerifierFactory.attach(this); + update(null); // fill cache. + } + + public synchronized void update(String s){ + int size = listeners.size(); + + Verifier[] verifiers = VerifierFactory.getVerifiers(); + int num_of_verifiers = verifiers.length; + cache.clear(); + for (int i=0; i. - */ - -/** - * VerifierFactoryObserver instances are notified when new Verifier - * instances are created. - * - * @version $Id: VerifierFactoryObserver.java,v 1.2.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author Enver Haase - * - * @see VerifierFactory#getVerifier(String) - * @see VerifierFactory#getVerifiers() - * @see VerifierFactory#attach(VerifierFactoryObserver) - * @see VerifierFactory#detach(VerifierFactoryObserver) - */ -public interface VerifierFactoryObserver{ - /** - * VerifierFactoryObserver instances are notified invoking this method. - * The String argument is the fully qualified class name of a class a - * new Verifier instance created by the VerifierFactory operates on. - */ - public void update(String s); -} +package org.aspectj.apache.bcel.verifier; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * VerifierFactoryObserver instances are notified when new Verifier + * instances are created. + * + * @version $Id: VerifierFactoryObserver.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author Enver Haase + * + * @see VerifierFactory#getVerifier(String) + * @see VerifierFactory#getVerifiers() + * @see VerifierFactory#attach(VerifierFactoryObserver) + * @see VerifierFactory#detach(VerifierFactoryObserver) + */ +public interface VerifierFactoryObserver{ + /** + * VerifierFactoryObserver instances are notified invoking this method. + * The String argument is the fully qualified class name of a class a + * new Verifier instance created by the VerifierFactory operates on. + */ + public void update(String s); +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/VerifyDialog.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/VerifyDialog.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/VerifyDialog.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/VerifyDialog.java index 436349147..63327504a 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/VerifyDialog.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/VerifyDialog.java @@ -1,559 +1,559 @@ -package org.aspectj.apache.bcel.verifier; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.awt.Color; - -import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.JavaClass; - -/** - * A class for simple graphical class file verification. - * Use the main(String []) method with fully qualified - * class names as arguments to use it as a stand-alone - * application. - * Use the VerifyDialog(String) constructor to use this - * class in your application. - * [This class was created using VisualAge for Java, - * but it does not work under VAJ itself (Version 3.02 JDK 1.2)] - * @version $Id: VerifyDialog.java,v 1.4.10.1 2008/04/25 17:55:36 aclement Exp $ - * @author Enver Haase - * @see #main(String[]) - * @see #VerifyDialog(String) - */ -public class VerifyDialog extends javax.swing.JDialog { - /** Machine-generated. */ - private javax.swing.JPanel ivjJDialogContentPane = null; - /** Machine-generated. */ - private javax.swing.JPanel ivjPass1Panel = null; - /** Machine-generated. */ - private javax.swing.JPanel ivjPass2Panel = null; - /** Machine-generated. */ - private javax.swing.JPanel ivjPass3Panel = null; - /** Machine-generated. */ - private javax.swing.JButton ivjPass1Button = null; - /** Machine-generated. */ - private javax.swing.JButton ivjPass2Button = null; - /** Machine-generated. */ - private javax.swing.JButton ivjPass3Button = null; - /** Machine-generated. */ - IvjEventHandler ivjEventHandler = new IvjEventHandler(); - - /** - * The class to verify. Default set to 'java.lang.Object' - * in case this class is instantiated via one of the many - * machine-generated constructors. - */ - private String class_name = "java.lang.Object"; - - /** - * This field is here to count the number of open VerifyDialog - * instances so the JVM can be exited afer every Dialog had been - * closed. - */ - private static int classes_to_verify; - -/** Machine-generated. */ -class IvjEventHandler implements java.awt.event.ActionListener { - public void actionPerformed(java.awt.event.ActionEvent e) { - if (e.getSource() == VerifyDialog.this.getPass1Button()) - connEtoC1(e); - if (e.getSource() == VerifyDialog.this.getPass2Button()) - connEtoC2(e); - if (e.getSource() == VerifyDialog.this.getPass3Button()) - connEtoC3(e); - if (e.getSource() == VerifyDialog.this.getFlushButton()) - connEtoC4(e); - }; - }; - /** Machine-generated. */ - private javax.swing.JButton ivjFlushButton = null; -/** Machine-generated. */ -public VerifyDialog() { - super(); - initialize(); -} - -/** Machine-generated. */ -public VerifyDialog(java.awt.Dialog owner) { - super(owner); -} - -/** Machine-generated. */ -public VerifyDialog(java.awt.Dialog owner, String title) { - super(owner, title); -} - -/** Machine-generated. */ -public VerifyDialog(java.awt.Dialog owner, String title, boolean modal) { - super(owner, title, modal); -} - -/** Machine-generated. */ -public VerifyDialog(java.awt.Dialog owner, boolean modal) { - super(owner, modal); -} - -/** Machine-generated. */ -public VerifyDialog(java.awt.Frame owner) { - super(owner); -} - -/** Machine-generated. */ -public VerifyDialog(java.awt.Frame owner, String title) { - super(owner, title); -} - -/** Machine-generated. */ -public VerifyDialog(java.awt.Frame owner, String title, boolean modal) { - super(owner, title, modal); -} - -/** Machine-generated. */ -public VerifyDialog(java.awt.Frame owner, boolean modal) { - super(owner, modal); -} - -/** - * Use this constructor if you want a possibility to verify other - * class files than java.lang.Object. - * @param fully_qualified_class_name java.lang.String - */ -public VerifyDialog(String fully_qualified_class_name) { - super(); - - int dotclasspos = fully_qualified_class_name.lastIndexOf(".class"); - if (dotclasspos != -1) fully_qualified_class_name = fully_qualified_class_name.substring(0,dotclasspos); - fully_qualified_class_name = fully_qualified_class_name.replace('/', '.'); - - class_name = fully_qualified_class_name; - initialize(); -} - - -/** Machine-generated. */ -private void connEtoC1(java.awt.event.ActionEvent arg1) { - try { - // user code begin {1} - // user code end - this.pass1Button_ActionPerformed(arg1); - // user code begin {2} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {3} - // user code end - handleException(ivjExc); - } -} - -/** Machine-generated. */ -private void connEtoC2(java.awt.event.ActionEvent arg1) { - try { - // user code begin {1} - // user code end - this.pass2Button_ActionPerformed(arg1); - // user code begin {2} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {3} - // user code end - handleException(ivjExc); - } -} - -/** Machine-generated. */ -private void connEtoC3(java.awt.event.ActionEvent arg1) { - try { - // user code begin {1} - // user code end - this.pass4Button_ActionPerformed(arg1); - // user code begin {2} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {3} - // user code end - handleException(ivjExc); - } -} - -/** Machine-generated. */ -private void connEtoC4(java.awt.event.ActionEvent arg1) { - try { - // user code begin {1} - // user code end - this.flushButton_ActionPerformed(arg1); - // user code begin {2} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {3} - // user code end - handleException(ivjExc); - } -} - -/** Machine-generated. */ -public void flushButton_ActionPerformed(java.awt.event.ActionEvent actionEvent) { - VerifierFactory.getVerifier(class_name).flush(); - Repository.removeClass(class_name); // Make sure it will be reloaded. - getPass1Panel().setBackground(Color.gray); - getPass1Panel().repaint(); - getPass2Panel().setBackground(Color.gray); - getPass2Panel().repaint(); - getPass3Panel().setBackground(Color.gray); - getPass3Panel().repaint(); -} - -/** Machine-generated. */ -private javax.swing.JButton getFlushButton() { - if (ivjFlushButton == null) { - try { - ivjFlushButton = new javax.swing.JButton(); - ivjFlushButton.setName("FlushButton"); - ivjFlushButton.setText("Flush: Forget old verification results"); - ivjFlushButton.setBackground(java.awt.SystemColor.controlHighlight); - ivjFlushButton.setBounds(60, 215, 300, 30); - ivjFlushButton.setForeground(java.awt.Color.red); - ivjFlushButton.setActionCommand("FlushButton"); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjFlushButton; -} - -/** Machine-generated. */ -private javax.swing.JPanel getJDialogContentPane() { - if (ivjJDialogContentPane == null) { - try { - ivjJDialogContentPane = new javax.swing.JPanel(); - ivjJDialogContentPane.setName("JDialogContentPane"); - ivjJDialogContentPane.setLayout(null); - getJDialogContentPane().add(getPass1Panel(), getPass1Panel().getName()); - getJDialogContentPane().add(getPass3Panel(), getPass3Panel().getName()); - getJDialogContentPane().add(getPass2Panel(), getPass2Panel().getName()); - getJDialogContentPane().add(getPass1Button(), getPass1Button().getName()); - getJDialogContentPane().add(getPass2Button(), getPass2Button().getName()); - getJDialogContentPane().add(getPass3Button(), getPass3Button().getName()); - getJDialogContentPane().add(getFlushButton(), getFlushButton().getName()); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjJDialogContentPane; -} - -/** Machine-generated. */ -private javax.swing.JButton getPass1Button() { - if (ivjPass1Button == null) { - try { - ivjPass1Button = new javax.swing.JButton(); - ivjPass1Button.setName("Pass1Button"); - ivjPass1Button.setText("Pass1: Verify binary layout of .class file"); - ivjPass1Button.setBackground(java.awt.SystemColor.controlHighlight); - ivjPass1Button.setBounds(100, 40, 300, 30); - ivjPass1Button.setActionCommand("Button1"); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjPass1Button; -} - -/** Machine-generated. */ -private javax.swing.JPanel getPass1Panel() { - if (ivjPass1Panel == null) { - try { - ivjPass1Panel = new javax.swing.JPanel(); - ivjPass1Panel.setName("Pass1Panel"); - ivjPass1Panel.setLayout(null); - ivjPass1Panel.setBackground(java.awt.SystemColor.controlShadow); - ivjPass1Panel.setBounds(30, 30, 50, 50); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjPass1Panel; -} - -/** Machine-generated. */ -private javax.swing.JButton getPass2Button() { - if (ivjPass2Button == null) { - try { - ivjPass2Button = new javax.swing.JButton(); - ivjPass2Button.setName("Pass2Button"); - ivjPass2Button.setText("Pass 2: Verify static .class file constraints"); - ivjPass2Button.setBackground(java.awt.SystemColor.controlHighlight); - ivjPass2Button.setBounds(100, 100, 300, 30); - ivjPass2Button.setActionCommand("Button2"); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjPass2Button; -} - -/** Machine-generated. */ -private javax.swing.JPanel getPass2Panel() { - if (ivjPass2Panel == null) { - try { - ivjPass2Panel = new javax.swing.JPanel(); - ivjPass2Panel.setName("Pass2Panel"); - ivjPass2Panel.setLayout(null); - ivjPass2Panel.setBackground(java.awt.SystemColor.controlShadow); - ivjPass2Panel.setBounds(30, 90, 50, 50); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjPass2Panel; -} - -/** Machine-generated. */ -private javax.swing.JButton getPass3Button() { - if (ivjPass3Button == null) { - try { - ivjPass3Button = new javax.swing.JButton(); - ivjPass3Button.setName("Pass3Button"); - ivjPass3Button.setText("Passes 3a+3b: Verify code arrays"); - ivjPass3Button.setBackground(java.awt.SystemColor.controlHighlight); - ivjPass3Button.setBounds(100, 160, 300, 30); - ivjPass3Button.setActionCommand("Button2"); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjPass3Button; -} - -/** Machine-generated. */ -private javax.swing.JPanel getPass3Panel() { - if (ivjPass3Panel == null) { - try { - ivjPass3Panel = new javax.swing.JPanel(); - ivjPass3Panel.setName("Pass3Panel"); - ivjPass3Panel.setLayout(null); - ivjPass3Panel.setBackground(java.awt.SystemColor.controlShadow); - ivjPass3Panel.setBounds(30, 150, 50, 50); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjPass3Panel; -} - -/** Machine-generated. */ -private void handleException(java.lang.Throwable exception) { - - /* Uncomment the following lines to print uncaught exceptions to stdout */ - System.out.println("--------- UNCAUGHT EXCEPTION ---------"); - exception.printStackTrace(System.out); -} - - -/** Machine-generated. */ -private void initConnections() throws java.lang.Exception { - // user code begin {1} - // user code end - getPass1Button().addActionListener(ivjEventHandler); - getPass2Button().addActionListener(ivjEventHandler); - getPass3Button().addActionListener(ivjEventHandler); - getFlushButton().addActionListener(ivjEventHandler); -} - -/** Machine-generated. */ -private void initialize() { - try { - // user code begin {1} - // user code end - setName("VerifyDialog"); - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - setSize(430, 280); - setVisible(true); - setModal(true); - setResizable(false); - setContentPane(getJDialogContentPane()); - initConnections(); - } catch (java.lang.Throwable ivjExc) { - handleException(ivjExc); - } - // user code begin {2} - setTitle("'"+class_name+"' verification - JustIce / BCEL"); - // user code end -} -/** - * Verifies one or more class files. - * Verification results are presented graphically: Red means 'rejected', - * green means 'passed' while yellow means 'could not be verified yet'. - * @param args java.lang.String[] fully qualified names of classes to verify. - */ -public static void main(java.lang.String[] args) { - classes_to_verify = args.length; - - for (int i=0; i. + */ + +import java.awt.Color; + +import org.aspectj.apache.bcel.Repository; +import org.aspectj.apache.bcel.classfile.JavaClass; + +/** + * A class for simple graphical class file verification. + * Use the main(String []) method with fully qualified + * class names as arguments to use it as a stand-alone + * application. + * Use the VerifyDialog(String) constructor to use this + * class in your application. + * [This class was created using VisualAge for Java, + * but it does not work under VAJ itself (Version 3.02 JDK 1.2)] + * @version $Id: VerifyDialog.java,v 1.1.2.1 2008/05/08 19:26:47 aclement Exp $ + * @author Enver Haase + * @see #main(String[]) + * @see #VerifyDialog(String) + */ +public class VerifyDialog extends javax.swing.JDialog { + /** Machine-generated. */ + private javax.swing.JPanel ivjJDialogContentPane = null; + /** Machine-generated. */ + private javax.swing.JPanel ivjPass1Panel = null; + /** Machine-generated. */ + private javax.swing.JPanel ivjPass2Panel = null; + /** Machine-generated. */ + private javax.swing.JPanel ivjPass3Panel = null; + /** Machine-generated. */ + private javax.swing.JButton ivjPass1Button = null; + /** Machine-generated. */ + private javax.swing.JButton ivjPass2Button = null; + /** Machine-generated. */ + private javax.swing.JButton ivjPass3Button = null; + /** Machine-generated. */ + IvjEventHandler ivjEventHandler = new IvjEventHandler(); + + /** + * The class to verify. Default set to 'java.lang.Object' + * in case this class is instantiated via one of the many + * machine-generated constructors. + */ + private String class_name = "java.lang.Object"; + + /** + * This field is here to count the number of open VerifyDialog + * instances so the JVM can be exited afer every Dialog had been + * closed. + */ + private static int classes_to_verify; + +/** Machine-generated. */ +class IvjEventHandler implements java.awt.event.ActionListener { + public void actionPerformed(java.awt.event.ActionEvent e) { + if (e.getSource() == VerifyDialog.this.getPass1Button()) + connEtoC1(e); + if (e.getSource() == VerifyDialog.this.getPass2Button()) + connEtoC2(e); + if (e.getSource() == VerifyDialog.this.getPass3Button()) + connEtoC3(e); + if (e.getSource() == VerifyDialog.this.getFlushButton()) + connEtoC4(e); + }; + }; + /** Machine-generated. */ + private javax.swing.JButton ivjFlushButton = null; +/** Machine-generated. */ +public VerifyDialog() { + super(); + initialize(); +} + +/** Machine-generated. */ +public VerifyDialog(java.awt.Dialog owner) { + super(owner); +} + +/** Machine-generated. */ +public VerifyDialog(java.awt.Dialog owner, String title) { + super(owner, title); +} + +/** Machine-generated. */ +public VerifyDialog(java.awt.Dialog owner, String title, boolean modal) { + super(owner, title, modal); +} + +/** Machine-generated. */ +public VerifyDialog(java.awt.Dialog owner, boolean modal) { + super(owner, modal); +} + +/** Machine-generated. */ +public VerifyDialog(java.awt.Frame owner) { + super(owner); +} + +/** Machine-generated. */ +public VerifyDialog(java.awt.Frame owner, String title) { + super(owner, title); +} + +/** Machine-generated. */ +public VerifyDialog(java.awt.Frame owner, String title, boolean modal) { + super(owner, title, modal); +} + +/** Machine-generated. */ +public VerifyDialog(java.awt.Frame owner, boolean modal) { + super(owner, modal); +} + +/** + * Use this constructor if you want a possibility to verify other + * class files than java.lang.Object. + * @param fully_qualified_class_name java.lang.String + */ +public VerifyDialog(String fully_qualified_class_name) { + super(); + + int dotclasspos = fully_qualified_class_name.lastIndexOf(".class"); + if (dotclasspos != -1) fully_qualified_class_name = fully_qualified_class_name.substring(0,dotclasspos); + fully_qualified_class_name = fully_qualified_class_name.replace('/', '.'); + + class_name = fully_qualified_class_name; + initialize(); +} + + +/** Machine-generated. */ +private void connEtoC1(java.awt.event.ActionEvent arg1) { + try { + // user code begin {1} + // user code end + this.pass1Button_ActionPerformed(arg1); + // user code begin {2} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {3} + // user code end + handleException(ivjExc); + } +} + +/** Machine-generated. */ +private void connEtoC2(java.awt.event.ActionEvent arg1) { + try { + // user code begin {1} + // user code end + this.pass2Button_ActionPerformed(arg1); + // user code begin {2} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {3} + // user code end + handleException(ivjExc); + } +} + +/** Machine-generated. */ +private void connEtoC3(java.awt.event.ActionEvent arg1) { + try { + // user code begin {1} + // user code end + this.pass4Button_ActionPerformed(arg1); + // user code begin {2} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {3} + // user code end + handleException(ivjExc); + } +} + +/** Machine-generated. */ +private void connEtoC4(java.awt.event.ActionEvent arg1) { + try { + // user code begin {1} + // user code end + this.flushButton_ActionPerformed(arg1); + // user code begin {2} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {3} + // user code end + handleException(ivjExc); + } +} + +/** Machine-generated. */ +public void flushButton_ActionPerformed(java.awt.event.ActionEvent actionEvent) { + VerifierFactory.getVerifier(class_name).flush(); + Repository.removeClass(class_name); // Make sure it will be reloaded. + getPass1Panel().setBackground(Color.gray); + getPass1Panel().repaint(); + getPass2Panel().setBackground(Color.gray); + getPass2Panel().repaint(); + getPass3Panel().setBackground(Color.gray); + getPass3Panel().repaint(); +} + +/** Machine-generated. */ +private javax.swing.JButton getFlushButton() { + if (ivjFlushButton == null) { + try { + ivjFlushButton = new javax.swing.JButton(); + ivjFlushButton.setName("FlushButton"); + ivjFlushButton.setText("Flush: Forget old verification results"); + ivjFlushButton.setBackground(java.awt.SystemColor.controlHighlight); + ivjFlushButton.setBounds(60, 215, 300, 30); + ivjFlushButton.setForeground(java.awt.Color.red); + ivjFlushButton.setActionCommand("FlushButton"); + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjFlushButton; +} + +/** Machine-generated. */ +private javax.swing.JPanel getJDialogContentPane() { + if (ivjJDialogContentPane == null) { + try { + ivjJDialogContentPane = new javax.swing.JPanel(); + ivjJDialogContentPane.setName("JDialogContentPane"); + ivjJDialogContentPane.setLayout(null); + getJDialogContentPane().add(getPass1Panel(), getPass1Panel().getName()); + getJDialogContentPane().add(getPass3Panel(), getPass3Panel().getName()); + getJDialogContentPane().add(getPass2Panel(), getPass2Panel().getName()); + getJDialogContentPane().add(getPass1Button(), getPass1Button().getName()); + getJDialogContentPane().add(getPass2Button(), getPass2Button().getName()); + getJDialogContentPane().add(getPass3Button(), getPass3Button().getName()); + getJDialogContentPane().add(getFlushButton(), getFlushButton().getName()); + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjJDialogContentPane; +} + +/** Machine-generated. */ +private javax.swing.JButton getPass1Button() { + if (ivjPass1Button == null) { + try { + ivjPass1Button = new javax.swing.JButton(); + ivjPass1Button.setName("Pass1Button"); + ivjPass1Button.setText("Pass1: Verify binary layout of .class file"); + ivjPass1Button.setBackground(java.awt.SystemColor.controlHighlight); + ivjPass1Button.setBounds(100, 40, 300, 30); + ivjPass1Button.setActionCommand("Button1"); + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjPass1Button; +} + +/** Machine-generated. */ +private javax.swing.JPanel getPass1Panel() { + if (ivjPass1Panel == null) { + try { + ivjPass1Panel = new javax.swing.JPanel(); + ivjPass1Panel.setName("Pass1Panel"); + ivjPass1Panel.setLayout(null); + ivjPass1Panel.setBackground(java.awt.SystemColor.controlShadow); + ivjPass1Panel.setBounds(30, 30, 50, 50); + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjPass1Panel; +} + +/** Machine-generated. */ +private javax.swing.JButton getPass2Button() { + if (ivjPass2Button == null) { + try { + ivjPass2Button = new javax.swing.JButton(); + ivjPass2Button.setName("Pass2Button"); + ivjPass2Button.setText("Pass 2: Verify static .class file constraints"); + ivjPass2Button.setBackground(java.awt.SystemColor.controlHighlight); + ivjPass2Button.setBounds(100, 100, 300, 30); + ivjPass2Button.setActionCommand("Button2"); + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjPass2Button; +} + +/** Machine-generated. */ +private javax.swing.JPanel getPass2Panel() { + if (ivjPass2Panel == null) { + try { + ivjPass2Panel = new javax.swing.JPanel(); + ivjPass2Panel.setName("Pass2Panel"); + ivjPass2Panel.setLayout(null); + ivjPass2Panel.setBackground(java.awt.SystemColor.controlShadow); + ivjPass2Panel.setBounds(30, 90, 50, 50); + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjPass2Panel; +} + +/** Machine-generated. */ +private javax.swing.JButton getPass3Button() { + if (ivjPass3Button == null) { + try { + ivjPass3Button = new javax.swing.JButton(); + ivjPass3Button.setName("Pass3Button"); + ivjPass3Button.setText("Passes 3a+3b: Verify code arrays"); + ivjPass3Button.setBackground(java.awt.SystemColor.controlHighlight); + ivjPass3Button.setBounds(100, 160, 300, 30); + ivjPass3Button.setActionCommand("Button2"); + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjPass3Button; +} + +/** Machine-generated. */ +private javax.swing.JPanel getPass3Panel() { + if (ivjPass3Panel == null) { + try { + ivjPass3Panel = new javax.swing.JPanel(); + ivjPass3Panel.setName("Pass3Panel"); + ivjPass3Panel.setLayout(null); + ivjPass3Panel.setBackground(java.awt.SystemColor.controlShadow); + ivjPass3Panel.setBounds(30, 150, 50, 50); + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjPass3Panel; +} + +/** Machine-generated. */ +private void handleException(java.lang.Throwable exception) { + + /* Uncomment the following lines to print uncaught exceptions to stdout */ + System.out.println("--------- UNCAUGHT EXCEPTION ---------"); + exception.printStackTrace(System.out); +} + + +/** Machine-generated. */ +private void initConnections() throws java.lang.Exception { + // user code begin {1} + // user code end + getPass1Button().addActionListener(ivjEventHandler); + getPass2Button().addActionListener(ivjEventHandler); + getPass3Button().addActionListener(ivjEventHandler); + getFlushButton().addActionListener(ivjEventHandler); +} + +/** Machine-generated. */ +private void initialize() { + try { + // user code begin {1} + // user code end + setName("VerifyDialog"); + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setSize(430, 280); + setVisible(true); + setModal(true); + setResizable(false); + setContentPane(getJDialogContentPane()); + initConnections(); + } catch (java.lang.Throwable ivjExc) { + handleException(ivjExc); + } + // user code begin {2} + setTitle("'"+class_name+"' verification - JustIce / BCEL"); + // user code end +} +/** + * Verifies one or more class files. + * Verification results are presented graphically: Red means 'rejected', + * green means 'passed' while yellow means 'could not be verified yet'. + * @param args java.lang.String[] fully qualified names of classes to verify. + */ +public static void main(java.lang.String[] args) { + classes_to_verify = args.length; + + for (int i=0; i. - */ - -/** - * Instances of this class should never be thrown. When such an instance is thrown, - * this is due to an INTERNAL ERROR of BCEL's class file verifier "JustIce". - * - * @version $Id: AssertionViolatedException.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public final class AssertionViolatedException extends RuntimeException{ - /** The error message. */ - private String detailMessage; - /** Constructs a new AssertionViolatedException with null as its error message string. */ - public AssertionViolatedException(){ - super(); - } - /** - * Constructs a new AssertionViolatedException with the specified error message preceded - * by "INTERNAL ERROR: ". - */ - public AssertionViolatedException(String message){ - super(message = "INTERNAL ERROR: "+message); // Thanks to Java, the constructor call here must be first. - detailMessage=message; - } - /** Extends the error message with a string before ("pre") and after ("post") the - 'old' error message. All of these three strings are allowed to be null, and null - is always replaced by the empty string (""). In particular, after invoking this - method, the error message of this object can no longer be null. - */ - public void extendMessage(String pre, String post){ - if (pre == null) pre=""; - if (detailMessage == null) detailMessage=""; - if (post == null) post=""; - detailMessage = pre+detailMessage+post; - } - /** - * Returns the error message string of this AssertionViolatedException object. - * @return the error message string of this AssertionViolatedException. - */ - public String getMessage(){ - return detailMessage; - } - - /** - * DO NOT USE. It's for experimental testing during development only. - */ - public static void main(String[] args){ - AssertionViolatedException ave = new AssertionViolatedException("Oops!"); - ave.extendMessage("\nFOUND:\n\t","\nExiting!!\n"); - throw ave; - } - -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Instances of this class should never be thrown. When such an instance is thrown, + * this is due to an INTERNAL ERROR of BCEL's class file verifier "JustIce". + * + * @version $Id: AssertionViolatedException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public final class AssertionViolatedException extends RuntimeException{ + /** The error message. */ + private String detailMessage; + /** Constructs a new AssertionViolatedException with null as its error message string. */ + public AssertionViolatedException(){ + super(); + } + /** + * Constructs a new AssertionViolatedException with the specified error message preceded + * by "INTERNAL ERROR: ". + */ + public AssertionViolatedException(String message){ + super(message = "INTERNAL ERROR: "+message); // Thanks to Java, the constructor call here must be first. + detailMessage=message; + } + /** Extends the error message with a string before ("pre") and after ("post") the + 'old' error message. All of these three strings are allowed to be null, and null + is always replaced by the empty string (""). In particular, after invoking this + method, the error message of this object can no longer be null. + */ + public void extendMessage(String pre, String post){ + if (pre == null) pre=""; + if (detailMessage == null) detailMessage=""; + if (post == null) post=""; + detailMessage = pre+detailMessage+post; + } + /** + * Returns the error message string of this AssertionViolatedException object. + * @return the error message string of this AssertionViolatedException. + */ + public String getMessage(){ + return detailMessage; + } + + /** + * DO NOT USE. It's for experimental testing during development only. + */ + public static void main(String[] args){ + AssertionViolatedException ave = new AssertionViolatedException("Oops!"); + ave.extendMessage("\nFOUND:\n\t","\nExiting!!\n"); + throw ave; + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/ClassConstraintException.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/ClassConstraintException.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/ClassConstraintException.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/ClassConstraintException.java index 2c2c1b5f9..50b949ecf 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/ClassConstraintException.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/ClassConstraintException.java @@ -1,79 +1,79 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Instances of this class are thrown by BCEL's class file verifier "JustIce" - * when a class file to verify does not pass the verification pass 2 as described - * in the Java Virtual Machine specification, 2nd edition. - * - * @version $Id: ClassConstraintException.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public class ClassConstraintException extends VerificationException{ - /** - * Constructs a new ClassConstraintException with null as its error message string. - */ - public ClassConstraintException(){ - super(); - } - - /** - * Constructs a new ClassConstraintException with the specified error message. - */ - public ClassConstraintException(String message){ - super (message); - } -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Instances of this class are thrown by BCEL's class file verifier "JustIce" + * when a class file to verify does not pass the verification pass 2 as described + * in the Java Virtual Machine specification, 2nd edition. + * + * @version $Id: ClassConstraintException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class ClassConstraintException extends VerificationException{ + /** + * Constructs a new ClassConstraintException with null as its error message string. + */ + public ClassConstraintException(){ + super(); + } + + /** + * Constructs a new ClassConstraintException with the specified error message. + */ + public ClassConstraintException(String message){ + super (message); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/CodeConstraintException.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/CodeConstraintException.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/CodeConstraintException.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/CodeConstraintException.java index e86259d58..292028d5c 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/CodeConstraintException.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/CodeConstraintException.java @@ -1,77 +1,77 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -/** - * Instances of this class are thrown by BCEL's class file verifier "JustIce" when - * a class file does not pass the verification pass 3. Note that the pass 3 used by - * "JustIce" involves verification that is usually delayed to pass 4. - * - * @version $Id: CodeConstraintException.java,v 1.2.10.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - */ -public abstract class CodeConstraintException extends VerificationException{ - /** - * Constructs a new CodeConstraintException with null as its error message string. - */ - CodeConstraintException(){ - super(); - } - /** - * Constructs a new CodeConstraintException with the specified error message. - */ - CodeConstraintException(String message){ - super(message); - } -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +/** + * Instances of this class are thrown by BCEL's class file verifier "JustIce" when + * a class file does not pass the verification pass 3. Note that the pass 3 used by + * "JustIce" involves verification that is usually delayed to pass 4. + * + * @version $Id: CodeConstraintException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public abstract class CodeConstraintException extends VerificationException{ + /** + * Constructs a new CodeConstraintException with null as its error message string. + */ + CodeConstraintException(){ + super(); + } + /** + * Constructs a new CodeConstraintException with the specified error message. + */ + CodeConstraintException(String message){ + super(message); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/InvalidMethodException.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/InvalidMethodException.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/InvalidMethodException.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/InvalidMethodException.java index c2153183e..a9c38214b 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/InvalidMethodException.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/InvalidMethodException.java @@ -1,69 +1,69 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -/** - * Instances of this class are thrown by BCEL's class file verifier "JustIce" - * when the verification of a method is requested that does not exist. - * - * @version $Id: InvalidMethodException.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public class InvalidMethodException extends RuntimeException{ - - /** Constructs an InvalidMethodException with the specified detail message. */ - public InvalidMethodException(String message){ - super(message); - } -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +/** + * Instances of this class are thrown by BCEL's class file verifier "JustIce" + * when the verification of a method is requested that does not exist. + * + * @version $Id: InvalidMethodException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class InvalidMethodException extends RuntimeException{ + + /** Constructs an InvalidMethodException with the specified detail message. */ + public InvalidMethodException(String message){ + super(message); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/LinkingConstraintException.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/LinkingConstraintException.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/LinkingConstraintException.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/LinkingConstraintException.java index 51614d352..dc66608bb 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/LinkingConstraintException.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/LinkingConstraintException.java @@ -1,74 +1,74 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -/** - * Instances of this class are thrown by BCEL's class file verifier "JustIce" when - * a class file to verify does not pass the verification pass 3 because of a violation - * of a constraint that is usually only verified at run-time (pass 4). - * The Java Virtual Machine Specification, 2nd edition, states that certain constraints - * are usually verified at run-time for performance reasons (the verification of those - * constraints requires loading in and recursively verifying referenced classes) that - * conceptually belong to pass 3; to be precise, that conceptually belong to the - * data flow analysis of pass 3 (called pass 3b in JustIce). - * These are the checks necessary for resolution: Compare pages 142-143 ("4.9.1 The - * Verification Process") and pages 50-51 ("2.17.3 Linking: Verification, Preparation, - * and Resolution") of the above mentioned book. - * TODO: At this time, this class is not used in JustIce. - * - * @version $Id: LinkingConstraintException.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public class LinkingConstraintException extends StructuralCodeConstraintException{ -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +/** + * Instances of this class are thrown by BCEL's class file verifier "JustIce" when + * a class file to verify does not pass the verification pass 3 because of a violation + * of a constraint that is usually only verified at run-time (pass 4). + * The Java Virtual Machine Specification, 2nd edition, states that certain constraints + * are usually verified at run-time for performance reasons (the verification of those + * constraints requires loading in and recursively verifying referenced classes) that + * conceptually belong to pass 3; to be precise, that conceptually belong to the + * data flow analysis of pass 3 (called pass 3b in JustIce). + * These are the checks necessary for resolution: Compare pages 142-143 ("4.9.1 The + * Verification Process") and pages 50-51 ("2.17.3 Linking: Verification, Preparation, + * and Resolution") of the above mentioned book. + * TODO: At this time, this class is not used in JustIce. + * + * @version $Id: LinkingConstraintException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class LinkingConstraintException extends StructuralCodeConstraintException{ +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/LoadingException.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/LoadingException.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/LoadingException.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/LoadingException.java index 6bb5d66db..6a677db0f 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/LoadingException.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/LoadingException.java @@ -1,79 +1,79 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * When loading a class file, BCEL will throw an instance of LoadingException if - * the class file is malformed; so it is not conforming to the "Pass 1" verification - * process as described in the Java Virtual Machine specification, 2nd. edition. - * @version $Id: LoadingException.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public class LoadingException extends VerifierConstraintViolatedException{ - - /** - * Constructs a new LoadingException with null as its error message string. - */ - public LoadingException(){ - super(); - } - - /** - * Constructs a new LoadingException with the specified error message. - */ - public LoadingException(String message){ - super (message); - } -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * When loading a class file, BCEL will throw an instance of LoadingException if + * the class file is malformed; so it is not conforming to the "Pass 1" verification + * process as described in the Java Virtual Machine specification, 2nd. edition. + * @version $Id: LoadingException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class LoadingException extends VerifierConstraintViolatedException{ + + /** + * Constructs a new LoadingException with null as its error message string. + */ + public LoadingException(){ + super(); + } + + /** + * Constructs a new LoadingException with the specified error message. + */ + public LoadingException(String message){ + super (message); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/LocalVariableInfoInconsistentException.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/LocalVariableInfoInconsistentException.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/LocalVariableInfoInconsistentException.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/LocalVariableInfoInconsistentException.java index 59602494a..efe05d5f7 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/LocalVariableInfoInconsistentException.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/LocalVariableInfoInconsistentException.java @@ -1,81 +1,81 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * A LocalVariableInfoInconsistentException instance is thrown by - * the LocalVariableInfo class when it detects that the information - * it holds is inconsistent; this is normally due to inconsistent - * LocalVariableTable entries in the Code attribute of a certain - * Method object. - * - * @version $Id: LocalVariableInfoInconsistentException.java,v 1.2.10.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - */ -public class LocalVariableInfoInconsistentException extends ClassConstraintException{ - /** - * Constructs a new LocalVariableInfoInconsistentException with null as its error message string. - */ - public LocalVariableInfoInconsistentException(){ - super(); - } - - /** - * Constructs a new LocalVariableInfoInconsistentException with the specified error message. - */ - public LocalVariableInfoInconsistentException(String message){ - super (message); - } -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * A LocalVariableInfoInconsistentException instance is thrown by + * the LocalVariableInfo class when it detects that the information + * it holds is inconsistent; this is normally due to inconsistent + * LocalVariableTable entries in the Code attribute of a certain + * Method object. + * + * @version $Id: LocalVariableInfoInconsistentException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class LocalVariableInfoInconsistentException extends ClassConstraintException{ + /** + * Constructs a new LocalVariableInfoInconsistentException with null as its error message string. + */ + public LocalVariableInfoInconsistentException(){ + super(); + } + + /** + * Constructs a new LocalVariableInfoInconsistentException with the specified error message. + */ + public LocalVariableInfoInconsistentException(String message){ + super (message); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/StaticCodeConstraintException.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/StaticCodeConstraintException.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/StaticCodeConstraintException.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/StaticCodeConstraintException.java index 7d0333db6..609905c19 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/StaticCodeConstraintException.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/StaticCodeConstraintException.java @@ -1,71 +1,71 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Instances of this class are thrown by BCEL's class file verifier "JustIce" when - * a class file to verify does not pass the verification pass 3 because of a violation - * of a static constraint as described in the Java Virtual Machine Specification, - * 2nd edition, 4.8.1, pages 133-137. The static constraints checking part of pass 3 - * is called pass 3a in JustIce. - * - * @version $Id: StaticCodeConstraintException.java,v 1.2.10.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - */ -public abstract class StaticCodeConstraintException extends CodeConstraintException{ - public StaticCodeConstraintException(String message){ - super(message); - } -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Instances of this class are thrown by BCEL's class file verifier "JustIce" when + * a class file to verify does not pass the verification pass 3 because of a violation + * of a static constraint as described in the Java Virtual Machine Specification, + * 2nd edition, 4.8.1, pages 133-137. The static constraints checking part of pass 3 + * is called pass 3a in JustIce. + * + * @version $Id: StaticCodeConstraintException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public abstract class StaticCodeConstraintException extends CodeConstraintException{ + public StaticCodeConstraintException(String message){ + super(message); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionConstraintException.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionConstraintException.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionConstraintException.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionConstraintException.java index caa7f23eb..0315a541c 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionConstraintException.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionConstraintException.java @@ -1,74 +1,74 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Instances of this class are thrown by BCEL's class file verifier "JustIce" when - * a class file to verify does not pass the verification pass 3 because of a violation - * of a static constraint as described in the Java Virtual Machine Specification, - * Second edition, 4.8.1, pages 133-137. The static constraints checking part of pass 3 - * is called pass 3a in JustIce. - * Static constraints on the instructions in the code array are checked early in - * pass 3a and are described on page 134 in the Java Virtual Machine Specification, - * Second Edition. - * - * @version $Id: StaticCodeInstructionConstraintException.java,v 1.2.10.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - */ -public class StaticCodeInstructionConstraintException extends StaticCodeConstraintException{ - public StaticCodeInstructionConstraintException(String message){ - super(message); - } -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Instances of this class are thrown by BCEL's class file verifier "JustIce" when + * a class file to verify does not pass the verification pass 3 because of a violation + * of a static constraint as described in the Java Virtual Machine Specification, + * Second edition, 4.8.1, pages 133-137. The static constraints checking part of pass 3 + * is called pass 3a in JustIce. + * Static constraints on the instructions in the code array are checked early in + * pass 3a and are described on page 134 in the Java Virtual Machine Specification, + * Second Edition. + * + * @version $Id: StaticCodeInstructionConstraintException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class StaticCodeInstructionConstraintException extends StaticCodeConstraintException{ + public StaticCodeInstructionConstraintException(String message){ + super(message); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionOperandConstraintException.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionOperandConstraintException.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionOperandConstraintException.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionOperandConstraintException.java index b41302a25..ff6b55c00 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionOperandConstraintException.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/StaticCodeInstructionOperandConstraintException.java @@ -1,74 +1,74 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Instances of this class are thrown by BCEL's class file verifier "JustIce" when - * a class file to verify does not pass the verification pass 3 because of a violation - * of a static constraint as described in the Java Virtual Machine Specification, - * Second edition, 4.8.1, pages 133-137. The static constraints checking part of pass 3 - * is called pass 3a in JustIce. - * Static constraints on the operands of instructions in the code array are checked late in - * pass 3a and are described on page 134-137 in the Java Virtual Machine Specification, - * Second Edition. - * - * @version $Id: StaticCodeInstructionOperandConstraintException.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public class StaticCodeInstructionOperandConstraintException extends StaticCodeConstraintException{ - public StaticCodeInstructionOperandConstraintException(String message){ - super(message); - } -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Instances of this class are thrown by BCEL's class file verifier "JustIce" when + * a class file to verify does not pass the verification pass 3 because of a violation + * of a static constraint as described in the Java Virtual Machine Specification, + * Second edition, 4.8.1, pages 133-137. The static constraints checking part of pass 3 + * is called pass 3a in JustIce. + * Static constraints on the operands of instructions in the code array are checked late in + * pass 3a and are described on page 134-137 in the Java Virtual Machine Specification, + * Second Edition. + * + * @version $Id: StaticCodeInstructionOperandConstraintException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class StaticCodeInstructionOperandConstraintException extends StaticCodeConstraintException{ + public StaticCodeInstructionOperandConstraintException(String message){ + super(message); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/StructuralCodeConstraintException.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/StructuralCodeConstraintException.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/StructuralCodeConstraintException.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/StructuralCodeConstraintException.java index 8c183e69c..7cd07b56d 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/StructuralCodeConstraintException.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/StructuralCodeConstraintException.java @@ -1,82 +1,82 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -/** - * Instances of this class are thrown by BCEL's class file verifier "JustIce" when - * a class file to verify does not pass the verification pass 3 because of a violation - * of a structural constraint as described in the Java Virtual Machine Specification, - * 2nd edition, 4.8.2, pages 137-139. - * Note that the notion of a "structural" constraint is somewhat misleading. Structural - * constraints are constraints on relationships between Java virtual machine instructions. - * These are the constraints where data-flow analysis is needed to verify if they hold. - * The data flow analysis of pass 3 is called pass 3b in JustIce. - * - * @version $Id: StructuralCodeConstraintException.java,v 1.2.10.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - */ -public class StructuralCodeConstraintException extends CodeConstraintException{ - /** - * Constructs a new StructuralCodeConstraintException with the specified error message. - */ - public StructuralCodeConstraintException(String message){ - super(message); - } - /** - * Constructs a new StructuralCodeConstraintException with null as its error message string. - */ - public StructuralCodeConstraintException(){ - super(); - } -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +/** + * Instances of this class are thrown by BCEL's class file verifier "JustIce" when + * a class file to verify does not pass the verification pass 3 because of a violation + * of a structural constraint as described in the Java Virtual Machine Specification, + * 2nd edition, 4.8.2, pages 137-139. + * Note that the notion of a "structural" constraint is somewhat misleading. Structural + * constraints are constraints on relationships between Java virtual machine instructions. + * These are the constraints where data-flow analysis is needed to verify if they hold. + * The data flow analysis of pass 3 is called pass 3b in JustIce. + * + * @version $Id: StructuralCodeConstraintException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class StructuralCodeConstraintException extends CodeConstraintException{ + /** + * Constructs a new StructuralCodeConstraintException with the specified error message. + */ + public StructuralCodeConstraintException(String message){ + super(message); + } + /** + * Constructs a new StructuralCodeConstraintException with null as its error message string. + */ + public StructuralCodeConstraintException(){ + super(); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/Utility.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/Utility.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/Utility.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/Utility.java index bce41a4e0..b50a1eba7 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/Utility.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/Utility.java @@ -1,76 +1,76 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.*; - -/** - * A utility class providing convenience methods concerning Throwable instances. - * @version $Id: Utility.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - * @see java.lang.Throwable - */ -public final class Utility{ - /** This class is not instantiable. */ - private Utility(){} - - /** This method returns the stack trace of a Throwable instance as a String. */ - public static String getStackTrace(Throwable t){ - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - t.printStackTrace(pw); - return sw.toString(); - } -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.*; + +/** + * A utility class providing convenience methods concerning Throwable instances. + * @version $Id: Utility.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + * @see java.lang.Throwable + */ +public final class Utility{ + /** This class is not instantiable. */ + private Utility(){} + + /** This method returns the stack trace of a Throwable instance as a String. */ + public static String getStackTrace(Throwable t){ + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + t.printStackTrace(pw); + return sw.toString(); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/VerificationException.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/VerificationException.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/VerificationException.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/VerificationException.java index 94c500a51..19581153d 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/VerificationException.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/VerificationException.java @@ -1,82 +1,82 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Instances of this class are thrown by BCEL's class file verifier "JustIce" when a - * class file to verify does not pass one of the verification passes 2 or 3. - * Note that the pass 3 used by "JustIce" involves verification that is usually - * delayed to pass 4. - * The name of this class is justified by the Java Virtual Machine Specification, 2nd - * edition, page 164, 5.4.1 where verification as a part of the linking process is - * defined to be the verification happening in passes 2 and 3. - * - * @version $Id: VerificationException.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public abstract class VerificationException extends VerifierConstraintViolatedException{ - /** - * Constructs a new VerificationException with null as its error message string. - */ - VerificationException(){ - super(); - } - /** - * Constructs a new VerificationException with the specified error message. - */ - VerificationException(String message){ - super(message); - } -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Instances of this class are thrown by BCEL's class file verifier "JustIce" when a + * class file to verify does not pass one of the verification passes 2 or 3. + * Note that the pass 3 used by "JustIce" involves verification that is usually + * delayed to pass 4. + * The name of this class is justified by the Java Virtual Machine Specification, 2nd + * edition, page 164, 5.4.1 where verification as a part of the linking process is + * defined to be the verification happening in passes 2 and 3. + * + * @version $Id: VerificationException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public abstract class VerificationException extends VerifierConstraintViolatedException{ + /** + * Constructs a new VerificationException with null as its error message string. + */ + VerificationException(){ + super(); + } + /** + * Constructs a new VerificationException with the specified error message. + */ + VerificationException(String message){ + super(message); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/VerifierConstraintViolatedException.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/VerifierConstraintViolatedException.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/VerifierConstraintViolatedException.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/VerifierConstraintViolatedException.java index 8cc5efe98..9172d5cb5 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/exc/VerifierConstraintViolatedException.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/exc/VerifierConstraintViolatedException.java @@ -1,107 +1,107 @@ -package org.aspectj.apache.bcel.verifier.exc; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Instances of this class are thrown by BCEL's class file verifier "JustIce" - * whenever - * verification proves that some constraint of a class file (as stated in the - * Java Virtual Machine Specification, Edition 2) is violated. - * This is roughly equivalent to the VerifyError the JVM-internal verifiers - * throw. - * - * @version $Id: VerifierConstraintViolatedException.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public abstract class VerifierConstraintViolatedException extends RuntimeException{ - // /** The name of the offending class that did not pass the verifier. */ - // String name_of_offending_class; - - /** The specified error message. */ - private String detailMessage; - /** - * Constructs a new VerifierConstraintViolatedException with null as its error message string. - */ - VerifierConstraintViolatedException(){ - super(); - } - /** - * Constructs a new VerifierConstraintViolatedException with the specified error message. - */ - VerifierConstraintViolatedException(String message){ - super(message); // Not that important - detailMessage = message; - } - - - /** Extends the error message with a string before ("pre") and after ("post") the - 'old' error message. All of these three strings are allowed to be null, and null - is always replaced by the empty string (""). In particular, after invoking this - method, the error message of this object can no longer be null. - */ - public void extendMessage(String pre, String post){ - if (pre == null) pre=""; - if (detailMessage == null) detailMessage=""; - if (post == null) post=""; - detailMessage = pre+detailMessage+post; - } - /** - * Returns the error message string of this VerifierConstraintViolatedException object. - * @return the error message string of this VerifierConstraintViolatedException. - */ - public String getMessage(){ - return detailMessage; - } -} +package org.aspectj.apache.bcel.verifier.exc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Instances of this class are thrown by BCEL's class file verifier "JustIce" + * whenever + * verification proves that some constraint of a class file (as stated in the + * Java Virtual Machine Specification, Edition 2) is violated. + * This is roughly equivalent to the VerifyError the JVM-internal verifiers + * throw. + * + * @version $Id: VerifierConstraintViolatedException.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public abstract class VerifierConstraintViolatedException extends RuntimeException{ + // /** The name of the offending class that did not pass the verifier. */ + // String name_of_offending_class; + + /** The specified error message. */ + private String detailMessage; + /** + * Constructs a new VerifierConstraintViolatedException with null as its error message string. + */ + VerifierConstraintViolatedException(){ + super(); + } + /** + * Constructs a new VerifierConstraintViolatedException with the specified error message. + */ + VerifierConstraintViolatedException(String message){ + super(message); // Not that important + detailMessage = message; + } + + + /** Extends the error message with a string before ("pre") and after ("post") the + 'old' error message. All of these three strings are allowed to be null, and null + is always replaced by the empty string (""). In particular, after invoking this + method, the error message of this object can no longer be null. + */ + public void extendMessage(String pre, String post){ + if (pre == null) pre=""; + if (detailMessage == null) detailMessage=""; + if (post == null) post=""; + detailMessage = pre+detailMessage+post; + } + /** + * Returns the error message string of this VerifierConstraintViolatedException object. + * @return the error message string of this VerifierConstraintViolatedException. + */ + public String getMessage(){ + return detailMessage; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/package.html b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/package.html similarity index 87% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/package.html rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/package.html index d5879092b..f41638ba0 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/package.html +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/package.html @@ -1,25 +1,25 @@ - - - - - - - -BCEL's verifier JustIce is there to help you dump correct Java class files created or modified with BCEL. - -

          Package Specification

          - -This is the top-level package of the JustIce verifier. To actually use it, have a look at the VerifierFactory and -Verifier classes. - -

          Related Documentation

          - -For a simple demonstration of JustIce working, please see: - - - - + + + + + + + +BCEL's verifier JustIce is there to help you dump correct Java class files created or modified with BCEL. + +

          Package Specification

          + +This is the top-level package of the JustIce verifier. To actually use it, have a look at the VerifierFactory and +Verifier classes. + +

          Related Documentation

          + +For a simple demonstration of JustIce working, please see: + + + + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/DOUBLE_Upper.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/DOUBLE_Upper.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/DOUBLE_Upper.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/DOUBLE_Upper.java index 495964c38..befafb95a 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/DOUBLE_Upper.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/DOUBLE_Upper.java @@ -1,79 +1,79 @@ -package org.aspectj.apache.bcel.verifier.statics; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.generic.Type; - -/** - * This class represents the upper half of a DOUBLE variable. - * @version $Id: DOUBLE_Upper.java,v 1.2.10.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - */ -public final class DOUBLE_Upper extends Type{ - - /** The one and only instance of this class. */ - private static DOUBLE_Upper singleInstance = new DOUBLE_Upper(); - - /** The constructor; this class must not be instantiated from the outside. */ - private DOUBLE_Upper(){ - super(Constants.T_UNKNOWN, "Long_Upper"); - } - - /** Use this method to get the single instance of this class. */ - public static DOUBLE_Upper theInstance(){ - return singleInstance; - } -} +package org.aspectj.apache.bcel.verifier.statics; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.generic.Type; + +/** + * This class represents the upper half of a DOUBLE variable. + * @version $Id: DOUBLE_Upper.java,v 1.1.2.1 2008/05/08 19:26:52 aclement Exp $ + * @author Enver Haase + */ +public final class DOUBLE_Upper extends Type{ + + /** The one and only instance of this class. */ + private static DOUBLE_Upper singleInstance = new DOUBLE_Upper(); + + /** The constructor; this class must not be instantiated from the outside. */ + private DOUBLE_Upper(){ + super(Constants.T_UNKNOWN, "Long_Upper"); + } + + /** Use this method to get the single instance of this class. */ + public static DOUBLE_Upper theInstance(){ + return singleInstance; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/IntList.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/IntList.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/IntList.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/IntList.java index 2bf3e3393..9c990eaf2 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/IntList.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/IntList.java @@ -1,85 +1,85 @@ -package org.aspectj.apache.bcel.verifier.statics; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.ArrayList; - -/** - * A small utility class representing a set of basic int values. - * - * @version $Id: IntList.java,v 1.2.10.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - */ -public class IntList{ - /** The int are stored as Integer objects here. */ - private ArrayList theList; - /** This constructor creates an empty list. */ - IntList(){ - theList = new ArrayList(); - } - /** Adds an element to the list. */ - void add(int i){ - theList.add(new Integer(i)); - } - /** Checks if the specified int is already in the list. */ - boolean contains(int i){ - Integer[] ints = new Integer[theList.size()]; - theList.toArray(ints); - for (int j=0; j. + */ + +import java.util.ArrayList; + +/** + * A small utility class representing a set of basic int values. + * + * @version $Id: IntList.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class IntList{ + /** The int are stored as Integer objects here. */ + private ArrayList theList; + /** This constructor creates an empty list. */ + IntList(){ + theList = new ArrayList(); + } + /** Adds an element to the list. */ + void add(int i){ + theList.add(new Integer(i)); + } + /** Checks if the specified int is already in the list. */ + boolean contains(int i){ + Integer[] ints = new Integer[theList.size()]; + theList.toArray(ints); + for (int j=0; j. - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.generic.Type; - -/** - * This class represents the upper half of a LONG variable. - * @version $Id: LONG_Upper.java,v 1.2.10.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - */ -public final class LONG_Upper extends Type{ - - /** The one and only instance of this class. */ - private static LONG_Upper singleInstance = new LONG_Upper(); - - /** The constructor; this class must not be instantiated from the outside. */ - private LONG_Upper(){ - super(Constants.T_UNKNOWN, "Long_Upper"); - } - - /** Use this method to get the single instance of this class. */ - public static LONG_Upper theInstance(){ - return singleInstance; - } -} +package org.aspectj.apache.bcel.verifier.statics; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.generic.Type; + +/** + * This class represents the upper half of a LONG variable. + * @version $Id: LONG_Upper.java,v 1.1.2.1 2008/05/08 19:26:52 aclement Exp $ + * @author Enver Haase + */ +public final class LONG_Upper extends Type{ + + /** The one and only instance of this class. */ + private static LONG_Upper singleInstance = new LONG_Upper(); + + /** The constructor; this class must not be instantiated from the outside. */ + private LONG_Upper(){ + super(Constants.T_UNKNOWN, "Long_Upper"); + } + + /** Use this method to get the single instance of this class. */ + public static LONG_Upper theInstance(){ + return singleInstance; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/LocalVariableInfo.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/LocalVariableInfo.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/LocalVariableInfo.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/LocalVariableInfo.java index b4b2edb4c..e95336adb 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/LocalVariableInfo.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/LocalVariableInfo.java @@ -1,144 +1,144 @@ -package org.aspectj.apache.bcel.verifier.statics; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.generic.Type; -import org.aspectj.apache.bcel.verifier.exc.*; -import java.util.Hashtable; - -/** - * A utility class holding the information about - * the name and the type of a local variable in - * a given slot (== index). This information - * often changes in course of byte code offsets. - * - * @version $Id: LocalVariableInfo.java,v 1.2.10.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - */ -public class LocalVariableInfo{ - - /** The types database. KEY: String representing the offset integer. */ - private Hashtable types = new Hashtable(); - /** The names database. KEY: String representing the offset integer. */ - private Hashtable names = new Hashtable(); - - /** - * Adds a name of a local variable and a certain slot to our 'names' - * (Hashtable) database. - */ - private void setName(int offset, String name){ - names.put( ((Integer.toString(offset))), name); - } - /** - * Adds a type of a local variable and a certain slot to our 'types' - * (Hashtable) database. - */ - private void setType(int offset, Type t){ - types.put( ((Integer.toString(offset))), t); - } - - /** - * Returns the type of the local variable that uses this local - * variable slot at the given bytecode offset. - * Care for legal bytecode offsets yourself, otherwise the return value - * might be wrong. - * May return 'null' if nothing is known about the type of this local - * variable slot at the given bytecode offset. - */ - public Type getType(int offset){ - return (Type) types.get(Integer.toString(offset)); - } - /** - * Returns the name of the local variable that uses this local - * variable slot at the given bytecode offset. - * Care for legal bytecode offsets yourself, otherwise the return value - * might be wrong. - * May return 'null' if nothing is known about the type of this local - * variable slot at the given bytecode offset. - */ - public String getName(int offset){ - return (String) (names.get(Integer.toString(offset))); - } - /** - * Adds some information about this local variable (slot). - * @throws LocalVariableInfoInconsistentException if the new information conflicts - * with already gathered information. - */ - public void add(String name, int startpc, int length, Type t) throws LocalVariableInfoInconsistentException{ - for (int i=startpc; i<=startpc+length; i++){ // incl/incl-notation! - add(i,name,t); - } - } - - /** - * Adds information about name and type for a given offset. - * @throws LocalVariableInfoInconsistentException if the new information conflicts - * with already gathered information. - */ - private void add(int offset, String name, Type t) throws LocalVariableInfoInconsistentException{ - if (getName(offset) != null){ - if (! getName(offset).equals(name)){ - throw new LocalVariableInfoInconsistentException("At bytecode offset '"+offset+"' a local variable has two different names: '"+getName(offset)+"' and '"+name+"'."); - } - } - if (getType(offset) != null){ - if (! getType(offset).equals(t)){ - throw new LocalVariableInfoInconsistentException("At bytecode offset '"+offset+"' a local variable has two different types: '"+getType(offset)+"' and '"+t+"'."); - } - } - setName(offset, name); - setType(offset, t); - } -} +package org.aspectj.apache.bcel.verifier.statics; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.generic.Type; +import org.aspectj.apache.bcel.verifier.exc.*; +import java.util.Hashtable; + +/** + * A utility class holding the information about + * the name and the type of a local variable in + * a given slot (== index). This information + * often changes in course of byte code offsets. + * + * @version $Id: LocalVariableInfo.java,v 1.1.2.1 2008/05/08 19:26:52 aclement Exp $ + * @author Enver Haase + */ +public class LocalVariableInfo{ + + /** The types database. KEY: String representing the offset integer. */ + private Hashtable types = new Hashtable(); + /** The names database. KEY: String representing the offset integer. */ + private Hashtable names = new Hashtable(); + + /** + * Adds a name of a local variable and a certain slot to our 'names' + * (Hashtable) database. + */ + private void setName(int offset, String name){ + names.put( ((Integer.toString(offset))), name); + } + /** + * Adds a type of a local variable and a certain slot to our 'types' + * (Hashtable) database. + */ + private void setType(int offset, Type t){ + types.put( ((Integer.toString(offset))), t); + } + + /** + * Returns the type of the local variable that uses this local + * variable slot at the given bytecode offset. + * Care for legal bytecode offsets yourself, otherwise the return value + * might be wrong. + * May return 'null' if nothing is known about the type of this local + * variable slot at the given bytecode offset. + */ + public Type getType(int offset){ + return (Type) types.get(Integer.toString(offset)); + } + /** + * Returns the name of the local variable that uses this local + * variable slot at the given bytecode offset. + * Care for legal bytecode offsets yourself, otherwise the return value + * might be wrong. + * May return 'null' if nothing is known about the type of this local + * variable slot at the given bytecode offset. + */ + public String getName(int offset){ + return (String) (names.get(Integer.toString(offset))); + } + /** + * Adds some information about this local variable (slot). + * @throws LocalVariableInfoInconsistentException if the new information conflicts + * with already gathered information. + */ + public void add(String name, int startpc, int length, Type t) throws LocalVariableInfoInconsistentException{ + for (int i=startpc; i<=startpc+length; i++){ // incl/incl-notation! + add(i,name,t); + } + } + + /** + * Adds information about name and type for a given offset. + * @throws LocalVariableInfoInconsistentException if the new information conflicts + * with already gathered information. + */ + private void add(int offset, String name, Type t) throws LocalVariableInfoInconsistentException{ + if (getName(offset) != null){ + if (! getName(offset).equals(name)){ + throw new LocalVariableInfoInconsistentException("At bytecode offset '"+offset+"' a local variable has two different names: '"+getName(offset)+"' and '"+name+"'."); + } + } + if (getType(offset) != null){ + if (! getType(offset).equals(t)){ + throw new LocalVariableInfoInconsistentException("At bytecode offset '"+offset+"' a local variable has two different types: '"+getType(offset)+"' and '"+t+"'."); + } + } + setName(offset, name); + setType(offset, t); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/LocalVariablesInfo.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/LocalVariablesInfo.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/LocalVariablesInfo.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/LocalVariablesInfo.java index e53e4410b..25ba4a111 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/LocalVariablesInfo.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/LocalVariablesInfo.java @@ -1,106 +1,106 @@ -package org.aspectj.apache.bcel.verifier.statics; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.generic.Type; -import org.aspectj.apache.bcel.verifier.exc.*; - -/** - * A utility class holding the information about - * the names and the types of the local variables in - * a given method. - * - * @version $Id: LocalVariablesInfo.java,v 1.2.10.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - */ -public class LocalVariablesInfo{ - - /** The information about the local variables is stored here. */ - private LocalVariableInfo[] localVariableInfos; - - /** The constructor. */ - LocalVariablesInfo(int max_locals){ - localVariableInfos = new LocalVariableInfo[max_locals]; - for (int i=0; i= localVariableInfos.length){ - throw new AssertionViolatedException("Slot number for local variable information out of range."); - } - return localVariableInfos[slot]; - } - - /** - * Adds information about the local variable in slot 'slot'. Automatically - * adds information for slot+1 if 't' is Type.LONG or Type.DOUBLE. - * @throws LocalVariableInfoInconsistentException if the new information conflicts - * with already gathered information. - */ - public void add(int slot, String name, int startpc, int length, Type t) throws LocalVariableInfoInconsistentException{ - // The add operation on LocalVariableInfo may throw the '...Inconsistent...' exception, we don't throw it explicitely here. - - if (slot < 0 || slot >= localVariableInfos.length){ - throw new AssertionViolatedException("Slot number for local variable information out of range."); - } - - localVariableInfos[slot].add(name, startpc, length, t); - if (t == Type.LONG) localVariableInfos[slot+1].add(name, startpc, length, LONG_Upper.theInstance()); - if (t == Type.DOUBLE) localVariableInfos[slot+1].add(name, startpc, length, DOUBLE_Upper.theInstance()); - } -} +package org.aspectj.apache.bcel.verifier.statics; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.generic.Type; +import org.aspectj.apache.bcel.verifier.exc.*; + +/** + * A utility class holding the information about + * the names and the types of the local variables in + * a given method. + * + * @version $Id: LocalVariablesInfo.java,v 1.1.2.1 2008/05/08 19:26:52 aclement Exp $ + * @author Enver Haase + */ +public class LocalVariablesInfo{ + + /** The information about the local variables is stored here. */ + private LocalVariableInfo[] localVariableInfos; + + /** The constructor. */ + LocalVariablesInfo(int max_locals){ + localVariableInfos = new LocalVariableInfo[max_locals]; + for (int i=0; i= localVariableInfos.length){ + throw new AssertionViolatedException("Slot number for local variable information out of range."); + } + return localVariableInfos[slot]; + } + + /** + * Adds information about the local variable in slot 'slot'. Automatically + * adds information for slot+1 if 't' is Type.LONG or Type.DOUBLE. + * @throws LocalVariableInfoInconsistentException if the new information conflicts + * with already gathered information. + */ + public void add(int slot, String name, int startpc, int length, Type t) throws LocalVariableInfoInconsistentException{ + // The add operation on LocalVariableInfo may throw the '...Inconsistent...' exception, we don't throw it explicitely here. + + if (slot < 0 || slot >= localVariableInfos.length){ + throw new AssertionViolatedException("Slot number for local variable information out of range."); + } + + localVariableInfos[slot].add(name, startpc, length, t); + if (t == Type.LONG) localVariableInfos[slot+1].add(name, startpc, length, LONG_Upper.theInstance()); + if (t == Type.DOUBLE) localVariableInfos[slot+1].add(name, startpc, length, DOUBLE_Upper.theInstance()); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/Pass1Verifier.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/Pass1Verifier.java similarity index 97% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/Pass1Verifier.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/Pass1Verifier.java index 7a30ec002..0a1d33510 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/Pass1Verifier.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/Pass1Verifier.java @@ -1,215 +1,215 @@ -package org.aspectj.apache.bcel.verifier.statics; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.verifier.PassVerifier; -import org.aspectj.apache.bcel.verifier.VerificationResult; -import org.aspectj.apache.bcel.verifier.Verifier; -import org.aspectj.apache.bcel.verifier.exc.LoadingException; -import org.aspectj.apache.bcel.verifier.exc.Utility; - -/** - * This PassVerifier verifies a class file according to pass 1 as - * described in The Java Virtual Machine Specification, 2nd edition. - * More detailed information is to be found at the do_verify() method's - * documentation. - * - * @version $Id: Pass1Verifier.java,v 1.3.10.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - * @see #do_verify() - */ -public final class Pass1Verifier extends PassVerifier{ - /** - * DON'T USE THIS EVEN PRIVATELY! USE getJavaClass() INSTEAD. - * @see #getJavaClass() - */ - private JavaClass jc; - - /** - * The Verifier that created this. - */ - private Verifier myOwner; - - /** Used to load in and return the myOwner-matching JavaClass object when needed. Avoids loading in a class file when it's not really needed! */ - private JavaClass getJavaClass(){ - if (jc == null){ - jc = Repository.lookupClass(myOwner.getClassName()); - } - return jc; - } - - /** - * Should only be instantiated by a Verifier. - * - * @see org.aspectj.apache.bcel.verifier.Verifier - */ - public Pass1Verifier(Verifier owner){ - myOwner = owner; - } - - /** - * Pass-one verification basically means loading in a class file. - * The Java Virtual Machine Specification is not too precise about - * what makes the difference between passes one and two. - * The answer is that only pass one is performed on a class file as - * long as its resolution is not requested; whereas pass two and - * pass three are performed during the resolution process. - * Only four constraints to be checked are explicitely stated by - * The Java Virtual Machine Specification, 2nd edition: - *
            - *
          • The first four bytes must contain the right magic number (0xCAFEBABE). - *
          • All recognized attributes must be of the proper length. - *
          • The class file must not be truncated or have extra bytes at the end. - *
          • The constant pool must not contain any superficially unrecognizable information. - *
          - * A more in-depth documentation of what pass one should do was written by - * Philip W. L. Fong: - *
            - *
          • the file should not be truncated. - *
          • the file should not have extra bytes at the end. - *
          • all variable-length structures should be well-formatted: - *
              - *
            • there should only be constant_pool_count-1 many entries in the constant pool. - *
            • all constant pool entries should have size the same as indicated by their type tag. - *
            • there are exactly interfaces_count many entries in the interfaces array of the class file. - *
            • there are exactly fields_count many entries in the fields array of the class file. - *
            • there are exactly methods_count many entries in the methods array of the class file. - *
            • there are exactly attributes_count many entries in the attributes array of the class file, fields, methods, and code attribute. - *
            • there should be exactly attribute_length many bytes in each attribute. Inconsistency between attribute_length and the actually size of the attribute content should be uncovered. For example, in an Exceptions attribute, the actual number of exceptions as required by the number_of_exceptions field might yeild an attribute size that doesn't match the attribute_length. Such an anomaly should be detected. - *
            • all attributes should have proper length. In particular, under certain context (e.g. while parsing method_info), recognizable attributes (e.g. "Code" attribute) should have correct format (e.g. attribute_length is 2). - *
            - *
          • Also, certain constant values are checked for validity: - *
              - *
            • The magic number should be 0xCAFEBABE. - *
            • The major and minor version numbers are valid. - *
            • All the constant pool type tags are recognizable. - *
            • All undocumented access flags are masked off before use. Strictly speaking, this is not really a check. - *
            • The field this_class should point to a string that represents a legal non-array class name, and this name should be the same as the class file being loaded. - *
            • the field super_class should point to a string that represents a legal non-array class name. - *
            • Because some of the above checks require cross referencing the constant pool entries, guards are set up to make sure that the referenced entries are of the right type and the indices are within the legal range (0 < index < constant_pool_count). - *
            - *
          • Extra checks done in pass 1: - *
              - *
            • the constant values of static fields should have the same type as the fields. - *
            • the number of words in a parameter list does not exceed 255 and locals_max. - *
            • the name and signature of fields and methods are verified to be of legal format. - *
            - *
          - * (From the Paper The Mysterious Pass One, first draft, September 2, 1997.) - *
          - * However, most of this is done by parsing a class file or generating a class file into BCEL's internal data structure. - * Therefore, all that is really done here is look up the class file from BCEL's repository. - * This is also motivated by the fact that some omitted things - * (like the check for extra bytes at the end of the class file) are handy when actually using BCEL to repair a class file (otherwise you would not be - * able to load it into BCEL). - * - * @see org.aspectj.apache.bcel.Repository - */ - public VerificationResult do_verify(){ - JavaClass jc; - try{ - jc = getJavaClass(); //loads in the class file if not already done. - - if (jc != null){ - /* If we find more constraints to check, we should do this in an own method. */ - if (! myOwner.getClassName().equals(jc.getClassName())){ - // This should maybe caught by BCEL: In case of renamed .class files we get wrong - // JavaClass objects here. - throw new LoadingException("Wrong name: the internal name of the .class file '"+jc.getClassName()+"' does not match the file's name '"+myOwner.getClassName()+"'."); - } - } - - } - catch(LoadingException e){ - return new VerificationResult(VerificationResult.VERIFIED_REJECTED, e.getMessage()); - } - catch(ClassFormatError e){ - // BCEL sometimes is a little harsh describing exceptual situations. - return new VerificationResult(VerificationResult.VERIFIED_REJECTED, e.getMessage()); - } - catch(RuntimeException e){ - // BCEL does not catch every possible RuntimeException; e.g. if - // a constant pool index is referenced that does not exist. - return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Parsing via BCEL did not succeed. "+e.getClass().getName()+" occured:\n"+Utility.getStackTrace(e)); - } - - if (jc != null){ - return VerificationResult.VR_OK; - } - else{ - //TODO: Maybe change Repository's behaviour to throw a LoadingException instead of just returning "null" - // if a class file cannot be found or in another way be looked up. - return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Repository.lookup() failed. FILE NOT FOUND?"); - } - } - - /** - * Currently this returns an empty array of String. - * One could parse the error messages of BCEL - * (written to java.lang.System.err) when loading - * a class file such as detecting unknown attributes - * or trailing garbage at the end of a class file. - * However, Markus Dahm does not like the idea so this - * method is currently useless and therefore marked as - * TODO. - */ - public String[] getMessages(){ - // This method is only here to override the javadoc-comment. - return super.getMessages(); - } - -} +package org.aspectj.apache.bcel.verifier.statics; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Repository; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.verifier.PassVerifier; +import org.aspectj.apache.bcel.verifier.VerificationResult; +import org.aspectj.apache.bcel.verifier.Verifier; +import org.aspectj.apache.bcel.verifier.exc.LoadingException; +import org.aspectj.apache.bcel.verifier.exc.Utility; + +/** + * This PassVerifier verifies a class file according to pass 1 as + * described in The Java Virtual Machine Specification, 2nd edition. + * More detailed information is to be found at the do_verify() method's + * documentation. + * + * @version $Id: Pass1Verifier.java,v 1.1.2.1 2008/05/08 19:26:52 aclement Exp $ + * @author Enver Haase + * @see #do_verify() + */ +public final class Pass1Verifier extends PassVerifier{ + /** + * DON'T USE THIS EVEN PRIVATELY! USE getJavaClass() INSTEAD. + * @see #getJavaClass() + */ + private JavaClass jc; + + /** + * The Verifier that created this. + */ + private Verifier myOwner; + + /** Used to load in and return the myOwner-matching JavaClass object when needed. Avoids loading in a class file when it's not really needed! */ + private JavaClass getJavaClass(){ + if (jc == null){ + jc = Repository.lookupClass(myOwner.getClassName()); + } + return jc; + } + + /** + * Should only be instantiated by a Verifier. + * + * @see org.aspectj.apache.bcel.verifier.Verifier + */ + public Pass1Verifier(Verifier owner){ + myOwner = owner; + } + + /** + * Pass-one verification basically means loading in a class file. + * The Java Virtual Machine Specification is not too precise about + * what makes the difference between passes one and two. + * The answer is that only pass one is performed on a class file as + * long as its resolution is not requested; whereas pass two and + * pass three are performed during the resolution process. + * Only four constraints to be checked are explicitely stated by + * The Java Virtual Machine Specification, 2nd edition: + *
            + *
          • The first four bytes must contain the right magic number (0xCAFEBABE). + *
          • All recognized attributes must be of the proper length. + *
          • The class file must not be truncated or have extra bytes at the end. + *
          • The constant pool must not contain any superficially unrecognizable information. + *
          + * A more in-depth documentation of what pass one should do was written by + * Philip W. L. Fong: + *
            + *
          • the file should not be truncated. + *
          • the file should not have extra bytes at the end. + *
          • all variable-length structures should be well-formatted: + *
              + *
            • there should only be constant_pool_count-1 many entries in the constant pool. + *
            • all constant pool entries should have size the same as indicated by their type tag. + *
            • there are exactly interfaces_count many entries in the interfaces array of the class file. + *
            • there are exactly fields_count many entries in the fields array of the class file. + *
            • there are exactly methods_count many entries in the methods array of the class file. + *
            • there are exactly attributes_count many entries in the attributes array of the class file, fields, methods, and code attribute. + *
            • there should be exactly attribute_length many bytes in each attribute. Inconsistency between attribute_length and the actually size of the attribute content should be uncovered. For example, in an Exceptions attribute, the actual number of exceptions as required by the number_of_exceptions field might yeild an attribute size that doesn't match the attribute_length. Such an anomaly should be detected. + *
            • all attributes should have proper length. In particular, under certain context (e.g. while parsing method_info), recognizable attributes (e.g. "Code" attribute) should have correct format (e.g. attribute_length is 2). + *
            + *
          • Also, certain constant values are checked for validity: + *
              + *
            • The magic number should be 0xCAFEBABE. + *
            • The major and minor version numbers are valid. + *
            • All the constant pool type tags are recognizable. + *
            • All undocumented access flags are masked off before use. Strictly speaking, this is not really a check. + *
            • The field this_class should point to a string that represents a legal non-array class name, and this name should be the same as the class file being loaded. + *
            • the field super_class should point to a string that represents a legal non-array class name. + *
            • Because some of the above checks require cross referencing the constant pool entries, guards are set up to make sure that the referenced entries are of the right type and the indices are within the legal range (0 < index < constant_pool_count). + *
            + *
          • Extra checks done in pass 1: + *
              + *
            • the constant values of static fields should have the same type as the fields. + *
            • the number of words in a parameter list does not exceed 255 and locals_max. + *
            • the name and signature of fields and methods are verified to be of legal format. + *
            + *
          + * (From the Paper The Mysterious Pass One, first draft, September 2, 1997.) + *
          + * However, most of this is done by parsing a class file or generating a class file into BCEL's internal data structure. + * Therefore, all that is really done here is look up the class file from BCEL's repository. + * This is also motivated by the fact that some omitted things + * (like the check for extra bytes at the end of the class file) are handy when actually using BCEL to repair a class file (otherwise you would not be + * able to load it into BCEL). + * + * @see org.aspectj.apache.bcel.Repository + */ + public VerificationResult do_verify(){ + JavaClass jc; + try{ + jc = getJavaClass(); //loads in the class file if not already done. + + if (jc != null){ + /* If we find more constraints to check, we should do this in an own method. */ + if (! myOwner.getClassName().equals(jc.getClassName())){ + // This should maybe caught by BCEL: In case of renamed .class files we get wrong + // JavaClass objects here. + throw new LoadingException("Wrong name: the internal name of the .class file '"+jc.getClassName()+"' does not match the file's name '"+myOwner.getClassName()+"'."); + } + } + + } + catch(LoadingException e){ + return new VerificationResult(VerificationResult.VERIFIED_REJECTED, e.getMessage()); + } + catch(ClassFormatError e){ + // BCEL sometimes is a little harsh describing exceptual situations. + return new VerificationResult(VerificationResult.VERIFIED_REJECTED, e.getMessage()); + } + catch(RuntimeException e){ + // BCEL does not catch every possible RuntimeException; e.g. if + // a constant pool index is referenced that does not exist. + return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Parsing via BCEL did not succeed. "+e.getClass().getName()+" occured:\n"+Utility.getStackTrace(e)); + } + + if (jc != null){ + return VerificationResult.VR_OK; + } + else{ + //TODO: Maybe change Repository's behaviour to throw a LoadingException instead of just returning "null" + // if a class file cannot be found or in another way be looked up. + return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Repository.lookup() failed. FILE NOT FOUND?"); + } + } + + /** + * Currently this returns an empty array of String. + * One could parse the error messages of BCEL + * (written to java.lang.System.err) when loading + * a class file such as detecting unknown attributes + * or trailing garbage at the end of a class file. + * However, Markus Dahm does not like the idea so this + * method is currently useless and therefore marked as + * TODO. + */ + public String[] getMessages(){ + // This method is only here to override the javadoc-comment. + return super.getMessages(); + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/Pass2Verifier.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/Pass2Verifier.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/Pass2Verifier.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/Pass2Verifier.java index a4f21acdb..aa83130ac 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/Pass2Verifier.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/Pass2Verifier.java @@ -1,1374 +1,1374 @@ -package org.aspectj.apache.bcel.verifier.statics; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.HashMap; -import java.util.HashSet; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.Attribute; -import org.aspectj.apache.bcel.classfile.Code; -import org.aspectj.apache.bcel.classfile.CodeException; -import org.aspectj.apache.bcel.classfile.Constant; -import org.aspectj.apache.bcel.classfile.ConstantClass; -import org.aspectj.apache.bcel.classfile.ConstantDouble; -import org.aspectj.apache.bcel.classfile.ConstantFieldref; -import org.aspectj.apache.bcel.classfile.ConstantFloat; -import org.aspectj.apache.bcel.classfile.ConstantInteger; -import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref; -import org.aspectj.apache.bcel.classfile.ConstantLong; -import org.aspectj.apache.bcel.classfile.ConstantMethodref; -import org.aspectj.apache.bcel.classfile.ConstantNameAndType; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.ConstantString; -import org.aspectj.apache.bcel.classfile.ConstantUtf8; -import org.aspectj.apache.bcel.classfile.ConstantValue; -import org.aspectj.apache.bcel.classfile.Deprecated; -import org.aspectj.apache.bcel.classfile.DescendingVisitor; -import org.aspectj.apache.bcel.classfile.EmptyVisitor; -import org.aspectj.apache.bcel.classfile.ExceptionTable; -import org.aspectj.apache.bcel.classfile.Field; -import org.aspectj.apache.bcel.classfile.InnerClass; -import org.aspectj.apache.bcel.classfile.InnerClasses; -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.classfile.LineNumber; -import org.aspectj.apache.bcel.classfile.LineNumberTable; -import org.aspectj.apache.bcel.classfile.LocalVariable; -import org.aspectj.apache.bcel.classfile.LocalVariableTable; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.classfile.Node; -import org.aspectj.apache.bcel.classfile.SourceFile; -import org.aspectj.apache.bcel.classfile.Synthetic; -import org.aspectj.apache.bcel.classfile.Unknown; -import org.aspectj.apache.bcel.classfile.Visitor; -import org.aspectj.apache.bcel.generic.ArrayType; -import org.aspectj.apache.bcel.generic.ObjectType; -import org.aspectj.apache.bcel.generic.Type; -import org.aspectj.apache.bcel.verifier.PassVerifier; -import org.aspectj.apache.bcel.verifier.VerificationResult; -import org.aspectj.apache.bcel.verifier.Verifier; -import org.aspectj.apache.bcel.verifier.VerifierFactory; -import org.aspectj.apache.bcel.verifier.exc.AssertionViolatedException; -import org.aspectj.apache.bcel.verifier.exc.ClassConstraintException; -import org.aspectj.apache.bcel.verifier.exc.LocalVariableInfoInconsistentException; - -/** - * This PassVerifier verifies a class file according to - * pass 2 as described in The Java Virtual Machine - * Specification, 2nd edition. - * More detailed information is to be found at the do_verify() - * method's documentation. - * - * @version $Id: Pass2Verifier.java,v 1.3.10.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - * @see #do_verify() - */ -public final class Pass2Verifier extends PassVerifier implements Constants{ - - /** - * The LocalVariableInfo instances used by Pass3bVerifier. - * localVariablesInfos[i] denotes the information for the - * local variables of method number i in the - * JavaClass this verifier operates on. - */ - private LocalVariablesInfo[] localVariablesInfos; - - /** The Verifier that created this. */ - private Verifier myOwner; - - /** - * Should only be instantiated by a Verifier. - * - * @see Verifier - */ - public Pass2Verifier(Verifier owner){ - myOwner = owner; - } - - /** - * Returns a LocalVariablesInfo object containing information - * about the usage of the local variables in the Code attribute - * of the said method or null if the class file this - * Pass2Verifier operates on could not be pass-2-verified correctly. - * The method number method_nr is the method you get using - * Repository.lookupClass(myOwner.getClassname()).getMethods()[method_nr];. - * You should not add own information. Leave that to JustIce. - */ - public LocalVariablesInfo getLocalVariablesInfo(int method_nr){ - if (this.verify() != VerificationResult.VR_OK) return null; // It's cached, don't worry. - if (method_nr < 0 || method_nr >= localVariablesInfos.length){ - throw new AssertionViolatedException("Method number out of range."); - } - return localVariablesInfos[method_nr]; - } - - /** - * Pass 2 is the pass where static properties of the - * class file are checked without looking into "Code" - * arrays of methods. - * This verification pass is usually invoked when - * a class is resolved; and it may be possible that - * this verification pass has to load in other classes - * such as superclasses or implemented interfaces. - * Therefore, Pass 1 is run on them.
          - * Note that most referenced classes are not loaded - * in for verification or for an existance check by this - * pass; only the syntactical correctness of their names - * and descriptors (a.k.a. signatures) is checked.
          - * Very few checks that conceptually belong here - * are delayed until pass 3a in JustIce. JustIce does - * not only check for syntactical correctness but also - * for semantical sanity - therefore it needs access to - * the "Code" array of methods in a few cases. Please - * see the pass 3a documentation, too. - * - * @see org.aspectj.apache.bcel.verifier.statics.Pass3aVerifier - */ - public VerificationResult do_verify(){ - VerificationResult vr1 = myOwner.doPass1(); - if (vr1.equals(VerificationResult.VR_OK)){ - - // For every method, we could have information about the local variables out of LocalVariableTable attributes of - // the Code attributes. - localVariablesInfos = new LocalVariablesInfo[Repository.lookupClass(myOwner.getClassName()).getMethods().length]; - - VerificationResult vr = VerificationResult.VR_OK; // default. - try{ - constant_pool_entries_satisfy_static_constraints(); - field_and_method_refs_are_valid(); - every_class_has_an_accessible_superclass(); - final_methods_are_not_overridden(); - } - catch (ClassConstraintException cce){ - vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, cce.getMessage()); - } - return vr; - } - else - return VerificationResult.VR_NOTYET; - } - - /** - * Ensures that every class has a super class and that - * final classes are not subclassed. - * This means, the class this Pass2Verifier operates - * on has proper super classes (transitively) up to - * java.lang.Object. - * The reason for really loading (and Pass1-verifying) - * all of those classes here is that we need them in - * Pass2 anyway to verify no final methods are overridden - * (that could be declared anywhere in the ancestor hierarchy). - * - * @throws ClassConstraintException otherwise. - */ - private void every_class_has_an_accessible_superclass(){ - HashSet hs = new HashSet(); // save class names to detect circular inheritance - JavaClass jc = Repository.lookupClass(myOwner.getClassName()); - int supidx = -1; - - while (supidx != 0){ - supidx = jc.getSuperclassNameIndex(); - - if (supidx == 0){ - if (jc != Repository.lookupClass(Type.OBJECT.getClassName())){ - throw new ClassConstraintException("Superclass of '"+jc.getClassName()+"' missing but not "+Type.OBJECT.getClassName()+" itself!"); - } - } - else{ - String supername = jc.getSuperclassName(); - if (! hs.add(supername)){ // If supername already is in the list - throw new ClassConstraintException("Circular superclass hierarchy detected."); - } - Verifier v = VerifierFactory.getVerifier(supername); - VerificationResult vr = v.doPass1(); - - if (vr != VerificationResult.VR_OK){ - throw new ClassConstraintException("Could not load in ancestor class '"+supername+"'."); - } - jc = Repository.lookupClass(supername); - - if (jc.isFinal()){ - throw new ClassConstraintException("Ancestor class '"+supername+"' has the FINAL access modifier and must therefore not be subclassed."); - } - } - } - } - - /** - * Ensures that final methods are not overridden. - * Precondition to run this method: - * constant_pool_entries_satisfy_static_constraints() and - * every_class_has_an_accessible_superclass() have to be invoked before - * (in that order). - * - * @throws ClassConstraintException otherwise. - * @see #constant_pool_entries_satisfy_static_constraints() - * @see #every_class_has_an_accessible_superclass() - */ - private void final_methods_are_not_overridden(){ - HashMap hashmap = new HashMap(); - JavaClass jc = Repository.lookupClass(myOwner.getClassName()); - - int supidx = -1; - while (supidx != 0){ - supidx = jc.getSuperclassNameIndex(); - - Method[] methods = jc.getMethods(); - for (int i=0; i= cplen)){ - throw new ClassConstraintException("Invalid index '"+index+"' used by '"+tostring(referrer)+"'."); - } - Constant c = cp.getConstant(index); - if (! shouldbe.isInstance(c)){ - /* String isnot = shouldbe.toString().substring(shouldbe.toString().lastIndexOf(".")+1); //Cut all before last "." */ - throw new ClassCastException("Illegal constant '"+tostring(c)+"' at index '"+index+"'. '"+tostring(referrer)+"' expects a '"+shouldbe+"'."); - } - } - /////////////////////////////////////// - // ClassFile structure (vmspec2 4.1) // - /////////////////////////////////////// - public void visitJavaClass(JavaClass obj){ - Attribute[] atts = obj.getAttributes(); - boolean foundSourceFile = false; - boolean foundInnerClasses = false; - - // Is there an InnerClass referenced? - // This is a costly check; existing verifiers don't do it! - boolean hasInnerClass = new InnerClassDetector(jc).innerClassReferenced(); - - for (int i=0; i 1){ - throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set."); - } - - if (obj.isFinal() && obj.isVolatile()){ - throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_FINAL, ACC_VOLATILE modifiers set."); - } - } - else{ // isInterface! - if (!obj.isPublic()){ - throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_PUBLIC modifier set but hasn't!"); - } - if (!obj.isStatic()){ - throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_STATIC modifier set but hasn't!"); - } - if (!obj.isFinal()){ - throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_FINAL modifier set but hasn't!"); - } - } - - if ((obj.getAccessFlags() & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_VOLATILE|ACC_TRANSIENT)) > 0){ - addMessage("Field '"+tostring(obj)+"' has access flag(s) other than ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_VOLATILE, ACC_TRANSIENT set (ignored)."); - } - - checkIndex(obj, obj.getNameIndex(), CONST_Utf8); - - String name = obj.getName(); - if (! validFieldName(name)){ - throw new ClassConstraintException("Field '"+tostring(obj)+"' has illegal name '"+obj.getName()+"'."); - } - - // A descriptor is often named signature in BCEL - checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8); - - String sig = ((ConstantUtf8) (cp.getConstant(obj.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor) - - try{ - Type.getType(sig); /* Don't need the return value */ - } - catch (ClassFormatError cfe){ // sometimes BCEL is a little harsh describing exceptional situations. - throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'."); - } - - String nameanddesc = (name+sig); - if (field_names_and_desc.contains(nameanddesc)){ - throw new ClassConstraintException("No two fields (like '"+tostring(obj)+"') are allowed have same names and descriptors!"); - } - if (field_names.contains(name)){ - addMessage("More than one field of name '"+name+"' detected (but with different type descriptors). This is very unusual."); - } - field_names_and_desc.add(nameanddesc); - field_names.add(name); - - Attribute[] atts = obj.getAttributes(); - for (int i=0; i 1){ - throw new ClassConstraintException("Method '"+tostring(obj)+"' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set."); - } - - if (obj.isAbstract()){ - if (obj.isFinal()) throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_FINAL modifier set."); - if (obj.isNative()) throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_NATIVE modifier set."); - if (obj.isPrivate()) throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_PRIVATE modifier set."); - if (obj.isStatic()) throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_STATIC modifier set."); - if (obj.isStrictfp()) throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_STRICT modifier set."); - if (obj.isSynchronized()) throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_SYNCHRONIZED modifier set."); - } - } - else{ // isInterface! - if (!name.equals(STATIC_INITIALIZER_NAME)){//vmspec2, p.116, 2nd paragraph - if (!obj.isPublic()){ - throw new ClassConstraintException("Interface method '"+tostring(obj)+"' must have the ACC_PUBLIC modifier set but hasn't!"); - } - if (!obj.isAbstract()){ - throw new ClassConstraintException("Interface method '"+tostring(obj)+"' must have the ACC_STATIC modifier set but hasn't!"); - } - if ( obj.isPrivate() || - obj.isProtected() || - obj.isStatic() || - obj.isFinal() || - obj.isSynchronized() || - obj.isNative() || - obj.isStrictfp() ){ - throw new ClassConstraintException("Interface method '"+tostring(obj)+"' must not have any of the ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT modifiers set."); - } - } - } - - // A specific instance initialization method... (vmspec2,Page 116). - if (name.equals(CONSTRUCTOR_NAME)){ - //..may have at most one of ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC set: is checked above. - //..may also have ACC_STRICT set, but none of the other flags in table 4.5 (vmspec2, page 115) - if ( obj.isStatic() || - obj.isFinal() || - obj.isSynchronized() || - obj.isNative() || - obj.isAbstract() ){ - throw new ClassConstraintException("Instance initialization method '"+tostring(obj)+"' must not have any of the ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT modifiers set."); - } - } - - // Class and interface initialization methods... - if (name.equals(STATIC_INITIALIZER_NAME)){ - if ((obj.getAccessFlags() & (~ACC_STRICT)) > 0){ - addMessage("Class or interface initialization method '"+tostring(obj)+"' has superfluous access modifier(s) set: everything but ACC_STRICT is ignored."); - } - if (obj.isAbstract()){ - throw new ClassConstraintException("Class or interface initialization method '"+tostring(obj)+"' must not be abstract. This contradicts the Java Language Specification, Second Edition (which omits this constraint) but is common practice of existing verifiers."); - } - } - - if ((obj.getAccessFlags() & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_SYNCHRONIZED|ACC_NATIVE|ACC_ABSTRACT|ACC_STRICT)) > 0){ - addMessage("Method '"+tostring(obj)+"' has access flag(s) other than ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT set (ignored)."); - } - - String nameanddesc = (name+sig); - if (method_names_and_desc.contains(nameanddesc)){ - throw new ClassConstraintException("No two methods (like '"+tostring(obj)+"') are allowed have same names and desciptors!"); - } - method_names_and_desc.add(nameanddesc); - - Attribute[] atts = obj.getAttributes(); - int num_code_atts = 0; - for (int i=0; i= cplen)){ - throw new ClassConstraintException("Invalid index '"+index+"' used by '"+tostring(obj)+"'."); - } - Constant c = cp.getConstant(index); - - if (CONST_Long.isInstance(c) && field_type.equals(Type.LONG)){ - return; - } - if (CONST_Float.isInstance(c) && field_type.equals(Type.FLOAT)){ - return; - } - if (CONST_Double.isInstance(c) && field_type.equals(Type.DOUBLE)){ - return; - } - if (CONST_Integer.isInstance(c) && (field_type.equals(Type.INT) || field_type.equals(Type.SHORT) || field_type.equals(Type.CHAR) || field_type.equals(Type.BYTE) || field_type.equals(Type.BOOLEAN))){ - return; - } - if (CONST_String.isInstance(c) && field_type.equals(Type.STRING)){ - return; - } - - throw new ClassConstraintException("Illegal type of ConstantValue '"+obj+"' embedding Constant '"+c+"'. It is referenced by field '"+tostring(f)+"' expecting a different type: '"+field_type+"'."); - } - } - // SYNTHETIC: see above - // DEPRECATED: see above - ///////////////////////////////////////////////////////// - // method_info-structure-ATTRIBUTES (vmspec2 4.6, 4.7) // - ///////////////////////////////////////////////////////// - public void visitCode(Code obj){//vmspec2 4.7.3 - // No code attribute allowed for native or abstract methods: see visitMethod(Method). - // Code array constraints are checked in Pass3 (3a and 3b). - - checkIndex(obj, obj.getNameIndex(), CONST_Utf8); - - String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes(); - if (! name.equals("Code")){ - throw new ClassConstraintException("The Code attribute '"+tostring(obj)+"' is not correctly named 'Code' but '"+name+"'."); - } - - Method m = null; // satisfy compiler - if (!(carrier.predecessor() instanceof Method)){ - addMessage("Code attribute '"+tostring(obj)+"' is not declared in a method_info structure but in '"+carrier.predecessor()+"'. Ignored."); - return; - } - else{ - m = (Method) carrier.predecessor(); // we can assume this method was visited before; - // i.e. the data consistency was verified. - } - - if (obj.getCode().length == 0){ - throw new ClassConstraintException("Code array of Code attribute '"+tostring(obj)+"' (method '"+m+"') must not be empty."); - } - - //In JustIce, the check for correct offsets into the code array is delayed to Pass 3a. - CodeException[] exc_table = obj.getExceptionTable(); - for (int i=0; i= code.getMaxLocals()){ - throw new ClassConstraintException("LocalVariableTable attribute '"+tostring(lvt)+"' references a LocalVariable '"+tostring(localvariables[i])+"' with an index that exceeds the surrounding Code attribute's max_locals value of '"+code.getMaxLocals()+"'."); - } - - try{ - localVariablesInfos[method_number].add(localindex, localname, localvariables[i].getStartPC(), localvariables[i].getLength(), t); - } - catch(LocalVariableInfoInconsistentException lviie){ - throw new ClassConstraintException("Conflicting information in LocalVariableTable '"+tostring(lvt)+"' found in Code attribute '"+tostring(obj)+"' (method '"+tostring(m)+"'). "+lviie.getMessage()); - } - }// for all local variables localvariables[i] in the LocalVariableTable attribute atts[a] END - - num_of_lvt_attribs++; - if (num_of_lvt_attribs > obj.getMaxLocals()){ - throw new ClassConstraintException("Number of LocalVariableTable attributes of Code attribute '"+tostring(obj)+"' (method '"+tostring(m)+"') exceeds number of local variable slots '"+obj.getMaxLocals()+"' ('There may be no more than one LocalVariableTable attribute per local variable in the Code attribute.')."); - } - }// if atts[a] instanceof LocalVariableTable END - }// for all attributes atts[a] END - }// visitCode(Code) END - - public void visitExceptionTable(ExceptionTable obj){//vmspec2 4.7.4 - // incorrectly named, it's the Exceptions attribute (vmspec2 4.7.4) - checkIndex(obj, obj.getNameIndex(), CONST_Utf8); - - String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes(); - if (! name.equals("Exceptions")){ - throw new ClassConstraintException("The Exceptions attribute '"+tostring(obj)+"' is not correctly named 'Exceptions' but '"+name+"'."); - } - - int[] exc_indices = obj.getExceptionIndexTable(); - - for (int i=0; iPrecondition: index-style cross referencing in the constant - * pool must be valid. Simply invoke constant_pool_entries_satisfy_static_constraints() - * before. - * - * @throws ClassConstraintException otherwise. - * @see #constant_pool_entries_satisfy_static_constraints() - */ - private void field_and_method_refs_are_valid(){ - JavaClass jc = Repository.lookupClass(myOwner.getClassName()); - DescendingVisitor v = new DescendingVisitor(jc, new FAMRAV_Visitor(jc)); - v.visit(); - } - - /** - * A Visitor class that ensures the ConstantCP-subclassed entries - * of the constant pool are valid. - * Precondition: index-style cross referencing in the constant - * pool must be valid. - * - * @see #constant_pool_entries_satisfy_static_constraints() - * @see org.aspectj.apache.bcel.classfile.ConstantCP - */ - private class FAMRAV_Visitor extends EmptyVisitor implements Visitor{ - private final ConstantPool cp; // ==jc.getConstantPool() -- only here to save typing work. - private FAMRAV_Visitor(JavaClass _jc){ - cp = _jc.getConstantPool(); - } - - public void visitConstantFieldref(ConstantFieldref obj){ - if (obj.getTag() != Constants.CONSTANT_Fieldref){ - throw new ClassConstraintException("ConstantFieldref '"+tostring(obj)+"' has wrong tag!"); - } - int name_and_type_index = obj.getNameAndTypeIndex(); - ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index)); - String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name - if (!validFieldName(name)){ - throw new ClassConstraintException("Invalid field name '"+name+"' referenced by '"+tostring(obj)+"'."); - } - - int class_index = obj.getClassIndex(); - ConstantClass cc = (ConstantClass) (cp.getConstant(class_index)); - String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form - if (! validClassName(className)){ - throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'."); - } - - String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor) - - try{ - Type.getType(sig); /* Don't need the return value */ - } - catch (ClassFormatError cfe){ - // Well, BCEL sometimes is a little harsh describing exceptional situations. - throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'."); - } - } - - public void visitConstantMethodref(ConstantMethodref obj){ - if (obj.getTag() != Constants.CONSTANT_Methodref){ - throw new ClassConstraintException("ConstantMethodref '"+tostring(obj)+"' has wrong tag!"); - } - int name_and_type_index = obj.getNameAndTypeIndex(); - ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index)); - String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name - if (!validClassMethodName(name)){ - throw new ClassConstraintException("Invalid (non-interface) method name '"+name+"' referenced by '"+tostring(obj)+"'."); - } - - int class_index = obj.getClassIndex(); - ConstantClass cc = (ConstantClass) (cp.getConstant(class_index)); - String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form - if (! validClassName(className)){ - throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'."); - } - - String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor) - - try{ - Type t = Type.getReturnType(sig); - if ( name.equals(CONSTRUCTOR_NAME) && (t != Type.VOID) ){ - throw new ClassConstraintException("Instance initialization method must have VOID return type."); - } - } - catch (ClassFormatError cfe){ - // Well, BCEL sometimes is a little harsh describing exceptional situations. - throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'."); - } - } - - public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj){ - if (obj.getTag() != Constants.CONSTANT_InterfaceMethodref){ - throw new ClassConstraintException("ConstantInterfaceMethodref '"+tostring(obj)+"' has wrong tag!"); - } - int name_and_type_index = obj.getNameAndTypeIndex(); - ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index)); - String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name - if (!validInterfaceMethodName(name)){ - throw new ClassConstraintException("Invalid (interface) method name '"+name+"' referenced by '"+tostring(obj)+"'."); - } - - int class_index = obj.getClassIndex(); - ConstantClass cc = (ConstantClass) (cp.getConstant(class_index)); - String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form - if (! validClassName(className)){ - throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'."); - } - - String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor) - - try{ - Type t = Type.getReturnType(sig); - if ( name.equals(STATIC_INITIALIZER_NAME) && (t != Type.VOID) ){ - addMessage("Class or interface initialization method '"+STATIC_INITIALIZER_NAME+"' usually has VOID return type instead of '"+t+"'. Note this is really not a requirement of The Java Virtual Machine Specification, Second Edition."); - } - } - catch (ClassFormatError cfe){ - // Well, BCEL sometimes is a little harsh describing exceptional situations. - throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'."); - } - - } - - } - - /** - * This method returns true if and only if the supplied String - * represents a valid Java class name. - */ - private static final boolean validClassName(String name){ - /* - * TODO: implement. - * Are there any restrictions? - */ - return true; - } - /** - * This method returns true if and only if the supplied String - * represents a valid method name. - * This is basically the same as a valid identifier name in the - * Java programming language, but the special name for - * the instance initialization method is allowed and the special name - * for the class/interface initialization method may be allowed. - */ - private static boolean validMethodName(String name, boolean allowStaticInit){ - if (validJavaLangMethodName(name)) return true; - - if (allowStaticInit){ - return (name.equals(CONSTRUCTOR_NAME) || name.equals(STATIC_INITIALIZER_NAME)); - } - else{ - return name.equals(CONSTRUCTOR_NAME); - } - } - - /** - * This method returns true if and only if the supplied String - * represents a valid method name that may be referenced by - * ConstantMethodref objects. - */ - private static boolean validClassMethodName(String name){ - return validMethodName(name, false); - } - - /** - * This method returns true if and only if the supplied String - * represents a valid Java programming language method name stored as a simple - * (non-qualified) name. - * Conforming to: The Java Virtual Machine Specification, Second Edition, §2.7, §2.7.1, §2.2. - */ - private static boolean validJavaLangMethodName(String name){ - if (!Character.isJavaIdentifierStart(name.charAt(0))) return false; - - for (int i=1; i. + */ + +import java.util.HashMap; +import java.util.HashSet; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.Repository; +import org.aspectj.apache.bcel.classfile.Attribute; +import org.aspectj.apache.bcel.classfile.Code; +import org.aspectj.apache.bcel.classfile.CodeException; +import org.aspectj.apache.bcel.classfile.Constant; +import org.aspectj.apache.bcel.classfile.ConstantClass; +import org.aspectj.apache.bcel.classfile.ConstantDouble; +import org.aspectj.apache.bcel.classfile.ConstantFieldref; +import org.aspectj.apache.bcel.classfile.ConstantFloat; +import org.aspectj.apache.bcel.classfile.ConstantInteger; +import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref; +import org.aspectj.apache.bcel.classfile.ConstantLong; +import org.aspectj.apache.bcel.classfile.ConstantMethodref; +import org.aspectj.apache.bcel.classfile.ConstantNameAndType; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.classfile.ConstantString; +import org.aspectj.apache.bcel.classfile.ConstantUtf8; +import org.aspectj.apache.bcel.classfile.ConstantValue; +import org.aspectj.apache.bcel.classfile.Deprecated; +import org.aspectj.apache.bcel.classfile.ExceptionTable; +import org.aspectj.apache.bcel.classfile.Field; +import org.aspectj.apache.bcel.classfile.InnerClass; +import org.aspectj.apache.bcel.classfile.InnerClasses; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.LineNumber; +import org.aspectj.apache.bcel.classfile.LineNumberTable; +import org.aspectj.apache.bcel.classfile.LocalVariable; +import org.aspectj.apache.bcel.classfile.LocalVariableTable; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.classfile.Node; +import org.aspectj.apache.bcel.classfile.SourceFile; +import org.aspectj.apache.bcel.classfile.Synthetic; +import org.aspectj.apache.bcel.classfile.Unknown; +import org.aspectj.apache.bcel.classfile.ClassVisitor; +import org.aspectj.apache.bcel.generic.ArrayType; +import org.aspectj.apache.bcel.generic.ObjectType; +import org.aspectj.apache.bcel.generic.Type; +import org.aspectj.apache.bcel.verifier.DescendingVisitor; +import org.aspectj.apache.bcel.verifier.EmptyClassVisitor; +import org.aspectj.apache.bcel.verifier.PassVerifier; +import org.aspectj.apache.bcel.verifier.VerificationResult; +import org.aspectj.apache.bcel.verifier.Verifier; +import org.aspectj.apache.bcel.verifier.VerifierFactory; +import org.aspectj.apache.bcel.verifier.exc.AssertionViolatedException; +import org.aspectj.apache.bcel.verifier.exc.ClassConstraintException; +import org.aspectj.apache.bcel.verifier.exc.LocalVariableInfoInconsistentException; + +/** + * This PassVerifier verifies a class file according to + * pass 2 as described in The Java Virtual Machine + * Specification, 2nd edition. + * More detailed information is to be found at the do_verify() + * method's documentation. + * + * @version $Id: Pass2Verifier.java,v 1.1.2.1 2008/05/08 19:26:52 aclement Exp $ + * @author Enver Haase + * @see #do_verify() + */ +public final class Pass2Verifier extends PassVerifier implements Constants{ + + /** + * The LocalVariableInfo instances used by Pass3bVerifier. + * localVariablesInfos[i] denotes the information for the + * local variables of method number i in the + * JavaClass this verifier operates on. + */ + private LocalVariablesInfo[] localVariablesInfos; + + /** The Verifier that created this. */ + private Verifier myOwner; + + /** + * Should only be instantiated by a Verifier. + * + * @see Verifier + */ + public Pass2Verifier(Verifier owner){ + myOwner = owner; + } + + /** + * Returns a LocalVariablesInfo object containing information + * about the usage of the local variables in the Code attribute + * of the said method or null if the class file this + * Pass2Verifier operates on could not be pass-2-verified correctly. + * The method number method_nr is the method you get using + * Repository.lookupClass(myOwner.getClassname()).getMethods()[method_nr];. + * You should not add own information. Leave that to JustIce. + */ + public LocalVariablesInfo getLocalVariablesInfo(int method_nr){ + if (this.verify() != VerificationResult.VR_OK) return null; // It's cached, don't worry. + if (method_nr < 0 || method_nr >= localVariablesInfos.length){ + throw new AssertionViolatedException("Method number out of range."); + } + return localVariablesInfos[method_nr]; + } + + /** + * Pass 2 is the pass where static properties of the + * class file are checked without looking into "Code" + * arrays of methods. + * This verification pass is usually invoked when + * a class is resolved; and it may be possible that + * this verification pass has to load in other classes + * such as superclasses or implemented interfaces. + * Therefore, Pass 1 is run on them.
          + * Note that most referenced classes are not loaded + * in for verification or for an existance check by this + * pass; only the syntactical correctness of their names + * and descriptors (a.k.a. signatures) is checked.
          + * Very few checks that conceptually belong here + * are delayed until pass 3a in JustIce. JustIce does + * not only check for syntactical correctness but also + * for semantical sanity - therefore it needs access to + * the "Code" array of methods in a few cases. Please + * see the pass 3a documentation, too. + * + * @see org.aspectj.apache.bcel.verifier.statics.Pass3aVerifier + */ + public VerificationResult do_verify(){ + VerificationResult vr1 = myOwner.doPass1(); + if (vr1.equals(VerificationResult.VR_OK)){ + + // For every method, we could have information about the local variables out of LocalVariableTable attributes of + // the Code attributes. + localVariablesInfos = new LocalVariablesInfo[Repository.lookupClass(myOwner.getClassName()).getMethods().length]; + + VerificationResult vr = VerificationResult.VR_OK; // default. + try{ + constant_pool_entries_satisfy_static_constraints(); + field_and_method_refs_are_valid(); + every_class_has_an_accessible_superclass(); + final_methods_are_not_overridden(); + } + catch (ClassConstraintException cce){ + vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, cce.getMessage()); + } + return vr; + } + else + return VerificationResult.VR_NOTYET; + } + + /** + * Ensures that every class has a super class and that + * final classes are not subclassed. + * This means, the class this Pass2Verifier operates + * on has proper super classes (transitively) up to + * java.lang.Object. + * The reason for really loading (and Pass1-verifying) + * all of those classes here is that we need them in + * Pass2 anyway to verify no final methods are overridden + * (that could be declared anywhere in the ancestor hierarchy). + * + * @throws ClassConstraintException otherwise. + */ + private void every_class_has_an_accessible_superclass(){ + HashSet hs = new HashSet(); // save class names to detect circular inheritance + JavaClass jc = Repository.lookupClass(myOwner.getClassName()); + int supidx = -1; + + while (supidx != 0){ + supidx = jc.getSuperclassNameIndex(); + + if (supidx == 0){ + if (jc != Repository.lookupClass(Type.OBJECT.getClassName())){ + throw new ClassConstraintException("Superclass of '"+jc.getClassName()+"' missing but not "+Type.OBJECT.getClassName()+" itself!"); + } + } + else{ + String supername = jc.getSuperclassName(); + if (! hs.add(supername)){ // If supername already is in the list + throw new ClassConstraintException("Circular superclass hierarchy detected."); + } + Verifier v = VerifierFactory.getVerifier(supername); + VerificationResult vr = v.doPass1(); + + if (vr != VerificationResult.VR_OK){ + throw new ClassConstraintException("Could not load in ancestor class '"+supername+"'."); + } + jc = Repository.lookupClass(supername); + + if (jc.isFinal()){ + throw new ClassConstraintException("Ancestor class '"+supername+"' has the FINAL access modifier and must therefore not be subclassed."); + } + } + } + } + + /** + * Ensures that final methods are not overridden. + * Precondition to run this method: + * constant_pool_entries_satisfy_static_constraints() and + * every_class_has_an_accessible_superclass() have to be invoked before + * (in that order). + * + * @throws ClassConstraintException otherwise. + * @see #constant_pool_entries_satisfy_static_constraints() + * @see #every_class_has_an_accessible_superclass() + */ + private void final_methods_are_not_overridden(){ + HashMap hashmap = new HashMap(); + JavaClass jc = Repository.lookupClass(myOwner.getClassName()); + + int supidx = -1; + while (supidx != 0){ + supidx = jc.getSuperclassNameIndex(); + + Method[] methods = jc.getMethods(); + for (int i=0; i= cplen)){ + throw new ClassConstraintException("Invalid index '"+index+"' used by '"+tostring(referrer)+"'."); + } + Constant c = cp.getConstant(index); + if (! shouldbe.isInstance(c)){ + /* String isnot = shouldbe.toString().substring(shouldbe.toString().lastIndexOf(".")+1); //Cut all before last "." */ + throw new ClassCastException("Illegal constant '"+tostring(c)+"' at index '"+index+"'. '"+tostring(referrer)+"' expects a '"+shouldbe+"'."); + } + } + /////////////////////////////////////// + // ClassFile structure (vmspec2 4.1) // + /////////////////////////////////////// + public void visitJavaClass(JavaClass obj){ + Attribute[] atts = obj.getAttributes(); + boolean foundSourceFile = false; + boolean foundInnerClasses = false; + + // Is there an InnerClass referenced? + // This is a costly check; existing verifiers don't do it! + boolean hasInnerClass = new InnerClassDetector(jc).innerClassReferenced(); + + for (int i=0; i 1){ + throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set."); + } + + if (obj.isFinal() && obj.isVolatile()){ + throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_FINAL, ACC_VOLATILE modifiers set."); + } + } + else{ // isInterface! + if (!obj.isPublic()){ + throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_PUBLIC modifier set but hasn't!"); + } + if (!obj.isStatic()){ + throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_STATIC modifier set but hasn't!"); + } + if (!obj.isFinal()){ + throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_FINAL modifier set but hasn't!"); + } + } + + if ((obj.getModifiers() & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_VOLATILE|ACC_TRANSIENT)) > 0){ + addMessage("Field '"+tostring(obj)+"' has access flag(s) other than ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_VOLATILE, ACC_TRANSIENT set (ignored)."); + } + + checkIndex(obj, obj.getNameIndex(), CONST_Utf8); + + String name = obj.getName(); + if (! validFieldName(name)){ + throw new ClassConstraintException("Field '"+tostring(obj)+"' has illegal name '"+obj.getName()+"'."); + } + + // A descriptor is often named signature in BCEL + checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8); + + String sig = ((ConstantUtf8) (cp.getConstant(obj.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor) + + try{ + Type.getType(sig); /* Don't need the return value */ + } + catch (ClassFormatError cfe){ // sometimes BCEL is a little harsh describing exceptional situations. + throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'."); + } + + String nameanddesc = (name+sig); + if (field_names_and_desc.contains(nameanddesc)){ + throw new ClassConstraintException("No two fields (like '"+tostring(obj)+"') are allowed have same names and descriptors!"); + } + if (field_names.contains(name)){ + addMessage("More than one field of name '"+name+"' detected (but with different type descriptors). This is very unusual."); + } + field_names_and_desc.add(nameanddesc); + field_names.add(name); + + Attribute[] atts = obj.getAttributes(); + for (int i=0; i 1){ + throw new ClassConstraintException("Method '"+tostring(obj)+"' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set."); + } + + if (obj.isAbstract()){ + if (obj.isFinal()) throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_FINAL modifier set."); + if (obj.isNative()) throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_NATIVE modifier set."); + if (obj.isPrivate()) throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_PRIVATE modifier set."); + if (obj.isStatic()) throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_STATIC modifier set."); + if (obj.isStrictfp()) throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_STRICT modifier set."); + if (obj.isSynchronized()) throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_SYNCHRONIZED modifier set."); + } + } + else{ // isInterface! + if (!name.equals(STATIC_INITIALIZER_NAME)){//vmspec2, p.116, 2nd paragraph + if (!obj.isPublic()){ + throw new ClassConstraintException("Interface method '"+tostring(obj)+"' must have the ACC_PUBLIC modifier set but hasn't!"); + } + if (!obj.isAbstract()){ + throw new ClassConstraintException("Interface method '"+tostring(obj)+"' must have the ACC_STATIC modifier set but hasn't!"); + } + if ( obj.isPrivate() || + obj.isProtected() || + obj.isStatic() || + obj.isFinal() || + obj.isSynchronized() || + obj.isNative() || + obj.isStrictfp() ){ + throw new ClassConstraintException("Interface method '"+tostring(obj)+"' must not have any of the ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT modifiers set."); + } + } + } + + // A specific instance initialization method... (vmspec2,Page 116). + if (name.equals(CONSTRUCTOR_NAME)){ + //..may have at most one of ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC set: is checked above. + //..may also have ACC_STRICT set, but none of the other flags in table 4.5 (vmspec2, page 115) + if ( obj.isStatic() || + obj.isFinal() || + obj.isSynchronized() || + obj.isNative() || + obj.isAbstract() ){ + throw new ClassConstraintException("Instance initialization method '"+tostring(obj)+"' must not have any of the ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT modifiers set."); + } + } + + // Class and interface initialization methods... + if (name.equals(STATIC_INITIALIZER_NAME)){ + if ((obj.getModifiers() & (~ACC_STRICT)) > 0){ + addMessage("Class or interface initialization method '"+tostring(obj)+"' has superfluous access modifier(s) set: everything but ACC_STRICT is ignored."); + } + if (obj.isAbstract()){ + throw new ClassConstraintException("Class or interface initialization method '"+tostring(obj)+"' must not be abstract. This contradicts the Java Language Specification, Second Edition (which omits this constraint) but is common practice of existing verifiers."); + } + } + + if ((obj.getModifiers() & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_SYNCHRONIZED|ACC_NATIVE|ACC_ABSTRACT|ACC_STRICT)) > 0){ + addMessage("Method '"+tostring(obj)+"' has access flag(s) other than ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT set (ignored)."); + } + + String nameanddesc = (name+sig); + if (method_names_and_desc.contains(nameanddesc)){ + throw new ClassConstraintException("No two methods (like '"+tostring(obj)+"') are allowed have same names and desciptors!"); + } + method_names_and_desc.add(nameanddesc); + + Attribute[] atts = obj.getAttributes(); + int num_code_atts = 0; + for (int i=0; i= cplen)){ + throw new ClassConstraintException("Invalid index '"+index+"' used by '"+tostring(obj)+"'."); + } + Constant c = cp.getConstant(index); + + if (CONST_Long.isInstance(c) && field_type.equals(Type.LONG)){ + return; + } + if (CONST_Float.isInstance(c) && field_type.equals(Type.FLOAT)){ + return; + } + if (CONST_Double.isInstance(c) && field_type.equals(Type.DOUBLE)){ + return; + } + if (CONST_Integer.isInstance(c) && (field_type.equals(Type.INT) || field_type.equals(Type.SHORT) || field_type.equals(Type.CHAR) || field_type.equals(Type.BYTE) || field_type.equals(Type.BOOLEAN))){ + return; + } + if (CONST_String.isInstance(c) && field_type.equals(Type.STRING)){ + return; + } + + throw new ClassConstraintException("Illegal type of ConstantValue '"+obj+"' embedding Constant '"+c+"'. It is referenced by field '"+tostring(f)+"' expecting a different type: '"+field_type+"'."); + } + } + // SYNTHETIC: see above + // DEPRECATED: see above + ///////////////////////////////////////////////////////// + // method_info-structure-ATTRIBUTES (vmspec2 4.6, 4.7) // + ///////////////////////////////////////////////////////// + public void visitCode(Code obj){//vmspec2 4.7.3 + // No code attribute allowed for native or abstract methods: see visitMethod(Method). + // Code array constraints are checked in Pass3 (3a and 3b). + + checkIndex(obj, obj.getNameIndex(), CONST_Utf8); + + String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes(); + if (! name.equals("Code")){ + throw new ClassConstraintException("The Code attribute '"+tostring(obj)+"' is not correctly named 'Code' but '"+name+"'."); + } + + Method m = null; // satisfy compiler + if (!(carrier.predecessor() instanceof Method)){ + addMessage("Code attribute '"+tostring(obj)+"' is not declared in a method_info structure but in '"+carrier.predecessor()+"'. Ignored."); + return; + } + else{ + m = (Method) carrier.predecessor(); // we can assume this method was visited before; + // i.e. the data consistency was verified. + } + + if (obj.getCode().length == 0){ + throw new ClassConstraintException("Code array of Code attribute '"+tostring(obj)+"' (method '"+m+"') must not be empty."); + } + + //In JustIce, the check for correct offsets into the code array is delayed to Pass 3a. + CodeException[] exc_table = obj.getExceptionTable(); + for (int i=0; i= code.getMaxLocals()){ + throw new ClassConstraintException("LocalVariableTable attribute '"+tostring(lvt)+"' references a LocalVariable '"+tostring(localvariables[i])+"' with an index that exceeds the surrounding Code attribute's max_locals value of '"+code.getMaxLocals()+"'."); + } + + try{ + localVariablesInfos[method_number].add(localindex, localname, localvariables[i].getStartPC(), localvariables[i].getLength(), t); + } + catch(LocalVariableInfoInconsistentException lviie){ + throw new ClassConstraintException("Conflicting information in LocalVariableTable '"+tostring(lvt)+"' found in Code attribute '"+tostring(obj)+"' (method '"+tostring(m)+"'). "+lviie.getMessage()); + } + }// for all local variables localvariables[i] in the LocalVariableTable attribute atts[a] END + + num_of_lvt_attribs++; + if (num_of_lvt_attribs > obj.getMaxLocals()){ + throw new ClassConstraintException("Number of LocalVariableTable attributes of Code attribute '"+tostring(obj)+"' (method '"+tostring(m)+"') exceeds number of local variable slots '"+obj.getMaxLocals()+"' ('There may be no more than one LocalVariableTable attribute per local variable in the Code attribute.')."); + } + }// if atts[a] instanceof LocalVariableTable END + }// for all attributes atts[a] END + }// visitCode(Code) END + + public void visitExceptionTable(ExceptionTable obj){//vmspec2 4.7.4 + // incorrectly named, it's the Exceptions attribute (vmspec2 4.7.4) + checkIndex(obj, obj.getNameIndex(), CONST_Utf8); + + String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes(); + if (! name.equals("Exceptions")){ + throw new ClassConstraintException("The Exceptions attribute '"+tostring(obj)+"' is not correctly named 'Exceptions' but '"+name+"'."); + } + + int[] exc_indices = obj.getExceptionIndexTable(); + + for (int i=0; iPrecondition: index-style cross referencing in the constant + * pool must be valid. Simply invoke constant_pool_entries_satisfy_static_constraints() + * before. + * + * @throws ClassConstraintException otherwise. + * @see #constant_pool_entries_satisfy_static_constraints() + */ + private void field_and_method_refs_are_valid(){ + JavaClass jc = Repository.lookupClass(myOwner.getClassName()); + DescendingVisitor v = new DescendingVisitor(jc, new FAMRAV_Visitor(jc)); + v.visit(); + } + + /** + * A Visitor class that ensures the ConstantCP-subclassed entries + * of the constant pool are valid. + * Precondition: index-style cross referencing in the constant + * pool must be valid. + * + * @see #constant_pool_entries_satisfy_static_constraints() + * @see org.aspectj.apache.bcel.classfile.ConstantCP + */ + private class FAMRAV_Visitor extends EmptyClassVisitor implements ClassVisitor{ + private final ConstantPool cp; // ==jc.getConstantPool() -- only here to save typing work. + private FAMRAV_Visitor(JavaClass _jc){ + cp = _jc.getConstantPool(); + } + + public void visitConstantFieldref(ConstantFieldref obj){ + if (obj.getTag() != Constants.CONSTANT_Fieldref){ + throw new ClassConstraintException("ConstantFieldref '"+tostring(obj)+"' has wrong tag!"); + } + int name_and_type_index = obj.getNameAndTypeIndex(); + ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index)); + String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name + if (!validFieldName(name)){ + throw new ClassConstraintException("Invalid field name '"+name+"' referenced by '"+tostring(obj)+"'."); + } + + int class_index = obj.getClassIndex(); + ConstantClass cc = (ConstantClass) (cp.getConstant(class_index)); + String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form + if (! validClassName(className)){ + throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'."); + } + + String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor) + + try{ + Type.getType(sig); /* Don't need the return value */ + } + catch (ClassFormatError cfe){ + // Well, BCEL sometimes is a little harsh describing exceptional situations. + throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'."); + } + } + + public void visitConstantMethodref(ConstantMethodref obj){ + if (obj.getTag() != Constants.CONSTANT_Methodref){ + throw new ClassConstraintException("ConstantMethodref '"+tostring(obj)+"' has wrong tag!"); + } + int name_and_type_index = obj.getNameAndTypeIndex(); + ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index)); + String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name + if (!validClassMethodName(name)){ + throw new ClassConstraintException("Invalid (non-interface) method name '"+name+"' referenced by '"+tostring(obj)+"'."); + } + + int class_index = obj.getClassIndex(); + ConstantClass cc = (ConstantClass) (cp.getConstant(class_index)); + String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form + if (! validClassName(className)){ + throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'."); + } + + String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor) + + try{ + Type t = Type.getReturnType(sig); + if ( name.equals(CONSTRUCTOR_NAME) && (t != Type.VOID) ){ + throw new ClassConstraintException("Instance initialization method must have VOID return type."); + } + } + catch (ClassFormatError cfe){ + // Well, BCEL sometimes is a little harsh describing exceptional situations. + throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'."); + } + } + + public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj){ + if (obj.getTag() != Constants.CONSTANT_InterfaceMethodref){ + throw new ClassConstraintException("ConstantInterfaceMethodref '"+tostring(obj)+"' has wrong tag!"); + } + int name_and_type_index = obj.getNameAndTypeIndex(); + ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index)); + String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name + if (!validInterfaceMethodName(name)){ + throw new ClassConstraintException("Invalid (interface) method name '"+name+"' referenced by '"+tostring(obj)+"'."); + } + + int class_index = obj.getClassIndex(); + ConstantClass cc = (ConstantClass) (cp.getConstant(class_index)); + String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form + if (! validClassName(className)){ + throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'."); + } + + String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor) + + try{ + Type t = Type.getReturnType(sig); + if ( name.equals(STATIC_INITIALIZER_NAME) && (t != Type.VOID) ){ + addMessage("Class or interface initialization method '"+STATIC_INITIALIZER_NAME+"' usually has VOID return type instead of '"+t+"'. Note this is really not a requirement of The Java Virtual Machine Specification, Second Edition."); + } + } + catch (ClassFormatError cfe){ + // Well, BCEL sometimes is a little harsh describing exceptional situations. + throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'."); + } + + } + + } + + /** + * This method returns true if and only if the supplied String + * represents a valid Java class name. + */ + private static final boolean validClassName(String name){ + /* + * TODO: implement. + * Are there any restrictions? + */ + return true; + } + /** + * This method returns true if and only if the supplied String + * represents a valid method name. + * This is basically the same as a valid identifier name in the + * Java programming language, but the special name for + * the instance initialization method is allowed and the special name + * for the class/interface initialization method may be allowed. + */ + private static boolean validMethodName(String name, boolean allowStaticInit){ + if (validJavaLangMethodName(name)) return true; + + if (allowStaticInit){ + return (name.equals(CONSTRUCTOR_NAME) || name.equals(STATIC_INITIALIZER_NAME)); + } + else{ + return name.equals(CONSTRUCTOR_NAME); + } + } + + /** + * This method returns true if and only if the supplied String + * represents a valid method name that may be referenced by + * ConstantMethodref objects. + */ + private static boolean validClassMethodName(String name){ + return validMethodName(name, false); + } + + /** + * This method returns true if and only if the supplied String + * represents a valid Java programming language method name stored as a simple + * (non-qualified) name. + * Conforming to: The Java Virtual Machine Specification, Second Edition, §2.7, §2.7.1, §2.2. + */ + private static boolean validJavaLangMethodName(String name){ + if (!Character.isJavaIdentifierStart(name.charAt(0))) return false; + + for (int i=1; i. - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.Attribute; -import org.aspectj.apache.bcel.classfile.Code; -import org.aspectj.apache.bcel.classfile.CodeException; -import org.aspectj.apache.bcel.classfile.Constant; -import org.aspectj.apache.bcel.classfile.ConstantClass; -import org.aspectj.apache.bcel.classfile.ConstantDouble; -import org.aspectj.apache.bcel.classfile.ConstantFieldref; -import org.aspectj.apache.bcel.classfile.ConstantFloat; -import org.aspectj.apache.bcel.classfile.ConstantInteger; -import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref; -import org.aspectj.apache.bcel.classfile.ConstantLong; -import org.aspectj.apache.bcel.classfile.ConstantMethodref; -import org.aspectj.apache.bcel.classfile.ConstantNameAndType; -import org.aspectj.apache.bcel.classfile.ConstantString; -import org.aspectj.apache.bcel.classfile.ConstantUtf8; -import org.aspectj.apache.bcel.classfile.Field; -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.classfile.LineNumber; -import org.aspectj.apache.bcel.classfile.LineNumberTable; -import org.aspectj.apache.bcel.classfile.LocalVariable; -import org.aspectj.apache.bcel.classfile.LocalVariableTable; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.generic.ArrayType; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.generic.FieldInstruction; -import org.aspectj.apache.bcel.generic.IINC; -import org.aspectj.apache.bcel.generic.INVOKEINTERFACE; -import org.aspectj.apache.bcel.generic.Instruction; -import org.aspectj.apache.bcel.generic.InstructionBranch; -import org.aspectj.apache.bcel.generic.InstructionByte; -import org.aspectj.apache.bcel.generic.InstructionHandle; -import org.aspectj.apache.bcel.generic.InstructionList; -import org.aspectj.apache.bcel.generic.InvokeInstruction; -import org.aspectj.apache.bcel.generic.LOOKUPSWITCH; -import org.aspectj.apache.bcel.generic.MULTIANEWARRAY; -import org.aspectj.apache.bcel.generic.ObjectType; -import org.aspectj.apache.bcel.generic.RET; -import org.aspectj.apache.bcel.generic.TABLESWITCH; -import org.aspectj.apache.bcel.generic.Type; -import org.aspectj.apache.bcel.verifier.PassVerifier; -import org.aspectj.apache.bcel.verifier.VerificationResult; -import org.aspectj.apache.bcel.verifier.Verifier; -import org.aspectj.apache.bcel.verifier.VerifierFactory; -import org.aspectj.apache.bcel.verifier.exc.AssertionViolatedException; -import org.aspectj.apache.bcel.verifier.exc.ClassConstraintException; -import org.aspectj.apache.bcel.verifier.exc.InvalidMethodException; -import org.aspectj.apache.bcel.verifier.exc.StaticCodeConstraintException; -import org.aspectj.apache.bcel.verifier.exc.StaticCodeInstructionConstraintException; -import org.aspectj.apache.bcel.verifier.exc.StaticCodeInstructionOperandConstraintException; - -/** - * This PassVerifier verifies a class file according to - * pass 3, static part as described in The Java Virtual - * Machine Specification, 2nd edition. - * More detailed information is to be found at the do_verify() - * method's documentation. - * - * @version $Id: Pass3aVerifier.java,v 1.3.10.2 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - * @see #do_verify() - */ -public final class Pass3aVerifier extends PassVerifier{ - - /** The Verifier that created this. */ - private Verifier myOwner; - - /** - * The method number to verify. - * This is the index in the array returned - * by JavaClass.getMethods(). - */ - private int method_no; - - /** The one and only InstructionList object used by an instance of this class. It's here for performance reasons by do_verify() and its callees. */ - InstructionList instructionList; - /** The one and only Code object used by an instance of this class. It's here for performance reasons by do_verify() and its callees. */ - Code code; - - /** Should only be instantiated by a Verifier. */ - public Pass3aVerifier(Verifier owner, int method_no){ - myOwner = owner; - this.method_no = method_no; - } - - /** - * Pass 3a is the verification of static constraints of - * JVM code (such as legal targets of branch instructions). - * This is the part of pass 3 where you do not need data - * flow analysis. - * JustIce also delays the checks for a correct exception - * table of a Code attribute and correct line number entries - * in a LineNumberTable attribute of a Code attribute (which - * conceptually belong to pass 2) to this pass. Also, most - * of the check for valid local variable entries in a - * LocalVariableTable attribute of a Code attribute is - * delayed until this pass. - * All these checks need access to the code array of the - * Code attribute. - * - * @throws InvalidMethodException if the method to verify does not exist. - */ - public VerificationResult do_verify(){ - if (myOwner.doPass2().equals(VerificationResult.VR_OK)){ - // Okay, class file was loaded correctly by Pass 1 - // and satisfies static constraints of Pass 2. - JavaClass jc = Repository.lookupClass(myOwner.getClassName()); - Method[] methods = jc.getMethods(); - if (method_no >= methods.length){ - throw new InvalidMethodException("METHOD DOES NOT EXIST!"); - } - Method method = methods[method_no]; - code = method.getCode(); - - // No Code? Nothing to verify! - if ( method.isAbstract() || method.isNative() ){ // IF mg HAS NO CODE (static constraint of Pass 2) - return VerificationResult.VR_OK; - } - - // TODO: - // We want a very sophisticated code examination here with good explanations - // on where to look for an illegal instruction or such. - // Only after that we should try to build an InstructionList and throw an - // AssertionViolatedException if after our examination InstructionList building - // still fails. - // That examination should be implemented in a byte-oriented way, i.e. look for - // an instruction, make sure its validity, count its length, find the next - // instruction and so on. - try{ - instructionList = new InstructionList(method.getCode().getCode()); - } - catch(RuntimeException re){ - return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Bad bytecode in the code array of the Code attribute of method '"+method+"'."); - } - - instructionList.setPositions(true); - - // Start verification. - VerificationResult vr = VerificationResult.VR_OK; //default - try{ - delayedPass2Checks(); - } - catch(ClassConstraintException cce){ - vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, cce.getMessage()); - return vr; - } - try{ - pass3StaticInstructionChecks(); - pass3StaticInstructionOperandsChecks(); - } - catch(StaticCodeConstraintException scce){ - vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, scce.getMessage()); - } - return vr; - } - else{ //did not pass Pass 2. - return VerificationResult.VR_NOTYET; - } - } - - /** - * These are the checks that could be done in pass 2 but are delayed to pass 3 - * for performance reasons. Also, these checks need access to the code array - * of the Code attribute of a Method so it's okay to perform them here. - * Also see the description of the do_verify() method. - * - * @throws ClassConstraintException if the verification fails. - * @see #do_verify() - */ - private void delayedPass2Checks(){ - - int[] instructionPositions = instructionList.getInstructionPositions(); - int codeLength = code.getCode().length; - - ///////////////////// - // LineNumberTable // - ///////////////////// - LineNumberTable lnt = code.getLineNumberTable(); - if (lnt != null){ - LineNumber[] lineNumbers = lnt.getLineNumberTable(); - IntList offsets = new IntList(); - lineNumber_loop: for (int i=0; i < lineNumbers.length; i++){ // may appear in any order. - for (int j=0; j < instructionPositions.length; j++){ - // TODO: Make this a binary search! The instructionPositions array is naturally ordered! - int offset = lineNumbers[i].getStartPC(); - if (instructionPositions[j] == offset){ - if (offsets.contains(offset)){ - addMessage("LineNumberTable attribute '"+code.getLineNumberTable()+"' refers to the same code offset ('"+offset+"') more than once which is violating the semantics [but is sometimes produced by IBM's 'jikes' compiler]."); - } - else{ - offsets.add(offset); - } - continue lineNumber_loop; - } - } - throw new ClassConstraintException("Code attribute '"+code+"' has a LineNumberTable attribute '"+code.getLineNumberTable()+"' referring to a code offset ('"+lineNumbers[i].getStartPC()+"') that does not exist."); - } - } - - /////////////////////////// - // LocalVariableTable(s) // - /////////////////////////// - /* We cannot use code.getLocalVariableTable() because there could be more - than only one. This is a bug in BCEL. */ - Attribute[] atts = code.getAttributes(); - for (int a=0; a= endpc){ - throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has its start_pc ('"+startpc+"') not smaller than its end_pc ('"+endpc+"')."); - } - if (!contains(instructionPositions, startpc)){ - throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has a non-existant bytecode offset as its start_pc ('"+startpc+"')."); - } - if ( (!contains(instructionPositions, endpc)) && (endpc != codeLength)){ - throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has a non-existant bytecode offset as its end_pc ('"+startpc+"') [that is also not equal to code_length ('"+codeLength+"')]."); - } - if (!contains(instructionPositions, handlerpc)){ - throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has a non-existant bytecode offset as its handler_pc ('"+handlerpc+"')."); - } - } - } - - /** - * These are the checks if constraints are satisfied which are described in the - * Java Virtual Machine Specification, Second Edition as Static Constraints on - * the instructions of Java Virtual Machine Code (chapter 4.8.1). - * - * @throws StaticCodeConstraintException if the verification fails. - */ - private void pass3StaticInstructionChecks(){ - - // Code array must not be empty: - // Enforced in pass 2 (also stated in the static constraints of the Code - // array in vmspec2), together with pass 1 (reading code_length bytes and - // interpreting them as code[]). So this must not be checked again here. - - if (! (code.getCode().length < 65536)){// contradicts vmspec2 page 152 ("Limitations"), but is on page 134. - throw new StaticCodeInstructionConstraintException("Code array in code attribute '"+code+"' too big: must be smaller than 65536 bytes."); - } - - // First opcode at offset 0: okay, that's clear. Nothing to do. - - // Only instances of the instructions documented in Section 6.4 may appear in - // the code array. - - // For BCEL's sake, we cannot handle WIDE stuff, but hopefully BCEL does its job right :) - - // The last byte of the last instruction in the code array must be the byte at index - // code_length-1 : See the do_verify() comments. We actually don't iterate through the - // byte array, but use an InstructionList so we cannot check for this. But BCEL does - // things right, so it's implicitly okay. - - // TODO: Check how BCEL handles (and will handle) instructions like IMPDEP1, IMPDEP2, - // BREAKPOINT... that BCEL knows about but which are illegal anyway. - // We currently go the safe way here. - InstructionHandle ih = instructionList.getStart(); - while (ih != null){ - Instruction i = ih.getInstruction(); - if (i.getOpcode()==Constants.IMPDEP1){ - throw new StaticCodeInstructionConstraintException("IMPDEP1 must not be in the code, it is an illegal instruction for _internal_ JVM use!"); - } - if (i.getOpcode()==Constants.IMPDEP2){ - throw new StaticCodeInstructionConstraintException("IMPDEP2 must not be in the code, it is an illegal instruction for _internal_ JVM use!"); - } - if (i.getOpcode()==Constants.BREAKPOINT){ - throw new StaticCodeInstructionConstraintException("BREAKPOINT must not be in the code, it is an illegal instruction for _internal_ JVM use!"); - } - ih = ih.getNext(); - } - - // The original verifier seems to do this check here, too. - // An unreachable last instruction may also not fall through the - // end of the code, which is stupid -- but with the original - // verifier's subroutine semantics one cannot predict reachability. - Instruction last = instructionList.getEnd().getInstruction(); - if (! ((last.isReturnInstruction()) || - (last instanceof RET) || - (last.getOpcode()==Constants.GOTO || last.getOpcode()==Constants.GOTO_W) || - (last.getOpcode()==Constants.ATHROW))) // JSR / JSR_W would possibly RETurn and then fall off the code! - throw new StaticCodeInstructionConstraintException("Execution must not fall off the bottom of the code array. This constraint is enforced statically as some existing verifiers do - so it may be a false alarm if the last instruction is not reachable."); - } - - /** - * These are the checks for the satisfaction of constraints which are described in the - * Java Virtual Machine Specification, Second Edition as Static Constraints on - * the operands of instructions of Java Virtual Machine Code (chapter 4.8.1). - * BCEL parses the code array to create an InstructionList and therefore has to check - * some of these constraints. Additional checks are also implemented here. - * - * @throws StaticCodeConstraintException if the verification fails. - */ - private void pass3StaticInstructionOperandsChecks(){ - // When building up the InstructionList, BCEL has already done all those checks - // mentioned in The Java Virtual Machine Specification, Second Edition, as - // "static constraints on the operands of instructions in the code array". - // TODO: see the do_verify() comments. Maybe we should really work on the - // byte array first to give more comprehensive messages. - // TODO: Review Exception API, possibly build in some "offending instruction" thing - // when we're ready to insulate the offending instruction by doing the - // above thing. - - // TODO: Implement as much as possible here. BCEL does _not_ check everything. - - ConstantPool cpg = new ConstantPool(Repository.lookupClass(myOwner.getClassName()).getConstantPool().getConstantPool()); - InstOperandConstraintVisitor v = new InstOperandConstraintVisitor(cpg); - - // Checks for the things BCEL does _not_ handle itself. - InstructionHandle ih = instructionList.getStart(); - while (ih != null){ - Instruction i = ih.getInstruction(); - - // An "own" constraint, due to JustIce's new definition of what "subroutine" means. - if (i.isJsrInstruction()){ - InstructionHandle target = ((InstructionBranch) i).getTarget(); - if (target == instructionList.getStart()){ - throw new StaticCodeInstructionOperandConstraintException("Due to JustIce's clear definition of subroutines, no JSR or JSR_W may have a top-level instruction (such as the very first instruction, which is targeted by instruction '"+ih+"' as its target."); - } - if (!(target.getInstruction().isASTORE())){ - throw new StaticCodeInstructionOperandConstraintException("Due to JustIce's clear definition of subroutines, no JSR or JSR_W may target anything else than an ASTORE instruction. Instruction '"+ih+"' targets '"+target+"'."); - } - } - - // vmspec2, page 134-137 - ih.accept(v); - - ih = ih.getNext(); - } - - } - - /** A small utility method returning if a given int i is in the given int[] ints. */ - private static boolean contains(int[] ints, int i){ - for (int j=0; j= cpg.getSize()){ - constraintViolated(i, "Illegal constant pool index '"+idx+"'."); - } - } - - /////////////////////////////////////////////////////////// - // The Java Virtual Machine Specification, pages 134-137 // - /////////////////////////////////////////////////////////// - /** - * Assures the generic preconditions of a LoadClass instance. - * The referenced class is loaded and pass2-verified. - */ - public void visitLoadClass(Instruction o){ - ObjectType t = o.getLoadClassType(cpg); - if (t != null){// null means "no class is loaded" - Verifier v = VerifierFactory.getVerifier(t.getClassName()); - VerificationResult vr = v.doPass1(); - if (vr.getStatus() != VerificationResult.VERIFIED_OK){ - constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded: '"+vr+"'."); - } - } - } - - // The target of each jump and branch instruction [...] must be the opcode [...] - // BCEL _DOES_ handle this. - - // tableswitch: BCEL will do it, supposedly. - - // lookupswitch: BCEL will do it, supposedly. - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - // LDC and LDC_W (LDC_W is a subclass of LDC in BCEL's model) - public void visitLDC(Instruction o){ - indexValid(o, o.getIndex()); - Constant c = cpg.getConstant(o.getIndex()); - if (! ( (c instanceof ConstantInteger) || - (c instanceof ConstantFloat) || - (c instanceof ConstantString) ) ){ - constraintViolated(o, "Operand of LDC or LDC_W must be one of CONSTANT_Integer, CONSTANT_Float or CONSTANT_String, but is '"+c+"'."); - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - // LDC2_W - public void visitLDC2_W(Instruction o){ - indexValid(o, o.getIndex()); - Constant c = cpg.getConstant(o.getIndex()); - if (! ( (c instanceof ConstantLong) || - (c instanceof ConstantDouble) ) ){ - constraintViolated(o, "Operand of LDC2_W must be CONSTANT_Long or CONSTANT_Double, but is '"+c+"'."); - } - try{ - indexValid(o, o.getIndex()+1); - } - catch(StaticCodeInstructionOperandConstraintException e){ - throw new AssertionViolatedException("OOPS: Does not BCEL handle that? LDC2_W operand has a problem."); - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - //getfield, putfield, getstatic, putstatic - public void visitFieldInstruction(FieldInstruction o){ - indexValid(o, o.getIndex()); - Constant c = cpg.getConstant(o.getIndex()); - if (! (c instanceof ConstantFieldref)){ - constraintViolated(o, "Indexing a constant that's not a CONSTANT_Fieldref but a '"+c+"'."); - } - - String field_name = o.getFieldName(cpg); - - JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName()); - Field[] fields = jc.getFields(); - Field f = null; - for (int i=0; i or - ConstantNameAndType cnat = (ConstantNameAndType) (cpg.getConstant(((ConstantInterfaceMethodref)c).getNameAndTypeIndex())); - String name = ((ConstantUtf8) (cpg.getConstant(cnat.getNameIndex()))).getBytes(); - if (name.equals(Constants.CONSTRUCTOR_NAME)){ - constraintViolated(o, "Method to invoke must not be '"+Constants.CONSTRUCTOR_NAME+"'."); - } - if (name.equals(Constants.STATIC_INITIALIZER_NAME)){ - constraintViolated(o, "Method to invoke must not be '"+Constants.STATIC_INITIALIZER_NAME+"'."); - } - } - - // The LoadClassType is the method-declaring class, so we have to check the other types. - - Type t = o.getReturnType(cpg); - if (t instanceof ArrayType){ - t = ((ArrayType) t).getBasicType(); - } - if (t instanceof ObjectType){ - Verifier v = VerifierFactory.getVerifier(((ObjectType) t).getClassName()); - VerificationResult vr = v.doPass2(); - if (vr.getStatus() != VerificationResult.VERIFIED_OK){ - constraintViolated(o, "Return type class/interface could not be verified successfully: '"+vr.getMessage()+"'."); - } - } - - Type[] ts = o.getArgumentTypes(cpg); - for (int i=0; i= 255){ - constraintViolated(o, "Not allowed to create an array with more than 255 dimensions."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitNEWARRAY(Instruction o){ - byte t = ((InstructionByte)o).getTypecode(); - if (! ( (t == Constants.T_BOOLEAN) || - (t == Constants.T_CHAR) || - (t == Constants.T_FLOAT) || - (t == Constants.T_DOUBLE) || - (t == Constants.T_BYTE) || - (t == Constants.T_SHORT) || - (t == Constants.T_INT) || - (t == Constants.T_LONG) ) ){ - constraintViolated(o, "Illegal type code '+t+' for 'atype' operand."); - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitILOAD(Instruction o){ - int idx = o.getIndex(); - if (idx < 0){ - constraintViolated(o, "Index '"+idx+"' must be non-negative."); - } - else{ - int maxminus1 = max_locals()-1; - if (idx > maxminus1){ - constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitFLOAD(Instruction o){ - int idx = o.getIndex(); - if (idx < 0){ - constraintViolated(o, "Index '"+idx+"' must be non-negative."); - } - else{ - int maxminus1 = max_locals()-1; - if (idx > maxminus1){ - constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitALOAD(Instruction o){ - int idx = o.getIndex(); - if (idx < 0){ - constraintViolated(o, "Index '"+idx+"' must be non-negative."); - } - else{ - int maxminus1 = max_locals()-1; - if (idx > maxminus1){ - constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitISTORE(Instruction o){ - int idx = o.getIndex(); - if (idx < 0){ - constraintViolated(o, "Index '"+idx+"' must be non-negative."); - } - else{ - int maxminus1 = max_locals()-1; - if (idx > maxminus1){ - constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitFSTORE(Instruction o){ - int idx = o.getIndex(); - if (idx < 0){ - constraintViolated(o, "Index '"+idx+"' must be non-negative."); - } - else{ - int maxminus1 = max_locals()-1; - if (idx > maxminus1){ - constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitASTORE(Instruction o){ - int idx = o.getIndex(); - if (idx < 0){ - constraintViolated(o, "Index '"+idx+"' must be non-negative."); - } - else{ - int maxminus1 = max_locals()-1; - if (idx > maxminus1){ - constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitIINC(IINC o){ - int idx = o.getIndex(); - if (idx < 0){ - constraintViolated(o, "Index '"+idx+"' must be non-negative."); - } - else{ - int maxminus1 = max_locals()-1; - if (idx > maxminus1){ - constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitRET(RET o){ - int idx = o.getIndex(); - if (idx < 0){ - constraintViolated(o, "Index '"+idx+"' must be non-negative."); - } - else{ - int maxminus1 = max_locals()-1; - if (idx > maxminus1){ - constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitLLOAD(Instruction o){ - int idx = o.getIndex(); - if (idx < 0){ - constraintViolated(o, "Index '"+idx+"' must be non-negative. [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]"); - } - else{ - int maxminus2 = max_locals()-2; - if (idx > maxminus2){ - constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitDLOAD(Instruction o){ - int idx = o.getIndex(); - if (idx < 0){ - constraintViolated(o, "Index '"+idx+"' must be non-negative. [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]"); - } - else{ - int maxminus2 = max_locals()-2; - if (idx > maxminus2){ - constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitLSTORE(Instruction o){ - int idx = o.getIndex(); - if (idx < 0){ - constraintViolated(o, "Index '"+idx+"' must be non-negative. [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]"); - } - else{ - int maxminus2 = max_locals()-2; - if (idx > maxminus2){ - constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitDSTORE(Instruction o){ - int idx = o.getIndex(); - if (idx < 0){ - constraintViolated(o, "Index '"+idx+"' must be non-negative. [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]"); - } - else{ - int maxminus2 = max_locals()-2; - if (idx > maxminus2){ - constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'."); - } - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitLOOKUPSWITCH(LOOKUPSWITCH o){ - int[] matchs = o.getMatchs(); - int max = Integer.MIN_VALUE; - for (int i=0; i= "low". We cannot check this, as BCEL hides - // it from us. - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitPUTSTATIC(FieldInstruction o){ - String field_name = o.getFieldName(cpg); - JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName()); - Field[] fields = jc.getFields(); - Field f = null; - for (int i=0; i. - if ((!(jc.isClass())) && (!(meth_name.equals(Constants.STATIC_INITIALIZER_NAME)))){ - constraintViolated(o, "Interface field '"+f+"' must be set in a '"+Constants.STATIC_INITIALIZER_NAME+"' method."); - } - } - - /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ - public void visitGETSTATIC(FieldInstruction o){ - String field_name = o.getFieldName(cpg); - JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName()); - Field[] fields = jc.getFields(); - Field f = null; - for (int i=0; i. + */ + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.Repository; +import org.aspectj.apache.bcel.classfile.Attribute; +import org.aspectj.apache.bcel.classfile.Code; +import org.aspectj.apache.bcel.classfile.CodeException; +import org.aspectj.apache.bcel.classfile.Constant; +import org.aspectj.apache.bcel.classfile.ConstantClass; +import org.aspectj.apache.bcel.classfile.ConstantDouble; +import org.aspectj.apache.bcel.classfile.ConstantFieldref; +import org.aspectj.apache.bcel.classfile.ConstantFloat; +import org.aspectj.apache.bcel.classfile.ConstantInteger; +import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref; +import org.aspectj.apache.bcel.classfile.ConstantLong; +import org.aspectj.apache.bcel.classfile.ConstantMethodref; +import org.aspectj.apache.bcel.classfile.ConstantNameAndType; +import org.aspectj.apache.bcel.classfile.ConstantString; +import org.aspectj.apache.bcel.classfile.ConstantUtf8; +import org.aspectj.apache.bcel.classfile.Field; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.LineNumber; +import org.aspectj.apache.bcel.classfile.LineNumberTable; +import org.aspectj.apache.bcel.classfile.LocalVariable; +import org.aspectj.apache.bcel.classfile.LocalVariableTable; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.generic.ArrayType; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.generic.FieldInstruction; +import org.aspectj.apache.bcel.generic.IINC; +import org.aspectj.apache.bcel.generic.INVOKEINTERFACE; +import org.aspectj.apache.bcel.generic.Instruction; +import org.aspectj.apache.bcel.generic.InstructionBranch; +import org.aspectj.apache.bcel.generic.InstructionByte; +import org.aspectj.apache.bcel.generic.InstructionHandle; +import org.aspectj.apache.bcel.generic.InstructionList; +import org.aspectj.apache.bcel.generic.InvokeInstruction; +import org.aspectj.apache.bcel.generic.LOOKUPSWITCH; +import org.aspectj.apache.bcel.generic.MULTIANEWARRAY; +import org.aspectj.apache.bcel.generic.ObjectType; +import org.aspectj.apache.bcel.generic.RET; +import org.aspectj.apache.bcel.generic.TABLESWITCH; +import org.aspectj.apache.bcel.generic.Type; +import org.aspectj.apache.bcel.verifier.EmptyClassVisitor; +import org.aspectj.apache.bcel.verifier.PassVerifier; +import org.aspectj.apache.bcel.verifier.VerificationResult; +import org.aspectj.apache.bcel.verifier.Verifier; +import org.aspectj.apache.bcel.verifier.VerifierFactory; +import org.aspectj.apache.bcel.verifier.exc.AssertionViolatedException; +import org.aspectj.apache.bcel.verifier.exc.ClassConstraintException; +import org.aspectj.apache.bcel.verifier.exc.InvalidMethodException; +import org.aspectj.apache.bcel.verifier.exc.StaticCodeConstraintException; +import org.aspectj.apache.bcel.verifier.exc.StaticCodeInstructionConstraintException; +import org.aspectj.apache.bcel.verifier.exc.StaticCodeInstructionOperandConstraintException; + +/** + * This PassVerifier verifies a class file according to + * pass 3, static part as described in The Java Virtual + * Machine Specification, 2nd edition. + * More detailed information is to be found at the do_verify() + * method's documentation. + * + * @version $Id: Pass3aVerifier.java,v 1.1.2.1 2008/05/08 19:26:52 aclement Exp $ + * @author Enver Haase + * @see #do_verify() + */ +public final class Pass3aVerifier extends PassVerifier{ + + /** The Verifier that created this. */ + private Verifier myOwner; + + /** + * The method number to verify. + * This is the index in the array returned + * by JavaClass.getMethods(). + */ + private int method_no; + + /** The one and only InstructionList object used by an instance of this class. It's here for performance reasons by do_verify() and its callees. */ + InstructionList instructionList; + /** The one and only Code object used by an instance of this class. It's here for performance reasons by do_verify() and its callees. */ + Code code; + + /** Should only be instantiated by a Verifier. */ + public Pass3aVerifier(Verifier owner, int method_no){ + myOwner = owner; + this.method_no = method_no; + } + + /** + * Pass 3a is the verification of static constraints of + * JVM code (such as legal targets of branch instructions). + * This is the part of pass 3 where you do not need data + * flow analysis. + * JustIce also delays the checks for a correct exception + * table of a Code attribute and correct line number entries + * in a LineNumberTable attribute of a Code attribute (which + * conceptually belong to pass 2) to this pass. Also, most + * of the check for valid local variable entries in a + * LocalVariableTable attribute of a Code attribute is + * delayed until this pass. + * All these checks need access to the code array of the + * Code attribute. + * + * @throws InvalidMethodException if the method to verify does not exist. + */ + public VerificationResult do_verify(){ + if (myOwner.doPass2().equals(VerificationResult.VR_OK)){ + // Okay, class file was loaded correctly by Pass 1 + // and satisfies static constraints of Pass 2. + JavaClass jc = Repository.lookupClass(myOwner.getClassName()); + Method[] methods = jc.getMethods(); + if (method_no >= methods.length){ + throw new InvalidMethodException("METHOD DOES NOT EXIST!"); + } + Method method = methods[method_no]; + code = method.getCode(); + + // No Code? Nothing to verify! + if ( method.isAbstract() || method.isNative() ){ // IF mg HAS NO CODE (static constraint of Pass 2) + return VerificationResult.VR_OK; + } + + // TODO: + // We want a very sophisticated code examination here with good explanations + // on where to look for an illegal instruction or such. + // Only after that we should try to build an InstructionList and throw an + // AssertionViolatedException if after our examination InstructionList building + // still fails. + // That examination should be implemented in a byte-oriented way, i.e. look for + // an instruction, make sure its validity, count its length, find the next + // instruction and so on. + try{ + instructionList = new InstructionList(method.getCode().getCode()); + } + catch(RuntimeException re){ + return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Bad bytecode in the code array of the Code attribute of method '"+method+"'."); + } + + instructionList.setPositions(true); + + // Start verification. + VerificationResult vr = VerificationResult.VR_OK; //default + try{ + delayedPass2Checks(); + } + catch(ClassConstraintException cce){ + vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, cce.getMessage()); + return vr; + } + try{ + pass3StaticInstructionChecks(); + pass3StaticInstructionOperandsChecks(); + } + catch(StaticCodeConstraintException scce){ + vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, scce.getMessage()); + } + return vr; + } + else{ //did not pass Pass 2. + return VerificationResult.VR_NOTYET; + } + } + + /** + * These are the checks that could be done in pass 2 but are delayed to pass 3 + * for performance reasons. Also, these checks need access to the code array + * of the Code attribute of a Method so it's okay to perform them here. + * Also see the description of the do_verify() method. + * + * @throws ClassConstraintException if the verification fails. + * @see #do_verify() + */ + private void delayedPass2Checks(){ + + int[] instructionPositions = instructionList.getInstructionPositions(); + int codeLength = code.getCode().length; + + ///////////////////// + // LineNumberTable // + ///////////////////// + LineNumberTable lnt = code.getLineNumberTable(); + if (lnt != null){ + LineNumber[] lineNumbers = lnt.getLineNumberTable(); + IntList offsets = new IntList(); + lineNumber_loop: for (int i=0; i < lineNumbers.length; i++){ // may appear in any order. + for (int j=0; j < instructionPositions.length; j++){ + // TODO: Make this a binary search! The instructionPositions array is naturally ordered! + int offset = lineNumbers[i].getStartPC(); + if (instructionPositions[j] == offset){ + if (offsets.contains(offset)){ + addMessage("LineNumberTable attribute '"+code.getLineNumberTable()+"' refers to the same code offset ('"+offset+"') more than once which is violating the semantics [but is sometimes produced by IBM's 'jikes' compiler]."); + } + else{ + offsets.add(offset); + } + continue lineNumber_loop; + } + } + throw new ClassConstraintException("Code attribute '"+code+"' has a LineNumberTable attribute '"+code.getLineNumberTable()+"' referring to a code offset ('"+lineNumbers[i].getStartPC()+"') that does not exist."); + } + } + + /////////////////////////// + // LocalVariableTable(s) // + /////////////////////////// + /* We cannot use code.getLocalVariableTable() because there could be more + than only one. This is a bug in BCEL. */ + Attribute[] atts = code.getAttributes(); + for (int a=0; a= endpc){ + throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has its start_pc ('"+startpc+"') not smaller than its end_pc ('"+endpc+"')."); + } + if (!contains(instructionPositions, startpc)){ + throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has a non-existant bytecode offset as its start_pc ('"+startpc+"')."); + } + if ( (!contains(instructionPositions, endpc)) && (endpc != codeLength)){ + throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has a non-existant bytecode offset as its end_pc ('"+startpc+"') [that is also not equal to code_length ('"+codeLength+"')]."); + } + if (!contains(instructionPositions, handlerpc)){ + throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has a non-existant bytecode offset as its handler_pc ('"+handlerpc+"')."); + } + } + } + + /** + * These are the checks if constraints are satisfied which are described in the + * Java Virtual Machine Specification, Second Edition as Static Constraints on + * the instructions of Java Virtual Machine Code (chapter 4.8.1). + * + * @throws StaticCodeConstraintException if the verification fails. + */ + private void pass3StaticInstructionChecks(){ + + // Code array must not be empty: + // Enforced in pass 2 (also stated in the static constraints of the Code + // array in vmspec2), together with pass 1 (reading code_length bytes and + // interpreting them as code[]). So this must not be checked again here. + + if (! (code.getCode().length < 65536)){// contradicts vmspec2 page 152 ("Limitations"), but is on page 134. + throw new StaticCodeInstructionConstraintException("Code array in code attribute '"+code+"' too big: must be smaller than 65536 bytes."); + } + + // First opcode at offset 0: okay, that's clear. Nothing to do. + + // Only instances of the instructions documented in Section 6.4 may appear in + // the code array. + + // For BCEL's sake, we cannot handle WIDE stuff, but hopefully BCEL does its job right :) + + // The last byte of the last instruction in the code array must be the byte at index + // code_length-1 : See the do_verify() comments. We actually don't iterate through the + // byte array, but use an InstructionList so we cannot check for this. But BCEL does + // things right, so it's implicitly okay. + + // TODO: Check how BCEL handles (and will handle) instructions like IMPDEP1, IMPDEP2, + // BREAKPOINT... that BCEL knows about but which are illegal anyway. + // We currently go the safe way here. + InstructionHandle ih = instructionList.getStart(); + while (ih != null){ + Instruction i = ih.getInstruction(); + if (i.getOpcode()==Constants.IMPDEP1){ + throw new StaticCodeInstructionConstraintException("IMPDEP1 must not be in the code, it is an illegal instruction for _internal_ JVM use!"); + } + if (i.getOpcode()==Constants.IMPDEP2){ + throw new StaticCodeInstructionConstraintException("IMPDEP2 must not be in the code, it is an illegal instruction for _internal_ JVM use!"); + } + if (i.getOpcode()==Constants.BREAKPOINT){ + throw new StaticCodeInstructionConstraintException("BREAKPOINT must not be in the code, it is an illegal instruction for _internal_ JVM use!"); + } + ih = ih.getNext(); + } + + // The original verifier seems to do this check here, too. + // An unreachable last instruction may also not fall through the + // end of the code, which is stupid -- but with the original + // verifier's subroutine semantics one cannot predict reachability. + Instruction last = instructionList.getEnd().getInstruction(); + if (! ((last.isReturnInstruction()) || + (last instanceof RET) || + (last.getOpcode()==Constants.GOTO || last.getOpcode()==Constants.GOTO_W) || + (last.getOpcode()==Constants.ATHROW))) // JSR / JSR_W would possibly RETurn and then fall off the code! + throw new StaticCodeInstructionConstraintException("Execution must not fall off the bottom of the code array. This constraint is enforced statically as some existing verifiers do - so it may be a false alarm if the last instruction is not reachable."); + } + + /** + * These are the checks for the satisfaction of constraints which are described in the + * Java Virtual Machine Specification, Second Edition as Static Constraints on + * the operands of instructions of Java Virtual Machine Code (chapter 4.8.1). + * BCEL parses the code array to create an InstructionList and therefore has to check + * some of these constraints. Additional checks are also implemented here. + * + * @throws StaticCodeConstraintException if the verification fails. + */ + private void pass3StaticInstructionOperandsChecks(){ + // When building up the InstructionList, BCEL has already done all those checks + // mentioned in The Java Virtual Machine Specification, Second Edition, as + // "static constraints on the operands of instructions in the code array". + // TODO: see the do_verify() comments. Maybe we should really work on the + // byte array first to give more comprehensive messages. + // TODO: Review Exception API, possibly build in some "offending instruction" thing + // when we're ready to insulate the offending instruction by doing the + // above thing. + + // TODO: Implement as much as possible here. BCEL does _not_ check everything. + + ConstantPool cpg = new ConstantPool(Repository.lookupClass(myOwner.getClassName()).getConstantPool().getConstantPool()); + InstOperandConstraintVisitor v = new InstOperandConstraintVisitor(cpg); + + // Checks for the things BCEL does _not_ handle itself. + InstructionHandle ih = instructionList.getStart(); + while (ih != null){ + Instruction i = ih.getInstruction(); + + // An "own" constraint, due to JustIce's new definition of what "subroutine" means. + if (i.isJsrInstruction()){ + InstructionHandle target = ((InstructionBranch) i).getTarget(); + if (target == instructionList.getStart()){ + throw new StaticCodeInstructionOperandConstraintException("Due to JustIce's clear definition of subroutines, no JSR or JSR_W may have a top-level instruction (such as the very first instruction, which is targeted by instruction '"+ih+"' as its target."); + } + if (!(target.getInstruction().isASTORE())){ + throw new StaticCodeInstructionOperandConstraintException("Due to JustIce's clear definition of subroutines, no JSR or JSR_W may target anything else than an ASTORE instruction. Instruction '"+ih+"' targets '"+target+"'."); + } + } + + // vmspec2, page 134-137 + ih.accept(v); + + ih = ih.getNext(); + } + + } + + /** A small utility method returning if a given int i is in the given int[] ints. */ + private static boolean contains(int[] ints, int i){ + for (int j=0; j= cpg.getSize()){ + constraintViolated(i, "Illegal constant pool index '"+idx+"'."); + } + } + + /////////////////////////////////////////////////////////// + // The Java Virtual Machine Specification, pages 134-137 // + /////////////////////////////////////////////////////////// + /** + * Assures the generic preconditions of a LoadClass instance. + * The referenced class is loaded and pass2-verified. + */ + public void visitLoadClass(Instruction o){ + ObjectType t = o.getLoadClassType(cpg); + if (t != null){// null means "no class is loaded" + Verifier v = VerifierFactory.getVerifier(t.getClassName()); + VerificationResult vr = v.doPass1(); + if (vr.getStatus() != VerificationResult.VERIFIED_OK){ + constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded: '"+vr+"'."); + } + } + } + + // The target of each jump and branch instruction [...] must be the opcode [...] + // BCEL _DOES_ handle this. + + // tableswitch: BCEL will do it, supposedly. + + // lookupswitch: BCEL will do it, supposedly. + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + // LDC and LDC_W (LDC_W is a subclass of LDC in BCEL's model) + public void visitLDC(Instruction o){ + indexValid(o, o.getIndex()); + Constant c = cpg.getConstant(o.getIndex()); + if (! ( (c instanceof ConstantInteger) || + (c instanceof ConstantFloat) || + (c instanceof ConstantString) ) ){ + constraintViolated(o, "Operand of LDC or LDC_W must be one of CONSTANT_Integer, CONSTANT_Float or CONSTANT_String, but is '"+c+"'."); + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + // LDC2_W + public void visitLDC2_W(Instruction o){ + indexValid(o, o.getIndex()); + Constant c = cpg.getConstant(o.getIndex()); + if (! ( (c instanceof ConstantLong) || + (c instanceof ConstantDouble) ) ){ + constraintViolated(o, "Operand of LDC2_W must be CONSTANT_Long or CONSTANT_Double, but is '"+c+"'."); + } + try{ + indexValid(o, o.getIndex()+1); + } + catch(StaticCodeInstructionOperandConstraintException e){ + throw new AssertionViolatedException("OOPS: Does not BCEL handle that? LDC2_W operand has a problem."); + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + //getfield, putfield, getstatic, putstatic + public void visitFieldInstruction(FieldInstruction o){ + indexValid(o, o.getIndex()); + Constant c = cpg.getConstant(o.getIndex()); + if (! (c instanceof ConstantFieldref)){ + constraintViolated(o, "Indexing a constant that's not a CONSTANT_Fieldref but a '"+c+"'."); + } + + String field_name = o.getFieldName(cpg); + + JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName()); + Field[] fields = jc.getFields(); + Field f = null; + for (int i=0; i or + ConstantNameAndType cnat = (ConstantNameAndType) (cpg.getConstant(((ConstantInterfaceMethodref)c).getNameAndTypeIndex())); + String name = ((ConstantUtf8) (cpg.getConstant(cnat.getNameIndex()))).getBytes(); + if (name.equals(Constants.CONSTRUCTOR_NAME)){ + constraintViolated(o, "Method to invoke must not be '"+Constants.CONSTRUCTOR_NAME+"'."); + } + if (name.equals(Constants.STATIC_INITIALIZER_NAME)){ + constraintViolated(o, "Method to invoke must not be '"+Constants.STATIC_INITIALIZER_NAME+"'."); + } + } + + // The LoadClassType is the method-declaring class, so we have to check the other types. + + Type t = o.getReturnType(cpg); + if (t instanceof ArrayType){ + t = ((ArrayType) t).getBasicType(); + } + if (t instanceof ObjectType){ + Verifier v = VerifierFactory.getVerifier(((ObjectType) t).getClassName()); + VerificationResult vr = v.doPass2(); + if (vr.getStatus() != VerificationResult.VERIFIED_OK){ + constraintViolated(o, "Return type class/interface could not be verified successfully: '"+vr.getMessage()+"'."); + } + } + + Type[] ts = o.getArgumentTypes(cpg); + for (int i=0; i= 255){ + constraintViolated(o, "Not allowed to create an array with more than 255 dimensions."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitNEWARRAY(Instruction o){ + byte t = ((InstructionByte)o).getTypecode(); + if (! ( (t == Constants.T_BOOLEAN) || + (t == Constants.T_CHAR) || + (t == Constants.T_FLOAT) || + (t == Constants.T_DOUBLE) || + (t == Constants.T_BYTE) || + (t == Constants.T_SHORT) || + (t == Constants.T_INT) || + (t == Constants.T_LONG) ) ){ + constraintViolated(o, "Illegal type code '+t+' for 'atype' operand."); + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitILOAD(Instruction o){ + int idx = o.getIndex(); + if (idx < 0){ + constraintViolated(o, "Index '"+idx+"' must be non-negative."); + } + else{ + int maxminus1 = max_locals()-1; + if (idx > maxminus1){ + constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitFLOAD(Instruction o){ + int idx = o.getIndex(); + if (idx < 0){ + constraintViolated(o, "Index '"+idx+"' must be non-negative."); + } + else{ + int maxminus1 = max_locals()-1; + if (idx > maxminus1){ + constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitALOAD(Instruction o){ + int idx = o.getIndex(); + if (idx < 0){ + constraintViolated(o, "Index '"+idx+"' must be non-negative."); + } + else{ + int maxminus1 = max_locals()-1; + if (idx > maxminus1){ + constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitISTORE(Instruction o){ + int idx = o.getIndex(); + if (idx < 0){ + constraintViolated(o, "Index '"+idx+"' must be non-negative."); + } + else{ + int maxminus1 = max_locals()-1; + if (idx > maxminus1){ + constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitFSTORE(Instruction o){ + int idx = o.getIndex(); + if (idx < 0){ + constraintViolated(o, "Index '"+idx+"' must be non-negative."); + } + else{ + int maxminus1 = max_locals()-1; + if (idx > maxminus1){ + constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitASTORE(Instruction o){ + int idx = o.getIndex(); + if (idx < 0){ + constraintViolated(o, "Index '"+idx+"' must be non-negative."); + } + else{ + int maxminus1 = max_locals()-1; + if (idx > maxminus1){ + constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitIINC(IINC o){ + int idx = o.getIndex(); + if (idx < 0){ + constraintViolated(o, "Index '"+idx+"' must be non-negative."); + } + else{ + int maxminus1 = max_locals()-1; + if (idx > maxminus1){ + constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitRET(RET o){ + int idx = o.getIndex(); + if (idx < 0){ + constraintViolated(o, "Index '"+idx+"' must be non-negative."); + } + else{ + int maxminus1 = max_locals()-1; + if (idx > maxminus1){ + constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitLLOAD(Instruction o){ + int idx = o.getIndex(); + if (idx < 0){ + constraintViolated(o, "Index '"+idx+"' must be non-negative. [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]"); + } + else{ + int maxminus2 = max_locals()-2; + if (idx > maxminus2){ + constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitDLOAD(Instruction o){ + int idx = o.getIndex(); + if (idx < 0){ + constraintViolated(o, "Index '"+idx+"' must be non-negative. [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]"); + } + else{ + int maxminus2 = max_locals()-2; + if (idx > maxminus2){ + constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitLSTORE(Instruction o){ + int idx = o.getIndex(); + if (idx < 0){ + constraintViolated(o, "Index '"+idx+"' must be non-negative. [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]"); + } + else{ + int maxminus2 = max_locals()-2; + if (idx > maxminus2){ + constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitDSTORE(Instruction o){ + int idx = o.getIndex(); + if (idx < 0){ + constraintViolated(o, "Index '"+idx+"' must be non-negative. [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]"); + } + else{ + int maxminus2 = max_locals()-2; + if (idx > maxminus2){ + constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'."); + } + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitLOOKUPSWITCH(LOOKUPSWITCH o){ + int[] matchs = o.getMatchs(); + int max = Integer.MIN_VALUE; + for (int i=0; i= "low". We cannot check this, as BCEL hides + // it from us. + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitPUTSTATIC(FieldInstruction o){ + String field_name = o.getFieldName(cpg); + JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName()); + Field[] fields = jc.getFields(); + Field f = null; + for (int i=0; i. + if ((!(jc.isClass())) && (!(meth_name.equals(Constants.STATIC_INITIALIZER_NAME)))){ + constraintViolated(o, "Interface field '"+f+"' must be set in a '"+Constants.STATIC_INITIALIZER_NAME+"' method."); + } + } + + /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ + public void visitGETSTATIC(FieldInstruction o){ + String field_name = o.getFieldName(cpg); + JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName()); + Field[] fields = jc.getFields(); + Field f = null; + for (int i=0; i. - */ - -import org.aspectj.apache.bcel.classfile.AnnotationDefault; -import org.aspectj.apache.bcel.classfile.Code; -import org.aspectj.apache.bcel.classfile.CodeException; -import org.aspectj.apache.bcel.classfile.ConstantClass; -import org.aspectj.apache.bcel.classfile.ConstantDouble; -import org.aspectj.apache.bcel.classfile.ConstantFieldref; -import org.aspectj.apache.bcel.classfile.ConstantFloat; -import org.aspectj.apache.bcel.classfile.ConstantInteger; -import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref; -import org.aspectj.apache.bcel.classfile.ConstantLong; -import org.aspectj.apache.bcel.classfile.ConstantMethodref; -import org.aspectj.apache.bcel.classfile.ConstantNameAndType; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.ConstantString; -import org.aspectj.apache.bcel.classfile.ConstantUtf8; -import org.aspectj.apache.bcel.classfile.ConstantValue; -import org.aspectj.apache.bcel.classfile.Deprecated; -import org.aspectj.apache.bcel.classfile.ExceptionTable; -import org.aspectj.apache.bcel.classfile.Field; -import org.aspectj.apache.bcel.classfile.InnerClass; -import org.aspectj.apache.bcel.classfile.InnerClasses; -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.classfile.LineNumber; -import org.aspectj.apache.bcel.classfile.LineNumberTable; -import org.aspectj.apache.bcel.classfile.LocalVariable; -import org.aspectj.apache.bcel.classfile.LocalVariableTable; -import org.aspectj.apache.bcel.classfile.LocalVariableTypeTable; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.classfile.Node; -import org.aspectj.apache.bcel.classfile.Signature; -import org.aspectj.apache.bcel.classfile.SourceFile; -import org.aspectj.apache.bcel.classfile.StackMap; -import org.aspectj.apache.bcel.classfile.Synthetic; -import org.aspectj.apache.bcel.classfile.Unknown; -import org.aspectj.apache.bcel.classfile.Visitor; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; -import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; -import org.aspectj.apache.bcel.verifier.exc.AssertionViolatedException; - -/** - * BCEL's Node classes (those from the classfile API that accept() Visitor - * instances) have toString() methods that were not designed to be robust, - * this gap is closed by this class. - * When performing class file verification, it may be useful to output which - * entity (e.g. a Code instance) is not satisfying the verifier's - * constraints, but in this case it could be possible for the toString() - * method to throw a RuntimeException. - * A (new StringRepresentation(Node n)).toString() never throws any exception. - * Note that this class also serves as a placeholder for more sophisticated message - * handling in future versions of JustIce. - * - * @version $Id: StringRepresentation.java,v 1.4.4.1 2008/04/25 17:55:38 aclement Exp $ - * @author Enver Haase - */ -public class StringRepresentation extends org.aspectj.apache.bcel.classfile.EmptyVisitor implements Visitor{ - /** The string representation, created by a visitXXX() method, output by toString(). */ - private String tostring; - /** The node we ask for its string representation. Not really needed; only for debug output. */ - private Node n; - /** - * Creates a new StringRepresentation object which is the representation of n. - * - * @see #toString() - */ - public StringRepresentation(Node n){ - this.n = n; - n.accept(this); // assign a string representation to field 'tostring' if we know n's class. - } - /** - * Returns the String representation. - */ - public String toString(){ - // The run-time check below is needed because we don't want to omit inheritance - // of "EmptyVisitor" and provide a thousand empty methods. - // However, in terms of performance this would be a better idea. - // If some new "Node" is defined in BCEL (such as some concrete "Attribute"), we - // want to know that this class has also to be adapted. - if (tostring == null) throw new AssertionViolatedException("Please adapt '"+getClass()+"' to deal with objects of class '"+n.getClass()+"'."); - return tostring; - } - /** - * Returns the String representation of the Node object obj; - * this is obj.toString() if it does not throw any RuntimeException, - * or else it is a string derived only from obj's class name. - */ - private String toString(Node obj){ - String ret; - try{ - ret = obj.toString(); - } - catch(RuntimeException e){ - String s = obj.getClass().getName(); - s = s.substring(s.lastIndexOf(".")+1); - ret = "<<"+s+">>"; - } - catch(ClassFormatError e){ /* BCEL can be harsh e.g. trying to convert the "signature" of a ReturnaddressType LocalVariable (shouldn't occur, but people do crazy things) */ - String s = obj.getClass().getName(); - s = s.substring(s.lastIndexOf(".")+1); - ret = "<<"+s+">>"; - } - return ret; - } - //////////////////////////////// - // Visitor methods start here // - //////////////////////////////// - // We don't of course need to call some default implementation: - // e.g. we could also simply output "Code" instead of a possibly - // lengthy Code attribute's toString(). - public void visitCode(Code obj){ - //tostring = toString(obj); - tostring = ""; // We don't need real code outputs. - } - public void visitCodeException(CodeException obj){ - tostring = toString(obj); - } - public void visitConstantClass(ConstantClass obj){ - tostring = toString(obj); - } - public void visitConstantDouble(ConstantDouble obj){ - tostring = toString(obj); - } - public void visitConstantFieldref(ConstantFieldref obj){ - tostring = toString(obj); - } - public void visitConstantFloat(ConstantFloat obj){ - tostring = toString(obj); - } - public void visitConstantInteger(ConstantInteger obj){ - tostring = toString(obj); - } - public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj){ - tostring = toString(obj); - } - public void visitConstantLong(ConstantLong obj){ - tostring = toString(obj); - } - public void visitConstantMethodref(ConstantMethodref obj){ - tostring = toString(obj); - } - public void visitConstantNameAndType(ConstantNameAndType obj){ - tostring = toString(obj); - } - public void visitConstantPool(ConstantPool obj){ - tostring = toString(obj); - } - public void visitConstantString(ConstantString obj){ - tostring = toString(obj); - } - public void visitConstantUtf8(ConstantUtf8 obj){ - tostring = toString(obj); - } - public void visitConstantValue(ConstantValue obj){ - tostring = toString(obj); - } - public void visitDeprecated(Deprecated obj){ - tostring = toString(obj); - } - public void visitExceptionTable(ExceptionTable obj){ - tostring = toString(obj); - } - public void visitField(Field obj){ - tostring = toString(obj); - } - public void visitInnerClass(InnerClass obj){ - tostring = toString(obj); - } - public void visitInnerClasses(InnerClasses obj){ - tostring = toString(obj); - } - public void visitJavaClass(JavaClass obj){ - tostring = toString(obj); - } - public void visitLineNumber(LineNumber obj){ - tostring = toString(obj); - } - public void visitLineNumberTable(LineNumberTable obj){ - tostring = ""; - } - public void visitLocalVariable(LocalVariable obj){ - tostring = toString(obj); - } - public void visitLocalVariableTable(LocalVariableTable obj){ - tostring = ""; - } - public void visitMethod(Method obj){ - tostring = toString(obj); - } - public void visitSignature(Signature obj){ - tostring = toString(obj); - } - public void visitSourceFile(SourceFile obj){ - tostring = toString(obj); - } - public void visitStackMap(StackMap obj){ - tostring = toString(obj); - } - public void visitSynthetic(Synthetic obj){ - tostring = toString(obj); - } - public void visitUnknown(Unknown obj){ - tostring = toString(obj); - } - - public void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations obj) {tostring = toString(obj);} - public void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations obj) {tostring = toString(obj);} - public void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations obj) {tostring = toString(obj);} - public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations obj) {tostring = toString(obj);} - public void visitAnnotationDefault(AnnotationDefault obj) {tostring = toString(obj);} - public void visitLocalVariableTypeTable(LocalVariableTypeTable obj) {tostring = toString(obj);} - -} +package org.aspectj.apache.bcel.verifier.statics; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.classfile.AnnotationDefault; +import org.aspectj.apache.bcel.classfile.Code; +import org.aspectj.apache.bcel.classfile.CodeException; +import org.aspectj.apache.bcel.classfile.ConstantClass; +import org.aspectj.apache.bcel.classfile.ConstantDouble; +import org.aspectj.apache.bcel.classfile.ConstantFieldref; +import org.aspectj.apache.bcel.classfile.ConstantFloat; +import org.aspectj.apache.bcel.classfile.ConstantInteger; +import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref; +import org.aspectj.apache.bcel.classfile.ConstantLong; +import org.aspectj.apache.bcel.classfile.ConstantMethodref; +import org.aspectj.apache.bcel.classfile.ConstantNameAndType; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.classfile.ConstantString; +import org.aspectj.apache.bcel.classfile.ConstantUtf8; +import org.aspectj.apache.bcel.classfile.ConstantValue; +import org.aspectj.apache.bcel.classfile.Deprecated; +import org.aspectj.apache.bcel.classfile.ExceptionTable; +import org.aspectj.apache.bcel.classfile.Field; +import org.aspectj.apache.bcel.classfile.InnerClass; +import org.aspectj.apache.bcel.classfile.InnerClasses; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.LineNumber; +import org.aspectj.apache.bcel.classfile.LineNumberTable; +import org.aspectj.apache.bcel.classfile.LocalVariable; +import org.aspectj.apache.bcel.classfile.LocalVariableTable; +import org.aspectj.apache.bcel.classfile.LocalVariableTypeTable; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.classfile.Node; +import org.aspectj.apache.bcel.classfile.Signature; +import org.aspectj.apache.bcel.classfile.SourceFile; +import org.aspectj.apache.bcel.classfile.StackMap; +import org.aspectj.apache.bcel.classfile.Synthetic; +import org.aspectj.apache.bcel.classfile.Unknown; +import org.aspectj.apache.bcel.classfile.ClassVisitor; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; +import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; +import org.aspectj.apache.bcel.verifier.exc.AssertionViolatedException; + +/** + * BCEL's Node classes (those from the classfile API that accept() Visitor + * instances) have toString() methods that were not designed to be robust, + * this gap is closed by this class. + * When performing class file verification, it may be useful to output which + * entity (e.g. a Code instance) is not satisfying the verifier's + * constraints, but in this case it could be possible for the toString() + * method to throw a RuntimeException. + * A (new StringRepresentation(Node n)).toString() never throws any exception. + * Note that this class also serves as a placeholder for more sophisticated message + * handling in future versions of JustIce. + * + * @version $Id: StringRepresentation.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class StringRepresentation extends org.aspectj.apache.bcel.verifier.EmptyClassVisitor implements ClassVisitor{ + /** The string representation, created by a visitXXX() method, output by toString(). */ + private String tostring; + /** The node we ask for its string representation. Not really needed; only for debug output. */ + private Node n; + /** + * Creates a new StringRepresentation object which is the representation of n. + * + * @see #toString() + */ + public StringRepresentation(Node n){ + this.n = n; + n.accept(this); // assign a string representation to field 'tostring' if we know n's class. + } + /** + * Returns the String representation. + */ + public String toString(){ + // The run-time check below is needed because we don't want to omit inheritance + // of "EmptyVisitor" and provide a thousand empty methods. + // However, in terms of performance this would be a better idea. + // If some new "Node" is defined in BCEL (such as some concrete "Attribute"), we + // want to know that this class has also to be adapted. + if (tostring == null) throw new AssertionViolatedException("Please adapt '"+getClass()+"' to deal with objects of class '"+n.getClass()+"'."); + return tostring; + } + /** + * Returns the String representation of the Node object obj; + * this is obj.toString() if it does not throw any RuntimeException, + * or else it is a string derived only from obj's class name. + */ + private String toString(Node obj){ + String ret; + try{ + ret = obj.toString(); + } + catch(RuntimeException e){ + String s = obj.getClass().getName(); + s = s.substring(s.lastIndexOf(".")+1); + ret = "<<"+s+">>"; + } + catch(ClassFormatError e){ /* BCEL can be harsh e.g. trying to convert the "signature" of a ReturnaddressType LocalVariable (shouldn't occur, but people do crazy things) */ + String s = obj.getClass().getName(); + s = s.substring(s.lastIndexOf(".")+1); + ret = "<<"+s+">>"; + } + return ret; + } + //////////////////////////////// + // Visitor methods start here // + //////////////////////////////// + // We don't of course need to call some default implementation: + // e.g. we could also simply output "Code" instead of a possibly + // lengthy Code attribute's toString(). + public void visitCode(Code obj){ + //tostring = toString(obj); + tostring = ""; // We don't need real code outputs. + } + public void visitCodeException(CodeException obj){ + tostring = toString(obj); + } + public void visitConstantClass(ConstantClass obj){ + tostring = toString(obj); + } + public void visitConstantDouble(ConstantDouble obj){ + tostring = toString(obj); + } + public void visitConstantFieldref(ConstantFieldref obj){ + tostring = toString(obj); + } + public void visitConstantFloat(ConstantFloat obj){ + tostring = toString(obj); + } + public void visitConstantInteger(ConstantInteger obj){ + tostring = toString(obj); + } + public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj){ + tostring = toString(obj); + } + public void visitConstantLong(ConstantLong obj){ + tostring = toString(obj); + } + public void visitConstantMethodref(ConstantMethodref obj){ + tostring = toString(obj); + } + public void visitConstantNameAndType(ConstantNameAndType obj){ + tostring = toString(obj); + } + public void visitConstantPool(ConstantPool obj){ + tostring = toString(obj); + } + public void visitConstantString(ConstantString obj){ + tostring = toString(obj); + } + public void visitConstantUtf8(ConstantUtf8 obj){ + tostring = toString(obj); + } + public void visitConstantValue(ConstantValue obj){ + tostring = toString(obj); + } + public void visitDeprecated(Deprecated obj){ + tostring = toString(obj); + } + public void visitExceptionTable(ExceptionTable obj){ + tostring = toString(obj); + } + public void visitField(Field obj){ + tostring = toString(obj); + } + public void visitInnerClass(InnerClass obj){ + tostring = toString(obj); + } + public void visitInnerClasses(InnerClasses obj){ + tostring = toString(obj); + } + public void visitJavaClass(JavaClass obj){ + tostring = toString(obj); + } + public void visitLineNumber(LineNumber obj){ + tostring = toString(obj); + } + public void visitLineNumberTable(LineNumberTable obj){ + tostring = ""; + } + public void visitLocalVariable(LocalVariable obj){ + tostring = toString(obj); + } + public void visitLocalVariableTable(LocalVariableTable obj){ + tostring = ""; + } + public void visitMethod(Method obj){ + tostring = toString(obj); + } + public void visitSignature(Signature obj){ + tostring = toString(obj); + } + public void visitSourceFile(SourceFile obj){ + tostring = toString(obj); + } + public void visitStackMap(StackMap obj){ + tostring = toString(obj); + } + public void visitSynthetic(Synthetic obj){ + tostring = toString(obj); + } + public void visitUnknown(Unknown obj){ + tostring = toString(obj); + } + + public void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations obj) {tostring = toString(obj);} + public void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations obj) {tostring = toString(obj);} + public void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations obj) {tostring = toString(obj);} + public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations obj) {tostring = toString(obj);} + public void visitAnnotationDefault(AnnotationDefault obj) {tostring = toString(obj);} + public void visitLocalVariableTypeTable(LocalVariableTypeTable obj) {tostring = toString(obj);} + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/package.html b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/package.html similarity index 87% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/package.html rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/package.html index e9d065009..349fee9a3 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/statics/package.html +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/statics/package.html @@ -1,26 +1,26 @@ - - - - - - - -Provides PassVerifier classes used internally by JustIce. You don't need to bother with them. - -

          Package Specification

          - -Contained in this package are PassVerifier classes for use with the JustIce verifier. -Only the passes performing what Sun calls 'static constraints' have PassVerifier classes -here. - -

          Related Documentation

          - -For a simple demonstration of JustIce working, please see: - - - - + + + + + + + +Provides PassVerifier classes used internally by JustIce. You don't need to bother with them. + +

          Package Specification

          + +Contained in this package are PassVerifier classes for use with the JustIce verifier. +Only the passes performing what Sun calls 'static constraints' have PassVerifier classes +here. + +

          Related Documentation

          + +For a simple demonstration of JustIce working, please see: + + + + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/ControlFlowGraph.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/ControlFlowGraph.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/ControlFlowGraph.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/ControlFlowGraph.java index b8aeb2441..08a79976b 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/ControlFlowGraph.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/ControlFlowGraph.java @@ -1,475 +1,475 @@ -package org.aspectj.apache.bcel.verifier.structurals; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Hashtable; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.generic.Instruction; -import org.aspectj.apache.bcel.generic.InstructionBranch; -import org.aspectj.apache.bcel.generic.InstructionHandle; -import org.aspectj.apache.bcel.generic.InstructionSelect; -import org.aspectj.apache.bcel.generic.MethodGen; -import org.aspectj.apache.bcel.generic.RET; -import org.aspectj.apache.bcel.verifier.exc.AssertionViolatedException; -import org.aspectj.apache.bcel.verifier.exc.StructuralCodeConstraintException; - -/** - * This class represents a control flow graph of a method. - * - * @version $Id: ControlFlowGraph.java,v 1.4.10.2 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public class ControlFlowGraph{ - - /** - * Objects of this class represent a node in a ControlFlowGraph. - * These nodes are instructions, not basic blocks. - */ - private class InstructionContextImpl implements InstructionContext{ - - /** - * The TAG field is here for external temporary flagging, such - * as graph colouring. - * - * @see #getTag() - * @see #setTag(int) - */ - private int TAG; - - /** - * The InstructionHandle this InstructionContext is wrapped around. - */ - private InstructionHandle instruction; - - /** - * The 'incoming' execution Frames. - */ - private HashMap inFrames; // key: the last-executed JSR - - /** - * The 'outgoing' execution Frames. - */ - private HashMap outFrames; // key: the last-executed JSR - - /** - * The 'execution predecessors' - a list of type InstructionContext - * of those instances that have been execute()d before in that order. - */ - private ArrayList executionPredecessors = null; // Type: InstructionContext - - /** - * Creates an InstructionHandleImpl object from an InstructionHandle. - * Creation of one per InstructionHandle suffices. Don't create more. - */ - public InstructionContextImpl(InstructionHandle inst){ - if (inst == null) throw new AssertionViolatedException("Cannot instantiate InstructionContextImpl from NULL."); - - instruction = inst; - inFrames = new java.util.HashMap(); - outFrames = new java.util.HashMap(); - } - - /* Satisfies InstructionContext.getTag(). */ - public int getTag(){ - return TAG; - } - - /* Satisfies InstructionContext.setTag(int). */ - public void setTag(int tag){ - TAG = tag; - } - - /** - * Returns the exception handlers of this instruction. - */ - public ExceptionHandler[] getExceptionHandlers(){ - return exceptionhandlers.getExceptionHandlers(getInstruction()); - } - - /** - * Returns a clone of the "outgoing" frame situation with respect to the given ExecutionChain. - */ - public Frame getOutFrame(ArrayList execChain){ - executionPredecessors = execChain; - - Frame org; - - InstructionContext jsr = lastExecutionJSR(); - - org = (Frame) outFrames.get(jsr); - - if (org == null){ - throw new AssertionViolatedException("outFrame not set! This:\n"+this+"\nExecutionChain: "+getExecutionChain()+"\nOutFrames: '"+outFrames+"'."); - } - return org.getClone(); - } - - /** - * "Merges in" (vmspec2, page 146) the "incoming" frame situation; - * executes the instructions symbolically - * and therefore calculates the "outgoing" frame situation. - * Returns: True iff the "incoming" frame situation changed after - * merging with "inFrame". - * The execPreds ArrayList must contain the InstructionContext - * objects executed so far in the correct order. This is just - * one execution path [out of many]. This is needed to correctly - * "merge" in the special case of a RET's successor. - * The InstConstraintVisitor and ExecutionVisitor instances - * must be set up correctly. - * @return true - if and only if the "outgoing" frame situation - * changed from the one before execute()ing. - */ - public boolean execute(Frame inFrame, ArrayList execPreds, InstConstraintVisitor icv, ExecutionVisitor ev){ - - executionPredecessors = (ArrayList) execPreds.clone(); - - //sanity check - if ( (lastExecutionJSR() == null) && (subroutines.subroutineOf(getInstruction()) != subroutines.getTopLevel() ) ){ - throw new AssertionViolatedException("Huh?! Am I '"+this+"' part of a subroutine or not?"); - } - if ( (lastExecutionJSR() != null) && (subroutines.subroutineOf(getInstruction()) == subroutines.getTopLevel() ) ){ - throw new AssertionViolatedException("Huh?! Am I '"+this+"' part of a subroutine or not?"); - } - - Frame inF = (Frame) inFrames.get(lastExecutionJSR()); - if (inF == null){// no incoming frame was set, so set it. - inFrames.put(lastExecutionJSR(), inFrame); - inF = inFrame; - } - else{// if there was an "old" inFrame - if (inF.equals(inFrame)){ //shortcut: no need to merge equal frames. - return false; - } - if (! mergeInFrames(inFrame)){ - return false; - } - } - - // Now we're sure the inFrame has changed! - - // new inFrame is already merged in, see above. - Frame workingFrame = inF.getClone(); - - try{ - // This verifies the InstructionConstraint for the current - // instruction, but does not modify the workingFrame object. -//InstConstraintVisitor icv = InstConstraintVisitor.getInstance(VerifierFactory.getVerifier(method_gen.getClassName())); - icv.setFrame(workingFrame); - getInstruction().accept(icv); - } - catch(StructuralCodeConstraintException ce){ - ce.extendMessage("","\nInstructionHandle: "+getInstruction()+"\n"); - ce.extendMessage("","\nExecution Frame:\n"+workingFrame); - extendMessageWithFlow(ce); - throw ce; - } - - // This executes the Instruction. - // Therefore the workingFrame object is modified. -//ExecutionVisitor ev = ExecutionVisitor.getInstance(VerifierFactory.getVerifier(method_gen.getClassName())); - ev.setFrame(workingFrame); - getInstruction().accept(ev); - //getInstruction().accept(ExecutionVisitor.withFrame(workingFrame)); - outFrames.put(lastExecutionJSR(), workingFrame); - - return true; // new inFrame was different from old inFrame so merging them - // yielded a different this.inFrame. - } - - /** - * Returns a simple String representation of this InstructionContext. - */ - public String toString(){ - //TODO: Put information in the brackets, e.g. - // Is this an ExceptionHandler? Is this a RET? Is this the start of - // a subroutine? - String ret = getInstruction().toString(false)+"\t[InstructionContext]"; - return ret; - } - - /** - * Does the actual merging (vmspec2, page 146). - * Returns true IFF this.inFrame was changed in course of merging with inFrame. - */ - private boolean mergeInFrames(Frame inFrame){ - // TODO: Can be performance-improved. - Frame inF = (Frame) inFrames.get(lastExecutionJSR()); - OperandStack oldstack = inF.getStack().getClone(); - LocalVariables oldlocals = inF.getLocals().getClone(); - try{ - inF.getStack().merge(inFrame.getStack()); - inF.getLocals().merge(inFrame.getLocals()); - } - catch (StructuralCodeConstraintException sce){ - extendMessageWithFlow(sce); - throw sce; - } - if ( oldstack.equals(inF.getStack()) && - oldlocals.equals(inF.getLocals()) ){ - return false; - } - else{ - return true; - } - } - - /** - * Returns the control flow execution chain. This is built - * while execute(Frame, ArrayList)-ing the code represented - * by the surrounding ControlFlowGraph. - */ - private String getExecutionChain(){ - String s = this.toString(); - for (int i=executionPredecessors.size()-1; i>=0; i--){ - s = executionPredecessors.get(i)+"\n" + s; - } - return s; - } - - - /** - * Extends the StructuralCodeConstraintException ("e") object with an at-the-end-extended message. - * This extended message will then reflect the execution flow needed to get to the constraint - * violation that triggered the throwing of the "e" object. - */ - private void extendMessageWithFlow(StructuralCodeConstraintException e){ - String s = "Execution flow:\n"; - e.extendMessage("", s+getExecutionChain()); - } - - /* - * Fulfils the contract of InstructionContext.getInstruction(). - */ - public InstructionHandle getInstruction(){ - return instruction; - } - - /** - * Returns the InstructionContextImpl with an JSR/JSR_W - * that was last in the ExecutionChain, without - * a corresponding RET, i.e. - * we were called by this one. - * Returns null if we were called from the top level. - */ - private InstructionContextImpl lastExecutionJSR(){ - - int size = executionPredecessors.size(); - int retcount = 0; - - for (int i=size-1; i>=0; i--){ - InstructionContextImpl current = (InstructionContextImpl) (executionPredecessors.get(i)); - Instruction currentlast = current.getInstruction().getInstruction(); - if (currentlast instanceof RET) retcount++; - if (currentlast.isJsrInstruction()){ - retcount--; - if (retcount == -1) return current; - } - } - return null; - } - - /* Satisfies InstructionContext.getSuccessors(). */ - public InstructionContext[] getSuccessors(){ - return contextsOf(_getSuccessors()); - } - - /** - * A utility method that calculates the successors of a given InstructionHandle - * That means, a RET does have successors as defined here. - * A JsrInstruction has its target as its successor - * (opposed to its physical successor) as defined here. - */ -// TODO: implement caching! - private InstructionHandle[] _getSuccessors(){ - final InstructionHandle[] empty = new InstructionHandle[0]; - final InstructionHandle[] single = new InstructionHandle[1]; - final InstructionHandle[] pair = new InstructionHandle[2]; - - Instruction inst = getInstruction().getInstruction(); - - if (inst instanceof RET){ - Subroutine s = subroutines.subroutineOf(getInstruction()); - if (s==null){ //return empty; // RET in dead code. "empty" would be the correct answer, but we know something about the surrounding project... - throw new AssertionViolatedException("Asking for successors of a RET in dead code?!"); - } -//TODO: remove -throw new AssertionViolatedException("DID YOU REALLY WANT TO ASK FOR RET'S SUCCS?"); -/* - InstructionHandle[] jsrs = s.getEnteringJsrInstructions(); - InstructionHandle[] ret = new InstructionHandle[jsrs.length]; - for (int i=0; i(NOT ORDERED!). - */ - public InstructionContext[] getInstructionContexts(){ - InstructionContext[] ret = new InstructionContext[instructionContexts.values().size()]; - return (InstructionContext[]) instructionContexts.values().toArray(ret); - } - - /** - * Returns true, if and only if the said instruction is not reachable; that means, - * if it not part of this ControlFlowGraph. - */ - public boolean isDead(InstructionHandle i){ - return instructionContexts.containsKey(i); - } -} +package org.aspectj.apache.bcel.verifier.structurals; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Hashtable; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.generic.Instruction; +import org.aspectj.apache.bcel.generic.InstructionBranch; +import org.aspectj.apache.bcel.generic.InstructionHandle; +import org.aspectj.apache.bcel.generic.InstructionSelect; +import org.aspectj.apache.bcel.generic.MethodGen; +import org.aspectj.apache.bcel.generic.RET; +import org.aspectj.apache.bcel.verifier.exc.AssertionViolatedException; +import org.aspectj.apache.bcel.verifier.exc.StructuralCodeConstraintException; + +/** + * This class represents a control flow graph of a method. + * + * @version $Id: ControlFlowGraph.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class ControlFlowGraph{ + + /** + * Objects of this class represent a node in a ControlFlowGraph. + * These nodes are instructions, not basic blocks. + */ + private class InstructionContextImpl implements InstructionContext{ + + /** + * The TAG field is here for external temporary flagging, such + * as graph colouring. + * + * @see #getTag() + * @see #setTag(int) + */ + private int TAG; + + /** + * The InstructionHandle this InstructionContext is wrapped around. + */ + private InstructionHandle instruction; + + /** + * The 'incoming' execution Frames. + */ + private HashMap inFrames; // key: the last-executed JSR + + /** + * The 'outgoing' execution Frames. + */ + private HashMap outFrames; // key: the last-executed JSR + + /** + * The 'execution predecessors' - a list of type InstructionContext + * of those instances that have been execute()d before in that order. + */ + private ArrayList executionPredecessors = null; // Type: InstructionContext + + /** + * Creates an InstructionHandleImpl object from an InstructionHandle. + * Creation of one per InstructionHandle suffices. Don't create more. + */ + public InstructionContextImpl(InstructionHandle inst){ + if (inst == null) throw new AssertionViolatedException("Cannot instantiate InstructionContextImpl from NULL."); + + instruction = inst; + inFrames = new java.util.HashMap(); + outFrames = new java.util.HashMap(); + } + + /* Satisfies InstructionContext.getTag(). */ + public int getTag(){ + return TAG; + } + + /* Satisfies InstructionContext.setTag(int). */ + public void setTag(int tag){ + TAG = tag; + } + + /** + * Returns the exception handlers of this instruction. + */ + public ExceptionHandler[] getExceptionHandlers(){ + return exceptionhandlers.getExceptionHandlers(getInstruction()); + } + + /** + * Returns a clone of the "outgoing" frame situation with respect to the given ExecutionChain. + */ + public Frame getOutFrame(ArrayList execChain){ + executionPredecessors = execChain; + + Frame org; + + InstructionContext jsr = lastExecutionJSR(); + + org = (Frame) outFrames.get(jsr); + + if (org == null){ + throw new AssertionViolatedException("outFrame not set! This:\n"+this+"\nExecutionChain: "+getExecutionChain()+"\nOutFrames: '"+outFrames+"'."); + } + return org.getClone(); + } + + /** + * "Merges in" (vmspec2, page 146) the "incoming" frame situation; + * executes the instructions symbolically + * and therefore calculates the "outgoing" frame situation. + * Returns: True iff the "incoming" frame situation changed after + * merging with "inFrame". + * The execPreds ArrayList must contain the InstructionContext + * objects executed so far in the correct order. This is just + * one execution path [out of many]. This is needed to correctly + * "merge" in the special case of a RET's successor. + * The InstConstraintVisitor and ExecutionVisitor instances + * must be set up correctly. + * @return true - if and only if the "outgoing" frame situation + * changed from the one before execute()ing. + */ + public boolean execute(Frame inFrame, ArrayList execPreds, InstConstraintVisitor icv, ExecutionVisitor ev){ + + executionPredecessors = (ArrayList) execPreds.clone(); + + //sanity check + if ( (lastExecutionJSR() == null) && (subroutines.subroutineOf(getInstruction()) != subroutines.getTopLevel() ) ){ + throw new AssertionViolatedException("Huh?! Am I '"+this+"' part of a subroutine or not?"); + } + if ( (lastExecutionJSR() != null) && (subroutines.subroutineOf(getInstruction()) == subroutines.getTopLevel() ) ){ + throw new AssertionViolatedException("Huh?! Am I '"+this+"' part of a subroutine or not?"); + } + + Frame inF = (Frame) inFrames.get(lastExecutionJSR()); + if (inF == null){// no incoming frame was set, so set it. + inFrames.put(lastExecutionJSR(), inFrame); + inF = inFrame; + } + else{// if there was an "old" inFrame + if (inF.equals(inFrame)){ //shortcut: no need to merge equal frames. + return false; + } + if (! mergeInFrames(inFrame)){ + return false; + } + } + + // Now we're sure the inFrame has changed! + + // new inFrame is already merged in, see above. + Frame workingFrame = inF.getClone(); + + try{ + // This verifies the InstructionConstraint for the current + // instruction, but does not modify the workingFrame object. +//InstConstraintVisitor icv = InstConstraintVisitor.getInstance(VerifierFactory.getVerifier(method_gen.getClassName())); + icv.setFrame(workingFrame); + getInstruction().accept(icv); + } + catch(StructuralCodeConstraintException ce){ + ce.extendMessage("","\nInstructionHandle: "+getInstruction()+"\n"); + ce.extendMessage("","\nExecution Frame:\n"+workingFrame); + extendMessageWithFlow(ce); + throw ce; + } + + // This executes the Instruction. + // Therefore the workingFrame object is modified. +//ExecutionVisitor ev = ExecutionVisitor.getInstance(VerifierFactory.getVerifier(method_gen.getClassName())); + ev.setFrame(workingFrame); + getInstruction().accept(ev); + //getInstruction().accept(ExecutionVisitor.withFrame(workingFrame)); + outFrames.put(lastExecutionJSR(), workingFrame); + + return true; // new inFrame was different from old inFrame so merging them + // yielded a different this.inFrame. + } + + /** + * Returns a simple String representation of this InstructionContext. + */ + public String toString(){ + //TODO: Put information in the brackets, e.g. + // Is this an ExceptionHandler? Is this a RET? Is this the start of + // a subroutine? + String ret = getInstruction().toString(false)+"\t[InstructionContext]"; + return ret; + } + + /** + * Does the actual merging (vmspec2, page 146). + * Returns true IFF this.inFrame was changed in course of merging with inFrame. + */ + private boolean mergeInFrames(Frame inFrame){ + // TODO: Can be performance-improved. + Frame inF = (Frame) inFrames.get(lastExecutionJSR()); + OperandStack oldstack = inF.getStack().getClone(); + LocalVariables oldlocals = inF.getLocals().getClone(); + try{ + inF.getStack().merge(inFrame.getStack()); + inF.getLocals().merge(inFrame.getLocals()); + } + catch (StructuralCodeConstraintException sce){ + extendMessageWithFlow(sce); + throw sce; + } + if ( oldstack.equals(inF.getStack()) && + oldlocals.equals(inF.getLocals()) ){ + return false; + } + else{ + return true; + } + } + + /** + * Returns the control flow execution chain. This is built + * while execute(Frame, ArrayList)-ing the code represented + * by the surrounding ControlFlowGraph. + */ + private String getExecutionChain(){ + String s = this.toString(); + for (int i=executionPredecessors.size()-1; i>=0; i--){ + s = executionPredecessors.get(i)+"\n" + s; + } + return s; + } + + + /** + * Extends the StructuralCodeConstraintException ("e") object with an at-the-end-extended message. + * This extended message will then reflect the execution flow needed to get to the constraint + * violation that triggered the throwing of the "e" object. + */ + private void extendMessageWithFlow(StructuralCodeConstraintException e){ + String s = "Execution flow:\n"; + e.extendMessage("", s+getExecutionChain()); + } + + /* + * Fulfils the contract of InstructionContext.getInstruction(). + */ + public InstructionHandle getInstruction(){ + return instruction; + } + + /** + * Returns the InstructionContextImpl with an JSR/JSR_W + * that was last in the ExecutionChain, without + * a corresponding RET, i.e. + * we were called by this one. + * Returns null if we were called from the top level. + */ + private InstructionContextImpl lastExecutionJSR(){ + + int size = executionPredecessors.size(); + int retcount = 0; + + for (int i=size-1; i>=0; i--){ + InstructionContextImpl current = (InstructionContextImpl) (executionPredecessors.get(i)); + Instruction currentlast = current.getInstruction().getInstruction(); + if (currentlast instanceof RET) retcount++; + if (currentlast.isJsrInstruction()){ + retcount--; + if (retcount == -1) return current; + } + } + return null; + } + + /* Satisfies InstructionContext.getSuccessors(). */ + public InstructionContext[] getSuccessors(){ + return contextsOf(_getSuccessors()); + } + + /** + * A utility method that calculates the successors of a given InstructionHandle + * That means, a RET does have successors as defined here. + * A JsrInstruction has its target as its successor + * (opposed to its physical successor) as defined here. + */ +// TODO: implement caching! + private InstructionHandle[] _getSuccessors(){ + final InstructionHandle[] empty = new InstructionHandle[0]; + final InstructionHandle[] single = new InstructionHandle[1]; + final InstructionHandle[] pair = new InstructionHandle[2]; + + Instruction inst = getInstruction().getInstruction(); + + if (inst instanceof RET){ + Subroutine s = subroutines.subroutineOf(getInstruction()); + if (s==null){ //return empty; // RET in dead code. "empty" would be the correct answer, but we know something about the surrounding project... + throw new AssertionViolatedException("Asking for successors of a RET in dead code?!"); + } +//TODO: remove +throw new AssertionViolatedException("DID YOU REALLY WANT TO ASK FOR RET'S SUCCS?"); +/* + InstructionHandle[] jsrs = s.getEnteringJsrInstructions(); + InstructionHandle[] ret = new InstructionHandle[jsrs.length]; + for (int i=0; i(NOT ORDERED!). + */ + public InstructionContext[] getInstructionContexts(){ + InstructionContext[] ret = new InstructionContext[instructionContexts.values().size()]; + return (InstructionContext[]) instructionContexts.values().toArray(ret); + } + + /** + * Returns true, if and only if the said instruction is not reachable; that means, + * if it not part of this ControlFlowGraph. + */ + public boolean isDead(InstructionHandle i){ + return instructionContexts.containsKey(i); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandler.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandler.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandler.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandler.java index b215f89ce..cccd54577 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandler.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandler.java @@ -1,93 +1,93 @@ -package org.aspectj.apache.bcel.verifier.structurals; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.generic.*; - -/** - * This class represents an exception handler; that is, an ObjectType - * representing a subclass of java.lang.Throwable and the instruction - * the handler starts off (represented by an InstructionContext). - * - * @version $Id: ExceptionHandler.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public class ExceptionHandler{ - /** The type of the exception to catch. NULL means ANY. */ - private ObjectType catchtype; - - /** The InstructionHandle where the handling begins. */ - private InstructionHandle handlerpc; - - /** Leave instance creation to JustIce. */ - ExceptionHandler(ObjectType catch_type, InstructionHandle handler_pc){ - catchtype = catch_type; - handlerpc = handler_pc; - } - - /** - * Returns the type of the exception that's handled. 'null' means 'ANY'. - */ - public ObjectType getExceptionType(){ - return catchtype; - } - - /** - * Returns the InstructionHandle where the handler starts off. - */ - public InstructionHandle getHandlerStart(){ - return handlerpc; - } -} +package org.aspectj.apache.bcel.verifier.structurals; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.generic.*; + +/** + * This class represents an exception handler; that is, an ObjectType + * representing a subclass of java.lang.Throwable and the instruction + * the handler starts off (represented by an InstructionContext). + * + * @version $Id: ExceptionHandler.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class ExceptionHandler{ + /** The type of the exception to catch. NULL means ANY. */ + private ObjectType catchtype; + + /** The InstructionHandle where the handling begins. */ + private InstructionHandle handlerpc; + + /** Leave instance creation to JustIce. */ + ExceptionHandler(ObjectType catch_type, InstructionHandle handler_pc){ + catchtype = catch_type; + handlerpc = handler_pc; + } + + /** + * Returns the type of the exception that's handled. 'null' means 'ANY'. + */ + public ObjectType getExceptionType(){ + return catchtype; + } + + /** + * Returns the InstructionHandle where the handler starts off. + */ + public InstructionHandle getHandlerStart(){ + return handlerpc; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandlers.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandlers.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandlers.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandlers.java index 273547775..2d6a821fb 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandlers.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/ExceptionHandlers.java @@ -1,107 +1,107 @@ -package org.aspectj.apache.bcel.verifier.structurals; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.generic.*; -import java.util.HashSet; -import java.util.Hashtable; - -/** - * This class allows easy access to ExceptionHandler objects. - * - * @version $Id: ExceptionHandlers.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public class ExceptionHandlers{ - /** - * The ExceptionHandler instances. - * Key: InstructionHandle objects, Values: HashSet instances. - */ - private Hashtable exceptionhandlers; - - /** - * Constructor. Creates a new ExceptionHandlers instance. - */ - public ExceptionHandlers(MethodGen mg){ - exceptionhandlers = new Hashtable(); - CodeExceptionGen[] cegs = mg.getExceptionHandlers(); - for (int i=0; i. + */ + +import org.aspectj.apache.bcel.generic.*; +import java.util.HashSet; +import java.util.Hashtable; + +/** + * This class allows easy access to ExceptionHandler objects. + * + * @version $Id: ExceptionHandlers.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class ExceptionHandlers{ + /** + * The ExceptionHandler instances. + * Key: InstructionHandle objects, Values: HashSet instances. + */ + private Hashtable exceptionhandlers; + + /** + * Constructor. Creates a new ExceptionHandlers instance. + */ + public ExceptionHandlers(MethodGen mg){ + exceptionhandlers = new Hashtable(); + CodeExceptionGen[] cegs = mg.getExceptionHandlers(); + for (int i=0; i. - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.Constant; -import org.aspectj.apache.bcel.classfile.ConstantDouble; -import org.aspectj.apache.bcel.classfile.ConstantFloat; -import org.aspectj.apache.bcel.classfile.ConstantInteger; -import org.aspectj.apache.bcel.classfile.ConstantLong; -import org.aspectj.apache.bcel.classfile.ConstantString; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.generic.*; - -/** - * This Visitor class may be used for a type-based Java Virtual Machine - * simulation. - * It does not check for correct types on the OperandStack or in the - * LocalVariables; nor does it check their sizes are sufficiently big. - * Thus, to use this Visitor for bytecode verifying, you have to make sure - * externally that the type constraints of the Java Virtual Machine instructions - * are satisfied. An InstConstraintVisitor may be used for this. - * Anyway, this Visitor does not mandate it. For example, when you - * visitIADD(IADD o), then there are two stack slots popped and one - * stack slot containing a Type.INT is pushed (where you could also - * pop only one slot if you know there are two Type.INT on top of the - * stack). Monitor-specific behaviour is not simulated. - * - *

          Conventions: - * - * Type.VOID will never be pushed onto the stack. Type.DOUBLE and Type.LONG - * that would normally take up two stack slots (like Double_HIGH and - * Double_LOW) are represented by a simple single Type.DOUBLE or Type.LONG - * object on the stack here. - * If a two-slot type is stored into a local variable, the next variable - * is given the type Type.UNKNOWN. - * - * @version $Id: ExecutionVisitor.java,v 1.5.8.2 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - * @see #visitDSTORE(DSTORE o) - * @see InstConstraintVisitor - */ -public class ExecutionVisitor extends EmptyVisitor implements Visitor{ - - /** - * The executionframe we're operating on. - */ - private Frame frame = null; - - /** - * The ConstantPoolGen we're working with. - * @see #setConstantPoolGen(ConstantPoolGen) - */ - private ConstantPool cpg = null; - - /** - * Constructor. Constructs a new instance of this class. - */ - public ExecutionVisitor(){} - - /** - * The OperandStack from the current Frame we're operating on. - * @see #setFrame(Frame) - */ - private OperandStack stack(){ - return frame.getStack(); - } - - /** - * The LocalVariables from the current Frame we're operating on. - * @see #setFrame(Frame) - */ - private LocalVariables locals(){ - return frame.getLocals(); - } - - /** - * Sets the ConstantPoolGen needed for symbolic execution. - */ - public void setConstantPoolGen(ConstantPool cpg){ - this.cpg = cpg; - } - - /** - * The only method granting access to the single instance of - * the ExecutionVisitor class. Before actively using this - * instance, SET THE ConstantPoolGen FIRST. - * @see #setConstantPoolGen(ConstantPoolGen) - */ - public void setFrame(Frame f){ - this.frame = f; - } - - ///** Symbolically executes the corresponding Java Virtual Machine instruction. */ - //public void visitWIDE(WIDE o){ - // The WIDE instruction is modelled as a flag - // of the embedded instructions in BCEL. - // Therefore BCEL checks for possible errors - // when parsing in the .class file: We don't - // have even the possibilty to care for WIDE - // here. - //} - - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitAALOAD(Instruction o){ - stack().pop(); // pop the index int -//System.out.print(stack().peek()); - Type t = stack().pop(); // Pop Array type - if (t == Type.NULL){ - stack().push(Type.NULL); - } // Do nothing stackwise --- a NullPointerException is thrown at Run-Time - else{ - ArrayType at = (ArrayType) t; - stack().push(at.getElementType()); - } - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitAASTORE(Instruction o){ - stack().pop(); - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitACONST_NULL(Instruction o){ - stack().push(Type.NULL); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitALOAD(Instruction o){ - stack().push(locals().get(o.getIndex())); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitANEWARRAY(Instruction o){ - stack().pop(); //count - stack().push( new ArrayType(o.getType(cpg), 1) ); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitARETURN(Instruction o){ - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitARRAYLENGTH(Instruction o){ - stack().pop(); - stack().push(Type.INT); - } - - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitASTORE(Instruction o){ - locals().set(o.getIndex(), stack().pop()); - //System.err.println("TODO-DEBUG: set LV '"+o.getIndex()+"' to '"+locals().get(o.getIndex())+"'."); - } - - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitATHROW(Instruction o){ - Type t = stack().pop(); - stack().clear(); - if (t.equals(Type.NULL)) - stack().push(Type.getType("Ljava/lang/NullPointerException;")); - else - stack().push(t); - } - - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitBALOAD(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.INT); - } - - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitBASTORE(Instruction o){ - stack().pop(); - stack().pop(); - stack().pop(); - } - - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitBIPUSH(Instruction o){ - stack().push(Type.INT); - } - - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitCALOAD(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitCASTORE(Instruction o){ - stack().pop(); - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitCHECKCAST(Instruction o){ - // It's possibly wrong to do so, but SUN's - // ByteCode verifier seems to do (only) this, too. - // TODO: One could use a sophisticated analysis here to check - // if a type cannot possibly be cated to another and by - // so doing predict the ClassCastException at run-time. - stack().pop(); - stack().push(o.getType(cpg)); - } - - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitD2F(Instruction o){ - stack().pop(); - stack().push(Type.FLOAT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitD2I(Instruction o){ - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitD2L(Instruction o){ - stack().pop(); - stack().push(Type.LONG); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDADD(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.DOUBLE); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDALOAD(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.DOUBLE); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDASTORE(Instruction o){ - stack().pop(); - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDCMPG(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDCMPL(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDCONST(Instruction o){ - stack().push(Type.DOUBLE); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDDIV(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.DOUBLE); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDLOAD(Instruction o){ - stack().push(Type.DOUBLE); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDMUL(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.DOUBLE); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDNEG(Instruction o){ - stack().pop(); - stack().push(Type.DOUBLE); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDREM(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.DOUBLE); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDRETURN(Instruction o){ - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDSTORE(Instruction o){ - locals().set(o.getIndex(), stack().pop()); - locals().set(o.getIndex()+1, Type.UNKNOWN); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDSUB(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.DOUBLE); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDUP(Instruction o){ - Type t = stack().pop(); - stack().push(t); - stack().push(t); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDUP_X1(Instruction o){ - Type w1 = stack().pop(); - Type w2 = stack().pop(); - stack().push(w1); - stack().push(w2); - stack().push(w1); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDUP_X2(Instruction o){ - Type w1 = stack().pop(); - Type w2 = stack().pop(); - if (w2.getSize() == 2){ - stack().push(w1); - stack().push(w2); - stack().push(w1); - } - else{ - Type w3 = stack().pop(); - stack().push(w1); - stack().push(w3); - stack().push(w2); - stack().push(w1); - } - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDUP2(Instruction o){ - Type t = stack().pop(); - if (t.getSize() == 2){ - stack().push(t); - stack().push(t); - } - else{ // t.getSize() is 1 - Type u = stack().pop(); - stack().push(u); - stack().push(t); - stack().push(u); - stack().push(t); - } - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDUP2_X1(Instruction o){ - Type t = stack().pop(); - if (t.getSize() == 2){ - Type u = stack().pop(); - stack().push(t); - stack().push(u); - stack().push(t); - } - else{ //t.getSize() is1 - Type u = stack().pop(); - Type v = stack().pop(); - stack().push(u); - stack().push(t); - stack().push(v); - stack().push(u); - stack().push(t); - } - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitDUP2_X2(Instruction o){ - Type t = stack().pop(); - if (t.getSize() == 2){ - Type u = stack().pop(); - if (u.getSize() == 2){ - stack().push(t); - stack().push(u); - stack().push(t); - }else{ - Type v = stack().pop(); - stack().push(t); - stack().push(v); - stack().push(u); - stack().push(t); - } - } - else{ //t.getSize() is 1 - Type u = stack().pop(); - Type v = stack().pop(); - if (v.getSize() == 2){ - stack().push(u); - stack().push(t); - stack().push(v); - stack().push(u); - stack().push(t); - }else{ - Type w = stack().pop(); - stack().push(u); - stack().push(t); - stack().push(w); - stack().push(v); - stack().push(u); - stack().push(t); - } - } - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitF2D(Instruction o){ - stack().pop(); - stack().push(Type.DOUBLE); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitF2I(Instruction o){ - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitF2L(Instruction o){ - stack().pop(); - stack().push(Type.LONG); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFADD(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.FLOAT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFALOAD(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.FLOAT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFASTORE(Instruction o){ - stack().pop(); - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFCMPG(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFCMPL(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFCONST(Instruction o){ - stack().push(Type.FLOAT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFDIV(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.FLOAT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFLOAD(Instruction o){ - stack().push(Type.FLOAT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFMUL(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.FLOAT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFNEG(Instruction o){ - stack().pop(); - stack().push(Type.FLOAT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFREM(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.FLOAT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFRETURN(Instruction o){ - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFSTORE(Instruction o){ - locals().set(o.getIndex(), stack().pop()); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitFSUB(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.FLOAT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitGETFIELD(FieldInstruction o){ - stack().pop(); - Type t = o.getFieldType(cpg); - if ( t.equals(Type.BOOLEAN) || - t.equals(Type.CHAR) || - t.equals(Type.BYTE) || - t.equals(Type.SHORT) ) - t = Type.INT; - stack().push(t); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitGETSTATIC(FieldInstruction o){ - Type t = o.getFieldType(cpg); - if ( t.equals(Type.BOOLEAN) || - t.equals(Type.CHAR) || - t.equals(Type.BYTE) || - t.equals(Type.SHORT) ) - t = Type.INT; - stack().push(t); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitGOTO(Instruction o){ - // no stack changes. - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitGOTO_W(Instruction o){ - // no stack changes. - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitI2B(Instruction o){ - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitI2C(Instruction o){ - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitI2D(Instruction o){ - stack().pop(); - stack().push(Type.DOUBLE); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitI2F(Instruction o){ - stack().pop(); - stack().push(Type.FLOAT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitI2L(Instruction o){ - stack().pop(); - stack().push(Type.LONG); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitI2S(Instruction o){ - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIADD(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIALOAD(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIAND(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIASTORE(Instruction o){ - stack().pop(); - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitICONST(Instruction o){ - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIDIV(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIF_ACMPEQ(Instruction o){ - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIF_ACMPNE(Instruction o){ - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIF_ICMPEQ(Instruction o){ - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIF_ICMPGE(Instruction o){ - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIF_ICMPGT(Instruction o){ - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIF_ICMPLE(Instruction o){ - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIF_ICMPLT(Instruction o){ - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIF_ICMPNE(Instruction o){ - stack().pop(); - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIFEQ(Instruction o){ - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIFGE(Instruction o){ - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIFGT(Instruction o){ - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIFLE(Instruction o){ - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIFLT(Instruction o){ - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIFNE(Instruction o){ - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIFNONNULL(Instruction o){ - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIFNULL(Instruction o){ - stack().pop(); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIINC(IINC o){ - // stack is not changed. - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitILOAD(Instruction o){ - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitIMUL(Instruction o){ - stack().pop(); - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitINEG(Instruction o){ - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitINSTANCEOF(Instruction o){ - stack().pop(); - stack().push(Type.INT); - } - /** Symbolically executes the corresponding Java Virtual Machine instruction. */ - public void visitINVOKEINTERFACE(INVOKEINTERFACE o){ - stack().pop(); //objectref - for (int i=0; i. + */ + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.Constant; +import org.aspectj.apache.bcel.classfile.ConstantDouble; +import org.aspectj.apache.bcel.classfile.ConstantFloat; +import org.aspectj.apache.bcel.classfile.ConstantInteger; +import org.aspectj.apache.bcel.classfile.ConstantLong; +import org.aspectj.apache.bcel.classfile.ConstantString; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.generic.ArrayType; +import org.aspectj.apache.bcel.generic.FieldInstruction; +import org.aspectj.apache.bcel.generic.IINC; +import org.aspectj.apache.bcel.generic.INVOKEINTERFACE; +import org.aspectj.apache.bcel.generic.Instruction; +import org.aspectj.apache.bcel.generic.InstructionBranch; +import org.aspectj.apache.bcel.generic.InstructionByte; +import org.aspectj.apache.bcel.generic.InvokeInstruction; +import org.aspectj.apache.bcel.generic.LOOKUPSWITCH; +import org.aspectj.apache.bcel.generic.MULTIANEWARRAY; +import org.aspectj.apache.bcel.generic.ObjectType; +import org.aspectj.apache.bcel.generic.RET; +import org.aspectj.apache.bcel.generic.ReturnaddressType; +import org.aspectj.apache.bcel.generic.TABLESWITCH; +import org.aspectj.apache.bcel.generic.Type; +import org.aspectj.apache.bcel.generic.InstVisitor; +import org.aspectj.apache.bcel.verifier.EmptyInstVisitor; + +/** + * This Visitor class may be used for a type-based Java Virtual Machine + * simulation. + * It does not check for correct types on the OperandStack or in the + * LocalVariables; nor does it check their sizes are sufficiently big. + * Thus, to use this Visitor for bytecode verifying, you have to make sure + * externally that the type constraints of the Java Virtual Machine instructions + * are satisfied. An InstConstraintVisitor may be used for this. + * Anyway, this Visitor does not mandate it. For example, when you + * visitIADD(IADD o), then there are two stack slots popped and one + * stack slot containing a Type.INT is pushed (where you could also + * pop only one slot if you know there are two Type.INT on top of the + * stack). Monitor-specific behaviour is not simulated. + * + *

          Conventions: + * + * Type.VOID will never be pushed onto the stack. Type.DOUBLE and Type.LONG + * that would normally take up two stack slots (like Double_HIGH and + * Double_LOW) are represented by a simple single Type.DOUBLE or Type.LONG + * object on the stack here. + * If a two-slot type is stored into a local variable, the next variable + * is given the type Type.UNKNOWN. + * + * @version $Id: ExecutionVisitor.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + * @see #visitDSTORE(DSTORE o) + * @see InstConstraintVisitor + */ +public class ExecutionVisitor extends EmptyInstVisitor implements InstVisitor { + + /** + * The executionframe we're operating on. + */ + private Frame frame = null; + + /** + * The ConstantPoolGen we're working with. + * @see #setConstantPoolGen(ConstantPoolGen) + */ + private ConstantPool cpg = null; + + /** + * Constructor. Constructs a new instance of this class. + */ + public ExecutionVisitor(){} + + /** + * The OperandStack from the current Frame we're operating on. + * @see #setFrame(Frame) + */ + private OperandStack stack(){ + return frame.getStack(); + } + + /** + * The LocalVariables from the current Frame we're operating on. + * @see #setFrame(Frame) + */ + private LocalVariables locals(){ + return frame.getLocals(); + } + + /** + * Sets the ConstantPoolGen needed for symbolic execution. + */ + public void setConstantPoolGen(ConstantPool cpg){ + this.cpg = cpg; + } + + /** + * The only method granting access to the single instance of + * the ExecutionVisitor class. Before actively using this + * instance, SET THE ConstantPoolGen FIRST. + * @see #setConstantPoolGen(ConstantPoolGen) + */ + public void setFrame(Frame f){ + this.frame = f; + } + + ///** Symbolically executes the corresponding Java Virtual Machine instruction. */ + //public void visitWIDE(WIDE o){ + // The WIDE instruction is modelled as a flag + // of the embedded instructions in BCEL. + // Therefore BCEL checks for possible errors + // when parsing in the .class file: We don't + // have even the possibilty to care for WIDE + // here. + //} + + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitAALOAD(Instruction o){ + stack().pop(); // pop the index int +//System.out.print(stack().peek()); + Type t = stack().pop(); // Pop Array type + if (t == Type.NULL){ + stack().push(Type.NULL); + } // Do nothing stackwise --- a NullPointerException is thrown at Run-Time + else{ + ArrayType at = (ArrayType) t; + stack().push(at.getElementType()); + } + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitAASTORE(Instruction o){ + stack().pop(); + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitACONST_NULL(Instruction o){ + stack().push(Type.NULL); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitALOAD(Instruction o){ + stack().push(locals().get(o.getIndex())); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitANEWARRAY(Instruction o){ + stack().pop(); //count + stack().push( new ArrayType(o.getType(cpg), 1) ); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitARETURN(Instruction o){ + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitARRAYLENGTH(Instruction o){ + stack().pop(); + stack().push(Type.INT); + } + + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitASTORE(Instruction o){ + locals().set(o.getIndex(), stack().pop()); + //System.err.println("TODO-DEBUG: set LV '"+o.getIndex()+"' to '"+locals().get(o.getIndex())+"'."); + } + + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitATHROW(Instruction o){ + Type t = stack().pop(); + stack().clear(); + if (t.equals(Type.NULL)) + stack().push(Type.getType("Ljava/lang/NullPointerException;")); + else + stack().push(t); + } + + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitBALOAD(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.INT); + } + + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitBASTORE(Instruction o){ + stack().pop(); + stack().pop(); + stack().pop(); + } + + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitBIPUSH(Instruction o){ + stack().push(Type.INT); + } + + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitCALOAD(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitCASTORE(Instruction o){ + stack().pop(); + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitCHECKCAST(Instruction o){ + // It's possibly wrong to do so, but SUN's + // ByteCode verifier seems to do (only) this, too. + // TODO: One could use a sophisticated analysis here to check + // if a type cannot possibly be cated to another and by + // so doing predict the ClassCastException at run-time. + stack().pop(); + stack().push(o.getType(cpg)); + } + + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitD2F(Instruction o){ + stack().pop(); + stack().push(Type.FLOAT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitD2I(Instruction o){ + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitD2L(Instruction o){ + stack().pop(); + stack().push(Type.LONG); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDADD(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.DOUBLE); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDALOAD(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.DOUBLE); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDASTORE(Instruction o){ + stack().pop(); + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDCMPG(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDCMPL(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDCONST(Instruction o){ + stack().push(Type.DOUBLE); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDDIV(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.DOUBLE); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDLOAD(Instruction o){ + stack().push(Type.DOUBLE); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDMUL(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.DOUBLE); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDNEG(Instruction o){ + stack().pop(); + stack().push(Type.DOUBLE); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDREM(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.DOUBLE); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDRETURN(Instruction o){ + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDSTORE(Instruction o){ + locals().set(o.getIndex(), stack().pop()); + locals().set(o.getIndex()+1, Type.UNKNOWN); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDSUB(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.DOUBLE); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDUP(Instruction o){ + Type t = stack().pop(); + stack().push(t); + stack().push(t); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDUP_X1(Instruction o){ + Type w1 = stack().pop(); + Type w2 = stack().pop(); + stack().push(w1); + stack().push(w2); + stack().push(w1); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDUP_X2(Instruction o){ + Type w1 = stack().pop(); + Type w2 = stack().pop(); + if (w2.getSize() == 2){ + stack().push(w1); + stack().push(w2); + stack().push(w1); + } + else{ + Type w3 = stack().pop(); + stack().push(w1); + stack().push(w3); + stack().push(w2); + stack().push(w1); + } + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDUP2(Instruction o){ + Type t = stack().pop(); + if (t.getSize() == 2){ + stack().push(t); + stack().push(t); + } + else{ // t.getSize() is 1 + Type u = stack().pop(); + stack().push(u); + stack().push(t); + stack().push(u); + stack().push(t); + } + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDUP2_X1(Instruction o){ + Type t = stack().pop(); + if (t.getSize() == 2){ + Type u = stack().pop(); + stack().push(t); + stack().push(u); + stack().push(t); + } + else{ //t.getSize() is1 + Type u = stack().pop(); + Type v = stack().pop(); + stack().push(u); + stack().push(t); + stack().push(v); + stack().push(u); + stack().push(t); + } + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitDUP2_X2(Instruction o){ + Type t = stack().pop(); + if (t.getSize() == 2){ + Type u = stack().pop(); + if (u.getSize() == 2){ + stack().push(t); + stack().push(u); + stack().push(t); + }else{ + Type v = stack().pop(); + stack().push(t); + stack().push(v); + stack().push(u); + stack().push(t); + } + } + else{ //t.getSize() is 1 + Type u = stack().pop(); + Type v = stack().pop(); + if (v.getSize() == 2){ + stack().push(u); + stack().push(t); + stack().push(v); + stack().push(u); + stack().push(t); + }else{ + Type w = stack().pop(); + stack().push(u); + stack().push(t); + stack().push(w); + stack().push(v); + stack().push(u); + stack().push(t); + } + } + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitF2D(Instruction o){ + stack().pop(); + stack().push(Type.DOUBLE); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitF2I(Instruction o){ + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitF2L(Instruction o){ + stack().pop(); + stack().push(Type.LONG); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFADD(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.FLOAT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFALOAD(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.FLOAT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFASTORE(Instruction o){ + stack().pop(); + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFCMPG(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFCMPL(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFCONST(Instruction o){ + stack().push(Type.FLOAT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFDIV(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.FLOAT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFLOAD(Instruction o){ + stack().push(Type.FLOAT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFMUL(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.FLOAT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFNEG(Instruction o){ + stack().pop(); + stack().push(Type.FLOAT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFREM(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.FLOAT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFRETURN(Instruction o){ + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFSTORE(Instruction o){ + locals().set(o.getIndex(), stack().pop()); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitFSUB(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.FLOAT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitGETFIELD(FieldInstruction o){ + stack().pop(); + Type t = o.getFieldType(cpg); + if ( t.equals(Type.BOOLEAN) || + t.equals(Type.CHAR) || + t.equals(Type.BYTE) || + t.equals(Type.SHORT) ) + t = Type.INT; + stack().push(t); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitGETSTATIC(FieldInstruction o){ + Type t = o.getFieldType(cpg); + if ( t.equals(Type.BOOLEAN) || + t.equals(Type.CHAR) || + t.equals(Type.BYTE) || + t.equals(Type.SHORT) ) + t = Type.INT; + stack().push(t); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitGOTO(Instruction o){ + // no stack changes. + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitGOTO_W(Instruction o){ + // no stack changes. + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitI2B(Instruction o){ + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitI2C(Instruction o){ + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitI2D(Instruction o){ + stack().pop(); + stack().push(Type.DOUBLE); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitI2F(Instruction o){ + stack().pop(); + stack().push(Type.FLOAT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitI2L(Instruction o){ + stack().pop(); + stack().push(Type.LONG); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitI2S(Instruction o){ + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIADD(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIALOAD(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIAND(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIASTORE(Instruction o){ + stack().pop(); + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitICONST(Instruction o){ + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIDIV(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIF_ACMPEQ(Instruction o){ + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIF_ACMPNE(Instruction o){ + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIF_ICMPEQ(Instruction o){ + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIF_ICMPGE(Instruction o){ + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIF_ICMPGT(Instruction o){ + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIF_ICMPLE(Instruction o){ + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIF_ICMPLT(Instruction o){ + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIF_ICMPNE(Instruction o){ + stack().pop(); + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIFEQ(Instruction o){ + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIFGE(Instruction o){ + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIFGT(Instruction o){ + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIFLE(Instruction o){ + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIFLT(Instruction o){ + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIFNE(Instruction o){ + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIFNONNULL(Instruction o){ + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIFNULL(Instruction o){ + stack().pop(); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIINC(IINC o){ + // stack is not changed. + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitILOAD(Instruction o){ + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitIMUL(Instruction o){ + stack().pop(); + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitINEG(Instruction o){ + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitINSTANCEOF(Instruction o){ + stack().pop(); + stack().push(Type.INT); + } + /** Symbolically executes the corresponding Java Virtual Machine instruction. */ + public void visitINVOKEINTERFACE(INVOKEINTERFACE o){ + stack().pop(); //objectref + for (int i=0; i. - */ - - -/** - * This class represents a JVM execution frame; that means, - * a local variable array and an operand stack. - * - * @version $Id: Frame.java,v 1.4.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ - -public class Frame{ - - /** - * For instance initialization methods, it is important to remember - * which instance it is that is not initialized yet. It will be - * initialized invoking another constructor later. - * NULL means the instance already *is* initialized. - */ - protected static UninitializedObjectType _this; - - /** - * - */ - private LocalVariables locals; - - /** - * - */ - private OperandStack stack; - - /** - * - */ - public Frame(int maxLocals, int maxStack){ - locals = new LocalVariables(maxLocals); - stack = new OperandStack(maxStack); - } - - /** - * - */ - public Frame(LocalVariables locals, OperandStack stack){ - this.locals = locals; - this.stack = stack; - } - - /** - * - */ - protected Object clone(){ - Frame f = new Frame(locals.getClone(), stack.getClone()); - return f; - } - - /** - * - */ - public Frame getClone(){ - return (Frame) clone(); - } - - /** - * - */ - public LocalVariables getLocals(){ - return locals; - } - - /** - * - */ - public OperandStack getStack(){ - return stack; - } - - /** - * - */ - public boolean equals(Object o){ - if (!(o instanceof Frame)) return false; // implies "null" is non-equal. - Frame f = (Frame) o; - return this.stack.equals(f.stack) && this.locals.equals(f.locals); - } - - /** - * Returns a String representation of the Frame instance. - */ - public String toString(){ - String s="Local Variables:\n"; - s += locals; - s += "OperandStack:\n"; - s += stack; - return s; - } -} +package org.aspectj.apache.bcel.verifier.structurals; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +/** + * This class represents a JVM execution frame; that means, + * a local variable array and an operand stack. + * + * @version $Id: Frame.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ + +public class Frame{ + + /** + * For instance initialization methods, it is important to remember + * which instance it is that is not initialized yet. It will be + * initialized invoking another constructor later. + * NULL means the instance already *is* initialized. + */ + protected static UninitializedObjectType _this; + + /** + * + */ + private LocalVariables locals; + + /** + * + */ + private OperandStack stack; + + /** + * + */ + public Frame(int maxLocals, int maxStack){ + locals = new LocalVariables(maxLocals); + stack = new OperandStack(maxStack); + } + + /** + * + */ + public Frame(LocalVariables locals, OperandStack stack){ + this.locals = locals; + this.stack = stack; + } + + /** + * + */ + protected Object clone(){ + Frame f = new Frame(locals.getClone(), stack.getClone()); + return f; + } + + /** + * + */ + public Frame getClone(){ + return (Frame) clone(); + } + + /** + * + */ + public LocalVariables getLocals(){ + return locals; + } + + /** + * + */ + public OperandStack getStack(){ + return stack; + } + + /** + * + */ + public boolean equals(Object o){ + if (!(o instanceof Frame)) return false; // implies "null" is non-equal. + Frame f = (Frame) o; + return this.stack.equals(f.stack) && this.locals.equals(f.locals); + } + + /** + * Returns a String representation of the Frame instance. + */ + public String toString(){ + String s="Local Variables:\n"; + s += locals; + s += "OperandStack:\n"; + s += stack; + return s; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/GenericArray.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/GenericArray.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/GenericArray.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/GenericArray.java index 04bab593a..fe5c13454 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/GenericArray.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/GenericArray.java @@ -1,66 +1,66 @@ -package org.aspectj.apache.bcel.verifier.structurals; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * A placeholder class that can be used to create an ObjectType of which - * has some of the properties arrays have. They implement java.lang.Cloneable - * and java.io.Serializable and they extend java.lang.Object. - * - * @version $Id: GenericArray.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public class GenericArray extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable{ -} +package org.aspectj.apache.bcel.verifier.structurals; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * A placeholder class that can be used to create an ObjectType of which + * has some of the properties arrays have. They implement java.lang.Cloneable + * and java.io.Serializable and they extend java.lang.Object. + * + * @version $Id: GenericArray.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class GenericArray extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable{ +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/InstConstraintVisitor.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/InstConstraintVisitor.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/InstConstraintVisitor.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/InstConstraintVisitor.java index 20473d34f..4965bf83c 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/InstConstraintVisitor.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/InstConstraintVisitor.java @@ -1,2426 +1,2446 @@ -package org.aspectj.apache.bcel.verifier.structurals; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.Constant; -import org.aspectj.apache.bcel.classfile.ConstantClass; -import org.aspectj.apache.bcel.classfile.ConstantDouble; -import org.aspectj.apache.bcel.classfile.ConstantInteger; -import org.aspectj.apache.bcel.classfile.ConstantFieldref; -import org.aspectj.apache.bcel.classfile.ConstantFloat; -import org.aspectj.apache.bcel.classfile.ConstantLong; -import org.aspectj.apache.bcel.classfile.ConstantString; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.classfile.Field; -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.generic.*; -import org.aspectj.apache.bcel.verifier.*; -import org.aspectj.apache.bcel.verifier.exc.*; - - -/** - * A Visitor class testing for valid preconditions of JVM instructions. - * The instance of this class will throw a StructuralCodeConstraintException - * instance if an instruction is visitXXX()ed which has preconditions that are - * not satisfied. - * TODO: Currently, the JVM's behaviour concerning monitors (MONITORENTER, - * MONITOREXIT) is not modeled in JustIce. - * - * @version $Id: InstConstraintVisitor.java,v 1.4.8.2 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - * @see org.aspectj.apache.bcel.verifier.exc.StructuralCodeConstraintException - * @see org.aspectj.apache.bcel.verifier.exc.LinkingConstraintException - */ -public class InstConstraintVisitor extends EmptyVisitor implements org.aspectj.apache.bcel.generic.Visitor{ - - private static ObjectType GENERIC_ARRAY = new ObjectType("org.aspectj.apache.bcel.verifier.structurals.GenericArray"); - - /** - * The constructor. Constructs a new instance of this class. - */ - public InstConstraintVisitor(){} - - /** - * The Execution Frame we're working on. - * - * @see #setFrame(Frame f) - * @see #locals() - * @see #stack() - */ - private Frame frame = null; - - private ConstantPool cpg = null; - - /** - * The MethodGen we're working on. - * - * @see #setMethodGen(MethodGen mg) - */ - private MethodGen mg = null; - - /** - * The OperandStack we're working on. - * - * @see #setFrame(Frame f) - */ - private OperandStack stack(){ - return frame.getStack(); - } - - /** - * The LocalVariables we're working on. - * - * @see #setFrame(Frame f) - */ - private LocalVariables locals(){ - return frame.getLocals(); - } - - /** - * This method is called by the visitXXX() to notify the acceptor of this InstConstraintVisitor - * that a constraint violation has occured. This is done by throwing an instance of a - * StructuralCodeConstraintException. - * @throws org.aspectj.apache.bcel.verifier.exc.StructuralCodeConstraintException always. - */ - private void constraintViolated(Instruction violator, String description){ - String fq_classname = violator.getClass().getName(); - throw new StructuralCodeConstraintException("Instruction "+ fq_classname.substring(fq_classname.lastIndexOf('.')+1) +" constraint violated: " + description); - } - - /** - * This returns the single instance of the InstConstraintVisitor class. - * To operate correctly, other values must have been set before actually - * using the instance. - * Use this method for performance reasons. - * - * @see #setConstantPoolGen(ConstantPoolGen cpg) - * @see #setMethodGen(MethodGen mg) - */ - public void setFrame(Frame f){ - this.frame = f; - //if (singleInstance.mg == null || singleInstance.cpg == null) throw new AssertionViolatedException("Forgot to set important values first."); - } - - /** - * Sets the ConstantPoolGen instance needed for constraint - * checking prior to execution. - */ - public void setConstantPoolGen(ConstantPool cpg){ - this.cpg = cpg; - } - - /** - * Sets the MethodGen instance needed for constraint - * checking prior to execution. - */ - public void setMethodGen(MethodGen mg){ - this.mg = mg; - } - - /** - * Assures index is of type INT. - * @throws org.aspectj.apache.bcel.verifier.exc.StructuralCodeConstraintException if the above constraint is not satisfied. - */ - private void indexOfInt(Instruction o, Type index){ - if (! index.equals(Type.INT)) - constraintViolated(o, "The 'index' is not of type int but of type "+index+"."); - } - - /** - * Assures the ReferenceType r is initialized (or Type.NULL). - * Formally, this means (!(r instanceof UninitializedObjectType)), because - * there are no uninitialized array types. - * @throws org.aspectj.apache.bcel.verifier.exc.StructuralCodeConstraintException if the above constraint is not satisfied. - */ - private void referenceTypeIsInitialized(Instruction o, ReferenceType r){ - if (r instanceof UninitializedObjectType){ - constraintViolated(o, "Working on an uninitialized object '"+r+"'."); - } - } - - /** Assures value is of type INT. */ - private void valueOfInt(Instruction o, Type value){ - if (! value.equals(Type.INT)) - constraintViolated(o, "The 'value' is not of type int but of type "+value+"."); - } - - /** - * Assures arrayref is of ArrayType or NULL; - * returns true if and only if arrayref is non-NULL. - * @throws org.aspectj.apache.bcel.verifier.exc.StructuralCodeConstraintException if the above constraint is violated. - */ - private boolean arrayrefOfArrayType(Instruction o, Type arrayref){ - if (! ((arrayref instanceof ArrayType) || arrayref.equals(Type.NULL)) ) - constraintViolated(o, "The 'arrayref' does not refer to an array but is of type "+arrayref+"."); - return (arrayref instanceof ArrayType); - } - - /***************************************************************/ - /* MISC */ - /***************************************************************/ - /** - * Ensures the general preconditions of an instruction that accesses the stack. - * This method is here because BCEL has no such superinterface for the stack - * accessing instructions; and there are funny unexpected exceptions in the - * semantices of the superinterfaces and superclasses provided. - * E.g. SWAP is a StackConsumer, but DUP_X1 is not a StackProducer. - * Therefore, this method is called by all StackProducer, StackConsumer, - * and StackInstruction instances via their visitXXX() method. - * Unfortunately, as the superclasses and superinterfaces overlap, some instructions - * cause this method to be called two or three times. [TODO: Fix this.] - * - * @see #visitStackConsumer(StackConsumer o) - * @see #visitStackProducer(StackProducer o) - * @see #visitStackInstruction(StackInstruction o) - */ - private void _visitStackAccessor(Instruction o){ - int consume = o.consumeStack(cpg); // Stack values are always consumed first; then produced. - if (consume > stack().slotsUsed()){ - constraintViolated((Instruction) o, "Cannot consume "+consume+" stack slots: only "+stack().slotsUsed()+" slot(s) left on stack!\nStack:\n"+stack()); - } - - int produce = o.produceStack(cpg) - ((Instruction) o).consumeStack(cpg); // Stack values are always consumed first; then produced. - if ( produce + stack().slotsUsed() > stack().maxStack() ){ - constraintViolated((Instruction) o, "Cannot produce "+produce+" stack slots: only "+(stack().maxStack()-stack().slotsUsed())+" free stack slot(s) left.\nStack:\n"+stack()); - } - } - - /***************************************************************/ - /* "generic"visitXXXX methods where XXXX is an interface */ - /* therefore, we don't know the order of visiting; but we know */ - /* these methods are called before the visitYYYY methods below */ - /***************************************************************/ - - /** - * Assures the generic preconditions of a LoadClass instance. - * The referenced class is loaded and pass2-verified. - */ - public void visitLoadClass(Instruction o){ - ObjectType t = o.getLoadClassType(cpg); - if (t != null){// null means "no class is loaded" - Verifier v = VerifierFactory.getVerifier(t.getClassName()); - VerificationResult vr = v.doPass2(); - if (vr.getStatus() != VerificationResult.VERIFIED_OK){ - constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded and resolved: '"+vr+"'."); - } - } - } - - /** - * Ensures the general preconditions of a StackConsumer instance. - */ - public void visitStackConsumer(Instruction o){ - _visitStackAccessor(o); - } - - /** - * Ensures the general preconditions of a StackProducer instance. - */ - public void visitStackProducer(Instruction o){ - _visitStackAccessor(o); - } - - - /***************************************************************/ - /* "generic" visitYYYY methods where YYYY is a superclass. */ - /* therefore, we know the order of visiting; we know */ - /* these methods are called after the visitXXXX methods above. */ - /***************************************************************/ - public void visitCPInstruction(Instruction o){ - int idx = o.getIndex(); - if ((idx < 0) || (idx >= cpg.getSize())){ - throw new AssertionViolatedException("Huh?! Constant pool index of instruction '"+o+"' illegal? Pass 3a should have checked this!"); - } - } - - public void visitFieldInstruction(Instruction o){ - // visitLoadClass(o) has been called before: Every FieldOrMethod - // implements LoadClass. - // visitCPInstruction(o) has been called before. - // A FieldInstruction may be: GETFIELD, GETSTATIC, PUTFIELD, PUTSTATIC - Constant c = cpg.getConstant(o.getIndex()); - if (!(c instanceof ConstantFieldref)){ - constraintViolated(o, "Index '"+o.getIndex()+"' should refer to a CONSTANT_Fieldref_info structure, but refers to '"+c+"'."); - } - // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o). - Type t = o.getType(cpg); - if (t instanceof ObjectType){ - String name = ((ObjectType)t).getClassName(); - Verifier v = VerifierFactory.getVerifier( name ); - VerificationResult vr = v.doPass2(); - if (vr.getStatus() != VerificationResult.VERIFIED_OK){ - constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'."); - } - } - } - - public void visitInvokeInstruction(InvokeInstruction o){ - // visitLoadClass(o) has been called before: Every FieldOrMethod - // implements LoadClass. - // visitCPInstruction(o) has been called before. - //TODO - } - - public void visitStackInstruction(Instruction o){ - _visitStackAccessor(o); - } - - /** - * Assures the generic preconditions of a LocalVariableInstruction instance. - * That is, the index of the local variable must be valid. - */ - public void visitLocalVariableInstruction(InstructionLV o){ - if (locals().maxLocals() <= (o.getType(cpg).getSize()==1? o.getIndex() : o.getIndex()+1) ){ - constraintViolated(o, "The 'index' is not a valid index into the local variable array."); - } - } - - public void visitLoadInstruction(Instruction o){ - //visitLocalVariableInstruction(o) is called before, because it is more generic. - - // LOAD instructions must not read Type.UNKNOWN - if (locals().get(o.getIndex()) == Type.UNKNOWN){ - constraintViolated(o, "Read-Access on local variable "+o.getIndex()+" with unknown content."); - } - - // LOAD instructions, two-slot-values at index N must have Type.UNKNOWN - // as a symbol for the higher halve at index N+1 - // [suppose some instruction put an int at N+1--- our double at N is defective] - if (o.getType(cpg).getSize() == 2){ - if (locals().get(o.getIndex()+1) != Type.UNKNOWN){ - constraintViolated(o, "Reading a two-locals value from local variables "+o.getIndex()+" and "+(o.getIndex()+1)+" where the latter one is destroyed."); - } - } - - // LOAD instructions must read the correct type. - if (!o.isALOAD()){ - if (locals().get(o.getIndex()) != o.getType(cpg) ){ - constraintViolated(o, "Local Variable type and LOADing Instruction type mismatch: Local Variable: '"+locals().get(o.getIndex())+"'; Instruction type: '"+o.getType(cpg)+"'."); - } - } - else{ // we deal with an ALOAD - if (!(locals().get(o.getIndex()) instanceof ReferenceType)){ - constraintViolated(o, "Local Variable type and LOADing Instruction type mismatch: Local Variable: '"+locals().get(o.getIndex())+"'; Instruction expects a ReferenceType."); - } - // ALOAD __IS ALLOWED__ to put uninitialized objects onto the stack! - //referenceTypeIsInitialized(o, (ReferenceType) (locals().get(o.getIndex()))); - } - - // LOAD instructions must have enough free stack slots. - if ((stack().maxStack() - stack().slotsUsed()) < o.getType(cpg).getSize()){ - constraintViolated(o, "Not enough free stack slots to load a '"+o.getType(cpg)+"' onto the OperandStack."); - } - } - - public void visitStoreInstruction(Instruction o){ - //visitLocalVariableInstruction(o) is called before, because it is more generic. - - if (stack().isEmpty()){ // Don't bother about 1 or 2 stack slots used. This check is implicitely done below while type checking. - constraintViolated(o, "Cannot STORE: Stack to read from is empty."); - } - - if (!o.isASTORE() ){ - if (! (stack().peek() == o.getType(cpg)) ){// the other xSTORE types are singletons in BCEL. - constraintViolated(o, "Stack top type and STOREing Instruction type mismatch: Stack top: '"+stack().peek()+"'; Instruction type: '"+o.getType(cpg)+"'."); - } - } - else{ // we deal with ASTORE - Type stacktop = stack().peek(); - if ( (!(stacktop instanceof ReferenceType)) && (!(stacktop instanceof ReturnaddressType)) ){ - constraintViolated(o, "Stack top type and STOREing Instruction type mismatch: Stack top: '"+stack().peek()+"'; Instruction expects a ReferenceType or a ReturnadressType."); - } - if (stacktop instanceof ReferenceType){ - referenceTypeIsInitialized(o, (ReferenceType) stacktop); - } - } - } - - public void visitReturnInstruction(Instruction o){ - if (o.getOpcode()==Constants.RETURN){ - return; - } - if (o.getOpcode()==Constants.ARETURN){ - if (stack().peek() == Type.NULL){ - return; - } - else{ - if (! (stack().peek() instanceof ReferenceType)){ - constraintViolated(o, "Reference type expected on top of stack, but is: '"+stack().peek()+"'."); - } - referenceTypeIsInitialized(o, (ReferenceType) (stack().peek())); - //ReferenceType objectref = (ReferenceType) (stack().peek()); - // TODO: This can only be checked if using Staerk-et-al's "set of object types" instead of a - // "wider cast object type" created during verification. - //if (! (objectref.isAssignmentCompatibleWith(mg.getType())) ){ - // constraintViolated(o, "Type on stack top which should be returned is a '"+stack().peek()+"' which is not assignment compatible with the return type of this method, '"+mg.getType()+"'."); - //} - } - } - else{ - Type method_type = mg.getType(); - if (method_type == Type.BOOLEAN || - method_type == Type.BYTE || - method_type == Type.SHORT || - method_type == Type.CHAR){ - method_type = Type.INT; - } - if (! ( method_type.equals( stack().peek() ))){ - constraintViolated(o, "Current method has return type of '"+mg.getType()+"' expecting a '"+method_type+"' on top of the stack. But stack top is a '"+stack().peek()+"'."); - } - } - } - - /***************************************************************/ - /* "special"visitXXXX methods for one type of instruction each */ - /***************************************************************/ - - public void visitAALOAD(Instruction o){ - Type arrayref = stack().peek(1); - Type index = stack().peek(0); - - indexOfInt(o, index); - if (arrayrefOfArrayType(o, arrayref)){ - if (! (((ArrayType) arrayref).getElementType() instanceof ReferenceType)){ - constraintViolated(o, "The 'arrayref' does not refer to an array with elements of a ReferenceType but to an array of "+((ArrayType) arrayref).getElementType()+"."); - } - referenceTypeIsInitialized(o, (ReferenceType) (((ArrayType) arrayref).getElementType())); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitAASTORE(Instruction o){ - Type arrayref = stack().peek(2); - Type index = stack().peek(1); - Type value = stack().peek(0); - - indexOfInt(o, index); - if (!(value instanceof ReferenceType)){ - constraintViolated(o, "The 'value' is not of a ReferenceType but of type "+value+"."); - }else{ - referenceTypeIsInitialized(o, (ReferenceType) value); - } - // Don't bother further with "referenceTypeIsInitialized()", there are no arrays - // of an uninitialized object type. - if (arrayrefOfArrayType(o, arrayref)){ - if (! (((ArrayType) arrayref).getElementType() instanceof ReferenceType)){ - constraintViolated(o, "The 'arrayref' does not refer to an array with elements of a ReferenceType but to an array of "+((ArrayType) arrayref).getElementType()+"."); - } - if (! ((ReferenceType)value).isAssignmentCompatibleWith((ReferenceType) ((ArrayType) arrayref).getElementType())){ - constraintViolated(o, "The type of 'value' ('"+value+"') is not assignment compatible to the components of the array 'arrayref' refers to. ('"+((ArrayType) arrayref).getElementType()+"')"); - } - } - } - - public void visitACONST_NULL(Instruction o){ - // Nothing needs to be done here. - } - - public void visitALOAD(Instruction o){ - //visitLoadInstruction(LoadInstruction) is called before. - // Nothing else needs to be done here. - } - - public void visitANEWARRAY(Instruction o){ - if (!stack().peek().equals(Type.INT)) - constraintViolated(o, "The 'count' at the stack top is not of type '"+Type.INT+"' but of type '"+stack().peek()+"'."); - // The runtime constant pool item at that index must be a symbolic reference to a class, - // array, or interface type. See Pass 3a. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitARETURN(Instruction o){ - if (! (stack().peek() instanceof ReferenceType) ){ - constraintViolated(o, "The 'objectref' at the stack top is not of a ReferenceType but of type '"+stack().peek()+"'."); - } - ReferenceType objectref = (ReferenceType) (stack().peek()); - referenceTypeIsInitialized(o, objectref); - - // The check below should already done via visitReturnInstruction(ReturnInstruction), see there. - // It cannot be done using Staerk-et-al's "set of object types" instead of a - // "wider cast object type", anyway. - //if (! objectref.isAssignmentCompatibleWith(mg.getReturnType() )){ - // constraintViolated(o, "The 'objectref' type "+objectref+" at the stack top is not assignment compatible with the return type '"+mg.getReturnType()+"' of the method."); - //} - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitARRAYLENGTH(Instruction o){ - Type arrayref = stack().peek(0); - arrayrefOfArrayType(o, arrayref); - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitASTORE(Instruction o){ - if (! ( (stack().peek() instanceof ReferenceType) || (stack().peek() instanceof ReturnaddressType) ) ){ - constraintViolated(o, "The 'objectref' is not of a ReferenceType or of ReturnaddressType but of "+stack().peek()+"."); - } - if (stack().peek() instanceof ReferenceType){ - referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) ); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitATHROW(Instruction o){ - // It's stated that 'objectref' must be of a ReferenceType --- but since Throwable is - // not derived from an ArrayType, it follows that 'objectref' must be of an ObjectType or Type.NULL. - if (! ((stack().peek() instanceof ObjectType) || (stack().peek().equals(Type.NULL))) ){ - constraintViolated(o, "The 'objectref' is not of an (initialized) ObjectType but of type "+stack().peek()+"."); - } - - // NULL is a subclass of every class, so to speak. - if (stack().peek().equals(Type.NULL)) return; - - ObjectType exc = (ObjectType) (stack().peek()); - ObjectType throwable = (ObjectType) (Type.getType("Ljava/lang/Throwable;")); - if ( (! (exc.subclassOf(throwable)) ) && (! (exc.equals(throwable))) ){ - constraintViolated(o, "The 'objectref' is not of class Throwable or of a subclass of Throwable, but of '"+stack().peek()+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitBALOAD(Instruction o){ - Type arrayref = stack().peek(1); - Type index = stack().peek(0); - indexOfInt(o, index); - if (arrayrefOfArrayType(o, arrayref)){ - if (! ( (((ArrayType) arrayref).getElementType().equals(Type.BOOLEAN)) || - (((ArrayType) arrayref).getElementType().equals(Type.BYTE)) ) ){ - constraintViolated(o, "The 'arrayref' does not refer to an array with elements of a Type.BYTE or Type.BOOLEAN but to an array of '"+((ArrayType) arrayref).getElementType()+"'."); - } - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitBASTORE(Instruction o){ - Type arrayref = stack().peek(2); - Type index = stack().peek(1); - Type value = stack().peek(0); - - indexOfInt(o, index); - valueOfInt(o, value); - if (arrayrefOfArrayType(o, arrayref)){ - if (! ( (((ArrayType) arrayref).getElementType().equals(Type.BOOLEAN)) || - (((ArrayType) arrayref).getElementType().equals(Type.BYTE)) ) ) - constraintViolated(o, "The 'arrayref' does not refer to an array with elements of a Type.BYTE or Type.BOOLEAN but to an array of '"+((ArrayType) arrayref).getElementType()+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitBIPUSH(Instruction o){ - // Nothing to do... - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitBREAKPOINT(Instruction o){ - throw new AssertionViolatedException("In this JustIce verification pass there should not occur an illegal instruction such as BREAKPOINT."); - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitCALOAD(Instruction o){ - Type arrayref = stack().peek(1); - Type index = stack().peek(0); - - indexOfInt(o, index); - arrayrefOfArrayType(o, arrayref); - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitCASTORE(Instruction o){ - Type arrayref = stack().peek(2); - Type index = stack().peek(1); - Type value = stack().peek(0); - - indexOfInt(o, index); - valueOfInt(o, value); - if (arrayrefOfArrayType(o, arrayref)){ - if (! ((ArrayType) arrayref).getElementType().equals(Type.CHAR) ){ - constraintViolated(o, "The 'arrayref' does not refer to an array with elements of type char but to an array of type "+((ArrayType) arrayref).getElementType()+"."); - } - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitCHECKCAST(Instruction o){ - // The objectref must be of type reference. - Type objectref = stack().peek(0); - if (!(objectref instanceof ReferenceType)){ - constraintViolated(o, "The 'objectref' is not of a ReferenceType but of type "+objectref+"."); - } - else{ - referenceTypeIsInitialized(o, (ReferenceType) objectref); - } - // The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the - // current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant - // pool item at the index must be a symbolic reference to a class, array, or interface type. - Constant c = cpg.getConstant(o.getIndex()); - if (! (c instanceof ConstantClass)){ - constraintViolated(o, "The Constant at 'index' is not a ConstantClass, but '"+c+"'."); - } - } - - public void visitD2F(Instruction o) { checkTop(o,Type.DOUBLE); } - public void visitD2I(Instruction o) { checkTop(o,Type.DOUBLE); } - public void visitD2L(Instruction o) { checkTop(o,Type.DOUBLE); } - - public void visitDADD(Instruction o){ - checkTop(o,Type.DOUBLE); - if (stack().peek(1) != Type.DOUBLE){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); - } - } - - public void visitDALOAD(Instruction o){ - indexOfInt(o, stack().peek()); - if (stack().peek(1) == Type.NULL){ - return; - } - if (! (stack().peek(1) instanceof ArrayType)){ - constraintViolated(o, "Stack next-to-top must be of type double[] but is '"+stack().peek(1)+"'."); - } - Type t = ((ArrayType) (stack().peek(1))).getBasicType(); - if (t != Type.DOUBLE){ - constraintViolated(o, "Stack next-to-top must be of type double[] but is '"+stack().peek(1)+"'."); - } - } - - public void visitDASTORE(Instruction o){ - if (stack().peek() != Type.DOUBLE){ - constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'."); - } - indexOfInt(o, stack().peek(1)); - if (stack().peek(2) == Type.NULL){ - return; - } - if (! (stack().peek(2) instanceof ArrayType)){ - constraintViolated(o, "Stack next-to-next-to-top must be of type double[] but is '"+stack().peek(2)+"'."); - } - Type t = ((ArrayType) (stack().peek(2))).getBasicType(); - if (t != Type.DOUBLE){ - constraintViolated(o, "Stack next-to-next-to-top must be of type double[] but is '"+stack().peek(2)+"'."); - } - } - - public void visitDCMPG(Instruction o){ - checkTop(o,Type.DOUBLE); - if (stack().peek(1) != Type.DOUBLE){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); - } - } - - public void visitDCMPL(Instruction o){ - checkTop(o,Type.DOUBLE); - if (stack().peek(1) != Type.DOUBLE){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); - } - } - - public void visitDCONST(Instruction o){ - // There's nothing to be done here. - } - - public void visitDDIV(Instruction o){ - checkTop(o,Type.DOUBLE); - if (stack().peek(1) != Type.DOUBLE){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); - } - } - - public void visitDLOAD(Instruction o){ - //visitLoadInstruction(LoadInstruction) is called before. - - // Nothing else needs to be done here. - } - - public void visitDMUL(Instruction o){ - checkTop(o,Type.DOUBLE); - if (stack().peek(1) != Type.DOUBLE){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); - } - } - - public void visitDNEG(Instruction o){ - checkTop(o,Type.DOUBLE); - } - - public void visitDREM(Instruction o){ - checkTop(o,Type.DOUBLE); - if (stack().peek(1) != Type.DOUBLE){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); - } - } - - private void checkTop(Instruction o,Type t) { - if (stack().peek()!=t) - constraintViolated(o, "The value at the stack top is not of type '"+t+"', but of type '"+stack().peek()+"'."); - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitDRETURN(Instruction o){ - checkTop(o,Type.DOUBLE); - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitDSTORE(Instruction o){ - //visitStoreInstruction(StoreInstruction) is called before. - - // Nothing else needs to be done here. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitDSUB(Instruction o){ - if (stack().peek() != Type.DOUBLE){ - constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'."); - } - if (stack().peek(1) != Type.DOUBLE){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitDUP(Instruction o){ - if (stack().peek().getSize() != 1){ - constraintViolated(o, "Won't DUP type on stack top '"+stack().peek()+"' because it must occupy exactly one slot, not '"+stack().peek().getSize()+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitDUP_X1(Instruction o){ - if (stack().peek().getSize() != 1){ - constraintViolated(o, "Type on stack top '"+stack().peek()+"' should occupy exactly one slot, not '"+stack().peek().getSize()+"'."); - } - if (stack().peek(1).getSize() != 1){ - constraintViolated(o, "Type on stack next-to-top '"+stack().peek(1)+"' should occupy exactly one slot, not '"+stack().peek(1).getSize()+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitDUP_X2(Instruction o){ - if (stack().peek().getSize() != 1){ - constraintViolated(o, "Stack top type must be of size 1, but is '"+stack().peek()+"' of size '"+stack().peek().getSize()+"'."); - } - if (stack().peek(1).getSize() == 2){ - return; // Form 2, okay. - } - else{ //stack().peek(1).getSize == 1. - if (stack().peek(2).getSize() != 1){ - constraintViolated(o, "If stack top's size is 1 and stack next-to-top's size is 1, stack next-to-next-to-top's size must also be 1, but is: '"+stack().peek(2)+"' of size '"+stack().peek(2).getSize()+"'."); - } - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitDUP2(Instruction o){ - if (stack().peek().getSize() == 2){ - return; // Form 2, okay. - } - else{ //stack().peek().getSize() == 1. - if (stack().peek(1).getSize() != 1){ - constraintViolated(o, "If stack top's size is 1, then stack next-to-top's size must also be 1. But it is '"+stack().peek(1)+"' of size '"+stack().peek(1).getSize()+"'."); - } - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitDUP2_X1(Instruction o){ - if (stack().peek().getSize() == 2){ - if (stack().peek(1).getSize() != 1){ - constraintViolated(o, "If stack top's size is 2, then stack next-to-top's size must be 1. But it is '"+stack().peek(1)+"' of size '"+stack().peek(1).getSize()+"'."); - } - else{ - return; // Form 2 - } - } - else{ // stack top is of size 1 - if ( stack().peek(1).getSize() != 1 ){ - constraintViolated(o, "If stack top's size is 1, then stack next-to-top's size must also be 1. But it is '"+stack().peek(1)+"' of size '"+stack().peek(1).getSize()+"'."); - } - if ( stack().peek(2).getSize() != 1 ){ - constraintViolated(o, "If stack top's size is 1, then stack next-to-next-to-top's size must also be 1. But it is '"+stack().peek(2)+"' of size '"+stack().peek(2).getSize()+"'."); - } - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitDUP2_X2(Instruction o){ - - if (stack().peek(0).getSize() == 2){ - if (stack().peek(1).getSize() == 2){ - return; // Form 4 - } - else{// stack top size is 2, next-to-top's size is 1 - if ( stack().peek(2).getSize() != 1 ){ - constraintViolated(o, "If stack top's size is 2 and stack-next-to-top's size is 1, then stack next-to-next-to-top's size must also be 1. But it is '"+stack().peek(2)+"' of size '"+stack().peek(2).getSize()+"'."); - } - else{ - return; // Form 2 - } - } - } - else{// stack top is of size 1 - if (stack().peek(1).getSize() == 1){ - if ( stack().peek(2).getSize() == 2 ){ - return; // Form 3 - } - else{ - if ( stack().peek(3).getSize() == 1){ - return; // Form 1 - } - } - } - } - constraintViolated(o, "The operand sizes on the stack do not match any of the four forms of usage of this instruction."); - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitF2D(Instruction o){ - if (stack().peek() != Type.FLOAT){ - constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'."); - } - } - - public void visitF2I(Instruction o){ - checkTop(o,Type.FLOAT); - } - - public void visitF2L(Instruction o){ - checkTop(o,Type.FLOAT); - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFADD(Instruction o){ - checkTop(o,Type.FLOAT); - if (stack().peek(1) != Type.FLOAT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFALOAD(Instruction o){ - indexOfInt(o, stack().peek()); - if (stack().peek(1) == Type.NULL){ - return; - } - if (! (stack().peek(1) instanceof ArrayType)){ - constraintViolated(o, "Stack next-to-top must be of type float[] but is '"+stack().peek(1)+"'."); - } - Type t = ((ArrayType) (stack().peek(1))).getBasicType(); - if (t != Type.FLOAT){ - constraintViolated(o, "Stack next-to-top must be of type float[] but is '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFASTORE(Instruction o){ - checkTop(o,Type.FLOAT); - indexOfInt(o, stack().peek(1)); - if (stack().peek(2) == Type.NULL){ - return; - } - if (! (stack().peek(2) instanceof ArrayType)){ - constraintViolated(o, "Stack next-to-next-to-top must be of type float[] but is '"+stack().peek(2)+"'."); - } - Type t = ((ArrayType) (stack().peek(2))).getBasicType(); - if (t != Type.FLOAT){ - constraintViolated(o, "Stack next-to-next-to-top must be of type float[] but is '"+stack().peek(2)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFCMPG(Instruction o){ - checkTop(o,Type.FLOAT); - if (stack().peek(1) != Type.FLOAT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFCMPL(Instruction o){ - checkTop(o,Type.FLOAT); - if (stack().peek(1) != Type.FLOAT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFCONST(Instruction o){ - // nothing to do here. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFDIV(Instruction o){ - checkTop(o,Type.FLOAT); - if (stack().peek(1) != Type.FLOAT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFLOAD(Instruction o){ - //visitLoadInstruction(LoadInstruction) is called before. - - // Nothing else needs to be done here. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFMUL(Instruction o){ - checkTop(o,Type.FLOAT); - if (stack().peek(1) != Type.FLOAT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFNEG(Instruction o){ - checkTop(o,Type.FLOAT); - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFREM(Instruction o){ - checkTop(o,Type.FLOAT); - if (stack().peek(1) != Type.FLOAT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFRETURN(Instruction o){ - checkTop(o,Type.FLOAT); - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFSTORE(Instruction o){ - //visitStoreInstruction(StoreInstruction) is called before. - - // Nothing else needs to be done here. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitFSUB(Instruction o){ - if (stack().peek() != Type.FLOAT){ - constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'."); - } - if (stack().peek(1) != Type.FLOAT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitGETFIELD(FieldInstruction o){ - Type objectref = stack().peek(); - if (! ( (objectref instanceof ObjectType) || (objectref == Type.NULL) ) ){ - constraintViolated(o, "Stack top should be an object reference that's not an array reference, but is '"+objectref+"'."); - } - - String field_name = o.getFieldName(cpg); - - JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName()); - Field[] fields = jc.getFields(); - Field f = null; - for (int i=0; i=0; i--){ - Type fromStack = stack().peek( (nargs-1) - i ); // 0 to nargs-1 - Type fromDesc = argtypes[i]; - if (fromDesc == Type.BOOLEAN || - fromDesc == Type.BYTE || - fromDesc == Type.CHAR || - fromDesc == Type.SHORT){ - fromDesc = Type.INT; - } - if (! fromStack.equals(fromDesc)){ - if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){ - //ReferenceType rFromStack = (ReferenceType) fromStack; - //ReferenceType rFromDesc = (ReferenceType) fromDesc; - // TODO: This can only be checked when using Staerk-et-al's "set of object types" - // instead of a "wider cast object type" created during verification. - //if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){ - // constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible)."); - //} - } - else{ - constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack."); - } - } - } - - Type objref = stack().peek(nargs); - if (objref == Type.NULL){ - return; - } - if (! (objref instanceof ReferenceType) ){ - constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '"+objref+"'."); - } - referenceTypeIsInitialized(o, (ReferenceType) objref); - if (!(objref instanceof ObjectType)){ - if (!(objref instanceof ArrayType)){ - constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '"+objref+"'."); // could be a ReturnaddressType - } - else{ - objref = GENERIC_ARRAY; - } - } - - // String objref_classname = ((ObjectType) objref).getClassName(); - // String theInterface = o.getClassName(cpg); - // TODO: This can only be checked if we're using Staerk-et-al's "set of object types" - // instead of "wider cast object types" generated during verification. - //if ( ! Repository.implementationOf(objref_classname, theInterface) ){ - // constraintViolated(o, "The 'objref' item '"+objref+"' does not implement '"+theInterface+"' as expected."); - //} - - int counted_count = 1; // 1 for the objectref - for (int i=0; i=0; i--){ - Type fromStack = stack().peek( (nargs-1) - i ); // 0 to nargs-1 - Type fromDesc = argtypes[i]; - if (fromDesc == Type.BOOLEAN || - fromDesc == Type.BYTE || - fromDesc == Type.CHAR || - fromDesc == Type.SHORT){ - fromDesc = Type.INT; - } - if (! fromStack.equals(fromDesc)){ - if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){ - ReferenceType rFromStack = (ReferenceType) fromStack; - ReferenceType rFromDesc = (ReferenceType) fromDesc; - // TODO: This can only be checked using Staerk-et-al's "set of object types", not - // using a "wider cast object type". - if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){ - constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible)."); - } - } - else{ - constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack."); - } - } - } - - Type objref = stack().peek(nargs); - if (objref == Type.NULL){ - return; - } - if (! (objref instanceof ReferenceType) ){ - constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '"+objref+"'."); - } - String objref_classname = null; - if ( !(o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME))){ - referenceTypeIsInitialized(o, (ReferenceType) objref); - if (!(objref instanceof ObjectType)){ - if (!(objref instanceof ArrayType)){ - constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '"+objref+"'."); // could be a ReturnaddressType - } - else{ - objref = GENERIC_ARRAY; - } - } - - objref_classname = ((ObjectType) objref).getClassName(); - } - else{ - if (!(objref instanceof UninitializedObjectType)){ - constraintViolated(o, "Expecting an UninitializedObjectType as 'objectref' on the stack, not a '"+objref+"'. Otherwise, you couldn't invoke a method since an array has no methods (not to speak of a return address)."); - } - objref_classname = ((UninitializedObjectType) objref).getInitialized().getClassName(); - } - - - String theClass = o.getClassName(cpg); - if ( ! Repository.instanceOf(objref_classname, theClass) ){ - constraintViolated(o, "The 'objref' item '"+objref+"' does not implement '"+theClass+"' as expected."); - } - - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitINVOKESTATIC(InvokeInstruction o){ - // Method is not native, otherwise pass 3 would not happen. - - Type t = o.getType(cpg); - if (t instanceof ObjectType){ - String name = ((ObjectType)t).getClassName(); - Verifier v = VerifierFactory.getVerifier( name ); - VerificationResult vr = v.doPass2(); - if (vr.getStatus() != VerificationResult.VERIFIED_OK){ - constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'."); - } - } - - Type[] argtypes = o.getArgumentTypes(cpg); - int nargs = argtypes.length; - - for (int i=nargs-1; i>=0; i--){ - Type fromStack = stack().peek( (nargs-1) - i ); // 0 to nargs-1 - Type fromDesc = argtypes[i]; - if (fromDesc == Type.BOOLEAN || - fromDesc == Type.BYTE || - fromDesc == Type.CHAR || - fromDesc == Type.SHORT){ - fromDesc = Type.INT; - } - if (! fromStack.equals(fromDesc)){ - if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){ - ReferenceType rFromStack = (ReferenceType) fromStack; - ReferenceType rFromDesc = (ReferenceType) fromDesc; - // TODO: This check can possibly only be done using Staerk-et-al's "set of object types" - // instead of a "wider cast object type" created during verification. - if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){ - constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible)."); - } - } - else{ - constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack."); - } - } - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitINVOKEVIRTUAL(InvokeInstruction o){ - // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o). - - Type t = o.getType(cpg); - if (t instanceof ObjectType){ - String name = ((ObjectType)t).getClassName(); - Verifier v = VerifierFactory.getVerifier( name ); - VerificationResult vr = v.doPass2(); - if (vr.getStatus() != VerificationResult.VERIFIED_OK){ - constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'."); - } - } - - - Type[] argtypes = o.getArgumentTypes(cpg); - int nargs = argtypes.length; - - for (int i=nargs-1; i>=0; i--){ - Type fromStack = stack().peek( (nargs-1) - i ); // 0 to nargs-1 - Type fromDesc = argtypes[i]; - if (fromDesc == Type.BOOLEAN || - fromDesc == Type.BYTE || - fromDesc == Type.CHAR || - fromDesc == Type.SHORT){ - fromDesc = Type.INT; - } - if (! fromStack.equals(fromDesc)){ - if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){ - ReferenceType rFromStack = (ReferenceType) fromStack; - ReferenceType rFromDesc = (ReferenceType) fromDesc; - // TODO: This can possibly only be checked when using Staerk-et-al's "set of object types" instead - // of a single "wider cast object type" created during verification. - if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){ - constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible)."); - } - } - else{ - constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack."); - } - } - } - - Type objref = stack().peek(nargs); - if (objref == Type.NULL){ - return; - } - if (! (objref instanceof ReferenceType) ){ - constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '"+objref+"'."); - } - referenceTypeIsInitialized(o, (ReferenceType) objref); - if (!(objref instanceof ObjectType)){ - if (!(objref instanceof ArrayType)){ - constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '"+objref+"'."); // could be a ReturnaddressType - } - else{ - objref = GENERIC_ARRAY; - } - } - - String objref_classname = ((ObjectType) objref).getClassName(); - - String theClass = o.getClassName(cpg); - - if ( ! Repository.instanceOf(objref_classname, theClass) ){ - constraintViolated(o, "The 'objref' item '"+objref+"' does not implement '"+theClass+"' as expected."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitIOR(Instruction o){ - if (stack().peek() != Type.INT){ - constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'."); - } - if (stack().peek(1) != Type.INT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitIREM(Instruction o){ - if (stack().peek() != Type.INT){ - constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'."); - } - if (stack().peek(1) != Type.INT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitIRETURN(Instruction o){ - if (stack().peek() != Type.INT){ - constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitISHL(Instruction o){ - checkTop(o,Type.INT); - if (stack().peek(1) != Type.INT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitISHR(Instruction o){ - checkTop(o,Type.INT); - if (stack().peek(1) != Type.INT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitISTORE(Instruction o){ - //visitStoreInstruction(StoreInstruction) is called before. - - // Nothing else needs to be done here. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitISUB(Instruction o){ - checkTop(o,Type.INT); - if (stack().peek(1) != Type.INT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitIUSHR(Instruction o){ - checkTop(o,Type.INT); - if (stack().peek(1) != Type.INT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitIXOR(Instruction o){ - if (stack().peek() != Type.INT){ - constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'."); - } - if (stack().peek(1) != Type.INT){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitJSR(InstructionBranch o){ - // nothing to do here. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitJSR_W(InstructionBranch o){ - // nothing to do here. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitL2D(Instruction o){ - if (stack().peek() != Type.LONG){ - constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitL2F(Instruction o){ - if (stack().peek() != Type.LONG){ - constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitL2I(Instruction o){ - if (stack().peek() != Type.LONG){ - constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLADD(Instruction o){ - if (stack().peek() != Type.LONG){ - constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); - } - if (stack().peek(1) != Type.LONG){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLALOAD(Instruction o){ - indexOfInt(o, stack().peek()); - if (stack().peek(1) == Type.NULL){ - return; - } - if (! (stack().peek(1) instanceof ArrayType)){ - constraintViolated(o, "Stack next-to-top must be of type long[] but is '"+stack().peek(1)+"'."); - } - Type t = ((ArrayType) (stack().peek(1))).getBasicType(); - if (t != Type.LONG){ - constraintViolated(o, "Stack next-to-top must be of type long[] but is '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLAND(Instruction o){ - if (stack().peek() != Type.LONG){ - constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); - } - if (stack().peek(1) != Type.LONG){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLASTORE(Instruction o){ - if (stack().peek() != Type.LONG){ - constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); - } - indexOfInt(o, stack().peek(1)); - if (stack().peek(2) == Type.NULL){ - return; - } - if (! (stack().peek(2) instanceof ArrayType)){ - constraintViolated(o, "Stack next-to-next-to-top must be of type long[] but is '"+stack().peek(2)+"'."); - } - Type t = ((ArrayType) (stack().peek(2))).getBasicType(); - if (t != Type.LONG){ - constraintViolated(o, "Stack next-to-next-to-top must be of type long[] but is '"+stack().peek(2)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLCMP(Instruction o){ - if (stack().peek() != Type.LONG){ - constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); - } - if (stack().peek(1) != Type.LONG){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLCONST(Instruction o){ - // Nothing to do here. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLDC(Instruction o){ - // visitCPInstruction is called first. - - Constant c = cpg.getConstant(o.getIndex()); - if (! ( ( c instanceof ConstantInteger) || - ( c instanceof ConstantFloat ) || - ( c instanceof ConstantString ) ) ){ - constraintViolated(o, "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String, but is '"+c+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLDC_W(Instruction o){ - // visitCPInstruction is called first. - - Constant c = cpg.getConstant(o.getIndex()); - if (! ( ( c instanceof ConstantInteger) || - ( c instanceof ConstantFloat ) || - ( c instanceof ConstantString ) ) ){ - constraintViolated(o, "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String, but is '"+c+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLDC2_W(Instruction o){ - // visitCPInstruction is called first. - - Constant c = cpg.getConstant(o.getIndex()); - if (! ( ( c instanceof ConstantLong) || - ( c instanceof ConstantDouble ) ) ){ - constraintViolated(o, "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String, but is '"+c+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLDIV(Instruction o){ - if (stack().peek() != Type.LONG){ - constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); - } - if (stack().peek(1) != Type.LONG){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLLOAD(Instruction o){ - //visitLoadInstruction(LoadInstruction) is called before. - - // Nothing else needs to be done here. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLMUL(Instruction o){ - if (stack().peek() != Type.LONG){ - constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); - } - if (stack().peek(1) != Type.LONG){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); - } - } - - public void visitLNEG(Instruction o){ - checkTop(o,Type.LONG); - } - - public void visitLOOKUPSWITCH(LOOKUPSWITCH o){ - checkTop(o,Type.INT); - // See also pass 3a. - } - - public void visitLOR(Instruction o){ - if (stack().peek() != Type.LONG){ - constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); - } - if (stack().peek(1) != Type.LONG){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); - } - } - - public void visitLREM(Instruction o){ - checkTop(o,Type.LONG); - if (stack().peek(1) != Type.LONG){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); - } - } - - public void visitLRETURN(Instruction o) { checkTop(o,Type.LONG); } - public void visitLSHL(Instruction o){ - checkTop(o,Type.INT); - if (stack().peek(1) != Type.LONG){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLSHR(Instruction o){ - if (stack().peek() != Type.INT){ - constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'."); - } - if (stack().peek(1) != Type.LONG){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLSTORE(Instruction o){ - //visitStoreInstruction(StoreInstruction) is called before. - - // Nothing else needs to be done here. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLSUB(Instruction o){ - checkTop(o,Type.LONG); - if (stack().peek(1) != Type.LONG){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLUSHR(Instruction o){ - checkTop(o,Type.INT); - if (stack().peek(1) != Type.LONG){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitLXOR(Instruction o){ - checkTop(o,Type.LONG); - if (stack().peek(1) != Type.LONG){ - constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitMONITORENTER(Instruction o){ - if (! ((stack().peek()) instanceof ReferenceType)){ - constraintViolated(o, "The stack top should be of a ReferenceType, but is '"+stack().peek()+"'."); - } - referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) ); - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitMONITOREXIT(Instruction o){ - if (! ((stack().peek()) instanceof ReferenceType)){ - constraintViolated(o, "The stack top should be of a ReferenceType, but is '"+stack().peek()+"'."); - } - referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) ); - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitMULTIANEWARRAY(MULTIANEWARRAY o){ - int dimensions = o.getDimensions(); - // Dimensions argument is okay: see Pass 3a. - for (int i=0; i, see Pass 3a. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitRET(RET o){ - if (! (locals().get(o.getIndex()) instanceof ReturnaddressType)){ - constraintViolated(o, "Expecting a ReturnaddressType in local variable "+o.getIndex()+"."); - } - if (locals().get(o.getIndex()) == ReturnaddressType.NO_TARGET){ - throw new AssertionViolatedException("Oops: RET expecting a target!"); - } - // Other constraints such as non-allowed overlapping subroutines are enforced - // while building the Subroutines data structure. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitRETURN(Instruction o){ - if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)){// If we leave an method - if ((Frame._this != null) && (!(mg.getClassName().equals(Type.OBJECT.getClassName()))) ) { - constraintViolated(o, "Leaving a constructor that itself did not call a constructor."); - } - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitSALOAD(Instruction o){ - indexOfInt(o, stack().peek()); - if (stack().peek(1) == Type.NULL){ - return; - } - if (! (stack().peek(1) instanceof ArrayType)){ - constraintViolated(o, "Stack next-to-top must be of type short[] but is '"+stack().peek(1)+"'."); - } - Type t = ((ArrayType) (stack().peek(1))).getBasicType(); - if (t != Type.SHORT){ - constraintViolated(o, "Stack next-to-top must be of type short[] but is '"+stack().peek(1)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitSASTORE(Instruction o){ - if (stack().peek() != Type.INT){ - constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'."); - } - indexOfInt(o, stack().peek(1)); - if (stack().peek(2) == Type.NULL){ - return; - } - if (! (stack().peek(2) instanceof ArrayType)){ - constraintViolated(o, "Stack next-to-next-to-top must be of type short[] but is '"+stack().peek(2)+"'."); - } - Type t = ((ArrayType) (stack().peek(2))).getBasicType(); - if (t != Type.SHORT){ - constraintViolated(o, "Stack next-to-next-to-top must be of type short[] but is '"+stack().peek(2)+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitSIPUSH(Instruction o){ - // nothing to do here. Generic visitXXX() methods did the trick before. - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitSWAP(Instruction o){ - if (stack().peek().getSize() != 1){ - constraintViolated(o, "The value at the stack top is not of size '1', but of size '"+stack().peek().getSize()+"'."); - } - if (stack().peek(1).getSize() != 1){ - constraintViolated(o, "The value at the stack next-to-top is not of size '1', but of size '"+stack().peek(1).getSize()+"'."); - } - } - - /** - * Ensures the specific preconditions of the said instruction. - */ - public void visitTABLESWITCH(TABLESWITCH o){ - indexOfInt(o, stack().peek()); - // See Pass 3a. - } - -} - +package org.aspectj.apache.bcel.verifier.structurals; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.Repository; +import org.aspectj.apache.bcel.classfile.Constant; +import org.aspectj.apache.bcel.classfile.ConstantClass; +import org.aspectj.apache.bcel.classfile.ConstantDouble; +import org.aspectj.apache.bcel.classfile.ConstantInteger; +import org.aspectj.apache.bcel.classfile.ConstantFieldref; +import org.aspectj.apache.bcel.classfile.ConstantFloat; +import org.aspectj.apache.bcel.classfile.ConstantLong; +import org.aspectj.apache.bcel.classfile.ConstantString; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.classfile.Field; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.verifier.EmptyInstVisitor; +import org.aspectj.apache.bcel.verifier.VerificationResult; +import org.aspectj.apache.bcel.verifier.Verifier; +import org.aspectj.apache.bcel.verifier.VerifierFactory; +import org.aspectj.apache.bcel.verifier.exc.*; +import org.aspectj.apache.bcel.generic.ArrayType; +import org.aspectj.apache.bcel.generic.FieldInstruction; +import org.aspectj.apache.bcel.generic.IINC; +import org.aspectj.apache.bcel.generic.INVOKEINTERFACE; +import org.aspectj.apache.bcel.generic.Instruction; +import org.aspectj.apache.bcel.generic.InstructionBranch; +import org.aspectj.apache.bcel.generic.InstructionLV; +import org.aspectj.apache.bcel.generic.InvokeInstruction; +import org.aspectj.apache.bcel.generic.LOOKUPSWITCH; +import org.aspectj.apache.bcel.generic.MULTIANEWARRAY; +import org.aspectj.apache.bcel.generic.MethodGen; +import org.aspectj.apache.bcel.generic.ObjectType; +import org.aspectj.apache.bcel.generic.RET; +import org.aspectj.apache.bcel.generic.ReferenceType; +import org.aspectj.apache.bcel.generic.ReturnaddressType; +import org.aspectj.apache.bcel.generic.TABLESWITCH; +import org.aspectj.apache.bcel.generic.Type; +import org.aspectj.apache.bcel.generic.InstVisitor; + + +/** + * A Visitor class testing for valid preconditions of JVM instructions. + * The instance of this class will throw a StructuralCodeConstraintException + * instance if an instruction is visitXXX()ed which has preconditions that are + * not satisfied. + * TODO: Currently, the JVM's behaviour concerning monitors (MONITORENTER, + * MONITOREXIT) is not modeled in JustIce. + * + * @version $Id: InstConstraintVisitor.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + * @see org.aspectj.apache.bcel.verifier.exc.StructuralCodeConstraintException + * @see org.aspectj.apache.bcel.verifier.exc.LinkingConstraintException + */ +public class InstConstraintVisitor extends EmptyInstVisitor implements InstVisitor { + + private static ObjectType GENERIC_ARRAY = new ObjectType("org.aspectj.apache.bcel.verifier.structurals.GenericArray"); + + /** + * The constructor. Constructs a new instance of this class. + */ + public InstConstraintVisitor(){} + + /** + * The Execution Frame we're working on. + * + * @see #setFrame(Frame f) + * @see #locals() + * @see #stack() + */ + private Frame frame = null; + + private ConstantPool cpg = null; + + /** + * The MethodGen we're working on. + * + * @see #setMethodGen(MethodGen mg) + */ + private MethodGen mg = null; + + /** + * The OperandStack we're working on. + * + * @see #setFrame(Frame f) + */ + private OperandStack stack(){ + return frame.getStack(); + } + + /** + * The LocalVariables we're working on. + * + * @see #setFrame(Frame f) + */ + private LocalVariables locals(){ + return frame.getLocals(); + } + + /** + * This method is called by the visitXXX() to notify the acceptor of this InstConstraintVisitor + * that a constraint violation has occured. This is done by throwing an instance of a + * StructuralCodeConstraintException. + * @throws org.aspectj.apache.bcel.verifier.exc.StructuralCodeConstraintException always. + */ + private void constraintViolated(Instruction violator, String description){ + String fq_classname = violator.getClass().getName(); + throw new StructuralCodeConstraintException("Instruction "+ fq_classname.substring(fq_classname.lastIndexOf('.')+1) +" constraint violated: " + description); + } + + /** + * This returns the single instance of the InstConstraintVisitor class. + * To operate correctly, other values must have been set before actually + * using the instance. + * Use this method for performance reasons. + * + * @see #setConstantPoolGen(ConstantPoolGen cpg) + * @see #setMethodGen(MethodGen mg) + */ + public void setFrame(Frame f){ + this.frame = f; + //if (singleInstance.mg == null || singleInstance.cpg == null) throw new AssertionViolatedException("Forgot to set important values first."); + } + + /** + * Sets the ConstantPoolGen instance needed for constraint + * checking prior to execution. + */ + public void setConstantPoolGen(ConstantPool cpg){ + this.cpg = cpg; + } + + /** + * Sets the MethodGen instance needed for constraint + * checking prior to execution. + */ + public void setMethodGen(MethodGen mg){ + this.mg = mg; + } + + /** + * Assures index is of type INT. + * @throws org.aspectj.apache.bcel.verifier.exc.StructuralCodeConstraintException if the above constraint is not satisfied. + */ + private void indexOfInt(Instruction o, Type index){ + if (! index.equals(Type.INT)) + constraintViolated(o, "The 'index' is not of type int but of type "+index+"."); + } + + /** + * Assures the ReferenceType r is initialized (or Type.NULL). + * Formally, this means (!(r instanceof UninitializedObjectType)), because + * there are no uninitialized array types. + * @throws org.aspectj.apache.bcel.verifier.exc.StructuralCodeConstraintException if the above constraint is not satisfied. + */ + private void referenceTypeIsInitialized(Instruction o, ReferenceType r){ + if (r instanceof UninitializedObjectType){ + constraintViolated(o, "Working on an uninitialized object '"+r+"'."); + } + } + + /** Assures value is of type INT. */ + private void valueOfInt(Instruction o, Type value){ + if (! value.equals(Type.INT)) + constraintViolated(o, "The 'value' is not of type int but of type "+value+"."); + } + + /** + * Assures arrayref is of ArrayType or NULL; + * returns true if and only if arrayref is non-NULL. + * @throws org.aspectj.apache.bcel.verifier.exc.StructuralCodeConstraintException if the above constraint is violated. + */ + private boolean arrayrefOfArrayType(Instruction o, Type arrayref){ + if (! ((arrayref instanceof ArrayType) || arrayref.equals(Type.NULL)) ) + constraintViolated(o, "The 'arrayref' does not refer to an array but is of type "+arrayref+"."); + return (arrayref instanceof ArrayType); + } + + /***************************************************************/ + /* MISC */ + /***************************************************************/ + /** + * Ensures the general preconditions of an instruction that accesses the stack. + * This method is here because BCEL has no such superinterface for the stack + * accessing instructions; and there are funny unexpected exceptions in the + * semantices of the superinterfaces and superclasses provided. + * E.g. SWAP is a StackConsumer, but DUP_X1 is not a StackProducer. + * Therefore, this method is called by all StackProducer, StackConsumer, + * and StackInstruction instances via their visitXXX() method. + * Unfortunately, as the superclasses and superinterfaces overlap, some instructions + * cause this method to be called two or three times. [TODO: Fix this.] + * + * @see #visitStackConsumer(StackConsumer o) + * @see #visitStackProducer(StackProducer o) + * @see #visitStackInstruction(StackInstruction o) + */ + private void _visitStackAccessor(Instruction o){ + int consume = o.consumeStack(cpg); // Stack values are always consumed first; then produced. + if (consume > stack().slotsUsed()){ + constraintViolated((Instruction) o, "Cannot consume "+consume+" stack slots: only "+stack().slotsUsed()+" slot(s) left on stack!\nStack:\n"+stack()); + } + + int produce = o.produceStack(cpg) - ((Instruction) o).consumeStack(cpg); // Stack values are always consumed first; then produced. + if ( produce + stack().slotsUsed() > stack().maxStack() ){ + constraintViolated((Instruction) o, "Cannot produce "+produce+" stack slots: only "+(stack().maxStack()-stack().slotsUsed())+" free stack slot(s) left.\nStack:\n"+stack()); + } + } + + /***************************************************************/ + /* "generic"visitXXXX methods where XXXX is an interface */ + /* therefore, we don't know the order of visiting; but we know */ + /* these methods are called before the visitYYYY methods below */ + /***************************************************************/ + + /** + * Assures the generic preconditions of a LoadClass instance. + * The referenced class is loaded and pass2-verified. + */ + public void visitLoadClass(Instruction o){ + ObjectType t = o.getLoadClassType(cpg); + if (t != null){// null means "no class is loaded" + Verifier v = VerifierFactory.getVerifier(t.getClassName()); + VerificationResult vr = v.doPass2(); + if (vr.getStatus() != VerificationResult.VERIFIED_OK){ + constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded and resolved: '"+vr+"'."); + } + } + } + + /** + * Ensures the general preconditions of a StackConsumer instance. + */ + public void visitStackConsumer(Instruction o){ + _visitStackAccessor(o); + } + + /** + * Ensures the general preconditions of a StackProducer instance. + */ + public void visitStackProducer(Instruction o){ + _visitStackAccessor(o); + } + + + /***************************************************************/ + /* "generic" visitYYYY methods where YYYY is a superclass. */ + /* therefore, we know the order of visiting; we know */ + /* these methods are called after the visitXXXX methods above. */ + /***************************************************************/ + public void visitCPInstruction(Instruction o){ + int idx = o.getIndex(); + if ((idx < 0) || (idx >= cpg.getSize())){ + throw new AssertionViolatedException("Huh?! Constant pool index of instruction '"+o+"' illegal? Pass 3a should have checked this!"); + } + } + + public void visitFieldInstruction(Instruction o){ + // visitLoadClass(o) has been called before: Every FieldOrMethod + // implements LoadClass. + // visitCPInstruction(o) has been called before. + // A FieldInstruction may be: GETFIELD, GETSTATIC, PUTFIELD, PUTSTATIC + Constant c = cpg.getConstant(o.getIndex()); + if (!(c instanceof ConstantFieldref)){ + constraintViolated(o, "Index '"+o.getIndex()+"' should refer to a CONSTANT_Fieldref_info structure, but refers to '"+c+"'."); + } + // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o). + Type t = o.getType(cpg); + if (t instanceof ObjectType){ + String name = ((ObjectType)t).getClassName(); + Verifier v = VerifierFactory.getVerifier( name ); + VerificationResult vr = v.doPass2(); + if (vr.getStatus() != VerificationResult.VERIFIED_OK){ + constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'."); + } + } + } + + public void visitInvokeInstruction(InvokeInstruction o){ + // visitLoadClass(o) has been called before: Every FieldOrMethod + // implements LoadClass. + // visitCPInstruction(o) has been called before. + //TODO + } + + public void visitStackInstruction(Instruction o){ + _visitStackAccessor(o); + } + + /** + * Assures the generic preconditions of a LocalVariableInstruction instance. + * That is, the index of the local variable must be valid. + */ + public void visitLocalVariableInstruction(InstructionLV o){ + if (locals().maxLocals() <= (o.getType(cpg).getSize()==1? o.getIndex() : o.getIndex()+1) ){ + constraintViolated(o, "The 'index' is not a valid index into the local variable array."); + } + } + + public void visitLoadInstruction(Instruction o){ + //visitLocalVariableInstruction(o) is called before, because it is more generic. + + // LOAD instructions must not read Type.UNKNOWN + if (locals().get(o.getIndex()) == Type.UNKNOWN){ + constraintViolated(o, "Read-Access on local variable "+o.getIndex()+" with unknown content."); + } + + // LOAD instructions, two-slot-values at index N must have Type.UNKNOWN + // as a symbol for the higher halve at index N+1 + // [suppose some instruction put an int at N+1--- our double at N is defective] + if (o.getType(cpg).getSize() == 2){ + if (locals().get(o.getIndex()+1) != Type.UNKNOWN){ + constraintViolated(o, "Reading a two-locals value from local variables "+o.getIndex()+" and "+(o.getIndex()+1)+" where the latter one is destroyed."); + } + } + + // LOAD instructions must read the correct type. + if (!o.isALOAD()){ + if (locals().get(o.getIndex()) != o.getType(cpg) ){ + constraintViolated(o, "Local Variable type and LOADing Instruction type mismatch: Local Variable: '"+locals().get(o.getIndex())+"'; Instruction type: '"+o.getType(cpg)+"'."); + } + } + else{ // we deal with an ALOAD + if (!(locals().get(o.getIndex()) instanceof ReferenceType)){ + constraintViolated(o, "Local Variable type and LOADing Instruction type mismatch: Local Variable: '"+locals().get(o.getIndex())+"'; Instruction expects a ReferenceType."); + } + // ALOAD __IS ALLOWED__ to put uninitialized objects onto the stack! + //referenceTypeIsInitialized(o, (ReferenceType) (locals().get(o.getIndex()))); + } + + // LOAD instructions must have enough free stack slots. + if ((stack().maxStack() - stack().slotsUsed()) < o.getType(cpg).getSize()){ + constraintViolated(o, "Not enough free stack slots to load a '"+o.getType(cpg)+"' onto the OperandStack."); + } + } + + public void visitStoreInstruction(Instruction o){ + //visitLocalVariableInstruction(o) is called before, because it is more generic. + + if (stack().isEmpty()){ // Don't bother about 1 or 2 stack slots used. This check is implicitely done below while type checking. + constraintViolated(o, "Cannot STORE: Stack to read from is empty."); + } + + if (!o.isASTORE() ){ + if (! (stack().peek() == o.getType(cpg)) ){// the other xSTORE types are singletons in BCEL. + constraintViolated(o, "Stack top type and STOREing Instruction type mismatch: Stack top: '"+stack().peek()+"'; Instruction type: '"+o.getType(cpg)+"'."); + } + } + else{ // we deal with ASTORE + Type stacktop = stack().peek(); + if ( (!(stacktop instanceof ReferenceType)) && (!(stacktop instanceof ReturnaddressType)) ){ + constraintViolated(o, "Stack top type and STOREing Instruction type mismatch: Stack top: '"+stack().peek()+"'; Instruction expects a ReferenceType or a ReturnadressType."); + } + if (stacktop instanceof ReferenceType){ + referenceTypeIsInitialized(o, (ReferenceType) stacktop); + } + } + } + + public void visitReturnInstruction(Instruction o){ + if (o.getOpcode()==Constants.RETURN){ + return; + } + if (o.getOpcode()==Constants.ARETURN){ + if (stack().peek() == Type.NULL){ + return; + } + else{ + if (! (stack().peek() instanceof ReferenceType)){ + constraintViolated(o, "Reference type expected on top of stack, but is: '"+stack().peek()+"'."); + } + referenceTypeIsInitialized(o, (ReferenceType) (stack().peek())); + //ReferenceType objectref = (ReferenceType) (stack().peek()); + // TODO: This can only be checked if using Staerk-et-al's "set of object types" instead of a + // "wider cast object type" created during verification. + //if (! (objectref.isAssignmentCompatibleWith(mg.getType())) ){ + // constraintViolated(o, "Type on stack top which should be returned is a '"+stack().peek()+"' which is not assignment compatible with the return type of this method, '"+mg.getType()+"'."); + //} + } + } + else{ + Type method_type = mg.getType(); + if (method_type == Type.BOOLEAN || + method_type == Type.BYTE || + method_type == Type.SHORT || + method_type == Type.CHAR){ + method_type = Type.INT; + } + if (! ( method_type.equals( stack().peek() ))){ + constraintViolated(o, "Current method has return type of '"+mg.getType()+"' expecting a '"+method_type+"' on top of the stack. But stack top is a '"+stack().peek()+"'."); + } + } + } + + /***************************************************************/ + /* "special"visitXXXX methods for one type of instruction each */ + /***************************************************************/ + + public void visitAALOAD(Instruction o){ + Type arrayref = stack().peek(1); + Type index = stack().peek(0); + + indexOfInt(o, index); + if (arrayrefOfArrayType(o, arrayref)){ + if (! (((ArrayType) arrayref).getElementType() instanceof ReferenceType)){ + constraintViolated(o, "The 'arrayref' does not refer to an array with elements of a ReferenceType but to an array of "+((ArrayType) arrayref).getElementType()+"."); + } + referenceTypeIsInitialized(o, (ReferenceType) (((ArrayType) arrayref).getElementType())); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitAASTORE(Instruction o){ + Type arrayref = stack().peek(2); + Type index = stack().peek(1); + Type value = stack().peek(0); + + indexOfInt(o, index); + if (!(value instanceof ReferenceType)){ + constraintViolated(o, "The 'value' is not of a ReferenceType but of type "+value+"."); + }else{ + referenceTypeIsInitialized(o, (ReferenceType) value); + } + // Don't bother further with "referenceTypeIsInitialized()", there are no arrays + // of an uninitialized object type. + if (arrayrefOfArrayType(o, arrayref)){ + if (! (((ArrayType) arrayref).getElementType() instanceof ReferenceType)){ + constraintViolated(o, "The 'arrayref' does not refer to an array with elements of a ReferenceType but to an array of "+((ArrayType) arrayref).getElementType()+"."); + } + if (! ((ReferenceType)value).isAssignmentCompatibleWith((ReferenceType) ((ArrayType) arrayref).getElementType())){ + constraintViolated(o, "The type of 'value' ('"+value+"') is not assignment compatible to the components of the array 'arrayref' refers to. ('"+((ArrayType) arrayref).getElementType()+"')"); + } + } + } + + public void visitACONST_NULL(Instruction o){ + // Nothing needs to be done here. + } + + public void visitALOAD(Instruction o){ + //visitLoadInstruction(LoadInstruction) is called before. + // Nothing else needs to be done here. + } + + public void visitANEWARRAY(Instruction o){ + if (!stack().peek().equals(Type.INT)) + constraintViolated(o, "The 'count' at the stack top is not of type '"+Type.INT+"' but of type '"+stack().peek()+"'."); + // The runtime constant pool item at that index must be a symbolic reference to a class, + // array, or interface type. See Pass 3a. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitARETURN(Instruction o){ + if (! (stack().peek() instanceof ReferenceType) ){ + constraintViolated(o, "The 'objectref' at the stack top is not of a ReferenceType but of type '"+stack().peek()+"'."); + } + ReferenceType objectref = (ReferenceType) (stack().peek()); + referenceTypeIsInitialized(o, objectref); + + // The check below should already done via visitReturnInstruction(ReturnInstruction), see there. + // It cannot be done using Staerk-et-al's "set of object types" instead of a + // "wider cast object type", anyway. + //if (! objectref.isAssignmentCompatibleWith(mg.getReturnType() )){ + // constraintViolated(o, "The 'objectref' type "+objectref+" at the stack top is not assignment compatible with the return type '"+mg.getReturnType()+"' of the method."); + //} + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitARRAYLENGTH(Instruction o){ + Type arrayref = stack().peek(0); + arrayrefOfArrayType(o, arrayref); + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitASTORE(Instruction o){ + if (! ( (stack().peek() instanceof ReferenceType) || (stack().peek() instanceof ReturnaddressType) ) ){ + constraintViolated(o, "The 'objectref' is not of a ReferenceType or of ReturnaddressType but of "+stack().peek()+"."); + } + if (stack().peek() instanceof ReferenceType){ + referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) ); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitATHROW(Instruction o){ + // It's stated that 'objectref' must be of a ReferenceType --- but since Throwable is + // not derived from an ArrayType, it follows that 'objectref' must be of an ObjectType or Type.NULL. + if (! ((stack().peek() instanceof ObjectType) || (stack().peek().equals(Type.NULL))) ){ + constraintViolated(o, "The 'objectref' is not of an (initialized) ObjectType but of type "+stack().peek()+"."); + } + + // NULL is a subclass of every class, so to speak. + if (stack().peek().equals(Type.NULL)) return; + + ObjectType exc = (ObjectType) (stack().peek()); + ObjectType throwable = (ObjectType) (Type.getType("Ljava/lang/Throwable;")); + if ( (! (exc.subclassOf(throwable)) ) && (! (exc.equals(throwable))) ){ + constraintViolated(o, "The 'objectref' is not of class Throwable or of a subclass of Throwable, but of '"+stack().peek()+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitBALOAD(Instruction o){ + Type arrayref = stack().peek(1); + Type index = stack().peek(0); + indexOfInt(o, index); + if (arrayrefOfArrayType(o, arrayref)){ + if (! ( (((ArrayType) arrayref).getElementType().equals(Type.BOOLEAN)) || + (((ArrayType) arrayref).getElementType().equals(Type.BYTE)) ) ){ + constraintViolated(o, "The 'arrayref' does not refer to an array with elements of a Type.BYTE or Type.BOOLEAN but to an array of '"+((ArrayType) arrayref).getElementType()+"'."); + } + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitBASTORE(Instruction o){ + Type arrayref = stack().peek(2); + Type index = stack().peek(1); + Type value = stack().peek(0); + + indexOfInt(o, index); + valueOfInt(o, value); + if (arrayrefOfArrayType(o, arrayref)){ + if (! ( (((ArrayType) arrayref).getElementType().equals(Type.BOOLEAN)) || + (((ArrayType) arrayref).getElementType().equals(Type.BYTE)) ) ) + constraintViolated(o, "The 'arrayref' does not refer to an array with elements of a Type.BYTE or Type.BOOLEAN but to an array of '"+((ArrayType) arrayref).getElementType()+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitBIPUSH(Instruction o){ + // Nothing to do... + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitBREAKPOINT(Instruction o){ + throw new AssertionViolatedException("In this JustIce verification pass there should not occur an illegal instruction such as BREAKPOINT."); + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitCALOAD(Instruction o){ + Type arrayref = stack().peek(1); + Type index = stack().peek(0); + + indexOfInt(o, index); + arrayrefOfArrayType(o, arrayref); + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitCASTORE(Instruction o){ + Type arrayref = stack().peek(2); + Type index = stack().peek(1); + Type value = stack().peek(0); + + indexOfInt(o, index); + valueOfInt(o, value); + if (arrayrefOfArrayType(o, arrayref)){ + if (! ((ArrayType) arrayref).getElementType().equals(Type.CHAR) ){ + constraintViolated(o, "The 'arrayref' does not refer to an array with elements of type char but to an array of type "+((ArrayType) arrayref).getElementType()+"."); + } + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitCHECKCAST(Instruction o){ + // The objectref must be of type reference. + Type objectref = stack().peek(0); + if (!(objectref instanceof ReferenceType)){ + constraintViolated(o, "The 'objectref' is not of a ReferenceType but of type "+objectref+"."); + } + else{ + referenceTypeIsInitialized(o, (ReferenceType) objectref); + } + // The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the + // current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant + // pool item at the index must be a symbolic reference to a class, array, or interface type. + Constant c = cpg.getConstant(o.getIndex()); + if (! (c instanceof ConstantClass)){ + constraintViolated(o, "The Constant at 'index' is not a ConstantClass, but '"+c+"'."); + } + } + + public void visitD2F(Instruction o) { checkTop(o,Type.DOUBLE); } + public void visitD2I(Instruction o) { checkTop(o,Type.DOUBLE); } + public void visitD2L(Instruction o) { checkTop(o,Type.DOUBLE); } + + public void visitDADD(Instruction o){ + checkTop(o,Type.DOUBLE); + if (stack().peek(1) != Type.DOUBLE){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); + } + } + + public void visitDALOAD(Instruction o){ + indexOfInt(o, stack().peek()); + if (stack().peek(1) == Type.NULL){ + return; + } + if (! (stack().peek(1) instanceof ArrayType)){ + constraintViolated(o, "Stack next-to-top must be of type double[] but is '"+stack().peek(1)+"'."); + } + Type t = ((ArrayType) (stack().peek(1))).getBasicType(); + if (t != Type.DOUBLE){ + constraintViolated(o, "Stack next-to-top must be of type double[] but is '"+stack().peek(1)+"'."); + } + } + + public void visitDASTORE(Instruction o){ + if (stack().peek() != Type.DOUBLE){ + constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'."); + } + indexOfInt(o, stack().peek(1)); + if (stack().peek(2) == Type.NULL){ + return; + } + if (! (stack().peek(2) instanceof ArrayType)){ + constraintViolated(o, "Stack next-to-next-to-top must be of type double[] but is '"+stack().peek(2)+"'."); + } + Type t = ((ArrayType) (stack().peek(2))).getBasicType(); + if (t != Type.DOUBLE){ + constraintViolated(o, "Stack next-to-next-to-top must be of type double[] but is '"+stack().peek(2)+"'."); + } + } + + public void visitDCMPG(Instruction o){ + checkTop(o,Type.DOUBLE); + if (stack().peek(1) != Type.DOUBLE){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); + } + } + + public void visitDCMPL(Instruction o){ + checkTop(o,Type.DOUBLE); + if (stack().peek(1) != Type.DOUBLE){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); + } + } + + public void visitDCONST(Instruction o){ + // There's nothing to be done here. + } + + public void visitDDIV(Instruction o){ + checkTop(o,Type.DOUBLE); + if (stack().peek(1) != Type.DOUBLE){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); + } + } + + public void visitDLOAD(Instruction o){ + //visitLoadInstruction(LoadInstruction) is called before. + + // Nothing else needs to be done here. + } + + public void visitDMUL(Instruction o){ + checkTop(o,Type.DOUBLE); + if (stack().peek(1) != Type.DOUBLE){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); + } + } + + public void visitDNEG(Instruction o){ + checkTop(o,Type.DOUBLE); + } + + public void visitDREM(Instruction o){ + checkTop(o,Type.DOUBLE); + if (stack().peek(1) != Type.DOUBLE){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); + } + } + + private void checkTop(Instruction o,Type t) { + if (stack().peek()!=t) + constraintViolated(o, "The value at the stack top is not of type '"+t+"', but of type '"+stack().peek()+"'."); + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitDRETURN(Instruction o){ + checkTop(o,Type.DOUBLE); + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitDSTORE(Instruction o){ + //visitStoreInstruction(StoreInstruction) is called before. + + // Nothing else needs to be done here. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitDSUB(Instruction o){ + if (stack().peek() != Type.DOUBLE){ + constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'."); + } + if (stack().peek(1) != Type.DOUBLE){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitDUP(Instruction o){ + if (stack().peek().getSize() != 1){ + constraintViolated(o, "Won't DUP type on stack top '"+stack().peek()+"' because it must occupy exactly one slot, not '"+stack().peek().getSize()+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitDUP_X1(Instruction o){ + if (stack().peek().getSize() != 1){ + constraintViolated(o, "Type on stack top '"+stack().peek()+"' should occupy exactly one slot, not '"+stack().peek().getSize()+"'."); + } + if (stack().peek(1).getSize() != 1){ + constraintViolated(o, "Type on stack next-to-top '"+stack().peek(1)+"' should occupy exactly one slot, not '"+stack().peek(1).getSize()+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitDUP_X2(Instruction o){ + if (stack().peek().getSize() != 1){ + constraintViolated(o, "Stack top type must be of size 1, but is '"+stack().peek()+"' of size '"+stack().peek().getSize()+"'."); + } + if (stack().peek(1).getSize() == 2){ + return; // Form 2, okay. + } + else{ //stack().peek(1).getSize == 1. + if (stack().peek(2).getSize() != 1){ + constraintViolated(o, "If stack top's size is 1 and stack next-to-top's size is 1, stack next-to-next-to-top's size must also be 1, but is: '"+stack().peek(2)+"' of size '"+stack().peek(2).getSize()+"'."); + } + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitDUP2(Instruction o){ + if (stack().peek().getSize() == 2){ + return; // Form 2, okay. + } + else{ //stack().peek().getSize() == 1. + if (stack().peek(1).getSize() != 1){ + constraintViolated(o, "If stack top's size is 1, then stack next-to-top's size must also be 1. But it is '"+stack().peek(1)+"' of size '"+stack().peek(1).getSize()+"'."); + } + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitDUP2_X1(Instruction o){ + if (stack().peek().getSize() == 2){ + if (stack().peek(1).getSize() != 1){ + constraintViolated(o, "If stack top's size is 2, then stack next-to-top's size must be 1. But it is '"+stack().peek(1)+"' of size '"+stack().peek(1).getSize()+"'."); + } + else{ + return; // Form 2 + } + } + else{ // stack top is of size 1 + if ( stack().peek(1).getSize() != 1 ){ + constraintViolated(o, "If stack top's size is 1, then stack next-to-top's size must also be 1. But it is '"+stack().peek(1)+"' of size '"+stack().peek(1).getSize()+"'."); + } + if ( stack().peek(2).getSize() != 1 ){ + constraintViolated(o, "If stack top's size is 1, then stack next-to-next-to-top's size must also be 1. But it is '"+stack().peek(2)+"' of size '"+stack().peek(2).getSize()+"'."); + } + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitDUP2_X2(Instruction o){ + + if (stack().peek(0).getSize() == 2){ + if (stack().peek(1).getSize() == 2){ + return; // Form 4 + } + else{// stack top size is 2, next-to-top's size is 1 + if ( stack().peek(2).getSize() != 1 ){ + constraintViolated(o, "If stack top's size is 2 and stack-next-to-top's size is 1, then stack next-to-next-to-top's size must also be 1. But it is '"+stack().peek(2)+"' of size '"+stack().peek(2).getSize()+"'."); + } + else{ + return; // Form 2 + } + } + } + else{// stack top is of size 1 + if (stack().peek(1).getSize() == 1){ + if ( stack().peek(2).getSize() == 2 ){ + return; // Form 3 + } + else{ + if ( stack().peek(3).getSize() == 1){ + return; // Form 1 + } + } + } + } + constraintViolated(o, "The operand sizes on the stack do not match any of the four forms of usage of this instruction."); + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitF2D(Instruction o){ + if (stack().peek() != Type.FLOAT){ + constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'."); + } + } + + public void visitF2I(Instruction o){ + checkTop(o,Type.FLOAT); + } + + public void visitF2L(Instruction o){ + checkTop(o,Type.FLOAT); + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFADD(Instruction o){ + checkTop(o,Type.FLOAT); + if (stack().peek(1) != Type.FLOAT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFALOAD(Instruction o){ + indexOfInt(o, stack().peek()); + if (stack().peek(1) == Type.NULL){ + return; + } + if (! (stack().peek(1) instanceof ArrayType)){ + constraintViolated(o, "Stack next-to-top must be of type float[] but is '"+stack().peek(1)+"'."); + } + Type t = ((ArrayType) (stack().peek(1))).getBasicType(); + if (t != Type.FLOAT){ + constraintViolated(o, "Stack next-to-top must be of type float[] but is '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFASTORE(Instruction o){ + checkTop(o,Type.FLOAT); + indexOfInt(o, stack().peek(1)); + if (stack().peek(2) == Type.NULL){ + return; + } + if (! (stack().peek(2) instanceof ArrayType)){ + constraintViolated(o, "Stack next-to-next-to-top must be of type float[] but is '"+stack().peek(2)+"'."); + } + Type t = ((ArrayType) (stack().peek(2))).getBasicType(); + if (t != Type.FLOAT){ + constraintViolated(o, "Stack next-to-next-to-top must be of type float[] but is '"+stack().peek(2)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFCMPG(Instruction o){ + checkTop(o,Type.FLOAT); + if (stack().peek(1) != Type.FLOAT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFCMPL(Instruction o){ + checkTop(o,Type.FLOAT); + if (stack().peek(1) != Type.FLOAT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFCONST(Instruction o){ + // nothing to do here. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFDIV(Instruction o){ + checkTop(o,Type.FLOAT); + if (stack().peek(1) != Type.FLOAT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFLOAD(Instruction o){ + //visitLoadInstruction(LoadInstruction) is called before. + + // Nothing else needs to be done here. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFMUL(Instruction o){ + checkTop(o,Type.FLOAT); + if (stack().peek(1) != Type.FLOAT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFNEG(Instruction o){ + checkTop(o,Type.FLOAT); + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFREM(Instruction o){ + checkTop(o,Type.FLOAT); + if (stack().peek(1) != Type.FLOAT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFRETURN(Instruction o){ + checkTop(o,Type.FLOAT); + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFSTORE(Instruction o){ + //visitStoreInstruction(StoreInstruction) is called before. + + // Nothing else needs to be done here. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitFSUB(Instruction o){ + if (stack().peek() != Type.FLOAT){ + constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'."); + } + if (stack().peek(1) != Type.FLOAT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitGETFIELD(FieldInstruction o){ + Type objectref = stack().peek(); + if (! ( (objectref instanceof ObjectType) || (objectref == Type.NULL) ) ){ + constraintViolated(o, "Stack top should be an object reference that's not an array reference, but is '"+objectref+"'."); + } + + String field_name = o.getFieldName(cpg); + + JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName()); + Field[] fields = jc.getFields(); + Field f = null; + for (int i=0; i=0; i--){ + Type fromStack = stack().peek( (nargs-1) - i ); // 0 to nargs-1 + Type fromDesc = argtypes[i]; + if (fromDesc == Type.BOOLEAN || + fromDesc == Type.BYTE || + fromDesc == Type.CHAR || + fromDesc == Type.SHORT){ + fromDesc = Type.INT; + } + if (! fromStack.equals(fromDesc)){ + if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){ + //ReferenceType rFromStack = (ReferenceType) fromStack; + //ReferenceType rFromDesc = (ReferenceType) fromDesc; + // TODO: This can only be checked when using Staerk-et-al's "set of object types" + // instead of a "wider cast object type" created during verification. + //if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){ + // constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible)."); + //} + } + else{ + constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack."); + } + } + } + + Type objref = stack().peek(nargs); + if (objref == Type.NULL){ + return; + } + if (! (objref instanceof ReferenceType) ){ + constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '"+objref+"'."); + } + referenceTypeIsInitialized(o, (ReferenceType) objref); + if (!(objref instanceof ObjectType)){ + if (!(objref instanceof ArrayType)){ + constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '"+objref+"'."); // could be a ReturnaddressType + } + else{ + objref = GENERIC_ARRAY; + } + } + + // String objref_classname = ((ObjectType) objref).getClassName(); + // String theInterface = o.getClassName(cpg); + // TODO: This can only be checked if we're using Staerk-et-al's "set of object types" + // instead of "wider cast object types" generated during verification. + //if ( ! Repository.implementationOf(objref_classname, theInterface) ){ + // constraintViolated(o, "The 'objref' item '"+objref+"' does not implement '"+theInterface+"' as expected."); + //} + + int counted_count = 1; // 1 for the objectref + for (int i=0; i=0; i--){ + Type fromStack = stack().peek( (nargs-1) - i ); // 0 to nargs-1 + Type fromDesc = argtypes[i]; + if (fromDesc == Type.BOOLEAN || + fromDesc == Type.BYTE || + fromDesc == Type.CHAR || + fromDesc == Type.SHORT){ + fromDesc = Type.INT; + } + if (! fromStack.equals(fromDesc)){ + if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){ + ReferenceType rFromStack = (ReferenceType) fromStack; + ReferenceType rFromDesc = (ReferenceType) fromDesc; + // TODO: This can only be checked using Staerk-et-al's "set of object types", not + // using a "wider cast object type". + if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){ + constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible)."); + } + } + else{ + constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack."); + } + } + } + + Type objref = stack().peek(nargs); + if (objref == Type.NULL){ + return; + } + if (! (objref instanceof ReferenceType) ){ + constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '"+objref+"'."); + } + String objref_classname = null; + if ( !(o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME))){ + referenceTypeIsInitialized(o, (ReferenceType) objref); + if (!(objref instanceof ObjectType)){ + if (!(objref instanceof ArrayType)){ + constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '"+objref+"'."); // could be a ReturnaddressType + } + else{ + objref = GENERIC_ARRAY; + } + } + + objref_classname = ((ObjectType) objref).getClassName(); + } + else{ + if (!(objref instanceof UninitializedObjectType)){ + constraintViolated(o, "Expecting an UninitializedObjectType as 'objectref' on the stack, not a '"+objref+"'. Otherwise, you couldn't invoke a method since an array has no methods (not to speak of a return address)."); + } + objref_classname = ((UninitializedObjectType) objref).getInitialized().getClassName(); + } + + + String theClass = o.getClassName(cpg); + if ( ! Repository.instanceOf(objref_classname, theClass) ){ + constraintViolated(o, "The 'objref' item '"+objref+"' does not implement '"+theClass+"' as expected."); + } + + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitINVOKESTATIC(InvokeInstruction o){ + // Method is not native, otherwise pass 3 would not happen. + + Type t = o.getType(cpg); + if (t instanceof ObjectType){ + String name = ((ObjectType)t).getClassName(); + Verifier v = VerifierFactory.getVerifier( name ); + VerificationResult vr = v.doPass2(); + if (vr.getStatus() != VerificationResult.VERIFIED_OK){ + constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'."); + } + } + + Type[] argtypes = o.getArgumentTypes(cpg); + int nargs = argtypes.length; + + for (int i=nargs-1; i>=0; i--){ + Type fromStack = stack().peek( (nargs-1) - i ); // 0 to nargs-1 + Type fromDesc = argtypes[i]; + if (fromDesc == Type.BOOLEAN || + fromDesc == Type.BYTE || + fromDesc == Type.CHAR || + fromDesc == Type.SHORT){ + fromDesc = Type.INT; + } + if (! fromStack.equals(fromDesc)){ + if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){ + ReferenceType rFromStack = (ReferenceType) fromStack; + ReferenceType rFromDesc = (ReferenceType) fromDesc; + // TODO: This check can possibly only be done using Staerk-et-al's "set of object types" + // instead of a "wider cast object type" created during verification. + if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){ + constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible)."); + } + } + else{ + constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack."); + } + } + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitINVOKEVIRTUAL(InvokeInstruction o){ + // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o). + + Type t = o.getType(cpg); + if (t instanceof ObjectType){ + String name = ((ObjectType)t).getClassName(); + Verifier v = VerifierFactory.getVerifier( name ); + VerificationResult vr = v.doPass2(); + if (vr.getStatus() != VerificationResult.VERIFIED_OK){ + constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'."); + } + } + + + Type[] argtypes = o.getArgumentTypes(cpg); + int nargs = argtypes.length; + + for (int i=nargs-1; i>=0; i--){ + Type fromStack = stack().peek( (nargs-1) - i ); // 0 to nargs-1 + Type fromDesc = argtypes[i]; + if (fromDesc == Type.BOOLEAN || + fromDesc == Type.BYTE || + fromDesc == Type.CHAR || + fromDesc == Type.SHORT){ + fromDesc = Type.INT; + } + if (! fromStack.equals(fromDesc)){ + if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){ + ReferenceType rFromStack = (ReferenceType) fromStack; + ReferenceType rFromDesc = (ReferenceType) fromDesc; + // TODO: This can possibly only be checked when using Staerk-et-al's "set of object types" instead + // of a single "wider cast object type" created during verification. + if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){ + constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible)."); + } + } + else{ + constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack."); + } + } + } + + Type objref = stack().peek(nargs); + if (objref == Type.NULL){ + return; + } + if (! (objref instanceof ReferenceType) ){ + constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '"+objref+"'."); + } + referenceTypeIsInitialized(o, (ReferenceType) objref); + if (!(objref instanceof ObjectType)){ + if (!(objref instanceof ArrayType)){ + constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '"+objref+"'."); // could be a ReturnaddressType + } + else{ + objref = GENERIC_ARRAY; + } + } + + String objref_classname = ((ObjectType) objref).getClassName(); + + String theClass = o.getClassName(cpg); + + if ( ! Repository.instanceOf(objref_classname, theClass) ){ + constraintViolated(o, "The 'objref' item '"+objref+"' does not implement '"+theClass+"' as expected."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitIOR(Instruction o){ + if (stack().peek() != Type.INT){ + constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'."); + } + if (stack().peek(1) != Type.INT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitIREM(Instruction o){ + if (stack().peek() != Type.INT){ + constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'."); + } + if (stack().peek(1) != Type.INT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitIRETURN(Instruction o){ + if (stack().peek() != Type.INT){ + constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitISHL(Instruction o){ + checkTop(o,Type.INT); + if (stack().peek(1) != Type.INT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitISHR(Instruction o){ + checkTop(o,Type.INT); + if (stack().peek(1) != Type.INT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitISTORE(Instruction o){ + //visitStoreInstruction(StoreInstruction) is called before. + + // Nothing else needs to be done here. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitISUB(Instruction o){ + checkTop(o,Type.INT); + if (stack().peek(1) != Type.INT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitIUSHR(Instruction o){ + checkTop(o,Type.INT); + if (stack().peek(1) != Type.INT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitIXOR(Instruction o){ + if (stack().peek() != Type.INT){ + constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'."); + } + if (stack().peek(1) != Type.INT){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitJSR(InstructionBranch o){ + // nothing to do here. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitJSR_W(InstructionBranch o){ + // nothing to do here. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitL2D(Instruction o){ + if (stack().peek() != Type.LONG){ + constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitL2F(Instruction o){ + if (stack().peek() != Type.LONG){ + constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitL2I(Instruction o){ + if (stack().peek() != Type.LONG){ + constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLADD(Instruction o){ + if (stack().peek() != Type.LONG){ + constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); + } + if (stack().peek(1) != Type.LONG){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLALOAD(Instruction o){ + indexOfInt(o, stack().peek()); + if (stack().peek(1) == Type.NULL){ + return; + } + if (! (stack().peek(1) instanceof ArrayType)){ + constraintViolated(o, "Stack next-to-top must be of type long[] but is '"+stack().peek(1)+"'."); + } + Type t = ((ArrayType) (stack().peek(1))).getBasicType(); + if (t != Type.LONG){ + constraintViolated(o, "Stack next-to-top must be of type long[] but is '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLAND(Instruction o){ + if (stack().peek() != Type.LONG){ + constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); + } + if (stack().peek(1) != Type.LONG){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLASTORE(Instruction o){ + if (stack().peek() != Type.LONG){ + constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); + } + indexOfInt(o, stack().peek(1)); + if (stack().peek(2) == Type.NULL){ + return; + } + if (! (stack().peek(2) instanceof ArrayType)){ + constraintViolated(o, "Stack next-to-next-to-top must be of type long[] but is '"+stack().peek(2)+"'."); + } + Type t = ((ArrayType) (stack().peek(2))).getBasicType(); + if (t != Type.LONG){ + constraintViolated(o, "Stack next-to-next-to-top must be of type long[] but is '"+stack().peek(2)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLCMP(Instruction o){ + if (stack().peek() != Type.LONG){ + constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); + } + if (stack().peek(1) != Type.LONG){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLCONST(Instruction o){ + // Nothing to do here. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLDC(Instruction o){ + // visitCPInstruction is called first. + + Constant c = cpg.getConstant(o.getIndex()); + if (! ( ( c instanceof ConstantInteger) || + ( c instanceof ConstantFloat ) || + ( c instanceof ConstantString ) ) ){ + constraintViolated(o, "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String, but is '"+c+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLDC_W(Instruction o){ + // visitCPInstruction is called first. + + Constant c = cpg.getConstant(o.getIndex()); + if (! ( ( c instanceof ConstantInteger) || + ( c instanceof ConstantFloat ) || + ( c instanceof ConstantString ) ) ){ + constraintViolated(o, "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String, but is '"+c+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLDC2_W(Instruction o){ + // visitCPInstruction is called first. + + Constant c = cpg.getConstant(o.getIndex()); + if (! ( ( c instanceof ConstantLong) || + ( c instanceof ConstantDouble ) ) ){ + constraintViolated(o, "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String, but is '"+c+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLDIV(Instruction o){ + if (stack().peek() != Type.LONG){ + constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); + } + if (stack().peek(1) != Type.LONG){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLLOAD(Instruction o){ + //visitLoadInstruction(LoadInstruction) is called before. + + // Nothing else needs to be done here. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLMUL(Instruction o){ + if (stack().peek() != Type.LONG){ + constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); + } + if (stack().peek(1) != Type.LONG){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); + } + } + + public void visitLNEG(Instruction o){ + checkTop(o,Type.LONG); + } + + public void visitLOOKUPSWITCH(LOOKUPSWITCH o){ + checkTop(o,Type.INT); + // See also pass 3a. + } + + public void visitLOR(Instruction o){ + if (stack().peek() != Type.LONG){ + constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'."); + } + if (stack().peek(1) != Type.LONG){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); + } + } + + public void visitLREM(Instruction o){ + checkTop(o,Type.LONG); + if (stack().peek(1) != Type.LONG){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); + } + } + + public void visitLRETURN(Instruction o) { checkTop(o,Type.LONG); } + public void visitLSHL(Instruction o){ + checkTop(o,Type.INT); + if (stack().peek(1) != Type.LONG){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLSHR(Instruction o){ + if (stack().peek() != Type.INT){ + constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'."); + } + if (stack().peek(1) != Type.LONG){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLSTORE(Instruction o){ + //visitStoreInstruction(StoreInstruction) is called before. + + // Nothing else needs to be done here. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLSUB(Instruction o){ + checkTop(o,Type.LONG); + if (stack().peek(1) != Type.LONG){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLUSHR(Instruction o){ + checkTop(o,Type.INT); + if (stack().peek(1) != Type.LONG){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitLXOR(Instruction o){ + checkTop(o,Type.LONG); + if (stack().peek(1) != Type.LONG){ + constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitMONITORENTER(Instruction o){ + if (! ((stack().peek()) instanceof ReferenceType)){ + constraintViolated(o, "The stack top should be of a ReferenceType, but is '"+stack().peek()+"'."); + } + referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) ); + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitMONITOREXIT(Instruction o){ + if (! ((stack().peek()) instanceof ReferenceType)){ + constraintViolated(o, "The stack top should be of a ReferenceType, but is '"+stack().peek()+"'."); + } + referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) ); + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitMULTIANEWARRAY(MULTIANEWARRAY o){ + int dimensions = o.getDimensions(); + // Dimensions argument is okay: see Pass 3a. + for (int i=0; i, see Pass 3a. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitRET(RET o){ + if (! (locals().get(o.getIndex()) instanceof ReturnaddressType)){ + constraintViolated(o, "Expecting a ReturnaddressType in local variable "+o.getIndex()+"."); + } + if (locals().get(o.getIndex()) == ReturnaddressType.NO_TARGET){ + throw new AssertionViolatedException("Oops: RET expecting a target!"); + } + // Other constraints such as non-allowed overlapping subroutines are enforced + // while building the Subroutines data structure. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitRETURN(Instruction o){ + if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)){// If we leave an method + if ((Frame._this != null) && (!(mg.getClassName().equals(Type.OBJECT.getClassName()))) ) { + constraintViolated(o, "Leaving a constructor that itself did not call a constructor."); + } + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitSALOAD(Instruction o){ + indexOfInt(o, stack().peek()); + if (stack().peek(1) == Type.NULL){ + return; + } + if (! (stack().peek(1) instanceof ArrayType)){ + constraintViolated(o, "Stack next-to-top must be of type short[] but is '"+stack().peek(1)+"'."); + } + Type t = ((ArrayType) (stack().peek(1))).getBasicType(); + if (t != Type.SHORT){ + constraintViolated(o, "Stack next-to-top must be of type short[] but is '"+stack().peek(1)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitSASTORE(Instruction o){ + if (stack().peek() != Type.INT){ + constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'."); + } + indexOfInt(o, stack().peek(1)); + if (stack().peek(2) == Type.NULL){ + return; + } + if (! (stack().peek(2) instanceof ArrayType)){ + constraintViolated(o, "Stack next-to-next-to-top must be of type short[] but is '"+stack().peek(2)+"'."); + } + Type t = ((ArrayType) (stack().peek(2))).getBasicType(); + if (t != Type.SHORT){ + constraintViolated(o, "Stack next-to-next-to-top must be of type short[] but is '"+stack().peek(2)+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitSIPUSH(Instruction o){ + // nothing to do here. Generic visitXXX() methods did the trick before. + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitSWAP(Instruction o){ + if (stack().peek().getSize() != 1){ + constraintViolated(o, "The value at the stack top is not of size '1', but of size '"+stack().peek().getSize()+"'."); + } + if (stack().peek(1).getSize() != 1){ + constraintViolated(o, "The value at the stack next-to-top is not of size '1', but of size '"+stack().peek(1).getSize()+"'."); + } + } + + /** + * Ensures the specific preconditions of the said instruction. + */ + public void visitTABLESWITCH(TABLESWITCH o){ + indexOfInt(o, stack().peek()); + // See Pass 3a. + } + +} + diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/InstructionContext.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/InstructionContext.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/InstructionContext.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/InstructionContext.java index b0c3fd08a..8e7566a12 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/InstructionContext.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/InstructionContext.java @@ -1,141 +1,141 @@ -package org.aspectj.apache.bcel.verifier.structurals; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.ArrayList; - -import org.aspectj.apache.bcel.generic.InstructionHandle; - -/** - * An InstructionContext offers convenient access - * to information like control flow successors and - * such. - * - * @version $Id: InstructionContext.java,v 1.4.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public interface InstructionContext{ - - /** - * The getTag and setTag methods may be used for - * temporary flagging, such as graph colouring. - * Nothing in the InstructionContext object depends - * on the value of the tag. JustIce does not use it. - * - * @see #setTag(int tag) - */ - public int getTag(); - - /** - * The getTag and setTag methods may be used for - * temporary flagging, such as graph colouring. - * Nothing in the InstructionContext object depends - * on the value of the tag. JustIce does not use it. - * - * @see #getTag() - */ - public void setTag(int tag); - - /** - * This method symbolically executes the Instruction - * held in the InstructionContext. - * It "merges in" the incoming execution frame situation - * (see The Java Virtual Machine Specification, 2nd - * edition, page 146). - * By so doing, the outgoing execution frame situation - * is calculated. - * - * This method is JustIce-specific and is usually of - * no sense for users of the ControlFlowGraph class. - * They should use getInstruction().accept(Visitor), - * possibly in conjunction with the ExecutionVisitor. - * - * - * @see ControlFlowGraph - * @see ExecutionVisitor - * @see #getOutFrame(ArrayList) - * @return true - if and only if the "outgoing" frame situation - * changed from the one before execute()ing. - */ - boolean execute(Frame inFrame, ArrayList executionPredecessors, InstConstraintVisitor icv, ExecutionVisitor ev); - - /** - * This method returns the outgoing execution frame situation; - * therefore it has to be calculated by execute(Frame, ArrayList) - * first. - * - * @see #execute(Frame, ArrayList, InstConstraintVisitor, ExecutionVisitor) - */ - Frame getOutFrame(ArrayList executionPredecessors); - - /** - * Returns the InstructionHandle this InstructionContext is wrapped around. - * - * @return The InstructionHandle this InstructionContext is wrapped around. - */ - InstructionHandle getInstruction(); - - /** - * Returns the usual control flow successors. - * @see #getExceptionHandlers() - */ - InstructionContext[] getSuccessors(); - - /** - * Returns the exception handlers that protect this instruction. - * They are special control flow successors. - */ - ExceptionHandler[] getExceptionHandlers(); -} +package org.aspectj.apache.bcel.verifier.structurals; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.util.ArrayList; + +import org.aspectj.apache.bcel.generic.InstructionHandle; + +/** + * An InstructionContext offers convenient access + * to information like control flow successors and + * such. + * + * @version $Id: InstructionContext.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public interface InstructionContext{ + + /** + * The getTag and setTag methods may be used for + * temporary flagging, such as graph colouring. + * Nothing in the InstructionContext object depends + * on the value of the tag. JustIce does not use it. + * + * @see #setTag(int tag) + */ + public int getTag(); + + /** + * The getTag and setTag methods may be used for + * temporary flagging, such as graph colouring. + * Nothing in the InstructionContext object depends + * on the value of the tag. JustIce does not use it. + * + * @see #getTag() + */ + public void setTag(int tag); + + /** + * This method symbolically executes the Instruction + * held in the InstructionContext. + * It "merges in" the incoming execution frame situation + * (see The Java Virtual Machine Specification, 2nd + * edition, page 146). + * By so doing, the outgoing execution frame situation + * is calculated. + * + * This method is JustIce-specific and is usually of + * no sense for users of the ControlFlowGraph class. + * They should use getInstruction().accept(Visitor), + * possibly in conjunction with the ExecutionVisitor. + * + * + * @see ControlFlowGraph + * @see ExecutionVisitor + * @see #getOutFrame(ArrayList) + * @return true - if and only if the "outgoing" frame situation + * changed from the one before execute()ing. + */ + boolean execute(Frame inFrame, ArrayList executionPredecessors, InstConstraintVisitor icv, ExecutionVisitor ev); + + /** + * This method returns the outgoing execution frame situation; + * therefore it has to be calculated by execute(Frame, ArrayList) + * first. + * + * @see #execute(Frame, ArrayList, InstConstraintVisitor, ExecutionVisitor) + */ + Frame getOutFrame(ArrayList executionPredecessors); + + /** + * Returns the InstructionHandle this InstructionContext is wrapped around. + * + * @return The InstructionHandle this InstructionContext is wrapped around. + */ + InstructionHandle getInstruction(); + + /** + * Returns the usual control flow successors. + * @see #getExceptionHandlers() + */ + InstructionContext[] getSuccessors(); + + /** + * Returns the exception handlers that protect this instruction. + * They are special control flow successors. + */ + ExceptionHandler[] getExceptionHandlers(); +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/LocalVariables.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/LocalVariables.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/LocalVariables.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/LocalVariables.java index 11a8e4978..2d1bd1f89 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/LocalVariables.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/LocalVariables.java @@ -1,229 +1,229 @@ -package org.aspectj.apache.bcel.verifier.structurals; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.generic.Type; -import org.aspectj.apache.bcel.generic.ReferenceType; -import org.aspectj.apache.bcel.verifier.exc.*; - -/** - * This class implements an array of local variables used for symbolic JVM - * simulation. - * - * @version $Id: LocalVariables.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public class LocalVariables{ - /** The Type[] containing the local variable slots. */ - private Type[] locals; - - /** - * Creates a new LocalVariables object. - */ - public LocalVariables(int maxLocals){ - locals = new Type[maxLocals]; - for (int i=0; i. + */ + +import org.aspectj.apache.bcel.generic.Type; +import org.aspectj.apache.bcel.generic.ReferenceType; +import org.aspectj.apache.bcel.verifier.exc.*; + +/** + * This class implements an array of local variables used for symbolic JVM + * simulation. + * + * @version $Id: LocalVariables.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class LocalVariables{ + /** The Type[] containing the local variable slots. */ + private Type[] locals; + + /** + * Creates a new LocalVariables object. + */ + public LocalVariables(int maxLocals){ + locals = new Type[maxLocals]; + for (int i=0; i. - */ - -import org.aspectj.apache.bcel.generic.*; -import org.aspectj.apache.bcel.verifier.exc.*; -import java.util.*; - -/** - * This class implements a stack used for symbolic JVM stack simulation. - * [It's used an an operand stack substitute.] - * Elements of this stack are org.aspectj.apache.bcel.generic.Type objects. - * - * @version $Id: OperandStack.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public class OperandStack{ - - /** We hold the stack information here. */ - private ArrayList stack = new ArrayList(); - - /** The maximum number of stack slots this OperandStack instance may hold. */ - private int maxStack; - - /** - * Creates an empty stack with a maximum of maxStack slots. - */ - public OperandStack(int maxStack){ - this.maxStack = maxStack; - } - - /** - * Creates an otherwise empty stack with a maximum of maxStack slots and - * the ObjectType 'obj' at the top. - */ - public OperandStack(int maxStack, ObjectType obj){ - this.maxStack = maxStack; - this.push(obj); - } - /** - * Returns a deep copy of this object; that means, the clone operates - * on a new stack. However, the Type objects on the stack are - * shared. - */ - protected Object clone(){ - OperandStack newstack = new OperandStack(this.maxStack); - newstack.stack = (ArrayList) this.stack.clone(); - return newstack; - } - - /** - * Clears the stack. - */ - public void clear(){ - stack = new ArrayList(); - } - - /** - * Returns true if and only if this OperandStack - * equals another, meaning equal lengths and equal - * objects on the stacks. - */ - public boolean equals(Object o){ - if (!(o instanceof OperandStack)) return false; - OperandStack s = (OperandStack) o; - return this.stack.equals(s.stack); - } - - /** - * Returns a (typed!) clone of this. - * - * @see #clone() - */ - public OperandStack getClone(){ - return (OperandStack) this.clone(); - } - - /** - * Returns true IFF this OperandStack is empty. - */ - public boolean isEmpty(){ - return stack.isEmpty(); - } - - /** - * Returns the number of stack slots this stack can hold. - */ - public int maxStack(){ - return this.maxStack; - } - - /** - * Returns the element on top of the stack. The element is not popped off the stack! - */ - public Type peek(){ - return peek(0); - } - - /** - * Returns the element that's i elements below the top element; that means, - * iff i==0 the top element is returned. The element is not popped off the stack! - */ - public Type peek(int i){ - return (Type) stack.get(size()-i-1); - } - - /** - * Returns the element on top of the stack. The element is popped off the stack. - */ - public Type pop(){ - Type e = (Type) stack.remove(size()-1); - return e; - } - - /** - * Pops i elements off the stack. ALWAYS RETURNS "null"!!! - */ - public Type pop(int i){ - for (int j=0; j= maxStack){ - throw new AssertionViolatedException("OperandStack too small, should have thrown proper Exception elsewhere. Stack: "+this); - } - stack.add(type); - } - - /** - * Returns the size of this OperandStack; that means, how many Type objects there are. - */ - int size(){ - return stack.size(); - } - - /** - * Returns the number of stack slots used. - * @see #maxStack() - */ - public int slotsUsed(){ - /* XXX change this to a better implementation using a variable - that keeps track of the actual slotsUsed()-value monitoring - all push()es and pop()s. - */ - int slots = 0; - for (int i=0; i. + */ + +import org.aspectj.apache.bcel.generic.*; +import org.aspectj.apache.bcel.verifier.exc.*; +import java.util.*; + +/** + * This class implements a stack used for symbolic JVM stack simulation. + * [It's used an an operand stack substitute.] + * Elements of this stack are org.aspectj.apache.bcel.generic.Type objects. + * + * @version $Id: OperandStack.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class OperandStack{ + + /** We hold the stack information here. */ + private ArrayList stack = new ArrayList(); + + /** The maximum number of stack slots this OperandStack instance may hold. */ + private int maxStack; + + /** + * Creates an empty stack with a maximum of maxStack slots. + */ + public OperandStack(int maxStack){ + this.maxStack = maxStack; + } + + /** + * Creates an otherwise empty stack with a maximum of maxStack slots and + * the ObjectType 'obj' at the top. + */ + public OperandStack(int maxStack, ObjectType obj){ + this.maxStack = maxStack; + this.push(obj); + } + /** + * Returns a deep copy of this object; that means, the clone operates + * on a new stack. However, the Type objects on the stack are + * shared. + */ + protected Object clone(){ + OperandStack newstack = new OperandStack(this.maxStack); + newstack.stack = (ArrayList) this.stack.clone(); + return newstack; + } + + /** + * Clears the stack. + */ + public void clear(){ + stack = new ArrayList(); + } + + /** + * Returns true if and only if this OperandStack + * equals another, meaning equal lengths and equal + * objects on the stacks. + */ + public boolean equals(Object o){ + if (!(o instanceof OperandStack)) return false; + OperandStack s = (OperandStack) o; + return this.stack.equals(s.stack); + } + + /** + * Returns a (typed!) clone of this. + * + * @see #clone() + */ + public OperandStack getClone(){ + return (OperandStack) this.clone(); + } + + /** + * Returns true IFF this OperandStack is empty. + */ + public boolean isEmpty(){ + return stack.isEmpty(); + } + + /** + * Returns the number of stack slots this stack can hold. + */ + public int maxStack(){ + return this.maxStack; + } + + /** + * Returns the element on top of the stack. The element is not popped off the stack! + */ + public Type peek(){ + return peek(0); + } + + /** + * Returns the element that's i elements below the top element; that means, + * iff i==0 the top element is returned. The element is not popped off the stack! + */ + public Type peek(int i){ + return (Type) stack.get(size()-i-1); + } + + /** + * Returns the element on top of the stack. The element is popped off the stack. + */ + public Type pop(){ + Type e = (Type) stack.remove(size()-1); + return e; + } + + /** + * Pops i elements off the stack. ALWAYS RETURNS "null"!!! + */ + public Type pop(int i){ + for (int j=0; j= maxStack){ + throw new AssertionViolatedException("OperandStack too small, should have thrown proper Exception elsewhere. Stack: "+this); + } + stack.add(type); + } + + /** + * Returns the size of this OperandStack; that means, how many Type objects there are. + */ + int size(){ + return stack.size(); + } + + /** + * Returns the number of stack slots used. + * @see #maxStack() + */ + public int slotsUsed(){ + /* XXX change this to a better implementation using a variable + that keeps track of the actual slotsUsed()-value monitoring + all push()es and pop()s. + */ + int slots = 0; + for (int i=0; i. - */ - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Random; -import java.util.Vector; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.generic.InstructionBranch; -import org.aspectj.apache.bcel.generic.InstructionHandle; -import org.aspectj.apache.bcel.generic.MethodGen; -import org.aspectj.apache.bcel.generic.ObjectType; -import org.aspectj.apache.bcel.generic.RET; -import org.aspectj.apache.bcel.generic.ReturnaddressType; -import org.aspectj.apache.bcel.generic.Type; -import org.aspectj.apache.bcel.verifier.PassVerifier; -import org.aspectj.apache.bcel.verifier.VerificationResult; -import org.aspectj.apache.bcel.verifier.Verifier; -import org.aspectj.apache.bcel.verifier.exc.AssertionViolatedException; -import org.aspectj.apache.bcel.verifier.exc.VerifierConstraintViolatedException; - -/** - * This PassVerifier verifies a method of class file according to pass 3, - * so-called structural verification as described in The Java Virtual Machine - * Specification, 2nd edition. - * More detailed information is to be found at the do_verify() method's - * documentation. - * - * @version $Id: Pass3bVerifier.java,v 1.5.8.2 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - * @see #do_verify() - */ - -public final class Pass3bVerifier extends PassVerifier{ - /* TODO: Throughout pass 3b, upper halves of LONG and DOUBLE - are represented by Type.UNKNOWN. This should be changed - in favour of LONG_Upper and DOUBLE_Upper as in pass 2. */ - - /** - * An InstructionContextQueue is a utility class that holds - * (InstructionContext, ArrayList) pairs in a Queue data structure. - * This is used to hold information about InstructionContext objects - * externally --- i.e. that information is not saved inside the - * InstructionContext object itself. This is useful to save the - * execution path of the symbolic execution of the - * Pass3bVerifier - this is not information - * that belongs into the InstructionContext object itself. - * Only at "execute()"ing - * time, an InstructionContext object will get the current information - * we have about its symbolic execution predecessors. - */ - private static final class InstructionContextQueue{ - private Vector ics = new Vector(); // Type: InstructionContext - private Vector ecs = new Vector(); // Type: ArrayList (of InstructionContext) - public void add(InstructionContext ic, ArrayList executionChain){ - ics.add(ic); - ecs.add(executionChain); - } - public boolean isEmpty(){ - return ics.isEmpty(); - } - public void remove(){ - this.remove(0); - } - public void remove(int i){ - ics.remove(i); - ecs.remove(i); - } - public InstructionContext getIC(int i){ - return (InstructionContext) ics.get(i); - } - public ArrayList getEC(int i){ - return (ArrayList) ecs.get(i); - } - public int size(){ - return ics.size(); - } - } // end Inner Class InstructionContextQueue - - /** In DEBUG mode, the verification algorithm is not randomized. */ - private static final boolean DEBUG = true; - - /** The Verifier that created this. */ - private Verifier myOwner; - - /** The method number to verify. */ - private int method_no; - - /** - * This class should only be instantiated by a Verifier. - * - * @see org.aspectj.apache.bcel.verifier.Verifier - */ - public Pass3bVerifier(Verifier owner, int method_no){ - myOwner = owner; - this.method_no = method_no; - } - - /** - * Whenever the outgoing frame - * situation of an InstructionContext changes, all its successors are - * put [back] into the queue [as if they were unvisited]. - * The proof of termination is about the existence of a - * fix point of frame merging. - */ - private void circulationPump(ControlFlowGraph cfg, InstructionContext start, Frame vanillaFrame, InstConstraintVisitor icv, ExecutionVisitor ev){ - final Random random = new Random(); - InstructionContextQueue icq = new InstructionContextQueue(); - - start.execute(vanillaFrame, new ArrayList(), icv, ev); // new ArrayList() <=> no Instruction was executed before - // => Top-Level routine (no jsr call before) - icq.add(start, new ArrayList()); - - // LOOP! - while (!icq.isEmpty()){ - InstructionContext u; - ArrayList ec; - if (!DEBUG){ - int r = random.nextInt(icq.size()); - u = icq.getIC(r); - ec = icq.getEC(r); - icq.remove(r); - } - else{ - u = icq.getIC(0); - ec = icq.getEC(0); - icq.remove(0); - } - - ArrayList oldchain = (ArrayList) (ec.clone()); - ArrayList newchain = (ArrayList) (ec.clone()); - newchain.add(u); - - if ((u.getInstruction().getInstruction()) instanceof RET){ -//System.err.println(u); - // We can only follow _one_ successor, the one after the - // JSR that was recently executed. - RET ret = (RET) (u.getInstruction().getInstruction()); - ReturnaddressType t = (ReturnaddressType) u.getOutFrame(oldchain).getLocals().get(ret.getIndex()); - InstructionContext theSuccessor = cfg.contextOf(t.getTarget()); - - // Sanity check - InstructionContext lastJSR = null; - int skip_jsr = 0; - for (int ss=oldchain.size()-1; ss >= 0; ss--){ - if (skip_jsr < 0){ - throw new AssertionViolatedException("More RET than JSR in execution chain?!"); - } -//System.err.println("+"+oldchain.get(ss)); - if (((InstructionContext) oldchain.get(ss)).getInstruction().getInstruction().isJsrInstruction()) { - if (skip_jsr == 0){ - lastJSR = (InstructionContext) oldchain.get(ss); - break; - } - else{ - skip_jsr--; - } - } - if (((InstructionContext) oldchain.get(ss)).getInstruction().getInstruction() instanceof RET){ - skip_jsr++; - } - } - if (lastJSR == null){ - throw new AssertionViolatedException("RET without a JSR before in ExecutionChain?! EC: '"+oldchain+"'."); - } - InstructionBranch jsr = (InstructionBranch) (lastJSR.getInstruction().getInstruction()); - if ( theSuccessor != (cfg.contextOf(jsr.physicalSuccessor())) ){ - throw new AssertionViolatedException("RET '"+u.getInstruction()+"' info inconsistent: jump back to '"+theSuccessor+"' or '"+cfg.contextOf(jsr.physicalSuccessor())+"'?"); - } - - if (theSuccessor.execute(u.getOutFrame(oldchain), newchain, icv, ev)){ - icq.add(theSuccessor, (ArrayList) newchain.clone()); - } - } - else{// "not a ret" - - // Normal successors. Add them to the queue of successors. - InstructionContext[] succs = u.getSuccessors(); - for (int s=0; s. + */ + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Random; +import java.util.Vector; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.Repository; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.generic.InstructionBranch; +import org.aspectj.apache.bcel.generic.InstructionHandle; +import org.aspectj.apache.bcel.generic.MethodGen; +import org.aspectj.apache.bcel.generic.ObjectType; +import org.aspectj.apache.bcel.generic.RET; +import org.aspectj.apache.bcel.generic.ReturnaddressType; +import org.aspectj.apache.bcel.generic.Type; +import org.aspectj.apache.bcel.verifier.PassVerifier; +import org.aspectj.apache.bcel.verifier.VerificationResult; +import org.aspectj.apache.bcel.verifier.Verifier; +import org.aspectj.apache.bcel.verifier.exc.AssertionViolatedException; +import org.aspectj.apache.bcel.verifier.exc.VerifierConstraintViolatedException; + +/** + * This PassVerifier verifies a method of class file according to pass 3, + * so-called structural verification as described in The Java Virtual Machine + * Specification, 2nd edition. + * More detailed information is to be found at the do_verify() method's + * documentation. + * + * @version $Id: Pass3bVerifier.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + * @see #do_verify() + */ + +public final class Pass3bVerifier extends PassVerifier{ + /* TODO: Throughout pass 3b, upper halves of LONG and DOUBLE + are represented by Type.UNKNOWN. This should be changed + in favour of LONG_Upper and DOUBLE_Upper as in pass 2. */ + + /** + * An InstructionContextQueue is a utility class that holds + * (InstructionContext, ArrayList) pairs in a Queue data structure. + * This is used to hold information about InstructionContext objects + * externally --- i.e. that information is not saved inside the + * InstructionContext object itself. This is useful to save the + * execution path of the symbolic execution of the + * Pass3bVerifier - this is not information + * that belongs into the InstructionContext object itself. + * Only at "execute()"ing + * time, an InstructionContext object will get the current information + * we have about its symbolic execution predecessors. + */ + private static final class InstructionContextQueue{ + private Vector ics = new Vector(); // Type: InstructionContext + private Vector ecs = new Vector(); // Type: ArrayList (of InstructionContext) + public void add(InstructionContext ic, ArrayList executionChain){ + ics.add(ic); + ecs.add(executionChain); + } + public boolean isEmpty(){ + return ics.isEmpty(); + } + public void remove(){ + this.remove(0); + } + public void remove(int i){ + ics.remove(i); + ecs.remove(i); + } + public InstructionContext getIC(int i){ + return (InstructionContext) ics.get(i); + } + public ArrayList getEC(int i){ + return (ArrayList) ecs.get(i); + } + public int size(){ + return ics.size(); + } + } // end Inner Class InstructionContextQueue + + /** In DEBUG mode, the verification algorithm is not randomized. */ + private static final boolean DEBUG = true; + + /** The Verifier that created this. */ + private Verifier myOwner; + + /** The method number to verify. */ + private int method_no; + + /** + * This class should only be instantiated by a Verifier. + * + * @see org.aspectj.apache.bcel.verifier.Verifier + */ + public Pass3bVerifier(Verifier owner, int method_no){ + myOwner = owner; + this.method_no = method_no; + } + + /** + * Whenever the outgoing frame + * situation of an InstructionContext changes, all its successors are + * put [back] into the queue [as if they were unvisited]. + * The proof of termination is about the existence of a + * fix point of frame merging. + */ + private void circulationPump(ControlFlowGraph cfg, InstructionContext start, Frame vanillaFrame, InstConstraintVisitor icv, ExecutionVisitor ev){ + final Random random = new Random(); + InstructionContextQueue icq = new InstructionContextQueue(); + + start.execute(vanillaFrame, new ArrayList(), icv, ev); // new ArrayList() <=> no Instruction was executed before + // => Top-Level routine (no jsr call before) + icq.add(start, new ArrayList()); + + // LOOP! + while (!icq.isEmpty()){ + InstructionContext u; + ArrayList ec; + if (!DEBUG){ + int r = random.nextInt(icq.size()); + u = icq.getIC(r); + ec = icq.getEC(r); + icq.remove(r); + } + else{ + u = icq.getIC(0); + ec = icq.getEC(0); + icq.remove(0); + } + + ArrayList oldchain = (ArrayList) (ec.clone()); + ArrayList newchain = (ArrayList) (ec.clone()); + newchain.add(u); + + if ((u.getInstruction().getInstruction()) instanceof RET){ +//System.err.println(u); + // We can only follow _one_ successor, the one after the + // JSR that was recently executed. + RET ret = (RET) (u.getInstruction().getInstruction()); + ReturnaddressType t = (ReturnaddressType) u.getOutFrame(oldchain).getLocals().get(ret.getIndex()); + InstructionContext theSuccessor = cfg.contextOf(t.getTarget()); + + // Sanity check + InstructionContext lastJSR = null; + int skip_jsr = 0; + for (int ss=oldchain.size()-1; ss >= 0; ss--){ + if (skip_jsr < 0){ + throw new AssertionViolatedException("More RET than JSR in execution chain?!"); + } +//System.err.println("+"+oldchain.get(ss)); + if (((InstructionContext) oldchain.get(ss)).getInstruction().getInstruction().isJsrInstruction()) { + if (skip_jsr == 0){ + lastJSR = (InstructionContext) oldchain.get(ss); + break; + } + else{ + skip_jsr--; + } + } + if (((InstructionContext) oldchain.get(ss)).getInstruction().getInstruction() instanceof RET){ + skip_jsr++; + } + } + if (lastJSR == null){ + throw new AssertionViolatedException("RET without a JSR before in ExecutionChain?! EC: '"+oldchain+"'."); + } + InstructionBranch jsr = (InstructionBranch) (lastJSR.getInstruction().getInstruction()); + if ( theSuccessor != (cfg.contextOf(jsr.physicalSuccessor())) ){ + throw new AssertionViolatedException("RET '"+u.getInstruction()+"' info inconsistent: jump back to '"+theSuccessor+"' or '"+cfg.contextOf(jsr.physicalSuccessor())+"'?"); + } + + if (theSuccessor.execute(u.getOutFrame(oldchain), newchain, icv, ev)){ + icq.add(theSuccessor, (ArrayList) newchain.clone()); + } + } + else{// "not a ret" + + // Normal successors. Add them to the queue of successors. + InstructionContext[] succs = u.getSuccessors(); + for (int s=0; s. - */ - -import org.aspectj.apache.bcel.generic.*; - -/** - * This interface defines properties of JVM bytecode subroutines. - * Note that it is 'abused' to maintain the top-level code in a - * consistent fashion, too. - * - * @version $Id: Subroutine.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public interface Subroutine{ - /** - * Returns all the JsrInstructions that have the - * first instruction of this subroutine as their target. - * Must not be invoked on the 'top-level subroutine'. - */ - public InstructionHandle[] getEnteringJsrInstructions(); - - /** - * Returns the one and only RET that leaves the subroutine. - * Note that JustIce has a pretty rigid notion of a subroutine. - * Must not be invoked on the 'top-level subroutine'. - * - * @see org.aspectj.apache.bcel.verifier.structurals.Subroutines - */ - public InstructionHandle getLeavingRET(); - - /** - * Returns all instructions that together form this subroutine. - * Note that an instruction is part of exactly one subroutine - * (the top-level code is considered to be a special subroutine) - - * else it is not reachable at all (dead code). - */ - public InstructionHandle[] getInstructions(); - - /** - * Returns if the given InstructionHandle refers to an instruction - * that is part of this subroutine. This is a convenience method - * that saves iteration over the InstructionHandle objects returned - * by getInstructions(). - * - * @see #getInstructions() - */ - public boolean contains(InstructionHandle inst); - - /** - * Returns an int[] containing the indices of the local variable slots - * accessed by this Subroutine (read-accessed, write-accessed or both); - * local variables referenced by subroutines of this subroutine are - * not included. - * - * @see #getRecursivelyAccessedLocalsIndices() - */ - public int[] getAccessedLocalsIndices(); - - /** - * Returns an int[] containing the indices of the local variable slots - * accessed by this Subroutine (read-accessed, write-accessed or both); - * local variables referenced by subroutines of this subroutine are - * included. - * - * @see #getAccessedLocalsIndices() - */ - public int[] getRecursivelyAccessedLocalsIndices(); - - /** - * Returns the subroutines that are directly called from this subroutine. - */ - public Subroutine[] subSubs(); -} +package org.aspectj.apache.bcel.verifier.structurals; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.generic.*; + +/** + * This interface defines properties of JVM bytecode subroutines. + * Note that it is 'abused' to maintain the top-level code in a + * consistent fashion, too. + * + * @version $Id: Subroutine.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public interface Subroutine{ + /** + * Returns all the JsrInstructions that have the + * first instruction of this subroutine as their target. + * Must not be invoked on the 'top-level subroutine'. + */ + public InstructionHandle[] getEnteringJsrInstructions(); + + /** + * Returns the one and only RET that leaves the subroutine. + * Note that JustIce has a pretty rigid notion of a subroutine. + * Must not be invoked on the 'top-level subroutine'. + * + * @see org.aspectj.apache.bcel.verifier.structurals.Subroutines + */ + public InstructionHandle getLeavingRET(); + + /** + * Returns all instructions that together form this subroutine. + * Note that an instruction is part of exactly one subroutine + * (the top-level code is considered to be a special subroutine) - + * else it is not reachable at all (dead code). + */ + public InstructionHandle[] getInstructions(); + + /** + * Returns if the given InstructionHandle refers to an instruction + * that is part of this subroutine. This is a convenience method + * that saves iteration over the InstructionHandle objects returned + * by getInstructions(). + * + * @see #getInstructions() + */ + public boolean contains(InstructionHandle inst); + + /** + * Returns an int[] containing the indices of the local variable slots + * accessed by this Subroutine (read-accessed, write-accessed or both); + * local variables referenced by subroutines of this subroutine are + * not included. + * + * @see #getRecursivelyAccessedLocalsIndices() + */ + public int[] getAccessedLocalsIndices(); + + /** + * Returns an int[] containing the indices of the local variable slots + * accessed by this Subroutine (read-accessed, write-accessed or both); + * local variables referenced by subroutines of this subroutine are + * included. + * + * @see #getAccessedLocalsIndices() + */ + public int[] getRecursivelyAccessedLocalsIndices(); + + /** + * Returns the subroutines that are directly called from this subroutine. + */ + public Subroutine[] subSubs(); +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/Subroutines.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/Subroutines.java similarity index 96% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/Subroutines.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/Subroutines.java index 3d6b241e1..b9d869026 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/Subroutines.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/Subroutines.java @@ -1,669 +1,669 @@ -package org.aspectj.apache.bcel.verifier.structurals; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.generic.*; -import org.aspectj.apache.bcel.verifier.exc.*; -import java.awt.Color; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Iterator; - - /** - * Instances of this class contain information about the subroutines - * found in a code array of a method. - * This implementation considers the top-level (the instructions - * reachable without a JSR or JSR_W starting off from the first - * instruction in a code array of a method) being a special subroutine; - * see getTopLevel() for that. - * Please note that the definition of subroutines in the Java Virtual - * Machine Specification, Second Edition is somewhat incomplete. - * Therefore, JustIce uses an own, more rigid notion. - * Basically, a subroutine is a piece of code that starts at the target - * of a JSR of JSR_W instruction and ends at a corresponding RET - * instruction. Note also that the control flow of a subroutine - * may be complex and non-linear; and that subroutines may be nested. - * JustIce also mandates subroutines not to be protected by exception - * handling code (for the sake of control flow predictability). - * To understand JustIce's notion of subroutines, please read - * - * TODO: refer to the paper. - * - * @version $Id: Subroutines.java,v 1.2.10.2 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - * @see #getTopLevel() - */ -public class Subroutines{ - /** - * This inner class implements the Subroutine interface. - */ - private class SubroutineImpl implements Subroutine{ - /** - * UNSET, a symbol for an uninitialized localVariable - * field. This is used for the "top-level" Subroutine; - * i.e. no subroutine. - */ - private final int UNSET = -1; - - /** - * The Local Variable slot where the first - * instruction of this subroutine (an ASTORE) stores - * the JsrInstruction's ReturnAddress in and - * the RET of this subroutine operates on. - */ - private int localVariable = UNSET; - - /** The instructions that belong to this subroutine. */ - private HashSet instructions = new HashSet(); // Elements: InstructionHandle - - /* - * Refer to the Subroutine interface for documentation. - */ - public boolean contains(InstructionHandle inst){ - return instructions.contains(inst); - } - - /** - * The JSR or JSR_W instructions that define this - * subroutine by targeting it. - */ - private HashSet theJSRs = new HashSet(); - - /** - * The RET instruction that leaves this subroutine. - */ - private InstructionHandle theRET; - - /** - * Returns a String representation of this object, merely - * for debugging purposes. - * (Internal) Warning: Verbosity on a problematic subroutine may cause - * stack overflow errors due to recursive subSubs() calls. - * Don't use this, then. - */ - public String toString(){ - String ret = "Subroutine: Local variable is '"+localVariable+"', JSRs are '"+theJSRs+"', RET is '"+theRET+"', Instructions: '"+instructions.toString()+"'."; - - ret += " Accessed local variable slots: '"; - int[] alv = getAccessedLocalsIndices(); - for (int i=0; inot a - * subroutine, the top-level, is also modeled as a Subroutine - * object. - * It is a special Subroutine object where you must not invoke - * getEnteringJsrInstructions() or getLeavingRET(). - * - * @see Subroutine#getEnteringJsrInstructions() - * @see Subroutine#getLeavingRET() - */ - public Subroutine getTopLevel(){ - return TOPLEVEL; - } - /** - * A utility method that calculates the successors of a given InstructionHandle - * in the same subroutine. That means, a RET does not have any successors - * as defined here. A JsrInstruction has its physical successor as its successor - * (opposed to its target) as defined here. - */ - private static InstructionHandle[] getSuccessors(InstructionHandle instruction){ - final InstructionHandle[] empty = new InstructionHandle[0]; - final InstructionHandle[] single = new InstructionHandle[1]; - final InstructionHandle[] pair = new InstructionHandle[2]; - - Instruction inst = instruction.getInstruction(); - - if (inst instanceof RET){ - return empty; - } - - // Terminates method normally. - if (inst.isReturnInstruction()){ - return empty; - } - - // Terminates method abnormally, because JustIce mandates - // subroutines not to be protected by exception handlers. - if (inst.getOpcode()==Constants.ATHROW){ - return empty; - } - - // See method comment. - if (inst.isJsrInstruction()){ - single[0] = instruction.getNext(); - return single; - } - - if (inst.getOpcode()==Constants.GOTO || inst.getOpcode()==Constants.GOTO_W){ - single[0] = ((InstructionBranch) inst).getTarget(); - return single; - } - - if (inst instanceof InstructionBranch){ - if (inst instanceof InstructionSelect){ - // BCEL's getTargets() returns only the non-default targets, - // thanks to Eli Tilevich for reporting. - InstructionHandle[] matchTargets = ((InstructionSelect) inst).getTargets(); - InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1]; - ret[0] = ((InstructionSelect) inst).getTarget(); - System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length); - return ret; - } - else{ - pair[0] = instruction.getNext(); - pair[1] = ((InstructionBranch) inst).getTarget(); - return pair; - } - } - - // default case: Fall through. - single[0] = instruction.getNext(); - return single; - } - - /** - * Returns a String representation of this object; merely for debugging puposes. - */ - public String toString(){ - return "---\n"+subroutines.toString()+"\n---\n"; - } -} +package org.aspectj.apache.bcel.verifier.structurals; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.generic.*; +import org.aspectj.apache.bcel.verifier.exc.*; +import java.awt.Color; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Iterator; + + /** + * Instances of this class contain information about the subroutines + * found in a code array of a method. + * This implementation considers the top-level (the instructions + * reachable without a JSR or JSR_W starting off from the first + * instruction in a code array of a method) being a special subroutine; + * see getTopLevel() for that. + * Please note that the definition of subroutines in the Java Virtual + * Machine Specification, Second Edition is somewhat incomplete. + * Therefore, JustIce uses an own, more rigid notion. + * Basically, a subroutine is a piece of code that starts at the target + * of a JSR of JSR_W instruction and ends at a corresponding RET + * instruction. Note also that the control flow of a subroutine + * may be complex and non-linear; and that subroutines may be nested. + * JustIce also mandates subroutines not to be protected by exception + * handling code (for the sake of control flow predictability). + * To understand JustIce's notion of subroutines, please read + * + * TODO: refer to the paper. + * + * @version $Id: Subroutines.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + * @see #getTopLevel() + */ +public class Subroutines{ + /** + * This inner class implements the Subroutine interface. + */ + private class SubroutineImpl implements Subroutine{ + /** + * UNSET, a symbol for an uninitialized localVariable + * field. This is used for the "top-level" Subroutine; + * i.e. no subroutine. + */ + private final int UNSET = -1; + + /** + * The Local Variable slot where the first + * instruction of this subroutine (an ASTORE) stores + * the JsrInstruction's ReturnAddress in and + * the RET of this subroutine operates on. + */ + private int localVariable = UNSET; + + /** The instructions that belong to this subroutine. */ + private HashSet instructions = new HashSet(); // Elements: InstructionHandle + + /* + * Refer to the Subroutine interface for documentation. + */ + public boolean contains(InstructionHandle inst){ + return instructions.contains(inst); + } + + /** + * The JSR or JSR_W instructions that define this + * subroutine by targeting it. + */ + private HashSet theJSRs = new HashSet(); + + /** + * The RET instruction that leaves this subroutine. + */ + private InstructionHandle theRET; + + /** + * Returns a String representation of this object, merely + * for debugging purposes. + * (Internal) Warning: Verbosity on a problematic subroutine may cause + * stack overflow errors due to recursive subSubs() calls. + * Don't use this, then. + */ + public String toString(){ + String ret = "Subroutine: Local variable is '"+localVariable+"', JSRs are '"+theJSRs+"', RET is '"+theRET+"', Instructions: '"+instructions.toString()+"'."; + + ret += " Accessed local variable slots: '"; + int[] alv = getAccessedLocalsIndices(); + for (int i=0; inot a + * subroutine, the top-level, is also modeled as a Subroutine + * object. + * It is a special Subroutine object where you must not invoke + * getEnteringJsrInstructions() or getLeavingRET(). + * + * @see Subroutine#getEnteringJsrInstructions() + * @see Subroutine#getLeavingRET() + */ + public Subroutine getTopLevel(){ + return TOPLEVEL; + } + /** + * A utility method that calculates the successors of a given InstructionHandle + * in the same subroutine. That means, a RET does not have any successors + * as defined here. A JsrInstruction has its physical successor as its successor + * (opposed to its target) as defined here. + */ + private static InstructionHandle[] getSuccessors(InstructionHandle instruction){ + final InstructionHandle[] empty = new InstructionHandle[0]; + final InstructionHandle[] single = new InstructionHandle[1]; + final InstructionHandle[] pair = new InstructionHandle[2]; + + Instruction inst = instruction.getInstruction(); + + if (inst instanceof RET){ + return empty; + } + + // Terminates method normally. + if (inst.isReturnInstruction()){ + return empty; + } + + // Terminates method abnormally, because JustIce mandates + // subroutines not to be protected by exception handlers. + if (inst.getOpcode()==Constants.ATHROW){ + return empty; + } + + // See method comment. + if (inst.isJsrInstruction()){ + single[0] = instruction.getNext(); + return single; + } + + if (inst.getOpcode()==Constants.GOTO || inst.getOpcode()==Constants.GOTO_W){ + single[0] = ((InstructionBranch) inst).getTarget(); + return single; + } + + if (inst instanceof InstructionBranch){ + if (inst instanceof InstructionSelect){ + // BCEL's getTargets() returns only the non-default targets, + // thanks to Eli Tilevich for reporting. + InstructionHandle[] matchTargets = ((InstructionSelect) inst).getTargets(); + InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1]; + ret[0] = ((InstructionSelect) inst).getTarget(); + System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length); + return ret; + } + else{ + pair[0] = instruction.getNext(); + pair[1] = ((InstructionBranch) inst).getTarget(); + return pair; + } + } + + // default case: Fall through. + single[0] = instruction.getNext(); + return single; + } + + /** + * Returns a String representation of this object; merely for debugging puposes. + */ + public String toString(){ + return "---\n"+subroutines.toString()+"\n---\n"; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/UninitializedObjectType.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/UninitializedObjectType.java similarity index 95% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/UninitializedObjectType.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/UninitializedObjectType.java index 5d8a34b1c..e755229f8 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/UninitializedObjectType.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/UninitializedObjectType.java @@ -1,97 +1,97 @@ -package org.aspectj.apache.bcel.verifier.structurals; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import org.aspectj.apache.bcel.*; -import org.aspectj.apache.bcel.generic.*; - -/** - * This class represents an uninitialized object type; see The Java - * Virtual Machine Specification, Second Edition, page 147: 4.9.4 for - * more details. - * - * @version $Id: UninitializedObjectType.java,v 1.2.10.1 2008/04/25 17:55:37 aclement Exp $ - * @author Enver Haase - */ -public class UninitializedObjectType extends ReferenceType implements Constants{ - - /** The "initialized" version. */ - private ObjectType initialized; - - /** Creates a new instance. */ - public UninitializedObjectType(ObjectType t){ - super(T_UNKNOWN, ""); - initialized = t; - } - - /** - * Returns the ObjectType of the same class as the one of the uninitialized object - * represented by this UninitializedObjectType instance. - */ - public ObjectType getInitialized(){ - return initialized; - } - - /** - * Returns true on equality of this and o. - * Equality means the ObjectType instances of "initialized" - * equal one another in this and the o instance. - * - */ - public boolean equals(Object o){ - if (! (o instanceof UninitializedObjectType)) return false; - return initialized.equals(((UninitializedObjectType)o).initialized); - } -} +package org.aspectj.apache.bcel.verifier.structurals; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import org.aspectj.apache.bcel.*; +import org.aspectj.apache.bcel.generic.*; + +/** + * This class represents an uninitialized object type; see The Java + * Virtual Machine Specification, Second Edition, page 147: 4.9.4 for + * more details. + * + * @version $Id: UninitializedObjectType.java,v 1.1.2.1 2008/05/08 19:26:48 aclement Exp $ + * @author Enver Haase + */ +public class UninitializedObjectType extends ReferenceType implements Constants{ + + /** The "initialized" version. */ + private ObjectType initialized; + + /** Creates a new instance. */ + public UninitializedObjectType(ObjectType t){ + super(T_UNKNOWN, ""); + initialized = t; + } + + /** + * Returns the ObjectType of the same class as the one of the uninitialized object + * represented by this UninitializedObjectType instance. + */ + public ObjectType getInitialized(){ + return initialized; + } + + /** + * Returns true on equality of this and o. + * Equality means the ObjectType instances of "initialized" + * equal one another in this and the o instance. + * + */ + public boolean equals(Object o){ + if (! (o instanceof UninitializedObjectType)) return false; + return initialized.equals(((UninitializedObjectType)o).initialized); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/package.html b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/package.html similarity index 92% rename from bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/package.html rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/package.html index 40232167c..01c016a30 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/verifier/structurals/package.html +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/structurals/package.html @@ -2,7 +2,7 @@ diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/BCELFactory.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELFactory.java similarity index 90% rename from bcel-builder/src/org/aspectj/apache/bcel/util/BCELFactory.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELFactory.java index ddaec18cb..60ef9d6fd 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/BCELFactory.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELFactory.java @@ -1,358 +1,376 @@ -package org.aspectj.apache.bcel.util; - -import org.aspectj.apache.bcel.generic.*; -import org.aspectj.apache.bcel.classfile.Utility; -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import java.io.PrintWriter; -import java.util.*; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2002 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -/** - * Factory creates il.append() statements, and sets instruction targets. - * A helper class for BCELifier. - * - * @see BCELifier - * @version $Id: BCELFactory.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - */ -class BCELFactory extends EmptyVisitor { - private MethodGen _mg; - private PrintWriter _out; - private ConstantPool _cp; - - BCELFactory(MethodGen mg, PrintWriter out) { - _mg = mg; - _cp = mg.getConstantPool(); - _out = out; - } - - private HashMap branch_map = new HashMap(); // Map - - public void start() { - if(!_mg.isAbstract() && !_mg.isNative()) { - for(InstructionHandle ih = _mg.getInstructionList().getStart(); - ih != null; ih = ih.getNext()) { - Instruction i = ih.getInstruction(); - - if(i instanceof InstructionBranch) { - branch_map.put(i, ih); // memorize container - } - - if(ih.hasTargeters()) { - if(i instanceof InstructionBranch) { - _out.println(" InstructionHandle ih_" + ih.getPosition() + ";"); - } else { - _out.print(" InstructionHandle ih_" + ih.getPosition() + " = "); - } - } else { - _out.print(" "); - } - - if(!visitInstruction(i)) - i.accept(this); - } - - updateBranchTargets(); - updateExceptionHandlers(); - } - } - - private boolean visitInstruction(Instruction i) { - short opcode = i.getOpcode(); - - if((InstructionConstants.INSTRUCTIONS[opcode] != null) && - !(i.isConstantInstruction()) && - !(i.isReturnInstruction())) { // Handled below - _out.println("il.append(InstructionConstants." + - i.getName().toUpperCase() + ");"); - return true; - } - - return false; - } - - public void visitLocalVariableInstruction(Instruction i) { - short opcode = i.getOpcode(); - Type type = i.getType(_cp); - - if(opcode == Constants.IINC) { - _out.println("il.append(new IINC(" + i.getIndex() + ", " + - ((IINC)i).getIncrement() + "));"); - } else { - String kind = (opcode < Constants.ISTORE)? "Load" : "Store"; - _out.println("il.append(_factory.create" + kind + "(" + - BCELifier.printType(type) + ", " + - i.getIndex() + "));"); - } - } - - public void visitArrayInstruction(Instruction i) { - short opcode = i.getOpcode(); - Type type = i.getType(_cp); - String kind = (opcode < Constants.IASTORE)? "Load" : "Store"; - - _out.println("il.append(_factory.createArray" + kind + "(" + - BCELifier.printType(type) + "));"); - } - - public void visitFieldInstruction(FieldInstruction i) { - short opcode = i.getOpcode(); - - String class_name = i.getClassName(_cp); - String field_name = i.getFieldName(_cp); - Type type = i.getFieldType(_cp); - - _out.println("il.append(_factory.createFieldAccess(\"" + - class_name + "\", \"" + field_name + "\", " + - BCELifier.printType(type) + ", " + - "Constants." + Constants.OPCODE_NAMES[opcode].toUpperCase() + - "));"); - } - - public void visitInvokeInstruction(InvokeInstruction i) { - short opcode = i.getOpcode(); - String class_name = i.getClassName(_cp); - String method_name = i.getMethodName(_cp); - Type type = i.getReturnType(_cp); - Type[] arg_types = i.getArgumentTypes(_cp); - - _out.println("il.append(_factory.createInvoke(\"" + - class_name + "\", \"" + method_name + "\", " + - BCELifier.printType(type) + ", " + - BCELifier.printArgumentTypes(arg_types) + ", " + - "Constants." + Constants.OPCODE_NAMES[opcode].toUpperCase() + - "));"); - } - - public void visitAllocationInstruction(Instruction i) { - Type type; - - if(i.isConstantPoolInstruction()) { - type = ((InstructionCP)i).getType(_cp); - } else { - type = ((InstructionByte)i).getType(); - } - - short opcode = ((Instruction)i).getOpcode(); - int dim = 1; - - switch(opcode) { - case Constants.NEW: - _out.println("il.append(_factory.createNew(\"" + - ((ObjectType)type).getClassName() + "\"));"); - break; - - case Constants.MULTIANEWARRAY: - dim = ((MULTIANEWARRAY)i).getDimensions(); - - case Constants.ANEWARRAY: - case Constants.NEWARRAY: - _out.println("il.append(_factory.createNewArray(" + - BCELifier.printType(type) + ", (short) " + dim + "));"); - break; - - default: - throw new RuntimeException("Oops: " + opcode); - } - } - - private void createConstant(Object value) { - String embed = value.toString(); - - if(value instanceof String) - embed = '"' + Utility.convertString(value.toString()) + '"'; - else if(value instanceof Character) - embed = "(char)0x" + Integer.toHexString(((Character)value).charValue()); - - _out.println("il.append(new PUSH(_cp, " + embed + "));"); - } - - public void visitLDC(Instruction i) { - createConstant(i.getValue(_cp)); - } - - public void visitLDC2_W(Instruction i) { - createConstant(i.getValue(_cp)); - } - - public void visitConstantPushInstruction(Instruction i) { - createConstant(i.getValue()); - } - - public void visitINSTANCEOF(Instruction i) { - Type type = i.getType(_cp); - - _out.println("il.append(new INSTANCEOF(_cp.addClass(" + - BCELifier.printType(type) + ")));"); - } - - public void visitCHECKCAST(Instruction i) { - Type type = i.getType(_cp); - - _out.println("il.append(_factory.createCheckCast(" + - BCELifier.printType(type) + "));"); - } - - public void visitReturnInstruction(Instruction i) { - Type type = i.getType(_cp); - - _out.println("il.append(_factory.createReturn(" + - BCELifier.printType(type) + "));"); - } - - // Memorize BranchInstructions that need an update - private ArrayList branches = new ArrayList(); - - public void visitBranchInstruction(InstructionBranch bi) { - BranchHandle bh = (BranchHandle)branch_map.get(bi); - int pos = bh.getPosition(); - String name = bi.getName() + "_" + pos; - - if(bi instanceof InstructionSelect) { - InstructionSelect s = (InstructionSelect)bi; - branches.add(bi); - - StringBuffer args = new StringBuffer("new int[] { "); - int[] matchs = s.getMatchs(); - - for(int i=0; i < matchs.length; i++) { - args.append(matchs[i]); - - if(i < matchs.length - 1) - args.append(", "); - } - - args.append(" }"); - - _out.print(" Select " + name + " = new " + - bi.getName().toUpperCase() + "(" + args + - ", new InstructionHandle[] { "); - - for(int i=0; i < matchs.length; i++) { - _out.print("null"); - - if(i < matchs.length - 1) - _out.print(", "); - } - - _out.println(");"); - } else { - int t_pos = bh.getTarget().getPosition(); - String target; - - if(pos > t_pos) { - target = "ih_" + t_pos; - } else { - branches.add(bi); - target = "null"; - } - - _out.println(" BranchInstruction " + name + - " = _factory.createBranchInstruction(" + - "Constants." + bi.getName().toUpperCase() + ", " + - target + ");"); - } - - if(bh.hasTargeters()) - _out.println(" ih_" + pos + " = il.append(" + name + ");"); - else - _out.println(" il.append(" + name + ");"); - } - - public void visitRET(RET i) { - _out.println("il.append(new RET(" + i.getIndex() + ")));"); - } - - private void updateBranchTargets() { - for(Iterator i = branches.iterator(); i.hasNext(); ) { - InstructionBranch bi = (InstructionBranch)i.next(); - BranchHandle bh = (BranchHandle)branch_map.get(bi); - int pos = bh.getPosition(); - String name = bi.getName() + "_" + pos; - int t_pos = bh.getTarget().getPosition(); - - _out.println(" " + name + ".setTarget(ih_" + t_pos + ");"); - - if(bi instanceof InstructionSelect) { - InstructionHandle[] ihs = ((InstructionSelect)bi).getTargets(); - - for(int j = 0; j < ihs.length; j++) { - t_pos = ihs[j].getPosition(); - - _out.println(" " + name + ".setTarget(" + j + - ", ih_" + t_pos + ");"); - } - } - } - } - - private void updateExceptionHandlers() { - CodeExceptionGen[] handlers = _mg.getExceptionHandlers(); - - for(int i=0; i < handlers.length; i++) { - CodeExceptionGen h = handlers[i]; - String type = (h.getCatchType() == null)? - "null" : BCELifier.printType(h.getCatchType()); - - _out.println(" method.addExceptionHandler(" + - "ih_" + h.getStartPC().getPosition() + ", " + - "ih_" + h.getEndPC().getPosition() + ", " + - "ih_" + h.getHandlerPC().getPosition() + ", " + - type + ");"); - } - } -} +package org.aspectj.apache.bcel.verifier.util; + +import org.aspectj.apache.bcel.verifier.EmptyClassVisitor; +import org.aspectj.apache.bcel.classfile.Utility; +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.generic.BranchHandle; +import org.aspectj.apache.bcel.generic.CodeExceptionGen; +import org.aspectj.apache.bcel.generic.FieldInstruction; +import org.aspectj.apache.bcel.generic.IINC; +import org.aspectj.apache.bcel.generic.Instruction; +import org.aspectj.apache.bcel.generic.InstructionBranch; +import org.aspectj.apache.bcel.generic.InstructionByte; +import org.aspectj.apache.bcel.generic.InstructionCP; +import org.aspectj.apache.bcel.generic.InstructionConstants; +import org.aspectj.apache.bcel.generic.InstructionHandle; +import org.aspectj.apache.bcel.generic.InstructionSelect; +import org.aspectj.apache.bcel.generic.InvokeInstruction; +import org.aspectj.apache.bcel.generic.MULTIANEWARRAY; +import org.aspectj.apache.bcel.generic.MethodGen; +import org.aspectj.apache.bcel.generic.ObjectType; +import org.aspectj.apache.bcel.generic.RET; +import org.aspectj.apache.bcel.generic.Type; + +import java.io.PrintWriter; +import java.util.*; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +/** + * Factory creates il.append() statements, and sets instruction targets. + * A helper class for BCELifier. + * + * @see BCELifier + * @version $Id: BCELFactory.java,v 1.1.2.1 2008/05/08 19:26:53 aclement Exp $ + * @author M. Dahm + */ +class BCELFactory extends org.aspectj.apache.bcel.verifier.EmptyInstVisitor { + private MethodGen _mg; + private PrintWriter _out; + private ConstantPool _cp; + + BCELFactory(MethodGen mg, PrintWriter out) { + _mg = mg; + _cp = mg.getConstantPool(); + _out = out; + } + + private HashMap branch_map = new HashMap(); // Map + + public void start() { + if(!_mg.isAbstract() && !_mg.isNative()) { + for(InstructionHandle ih = _mg.getInstructionList().getStart(); + ih != null; ih = ih.getNext()) { + Instruction i = ih.getInstruction(); + + if(i instanceof InstructionBranch) { + branch_map.put(i, ih); // memorize container + } + + if(ih.hasTargeters()) { + if(i instanceof InstructionBranch) { + _out.println(" InstructionHandle ih_" + ih.getPosition() + ";"); + } else { + _out.print(" InstructionHandle ih_" + ih.getPosition() + " = "); + } + } else { + _out.print(" "); + } + + if(!visitInstruction(i)) + i.accept(this); + } + + updateBranchTargets(); + updateExceptionHandlers(); + } + } + + private boolean visitInstruction(Instruction i) { + short opcode = i.getOpcode(); + + if((InstructionConstants.INSTRUCTIONS[opcode] != null) && + !(i.isConstantInstruction()) && + !(i.isReturnInstruction())) { // Handled below + _out.println("il.append(InstructionConstants." + + i.getName().toUpperCase() + ");"); + return true; + } + + return false; + } + + public void visitLocalVariableInstruction(Instruction i) { + short opcode = i.getOpcode(); + Type type = i.getType(_cp); + + if(opcode == Constants.IINC) { + _out.println("il.append(new IINC(" + i.getIndex() + ", " + + ((IINC)i).getIncrement() + "));"); + } else { + String kind = (opcode < Constants.ISTORE)? "Load" : "Store"; + _out.println("il.append(_factory.create" + kind + "(" + + BCELifier.printType(type) + ", " + + i.getIndex() + "));"); + } + } + + public void visitArrayInstruction(Instruction i) { + short opcode = i.getOpcode(); + Type type = i.getType(_cp); + String kind = (opcode < Constants.IASTORE)? "Load" : "Store"; + + _out.println("il.append(_factory.createArray" + kind + "(" + + BCELifier.printType(type) + "));"); + } + + public void visitFieldInstruction(FieldInstruction i) { + short opcode = i.getOpcode(); + + String class_name = i.getClassName(_cp); + String field_name = i.getFieldName(_cp); + Type type = i.getFieldType(_cp); + + _out.println("il.append(_factory.createFieldAccess(\"" + + class_name + "\", \"" + field_name + "\", " + + BCELifier.printType(type) + ", " + + "Constants." + Constants.OPCODE_NAMES[opcode].toUpperCase() + + "));"); + } + + public void visitInvokeInstruction(InvokeInstruction i) { + short opcode = i.getOpcode(); + String class_name = i.getClassName(_cp); + String method_name = i.getMethodName(_cp); + Type type = i.getReturnType(_cp); + Type[] arg_types = i.getArgumentTypes(_cp); + + _out.println("il.append(_factory.createInvoke(\"" + + class_name + "\", \"" + method_name + "\", " + + BCELifier.printType(type) + ", " + + BCELifier.printArgumentTypes(arg_types) + ", " + + "Constants." + Constants.OPCODE_NAMES[opcode].toUpperCase() + + "));"); + } + + public void visitAllocationInstruction(Instruction i) { + Type type; + + if(i.isConstantPoolInstruction()) { + type = ((InstructionCP)i).getType(_cp); + } else { + type = ((InstructionByte)i).getType(); + } + + short opcode = ((Instruction)i).getOpcode(); + int dim = 1; + + switch(opcode) { + case Constants.NEW: + _out.println("il.append(_factory.createNew(\"" + + ((ObjectType)type).getClassName() + "\"));"); + break; + + case Constants.MULTIANEWARRAY: + dim = ((MULTIANEWARRAY)i).getDimensions(); + + case Constants.ANEWARRAY: + case Constants.NEWARRAY: + _out.println("il.append(_factory.createNewArray(" + + BCELifier.printType(type) + ", (short) " + dim + "));"); + break; + + default: + throw new RuntimeException("Oops: " + opcode); + } + } + + private void createConstant(Object value) { + String embed = value.toString(); + + if(value instanceof String) + embed = '"' + Utility.convertString(value.toString()) + '"'; + else if(value instanceof Character) + embed = "(char)0x" + Integer.toHexString(((Character)value).charValue()); + + _out.println("il.append(new PUSH(_cp, " + embed + "));"); + } + + public void visitLDC(Instruction i) { + createConstant(i.getValue(_cp)); + } + + public void visitLDC2_W(Instruction i) { + createConstant(i.getValue(_cp)); + } + + public void visitConstantPushInstruction(Instruction i) { + createConstant(i.getValue()); + } + + public void visitINSTANCEOF(Instruction i) { + Type type = i.getType(_cp); + + _out.println("il.append(new INSTANCEOF(_cp.addClass(" + + BCELifier.printType(type) + ")));"); + } + + public void visitCHECKCAST(Instruction i) { + Type type = i.getType(_cp); + + _out.println("il.append(_factory.createCheckCast(" + + BCELifier.printType(type) + "));"); + } + + public void visitReturnInstruction(Instruction i) { + Type type = i.getType(_cp); + + _out.println("il.append(_factory.createReturn(" + + BCELifier.printType(type) + "));"); + } + + // Memorize BranchInstructions that need an update + private ArrayList branches = new ArrayList(); + + public void visitBranchInstruction(InstructionBranch bi) { + BranchHandle bh = (BranchHandle)branch_map.get(bi); + int pos = bh.getPosition(); + String name = bi.getName() + "_" + pos; + + if(bi instanceof InstructionSelect) { + InstructionSelect s = (InstructionSelect)bi; + branches.add(bi); + + StringBuffer args = new StringBuffer("new int[] { "); + int[] matchs = s.getMatchs(); + + for(int i=0; i < matchs.length; i++) { + args.append(matchs[i]); + + if(i < matchs.length - 1) + args.append(", "); + } + + args.append(" }"); + + _out.print(" Select " + name + " = new " + + bi.getName().toUpperCase() + "(" + args + + ", new InstructionHandle[] { "); + + for(int i=0; i < matchs.length; i++) { + _out.print("null"); + + if(i < matchs.length - 1) + _out.print(", "); + } + + _out.println(");"); + } else { + int t_pos = bh.getTarget().getPosition(); + String target; + + if(pos > t_pos) { + target = "ih_" + t_pos; + } else { + branches.add(bi); + target = "null"; + } + + _out.println(" BranchInstruction " + name + + " = _factory.createBranchInstruction(" + + "Constants." + bi.getName().toUpperCase() + ", " + + target + ");"); + } + + if(bh.hasTargeters()) + _out.println(" ih_" + pos + " = il.append(" + name + ");"); + else + _out.println(" il.append(" + name + ");"); + } + + public void visitRET(RET i) { + _out.println("il.append(new RET(" + i.getIndex() + ")));"); + } + + private void updateBranchTargets() { + for(Iterator i = branches.iterator(); i.hasNext(); ) { + InstructionBranch bi = (InstructionBranch)i.next(); + BranchHandle bh = (BranchHandle)branch_map.get(bi); + int pos = bh.getPosition(); + String name = bi.getName() + "_" + pos; + int t_pos = bh.getTarget().getPosition(); + + _out.println(" " + name + ".setTarget(ih_" + t_pos + ");"); + + if(bi instanceof InstructionSelect) { + InstructionHandle[] ihs = ((InstructionSelect)bi).getTargets(); + + for(int j = 0; j < ihs.length; j++) { + t_pos = ihs[j].getPosition(); + + _out.println(" " + name + ".setTarget(" + j + + ", ih_" + t_pos + ");"); + } + } + } + } + + private void updateExceptionHandlers() { + CodeExceptionGen[] handlers = _mg.getExceptionHandlers(); + + for(int i=0; i < handlers.length; i++) { + CodeExceptionGen h = handlers[i]; + String type = (h.getCatchType() == null)? + "null" : BCELifier.printType(h.getCatchType()); + + _out.println(" method.addExceptionHandler(" + + "ih_" + h.getStartPC().getPosition() + ", " + + "ih_" + h.getEndPC().getPosition() + ", " + + "ih_" + h.getHandlerPC().getPosition() + ", " + + type + ");"); + } + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/BCELifier.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELifier.java similarity index 90% rename from bcel-builder/src/org/aspectj/apache/bcel/util/BCELifier.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELifier.java index 36ca3963f..cf742fc50 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/BCELifier.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELifier.java @@ -1,314 +1,341 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2002 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -import java.io.OutputStream; -import java.io.PrintWriter; - -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.ClassParser; -import org.aspectj.apache.bcel.classfile.ConstantValue; -import org.aspectj.apache.bcel.classfile.Field; -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.classfile.Utility; -import org.aspectj.apache.bcel.generic.ArrayType; -import org.aspectj.apache.bcel.classfile.ConstantPool; -import org.aspectj.apache.bcel.generic.MethodGen; -import org.aspectj.apache.bcel.generic.Type; - -/** - * This class takes a given JavaClass object and converts it to a - * Java program that creates that very class using BCEL. This - * gives new users of BCEL a useful example showing how things - * are done with BCEL. It does not cover all features of BCEL, - * but tries to mimic hand-written code as close as possible. - * - * @version $Id: BCELifier.java,v 1.3.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - */ -public class BCELifier extends org.aspectj.apache.bcel.classfile.EmptyVisitor { - private JavaClass _clazz; - private PrintWriter _out; - private ConstantPool _cp; - - /** @param clazz Java class to "decompile" - * @param out where to output Java program - */ - public BCELifier(JavaClass clazz, OutputStream out) { - _clazz = clazz; - _out = new PrintWriter(out); - _cp = new ConstantPool(_clazz.getConstantPool().getConstantPool()); - } - - /** Start Java code generation - */ - public void start() { - visitJavaClass(_clazz); - _out.flush(); - } - - public void visitJavaClass(JavaClass clazz) { - String class_name = clazz.getClassName(); - String super_name = clazz.getSuperclassName(); - String package_name = clazz.getPackageName(); - String inter = Utility.printArray(clazz.getInterfaceNames(), - false, true); - if(!"".equals(package_name)) { - class_name = class_name.substring(package_name.length() + 1); - _out.println("package " + package_name + ";\n"); - } - - _out.println("import org.aspectj.apache.bcel.generic.*;"); - _out.println("import org.aspectj.apache.bcel.classfile.*;"); - _out.println("import org.aspectj.apache.bcel.*;"); - _out.println("import java.io.*;\n"); - - _out.println("public class " + class_name + "Creator implements Constants {"); - _out.println(" private InstructionFactory _factory;"); - _out.println(" private ConstantPoolGen _cp;"); - _out.println(" private ClassGen _cg;\n"); - - _out.println(" public " + class_name + "Creator() {"); - _out.println(" _cg = new ClassGen(\"" + - (("".equals(package_name))? class_name : - package_name + "." + class_name) + - "\", \"" + super_name + "\", " + - "\"" + clazz.getSourceFileName() + "\", " + - printFlags(clazz.getAccessFlags(), true) + ", " + - "new String[] { " + inter + " });\n"); - - _out.println(" _cp = _cg.getConstantPool();"); - _out.println(" _factory = new InstructionFactory(_cg, _cp);"); - _out.println(" }\n"); - - printCreate(); - - Field[] fields = clazz.getFields(); - - if(fields.length > 0) { - _out.println(" private void createFields() {"); - _out.println(" FieldGen field;"); - - for(int i=0; i < fields.length; i++) { - fields[i].accept(this); - } - - _out.println(" }\n"); - } - - Method[] methods = clazz.getMethods(); - - for(int i=0; i < methods.length; i++) { - _out.println(" private void createMethod_" + i + "() {"); - - methods[i].accept(this); - _out.println(" }\n"); - } - - printMain(); - _out.println("}"); - } - - private void printCreate() { - _out.println(" public void create(OutputStream out) throws IOException {"); - - Field[] fields = _clazz.getFields(); - if(fields.length > 0) { - _out.println(" createFields();"); - } - - Method[] methods = _clazz.getMethods(); - for(int i=0; i < methods.length; i++) { - _out.println(" createMethod_" + i + "();"); - } - - _out.println(" _cg.getJavaClass().dump(out);"); - - _out.println(" }\n"); - } - - private void printMain() { - String class_name = _clazz.getClassName(); - - _out.println(" public static void main(String[] args) throws Exception {"); - _out.println(" " + class_name + "Creator creator = new " + - class_name + "Creator();"); - _out.println(" creator.create(new FileOutputStream(\"" + class_name + - ".class\"));"); - _out.println(" }"); - } - - public void visitField(Field field) { - _out.println("\n field = new FieldGen(" + - printFlags(field.getAccessFlags()) + - ", " + printType(field.getSignature()) + ", \"" + - field.getName() + "\", _cp);"); - - ConstantValue cv = field.getConstantValue(); - - if(cv != null) { - String value = cv.toString(); - _out.println(" field.setInitValue(" + value + ")"); - } - - _out.println(" _cg.addField(field.getField());"); - } - - public void visitMethod(Method method) { - MethodGen mg = new MethodGen(method, _clazz.getClassName(), _cp); - - Type result_type = mg.getReturnType(); - Type[] arg_types = mg.getArgumentTypes(); - - _out.println(" InstructionList il = new InstructionList();"); - _out.println(" MethodGen method = new MethodGen(" + - printFlags(method.getAccessFlags()) + - ", " + printType(result_type) + - ", " + printArgumentTypes(arg_types) + ", " + - "new String[] { " + - Utility.printArray(mg.getArgumentNames(), false, true) + - " }, \"" + method.getName() + "\", \"" + - _clazz.getClassName() + "\", il, _cp);\n"); - - BCELFactory factory = new BCELFactory(mg, _out); - factory.start(); - - _out.println(" method.setMaxStack();"); - _out.println(" method.setMaxLocals();"); - _out.println(" _cg.addMethod(method.getMethod());"); - _out.println(" il.dispose();"); - } - - static String printFlags(int flags) { - return printFlags(flags, false); - } - - static String printFlags(int flags, boolean for_class) { - if(flags == 0) - return "0"; - - StringBuffer buf = new StringBuffer(); - for(int i=0, pow=1; i <= Constants.MAX_ACC_FLAG; i++) { - if((flags & pow) != 0) { - if((pow == Constants.ACC_SYNCHRONIZED) && for_class) - buf.append("ACC_SUPER | "); - else - buf.append("ACC_" + Constants.ACCESS_NAMES[i].toUpperCase() + " | "); - } - - pow <<= 1; - } - - String str = buf.toString(); - return str.substring(0, str.length() - 3); - } - - static String printArgumentTypes(Type[] arg_types) { - if(arg_types.length == 0) - return "Type.NO_ARGS"; - - StringBuffer args = new StringBuffer(); - - for(int i=0; i < arg_types.length; i++) { - args.append(printType(arg_types[i])); - - if(i < arg_types.length - 1) - args.append(", "); - } - - return "new Type[] { " + args.toString() + " }"; - } - - static String printType(Type type) { - return printType(type.getSignature()); - } - - static String printType(String signature) { - Type type = Type.getType(signature); - byte t = type.getType(); - - if(t <= Constants.T_VOID) { - return "Type." + Constants.TYPE_NAMES[t].toUpperCase(); - } else if(type.toString().equals("java.lang.String")) { - return "Type.STRING"; - } else if(type.toString().equals("java.lang.Object")) { - return "Type.OBJECT"; - } else if(type.toString().equals("java.lang.StringBuffer")) { - return "Type.STRINGBUFFER"; - } else if(type instanceof ArrayType) { - ArrayType at = (ArrayType)type; - - return "new ArrayType(" + printType(at.getBasicType()) + - ", " + at.getDimensions() + ")"; - } else { - return "new ObjectType(\"" + Utility.signatureToString(signature, false) + - "\")"; - } - } - - /** Default main method - */ - public static void main(String[] argv) throws Exception { - JavaClass java_class; - String name = argv[0]; - - if((java_class = Repository.lookupClass(name)) == null) - java_class = new ClassParser(name).parse(); // May throw IOException - - BCELifier bcelifier = new BCELifier(java_class, System.out); - bcelifier.start(); - } -} +package org.aspectj.apache.bcel.verifier.util; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +import java.io.OutputStream; +import java.io.PrintWriter; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.Repository; +import org.aspectj.apache.bcel.classfile.ClassParser; +import org.aspectj.apache.bcel.classfile.ConstantValue; +import org.aspectj.apache.bcel.classfile.Field; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.classfile.Utility; +import org.aspectj.apache.bcel.generic.ArrayType; +import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.generic.MethodGen; +import org.aspectj.apache.bcel.generic.Type; + +/** + * This class takes a given JavaClass object and converts it to a + * Java program that creates that very class using BCEL. This + * gives new users of BCEL a useful example showing how things + * are done with BCEL. It does not cover all features of BCEL, + * but tries to mimic hand-written code as close as possible. + * + * @version $Id: BCELifier.java,v 1.1.2.1 2008/05/08 19:26:53 aclement Exp $ + * @author M. Dahm + */ +public class BCELifier extends org.aspectj.apache.bcel.verifier.EmptyClassVisitor { + private JavaClass _clazz; + private PrintWriter _out; + private ConstantPool _cp; + + /** @param clazz Java class to "decompile" + * @param out where to output Java program + */ + public BCELifier(JavaClass clazz, OutputStream out) { + _clazz = clazz; + _out = new PrintWriter(out); + _cp = new ConstantPool(_clazz.getConstantPool().getConstantPool()); + } + + /** Start Java code generation + */ + public void start() { + visitJavaClass(_clazz); + _out.flush(); + } + + public void visitJavaClass(JavaClass clazz) { + String class_name = clazz.getClassName(); + String super_name = clazz.getSuperclassName(); + String package_name = clazz.getPackageName(); + String inter = BCELifier.printArray(clazz.getInterfaceNames(), + false, true); + if(!"".equals(package_name)) { + class_name = class_name.substring(package_name.length() + 1); + _out.println("package " + package_name + ";\n"); + } + + _out.println("import org.aspectj.apache.bcel.generic.*;"); + _out.println("import org.aspectj.apache.bcel.classfile.*;"); + _out.println("import org.aspectj.apache.bcel.*;"); + _out.println("import java.io.*;\n"); + + _out.println("public class " + class_name + "Creator implements Constants {"); + _out.println(" private InstructionFactory _factory;"); + _out.println(" private ConstantPoolGen _cp;"); + _out.println(" private ClassGen _cg;\n"); + + _out.println(" public " + class_name + "Creator() {"); + _out.println(" _cg = new ClassGen(\"" + + (("".equals(package_name))? class_name : + package_name + "." + class_name) + + "\", \"" + super_name + "\", " + + "\"" + clazz.getSourceFileName() + "\", " + + printFlags(clazz.getModifiers(), true) + ", " + + "new String[] { " + inter + " });\n"); + + _out.println(" _cp = _cg.getConstantPool();"); + _out.println(" _factory = new InstructionFactory(_cg, _cp);"); + _out.println(" }\n"); + + printCreate(); + + Field[] fields = clazz.getFields(); + + if(fields.length > 0) { + _out.println(" private void createFields() {"); + _out.println(" FieldGen field;"); + + for(int i=0; i < fields.length; i++) { + fields[i].accept(this); + } + + _out.println(" }\n"); + } + + Method[] methods = clazz.getMethods(); + + for(int i=0; i < methods.length; i++) { + _out.println(" private void createMethod_" + i + "() {"); + + methods[i].accept(this); + _out.println(" }\n"); + } + + printMain(); + _out.println("}"); + } + + private void printCreate() { + _out.println(" public void create(OutputStream out) throws IOException {"); + + Field[] fields = _clazz.getFields(); + if(fields.length > 0) { + _out.println(" createFields();"); + } + + Method[] methods = _clazz.getMethods(); + for(int i=0; i < methods.length; i++) { + _out.println(" createMethod_" + i + "();"); + } + + _out.println(" _cg.getJavaClass().dump(out);"); + + _out.println(" }\n"); + } + + private void printMain() { + String class_name = _clazz.getClassName(); + + _out.println(" public static void main(String[] args) throws Exception {"); + _out.println(" " + class_name + "Creator creator = new " + + class_name + "Creator();"); + _out.println(" creator.create(new FileOutputStream(\"" + class_name + + ".class\"));"); + _out.println(" }"); + } + + public void visitField(Field field) { + _out.println("\n field = new FieldGen(" + + printFlags(field.getModifiers()) + + ", " + printType(field.getSignature()) + ", \"" + + field.getName() + "\", _cp);"); + + ConstantValue cv = field.getConstantValue(); + + if(cv != null) { + String value = cv.toString(); + _out.println(" field.setInitValue(" + value + ")"); + } + + _out.println(" _cg.addField(field.getField());"); + } + + public void visitMethod(Method method) { + MethodGen mg = new MethodGen(method, _clazz.getClassName(), _cp); + + Type result_type = mg.getReturnType(); + Type[] arg_types = mg.getArgumentTypes(); + + _out.println(" InstructionList il = new InstructionList();"); + _out.println(" MethodGen method = new MethodGen(" + + printFlags(method.getModifiers()) + + ", " + printType(result_type) + + ", " + printArgumentTypes(arg_types) + ", " + + "new String[] { " + + BCELifier.printArray(mg.getArgumentNames(), false, true) + + " }, \"" + method.getName() + "\", \"" + + _clazz.getClassName() + "\", il, _cp);\n"); + + BCELFactory factory = new BCELFactory(mg, _out); + factory.start(); + + _out.println(" method.setMaxStack();"); + _out.println(" method.setMaxLocals();"); + _out.println(" _cg.addMethod(method.getMethod());"); + _out.println(" il.dispose();"); + } + + public static final String printArray(Object[] obj, boolean braces, + boolean quote) { + if(obj == null) + return null; + + StringBuffer buf = new StringBuffer(); + if(braces) + buf.append('{'); + + for(int i=0; i < obj.length; i++) { + if(obj[i] != null) { + buf.append((quote? "\"" : "") + obj[i].toString() + (quote? "\"" : "")); + } else { + buf.append("null"); + } + + if(i < obj.length - 1) { + buf.append(", "); + } + } + + if(braces) + buf.append('}'); + + return buf.toString(); + } + +static String printFlags(int flags) { + return printFlags(flags, false); + } + + static String printFlags(int flags, boolean for_class) { + if(flags == 0) + return "0"; + + StringBuffer buf = new StringBuffer(); + for(int i=0, pow=1; i <= Constants.MAX_ACC_FLAG; i++) { + if((flags & pow) != 0) { + if((pow == Constants.ACC_SYNCHRONIZED) && for_class) + buf.append("ACC_SUPER | "); + else + buf.append("ACC_" + Constants.ACCESS_NAMES[i].toUpperCase() + " | "); + } + + pow <<= 1; + } + + String str = buf.toString(); + return str.substring(0, str.length() - 3); + } + + static String printArgumentTypes(Type[] arg_types) { + if(arg_types.length == 0) + return "Type.NO_ARGS"; + + StringBuffer args = new StringBuffer(); + + for(int i=0; i < arg_types.length; i++) { + args.append(printType(arg_types[i])); + + if(i < arg_types.length - 1) + args.append(", "); + } + + return "new Type[] { " + args.toString() + " }"; + } + + static String printType(Type type) { + return printType(type.getSignature()); + } + + static String printType(String signature) { + Type type = Type.getType(signature); + byte t = type.getType(); + + if(t <= Constants.T_VOID) { + return "Type." + Constants.TYPE_NAMES[t].toUpperCase(); + } else if(type.toString().equals("java.lang.String")) { + return "Type.STRING"; + } else if(type.toString().equals("java.lang.Object")) { + return "Type.OBJECT"; + } else if(type.toString().equals("java.lang.StringBuffer")) { + return "Type.STRINGBUFFER"; + } else if(type instanceof ArrayType) { + ArrayType at = (ArrayType)type; + + return "new ArrayType(" + printType(at.getBasicType()) + + ", " + at.getDimensions() + ")"; + } else { + return "new ObjectType(\"" + Utility.signatureToString(signature, false) + + "\")"; + } + } + + /** Default main method + */ + public static void main(String[] argv) throws Exception { + JavaClass java_class; + String name = argv[0]; + + if((java_class = Repository.lookupClass(name)) == null) + java_class = new ClassParser(name).parse(); // May throw IOException + + BCELifier bcelifier = new BCELifier(java_class, System.out); + bcelifier.start(); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/util/InstructionFinder.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/InstructionFinder.java similarity index 97% rename from bcel-builder/src/org/aspectj/apache/bcel/util/InstructionFinder.java rename to bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/InstructionFinder.java index 653ae6cd5..f2386910a 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/util/InstructionFinder.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/InstructionFinder.java @@ -1,440 +1,440 @@ -package org.aspectj.apache.bcel.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache BCEL" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache BCEL", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.util.*; -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.generic.*; -import org.apache.regexp.*; - -/** - * InstructionFinder is a tool to search for given instructions patterns, - * i.e., match sequences of instructions in an instruction list via - * regular expressions. This can be used, e.g., in order to implement - * a peep hole optimizer that looks for code patterns and replaces - * them with faster equivalents. - * - *

          This class internally uses the - * Regexp package to search for regular expressions. - * - * A typical application would look like this: -

          -    InstructionFinder f   = new InstructionFinder(il);
          -    String            pat = "IfInstruction ICONST_0 GOTO ICONST_1 NOP (IFEQ|IFNE)";
          -    
          -    for(Iterator i = f.search(pat, constraint); i.hasNext(); ) {
          -      InstructionHandle[] match = (InstructionHandle[])i.next();
          -      ...
          -      il.delete(match[1], match[5]);
          -      ...
          -    }
          -
          - * @version $Id: InstructionFinder.java,v 1.2.10.2 2008/04/25 17:55:36 aclement Exp $ - * @author M. Dahm - * @see Instruction - * @see InstructionList - */ -public class InstructionFinder { - private static final int OFFSET = 32767; // char + OFFSET is outside of LATIN-1 - private static final int NO_OPCODES = 256; // Potential number, some are not used - - private static final HashMap map = new HashMap(); // Map - - private InstructionList il; - private String il_string; // instruction list as string - private InstructionHandle[] handles; // map instruction list to array - - /** - * @param il instruction list to search for given patterns - */ - public InstructionFinder(InstructionList il) { - this.il = il; - reread(); - } - - /** - * Reread the instruction list, e.g., after you've altered the list upon a match. - */ - public final void reread() { - int size = il.getLength(); - char[] buf = new char[size]; // Create a string with length equal to il length - handles = il.getInstructionHandles(); - - // Map opcodes to characters - for(int i=0; i < size; i++) - buf[i] = makeChar(handles[i].getInstruction().getOpcode()); - - il_string = new String(buf); - } - - /** - * Map symbolic instruction names like "getfield" to a single character. - * - * @param pattern instruction pattern in lower case - * @return encoded string for a pattern such as "BranchInstruction". - */ - private static final String mapName(String pattern) { - String result = (String)map.get(pattern); - - if(result != null) - return result; - - for(short i=0; i < NO_OPCODES; i++) - if(pattern.equals(Constants.OPCODE_NAMES[i])) - return "" + makeChar(i); - - throw new RuntimeException("Instruction unknown: " + pattern); - } - - /** - * Replace symbolic names of instructions with the appropiate character and remove - * all white space from string. Meta characters such as +, * are ignored. - * - * @param pattern The pattern to compile - * @return translated regular expression string - */ - private static final String compilePattern(String pattern) { - String lower = pattern.toLowerCase(); - StringBuffer buf = new StringBuffer(); - int size = pattern.length(); - - for(int i=0; i < size; i++) { - char ch = lower.charAt(i); - - if(Character.isLetterOrDigit(ch)) { - StringBuffer name = new StringBuffer(); - - while((Character.isLetterOrDigit(ch) || ch == '_') && i < size) { - name.append(ch); - - if(++i < size) - ch = lower.charAt(i); - else - break; - } - - i--; - - buf.append(mapName(name.toString())); - } else if(!Character.isWhitespace(ch)) - buf.append(ch); - } - - return buf.toString(); - } - - /** - * @return the matched piece of code as an array of instruction (handles) - */ - private InstructionHandle[] getMatch(int matched_from, int match_length) { - InstructionHandle[] match = new InstructionHandle[match_length]; - System.arraycopy(handles, matched_from, match, 0, match_length); - - return match; - } - - /** - * Search for the given pattern in the instruction list. You can search for any valid - * opcode via its symbolic name, e.g. "istore". You can also use a super class or - * an interface name to match a whole set of instructions, e.g. "BranchInstruction" or - * "LoadInstruction". "istore" is also an alias for all "istore_x" instructions. Additional - * aliases are "if" for "ifxx", "if_icmp" for "if_icmpxx", "if_acmp" for "if_acmpxx". - * - * Consecutive instruction names must be separated by white space which will be removed - * during the compilation of the pattern. - * - * For the rest the usual pattern matching rules for regular expressions apply.

          - * Example pattern: - *

          -     search("BranchInstruction NOP ((IfInstruction|GOTO)+ ISTORE Instruction)*");
          -   * 
          - * - *

          If you alter the instruction list upon a match such that other - * matching areas are affected, you should call reread() to update - * the finder and call search() again, because the matches are cached. - * - * @param pattern the instruction pattern to search for, where case is ignored - * @param from where to start the search in the instruction list - * @param constraint optional CodeConstraint to check the found code pattern for - * user-defined constraints - * @return iterator of matches where e.nextElement() returns an array of instruction handles - * describing the matched area - */ - public final Iterator search(String pattern, InstructionHandle from, - CodeConstraint constraint) - { - String search = compilePattern(pattern); - int start = -1; - - for(int i=0; i < handles.length; i++) { - if(handles[i] == from) { - start = i; // Where to start search from (index) - break; - } - } - - if(start == -1) - throw new ClassGenException("Instruction handle " + from + - " not found in instruction list."); - try { - RE regex = new RE(search); - ArrayList matches = new ArrayList(); - - while(start < il_string.length() && regex.match(il_string, start)) { - int startExpr = regex.getParenStart(0); - int endExpr = regex.getParenEnd(0); - int lenExpr = regex.getParenLength(0); - - InstructionHandle[] match = getMatch(startExpr, lenExpr); - - if((constraint == null) || constraint.checkCode(match)) - matches.add(match); - start = endExpr; - } - - return matches.iterator(); - } catch(RESyntaxException e) { - System.err.println(e); - } - - return null; - } - - /** - * Start search beginning from the start of the given instruction list. - * - * @param pattern the instruction pattern to search for, where case is ignored - * @return iterator of matches where e.nextElement() - * returns an array of instruction handles describing the matched - * area - */ - public final Iterator search(String pattern) { - return search(pattern, il.getStart(), null); - } - - /** - * Start search beginning from `from'. - * - * @param pattern the instruction pattern to search for, where case is ignored - * @param from where to start the search in the instruction list - * @return iterator of matches where e.nextElement() returns an array of instruction handles - * describing the matched area - */ - public final Iterator search(String pattern, InstructionHandle from) { - return search(pattern, from, null); - } - - /** - * Start search beginning from the start of the given instruction list. - * Check found matches with the constraint object. - * - * @param pattern the instruction pattern to search for, case is ignored - * @param constraint constraints to be checked on matching code - * @return instruction handle or `null' if the match failed - */ - public final Iterator search(String pattern, CodeConstraint constraint) { - return search(pattern, il.getStart(), constraint); - } - - /** - * Convert opcode number to char. - */ - private static final char makeChar(short opcode) { - return (char)(opcode + OFFSET); - } - - /** - * @return the inquired instruction list - */ - public final InstructionList getInstructionList() { return il; } - - /** - * Code patterns found may be checked using an additional - * user-defined constraint object whether they really match the needed criterion. - * I.e., check constraints that can not expressed with regular expressions. - * - */ - public interface CodeConstraint { - /** - * @param match array of instructions matching the requested pattern - * @return true if the matched area is really useful - */ - public boolean checkCode(InstructionHandle[] match); - } - - // Initialize pattern map - - static { - map.put("arithmeticinstruction", "(irem|lrem|iand|ior|ineg|isub|lneg|fneg|fmul|ldiv|fadd|lxor|frem|idiv|land|ixor|ishr|fsub|lshl|fdiv|iadd|lor|dmul|lsub|ishl|imul|lmul|lushr|dneg|iushr|lshr|ddiv|drem|dadd|ladd|dsub)"); - map.put("invokeinstruction", "(invokevirtual|invokeinterface|invokestatic|invokespecial)"); - map.put("arrayinstruction", "(baload|aastore|saload|caload|fastore|lastore|iaload|castore|iastore|aaload|bastore|sastore|faload|laload|daload|dastore)"); - map.put("gotoinstruction", "(goto|goto_w)"); - map.put("conversioninstruction", "(d2l|l2d|i2s|d2i|l2i|i2b|l2f|d2f|f2i|i2d|i2l|f2d|i2c|f2l|i2f)"); - map.put("localvariableinstruction", "(fstore|iinc|lload|dstore|dload|iload|aload|astore|istore|fload|lstore)"); - map.put("loadinstruction", "(fload|dload|lload|iload|aload)"); - map.put("fieldinstruction", "(getfield|putstatic|getstatic|putfield)"); - map.put("cpinstruction", "(ldc2_w|invokeinterface|multianewarray|putstatic|instanceof|getstatic|checkcast|getfield|invokespecial|ldc_w|invokestatic|invokevirtual|putfield|ldc|new|anewarray)"); - map.put("stackinstruction", "(dup2|swap|dup2_x2|pop|pop2|dup|dup2_x1|dup_x2|dup_x1)"); - map.put("branchinstruction", "(ifle|if_acmpne|if_icmpeq|if_acmpeq|ifnonnull|goto_w|iflt|ifnull|if_icmpne|tableswitch|if_icmple|ifeq|if_icmplt|jsr_w|if_icmpgt|ifgt|jsr|goto|ifne|ifge|lookupswitch|if_icmpge)"); - map.put("returninstruction", "(lreturn|ireturn|freturn|dreturn|areturn|return)"); - map.put("storeinstruction", "(istore|fstore|dstore|astore|lstore)"); - map.put("select", "(tableswitch|lookupswitch)"); - map.put("ifinstruction", "(ifeq|ifgt|if_icmpne|if_icmpeq|ifge|ifnull|ifne|if_icmple|if_icmpge|if_acmpeq|if_icmplt|if_acmpne|ifnonnull|iflt|if_icmpgt|ifle)"); - map.put("jsrinstruction", "(jsr|jsr_w)"); - map.put("variablelengthinstruction", "(tableswitch|jsr|goto|lookupswitch)"); - map.put("unconditionalbranch", "(goto|jsr|jsr_w|athrow|goto_w)"); - map.put("constantpushinstruction", "(dconst|bipush|sipush|fconst|iconst|lconst)"); - map.put("typedinstruction", "(imul|lsub|aload|fload|lor|new|aaload|fcmpg|iand|iaload|lrem|idiv|d2l|isub|dcmpg|dastore|ret|f2d|f2i|drem|iinc|i2c|checkcast|frem|lreturn|astore|lushr|daload|dneg|fastore|istore|lshl|ldiv|lstore|areturn|ishr|ldc_w|invokeinterface|aastore|lxor|ishl|l2d|i2f|return|faload|sipush|iushr|caload|instanceof|invokespecial|putfield|fmul|ireturn|laload|d2f|lneg|ixor|i2l|fdiv|lastore|multianewarray|i2b|getstatic|i2d|putstatic|fcmpl|saload|ladd|irem|dload|jsr_w|dconst|dcmpl|fsub|freturn|ldc|aconst_null|castore|lmul|ldc2_w|dadd|iconst|f2l|ddiv|dstore|land|jsr|anewarray|dmul|bipush|dsub|sastore|d2i|i2s|lshr|iadd|l2i|lload|bastore|fstore|fneg|iload|fadd|baload|fconst|ior|ineg|dreturn|l2f|lconst|getfield|invokevirtual|invokestatic|iastore)"); - map.put("popinstruction", "(fstore|dstore|pop|pop2|astore|putstatic|istore|lstore)"); - map.put("allocationinstruction", "(multianewarray|new|anewarray|newarray)"); - map.put("indexedinstruction", "(lload|lstore|fload|ldc2_w|invokeinterface|multianewarray|astore|dload|putstatic|instanceof|getstatic|checkcast|getfield|invokespecial|dstore|istore|iinc|ldc_w|ret|fstore|invokestatic|iload|putfield|invokevirtual|ldc|new|aload|anewarray)"); - map.put("pushinstruction", "(dup|lload|dup2|bipush|fload|ldc2_w|sipush|lconst|fconst|dload|getstatic|ldc_w|aconst_null|dconst|iload|ldc|iconst|aload)"); - map.put("stackproducer", "(imul|lsub|aload|fload|lor|new|aaload|fcmpg|iand|iaload|lrem|idiv|d2l|isub|dcmpg|dup|f2d|f2i|drem|i2c|checkcast|frem|lushr|daload|dneg|lshl|ldiv|ishr|ldc_w|invokeinterface|lxor|ishl|l2d|i2f|faload|sipush|iushr|caload|instanceof|invokespecial|fmul|laload|d2f|lneg|ixor|i2l|fdiv|getstatic|i2b|swap|i2d|dup2|fcmpl|saload|ladd|irem|dload|jsr_w|dconst|dcmpl|fsub|ldc|arraylength|aconst_null|tableswitch|lmul|ldc2_w|iconst|dadd|f2l|ddiv|land|jsr|anewarray|dmul|bipush|dsub|d2i|newarray|i2s|lshr|iadd|lload|l2i|fneg|iload|fadd|baload|fconst|lookupswitch|ior|ineg|lconst|l2f|getfield|invokevirtual|invokestatic)"); - map.put("stackconsumer", "(imul|lsub|lor|iflt|fcmpg|if_icmpgt|iand|ifeq|if_icmplt|lrem|ifnonnull|idiv|d2l|isub|dcmpg|dastore|if_icmpeq|f2d|f2i|drem|i2c|checkcast|frem|lreturn|astore|lushr|pop2|monitorexit|dneg|fastore|istore|lshl|ldiv|lstore|areturn|if_icmpge|ishr|monitorenter|invokeinterface|aastore|lxor|ishl|l2d|i2f|return|iushr|instanceof|invokespecial|fmul|ireturn|d2f|lneg|ixor|pop|i2l|ifnull|fdiv|lastore|i2b|if_acmpeq|ifge|swap|i2d|putstatic|fcmpl|ladd|irem|dcmpl|fsub|freturn|ifgt|castore|lmul|dadd|f2l|ddiv|dstore|land|if_icmpne|if_acmpne|dmul|dsub|sastore|ifle|d2i|i2s|lshr|iadd|l2i|bastore|fstore|fneg|fadd|ior|ineg|ifne|dreturn|l2f|if_icmple|getfield|invokevirtual|invokestatic|iastore)"); - map.put("exceptionthrower", "(irem|lrem|laload|putstatic|baload|dastore|areturn|getstatic|ldiv|anewarray|iastore|castore|idiv|saload|lastore|fastore|putfield|lreturn|caload|getfield|return|aastore|freturn|newarray|instanceof|multianewarray|athrow|faload|iaload|aaload|dreturn|monitorenter|checkcast|bastore|arraylength|new|invokevirtual|sastore|ldc_w|ireturn|invokespecial|monitorexit|invokeinterface|ldc|invokestatic|daload)"); - map.put("loadclass", "(multianewarray|invokeinterface|instanceof|invokespecial|putfield|checkcast|putstatic|invokevirtual|new|getstatic|invokestatic|getfield|anewarray)"); - map.put("instructiontargeter", "(ifle|if_acmpne|if_icmpeq|if_acmpeq|ifnonnull|goto_w|iflt|ifnull|if_icmpne|tableswitch|if_icmple|ifeq|if_icmplt|jsr_w|if_icmpgt|ifgt|jsr|goto|ifne|ifge|lookupswitch|if_icmpge)"); - - // Some aliases - map.put("if_icmp", "(if_icmpne|if_icmpeq|if_icmple|if_icmpge|if_icmplt|if_icmpgt)"); - map.put("if_acmp", "(if_acmpeq|if_acmpne)"); - map.put("if", "(ifeq|ifne|iflt|ifge|ifgt|ifle)"); - - // Precompile some aliases first - map.put("iconst", precompile(Constants.ICONST_0, Constants.ICONST_5, Constants.ICONST_M1)); - map.put("lconst", new String(new char[] { '(', makeChar(Constants.LCONST_0), '|', - makeChar(Constants.LCONST_1), ')' })); - map.put("dconst", new String(new char[] { '(', makeChar(Constants.DCONST_0), '|', - makeChar(Constants.DCONST_1), ')' })); - map.put("fconst", new String(new char[] { '(', makeChar(Constants.FCONST_0), '|', - makeChar(Constants.FCONST_1), ')' })); - - map.put("iload", precompile(Constants.ILOAD_0, Constants.ILOAD_3, Constants.ILOAD)); - map.put("dload", precompile(Constants.DLOAD_0, Constants.DLOAD_3, Constants.DLOAD)); - map.put("fload", precompile(Constants.FLOAD_0, Constants.FLOAD_3, Constants.FLOAD)); - map.put("aload", precompile(Constants.ALOAD_0, Constants.ALOAD_3, Constants.ALOAD)); - - map.put("istore", precompile(Constants.ISTORE_0, Constants.ISTORE_3, Constants.ISTORE)); - map.put("dstore", precompile(Constants.DSTORE_0, Constants.DSTORE_3, Constants.DSTORE)); - map.put("fstore", precompile(Constants.FSTORE_0, Constants.FSTORE_3, Constants.FSTORE)); - map.put("astore", precompile(Constants.ASTORE_0, Constants.ASTORE_3, Constants.ASTORE)); - - // Compile strings - - for(Iterator i = map.keySet().iterator(); i.hasNext(); ) { - String key = (String)i.next(); - String value = (String)map.get(key); - - char ch = value.charAt(1); // Omit already precompiled patterns - if(ch < OFFSET) { - map.put(key, compilePattern(value)); // precompile all patterns - } - } - - // Add instruction alias to match anything - - StringBuffer buf = new StringBuffer("("); - - for(short i=0; i < NO_OPCODES; i++) { - if(Constants.iLen[i] != Constants.UNDEFINED_LENGTH) { // Not an invalid opcode - buf.append(makeChar(i)); - - if(i < NO_OPCODES - 1) - buf.append('|'); - } - } - buf.append(')'); - - map.put("instruction", buf.toString()); - } - - private static String precompile(short from, short to, short extra) { - StringBuffer buf = new StringBuffer("("); - - for(short i=from; i <= to; i++) { - buf.append(makeChar(i)); - buf.append('|'); - } - - buf.append(makeChar(extra)); - buf.append(")"); - return buf.toString(); - } - - /* - * Internal debugging routines. - */ - private static final String pattern2string(String pattern) { - return pattern2string(pattern, true); - } - - private static final String pattern2string(String pattern, boolean make_string) { - StringBuffer buf = new StringBuffer(); - - for(int i=0; i < pattern.length(); i++) { - char ch = pattern.charAt(i); - - if(ch >= OFFSET) { - if(make_string) - buf.append(Constants.OPCODE_NAMES[ch - OFFSET]); - else - buf.append((int)(ch - OFFSET)); - } else - buf.append(ch); - } - - return buf.toString(); - } -} +package org.aspectj.apache.bcel.verifier.util; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache BCEL" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache BCEL", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.util.*; +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.generic.*; +import org.apache.regexp.*; + +/** + * InstructionFinder is a tool to search for given instructions patterns, + * i.e., match sequences of instructions in an instruction list via + * regular expressions. This can be used, e.g., in order to implement + * a peep hole optimizer that looks for code patterns and replaces + * them with faster equivalents. + * + *

          This class internally uses the + * Regexp package to search for regular expressions. + * + * A typical application would look like this: +

          +    InstructionFinder f   = new InstructionFinder(il);
          +    String            pat = "IfInstruction ICONST_0 GOTO ICONST_1 NOP (IFEQ|IFNE)";
          +    
          +    for(Iterator i = f.search(pat, constraint); i.hasNext(); ) {
          +      InstructionHandle[] match = (InstructionHandle[])i.next();
          +      ...
          +      il.delete(match[1], match[5]);
          +      ...
          +    }
          +
          + * @version $Id: InstructionFinder.java,v 1.1.2.1 2008/05/08 19:26:53 aclement Exp $ + * @author M. Dahm + * @see Instruction + * @see InstructionList + */ +public class InstructionFinder { + private static final int OFFSET = 32767; // char + OFFSET is outside of LATIN-1 + private static final int NO_OPCODES = 256; // Potential number, some are not used + + private static final HashMap map = new HashMap(); // Map + + private InstructionList il; + private String il_string; // instruction list as string + private InstructionHandle[] handles; // map instruction list to array + + /** + * @param il instruction list to search for given patterns + */ + public InstructionFinder(InstructionList il) { + this.il = il; + reread(); + } + + /** + * Reread the instruction list, e.g., after you've altered the list upon a match. + */ + public final void reread() { + int size = il.getLength(); + char[] buf = new char[size]; // Create a string with length equal to il length + handles = il.getInstructionHandles(); + + // Map opcodes to characters + for(int i=0; i < size; i++) + buf[i] = makeChar(handles[i].getInstruction().getOpcode()); + + il_string = new String(buf); + } + + /** + * Map symbolic instruction names like "getfield" to a single character. + * + * @param pattern instruction pattern in lower case + * @return encoded string for a pattern such as "BranchInstruction". + */ + private static final String mapName(String pattern) { + String result = (String)map.get(pattern); + + if(result != null) + return result; + + for(short i=0; i < NO_OPCODES; i++) + if(pattern.equals(Constants.OPCODE_NAMES[i])) + return "" + makeChar(i); + + throw new RuntimeException("Instruction unknown: " + pattern); + } + + /** + * Replace symbolic names of instructions with the appropiate character and remove + * all white space from string. Meta characters such as +, * are ignored. + * + * @param pattern The pattern to compile + * @return translated regular expression string + */ + private static final String compilePattern(String pattern) { + String lower = pattern.toLowerCase(); + StringBuffer buf = new StringBuffer(); + int size = pattern.length(); + + for(int i=0; i < size; i++) { + char ch = lower.charAt(i); + + if(Character.isLetterOrDigit(ch)) { + StringBuffer name = new StringBuffer(); + + while((Character.isLetterOrDigit(ch) || ch == '_') && i < size) { + name.append(ch); + + if(++i < size) + ch = lower.charAt(i); + else + break; + } + + i--; + + buf.append(mapName(name.toString())); + } else if(!Character.isWhitespace(ch)) + buf.append(ch); + } + + return buf.toString(); + } + + /** + * @return the matched piece of code as an array of instruction (handles) + */ + private InstructionHandle[] getMatch(int matched_from, int match_length) { + InstructionHandle[] match = new InstructionHandle[match_length]; + System.arraycopy(handles, matched_from, match, 0, match_length); + + return match; + } + + /** + * Search for the given pattern in the instruction list. You can search for any valid + * opcode via its symbolic name, e.g. "istore". You can also use a super class or + * an interface name to match a whole set of instructions, e.g. "BranchInstruction" or + * "LoadInstruction". "istore" is also an alias for all "istore_x" instructions. Additional + * aliases are "if" for "ifxx", "if_icmp" for "if_icmpxx", "if_acmp" for "if_acmpxx". + * + * Consecutive instruction names must be separated by white space which will be removed + * during the compilation of the pattern. + * + * For the rest the usual pattern matching rules for regular expressions apply.

          + * Example pattern: + *

          +     search("BranchInstruction NOP ((IfInstruction|GOTO)+ ISTORE Instruction)*");
          +   * 
          + * + *

          If you alter the instruction list upon a match such that other + * matching areas are affected, you should call reread() to update + * the finder and call search() again, because the matches are cached. + * + * @param pattern the instruction pattern to search for, where case is ignored + * @param from where to start the search in the instruction list + * @param constraint optional CodeConstraint to check the found code pattern for + * user-defined constraints + * @return iterator of matches where e.nextElement() returns an array of instruction handles + * describing the matched area + */ + public final Iterator search(String pattern, InstructionHandle from, + CodeConstraint constraint) + { + String search = compilePattern(pattern); + int start = -1; + + for(int i=0; i < handles.length; i++) { + if(handles[i] == from) { + start = i; // Where to start search from (index) + break; + } + } + + if(start == -1) + throw new ClassGenException("Instruction handle " + from + + " not found in instruction list."); + try { + RE regex = new RE(search); + ArrayList matches = new ArrayList(); + + while(start < il_string.length() && regex.match(il_string, start)) { + int startExpr = regex.getParenStart(0); + int endExpr = regex.getParenEnd(0); + int lenExpr = regex.getParenLength(0); + + InstructionHandle[] match = getMatch(startExpr, lenExpr); + + if((constraint == null) || constraint.checkCode(match)) + matches.add(match); + start = endExpr; + } + + return matches.iterator(); + } catch(RESyntaxException e) { + System.err.println(e); + } + + return null; + } + + /** + * Start search beginning from the start of the given instruction list. + * + * @param pattern the instruction pattern to search for, where case is ignored + * @return iterator of matches where e.nextElement() + * returns an array of instruction handles describing the matched + * area + */ + public final Iterator search(String pattern) { + return search(pattern, il.getStart(), null); + } + + /** + * Start search beginning from `from'. + * + * @param pattern the instruction pattern to search for, where case is ignored + * @param from where to start the search in the instruction list + * @return iterator of matches where e.nextElement() returns an array of instruction handles + * describing the matched area + */ + public final Iterator search(String pattern, InstructionHandle from) { + return search(pattern, from, null); + } + + /** + * Start search beginning from the start of the given instruction list. + * Check found matches with the constraint object. + * + * @param pattern the instruction pattern to search for, case is ignored + * @param constraint constraints to be checked on matching code + * @return instruction handle or `null' if the match failed + */ + public final Iterator search(String pattern, CodeConstraint constraint) { + return search(pattern, il.getStart(), constraint); + } + + /** + * Convert opcode number to char. + */ + private static final char makeChar(short opcode) { + return (char)(opcode + OFFSET); + } + + /** + * @return the inquired instruction list + */ + public final InstructionList getInstructionList() { return il; } + + /** + * Code patterns found may be checked using an additional + * user-defined constraint object whether they really match the needed criterion. + * I.e., check constraints that can not expressed with regular expressions. + * + */ + public interface CodeConstraint { + /** + * @param match array of instructions matching the requested pattern + * @return true if the matched area is really useful + */ + public boolean checkCode(InstructionHandle[] match); + } + + // Initialize pattern map + + static { + map.put("arithmeticinstruction", "(irem|lrem|iand|ior|ineg|isub|lneg|fneg|fmul|ldiv|fadd|lxor|frem|idiv|land|ixor|ishr|fsub|lshl|fdiv|iadd|lor|dmul|lsub|ishl|imul|lmul|lushr|dneg|iushr|lshr|ddiv|drem|dadd|ladd|dsub)"); + map.put("invokeinstruction", "(invokevirtual|invokeinterface|invokestatic|invokespecial)"); + map.put("arrayinstruction", "(baload|aastore|saload|caload|fastore|lastore|iaload|castore|iastore|aaload|bastore|sastore|faload|laload|daload|dastore)"); + map.put("gotoinstruction", "(goto|goto_w)"); + map.put("conversioninstruction", "(d2l|l2d|i2s|d2i|l2i|i2b|l2f|d2f|f2i|i2d|i2l|f2d|i2c|f2l|i2f)"); + map.put("localvariableinstruction", "(fstore|iinc|lload|dstore|dload|iload|aload|astore|istore|fload|lstore)"); + map.put("loadinstruction", "(fload|dload|lload|iload|aload)"); + map.put("fieldinstruction", "(getfield|putstatic|getstatic|putfield)"); + map.put("cpinstruction", "(ldc2_w|invokeinterface|multianewarray|putstatic|instanceof|getstatic|checkcast|getfield|invokespecial|ldc_w|invokestatic|invokevirtual|putfield|ldc|new|anewarray)"); + map.put("stackinstruction", "(dup2|swap|dup2_x2|pop|pop2|dup|dup2_x1|dup_x2|dup_x1)"); + map.put("branchinstruction", "(ifle|if_acmpne|if_icmpeq|if_acmpeq|ifnonnull|goto_w|iflt|ifnull|if_icmpne|tableswitch|if_icmple|ifeq|if_icmplt|jsr_w|if_icmpgt|ifgt|jsr|goto|ifne|ifge|lookupswitch|if_icmpge)"); + map.put("returninstruction", "(lreturn|ireturn|freturn|dreturn|areturn|return)"); + map.put("storeinstruction", "(istore|fstore|dstore|astore|lstore)"); + map.put("select", "(tableswitch|lookupswitch)"); + map.put("ifinstruction", "(ifeq|ifgt|if_icmpne|if_icmpeq|ifge|ifnull|ifne|if_icmple|if_icmpge|if_acmpeq|if_icmplt|if_acmpne|ifnonnull|iflt|if_icmpgt|ifle)"); + map.put("jsrinstruction", "(jsr|jsr_w)"); + map.put("variablelengthinstruction", "(tableswitch|jsr|goto|lookupswitch)"); + map.put("unconditionalbranch", "(goto|jsr|jsr_w|athrow|goto_w)"); + map.put("constantpushinstruction", "(dconst|bipush|sipush|fconst|iconst|lconst)"); + map.put("typedinstruction", "(imul|lsub|aload|fload|lor|new|aaload|fcmpg|iand|iaload|lrem|idiv|d2l|isub|dcmpg|dastore|ret|f2d|f2i|drem|iinc|i2c|checkcast|frem|lreturn|astore|lushr|daload|dneg|fastore|istore|lshl|ldiv|lstore|areturn|ishr|ldc_w|invokeinterface|aastore|lxor|ishl|l2d|i2f|return|faload|sipush|iushr|caload|instanceof|invokespecial|putfield|fmul|ireturn|laload|d2f|lneg|ixor|i2l|fdiv|lastore|multianewarray|i2b|getstatic|i2d|putstatic|fcmpl|saload|ladd|irem|dload|jsr_w|dconst|dcmpl|fsub|freturn|ldc|aconst_null|castore|lmul|ldc2_w|dadd|iconst|f2l|ddiv|dstore|land|jsr|anewarray|dmul|bipush|dsub|sastore|d2i|i2s|lshr|iadd|l2i|lload|bastore|fstore|fneg|iload|fadd|baload|fconst|ior|ineg|dreturn|l2f|lconst|getfield|invokevirtual|invokestatic|iastore)"); + map.put("popinstruction", "(fstore|dstore|pop|pop2|astore|putstatic|istore|lstore)"); + map.put("allocationinstruction", "(multianewarray|new|anewarray|newarray)"); + map.put("indexedinstruction", "(lload|lstore|fload|ldc2_w|invokeinterface|multianewarray|astore|dload|putstatic|instanceof|getstatic|checkcast|getfield|invokespecial|dstore|istore|iinc|ldc_w|ret|fstore|invokestatic|iload|putfield|invokevirtual|ldc|new|aload|anewarray)"); + map.put("pushinstruction", "(dup|lload|dup2|bipush|fload|ldc2_w|sipush|lconst|fconst|dload|getstatic|ldc_w|aconst_null|dconst|iload|ldc|iconst|aload)"); + map.put("stackproducer", "(imul|lsub|aload|fload|lor|new|aaload|fcmpg|iand|iaload|lrem|idiv|d2l|isub|dcmpg|dup|f2d|f2i|drem|i2c|checkcast|frem|lushr|daload|dneg|lshl|ldiv|ishr|ldc_w|invokeinterface|lxor|ishl|l2d|i2f|faload|sipush|iushr|caload|instanceof|invokespecial|fmul|laload|d2f|lneg|ixor|i2l|fdiv|getstatic|i2b|swap|i2d|dup2|fcmpl|saload|ladd|irem|dload|jsr_w|dconst|dcmpl|fsub|ldc|arraylength|aconst_null|tableswitch|lmul|ldc2_w|iconst|dadd|f2l|ddiv|land|jsr|anewarray|dmul|bipush|dsub|d2i|newarray|i2s|lshr|iadd|lload|l2i|fneg|iload|fadd|baload|fconst|lookupswitch|ior|ineg|lconst|l2f|getfield|invokevirtual|invokestatic)"); + map.put("stackconsumer", "(imul|lsub|lor|iflt|fcmpg|if_icmpgt|iand|ifeq|if_icmplt|lrem|ifnonnull|idiv|d2l|isub|dcmpg|dastore|if_icmpeq|f2d|f2i|drem|i2c|checkcast|frem|lreturn|astore|lushr|pop2|monitorexit|dneg|fastore|istore|lshl|ldiv|lstore|areturn|if_icmpge|ishr|monitorenter|invokeinterface|aastore|lxor|ishl|l2d|i2f|return|iushr|instanceof|invokespecial|fmul|ireturn|d2f|lneg|ixor|pop|i2l|ifnull|fdiv|lastore|i2b|if_acmpeq|ifge|swap|i2d|putstatic|fcmpl|ladd|irem|dcmpl|fsub|freturn|ifgt|castore|lmul|dadd|f2l|ddiv|dstore|land|if_icmpne|if_acmpne|dmul|dsub|sastore|ifle|d2i|i2s|lshr|iadd|l2i|bastore|fstore|fneg|fadd|ior|ineg|ifne|dreturn|l2f|if_icmple|getfield|invokevirtual|invokestatic|iastore)"); + map.put("exceptionthrower", "(irem|lrem|laload|putstatic|baload|dastore|areturn|getstatic|ldiv|anewarray|iastore|castore|idiv|saload|lastore|fastore|putfield|lreturn|caload|getfield|return|aastore|freturn|newarray|instanceof|multianewarray|athrow|faload|iaload|aaload|dreturn|monitorenter|checkcast|bastore|arraylength|new|invokevirtual|sastore|ldc_w|ireturn|invokespecial|monitorexit|invokeinterface|ldc|invokestatic|daload)"); + map.put("loadclass", "(multianewarray|invokeinterface|instanceof|invokespecial|putfield|checkcast|putstatic|invokevirtual|new|getstatic|invokestatic|getfield|anewarray)"); + map.put("instructiontargeter", "(ifle|if_acmpne|if_icmpeq|if_acmpeq|ifnonnull|goto_w|iflt|ifnull|if_icmpne|tableswitch|if_icmple|ifeq|if_icmplt|jsr_w|if_icmpgt|ifgt|jsr|goto|ifne|ifge|lookupswitch|if_icmpge)"); + + // Some aliases + map.put("if_icmp", "(if_icmpne|if_icmpeq|if_icmple|if_icmpge|if_icmplt|if_icmpgt)"); + map.put("if_acmp", "(if_acmpeq|if_acmpne)"); + map.put("if", "(ifeq|ifne|iflt|ifge|ifgt|ifle)"); + + // Precompile some aliases first + map.put("iconst", precompile(Constants.ICONST_0, Constants.ICONST_5, Constants.ICONST_M1)); + map.put("lconst", new String(new char[] { '(', makeChar(Constants.LCONST_0), '|', + makeChar(Constants.LCONST_1), ')' })); + map.put("dconst", new String(new char[] { '(', makeChar(Constants.DCONST_0), '|', + makeChar(Constants.DCONST_1), ')' })); + map.put("fconst", new String(new char[] { '(', makeChar(Constants.FCONST_0), '|', + makeChar(Constants.FCONST_1), ')' })); + + map.put("iload", precompile(Constants.ILOAD_0, Constants.ILOAD_3, Constants.ILOAD)); + map.put("dload", precompile(Constants.DLOAD_0, Constants.DLOAD_3, Constants.DLOAD)); + map.put("fload", precompile(Constants.FLOAD_0, Constants.FLOAD_3, Constants.FLOAD)); + map.put("aload", precompile(Constants.ALOAD_0, Constants.ALOAD_3, Constants.ALOAD)); + + map.put("istore", precompile(Constants.ISTORE_0, Constants.ISTORE_3, Constants.ISTORE)); + map.put("dstore", precompile(Constants.DSTORE_0, Constants.DSTORE_3, Constants.DSTORE)); + map.put("fstore", precompile(Constants.FSTORE_0, Constants.FSTORE_3, Constants.FSTORE)); + map.put("astore", precompile(Constants.ASTORE_0, Constants.ASTORE_3, Constants.ASTORE)); + + // Compile strings + + for(Iterator i = map.keySet().iterator(); i.hasNext(); ) { + String key = (String)i.next(); + String value = (String)map.get(key); + + char ch = value.charAt(1); // Omit already precompiled patterns + if(ch < OFFSET) { + map.put(key, compilePattern(value)); // precompile all patterns + } + } + + // Add instruction alias to match anything + + StringBuffer buf = new StringBuffer("("); + + for(short i=0; i < NO_OPCODES; i++) { + if(Constants.iLen[i] != Constants.UNDEFINED_LENGTH) { // Not an invalid opcode + buf.append(makeChar(i)); + + if(i < NO_OPCODES - 1) + buf.append('|'); + } + } + buf.append(')'); + + map.put("instruction", buf.toString()); + } + + private static String precompile(short from, short to, short extra) { + StringBuffer buf = new StringBuffer("("); + + for(short i=from; i <= to; i++) { + buf.append(makeChar(i)); + buf.append('|'); + } + + buf.append(makeChar(extra)); + buf.append(")"); + return buf.toString(); + } + + /* + * Internal debugging routines. + */ + private static final String pattern2string(String pattern) { + return pattern2string(pattern, true); + } + + private static final String pattern2string(String pattern, boolean make_string) { + StringBuffer buf = new StringBuffer(); + + for(int i=0; i < pattern.length(); i++) { + char ch = pattern.charAt(i); + + if(ch >= OFFSET) { + if(make_string) + buf.append(Constants.OPCODE_NAMES[ch - OFFSET]); + else + buf.append((int)(ch - OFFSET)); + } else + buf.append(ch); + } + + return buf.toString(); + } +} -- 2.39.5