Browse Source

Simplified and tested the reading of line numbers.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/604/head
Dimitar Dobrev 10 years ago
parent
commit
1471e6f2fb
  1. 16
      src/CppParser/Parser.cpp
  2. 2
      src/CppParser/Parser.h
  3. 10
      src/Generator.Tests/AST/TestAST.cs
  4. 3
      tests/Native/AST.h

16
src/CppParser/Parser.cpp

@ -2403,14 +2403,6 @@ SourceLocationKind Parser::GetLocationKind(const clang::SourceLocation& Loc) @@ -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( @@ -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) @@ -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())
{

2
src/CppParser/Parser.h

@ -102,8 +102,6 @@ protected: @@ -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);

10
src/Generator.Tests/AST/TestAST.cs

@ -237,13 +237,13 @@ namespace CppSharp.Generator.Tests.AST @@ -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 @@ -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);
}
}
}

3
tests/Native/AST.h

@ -1,3 +1,5 @@ @@ -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 @@ -93,6 +95,7 @@ class HasAmbiguousFunctions
public:
void ambiguous();
void ambiguous() const;
Q_SIGNALS:
};
class Atomics

Loading…
Cancel
Save