mutatedType = ((JNATypeConversion)result.typeConverter).resolveTypeDef(mutatedType, callerLibraryName, true, false); VariablesDeclaration convDecl = new VariablesDeclaration(); convDecl.addModifiers(ModifierType.Public); convDecl.importDetails(e, false); convDecl.importDetails(mutatedType, true); convDecl.importDetails(javaType, true); convDecl.moveAllCommentsBefore(); convDecl.deDioxygenizeCommentBefore(); convDecl.setValueType(javaType); convDecl.addDeclarator(new DirectDeclarator(name, initVal));
int nDecl = v.getDeclarators().size(); for (Declarator vs : v.getDeclarators()) { if (vs == null || vs instanceof DirectDeclarator && nDecl == 1) { continue; Declarator.MutableByDeclarator mutatedType = vs.mutateType(v.getValueType()); if (mutatedType instanceof Function) { Function f = (Function) mutatedType; if (mutatedType instanceof TypeRef) { TypeRef tr = (TypeRef) mutatedType; decl = new VariablesDeclaration(tr, new DirectDeclarator(vs.resolveName(), vs.getBits(), vs.getDefaultValue())); decl.importDetails(v, false); decl.importDetails(vs, false); TypeRef vt = v.getValueType(); decl = new VariablesDeclaration(vt == null ? null : vt.clone(), vs.clone()); decl.importDetails(v, false); decl.importDetails(vs, false); decl.importDetails(v.getValueType(), true); v.replaceBy(null);
public VariablesDeclaration(TypeRef valueType, List<Declarator> declarators) { setValueType(valueType); setDeclarators(declarators); } @Override
protected boolean isField(VariablesDeclaration vd) { List<Modifier> mods = vd.getModifiers(); if (vd.hasModifier(ModifierType.Final)) { return false; } if (vd.getValueType() == null || vd.getValueType().toString().equals(VirtualTablePointer.class.getName())) { return false; } return true; }
@Override public void visitVariablesDeclaration(VariablesDeclaration v) { if (v.getDeclarators().isEmpty() && v.getValueType() instanceof TaggedTypeRef) { TaggedTypeRefDeclaration d = new TaggedTypeRefDeclaration((TaggedTypeRef) v.getValueType()); d.importComments(v); v.replaceBy(d); d.accept(this); } else { super.visitVariablesDeclaration(v); } }
@Override public void visitVariablesDeclaration(VariablesDeclaration v) { super.visitVariablesDeclaration(v); if (v.getDeclarators().size() == 1) { Declarator decl = v.getDeclarators().get(0); TypeRef vt = v.getValueType(); MutableByDeclarator mt = decl instanceof DirectDeclarator ? vt : decl.mutateTypeKeepingParent(vt); deleteStat.setCommentAfter("// object would end up being deleted by the GC later, but in C++ it would be deleted here."); Statement.Block parentBlock = (Statement.Block) v.getParentElement(); List<Statement> stats = new ArrayList<Statement>(parentBlock.getStatements()); for (int i = stats.size(); i-- != 0;) { ); v.setValueType(conv.getTypeRef(false)); v.setDeclarators(Arrays.asList((Declarator) new DirectDeclarator(decl.resolveName(), newAllocateArray(((TargettedTypeRef) mutatedType).getTarget(), conv.arrayLengths))));
if (vd.getDeclarators().size() != 1) { continue; // should not happen ! String name = vd.getDeclarators().get(0).resolveName(); TypeRef tr = vd.getValueType(); if (!isField(vd)) { continue; pair.getSecond().add(new Pair<String, String>(vd.getCommentBefore(), name)); int iArg = 0; for (VariablesDeclaration vd : new CompoundCollection<VariablesDeclaration>(decls.getFirst(), decls.getSecond())) { String name = chooseJavaArgName(vd.getDeclarators().get(0).resolveName(), iArg, names); namesById.put(vd.getId(), name); fieldsConstr.addArg(new Arg(name, vd.getValueType().clone())); iArg++; String name = vd.getDeclarators().get(0).resolveName(), uname = namesById.get(vd.getId()); Struct parent = (Struct) vd.getParentElement(); Identifier parentTgName = typeConverter().getTaggedTypeIdentifierInJava(parent); if (!result.config.noComments) { fieldsConstr.addToCommentBefore("@param " + name + " @see " + parentTgName + "#" + vd.getDeclarators().get(0).resolveName()); String name = vd.getDeclarators().get(0).resolveName(), uname = namesById.get(vd.getId()); if (!result.config.noComments) { if (vd.getCommentBefore() != null) { fieldsConstr.addToCommentBefore("@param " + uname + " " + vd.getCommentBefore()); if (vd.getValueType() instanceof TypeRef.ArrayRef) {
return; for (Declarator d : globals.getDeclarators()) { try { Identifier name = result.typeConverter.getValidJavaArgumentName(ident(d.resolveName())); TypeRef type = (TypeRef) d.mutateTypeKeepingParent(globals.getValueType()); if (type == null) { continue; modifiers.addAll(globals.getModifiers()); VariablesDeclaration vd = new VariablesDeclaration( globalType, new Declarator.DirectDeclarator( vd.addModifiers(ModifierType.Public, ModifierType.Static, ModifierType.Final); vd.importComments(globals); holderStruct.addModifiers(ModifierType.Final); VariablesDeclaration vd = ((JNADeclarationsConverter) result.declarationsConverter).convertVariablesDeclarationToJNA("value", type, new int[1], callerLibraryName); if (vd.getValueType().toString().equals(result.config.runtime.pointerClass.getName())) { isByRef = true; instType = convPointerType; struct.addDeclaration(new VariablesDeclaration(instType, new Declarator.DirectDeclarator(instName.toString())).addModifiers(ModifierType.Private, ModifierType.Static)); Expression.VariableRef instRef = new Expression.VariableRef(instName); Expression ptrExpr = methodCall(
VariablesDeclaration vd = new VariablesDeclaration(tr, new DirectDeclarator(name, val.getFirst())); if (!result.config.noComments) { vd.setCommentBefore(v.getCommentBefore()); vd.addToCommentBefore(decl.getCommentBefore()); vd.addToCommentBefore(decl.getCommentAfter()); vd.addToCommentBefore(v.getCommentAfter()); vd.addModifiers(ModifierType.Public, ModifierType.Static, ModifierType.Final);
TypeRef valueType = v.getValueType(); for (Declarator vs : v.getDeclarators()) { String name = vs.resolveName(); if (name == null || name.length() == 0) { Declarator d = v.getDeclarators().get(0); if (d.getBits() > 0) { int bits = d.getBits(); vd.addAnnotation(new Annotation(result.config.runtime.typeRef(JNAeratorConfig.Runtime.Ann.Bits), expr(bits))); String st = vd.getValueType().toString(), mst = st; if (st.equals("int") || st.equals("long") || st.equals("short") || st.equals("long")) { if (bits <= 8) { vd.setValueType(new Primitive(mst)); vd.addToCommentBefore("C type : " + mutatedType); Function getMethod = new Function(Function.Type.JavaMethod, ident("get" + StringUtils.capitalize(name)), vd.getValueType().clone()).setBody(block( new Statement.Return(varRef(name)))).addModifiers(ModifierType.Public); if (signatures.addMethod(getMethod)) { Function setMethod = new Function(Function.Type.JavaMethod, ident("set" + StringUtils.capitalize(name)), typeRef(Void.TYPE), new Arg(name, vd.getValueType().clone())).setBody(block( stat(expr(memberRef(thisRef(), MemberRefStyle.Dot, ident(name)), AssignmentOperator.Equal, varRef(name))))).addModifiers(ModifierType.Public); if (signatures.addMethod(setMethod)) {
public static Statement stat(TypeRef tr, String varName, Expression ass) { VariablesDeclaration vd = new VariablesDeclaration(tr, new Declarator.DirectDeclarator(varName, ass)); return vd;//new Statement.DeclarationStatement(vd); }
public void visitVariablesDeclaration(VariablesDeclaration v) { visitDeclaration(v); visit(v.getDeclarators()); }
@Override public void visitConstant(Constant c) { if (c.getValue() instanceof String) { //Struct s = c.findParentOfType(Struct.class); Class charClass; String ptrMethodName; if (c.getType() == Constant.Type.LongString) { charClass = Short.class; ptrMethodName = "pointerToWideCString"; } else { charClass = Byte.class; ptrMethodName = "pointerToCString"; } String fieldName = "strConstant" + (++nConstants); VariablesDeclaration staticConstField = new VariablesDeclaration(typeRef(ident(ptrClass(), expr(typeRef(charClass)))), new DirectDeclarator(fieldName, staticPtrMethod(ptrMethodName, c.clone()))); staticConstField.addModifiers(ModifierType.Static, ModifierType.Private, ModifierType.Final); //s.addDeclaration(staticConstField); extraDeclarationsOut.add(staticConstField); c.replaceBy(varRef(fieldName)); return; } super.visitConstant(c); } //
@Test public void addSibling() { VariablesDeclaration d = new VariablesDeclaration(); Declarator s1 = new Declarator.DirectDeclarator(), s2 = new Declarator.DirectDeclarator(); d.setDeclarators(Arrays.asList(s1)); s1.insertSibling(s2, false); List<Declarator> list = d.getDeclarators(); assertEquals("Failed to add after", 2, list.size()); assertSame("Added, but not after", s1, list.get(0)); assertSame(s2, list.get(1)); s2.replaceBy(null); list = d.getDeclarators(); assertEquals("Failed to remove added element", 1, list.size()); assertSame("Removed bad element", s1, list.get(0)); d.setDeclarators(Arrays.asList(s1)); s1.insertSibling(s2, true); list = d.getDeclarators(); assertEquals("Failed to add before", 2, list.size()); assertSame("Added, but not before", s2, list.get(0)); assertSame(s1, list.get(1)); s2.replaceBy(null); list = d.getDeclarators(); assertEquals("Failed to remove added element", 1, list.size()); assertSame("Removed bad element", s1, list.get(0)); } }
typeDef = new TypeDef(vd.getValueType(), vd.getDeclarators());
if (v.findParentOfType(Struct.class) != null) { return; if (v.getValueType() instanceof FunctionSignature) { return; for (Declarator decl : v.getDeclarators()) { if (!(decl instanceof DirectDeclarator)) { continue; // TODO provide a mapping of exported values TypeRef mutatedType = (TypeRef) decl.mutateTypeKeepingParent(v.getValueType()); if (mutatedType == null || !mutatedType.getModifiers().contains(ModifierType.Const)
field = new VariablesDeclaration(); field.addDeclarator(declarator = new DirectDeclarator()); field.setValueType(fieldType); field.setValueType(typeRef("int"));
protected void outputNSString(String name, String value, DeclarationsHolder out, Signatures signatures, Element... elementsToTakeCommentsFrom) { if (!signatures.addVariable(name)) { return; } TypeRef tr = typeRef(String.class); VariablesDeclaration vd = new VariablesDeclaration(tr, new DirectDeclarator(name, expr(value))); if (!result.config.noComments) { for (Element e : elementsToTakeCommentsFrom) { vd.addToCommentBefore(e.getCommentBefore()); vd.addToCommentBefore(e.getCommentAfter()); } } vd.addModifiers(ModifierType.Public); out.addDeclaration(vd); } static Map<Class<?>, Pair<List<Pair<Function, String>>, Set<String>>> cachedForcedMethodsAndTheirSignatures;
decl = new VariablesDeclaration(tr); decl.setDeclarators(d1);
public void visitVariablesDeclaration(VariablesDeclaration e) { formatComments(e, false, true, true); if (!e.getAnnotations().isEmpty()) { implode(e.getAnnotations(), "\n" + indent).append("\n", indent); } modifiersStringPrefix(e); valueTypeAndStorageSuffix(e); if (!(e.getParentElement() instanceof Catch)) { append(";"); } if (e.getCommentAfter() != null) { space().append(e.getCommentAfter()); } }