Browse Source

Update namespace formatting to inner

pull/1912/head
duckdoom5 1 year ago
parent
commit
e03e153176
  1. 2
      .clang-format
  2. 32
      src/CppParser/ASTNameMangler.cpp
  3. 48
      src/CppParser/ASTNameMangler.h
  4. 50
      src/CppParser/CXXABI.h
  5. 26
      src/CppParser/Parser.h
  6. 4
      tests/dotnet/CSharp/AnotherUnit.cpp
  7. 4
      tests/dotnet/CSharp/AnotherUnit.h
  8. 64
      tests/dotnet/CSharp/CSharp.h
  9. 28
      tests/dotnet/CSharp/CSharpTemplates.h
  10. 10
      tests/dotnet/Common/AnotherUnit.h
  11. 168
      tests/dotnet/Common/Common.h
  12. 18
      tests/dotnet/NamespacesBase/NamespacesBase.h
  13. 24
      tests/dotnet/NamespacesDerived/NamespacesDerived.h
  14. 46
      tests/dotnet/Native/AST.h

2
.clang-format

@ -56,7 +56,7 @@ KeepEmptyLinesAtTheStartOfBlocks : true
MaxEmptyLinesToKeep : 2 MaxEmptyLinesToKeep : 2
EmptyLineAfterAccessModifier : Leave EmptyLineAfterAccessModifier : Leave
EmptyLineBeforeAccessModifier : LogicalBlock EmptyLineBeforeAccessModifier : LogicalBlock
NamespaceIndentation : All NamespaceIndentation : Inner
PointerAlignment : Left PointerAlignment : Left
SpacesBeforeTrailingComments : 1 SpacesBeforeTrailingComments : 1
SpacesInAngles : Never SpacesInAngles : Never

32
src/CppParser/ASTNameMangler.cpp

