Esempio 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);
        }
Esempio n. 2
0
        public static List <string> GetCursorTokens(CXCursor cursor)
        {
            // get liter-string from token
            CXSourceRange range  = clang.getCursorExtent(cursor);
            IntPtr        tokens = IntPtr.Zero;
            uint          numToken;
            List <string> result = new List <string>();

            clang.tokenize(CurrentTU, range, out tokens, out numToken);
            IntPtr tmp = tokens;

            for (uint loop = 0; loop < numToken; ++loop, tmp = IntPtr.Add(tmp, Marshal.SizeOf <CXToken>()))
            {
                CXToken token = Marshal.PtrToStructure <CXToken>(tmp);
                result.Add(clang.getTokenSpelling(CurrentTU, token).ToString());
            }
            clang.disposeTokens(CurrentTU, tokens, numToken);
            return(result);
        }
Esempio n. 3
0
        static CXToken[] Tokenize(CXTranslationUnit tu, CXSourceRange range)
        {
            IntPtr pTokens;
            uint   numTokens;

            clang.tokenize(tu, range, out pTokens, out numTokens);
            try {
                var tokens = new CXToken[numTokens];
                unsafe {
                    var p = (CXToken *)pTokens.ToPointer();
                    for (uint i = 0; i < numTokens; i++)
                    {
                        tokens[i] = p[i];
                    }
                }
                return(tokens);
            } finally {
                clang.disposeTokens(tu, pTokens, numTokens);
            }
        }
Esempio n. 4
0
        public static string[] Tokenize(this CXCursor cursor, CXTranslationUnit translationUnit)
        {
            var    range = clang.getCursorExtent(cursor);
            IntPtr nativeTokens;
            uint   numTokens;

            clang.tokenize(translationUnit, range, out nativeTokens, out numTokens);

            var result = new List <string>();
            var tokens = new CXToken[numTokens];

            for (uint i = 0; i < numTokens; ++i)
            {
                tokens[i]     = (CXToken)Marshal.PtrToStructure(nativeTokens, typeof(CXToken));
                nativeTokens += Marshal.SizeOf(typeof(CXToken));

                var name = clang.getTokenSpelling(translationUnit, tokens[i]).ToString();
                result.Add(name);
            }

            return(result.ToArray());
        }
Esempio n. 5
0
 internal ClangToken(IntPtr translationUnit, CXToken source)
 {
     this.tu     = translationUnit;
     this.source = source;
 }
Esempio n. 6
0
 /// <summary>
 /// Convert to Managed Clang Token
 /// </summary>
 /// <param name="token">Native Clang Token</param>
 /// <param name="tu">Native Clang Translation Unit Pointer</param>
 /// <returns>Managed Clang Token</returns>
 internal static ClangToken ToManaged(this CXToken token, IntPtr tu)
 {
     return(new ClangToken(tu, token));
 }
Esempio n. 7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="translation_unit">Native Clang Translation Unit Pointer</param>
        /// <param name="source">Native Clang Token</param>

        internal ClangToken(IntPtr translation_unit, CXToken source)
        {
            this.TranslationUnit = translation_unit;

            this.Source = source;
        }
Esempio n. 8
0
 internal static unsafe extern void clang_disposeTokens(CXTranslationUnit tu, CXToken* Tokens, uint NumTokens);
Esempio n. 9
0
 internal static unsafe extern void clang_tokenize(CXTranslationUnit tu, CXSourceRange Range, CXToken** Tokens, uint* NumTokens);
Esempio n. 10
0
 internal static extern CXSourceRange clang_getTokenExtent(CXTranslationUnit tu, CXToken tok);
Esempio n. 11
0
 internal static extern CXSourceLocation clang_getTokenLocation(CXTranslationUnit tu, CXToken tok);
Esempio n. 12
0
 internal static extern CXString clang_getTokenSpelling(CXTranslationUnit tu, CXToken tok);
Esempio n. 13
0
 internal static extern TokenKind clang_getTokenKind(CXToken tok);
Esempio n. 14
0
 public VToken(VisitorCursor parent, CXToken token)
 {
     Parent = parent;
     Token  = token;
 }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Token"/> class.
 /// </summary>
 /// <param name="translationUnit">The translationUnit<see cref="TranslationUnit"/></param>
 /// <param name="token">The token<see cref="CXToken"/></param>
 internal Token(TranslationUnit translationUnit, CXToken token)
 {
     this._translationUnit = translationUnit;
     this.m_value          = token;
 }