use of soot.SootClass in project robovm by robovm.
the class AnnotationsTest method testCopyParameterAnnotationsMultipleAllNoShift.
@Test
public void testCopyParameterAnnotationsMultipleAllNoShift() {
SootClass sc = toSootClass(getClass());
SootMethod src = sc.getMethodByName("src6");
SootMethod dest = sc.getMethodByName("dest6");
copyParameterAnnotations(src, dest, 0, 2, 0, Visibility.Any);
assertEquals("void dest6(@A @B @C int, @B @C @D int)", toString(dest));
}
use of soot.SootClass in project robovm by robovm.
the class AnnotationImplPlugin method beforeClass.
@Override
public void beforeClass(Config config, Clazz clazz, ModuleBuilder moduleBuilder) {
init();
SootClass sootClass = clazz.getSootClass();
if ((sootClass.getModifiers() & MOD_ANNOTATION) > 0) {
try {
String implInternalName = clazz.getInternalName() + IMPL_CLASS_NAME_SUFFIX;
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cw.visit(V1_7, ACC_SUPER + ACC_FINAL + ACC_SYNTHETIC + ACC_PUBLIC, implInternalName, null, BASE_CLASS, new String[] { clazz.getInternalName() });
generateConstructor(clazz, cw);
generateAnnotationTypeMethod(clazz, cw);
generateMembersToStringMethod(clazz, cw);
generateFastEqualsMethod(clazz, cw);
generateSlowEqualsMethod(clazz, cw);
generateHashCodeMethod(clazz, cw);
generateMemberFieldsAndAccessorMethods(clazz, cw);
generateSetDefaultsMethod(clazz, cw);
generateSingletonFactoryMethod(clazz, cw);
generateFactoryMethod(clazz, cw);
cw.visitEnd();
File f = clazz.getPath().getGeneratedClassFile(implInternalName);
FileUtils.writeByteArrayToFile(f, cw.toByteArray());
// The impl class is created after the interface is compiled.
// This prevents the triggering of a recompile of the interface.
f.setLastModified(clazz.lastModified());
// Add the impl class as a dependency for the annotation interface.
// Important! This must be done AFTER the class file has been written.
clazz.getClazzInfo().addClassDependency(implInternalName, false);
// Make sure the factory methods are always linked in when the
// annotation class is referenced.
clazz.getClazzInfo().addInvokeMethodDependency(implInternalName, "$createSingleton", "()Ljava/lang/Object;", false);
clazz.getClazzInfo().addInvokeMethodDependency(implInternalName, "$create", "()Ljava/lang/Object;", false);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
use of soot.SootClass 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]));
}
use of soot.SootClass in project robovm by robovm.
the class MethodCompiler method canCallDirectly.
private boolean canCallDirectly(InvokeExpr expr) {
if (expr instanceof InterfaceInvokeExpr) {
// Never possible
return false;
}
SootClass sootClass = this.sootMethod.getDeclaringClass();
SootMethodRef methodRef = expr.getMethodRef();
if (!methodRef.declaringClass().equals(sootClass)) {
return false;
}
try {
SootMethod method = sootClass.getMethod(methodRef.name(), methodRef.parameterTypes(), methodRef.returnType());
if (method.isAbstract()) {
return false;
}
/*
* The method exists and isn't abstract. Non virtual (invokespecial)
* as well as static calls and calls to final methods can be done directly.
*/
if (method.isStatic()) {
// want an exception to be thrown so we need a trampoline.
return expr instanceof StaticInvokeExpr;
}
if (expr instanceof SpecialInvokeExpr) {
return true;
}
if (expr instanceof VirtualInvokeExpr) {
// the method must be private
return Modifier.isFinal(sootClass.getModifiers()) || Modifier.isFinal(method.getModifiers()) || method.isPrivate();
}
return false;
} catch (RuntimeException e) {
// isn't declared in the class.
return false;
}
}
use of soot.SootClass in project robovm by robovm.
the class MarshalerLookup method getBaseType.
private soot.Type getBaseType(SootMethod m, AnnotationTag anno) {
AnnotationClassElem el = (AnnotationClassElem) getElemByName(anno, "baseType");
if (el != null) {
switch(el.getDesc().charAt(0)) {
case 'Z':
return BooleanType.v();
case 'B':
return ByteType.v();
case 'S':
return ShortType.v();
case 'C':
return CharType.v();
case 'I':
return IntType.v();
case 'J':
return LongType.v();
case 'F':
return FloatType.v();
case 'D':
return DoubleType.v();
}
return null;
}
soot.Type t = m.getReturnType();
if (t == VoidType.v()) {
t = m.getParameterType(0);
}
if (t instanceof RefType) {
SootClass c = ((RefType) t).getSootClass();
if (isInstanceOfClass(c, "java.nio.ByteBuffer")) {
return ByteType.v();
} else if (isInstanceOfClass(c, "java.nio.ShortBuffer")) {
return ShortType.v();
} else if (isInstanceOfClass(c, "java.nio.CharBuffer")) {
return CharType.v();
} else if (isInstanceOfClass(c, "java.nio.IntBuffer")) {
return IntType.v();
} else if (isInstanceOfClass(c, "java.nio.LongBuffer")) {
return LongType.v();
} else if (isInstanceOfClass(c, "java.nio.FloatBuffer")) {
return FloatType.v();
} else if (isInstanceOfClass(c, "java.nio.DoubleBuffer")) {
return DoubleType.v();
} else if (isInstanceOfClass(c, "org.robovm.rt.bro.Struct")) {
return config.getClazzes().load("org/robovm/rt/bro/Struct").getSootClass().getType();
}
} else if (t instanceof ArrayType) {
ArrayType arrayType = (ArrayType) t;
if (arrayType.baseType instanceof PrimType || isInstanceOfClass(arrayType.baseType, "org.robovm.rt.bro.Struct")) {
return arrayType.baseType;
}
}
return null;
}
Aggregations