Java Code Examples for org.apache.bcel.generic.Type#INT
The following examples show how to use
org.apache.bcel.generic.Type#INT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Subtypes2Test.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); typeSerializable = ObjectTypeFactory.getInstance("java.io.Serializable"); typeClonable = ObjectTypeFactory.getInstance("java.lang.Cloneable"); typeObject = ObjectTypeFactory.getInstance(Values.DOTTED_JAVA_LANG_OBJECT); typeInteger = ObjectTypeFactory.getInstance("java.lang.Integer"); typeString = ObjectTypeFactory.getInstance(Values.DOTTED_JAVA_LANG_STRING); typeComparable = ObjectTypeFactory.getInstance("java.lang.Comparable"); typeList = ObjectTypeFactory.getInstance("java.util.List"); typeCollection = ObjectTypeFactory.getInstance("java.util.Collection"); typeHashSet = ObjectTypeFactory.getInstance("java.util.HashSet"); typeArrayClonable = new ArrayType(typeClonable, 1); typeArrayComparable = new ArrayType(typeComparable, 1); typeArrayObject = new ArrayType(typeObject, 1); typeArrayInteger = new ArrayType(typeInteger, 1); typeArrayString = new ArrayType(typeString, 1); typeArrayArrayObject = new ArrayType(typeObject, 2); typeArrayArraySerializable = new ArrayType(typeSerializable, 2); typeArrayArrayString = new ArrayType(typeString, 2); typeArrayInt = new ArrayType(Type.INT, 1); typeArrayArrayInt = new ArrayType(Type.INT, 2); typeArrayArrayArrayInt = new ArrayType(Type.INT, 3); typeArrayChar = new ArrayType(Type.CHAR, 1); typeArrayArrayChar = new ArrayType(Type.CHAR, 2); typeArrayArrayArrayChar = new ArrayType(Type.CHAR, 3); typeDynamicString = new FindRefComparison.DynamicStringType(); typeStaticString = new FindRefComparison.StaticStringType(); typeParameterString = new FindRefComparison.ParameterStringType(); }
Example 2
Source File: TestReturn03Creator.java From commons-bcel with Apache License 2.0 | 5 votes |
private void createMethod_1() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.INT, Type.NO_ARGS, new String[] { }, "test3", TEST_PACKAGE+".TestReturn03", il, _cp); final InstructionHandle ih_0 = il.append(InstructionConst.ACONST_NULL); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(InstructionFactory.createReturn(Type.OBJECT)); method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }
Example 3
Source File: StandardTypeMerger.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public Type mergeTypes(Type a, Type b) throws DataflowAnalysisException { if (a == null) { return b; } if (b == null) { return a; } byte aType = a.getType(), bType = b.getType(); if (aType == T_TOP) { return b; } else if (bType == T_TOP) { return a; } else if (aType == T_BOTTOM || bType == T_BOTTOM) { // is bottom return BottomType.instance(); } else if (isReferenceType(aType) && isReferenceType(bType)) { // Two // object // types! // Handle the Null type, which serves as a special "top" // value for reference types. if (aType == T_NULL) { return b; } else if (bType == T_NULL) { return a; } ReferenceType aRef = (ReferenceType) a; ReferenceType bRef = (ReferenceType) b; return mergeReferenceTypes(aRef, bRef); } else if (isReferenceType(aType) || isReferenceType(bType)) { // meet // non-object // is // bottom return BottomType.instance(); } else if (aType == bType) { return a; } else if (isIntegerType(aType) && isIntegerType(bType)) { // integer types // - use T_INT return Type.INT; } else { // Default - types are incompatible return BottomType.instance(); } }
Example 4
Source File: ASTFunAppl.java From commons-bcel with Apache License 2.0 | 4 votes |
/** * Fifth pass, produce Java byte code. */ @Override public void byte_code(final InstructionList il, final MethodGen method, final ConstantPoolGen cp) { final String fname = name.getName(); // Function f = function; //ASTIdent fun = f.getName(); // ASTIdent[] args = f.getArgs(); final String class_name = method.getClassName(); if(fname.equals("READ")) { il.append(new INVOKESTATIC(cp.addMethodref(class_name, "_readInt", "()I"))); } else if(fname.equals("WRITE")) { exprs[0].byte_code(il, method, cp); ASTFunDecl.pop(); il.append(new INVOKESTATIC(cp.addMethodref(class_name, "_writeInt", "(I)I"))); } else { // Normal function final int size = exprs.length; Type[] argv = null; if(exprs != null) { argv = new Type[size]; for(int i=0; i < size; i++) { argv[i] = Type.INT; exprs[i].byte_code(il, method, cp); } //ASTFunDecl.push(size); } ASTFunDecl.pop(size); // Function call il.append(new INVOKESTATIC(cp.addMethodref(class_name, fname, Type.getMethodSignature(Type.INT, argv)))); } ASTFunDecl.push(); }
Example 5
Source File: Pass3bVerifier.java From commons-bcel with Apache License 2.0 | 4 votes |
/** * Pass 3b implements the data flow analysis as described in the Java Virtual * Machine Specification, Second Edition. * Later versions will use LocalVariablesInfo objects to verify if the * verifier-inferred types and the class file's debug information (LocalVariables * attributes) match [TODO]. * * @see org.apache.bcel.verifier.statics.LocalVariablesInfo * @see org.apache.bcel.verifier.statics.Pass2Verifier#getLocalVariablesInfo(int) */ @Override public VerificationResult do_verify() { if (! myOwner.doPass3a(methodNo).equals(VerificationResult.VR_OK)) { return VerificationResult.VR_NOTYET; } // Pass 3a ran before, so it's safe to assume the JavaClass object is // in the BCEL repository. JavaClass jc; try { jc = Repository.lookupClass(myOwner.getClassName()); } catch (final ClassNotFoundException e) { // FIXME: maybe not the best way to handle this throw new AssertionViolatedException("Missing class: " + e, e); } final ConstantPoolGen constantPoolGen = new ConstantPoolGen(jc.getConstantPool()); // Init Visitors final InstConstraintVisitor icv = new InstConstraintVisitor(); icv.setConstantPoolGen(constantPoolGen); final ExecutionVisitor ev = new ExecutionVisitor(); ev.setConstantPoolGen(constantPoolGen); final Method[] methods = jc.getMethods(); // Method no "methodNo" exists, we ran Pass3a before on it! try{ final MethodGen mg = new MethodGen(methods[methodNo], myOwner.getClassName(), constantPoolGen); icv.setMethodGen(mg); ////////////// DFA BEGINS HERE //////////////// if (! (mg.isAbstract() || mg.isNative()) ) { // IF mg HAS CODE (See pass 2) final ControlFlowGraph cfg = new ControlFlowGraph(mg); // Build the initial frame situation for this method. final Frame f = new Frame(mg.getMaxLocals(),mg.getMaxStack()); if ( !mg.isStatic() ) { if (mg.getName().equals(Const.CONSTRUCTOR_NAME)) { Frame.setThis(new UninitializedObjectType(ObjectType.getInstance(jc.getClassName()))); f.getLocals().set(0, Frame.getThis()); } else{ Frame.setThis(null); f.getLocals().set(0, ObjectType.getInstance(jc.getClassName())); } } final Type[] argtypes = mg.getArgumentTypes(); int twoslotoffset = 0; for (int j=0; j<argtypes.length; j++) { if (argtypes[j] == Type.SHORT || argtypes[j] == Type.BYTE || argtypes[j] == Type.CHAR || argtypes[j] == Type.BOOLEAN) { argtypes[j] = Type.INT; } f.getLocals().set(twoslotoffset + j + (mg.isStatic()?0:1), argtypes[j]); if (argtypes[j].getSize() == 2) { twoslotoffset++; f.getLocals().set(twoslotoffset + j + (mg.isStatic()?0:1), Type.UNKNOWN); } } circulationPump(mg,cfg, cfg.contextOf(mg.getInstructionList().getStart()), f, icv, ev); } } catch (final VerifierConstraintViolatedException ce) { ce.extendMessage("Constraint violated in method '"+methods[methodNo]+"':\n",""); return new VerificationResult(VerificationResult.VERIFIED_REJECTED, ce.getMessage()); } catch (final RuntimeException re) { // These are internal errors final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); re.printStackTrace(pw); throw new AssertionViolatedException("Some RuntimeException occured while verify()ing class '"+jc.getClassName()+ "', method '"+methods[methodNo]+"'. Original RuntimeException's stack trace:\n---\n"+sw+"---\n", re); } return VerificationResult.VR_OK; }