@Override public void visitIf(If ifStat) { super.visitIf(ifStat); Expression cond = ifStat.getCondition(); if (!(cond instanceof BinaryOp)) // TODO use typing rather than this hack to detect implicit boolean conversion in if statements (and not only there) { cond.replaceBy(expr(cond, BinaryOperator.IsDifferent, expr(0))); } }
public static Expression javaStaticFieldRef(Identifier javaClass, Identifier fieldName) { return memberRef( expr(typeRef(javaClass)), MemberRefStyle.Dot, fieldName); }
public static Expression javaStaticFieldRef(Identifier javaClass, Identifier fieldName) { return memberRef( expr(typeRef(javaClass)), MemberRefStyle.Dot, fieldName); }
private Expression createGetPeerExpression(Expression value) { return methodCall(expr(typeRef(org.bridj.Pointer.class)), "getPeer", value); } private Expression createPointerToAddressExpression(NL4JConversion pointerType, Expression value) {
public static Identifier v8Ident(String name, Identifier... args) { Expression[] exprArgs = new Expression[args.length]; for (int i = 0; i < args.length; i++) { exprArgs[i] = expr(typeRef(args[i])); } return templateIdent(ident("v8", name), exprArgs); }
public Expression arrayLength() { Expression length = null; for (Expression m : arrayLengths) { m.setParenthesis(true); if (length == null) { length = m.clone(); } else { length = expr(length, Expression.BinaryOperator.Multiply, m.clone()); } } return length.setParenthesis(arrayLengths.size() > 1); }
Expression staticPtrMethod(String name, Expression... args) { return methodCall(expr(typeRef(ptrClass())), name, args); } int iFile = 0;
public static Identifier v8Ident(String name, Identifier... args) { Expression[] exprArgs = new Expression[args.length]; for (int i = 0; i < args.length; i++) { exprArgs[i] = expr(typeRef(args[i])); } return templateIdent(ident("v8", name), exprArgs); }
@Override public TypeRef pointerTypeRef(TypeRef targetTypeRef) { return typeRef(ident(result.config.runtime.pointerClass, expr(targetTypeRef.clone()))); }
public Expression typeLiteral(TypeRef c) { if (c == null) { return null; } if (c.toString().equals("?")) { return new Expression.Cast(typeRef(Type.class), Constant.newNull()); } return memberRef(expr(c), MemberRefStyle.Dot, "class"); }
public Expression typeLiteral(TypeRef c) { if (c == null) { return null; } if (c.toString().equals("?")) { return new Expression.Cast(typeRef(Type.class), Constant.newNull()); } return memberRef(expr(c), MemberRefStyle.Dot, "class"); }
private void addParentNamespaceAnnotation(ModifiableElement dest, Identifier parentNamespace) { if (parentNamespace != null) { dest.addAnnotation(new Annotation(typeRef(org.bridj.ann.Namespace.class), expr(parentNamespace.toString()))); } } }
private void addParentNamespaceAnnotation(ModifiableElement dest, Identifier parentNamespace) { if (parentNamespace != null) { dest.addAnnotation(new Annotation(typeRef(org.bridj.ann.Namespace.class), expr(parentNamespace.toString()))); } } }
public Expression getLibraryInstanceReferenceExpression(String libraryName) { Identifier hub = getHubFullClassName(); Identifier classIdent; String fieldName; if (hub != null) { classIdent = hub; fieldName = libraryName; } else { classIdent = getLibraryClassFullName(libraryName); fieldName = "INSTANCE"; } return memberRef(expr(typeRef(classIdent)), MemberRefStyle.Dot, fieldName); }
TypeRef pointerToTypeRef(TypeRef targetType) { Identifier id = ident(ptrClass()); id.resolveLastSimpleIdentifier().addTemplateArgument(expr(targetType)); return typeRef(id); }
Statement throwIfArraySizeDifferent(String varAndFieldName) { return new Statement.If( expr( memberRef(varRef(varAndFieldName), MemberRefStyle.Dot, "length"), BinaryOperator.IsDifferent, memberRef(memberRef(thisRef(), MemberRefStyle.Dot, varAndFieldName), MemberRefStyle.Dot, "length")), new Statement.Throw(new Expression.New(typeRef(IllegalArgumentException.class), expr("Wrong array size !"))), null); }
@Override public Struct convertCallback(FunctionSignature functionSignature, Signatures signatures, Identifier callerLibraryName) { Struct decl = super.convertCallback(functionSignature, signatures, callerLibraryName); if (decl != null) { decl.setParents(Arrays.asList((SimpleTypeRef) (FunctionSignature.Type.ObjCBlock.equals(functionSignature.getType()) ? result.config.runtime.typeRef(JNAeratorConfig.Runtime.Ann.ObjCBlock) : (SimpleTypeRef) typeRef(ident(result.config.runtime.callbackClass, expr(typeRef(decl.getTag().clone()))))))); //addCallingConventionAnnotation(functionSignature.getFunction(), decl); } return decl; }
@Override public Struct convertCallback(FunctionSignature functionSignature, Signatures signatures, Identifier callerLibraryName) { Struct decl = super.convertCallback(functionSignature, signatures, callerLibraryName); if (decl != null) { decl.setParents(Arrays.asList((SimpleTypeRef) (FunctionSignature.Type.ObjCBlock.equals(functionSignature.getType()) ? result.config.runtime.typeRef(JNAeratorConfig.Runtime.Ann.ObjCBlock) : (SimpleTypeRef) typeRef(ident(result.config.runtime.callbackClass, expr(typeRef(decl.getTag().clone()))))))); //addCallingConventionAnnotation(functionSignature.getFunction(), decl); } return decl; }
private Function newStaticInit() { Function f = new Function(Function.Type.StaticInit, null, null).setBody(block( stat(methodCall( expr(typeRef(BridJ.class)), Expression.MemberRefStyle.Dot, "register")))).addModifiers(ModifierType.Static); return f; }
private Function newStaticInit() { Function f = new Function(Function.Type.StaticInit, null, null).setBody(block( stat(methodCall( expr(typeRef(BridJ.class)), Expression.MemberRefStyle.Dot, "register")))).addModifiers(ModifierType.Static); return f; }