Search in sources :

Example 1 with VisibilityParameterAnnotationTag

use of soot.tagkit.VisibilityParameterAnnotationTag in project robovm by robovm.

the class AttributesEncoder method encodeAttributes.

private Constant encodeAttributes(Host host) {
    List<Value> attributes = new ArrayList<Value>();
    for (Tag tag : host.getTags()) {
        if (tag instanceof SourceFileTag) {
            // Skip. We don't need this at this time.
            Value sourceFile = getString(((SourceFileTag) tag).getSourceFile());
            attributes.add(new PackedStructureConstant(new PackedStructureType(I8, I8_PTR), new IntegerConstant(SOURCE_FILE), sourceFile));
        } else if (tag instanceof EnclosingMethodTag) {
            EnclosingMethodTag emt = (EnclosingMethodTag) tag;
            Value eClass = getString(emt.getEnclosingClass());
            Value eMethod = getStringOrNull(emt.getEnclosingMethod());
            Value eDesc = getStringOrNull(emt.getEnclosingMethodSig());
            attributes.add(new PackedStructureConstant(new PackedStructureType(I8, I8_PTR, I8_PTR, I8_PTR), new IntegerConstant(ENCLOSING_METHOD), eClass, eMethod, eDesc));
        } else if (tag instanceof SignatureTag) {
            Value signature = getString(((SignatureTag) tag).getSignature());
            attributes.add(new PackedStructureConstant(new PackedStructureType(I8, I8_PTR), new IntegerConstant(SIGNATURE), signature));
        } else if (tag instanceof InnerClassTag) {
            InnerClassTag ict = (InnerClassTag) tag;
            Value innerClass = getStringOrNull(ict.getInnerClass());
            Value outerClass = getStringOrNull(ict.getOuterClass());
            Value innerName = getStringOrNull(ict.getShortName());
            Value innerClassAccess = new IntegerConstant(ict.getAccessFlags());
            attributes.add(new PackedStructureConstant(new PackedStructureType(I8, I8_PTR, I8_PTR, I8_PTR, I32), new IntegerConstant(INNER_CLASS), innerClass, outerClass, innerName, innerClassAccess));
        } else if (tag instanceof AnnotationDefaultTag) {
            StructureConstant value = encodeAnnotationElementValue(((AnnotationDefaultTag) tag).getDefaultVal());
            attributes.add(new PackedStructureConstant(new PackedStructureType(I8, value.getType()), new IntegerConstant(ANNOTATION_DEFAULT), value));
        } else if (tag instanceof VisibilityAnnotationTag) {
            VisibilityAnnotationTag vat = (VisibilityAnnotationTag) tag;
            if (vat.getVisibility() == AnnotationConstants.RUNTIME_VISIBLE) {
                Type[] types = new Type[vat.getAnnotations().size()];
                Value[] values = new Value[vat.getAnnotations().size()];
                int i = 0;
                for (AnnotationTag at : vat.getAnnotations()) {
                    values[i] = encodeAnnotationTagValue(at);
                    types[i] = values[i].getType();
                    i++;
                }
                attributes.add(new PackedStructureConstant(new PackedStructureType(I8, I32, new PackedStructureType(types)), new IntegerConstant(RUNTIME_VISIBLE_ANNOTATIONS), new IntegerConstant(vat.getAnnotations().size()), new PackedStructureConstant(new PackedStructureType(types), values)));
            }
        } else if (tag instanceof VisibilityParameterAnnotationTag) {
            VisibilityParameterAnnotationTag vpat = (VisibilityParameterAnnotationTag) tag;
            List<Type> typesList = new ArrayList<Type>();
            List<Value> valuesList = new ArrayList<Value>();
            boolean hasRuntimeVisible = false;
            for (VisibilityAnnotationTag vat : vpat.getVisibilityAnnotations()) {
                typesList.add(I32);
                if (vat.getVisibility() == AnnotationConstants.RUNTIME_VISIBLE && vat.getAnnotations() != null && !vat.getAnnotations().isEmpty()) {
                    hasRuntimeVisible = true;
                    valuesList.add(new IntegerConstant(vat.getAnnotations().size()));
                    for (AnnotationTag at : vat.getAnnotations()) {
                        valuesList.add(encodeAnnotationTagValue(at));
                        typesList.add(valuesList.get(valuesList.size() - 1).getType());
                    }
                } else {
                    valuesList.add(new IntegerConstant(0));
                }
            }
            if (hasRuntimeVisible) {
                Type[] types = typesList.toArray(new Type[typesList.size()]);
                Value[] values = valuesList.toArray(new Value[valuesList.size()]);
                attributes.add(new PackedStructureConstant(new PackedStructureType(I8, I32, new PackedStructureType(types)), new IntegerConstant(RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS), new IntegerConstant(vpat.getVisibilityAnnotations().size()), new PackedStructureConstant(new PackedStructureType(types), values)));
            }
        }
    }
    if (host instanceof SootMethod) {
        List<SootClass> exceptions = ((SootMethod) host).getExceptions();
        if (!exceptions.isEmpty()) {
            Value[] values = new Value[exceptions.size()];
            for (int i = 0; i < exceptions.size(); i++) {
                String exName = getInternalName(exceptions.get(i));
                values[i] = getString(exName);
                addDependency(exName);
            }
            attributes.add(new PackedStructureConstant(new PackedStructureType(I8, I32, new ArrayType(exceptions.size(), I8_PTR)), new IntegerConstant(EXCEPTIONS), new IntegerConstant(exceptions.size()), new ArrayConstant(new ArrayType(exceptions.size(), I8_PTR), values)));
        }
    }
    if (attributes.isEmpty()) {
        return null;
    }
    attributes.add(0, new IntegerConstant(attributes.size()));
    Type[] types = new Type[attributes.size()];
    for (int i = 0; i < types.length; i++) {
        types[i] = attributes.get(i).getType();
    }
    return new PackedStructureConstant(new PackedStructureType(types), attributes.toArray(new Value[0]));
}
Also used : ArrayList(java.util.ArrayList) SourceFileTag(soot.tagkit.SourceFileTag) ArrayType(org.robovm.compiler.llvm.ArrayType) InnerClassTag(soot.tagkit.InnerClassTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) ArrayConstant(org.robovm.compiler.llvm.ArrayConstant) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) AnnotationDefaultTag(soot.tagkit.AnnotationDefaultTag) SootClass(soot.SootClass) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) PackedStructureConstant(org.robovm.compiler.llvm.PackedStructureConstant) EnclosingMethodTag(soot.tagkit.EnclosingMethodTag) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) ArrayType(org.robovm.compiler.llvm.ArrayType) Type(org.robovm.compiler.llvm.Type) StructureConstant(org.robovm.compiler.llvm.StructureConstant) PackedStructureConstant(org.robovm.compiler.llvm.PackedStructureConstant) Value(org.robovm.compiler.llvm.Value) SignatureTag(soot.tagkit.SignatureTag) SootMethod(soot.SootMethod) Tag(soot.tagkit.Tag) AnnotationDefaultTag(soot.tagkit.AnnotationDefaultTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) InnerClassTag(soot.tagkit.InnerClassTag) SignatureTag(soot.tagkit.SignatureTag) AnnotationTag(soot.tagkit.AnnotationTag) SourceFileTag(soot.tagkit.SourceFileTag) EnclosingMethodTag(soot.tagkit.EnclosingMethodTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag)

