Browse Source

Added a new property for the line number of the end of a declaration.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/443/head
Dimitar Dobrev 10 years ago
parent
commit
f0d237d9c2
  1. 6
      src/AST/Declaration.cs
  2. 3
      src/Core/Parser/ASTConverter.cs
  3. 6
      src/CppParser/AST.cpp
  4. 3
      src/CppParser/AST.h
  5. 18
      src/CppParser/Bindings/CLI/AST.cpp
  6. 8
      src/CppParser/Bindings/CLI/AST.h
  7. 750
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs
  8. 742
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs
  9. 750
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs
  10. 750
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs
  11. 53
      src/CppParser/Parser.cpp
  12. 1
      src/CppParser/Parser.h
  13. 4
      src/Generator.Tests/AST/TestAST.cs

6
src/AST/Declaration.cs

@ -55,7 +55,8 @@ namespace CppSharp.AST @@ -55,7 +55,8 @@ namespace CppSharp.AST
{
public SourceLocation Location;
public int LineNumber { get; set; }
public int LineNumberStart { get; set; }
public int LineNumberEnd { get; set; }
private DeclarationContext @namespace;
public DeclarationContext OriginalNamespace;
@ -342,7 +343,8 @@ namespace CppSharp.AST @@ -342,7 +343,8 @@ namespace CppSharp.AST
PreprocessedEntities = new List<PreprocessedEntity>(
declaration.PreprocessedEntities);
OriginalPtr = declaration.OriginalPtr;
LineNumber = declaration.LineNumber;
this.LineNumberStart = declaration.LineNumberStart;
this.LineNumberEnd = declaration.LineNumberEnd;
}
public override string ToString()

3
src/Core/Parser/ASTConverter.cs

@ -727,7 +727,8 @@ namespace CppSharp @@ -727,7 +727,8 @@ namespace CppSharp
_decl.Name = decl.Name;
_decl.Namespace = Visit(decl._Namespace) as AST.DeclarationContext;
_decl.Location = new SourceLocation(decl.Location.ID);
_decl.LineNumber = decl.LineNumber;
_decl.LineNumberStart = decl.LineNumberStart;
_decl.LineNumberEnd = decl.LineNumberEnd;
_decl.DebugText = decl.DebugText;
_decl.IsIncomplete = decl.IsIncomplete;
_decl.IsDependent = decl.IsDependent;

6
src/CppParser/AST.cpp

@ -147,7 +147,8 @@ Declaration::Declaration(DeclarationKind kind) @@ -147,7 +147,8 @@ Declaration::Declaration(DeclarationKind kind)
, Access(AccessSpecifier::Public)
, _Namespace(0)
, Location(0)
, LineNumber(0)
, LineNumberStart(0)
, LineNumberEnd(0)
, Comment(0)
, IsIncomplete(false)
, IsDependent(false)
@ -162,7 +163,8 @@ Declaration::Declaration(const Declaration& rhs) @@ -162,7 +163,8 @@ Declaration::Declaration(const Declaration& rhs)
, Access(rhs.Access)
, _Namespace(rhs._Namespace)
, Location(rhs.Location.ID)
, LineNumber(rhs.LineNumber)
, LineNumberStart(rhs.LineNumberStart)
, LineNumberEnd(rhs.LineNumberEnd)
, Name(rhs.Name)
, Comment(rhs.Comment)
, DebugText(rhs.DebugText)

3
src/CppParser/AST.h

@ -390,7 +390,8 @@ public: @@ -390,7 +390,8 @@ public:
AccessSpecifier Access;
DeclarationContext* _Namespace;
SourceLocation Location;
int LineNumber;
int LineNumberStart;
int LineNumberEnd;
STRING(Name)
RawComment* Comment;
STRING(DebugText)

18
src/CppParser/Bindings/CLI/AST.cpp

