@Override public void visitFunctionSignature(FunctionSignature functionSignature) { super.visitFunctionSignature(functionSignature); Function function = functionSignature.getFunction(); Identifier name = typeConverter.inferCallBackName(functionSignature, false, false, null); Identifier identifier = typeConverter.computeCallbackIdentifierInJava(functionSignature); functionSignature.setResolvedJavaIdentifier(identifier); if (function != null) { if (functionSignature.findParentOfType(Struct.class) == null) { getList(callbacksByLibrary, getLibrary(functionSignature)).add(functionSignature); } if (name != null) { callbacksByName.put(name, functionSignature); if (identifier != null) { callbacksFullNames.add(identifier); } } } }
@Override public void visitFunctionSignature(FunctionSignature functionSignature) { super.visitFunctionSignature(functionSignature); Function function = functionSignature.getFunction(); Identifier name = typeConverter.inferCallBackName(functionSignature, false, false, null); Identifier identifier = typeConverter.computeCallbackIdentifierInJava(functionSignature); functionSignature.setResolvedJavaIdentifier(identifier); if (function != null) { if (functionSignature.findParentOfType(Struct.class) == null) { getList(callbacksByLibrary, getLibrary(functionSignature)).add(functionSignature); } if (name != null) { callbacksByName.put(name, functionSignature); if (identifier != null) { callbacksFullNames.add(identifier); } } } }
protected void valueTypeAndStorageSuffix(StoredDeclarations e) { if (e.getValueType() instanceof FunctionSignature) { FunctionSignature sig = (FunctionSignature) e.getValueType(); if (sig.getFunction() != null) { Identifier name = sig.getFunction().getName(); if (name != null && e.declarators.size() == 1) { String stoName = e.declarators.get(0).resolveName(); if (name.equals(stoName) || stoName == null) { append(sig); return; } } } } append(e.getValueType()).space(!e.getDeclarators().isEmpty()).implode(e.getDeclarators(), ", "); }
@Override public void visitFunctionSignature(FunctionSignature functionSignature) { Identifier origName = functionSignature.getFunction() == null ? null : functionSignature.getFunction().getName(); Element parent = functionSignature.getParentElement(); if (arg.getName() == null) { arg.setName(origName.toString()); functionSignature.getFunction().setName(null); Function f = functionSignature.getFunction(); if (holder != null && f != null && !isNull(f.getName())) { Identifier fnameClone = f.getName().clone();
@Override public void visitFunctionSignature(FunctionSignature functionSignature) { Identifier origName = functionSignature.getFunction() == null ? null : functionSignature.getFunction().getName(); Element parent = functionSignature.getParentElement(); if (arg.getName() == null) { arg.setName(origName.toString()); functionSignature.getFunction().setName(null); Function f = functionSignature.getFunction(); if (holder != null && f != null && !isNull(f.getName())) { Identifier fnameClone = f.getName().clone();
((FunctionSignature)tr).getFunction().getName() != null )) ) { if (state.backtracking>0) {state.failed=true; return decl;}
Function function = functionSignature.getFunction();
@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;
Function function = functionSignature.getFunction();
/** * @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>();
public void visitFunctionSignature(FunctionSignature e) { if (e.getFunction() == null) { return; } assert e.getFunction().getBody() == null; modifiersStringPrefix(e); append(e.getFunction().getValueType()).space(e.getFunction().getValueType() != null); if (e.getParentElement() instanceof TypeRef.Pointer) { append("("); modifiersStringPrefix(e.getFunction()); switch (e.getType()) { case CFunction: append("*"); break; case ObjCBlock: append("^"); break; } append(e.getFunction().getName()); append(")"); } else { append(e.getFunction().getName()); } append("("); implode(e.getFunction().getArgs(), ", "); append(")"); append(e.getModifiers().isEmpty() ? "" : " "); implode(e.getModifiers(), " "); }
/** * @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>();
@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;
protected void variableDeclarationToString(TypeRef e, String varName, boolean isVarArg) { if (e instanceof FunctionSignature) { FunctionSignature fs = (FunctionSignature) e; if (!isVarArg && fs.getFunction() != null && fs.getFunction().getName() != null) { append(indent); return; } } else if (e instanceof ArrayRef) { ArrayRef ar = (ArrayRef) e; append(ar.getTarget(), isVarArg ? "... " : " ", varName); bracketsToString(ar); return; } append(e).append(isVarArg ? "... " : " ").append(varName); }
@Override public Struct convertCallback(FunctionSignature functionSignature, Signatures signatures, Identifier callerLibraryName) { Struct decl = super.convertCallback(functionSignature, signatures, callerLibraryName); if (decl != null) { List<Modifier> mods = functionSignature.getFunction().getModifiers(); decl.setParents(Arrays.asList((SimpleTypeRef) typeRef( functionSignature.getFunction().hasModifier(ModifierType.__stdcall) ? StdCallLibrary.StdCallCallback.class : result.config.runtime.callbackClass))); } return decl; } static Map<Class<?>, Pair<List<Pair<Function, String>>, Set<String>>> cachedForcedMethodsAndTheirSignatures;
@Override public Struct convertCallback(FunctionSignature functionSignature, Signatures signatures, Identifier callerLibraryName) { Struct decl = super.convertCallback(functionSignature, signatures, callerLibraryName); if (decl != null) { List<Modifier> mods = functionSignature.getFunction().getModifiers(); decl.setParents(Arrays.asList((SimpleTypeRef) typeRef( functionSignature.getFunction().hasModifier(ModifierType.__stdcall) ? StdCallLibrary.StdCallCallback.class : result.config.runtime.callbackClass))); } return decl; } static Map<Class<?>, Pair<List<Pair<Function, String>>, Set<String>>> cachedForcedMethodsAndTheirSignatures;
public static boolean isNamedFunctionType(TypeRef tr) { if (!(tr instanceof FunctionSignature)) { return false; } FunctionSignature fs = (FunctionSignature) tr; Function f = fs.getFunction(); return f != null && f.getName() != null; }
public void visitFunctionSignature(FunctionSignature functionSignature) { visitTypeRef(functionSignature); if (functionSignature != null) visit(functionSignature.getFunction()); }
@Override public boolean replaceChild(Element child, Element by) { if (getFunction() == child) { setFunction((Function) by); return true; } return super.replaceChild(child, by); } }
public static boolean isNamedFunctionType(TypeRef tr) { if (!(tr instanceof FunctionSignature)) { return false; } FunctionSignature fs = (FunctionSignature) tr; Function f = fs.getFunction(); return f != null && f.getName() != null; }