Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
 public string GetText(SourceRange extent) {
     return Encoding.GetString(_bytes.Slice(extent));
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 4
0
 public static extern void clang_tokenize(IntPtr tu, SourceRange range, out IntPtr tokens, out uint numTokens);
Ejemplo n.º 5
0
 public static extern ClangString clang_getDiagnosticFixIt(
     IntPtr diag, uint fixit, out SourceRange replacementRange);
Ejemplo n.º 6
0
 public static extern SourceLocation clang_getRangeEnd(SourceRange range);
Ejemplo n.º 7
0
 public static extern void clang_tokenize(IntPtr tu, SourceRange range, out IntPtr tokens, out uint numTokens);
Ejemplo n.º 8
0
 public static extern ClangString clang_getDiagnosticFixIt(
     IntPtr diag, uint fixit, out SourceRange replacementRange);
Ejemplo n.º 9
0
 public static extern SourceLocation clang_getRangeEnd(SourceRange range);
Ejemplo n.º 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));
 }
Ejemplo n.º 11
0
 public static string Substring(this string source, SourceRange range)
 {
     return(source.Substring(range.Start.Offset, range.End.Offset - range.Start.Offset));
 }
Ejemplo n.º 12
0
 public string GetText(SourceRange extent)
 {
     return(Encoding.GetString(_bytes.Slice(extent)));
 }