From 53bce57b197933d252affe5523c0fd3aab368f40 Mon Sep 17 00:00:00 2001 From: triton Date: Wed, 29 May 2013 19:20:06 +0100 Subject: [PATCH] Added parsing of access specifiers in methods. This lets us keep track of groups of methods in the order they were declared in the native class which is useful to bind some libraries, like Qt which uses non-standard constructs like Q_SIGNALS. Since we now also keep track of macro expansions in declarations this gives us the information needed to deal with those cases correctly. --- src/Bridge/Class.cs | 13 +++++++++++++ src/Bridge/Method.cs | 1 + src/Parser/Parser.cpp | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/Bridge/Class.cs b/src/Bridge/Class.cs index 42540a13..9a1161b7 100644 --- a/src/Bridge/Class.cs +++ b/src/Bridge/Class.cs @@ -12,6 +12,17 @@ namespace CppSharp Public } + // A C++ access specifier declaration. + public class AccessSpecifierDecl : Declaration + { + public AccessSpecifier Access; + + public override T Visit(IDeclVisitor visitor) + { + throw new NotImplementedException(); + } + } + // Represents a base class of a C++ class. public class BaseClassSpecifier { @@ -86,6 +97,7 @@ namespace CppSharp public List Fields; public List Properties; public List Methods; + public List Specifiers; // True if the record is a POD (Plain Old Data) type. public bool IsPOD; @@ -111,6 +123,7 @@ namespace CppSharp Fields = new List(); Properties = new List(); Methods = new List(); + Specifiers = new List(); IsAbstract = false; IsUnion = false; IsOpaque = false; diff --git a/src/Bridge/Method.cs b/src/Bridge/Method.cs index e3c85932..b9e582af 100644 --- a/src/Bridge/Method.cs +++ b/src/Bridge/Method.cs @@ -69,6 +69,7 @@ namespace CppSharp } public AccessSpecifier Access { get; set; } + public AccessSpecifierDecl AccessDecl { get; set; } public bool IsVirtual { get; set; } public bool IsStatic { get; set; } diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index bd20fc94..8af61136 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -419,6 +419,8 @@ CppSharp::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) RC->Layout->DataSize = (int)Layout->getDataSize().getQuantity(); } + CppSharp::AccessSpecifierDecl^ AccessDecl = nullptr; + for(auto it = Record->decls_begin(); it != Record->decls_end(); ++it) { auto D = *it; @@ -432,6 +434,7 @@ CppSharp::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) { auto MD = cast(D); auto Method = WalkMethodCXX(MD); + Method->AccessDecl = AccessDecl; RC->Methods->Add(Method); HandleComments(MD, Method); break; @@ -448,6 +451,22 @@ CppSharp::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) HandleComments(FD, Field); break; } + case Decl::AccessSpec: + { + AccessSpecDecl* AS = cast(D); + + AccessDecl = gcnew CppSharp::AccessSpecifierDecl(); + AccessDecl->Access = ConvertToAccess(AS->getAccess()); + AccessDecl->Namespace = RC; + + auto startLoc = GetDeclStartLocation(C.get(), AS); + auto range = SourceRange(startLoc, AS->getColonLoc()); + HandlePreprocessedEntities(AccessDecl, range, + CppSharp::MacroLocation::Unknown); + + RC->Specifiers->Add(AccessDecl); + break; + } case Decl::IndirectField: // FIXME: Handle indirect fields default: {