Search in sources :

Example 6 with AnnotationTag

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

the class Annotations method copyAnnotations.

private static void copyAnnotations(SootMethod fromMethod, SootMethod toMethod, int visibility) {
    for (Tag tag : fromMethod.getTags()) {
        if (tag instanceof VisibilityAnnotationTag) {
            if (((VisibilityAnnotationTag) tag).getVisibility() == visibility) {
                VisibilityAnnotationTag copy = new VisibilityAnnotationTag(visibility);
                for (AnnotationTag annoTag : ((VisibilityAnnotationTag) tag).getAnnotations()) {
                    copy.addAnnotation(annoTag);
                }
                toMethod.addTag(copy);
            }
        }
    }
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) Tag(soot.tagkit.Tag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Example 7 with AnnotationTag

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

the class Annotations method getMarshalerAnnotations.

public static List<AnnotationTag> getMarshalerAnnotations(SootClass clazz) {
    List<AnnotationTag> tags = new ArrayList<AnnotationTag>();
    AnnotationTag marshaler = getAnnotation(clazz, MARSHALER);
    if (marshaler != null) {
        tags.add(marshaler);
    } else {
        AnnotationTag marshalers = getAnnotation(clazz, MARSHALERS);
        if (marshalers != null) {
            for (AnnotationElem e : ((AnnotationArrayElem) marshalers.getElemAt(0)).getValues()) {
                AnnotationAnnotationElem elem = (AnnotationAnnotationElem) e;
                tags.add(elem.getValue());
            }
        }
    }
    return tags;
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) ArrayList(java.util.ArrayList) AnnotationArrayElem(soot.tagkit.AnnotationArrayElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) AnnotationElem(soot.tagkit.AnnotationElem)

Example 8 with AnnotationTag

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

the class GlobalValueMethodCompiler method doCompile.

protected Function doCompile(ModuleBuilder moduleBuilder, SootMethod method) {
    AnnotationTag globalValueAnnotation = getAnnotation(method, GLOBAL_VALUE);
    validateGlobalValueMethod(method, globalValueAnnotation);
    boolean optional = readBooleanElem(globalValueAnnotation, "optional", false);
    boolean dereference = readBooleanElem(globalValueAnnotation, "dereference", true);
    Function fn = createMethodFunction(method);
    moduleBuilder.addFunction(fn);
    Type valueType = getStructMemberType(method);
    // Load the address of the resolved @GlobalValue method
    Variable valuePtr = fn.newVariable(new PointerType(valueType));
    Global valuePtrPtr = new Global(Symbols.globalValuePtrSymbol(method), _private, new NullConstant(I8_PTR));
    moduleBuilder.addGlobal(valuePtrPtr);
    fn.add(new Load(valuePtr, new ConstantBitcast(valuePtrPtr.ref(), new PointerType(valuePtr.getType()))));
    Label nullLabel = new Label();
    Label notNullLabel = new Label();
    Variable nullCheck = fn.newVariable(I1);
    fn.add(new Icmp(nullCheck, Condition.eq, valuePtr.ref(), new NullConstant(valuePtr.getType())));
    fn.add(new Br(nullCheck.ref(), fn.newBasicBlockRef(nullLabel), fn.newBasicBlockRef(notNullLabel)));
    fn.newBasicBlock(nullLabel);
    VariableRef env = fn.getParameterRef(0);
    call(fn, BC_THROW_UNSATISIFED_LINK_ERROR, env, moduleBuilder.getString(String.format((optional ? "Optional " : "") + "@GlobalValue method %s.%s%s not bound", className, method.getName(), getDescriptor(method))));
    fn.add(new Unreachable());
    fn.newBasicBlock(notNullLabel);
    if (method.getParameterCount() == 0) {
        // Getter
        Value result = loadValueForGetter(method, fn, valueType, valuePtr.ref(), env, dereference, MarshalerFlags.CALL_TYPE_GLOBAL_VALUE);
        fn.add(new Ret(result));
    } else {
        // Setter
        // 'env' is parameter 0, the value we're interested in is at index 1
        Value value = fn.getParameterRef(1);
        storeValueForSetter(method, fn, valueType, valuePtr.ref(), env, value, MarshalerFlags.CALL_TYPE_GLOBAL_VALUE);
        fn.add(new Ret());
    }
    return fn;
}
Also used : Ret(org.robovm.compiler.llvm.Ret) Load(org.robovm.compiler.llvm.Load) VariableRef(org.robovm.compiler.llvm.VariableRef) Variable(org.robovm.compiler.llvm.Variable) ConstantBitcast(org.robovm.compiler.llvm.ConstantBitcast) Label(org.robovm.compiler.llvm.Label) NullConstant(org.robovm.compiler.llvm.NullConstant) PointerType(org.robovm.compiler.llvm.PointerType) Global(org.robovm.compiler.llvm.Global) Br(org.robovm.compiler.llvm.Br) AnnotationTag(soot.tagkit.AnnotationTag) Function(org.robovm.compiler.llvm.Function) PointerType(org.robovm.compiler.llvm.PointerType) Type(org.robovm.compiler.llvm.Type) VoidType(soot.VoidType) Unreachable(org.robovm.compiler.llvm.Unreachable) Value(org.robovm.compiler.llvm.Value) Icmp(org.robovm.compiler.llvm.Icmp)

Example 9 with AnnotationTag

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

the class ObjCBlockPlugin method addMarshalerAnnotation.

static void addMarshalerAnnotation(SootMethod method, String marshalerName) {
    AnnotationTag annotationTag = new AnnotationTag(MARSHALER, 1);
    annotationTag.addElem(new AnnotationClassElem("L" + marshalerName + ";", 'c', "value"));
    addRuntimeVisibleAnnotation(method, annotationTag);
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) AnnotationClassElem(soot.tagkit.AnnotationClassElem)

Example 10 with AnnotationTag

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

the class ObjCBlockPlugin method addMarshalerAnnotation.

static void addMarshalerAnnotation(SootMethod method, int paramIndex, String marshalerName) {
    AnnotationTag annotationTag = new AnnotationTag(MARSHALER, 1);
    annotationTag.addElem(new AnnotationClassElem("L" + marshalerName + ";", 'c', "value"));
    addRuntimeVisibleParameterAnnotation(method, paramIndex, annotationTag);
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) AnnotationClassElem(soot.tagkit.AnnotationClassElem)

Aggregations

AnnotationTag (soot.tagkit.AnnotationTag)21 ArrayList (java.util.ArrayList)7 VisibilityAnnotationTag (soot.tagkit.VisibilityAnnotationTag)7 VisibilityParameterAnnotationTag (soot.tagkit.VisibilityParameterAnnotationTag)7 Tag (soot.tagkit.Tag)4 Type (org.robovm.compiler.llvm.Type)3 Value (org.robovm.compiler.llvm.Value)3 VoidType (soot.VoidType)3 AnnotationClassElem (soot.tagkit.AnnotationClassElem)3 CompilerException (org.robovm.compiler.CompilerException)2 Clazz (org.robovm.compiler.clazz.Clazz)2 Br (org.robovm.compiler.llvm.Br)2 Function (org.robovm.compiler.llvm.Function)2 Global (org.robovm.compiler.llvm.Global)2 Icmp (org.robovm.compiler.llvm.Icmp)2 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)2 Label (org.robovm.compiler.llvm.Label)2 Load (org.robovm.compiler.llvm.Load)2 NullConstant (org.robovm.compiler.llvm.NullConstant)2 PointerType (org.robovm.compiler.llvm.PointerType)2