private CXChildVisitResult Visitor(CXCursor cursor, CXCursor parent, IntPtr data) { if (CXCursorKind.CXCursor_ParmDecl == cursor.kind) { // prepare client data GCHandle funcHandle = (GCHandle)data; FunctionProto proto = funcHandle.Target as FunctionProto; CXType type = clang.getCursorType(cursor); FunctionParameter param = new FunctionParameter { Name = clang.getCursorSpelling(cursor).ToString(), Type = TypeVisitorHelper.GetNativeType(AST_, type) }; clang.visitChildren(cursor, (CXCursor c, CXCursor p, IntPtr d) => { if (ClangTraits.IsLiteralCursor(c)) { // get liter-string from token List <string> tokens = ASTVisitor.GetCursorTokens(c); // set default literal param.DefaultValue = string.Concat(tokens); } return(CXChildVisitResult.CXChildVisit_Continue); }, new CXClientData(IntPtr.Zero)); proto.AddParameter(param); } return(CXChildVisitResult.CXChildVisit_Recurse); }
private static FunctionProto GetFunctionProto(AST ast, CXType funcType, TypeVisitContext context) { Debug.Assert(ClangTraits.IsFunction(funcType)); FunctionProto proto = new FunctionProto(); proto.ResultType = GetNativeType(ast, clang.getResultType(funcType), context); uint arity = (uint)clang.getNumArgTypes(funcType); for (uint loop = 0; loop < arity; ++loop) { CXType argType = clang.getArgType(funcType, loop); FunctionParameter param = new FunctionParameter(); param.Type = GetNativeType(ast, argType, context); proto.AddParameter(param); } return(proto); }