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