From 2a136133736149fe154c6f7c40230af5869aee16 Mon Sep 17 00:00:00 2001 From: Balazs Somogyi Date: Mon, 4 Sep 2023 17:44:03 +0200 Subject: [PATCH] Fix attribute parsing --- src/CppAst/CppAst.csproj | 4 ++-- src/CppAst/CppModelBuilder.cs | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/CppAst/CppAst.csproj b/src/CppAst/CppAst.csproj index ad89dd5..f8340d1 100644 --- a/src/CppAst/CppAst.csproj +++ b/src/CppAst/CppAst.csproj @@ -3,7 +3,7 @@ netstandard2.0 0.8.0 alpha - 007 + 011 CppAst.cgnx CppAst is a .NET library providing a C/C++ parser for header files with access to the full AST, comments and macros Alexandre Mutel @@ -25,7 +25,7 @@ true true snupkg - 0.8.0-alpha-007 + 0.8.0-alpha-011 diff --git a/src/CppAst/CppModelBuilder.cs b/src/CppAst/CppModelBuilder.cs index 61b6444..3e56844 100644 --- a/src/CppAst/CppModelBuilder.cs +++ b/src/CppAst/CppModelBuilder.cs @@ -2108,7 +2108,7 @@ private uint IncOffset(int inc, uint offset) return offset; } - private Tuple GetExtent(CXTranslationUnit tu, CXFile file, CXCursor cur) + private Tuple GetExtent(CXTranslationUnit tu, CXCursor cur) { var cursorExtend = cur.Extent; var begin = cursorExtend.Start; @@ -2155,19 +2155,17 @@ bool HasInlineTypeDefinition(CXCursor varDecl) CXSourceLocation GetNextLocation(CXSourceLocation loc, int inc = 1) { CXSourceLocation value; - uint originalOffset, u, z; - CXFile f; - loc.GetSpellingLocation(out f, out u, out z, out originalOffset); - var offset = IncOffset(inc, z); - var shouldUseLine = (z != 0 && (offset != 0 || offset != uint.MaxValue)); + loc.GetSpellingLocation(out var file, out var line, out var column, out var originalOffset); + var signedOffset = (int)column + inc; + var shouldUseLine = (column != 0 && signedOffset > 0); if (shouldUseLine) { - value = tu.GetLocation(f, u, offset); + value = tu.GetLocation(file, line, (uint)signedOffset); } else { - offset = IncOffset(inc, originalOffset); - value = tu.GetLocationForOffset(f, offset); + var offset = IncOffset(inc, originalOffset); + value = tu.GetLocationForOffset(file, offset); } return value; @@ -2385,7 +2383,7 @@ with custom or even compiler attributes in your parsing. Thus we have This code supports stepping back when its valid to parse attributes, it doesn't currently support all cases but it supports most valid cases. */ - var range = GetExtent(_tu, cursor.IncludedFile, cursor); + var range = GetExtent(_tu, cursor); var beg = range.Item1.Start; var end = range.Item1.End;