Пример #1
0
        /// <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);
            }
        }
Пример #2
0
 public string GetText(SourceRange extent) {
     return Encoding.GetString(_bytes.Slice(extent));
 }
Пример #3
0
 /// <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);
     }
 }
Пример #4
0
 public static extern void clang_tokenize(IntPtr tu, SourceRange range, out IntPtr tokens, out uint numTokens);
Пример #5
0
 public static extern ClangString clang_getDiagnosticFixIt(
     IntPtr diag, uint fixit, out SourceRange replacementRange);
Пример #6
0
 public static extern SourceLocation clang_getRangeEnd(SourceRange range);
Пример #7
0
 public static extern void clang_tokenize(IntPtr tu, SourceRange range, out IntPtr tokens, out uint numTokens);
Пример #8
0
 public static extern ClangString clang_getDiagnosticFixIt(
     IntPtr diag, uint fixit, out SourceRange replacementRange);
Пример #9
0
 public static extern SourceLocation clang_getRangeEnd(SourceRange range);
Пример #10
0
 public static T[] Slice <T>(this IList <T> collection, SourceRange range)
 {
     return(Slice(collection, range.Start.Offset, range.End.Offset - range.Start.Offset));
 }
Пример #11
0
 public static string Substring(this string source, SourceRange range)
 {
     return(source.Substring(range.Start.Offset, range.End.Offset - range.Start.Offset));
 }
Пример #12
0
 public string GetText(SourceRange extent)
 {
     return(Encoding.GetString(_bytes.Slice(extent)));
 }