Example 2 with VisibilityParameterAnnotationTag

use of soot.tagkit.VisibilityParameterAnnotationTag in project robovm by robovm.

the class Annotations method getOrCreateRuntimeVisibilityAnnotationTag.

public static VisibilityAnnotationTag getOrCreateRuntimeVisibilityAnnotationTag(SootMethod method, int paramIndex) {
    for (Tag tag : method.getTags()) {
        if (tag instanceof VisibilityParameterAnnotationTag) {
            ArrayList<VisibilityAnnotationTag> l = ((VisibilityParameterAnnotationTag) tag).getVisibilityAnnotations();
            if (l != null && paramIndex < l.size()) {
                if ((l.get(paramIndex)).getVisibility() == RUNTIME_VISIBLE) {
                    return l.get(paramIndex);
                }
            }
        }
    }
    VisibilityParameterAnnotationTag ptag = new VisibilityParameterAnnotationTag(method.getParameterCount(), RUNTIME_VISIBLE);
    ArrayList<VisibilityAnnotationTag> l = new ArrayList<VisibilityAnnotationTag>();
    for (int i = 0; i < method.getParameterCount(); i++) {
        l.add(new VisibilityAnnotationTag(RUNTIME_VISIBLE));
    }
    method.addTag(ptag);
    return l.get(paramIndex);
}
Also used : VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) ArrayList(java.util.ArrayList) Tag(soot.tagkit.Tag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Example 3 with VisibilityParameterAnnotationTag

use of soot.tagkit.VisibilityParameterAnnotationTag in project soot by Sable.

the class Util method addAnnotationVisibilityParameterAttribute.

private void addAnnotationVisibilityParameterAttribute(Host host, attribute_info attribute, ClassFile coffiClass, Collection<Type> references) {
    VisibilityParameterAnnotationTag tag;
    if (attribute instanceof RuntimeVisibleParameterAnnotations_attribute) {
        RuntimeVisibleParameterAnnotations_attribute attr = (RuntimeVisibleParameterAnnotations_attribute) attribute;
        tag = new VisibilityParameterAnnotationTag(attr.num_parameters, AnnotationConstants.RUNTIME_VISIBLE);
        for (int i = 0; i < attr.num_parameters; i++) {
            parameter_annotation pAnnot = attr.parameter_annotations[i];
            VisibilityAnnotationTag vTag = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_VISIBLE);
            addAnnotations(pAnnot.num_annotations, pAnnot.annotations, coffiClass, vTag, references);
            tag.addVisibilityAnnotation(vTag);
        }
    } else {
        RuntimeInvisibleParameterAnnotations_attribute attr = (RuntimeInvisibleParameterAnnotations_attribute) attribute;
        tag = new VisibilityParameterAnnotationTag(attr.num_parameters, AnnotationConstants.RUNTIME_INVISIBLE);
        for (int i = 0; i < attr.num_parameters; i++) {
            parameter_annotation pAnnot = attr.parameter_annotations[i];
            VisibilityAnnotationTag vTag = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_INVISIBLE);
            addAnnotations(pAnnot.num_annotations, pAnnot.annotations, coffiClass, vTag, references);
            tag.addVisibilityAnnotation(vTag);
        }
    }
    host.addTag(tag);
}
Also used : VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Example 4 with VisibilityParameterAnnotationTag

