use of soot.tagkit.SignatureTag 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();
}
}
}
use of soot.tagkit.SignatureTag in project soot by Sable.
the class AbstractJasminClass method emitMethod.
protected void emitMethod(SootMethod method) {
if (method.isPhantom())
return;
// Emit prologue
emit(".method " + Modifier.toString(method.getModifiers()) + " " + method.getName() + jasminDescriptorOf(method.makeRef()));
Iterator<SootClass> throwsIt = method.getExceptions().iterator();
while (throwsIt.hasNext()) {
SootClass exceptClass = throwsIt.next();
emit(".throws " + exceptClass.getName());
}
if (method.hasTag("SyntheticTag") || Modifier.isSynthetic(method.getModifiers())) {
emit(".synthetic");
}
if (method.hasTag("DeprecatedTag")) {
emit(".deprecated");
}
if (method.hasTag("SignatureTag")) {
String sigAttr = ".signature_attr ";
SignatureTag sigTag = (SignatureTag) method.getTag("SignatureTag");
sigAttr += "\"" + sigTag.getSignature() + "\"";
emit(sigAttr);
}
if (method.hasTag("AnnotationDefaultTag")) {
String annotDefAttr = ".annotation_default ";
AnnotationDefaultTag annotDefTag = (AnnotationDefaultTag) method.getTag("AnnotationDefaultTag");
annotDefAttr += getElemAttr(annotDefTag.getDefaultVal());
annotDefAttr += ".end .annotation_default";
emit(annotDefAttr);
}
Iterator<Tag> vit = method.getTags().iterator();
while (vit.hasNext()) {
Tag t = (Tag) vit.next();
if (t.getName().equals("VisibilityAnnotationTag")) {
emit(getVisibilityAnnotationAttr((VisibilityAnnotationTag) t));
}
if (t.getName().equals("VisibilityParameterAnnotationTag")) {
emit(getVisibilityParameterAnnotationAttr((VisibilityParameterAnnotationTag) t));
}
}
if (method.isConcrete()) {
if (!method.hasActiveBody())
throw new RuntimeException("method: " + method.getName() + " has no active body!");
else
emitMethodBody(method);
}
// Emit epilogue
emit(".end method");
Iterator<Tag> it = method.getTags().iterator();
while (it.hasNext()) {
Tag tag = (Tag) it.next();
if (tag instanceof Attribute)
emit(".method_attribute " + tag.getName() + " \"" + new String(Base64.encode(tag.getValue())) + "\"");
}
}
use of soot.tagkit.SignatureTag in project robovm by robovm.
the class ObjCMemberPlugin method createGenericSignatureForMsgSend.
private void createGenericSignatureForMsgSend(SootMethod annotatedMethod, SootMethod m, List<Type> paramTypes, boolean extensions) {
SignatureTag tag = (SignatureTag) annotatedMethod.getTag(SignatureTag.class.getSimpleName());
if (tag != null) {
SootMethodType type = new SootMethodType(annotatedMethod);
List<String> genericParameterTypes = new ArrayList<>();
for (org.robovm.compiler.util.generic.Type t : type.getGenericParameterTypes()) {
genericParameterTypes.add(t.toGenericSignature());
}
if (!extensions) {
/*
* For non extensions the generic signature is missing the
* receiver as parameter 1.
*/
genericParameterTypes.add(0, Types.getDescriptor(paramTypes.get(0)));
}
/*
* Always insert the selector as parameter 2 of the generic
* signature.
*/
genericParameterTypes.add(1, Types.getDescriptor(paramTypes.get(1)));
StringBuilder sb = new StringBuilder("(");
sb.append(StringUtils.join(genericParameterTypes, ""));
sb.append(")");
sb.append(type.getGenericReturnType().toGenericSignature());
m.addTag(new SignatureTag(sb.toString()));
}
}
use of soot.tagkit.SignatureTag in project robovm by robovm.
the class ObjCBlockPluginTest method signatureToType.
private Type signatureToType(String desc) {
String rawDesc = desc.replaceAll("<.*>", "");
String internalName = rawDesc.replaceAll("^\\[*", "");
int dims = rawDesc.length() - internalName.length();
internalName = Types.getInternalNameFromDescriptor(internalName);
soot.Type sootType = SootResolver.v().makeClassRef(internalName.replace('/', '.')).getType();
for (int i = 0; i < dims; i++) {
sootType = sootType.makeArrayType();
}
SootMethod m = new SootMethod("foo", Arrays.asList(sootType), VoidType.v());
m.addTag(new SignatureTag("(" + desc + ")V"));
SootMethodType mType = new SootMethodType(m);
return mType.getGenericParameterTypes()[0];
}
use of soot.tagkit.SignatureTag in project soot by Sable.
the class AbstractASMBackend method generateFields.
/**
* Emits the bytecode for all fields of the class
*/
protected void generateFields() {
for (SootField f : sc.getFields()) {
if (f.isPhantom())
continue;
String name = f.getName();
String desc = toTypeDesc(f.getType());
String sig = null;
if (f.hasTag("SignatureTag")) {
SignatureTag genericSignature = (SignatureTag) f.getTag("SignatureTag");
sig = genericSignature.getSignature();
}
Object value = getDefaultValue(f);
int access = getModifiers(f.getModifiers(), f);
FieldVisitor fv = cv.visitField(access, name, desc, sig, value);
if (fv != null) {
generateAnnotations(fv, f);
generateAttributes(fv, f);
fv.visitEnd();
}
}
}
Aggregations