Skip to content

Commit 1471e6f

Browse files
committed
Simplified and tested the reading of line numbers.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 05d7088 commit 1471e6f

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

src/CppParser/Parser.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,14 +2403,6 @@ SourceLocationKind Parser::GetLocationKind(const clang::SourceLocation& Loc)
24032403
return SourceLocationKind::System;
24042404
}
24052405

2406-
void Parser::GetLineNumbersFromLocation(const clang::SourceLocation& StartLoc,
2407-
const clang::SourceLocation& EndLoc, int* LineNumberStart, int* LineNumberEnd)
2408-
{
2409-
auto& SM = C->getSourceManager();
2410-
*LineNumberStart = StartLoc.isInvalid() ? -1 : SM.getExpansionLineNumber(StartLoc);
2411-
*LineNumberEnd = EndLoc.isInvalid() ? -1 : SM.getExpansionLineNumber(EndLoc);
2412-
}
2413-
24142406
bool Parser::IsValidDeclaration(const clang::SourceLocation& Loc)
24152407
{
24162408
auto Kind = GetLocationKind(Loc);
@@ -2583,8 +2575,8 @@ PreprocessedEntity* Parser::WalkPreprocessedEntity(
25832575
break;
25842576

25852577
auto Definition = new MacroDefinition();
2586-
GetLineNumbersFromLocation(MD->getLocation(), MD->getLocation(),
2587-
&Definition->LineNumberStart, &Definition->LineNumberEnd);
2578+
Definition->LineNumberStart = SM.getExpansionLineNumber(MD->getLocation());
2579+
Definition->LineNumberEnd = SM.getExpansionLineNumber(MD->getLocation());
25882580
Entity = Definition;
25892581

25902582
Definition->Name = II->getName().trim();
@@ -2769,8 +2761,8 @@ void Parser::HandleDeclaration(clang::Decl* D, Declaration* Decl)
27692761
Decl->OriginalPtr = (void*) D;
27702762
Decl->USR = GetDeclUSR(D);
27712763
Decl->Location = SourceLocation(D->getLocation().getRawEncoding());
2772-
GetLineNumbersFromLocation(D->getLocStart(), D->getLocEnd(),
2773-
&Decl->LineNumberStart, &Decl->LineNumberEnd);
2764+
Decl->LineNumberStart = C->getSourceManager().getExpansionLineNumber(D->getLocStart());
2765+
Decl->LineNumberEnd = C->getSourceManager().getExpansionLineNumber(D->getLocEnd());
27742766

27752767
if (Decl->PreprocessedEntities.empty() && !D->isImplicit())
27762768
{

src/CppParser/Parser.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ class Parser
102102

103103
// Clang helpers
104104
SourceLocationKind GetLocationKind(const clang::SourceLocation& Loc);
105-
void GetLineNumbersFromLocation(const clang::SourceLocation& StartLoc, const clang::SourceLocation& EndLoc,
106-
int* LineNumberStart, int* LineNumberEnd);
107105
bool IsValidDeclaration(const clang::SourceLocation& Loc);
108106
std::string GetDeclMangledName(clang::Decl* D);
109107
std::string GetTypeName(const clang::Type* Type);

src/Generator.Tests/AST/TestAST.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ public void TestFindClassInNamespace()
237237
[Test]
238238
public void TestLineNumber()
239239
{
240-
Assert.AreEqual(63, AstContext.FindClass("HiddenInNamespace").First().LineNumberStart);
240+
Assert.AreEqual(65, AstContext.FindClass("HiddenInNamespace").First().LineNumberStart);
241241
}
242242

243243
[Test]
244244
public void TestLineNumberOfFriend()
245245
{
246-
Assert.AreEqual(86, AstContext.FindFunction("operator+").First().LineNumberStart);
246+
Assert.AreEqual(88, AstContext.FindFunction("operator+").First().LineNumberStart);
247247
}
248248

249249
[Test]
@@ -275,5 +275,11 @@ public void TestAtomics()
275275
.Find(f => f.Name == "AtomicInt").Type as BuiltinType;
276276
Assert.IsTrue(type != null && type.IsPrimitiveType(PrimitiveType.Int));
277277
}
278+
279+
[Test]
280+
public void TestMacroLineNumber()
281+
{
282+
Assert.AreEqual(98, AstContext.FindClass("HasAmbiguousFunctions").First().Specifiers.Last().LineNumberStart);
283+
}
278284
}
279285
}

tests/Native/AST.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define Q_SIGNALS protected
2+
13
// Tests assignment of AST.Parameter properties
24
void TestParameterProperties(bool a, const short& b, int* c = nullptr) {};
35

@@ -93,6 +95,7 @@ class HasAmbiguousFunctions
9395
public:
9496
void ambiguous();
9597
void ambiguous() const;
98+
Q_SIGNALS:
9699
};
97100

98101
class Atomics
@@ -102,4 +105,4 @@ class Atomics
102105
_Atomic(int) AtomicInt;
103106
# endif
104107
#endif
105-
};
108+
};

0 commit comments

Comments
 (0)