use of org.robovm.compiler.llvm.PackedStructureConstant 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 org.robovm.compiler.llvm.PackedStructureConstant in project robovm by robovm.
the class AttributesEncoder method encodeAnnotationElementValue.
private PackedStructureConstant encodeAnnotationElementValue(AnnotationElem ae) {
PackedStructureType type = getAnnotationElementType(ae);
Value kind = new IntegerConstant((byte) ae.getKind());
if (ae instanceof AnnotationIntElem) {
AnnotationIntElem aie = (AnnotationIntElem) ae;
return new PackedStructureConstant(type, kind, new IntegerConstant(aie.getValue()));
} else if (ae instanceof AnnotationLongElem) {
AnnotationLongElem ale = (AnnotationLongElem) ae;
return new PackedStructureConstant(type, kind, new IntegerConstant(ale.getValue()));
} else if (ae instanceof AnnotationFloatElem) {
AnnotationFloatElem afe = (AnnotationFloatElem) ae;
return new PackedStructureConstant(type, kind, new FloatingPointConstant(afe.getValue()));
} else if (ae instanceof AnnotationDoubleElem) {
AnnotationDoubleElem ade = (AnnotationDoubleElem) ae;
return new PackedStructureConstant(type, kind, new FloatingPointConstant(ade.getValue()));
} else if (ae instanceof AnnotationStringElem) {
AnnotationStringElem ase = (AnnotationStringElem) ae;
return new PackedStructureConstant(type, kind, getStringOrNull(ase.getValue()));
} else if (ae instanceof AnnotationClassElem) {
AnnotationClassElem ace = (AnnotationClassElem) ae;
addDependencyIfNeeded(ace.getDesc());
return new PackedStructureConstant(type, kind, getStringOrNull(ace.getDesc()));
} else if (ae instanceof AnnotationEnumElem) {
AnnotationEnumElem aee = (AnnotationEnumElem) ae;
addDependencyIfNeeded(aee.getTypeName());
return new PackedStructureConstant(type, kind, getStringOrNull(aee.getTypeName()), getStringOrNull(aee.getConstantName()));
} else if (ae instanceof AnnotationArrayElem) {
AnnotationArrayElem aae = (AnnotationArrayElem) ae;
Value[] values = new Value[aae.getNumValues() + 2];
values[0] = kind;
values[1] = new IntegerConstant((char) aae.getNumValues());
for (int i = 0; i < aae.getNumValues(); i++) {
values[i + 2] = encodeAnnotationElementValue(aae.getValueAt(i));
}
return new PackedStructureConstant(type, values);
} else if (ae instanceof AnnotationAnnotationElem) {
AnnotationAnnotationElem aae = (AnnotationAnnotationElem) ae;
return new PackedStructureConstant(type, kind, encodeAnnotationTagValue(aae.getValue()));
}
throw new IllegalArgumentException("Unknown AnnotationElem type: " + ae.getClass());
}
use of org.robovm.compiler.llvm.PackedStructureConstant in project robovm by robovm.
the class AttributesEncoder method encodeAnnotationTagValue.
private PackedStructureConstant encodeAnnotationTagValue(AnnotationTag tag) {
Value[] values = new Value[tag.getNumElems() * 2 + 2];
values[0] = getString(tag.getType());
addDependencyIfNeeded(tag.getType());
values[1] = new IntegerConstant(tag.getNumElems());
for (int i = 0; i < tag.getNumElems(); i++) {
values[i * 2 + 2] = getString(tag.getElemAt(i).getName());
values[i * 2 + 2 + 1] = encodeAnnotationElementValue(tag.getElemAt(i));
}
return new PackedStructureConstant(getAnnotationTagType(tag), values);
}
Aggregations