void addConstructor(Struct s, Function f) { Identifier structName = getActualTaggedTypeName(s); f.setName(structName); s.addDeclaration(f); }
public Function(Type type, Identifier name, TypeRef returnType) { setType(type); setName(name); setValueType(returnType); } public Function(Type type, Identifier name, TypeRef returnType, Arg... args) {
void addConstructor(Struct s, Function f) { Identifier structName = getActualTaggedTypeName(s); f.setName(structName); s.addDeclaration(f); }
public Function(Type type, Identifier name, TypeRef returnType, List<Arg> args) { setType(type); setName(name); setValueType(returnType); setArgs(args); }
public MutableByDeclarator mutateType(MutableByDeclarator type) { if (type == null) return null; type = type.clone(); if (type instanceof Function) { ((Function)type).setName(new Identifier.SimpleIdentifier(getName())); } ((Element)type).importDetails(this, false); return type; } @Override
private void fillIn(Signatures signatures, Identifier functionName, Function nativeMethod, NL4JConversion returnType, List<NL4JConversion> paramTypes, List<String> paramNames, Identifier varArgType, String varArgName, boolean isCallback, boolean useRawTypes) { for (int i = 0, n = paramTypes.size(); i < n; i++) { NL4JConversion paramType = paramTypes.get(i); String paramName = paramNames.get(i); nativeMethod.addArg(paramType.annotateTypedType(new Arg(paramName, paramType.getTypeRef(useRawTypes)), useRawTypes));//.getTypedTypeRef()))); } if (varArgType != null) { nativeMethod.addArg(new Arg(varArgName, typeRef(varArgType.clone()))).setVarArg(true); } if (returnType != null) { returnType.annotateTypedType(nativeMethod, useRawTypes); nativeMethod.setValueType(returnType.getTypeRef(useRawTypes)); } String natSig = nativeMethod.computeSignature(SignatureType.JavaStyle); Identifier javaMethodName = signatures == null ? functionName : signatures.findNextMethodName(natSig, functionName); if (!javaMethodName.equals(functionName)) { nativeMethod.setName(javaMethodName); } }
private void fillIn(Signatures signatures, Identifier functionName, Function nativeMethod, NL4JConversion returnType, List<NL4JConversion> paramTypes, List<String> paramNames, Identifier varArgType, String varArgName, boolean isCallback, boolean useRawTypes) { for (int i = 0, n = paramTypes.size(); i < n; i++) { NL4JConversion paramType = paramTypes.get(i); String paramName = paramNames.get(i); nativeMethod.addArg(paramType.annotateTypedType(new Arg(paramName, paramType.getTypeRef(useRawTypes)), useRawTypes));//.getTypedTypeRef()))); } if (varArgType != null) { nativeMethod.addArg(new Arg(varArgName, typeRef(varArgType.clone()))).setVarArg(true); } if (returnType != null) { returnType.annotateTypedType(nativeMethod, useRawTypes); nativeMethod.setValueType(returnType.getTypeRef(useRawTypes)); } String natSig = nativeMethod.computeSignature(SignatureType.JavaStyle); Identifier javaMethodName = signatures == null ? functionName : signatures.findNextMethodName(natSig, functionName); if (!javaMethodName.equals(functionName)) { nativeMethod.setName(javaMethodName); } }
@Override public boolean replaceChild(Element child, Element by) { if (child == getBody()) { setBody((Statement.Block)by); return true; } if (child == getName()) { setName((Identifier)by); return true; } if (replaceChild(args, Arg.class, this, child, by)) return true; if (replaceChild(thrown, TypeRef.class, this, child, by)) return true; if (replaceChild(initializers, FunctionCall.class, this, child, by)) return true; return super.replaceChild(child, by); }
/** * @return true if the functionSignature changed and triggerered * revisitation */ private boolean chooseNameIfMissing(FunctionSignature functionSignature) { Function function = functionSignature.getFunction(); Element parent = functionSignature.getParentElement(); if (function != null && (isNull(function.getName()) || parent instanceof VariablesDeclaration || parent instanceof Arg)) { String name = null; String exact = JNAeratorUtils.getExactTypeDefName(functionSignature); if (exact != null) { name = exact; } else { List<String> ownerNames = JNAeratorUtils.guessOwnerName(function); if (function.getName() != null) { ownerNames.add(function.getName().toString()); } name = chooseName(functionSignature, ownerNames, true); } if (name != null) { function.setName(ident(name)); function.accept(this); return true; } } return false; } Map<String, Integer> nextUnnamedId = new LinkedHashMap<String, Integer>();
/** * @return true if the functionSignature changed and triggerered * revisitation */ private boolean chooseNameIfMissing(FunctionSignature functionSignature) { Function function = functionSignature.getFunction(); Element parent = functionSignature.getParentElement(); if (function != null && (isNull(function.getName()) || parent instanceof VariablesDeclaration || parent instanceof Arg)) { String name = null; String exact = JNAeratorUtils.getExactTypeDefName(functionSignature); if (exact != null) { name = exact; } else { List<String> ownerNames = JNAeratorUtils.guessOwnerName(function); if (function.getName() != null) { ownerNames.add(function.getName().toString()); } name = chooseName(functionSignature, ownerNames, true); } if (name != null) { function.setName(ident(name)); function.accept(this); return true; } } return false; } Map<String, Integer> nextUnnamedId = new LinkedHashMap<String, Integer>();
createCopy.setCommentBefore("Factory method"); createCopy.addToCommentBefore("@see #" + meth.computeSignature(SignatureType.JavaStyle)); createCopy.setName(ident("create" + name.substring("init".length()))); createCopy.addModifiers(ModifierType.Public, ModifierType.Static); createCopy.reorganizeModifiers();
createCopy.setCommentBefore("Factory method"); createCopy.addToCommentBefore("@see #" + meth.computeSignature(SignatureType.JavaStyle)); createCopy.setName(ident("create" + name.substring("init".length()))); createCopy.addModifiers(ModifierType.Public, ModifierType.Static); createCopy.reorganizeModifiers();
Function createCastMethod(Identifier name, Identifier classId, boolean isStatic) { Function m = new Function(); m.setType(Function.Type.JavaMethod); m.addModifiers(ModifierType.Public); m.setName(ident("as" + (isStatic ? "Static_" : "_") + name)); m.setValueType(typeRef(classId.clone())); m.setBody(block( new Statement.Return( methodCall( expr(typeRef(Rococoa.class)), MemberRefStyle.Dot, "cast", varRef("this"), result.typeConverter.typeLiteral(typeRef(classId.clone())))))); return m; }
Function createCastMethod(Identifier name, Identifier classId, boolean isStatic) { Function m = new Function(); m.setType(Function.Type.JavaMethod); m.addModifiers(ModifierType.Public); m.setName(ident("as" + (isStatic ? "Static_" : "_") + name)); m.setValueType(typeRef(classId.clone())); m.setBody(block( new Statement.Return( methodCall( expr(typeRef(Rococoa.class)), MemberRefStyle.Dot, "cast", varRef("this"), result.typeConverter.typeLiteral(typeRef(classId.clone())))))); return m; }
@Override public void visitArg(Arg arg) { Declarator d = arg.getDeclarator(); if (d == null) { TypeRef tr = arg.getValueType(); if (tr instanceof TypeRef.Pointer) { TypeRef target = ((TypeRef.Pointer)tr).getTarget(); if (target instanceof TypeRef.FunctionSignature) { TypeRef.FunctionSignature fs = (TypeRef.FunctionSignature) target; Identifier name = fs.getFunction() == null ? null : fs.getFunction().getName(); if (name != null) { arg.setDeclarator(new DirectDeclarator(name.toString())); fs.getFunction().setName(null); } } } } else if (!(d instanceof DirectDeclarator)) { MutableByDeclarator type = d.mutateType(arg.getValueType()); if (type instanceof TypeRef) { arg.setValueType((TypeRef) type); arg.setDeclarator(new DirectDeclarator(d.resolveName(), d.getBits(), arg.getDefaultValue())); } else { type = null; } } super.visitArg(arg); } private static final boolean mutateDeclaratorTypes = true;
@Override public void visitArg(Arg arg) { Declarator d = arg.getDeclarator(); if (d == null) { TypeRef tr = arg.getValueType(); if (tr instanceof TypeRef.Pointer) { TypeRef target = ((TypeRef.Pointer)tr).getTarget(); if (target instanceof TypeRef.FunctionSignature) { TypeRef.FunctionSignature fs = (TypeRef.FunctionSignature) target; Identifier name = fs.getFunction() == null ? null : fs.getFunction().getName(); if (name != null) { arg.setDeclarator(new DirectDeclarator(name.toString())); fs.getFunction().setName(null); } } } } else if (!(d instanceof DirectDeclarator)) { MutableByDeclarator type = d.mutateType(arg.getValueType()); if (type instanceof TypeRef) { arg.setValueType((TypeRef) type); arg.setDeclarator(new DirectDeclarator(d.resolveName(), d.getBits(), arg.getDefaultValue())); } else { type = null; } } super.visitArg(arg); } private static final boolean mutateDeclaratorTypes = true;
if (mutatedType instanceof Function) { Function f = (Function) mutatedType; f.setName(new SimpleIdentifier(vs.resolveName())); decl = (Function) mutatedType; decl.importDetails(v, false);
if (mutatedType instanceof Function) { Function f = (Function) mutatedType; f.setName(new SimpleIdentifier(vs.resolveName())); decl = (Function) mutatedType; decl.importDetails(v, false);
if (arg.getName() == null) { arg.setName(origName.toString()); functionSignature.getFunction().setName(null);
if (arg.getName() == null) { arg.setName(origName.toString()); functionSignature.getFunction().setName(null);