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