Browse Source

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.
pull/1/head
triton 13 years ago
parent
commit
53bce57b19
  1. 13
      src/Bridge/Class.cs
  2. 1
      src/Bridge/Method.cs
  3. 19
      src/Parser/Parser.cpp

13
src/Bridge/Class.cs

@ -12,6 +12,17 @@ namespace CppSharp @@ -12,6 +12,17 @@ namespace CppSharp
Public
}
// A C++ access specifier declaration.
public class AccessSpecifierDecl : Declaration
{
public AccessSpecifier Access;
public override T Visit<T>(IDeclVisitor<T> visitor)
{
throw new NotImplementedException();
}
}
// Represents a base class of a C++ class.
public class BaseClassSpecifier
{
@ -86,6 +97,7 @@ namespace CppSharp @@ -86,6 +97,7 @@ namespace CppSharp
public List<Field> Fields;
public List<Property> Properties;
public List<Method> Methods;
public List<AccessSpecifierDecl> Specifiers;
// True if the record is a POD (Plain Old Data) type.
public bool IsPOD;
@ -111,6 +123,7 @@ namespace CppSharp @@ -111,6 +123,7 @@ namespace CppSharp
Fields = new List<Field>();
Properties = new List<Property>();
Methods = new List<Method>();
Specifiers = new List<AccessSpecifierDecl>();
IsAbstract = false;
IsUnion = false;
IsOpaque = false;

1
src/Bridge/Method.cs

@ -69,6 +69,7 @@ namespace CppSharp @@ -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; }

19
src/Parser/Parser.cpp

@ -419,6 +419,8 @@ CppSharp::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) @@ -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) @@ -432,6 +434,7 @@ CppSharp::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
{
auto MD = cast<CXXMethodDecl>(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) @@ -448,6 +451,22 @@ CppSharp::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
HandleComments(FD, Field);
break;
}
case Decl::AccessSpec:
{
AccessSpecDecl* AS = cast<AccessSpecDecl>(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:
{

Loading…
Cancel
Save