@ -1222,14 +1222,24 @@ void CppSharp::Parser::AST::Declaration::Location::set(CppSharp::Parser::SourceL @@ -1222,14 +1222,24 @@ void CppSharp::Parser::AST::Declaration::Location::set(CppSharp::Parser::SourceL
((::CppSharp::CppParser::AST::Declaration*)NativePtr)->Location = _marshal0;
}
int CppSharp::Parser::AST::Declaration::LineNumber::get()
int CppSharp::Parser::AST::Declaration::LineNumberStart::get()
{
return ((::CppSharp::CppParser::AST::Declaration*)NativePtr)->LineNumber;
return ((::CppSharp::CppParser::AST::Declaration*)NativePtr)->LineNumberStart;
}
void CppSharp::Parser::AST::Declaration::LineNumber::set(int value)
void CppSharp::Parser::AST::Declaration::LineNumberStart::set(int value)
{
((::CppSharp::CppParser::AST::Declaration*)NativePtr)->LineNumber = value;
((::CppSharp::CppParser::AST::Declaration*)NativePtr)->LineNumberStart = value;
}
int CppSharp::Parser::AST::Declaration::LineNumberEnd::get()
{
return ((::CppSharp::CppParser::AST::Declaration*)NativePtr)->LineNumberEnd;
}
void CppSharp::Parser::AST::Declaration::LineNumberEnd::set(int value)
{
((::CppSharp::CppParser::AST::Declaration*)NativePtr)->LineNumberEnd = value;
}
CppSharp::Parser::AST::RawComment^ CppSharp::Parser::AST::Declaration::Comment::get()

8
src/CppParser/Bindings/CLI/AST.h

@ -1029,7 +1029,13 @@ namespace CppSharp @@ -1029,7 +1029,13 @@ namespace CppSharp
void set(CppSharp::Parser::SourceLocation);
}
property int LineNumber
property int LineNumberStart
{
int get();
void set(int);
}
property int LineNumberEnd
{
int get();
void set(int);

750
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs

File diff suppressed because it is too large Load Diff

742
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs

File diff suppressed because it is too large Load Diff

750
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs

File diff suppressed because it is too large Load Diff

750
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs

File diff suppressed because it is too large Load Diff

53
src/CppParser/Parser.cpp

@ -2434,20 +2434,7 @@ Friend* Parser::WalkFriend(clang::FriendDecl *FD) @@ -2434,20 +2434,7 @@ Friend* Parser::WalkFriend(clang::FriendDecl *FD)
if (FriendDecl)
{
F->Declaration = WalkDeclarationDef(FriendDecl);
if (F->Declaration)
{
for (auto it = FriendDecl->redecls_begin(); it != FriendDecl->redecls_end(); it++)
{
if (it->getLocation() != FriendDecl->getLocation())
{
auto DecomposedLoc = C->getSourceManager().getDecomposedLoc(it->getLocation());
F->Declaration->LineNumber = C->getSourceManager().getLineNumber(
DecomposedLoc.first, DecomposedLoc.second);
break;
}
}
}
F->Declaration = GetDeclarationFromFriend(FriendDecl);
}
//auto TL = FD->getFriendType()->getTypeLoc();
@ -2762,8 +2749,11 @@ void Parser::HandleDeclaration(clang::Decl* D, Declaration* Decl) @@ -2762,8 +2749,11 @@ void Parser::HandleDeclaration(clang::Decl* D, Declaration* Decl)
Decl->OriginalPtr = (void*) D;
Decl->USR = GetDeclUSR(D);
Decl->Location = SourceLocation(D->getLocation().getRawEncoding());
auto DecomposedLoc = C->getSourceManager().getDecomposedLoc(D->getLocation());
Decl->LineNumber = C->getSourceManager().getLineNumber(DecomposedLoc.first, DecomposedLoc.second);
auto& SM = C->getSourceManager();
auto DecomposedLocStart = SM.getDecomposedLoc(D->getLocation());
Decl->LineNumberStart = SM.getLineNumber(DecomposedLocStart.first, DecomposedLocStart.second);
auto DecomposedLocEnd = SM.getDecomposedLoc(D->getLocEnd());
Decl->LineNumberEnd = SM.getLineNumber(DecomposedLocEnd.first, DecomposedLocEnd.second);
if (Decl->PreprocessedEntities.empty() && !D->isImplicit())
{
@ -3517,3 +3507,34 @@ ParserTargetInfo* Parser::GetTargetInfo() @@ -3517,3 +3507,34 @@ ParserTargetInfo* Parser::GetTargetInfo()
return parserTargetInfo;
}
Declaration* Parser::GetDeclarationFromFriend(clang::NamedDecl* FriendDecl)
{
Declaration* Decl = WalkDeclarationDef(FriendDecl);
if (!Decl) return nullptr;
int MinLineNumberStart = std::numeric_limits<int>::max();
int MinLineNumberEnd = std::numeric_limits<int>::max();
auto& SM = C->getSourceManager();
for (auto it = FriendDecl->redecls_begin(); it != FriendDecl->redecls_end(); it++)
{
if (it->getLocation() != FriendDecl->getLocation())
{
auto DecomposedLocStart = SM.getDecomposedLoc(it->getLocation());
int NewLineNumberStart = SM.getLineNumber(DecomposedLocStart.first, DecomposedLocStart.second);
auto DecomposedLocEnd = SM.getDecomposedLoc(it->getLocEnd());
int NewLineNumberEnd = SM.getLineNumber(DecomposedLocEnd.first, DecomposedLocEnd.second);
if (NewLineNumberStart < MinLineNumberStart)
{
MinLineNumberStart = NewLineNumberStart;
MinLineNumberEnd = NewLineNumberEnd;
}
}
}
if (MinLineNumberStart < std::numeric_limits<int>::max())
{
Decl->LineNumberStart = MinLineNumberStart;
Decl->LineNumberEnd = MinLineNumberEnd;
}
return Decl;
}

1
src/CppParser/Parser.h

@ -144,6 +144,7 @@ private: @@ -144,6 +144,7 @@ private:
llvm::object::basic_symbol_iterator Begin,
llvm::object::basic_symbol_iterator End,
CppSharp::CppParser::NativeLibrary*& NativeLib);
Declaration* GetDeclarationFromFriend(clang::NamedDecl* FriendDecl);
};
} }

4
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().LineNumber);
Assert.AreEqual(63, AstContext.FindClass("HiddenInNamespace").First().LineNumberStart);
}
[Test]
public void TestLineNumberOfFriend()
{
Assert.AreEqual(83, AstContext.FindFunction("operator+").First().LineNumber);
Assert.AreEqual(83, AstContext.FindFunction("operator+").First().LineNumberStart);
}
[Test]

Loading…
Cancel
Save