use of soot.tagkit.VisibilityParameterAnnotationTag in project soot by Sable.

the class DexPrinter method buildMethodParameterAnnotations.

/**
 * Returns all method parameter annotations (or null) for a specific parameter
 *
 * @param m
 *            the method
 * @param paramIdx
 *            the parameter index
 * @return the annotations (or null)
 */
private Set<Annotation> buildMethodParameterAnnotations(SootMethod m, final int paramIdx) {
    Set<String> skipList = null;
    Set<Annotation> annotations = null;
    for (Tag t : m.getTags()) {
        if (t.getName().equals("VisibilityParameterAnnotationTag")) {
            VisibilityParameterAnnotationTag vat = (VisibilityParameterAnnotationTag) t;
            if (skipList == null) {
                skipList = new HashSet<String>();
                annotations = new HashSet<Annotation>();
            }
            List<ImmutableAnnotation> visibilityItems = buildVisibilityParameterAnnotationTag(vat, skipList, paramIdx);
            annotations.addAll(visibilityItems);
        }
    }
    return annotations;
}
Also used : VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) ConstantValueTag(soot.tagkit.ConstantValueTag) SourceFileTag(soot.tagkit.SourceFileTag) AnnotationDefaultTag(soot.tagkit.AnnotationDefaultTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) InnerClassTag(soot.tagkit.InnerClassTag) FloatConstantValueTag(soot.tagkit.FloatConstantValueTag) AnnotationTag(soot.tagkit.AnnotationTag) IntegerConstantValueTag(soot.tagkit.IntegerConstantValueTag) EnclosingMethodTag(soot.tagkit.EnclosingMethodTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) Tag(soot.tagkit.Tag) LineNumberTag(soot.tagkit.LineNumberTag) ParamNamesTag(soot.tagkit.ParamNamesTag) DoubleConstantValueTag(soot.tagkit.DoubleConstantValueTag) LongConstantValueTag(soot.tagkit.LongConstantValueTag) SignatureTag(soot.tagkit.SignatureTag) StringConstantValueTag(soot.tagkit.StringConstantValueTag) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) Annotation(org.jf.dexlib2.iface.Annotation) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation)

Example 5 with VisibilityParameterAnnotationTag

use of soot.tagkit.VisibilityParameterAnnotationTag in project soot by Sable.

the class AbstractASMBackend method generateMethods.

/**
 * Emits the bytecode for all methods of the class
 */
