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); }
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); }
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); } }
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()); }
internal ClangToken(IntPtr translationUnit, CXToken source) { this.tu = translationUnit; this.source = source; }
/// <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)); }
/// <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; }
internal static unsafe extern void clang_disposeTokens(CXTranslationUnit tu, CXToken* Tokens, uint NumTokens);
internal static unsafe extern void clang_tokenize(CXTranslationUnit tu, CXSourceRange Range, CXToken** Tokens, uint* NumTokens);
internal static extern CXSourceRange clang_getTokenExtent(CXTranslationUnit tu, CXToken tok);
internal static extern CXSourceLocation clang_getTokenLocation(CXTranslationUnit tu, CXToken tok);
internal static extern CXString clang_getTokenSpelling(CXTranslationUnit tu, CXToken tok);
internal static extern TokenKind clang_getTokenKind(CXToken tok);
public VToken(VisitorCursor parent, CXToken token) { Parent = parent; Token = token; }
/// <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; }