Exemplo n.º 1
0
        private CXChildVisitResult ParameterVisitor(CXCursor cursor, CXCursor parent, IntPtr data)
        {
            if (CXCursorKind.CXCursor_ParmDecl == cursor.kind)
            {
                // prepare client data
                GCHandle astHandle            = (GCHandle)data;
                OnVisitFunctionParameter func = astHandle.Target as OnVisitFunctionParameter;

                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
                        CXSourceRange range = clang.getCursorExtent(c);
                        IntPtr tokens       = IntPtr.Zero;
                        uint numToken;
                        string liter = "";
                        clang.tokenize(ASTVisitor.CurrentTU, range, out tokens, out numToken);
                        IntPtr tmp = tokens;
                        for (uint loop = 0; loop < numToken; ++loop, IntPtr.Add(tmp, 1))
                        {
                            CXToken token = Marshal.PtrToStructure <CXToken>(tmp);
                            liter        += clang.getTokenSpelling(ASTVisitor.CurrentTU, token).ToString();
                        }
                        clang.disposeTokens(ASTVisitor.CurrentTU, tokens, numToken);

                        // set default literal
                        param.DefaultValue = liter;
                    }
                    return(CXChildVisitResult.CXChildVisit_Continue);
                }, new CXClientData(IntPtr.Zero));

                func(param);
            }

            return(CXChildVisitResult.CXChildVisit_Recurse);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public void AddParameter(FunctionParameter param)
 {
     ParamList.Add(param);
 }