@ -17,24 +17,24 @@ using namespace clang;
using namespace CppSharp::CppParser; using namespace CppSharp::CppParser;
namespace { namespace {
enum ObjCKind enum ObjCKind
{ {
ObjCClass, ObjCClass,
ObjCMetaclass, ObjCMetaclass,
}; };
StringRef getClassSymbolPrefix(ObjCKind Kind, const ASTContext& Context) StringRef getClassSymbolPrefix(ObjCKind Kind, const ASTContext& Context)
{ {
if (Context.getLangOpts().ObjCRuntime.isGNUFamily()) if (Context.getLangOpts().ObjCRuntime.isGNUFamily())
return Kind == ObjCMetaclass ? "_OBJC_METACLASS_" : "_OBJC_CLASS_"; return Kind == ObjCMetaclass ? "_OBJC_METACLASS_" : "_OBJC_CLASS_";
return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_"; return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_";
} }
void WriteObjCClassName(const ObjCInterfaceDecl* D, raw_ostream& OS) void WriteObjCClassName(const ObjCInterfaceDecl* D, raw_ostream& OS)
{ {
OS << getClassSymbolPrefix(ObjCClass, D->getASTContext()); OS << getClassSymbolPrefix(ObjCClass, D->getASTContext());
OS << D->getObjCRuntimeNameAsString(); OS << D->getObjCRuntimeNameAsString();
} }
} // namespace } // namespace
ASTNameMangler::ASTNameMangler(ASTContext& Ctx) ASTNameMangler::ASTNameMangler(ASTContext& Ctx)

48
src/CppParser/ASTNameMangler.h

@ -13,36 +13,36 @@
#include <string> #include <string>
namespace clang { namespace clang {
class ASTContext; class ASTContext;
class MangleContext; class MangleContext;
struct ThunkInfo; struct ThunkInfo;
} // namespace clang } // namespace clang
namespace llvm { namespace llvm {
class raw_ostream; class raw_ostream;
} }
namespace CppSharp::CppParser { namespace CppSharp::CppParser {
/// <summary> /// <summary>
/// Helper class for getting the mangled name of a declaration /// Helper class for getting the mangled name of a declaration
/// </summary> /// </summary>
/// <remarks>Source adapted from https://clang.llvm.org/doxygen/Mangle_8cpp_source.html#l00394</remarks> /// <remarks>Source adapted from https://clang.llvm.org/doxygen/Mangle_8cpp_source.html#l00394</remarks>
class ASTNameMangler class ASTNameMangler
{ {
public: public:
explicit ASTNameMangler(clang::ASTContext& Ctx); explicit ASTNameMangler(clang::ASTContext& Ctx);
std::string GetName(const clang::Decl* D) const; std::string GetName(const clang::Decl* D) const;
bool WriteName(const clang::Decl* D, llvm::raw_ostream& OS) const; bool WriteName(const clang::Decl* D, llvm::raw_ostream& OS) const;
private: private:
std::string GetMangledStructor(const clang::NamedDecl* ND, unsigned StructorType) const; std::string GetMangledStructor(const clang::NamedDecl* ND, unsigned StructorType) const;
std::string GetMangledThunk(const clang::CXXMethodDecl* MD, const clang::ThunkInfo& T, bool ElideOverrideInfo) const; std::string GetMangledThunk(const clang::CXXMethodDecl* MD, const clang::ThunkInfo& T, bool ElideOverrideInfo) const;
bool WriteFuncOrVarName(const clang::NamedDecl* D, llvm::raw_ostream& OS) const; bool WriteFuncOrVarName(const clang::NamedDecl* D, llvm::raw_ostream& OS) const;
llvm::DataLayout DL; llvm::DataLayout DL;
std::unique_ptr<clang::MangleContext> MC; std::unique_ptr<clang::MangleContext> MC;
}; };
} // namespace CppSharp::CppParser } // namespace CppSharp::CppParser

50
src/CppParser/CXXABI.h

@ -17,31 +17,31 @@
namespace clang { namespace clang {
class ASTContext; class ASTContext;
class MemberPointerType; class MemberPointerType;
/// Implements C++ ABI-specific semantic analysis functions. /// Implements C++ ABI-specific semantic analysis functions.
class CXXABI class CXXABI
{ {
public: public:
virtual ~CXXABI(); virtual ~CXXABI();
/// Returns the size of a member pointer in multiples of the target /// Returns the size of a member pointer in multiples of the target
/// pointer size. /// pointer size.
virtual unsigned getMemberPointerSize(const MemberPointerType* MPT) const = 0; virtual unsigned getMemberPointerSize(const MemberPointerType* MPT) const = 0;
/// Returns the default calling convention for C++ methods. /// Returns the default calling convention for C++ methods.
virtual CallingConv getDefaultMethodCallConv() const = 0; virtual CallingConv getDefaultMethodCallConv() const = 0;
// Returns whether the given class is nearly empty, with just virtual pointers // Returns whether the given class is nearly empty, with just virtual pointers
// and no data except possibly virtual bases. // and no data except possibly virtual bases.
virtual bool isNearlyEmpty(const CXXRecordDecl* RD) const = 0; virtual bool isNearlyEmpty(const CXXRecordDecl* RD) const = 0;
}; };
/// Creates an instance of a C++ ABI class. /// Creates an instance of a C++ ABI class.
CXXABI* CreateARMCXXABI(ASTContext& Ctx); CXXABI* CreateARMCXXABI(ASTContext& Ctx);
CXXABI* CreateItaniumCXXABI(ASTContext& Ctx); CXXABI* CreateItaniumCXXABI(ASTContext& Ctx);
CXXABI* CreateMicrosoftCXXABI(ASTContext& Ctx); CXXABI* CreateMicrosoftCXXABI(ASTContext& Ctx);
} // namespace clang } // namespace clang
#endif #endif

26
src/CppParser/Parser.h

@ -29,19 +29,19 @@
#include <unordered_set> #include <unordered_set>
namespace clang { namespace clang {
namespace CodeGen { namespace CodeGen {
class CodeGenTypes; class CodeGenTypes;
} }
struct ASTTemplateArgumentListInfo; struct ASTTemplateArgumentListInfo;
class FunctionTemplateSpecialization; class FunctionTemplateSpecialization;
class FunctionTemplateSpecializationInfo; class FunctionTemplateSpecializationInfo;
class PreprocessingRecord; class PreprocessingRecord;
class PreprocessedEntity; class PreprocessedEntity;
class RawComment; class RawComment;
class TemplateSpecializationTypeLoc; class TemplateSpecializationTypeLoc;
class TemplateArgumentList; class TemplateArgumentList;
class VTableLayout; class VTableLayout;
class VTableComponent; class VTableComponent;
} // namespace clang } // namespace clang
#define Debug printf #define Debug printf

4
tests/dotnet/CSharp/AnotherUnit.cpp

@ -43,6 +43,6 @@ MultipleInheritance::~MultipleInheritance()
} }
namespace HasFreeConstant { namespace HasFreeConstant {
extern const int DLL_API FREE_CONSTANT_IN_NAMESPACE = 5; extern const int DLL_API FREE_CONSTANT_IN_NAMESPACE = 5;
extern const std::string DLL_API STD_STRING_CONSTANT = "test"; extern const std::string DLL_API STD_STRING_CONSTANT = "test";
} // namespace HasFreeConstant } // namespace HasFreeConstant

4
tests/dotnet/CSharp/AnotherUnit.h

@ -54,6 +54,6 @@ public:
}; };
namespace HasFreeConstant { namespace HasFreeConstant {
extern const int DLL_API FREE_CONSTANT_IN_NAMESPACE; extern const int DLL_API FREE_CONSTANT_IN_NAMESPACE;
extern const std::string DLL_API STD_STRING_CONSTANT; extern const std::string DLL_API STD_STRING_CONSTANT;
} // namespace HasFreeConstant } // namespace HasFreeConstant

64
tests/dotnet/CSharp/CSharp.h

@ -355,11 +355,11 @@ class TestObjectMapWithClassDerivedFromStruct : public QGenericArgument
#define DEFAULT_INT (2 * 1000UL + 500UL) #define DEFAULT_INT (2 * 1000UL + 500UL)
namespace Qt { namespace Qt {
enum GlobalColor enum GlobalColor
{ {
black, black,
white, white,
}; };
} // namespace Qt } // namespace Qt
class DLL_API QColor class DLL_API QColor
@ -392,11 +392,11 @@ public:
}; };
namespace lowerCaseNameSpace { namespace lowerCaseNameSpace {
enum class Enum enum class Enum
{ {
Item1, Item1,
Item2 Item2
}; };
} // namespace lowerCaseNameSpace } // namespace lowerCaseNameSpace
class DLL_API DefaultZeroMappedToEnum class DLL_API DefaultZeroMappedToEnum
@ -1012,15 +1012,15 @@ class DLL_API ClassWithVirtualBase : public virtual Foo
}; };
namespace NamespaceA { namespace NamespaceA {
CS_VALUE_TYPE class DLL_API A{}; CS_VALUE_TYPE class DLL_API A{};
} }
namespace NamespaceB { namespace NamespaceB {
class DLL_API B class DLL_API B
{ {
public: public:
void Function(CS_OUT NamespaceA::A& a); void Function(CS_OUT NamespaceA::A& a);
}; };
} // namespace NamespaceB } // namespace NamespaceB
class DLL_API HasPrivateVirtualProperty class DLL_API HasPrivateVirtualProperty
@ -1069,11 +1069,11 @@ public:
// https://github.com/mono/CppSharp/issues/1283 // https://github.com/mono/CppSharp/issues/1283
namespace NamespaceWithVirtualPropertyClass { namespace NamespaceWithVirtualPropertyClass {
class DLL_API HasOverriddenPropertyInNamespacedClass class DLL_API HasOverriddenPropertyInNamespacedClass
{ {
public: public:
virtual int property() = 0; virtual int property() = 0;
}; };
} // namespace NamespaceWithVirtualPropertyClass } // namespace NamespaceWithVirtualPropertyClass
class DLL_API TestOverrideOfPropertyInNamespacedClass : public NamespaceWithVirtualPropertyClass::HasOverriddenPropertyInNamespacedClass class DLL_API TestOverrideOfPropertyInNamespacedClass : public NamespaceWithVirtualPropertyClass::HasOverriddenPropertyInNamespacedClass
@ -1429,7 +1429,7 @@ public:
inline namespace InlineNamespace { inline namespace InlineNamespace {
DLL_API void FunctionInsideInlineNamespace(); DLL_API void FunctionInsideInlineNamespace();
} }
class DLL_API TestArrays class DLL_API TestArrays
@ -1526,18 +1526,18 @@ class DLL_API TestAnonymousMemberNameCollision : public ClassUsingUnion
}; };
namespace CXXRecordDeclWithoutDefinition { namespace CXXRecordDeclWithoutDefinition {
template <typename... T> template <typename... T>
struct list; struct list;
template <typename T> template <typename T>
struct it; struct it;
template <> template <>
struct it<list<>> struct it<list<>>
{}; {};
template <> template <>
struct it<list<> const> struct it<list<> const>
{}; {};
} // namespace CXXRecordDeclWithoutDefinition } // namespace CXXRecordDeclWithoutDefinition
template <int... n> template <int... n>

28
tests/dotnet/CSharp/CSharpTemplates.h

@ -987,20 +987,20 @@ inline void FunctionTemplateInstantiation()
// KEEP ORDER OTHERWISE TEST WONT WORK // KEEP ORDER OTHERWISE TEST WONT WORK
namespace IncompleteClassTemplatesTests { namespace IncompleteClassTemplatesTests {
template <size_t Size> template <size_t Size>
struct StructSizeT struct StructSizeT
{}; {};
template <typename T> template <typename T>
struct StructT struct StructT
{ {
template <typename U> template <typename U>
struct Inc struct Inc
{}; {};
}; };
struct Instantiation struct Instantiation
{ {
StructT<StructSizeT<4000>> st; StructT<StructSizeT<4000>> st;
}; };
} // namespace IncompleteClassTemplatesTests } // namespace IncompleteClassTemplatesTests

10
tests/dotnet/Common/AnotherUnit.h

@ -5,13 +5,13 @@ typedef void (*DelegateInAnotherUnit)();
// Tests automatic generation of anonymous delegates in different translation units // Tests automatic generation of anonymous delegates in different translation units
namespace DelegateNamespace { namespace DelegateNamespace {
namespace Nested { namespace Nested {
void DLL_API f3(void (*)()); void DLL_API f3(void (*)());
} }
void DLL_API f4(void (*)()); void DLL_API f4(void (*)());
} // namespace DelegateNamespace } // namespace DelegateNamespace
namespace AnotherUnit { namespace AnotherUnit {
void DLL_API f(); void DLL_API f();
} }

168
tests/dotnet/Common/Common.h

@ -381,11 +381,11 @@ struct DLL_API TestDelegates
}; };
namespace DelegateNamespace { namespace DelegateNamespace {
namespace Nested { namespace Nested {
void DLL_API f1(void (*)()); void DLL_API f1(void (*)());
} }
void DLL_API f2(void (*)()); void DLL_API f2(void (*)());
} // namespace DelegateNamespace } // namespace DelegateNamespace
// Tests memory leaks in constructors // Tests memory leaks in constructors
@ -480,35 +480,35 @@ class DLL_API SomeClassExtendingTheStruct : public SomeStruct
}; };
namespace SomeNamespace { namespace SomeNamespace {
class DLL_API NamespacedAbstractClass class DLL_API NamespacedAbstractClass
{ {
public: public:
virtual void AbstractMethod() = 0; virtual void AbstractMethod() = 0;
}; };
class DLL_API NamespacedAbstractImpl class DLL_API NamespacedAbstractImpl
{ {
public: public:
virtual void AbstractMethod(); virtual void AbstractMethod();
}; };
class Inlines class Inlines
{ {
public: public:
constexpr Inlines(float param, const char* name) {} constexpr Inlines(float param, const char* name) {}
inline operator NamespacedAbstractImpl() const { return NamespacedAbstractImpl(); } inline operator NamespacedAbstractImpl() const { return NamespacedAbstractImpl(); }
protected: protected:
void protectedInlined() {} void protectedInlined() {}
}; };
constexpr Inlines constWithParams(5.f, "test"); constexpr Inlines constWithParams(5.f, "test");
class AbstractInlines class AbstractInlines
{ {
public: public:
virtual void hasVariadicArgs(int regular, ...) = 0; virtual void hasVariadicArgs(int regular, ...) = 0;
}; };
} // namespace SomeNamespace } // namespace SomeNamespace
// Test operator overloads // Test operator overloads
@ -1004,64 +1004,64 @@ public:
}; };
namespace boost { namespace boost {
template <class T> template <class T>
struct is_member_pointer_cv struct is_member_pointer_cv
{ {
static const bool value = false; static const bool value = false;
}; };
template <class T, class U> template <class T, class U>
struct is_member_pointer_cv<T U::*> struct is_member_pointer_cv<T U::*>
{ {
static const bool value = true; static const bool value = true;
}; };
// all of this below tests corner cases with type locations
template <class T>
struct make_tuple_traits
{
typedef T type;
// commented away, see below (JJ)
// typedef typename IF<
// boost::is_function<T>::value,
// T&,
// T>::RET type;
};
namespace detail { // all of this below tests corner cases with type locations
struct swallow_assign; template <class T>
typedef void (detail::swallow_assign::*ignore_t)(); struct make_tuple_traits
struct swallow_assign {
{ typedef T type;
swallow_assign(ignore_t (*)(ignore_t));
template <typename T>
swallow_assign const& operator=(const T&) const;
};
swallow_assign::swallow_assign(ignore_t (*)(ignore_t)) // commented away, see below (JJ)
{ // typedef typename IF<
} // boost::is_function<T>::value,
// T&,
// T>::RET type;
};
namespace detail {
struct swallow_assign;
typedef void (detail::swallow_assign::*ignore_t)();
struct swallow_assign
{
swallow_assign(ignore_t (*)(ignore_t));
template <typename T> template <typename T>
swallow_assign const& swallow_assign::operator=(const T&) const swallow_assign const& operator=(const T&) const;
{ };
return *this;
}
} // namespace detail
template <> swallow_assign::swallow_assign(ignore_t (*)(ignore_t))
struct make_tuple_traits<detail::ignore_t(detail::ignore_t)>
{ {
typedef detail::swallow_assign type; }
};
template <class T> template <typename T>
struct is_class_or_union swallow_assign const& swallow_assign::operator=(const T&) const
{ {
template <class U> return *this;
static char is_class_or_union_tester(void (U::*)(void)); }
};
} // namespace detail
template <>
struct make_tuple_traits<detail::ignore_t(detail::ignore_t)>
{
typedef detail::swallow_assign type;
};
template <class T>
struct is_class_or_union
{
template <class U>
static char is_class_or_union_tester(void (U::*)(void));
};
} // namespace boost } // namespace boost
template <std::size_t N, std::size_t... I> template <std::size_t N, std::size_t... I>
@ -1401,9 +1401,9 @@ void TemplatedFunction(T type)
} }
inline namespace InlineNamespace { inline namespace InlineNamespace {
void FunctionInsideInlineNamespace() void FunctionInsideInlineNamespace()
{ {
} }
} // namespace InlineNamespace } // namespace InlineNamespace
union union
@ -1431,9 +1431,9 @@ struct TemplateWithUsingTemplateMember
}; };
namespace hasUnnamedDecl { namespace hasUnnamedDecl {
extern "C" extern "C"
{ {
} }
} // namespace hasUnnamedDecl } // namespace hasUnnamedDecl
enum ItemsDifferByCase enum ItemsDifferByCase

18
tests/dotnet/NamespacesBase/NamespacesBase.h

@ -2,16 +2,16 @@
namespace OverlappingNamespace { namespace OverlappingNamespace {
enum ColorsEnum enum ColorsEnum
{ {
white, white,
black, black,
red, red,
blue, blue,
green, green,
}; };
class DLL_API InBaseLib{}; class DLL_API InBaseLib{};
} // namespace OverlappingNamespace } // namespace OverlappingNamespace

24
tests/dotnet/NamespacesDerived/NamespacesDerived.h

@ -8,13 +8,13 @@
// Namespace clashes with NamespacesBase.OverlappingNamespace // Namespace clashes with NamespacesBase.OverlappingNamespace
// Test whether qualified names turn out right. // Test whether qualified names turn out right.
namespace OverlappingNamespace { namespace OverlappingNamespace {
class DLL_API InDerivedLib class DLL_API InDerivedLib
{ {
public: public:
InDerivedLib(); InDerivedLib();
Base parentNSComponent; Base parentNSComponent;
ColorsEnum color; ColorsEnum color;
}; };
} // namespace OverlappingNamespace } // namespace OverlappingNamespace
@ -135,11 +135,11 @@ private:
DLL_API bool operator<<(const Base& b, const char* str); DLL_API bool operator<<(const Base& b, const char* str);
namespace NamespacesBase { namespace NamespacesBase {
class DLL_API ClassInNamespaceNamedAfterDependency class DLL_API ClassInNamespaceNamedAfterDependency
{ {
private: private:
Base base; Base base;
}; };
} // namespace NamespacesBase } // namespace NamespacesBase
/// Hash set/map base class. /// Hash set/map base class.

46
tests/dotnet/Native/AST.h

@ -5,30 +5,30 @@ void TestParameterProperties(bool a, const short& b, int* c = nullptr) {};
// Tests various AST helper methods (like FindClass, FindOperator etc.) // Tests various AST helper methods (like FindClass, FindOperator etc.)
namespace Math { namespace Math {
// Tests FindClass("Math::Complex") // Tests FindClass("Math::Complex")
struct Complex struct Complex
{
Complex(double r, double i)
: re(r)
, im(i)
{ {
Complex(double r, double i) }
: re(r) Complex operator+(Complex& other);
, im(i)
{
}
Complex operator+(Complex& other);
private:
double re, im;
};
// Tests FindTypedef("Math::Single") private:
typedef float Single; double re, im;
};
// Tests FindOperator method // Tests FindTypedef("Math::Single")
Complex Complex::operator+(Complex& other) typedef float Single;
{
return Complex(re + other.re, im + other.im);
}
void function(); // Tests FindOperator method
Complex Complex::operator+(Complex& other)
{
return Complex(re + other.re, im + other.im);
}
void function();
} // namespace Math } // namespace Math
// Tests Enum.ItemByName // Tests Enum.ItemByName
@ -90,9 +90,9 @@ public:
}; };
namespace HidesClass { namespace HidesClass {
class HiddenInNamespace class HiddenInNamespace
{ {
}; };
} // namespace HidesClass } // namespace HidesClass
void testSignature(); void testSignature();

Loading…
Cancel
Save