public static TokenGroup GetTokens(CXTranslationUnit tu, CXSourceRange range)
        {
            IntPtr tokens;
            uint count;
            clang.tokenize (tu, range, out tokens, out count);

            return new TokenGroup (tu, tokens, count);
        }
Exemple #2
0
        private unsafe void VisitMacroDefinitionRecord(MacroDefinitionRecord macroDefinitionRecord)
        {
            if (IsExcluded(macroDefinitionRecord))
            {
                return;
            }

            if (macroDefinitionRecord.IsFunctionLike)
            {
                AddDiagnostic(DiagnosticLevel.Warning, $"Function like macro definition records are not supported: '{macroDefinitionRecord.Name}'. Generated bindings may be incomplete.", macroDefinitionRecord);
                return;
            }

            var translationUnitHandle = macroDefinitionRecord.TranslationUnit.Handle;
            var tokens = translationUnitHandle.Tokenize(macroDefinitionRecord.Extent).ToArray();

            if ((tokens[0].Kind == CXTokenKind.CXToken_Identifier) && (tokens[0].GetSpelling(translationUnitHandle).CString == macroDefinitionRecord.Spelling))
            {
                if (tokens.Length == 1)
                {
                    // Nothing to do for simple macro definitions with no value
                    return;
                }

                var macroName = $"ClangSharpMacro_{macroDefinitionRecord.Spelling}";

                _fileContentsBuilder.Append('\n');
                _fileContentsBuilder.Append($"const auto {macroName} = ");

                var sourceRangeEnd   = tokens[tokens.Length - 1].GetExtent(translationUnitHandle).End;
                var sourceRangeStart = tokens[1].GetLocation(translationUnitHandle);

                var sourceRange = CXSourceRange.Create(sourceRangeStart, sourceRangeEnd);

                var macroValue = GetSourceRangeContents(translationUnitHandle, sourceRange);
                _fileContentsBuilder.Append(macroValue);

                _fileContentsBuilder.Append(';');
                _fileContentsBuilder.Append('\n');
            }
            else
            {
                AddDiagnostic(DiagnosticLevel.Error, $"Unsupported macro definition record: {macroDefinitionRecord.Name}. Generated bindings may be incomplete.", macroDefinitionRecord);
            }
        }
Exemple #3
0
 public static extern void tokenize(CXTranslationUnit @TU, CXSourceRange @Range, out IntPtr @Tokens, out uint @NumTokens);
Exemple #4
0
 public static extern CXString getDiagnosticFixIt(CXDiagnostic @Diagnostic, uint @FixIt, out CXSourceRange @ReplacementRange);
Exemple #5
0
 public static extern CXSourceLocation getRangeEnd(CXSourceRange @range);
Exemple #6
0
 public static extern CXSourceLocation getRangeStart(CXSourceRange @range);
Exemple #7
0
 public static extern int Range_isNull(CXSourceRange @range);
Exemple #8
0
 public static extern uint equalRanges(CXSourceRange @range1, CXSourceRange @range2);
Exemple #9
0
 public void Tokenize(CXSourceRange sourceRange, out CXToken[] tokens) => clang.tokenize(this, sourceRange, out tokens, out _);
Exemple #10
0
 public static extern void tokenize(CXTranslationUnit @TU, CXSourceRange @Range, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] out CXToken[] @Tokens, out uint @NumTokens);
Exemple #11
0
 public CXString GetFixIt(uint fixIt, out CXSourceRange replacementRange) => clang.getDiagnosticFixIt(this, fixIt, out replacementRange);