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 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 static String getMethodName(Function function) { StringBuilder nb = new StringBuilder(); nb.append(function.getName()); boolean firstArg = true; for (Arg arg : function.getArgs()) { if (arg.isVarArg()) { continue; } if (firstArg) { firstArg = false; } else { nb.append("_"); nb.append(arg.getSelector()); } } return nb.toString(); }
public static String getMethodName(Function function) { StringBuilder nb = new StringBuilder(); nb.append(function.getName()); boolean firstArg = true; for (Arg arg : function.getArgs()) { if (arg.isVarArg()) { continue; } if (firstArg) { firstArg = false; } else { nb.append("_"); nb.append(arg.getSelector()); } } return nb.toString(); }
public static Identifier getName(Element element) { if (element instanceof Function) return ((Function) element).getName(); if (element instanceof TaggedTypeRefDeclaration) return getName(((TaggedTypeRefDeclaration) element).getTaggedTypeRef()); if (element instanceof TypeRef.TaggedTypeRef) return ((TypeRef.TaggedTypeRef) element).getTag(); return null; }
@Override public void visitFunction(final Function element) { currentTable.defineVariable(element.getName(), element); currentTable = new SymbolTable(currentTable, null, element); try { super.visitFunction(element); } finally { currentTable = currentTable.parent; } }
public final void convertFunctions(List<Function> functions, Signatures signatures, DeclarationsHolder declarations, DeclarationsHolder implementations) { if (functions != null) { //System.err.println("FUNCTIONS " + functions); for (Function function : functions) { if (skip(function.getName() + "", result.config.skippedFunctionNames)) continue; convertFunction(function, signatures, false, declarations, implementations, declarations.getResolvedJavaIdentifier(), -1); } } }
public final void convertFunctions(List<Function> functions, Signatures signatures, DeclarationsHolder declarations, DeclarationsHolder implementations) { if (functions != null) { //System.err.println("FUNCTIONS " + functions); for (Function function : functions) { if (skip(function.getName() + "", result.config.skippedFunctionNames)) continue; convertFunction(function, signatures, false, declarations, implementations, declarations.getResolvedJavaIdentifier(), -1); } } }
@Override public void visitFunction(final Function element) { currentTable.defineVariable(element.getName(), element); currentTable = new SymbolTable(currentTable, null, element); try { super.visitFunction(element); } finally { currentTable = currentTable.parent; } }
public static TypeRef fixReturnType(Function function) { TypeRef returnType = function.getValueType(); if (returnType == null) { returnType = RococoaUtils.ROCOCOA_ID_TYPEREF; } Struct declaringClass = function.findParentOfType(Struct.class); if (returnType.toString().equals("id")) { String pointedClassName; if (function.getName().toString().matches("^(alloc|(init|copy|mutableCopy)([A-Z].*)?)$") || RococoaUtils.methodNameMatchesObjcStaticConstructor(declaringClass, function.getName())) { pointedClassName = declaringClass.getTag().toString(); } else /// Lets subclasses redefine method return type when parent method return type is ID { pointedClassName = "NSObject"; } returnType = new TypeRef.Pointer(new TypeRef.SimpleTypeRef(pointedClassName), PointerStyle.Pointer); } return returnType; } }
public static TypeRef fixReturnType(Function function) { TypeRef returnType = function.getValueType(); if (returnType == null) { returnType = RococoaUtils.ROCOCOA_ID_TYPEREF; } Struct declaringClass = function.findParentOfType(Struct.class); if (returnType.toString().equals("id")) { String pointedClassName; if (function.getName().toString().matches("^(alloc|(init|copy|mutableCopy)([A-Z].*)?)$") || RococoaUtils.methodNameMatchesObjcStaticConstructor(declaringClass, function.getName())) { pointedClassName = declaringClass.getTag().toString(); } else /// Lets subclasses redefine method return type when parent method return type is ID { pointedClassName = "NSObject"; } returnType = new TypeRef.Pointer(new TypeRef.SimpleTypeRef(pointedClassName), PointerStyle.Pointer); } return returnType; } }
@Override public void sourcesParsed(SourceFiles sourceFiles) { List<SourceFile> files = sourceFiles.getSourceFiles(); assertTrue(pref + "Parsing failed completely", !files.isEmpty()); //assertTrue(pref + "Expected more than one source file", files.size() > 1); SourceFile lastFile = files.get(files.size() - 1); List<Declaration> declarations = lastFile.getDeclarations(); assertTrue(pref + "Only parsed " + declarations.size() + " declarations", declarations.size() > 1); Declaration d = declarations.get(declarations.size() - 1); assertTrue(pref + "Not a function: " + d + " (" + (d == null ? "?" : d.getClass().getName()) + ")", d instanceof Function); Function f = (Function)d; assertEquals(pref + "Didn't find " + testFunctionName, testFunctionName, f.getName() + ""); }
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(), ", "); }
private void addAllocIfMissing(Struct in, String allocName) { Identifier n = in.getTag(); if (n.equals("NSObject") || n.equals("NSClass")) { return; } boolean hasAlloc = false; for (Declaration d : in.getDeclarations()) { if (d instanceof Function) { Function f = (Function) d; if (f.getArgs().isEmpty() && allocName.equals(f.getName())) { hasAlloc = true; break; } } } if (!hasAlloc) { in.addDeclaration(new Function(Function.Type.ObjCMethod, ident(allocName), typeRef(in.getTag())).addModifiers(ModifierType.Static)); } }
private void addAllocIfMissing(Struct in, String allocName) { Identifier n = in.getTag(); if (n.equals("NSObject") || n.equals("NSClass")) { return; } boolean hasAlloc = false; for (Declaration d : in.getDeclarations()) { if (d instanceof Function) { Function f = (Function) d; if (f.getArgs().isEmpty() && allocName.equals(f.getName())) { hasAlloc = true; break; } } } if (!hasAlloc) { in.addDeclaration(new Function(Function.Type.ObjCMethod, ident(allocName), typeRef(in.getTag())).addModifiers(ModifierType.Static)); } }
@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); }
public void visitFunction(Function function) { visitDeclaration(function); visit(function.getArgs()); visit(function.getThrown()); visit(function.getInitializers()); visit(function.getBody()); visit(function.getName()); }
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); }
private Function createProxyCopy(Function originalMethod, Function meth) { if (isMethodExcludedFromStaticForwarding(originalMethod)) { return null; } Function proxyCopy = meth.clone(); proxyCopy.addModifiers(ModifierType.Public, ModifierType.Static); proxyCopy.reorganizeModifiers(); Expression[] args = new Expression[meth.getArgs().size()]; int i = 0; for (Arg arg : meth.getArgs()) { args[i++] = varRef(arg.getName()); } Expression val = methodCall(methodCall(null, null, classInstanceGetterName), Expression.MemberRefStyle.Dot, meth.getName().toString(), args); proxyCopy.setBody(new Block( meth.getValueType() == null || "void".equals(meth.getValueType().toString()) ? stat(val) : new Statement.Return(val))); return proxyCopy; } // protected static _class_ _CLASS_ = org.rococoa.Rococoa.createClass("NSURL", _class_.class);
private Function createProxyCopy(Function originalMethod, Function meth) { if (isMethodExcludedFromStaticForwarding(originalMethod)) { return null; } Function proxyCopy = meth.clone(); proxyCopy.addModifiers(ModifierType.Public, ModifierType.Static); proxyCopy.reorganizeModifiers(); Expression[] args = new Expression[meth.getArgs().size()]; int i = 0; for (Arg arg : meth.getArgs()) { args[i++] = varRef(arg.getName()); } Expression val = methodCall(methodCall(null, null, classInstanceGetterName), Expression.MemberRefStyle.Dot, meth.getName().toString(), args); proxyCopy.setBody(new Block( meth.getValueType() == null || "void".equals(meth.getValueType().toString()) ? stat(val) : new Statement.Return(val))); return proxyCopy; } // protected static _class_ _CLASS_ = org.rococoa.Rococoa.createClass("NSURL", _class_.class);