diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index 2235c9df..9ad6cd2a 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -2403,14 +2403,6 @@ SourceLocationKind Parser::GetLocationKind(const clang::SourceLocation& Loc) return SourceLocationKind::System; } -void Parser::GetLineNumbersFromLocation(const clang::SourceLocation& StartLoc, - const clang::SourceLocation& EndLoc, int* LineNumberStart, int* LineNumberEnd) -{ - auto& SM = C->getSourceManager(); - *LineNumberStart = StartLoc.isInvalid() ? -1 : SM.getExpansionLineNumber(StartLoc); - *LineNumberEnd = EndLoc.isInvalid() ? -1 : SM.getExpansionLineNumber(EndLoc); -} - bool Parser::IsValidDeclaration(const clang::SourceLocation& Loc) { auto Kind = GetLocationKind(Loc); @@ -2583,8 +2575,8 @@ PreprocessedEntity* Parser::WalkPreprocessedEntity( break; auto Definition = new MacroDefinition(); - GetLineNumbersFromLocation(MD->getLocation(), MD->getLocation(), - &Definition->LineNumberStart, &Definition->LineNumberEnd); + Definition->LineNumberStart = SM.getExpansionLineNumber(MD->getLocation()); + Definition->LineNumberEnd = SM.getExpansionLineNumber(MD->getLocation()); Entity = Definition; Definition->Name = II->getName().trim(); @@ -2769,8 +2761,8 @@ void Parser::HandleDeclaration(clang::Decl* D, Declaration* Decl) Decl->OriginalPtr = (void*) D; Decl->USR = GetDeclUSR(D); Decl->Location = SourceLocation(D->getLocation().getRawEncoding()); - GetLineNumbersFromLocation(D->getLocStart(), D->getLocEnd(), - &Decl->LineNumberStart, &Decl->LineNumberEnd); + Decl->LineNumberStart = C->getSourceManager().getExpansionLineNumber(D->getLocStart()); + Decl->LineNumberEnd = C->getSourceManager().getExpansionLineNumber(D->getLocEnd()); if (Decl->PreprocessedEntities.empty() && !D->isImplicit()) { diff --git a/src/CppParser/Parser.h b/src/CppParser/Parser.h index 550d22c3..ae0dfa70 100644 --- a/src/CppParser/Parser.h +++ b/src/CppParser/Parser.h @@ -102,8 +102,6 @@ protected: // Clang helpers SourceLocationKind GetLocationKind(const clang::SourceLocation& Loc); - void GetLineNumbersFromLocation(const clang::SourceLocation& StartLoc, const clang::SourceLocation& EndLoc, - int* LineNumberStart, int* LineNumberEnd); bool IsValidDeclaration(const clang::SourceLocation& Loc); std::string GetDeclMangledName(clang::Decl* D); std::string GetTypeName(const clang::Type* Type); diff --git a/src/Generator.Tests/AST/TestAST.cs b/src/Generator.Tests/AST/TestAST.cs index 9ed28504..830dc863 100644 --- a/src/Generator.Tests/AST/TestAST.cs +++ b/src/Generator.Tests/AST/TestAST.cs @@ -237,13 +237,13 @@ namespace CppSharp.Generator.Tests.AST [Test] public void TestLineNumber() { - Assert.AreEqual(63, AstContext.FindClass("HiddenInNamespace").First().LineNumberStart); + Assert.AreEqual(65, AstContext.FindClass("HiddenInNamespace").First().LineNumberStart); } [Test] public void TestLineNumberOfFriend() { - Assert.AreEqual(86, AstContext.FindFunction("operator+").First().LineNumberStart); + Assert.AreEqual(88, AstContext.FindFunction("operator+").First().LineNumberStart); } [Test] @@ -275,5 +275,11 @@ namespace CppSharp.Generator.Tests.AST .Find(f => f.Name == "AtomicInt").Type as BuiltinType; Assert.IsTrue(type != null && type.IsPrimitiveType(PrimitiveType.Int)); } + + [Test] + public void TestMacroLineNumber() + { + Assert.AreEqual(98, AstContext.FindClass("HasAmbiguousFunctions").First().Specifiers.Last().LineNumberStart); + } } } diff --git a/tests/Native/AST.h b/tests/Native/AST.h index 089fae54..2562a076 100644 --- a/tests/Native/AST.h +++ b/tests/Native/AST.h @@ -1,3 +1,5 @@ +#define Q_SIGNALS protected + // Tests assignment of AST.Parameter properties void TestParameterProperties(bool a, const short& b, int* c = nullptr) {}; @@ -93,6 +95,7 @@ class HasAmbiguousFunctions public: void ambiguous(); void ambiguous() const; +Q_SIGNALS: }; class Atomics @@ -102,4 +105,4 @@ class Atomics _Atomic(int) AtomicInt; # endif #endif -}; \ No newline at end of file +};