/// <summary> /// Tokenize the source code described by the given range into raw lexical tokens. /// </summary> /// <param name="range">The range to tokenize.</param> /// <returns>A list of raw lexical tokens.</returns> public IEnumerable <Token> Tokenize(SourceRange range, TokenKind filter = TokenKind.All) { IntPtr tokenPtr; uint numTokens; Interop.clang_tokenize(Native, range.Native, out tokenPtr, out numTokens); var tokens = new Interop.Token[numTokens]; try { unsafe { for (uint i = 0; i < numTokens; ++i) { tokens[i] = *(Interop.Token *)(tokenPtr + (int)(i * sizeof(Interop.Token))); } return(tokens .Where(t => filter == TokenKind.All || Interop.clang_getTokenKind(t) == filter) .Select(token => new Token(token, this))); } } finally { Interop.clang_disposeTokens(Native, tokenPtr, numTokens); } }
public string GetText(SourceRange extent) { return Encoding.GetString(_bytes.Slice(extent)); }
/// <summary> /// Tokenize the source code described by the given range into raw lexical tokens. /// </summary> /// <param name="range">The range to tokenize.</param> /// <returns>A list of raw lexical tokens.</returns> public IEnumerable<Token> Tokenize(SourceRange range, TokenKind filter = TokenKind.All) { IntPtr tokenPtr; uint numTokens; Interop.clang_tokenize(Native, range.Native, out tokenPtr, out numTokens); var tokens = new Interop.Token[numTokens]; try { unsafe { for (uint i = 0; i < numTokens; ++i) { tokens[i] = *(Interop.Token*)(tokenPtr + (int)(i * sizeof(Interop.Token))); } return tokens .Where(t => filter == TokenKind.All || Interop.clang_getTokenKind(t) == filter) .Select(token => new Token(token, this)); } } finally { Interop.clang_disposeTokens(Native, tokenPtr, numTokens); } }
public static extern void clang_tokenize(IntPtr tu, SourceRange range, out IntPtr tokens, out uint numTokens);
public static extern ClangString clang_getDiagnosticFixIt( IntPtr diag, uint fixit, out SourceRange replacementRange);
public static extern SourceLocation clang_getRangeEnd(SourceRange range);
public static T[] Slice <T>(this IList <T> collection, SourceRange range) { return(Slice(collection, range.Start.Offset, range.End.Offset - range.Start.Offset)); }
public static string Substring(this string source, SourceRange range) { return(source.Substring(range.Start.Offset, range.End.Offset - range.Start.Offset)); }
public string GetText(SourceRange extent) { return(Encoding.GetString(_bytes.Slice(extent))); }