protected void generateMethods() {
    List<SootMethod> sortedMethods = new ArrayList<SootMethod>(sc.getMethods());
    Collections.sort(sortedMethods, new SootMethodComparator());
    for (SootMethod sm : sortedMethods) {
        if (sm.isPhantom())
            continue;
        int access = getModifiers(sm.getModifiers(), sm);
        String name = sm.getName();
        StringBuilder descBuilder = new StringBuilder(5);
        descBuilder.append('(');
        for (Type t : sm.getParameterTypes()) {
            descBuilder.append(toTypeDesc(t));
        }
        descBuilder.append(')');
        descBuilder.append(toTypeDesc(sm.getReturnType()));
        String sig = null;
        if (sm.hasTag("SignatureTag")) {
            SignatureTag genericSignature = (SignatureTag) sm.getTag("SignatureTag");
            sig = genericSignature.getSignature();
        }
        List<SootClass> exceptionList = sm.getExceptionsUnsafe();
        String[] exceptions;
        if (exceptionList != null) {
            exceptions = new String[exceptionList.size()];
            int i = 0;
            for (SootClass exc : sm.getExceptions()) {
                exceptions[i] = slashify(exc.getName());
                ++i;
            }
        } else
            exceptions = new String[0];
        MethodVisitor mv = cv.visitMethod(access, name, descBuilder.toString(), sig, exceptions);
        if (mv != null) {
            // Visit parameter annotations
            for (Tag t : sm.getTags()) {
                if (t instanceof VisibilityParameterAnnotationTag) {
                    VisibilityParameterAnnotationTag vpt = (VisibilityParameterAnnotationTag) t;
                    ArrayList<VisibilityAnnotationTag> tags = vpt.getVisibilityAnnotations();
                    if (tags != null) {
                        for (int j = 0; j < tags.size(); ++j) {
                            VisibilityAnnotationTag va = tags.get(j);
                            if (va == null) {
                                continue;
                            }
                            for (AnnotationTag at : va.getAnnotations()) {
                                AnnotationVisitor av = mv.visitParameterAnnotation(j, at.getType(), (va.getVisibility() == AnnotationConstants.RUNTIME_VISIBLE));
                                generateAnnotationElems(av, at.getElems(), true);
                            }
                        }
                    }
                }
            }
            generateAnnotations(mv, sm);
            generateAttributes(mv, sm);
            if (sm.hasActiveBody()) {
                mv.visitCode();
                generateMethodBody(mv, sm);
                /*
					 * Correct values are computed automatically by ASM,
					 * but we need the call anyways.
					 */
                mv.visitMaxs(0, 0);
            }
            mv.visitEnd();
        }
    }
}
Also used : VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) ArrayList(java.util.ArrayList) MethodVisitor(org.objectweb.asm.MethodVisitor) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) SignatureTag(soot.tagkit.SignatureTag) Tag(soot.tagkit.Tag) SourceFileTag(soot.tagkit.SourceFileTag) AnnotationDefaultTag(soot.tagkit.AnnotationDefaultTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) InnerClassTag(soot.tagkit.InnerClassTag) OuterClassTag(soot.tagkit.OuterClassTag) SignatureTag(soot.tagkit.SignatureTag) AnnotationTag(soot.tagkit.AnnotationTag) EnclosingMethodTag(soot.tagkit.EnclosingMethodTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag)

Aggregations

VisibilityAnnotationTag (soot.tagkit.VisibilityAnnotationTag)11 VisibilityParameterAnnotationTag (soot.tagkit.VisibilityParameterAnnotationTag)11 AnnotationTag (soot.tagkit.AnnotationTag)9 Tag (soot.tagkit.Tag)8 ArrayList (java.util.ArrayList)7 AnnotationDefaultTag (soot.tagkit.AnnotationDefaultTag)5 EnclosingMethodTag (soot.tagkit.EnclosingMethodTag)5 InnerClassTag (soot.tagkit.InnerClassTag)5 SignatureTag (soot.tagkit.SignatureTag)5 SourceFileTag (soot.tagkit.SourceFileTag)4 List (java.util.List)2 ImmutableAnnotation (org.jf.dexlib2.immutable.ImmutableAnnotation)2 AnnotationAnnotationElem (soot.tagkit.AnnotationAnnotationElem)2 AnnotationElem (soot.tagkit.AnnotationElem)2 DoubleConstantValueTag (soot.tagkit.DoubleConstantValueTag)2 FloatConstantValueTag (soot.tagkit.FloatConstantValueTag)2 IntegerConstantValueTag (soot.tagkit.IntegerConstantValueTag)2 LongConstantValueTag (soot.tagkit.LongConstantValueTag)2 ParamNamesTag (soot.tagkit.ParamNamesTag)2 StringConstantValueTag (soot.tagkit.StringConstantValueTag)2