Exemplo n.º 1
0
        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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
 public static extern void tokenize(CXTranslationUnit @TU, CXSourceRange @Range, out IntPtr @Tokens, out uint @NumTokens);
Exemplo n.º 4
0
 public static extern CXString getDiagnosticFixIt(CXDiagnostic @Diagnostic, uint @FixIt, out CXSourceRange @ReplacementRange);
Exemplo n.º 5
0
 public static extern CXSourceLocation getRangeEnd(CXSourceRange @range);
Exemplo n.º 6
0
 public static extern CXSourceLocation getRangeStart(CXSourceRange @range);
Exemplo n.º 7
0
 public static extern int Range_isNull(CXSourceRange @range);
Exemplo n.º 8
0
 public static extern uint equalRanges(CXSourceRange @range1, CXSourceRange @range2);
Exemplo n.º 9
0
 public void Tokenize(CXSourceRange sourceRange, out CXToken[] tokens) => clang.tokenize(this, sourceRange, out tokens, out _);
Exemplo n.º 10
0
 public static extern void tokenize(CXTranslationUnit @TU, CXSourceRange @Range, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] out CXToken[] @Tokens, out uint @NumTokens);
Exemplo n.º 11
0
 public CXString GetFixIt(uint fixIt, out CXSourceRange replacementRange) => clang.getDiagnosticFixIt(this, fixIt, out replacementRange);