Browse Source

Update namespace formatting to inner

pull/1912/head
duckdoom5 8 months 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 @@ -56,7 +56,7 @@ KeepEmptyLinesAtTheStartOfBlocks : true
MaxEmptyLinesToKeep : 2
EmptyLineAfterAccessModifier : Leave
EmptyLineBeforeAccessModifier : LogicalBlock
NamespaceIndentation : All
NamespaceIndentation : Inner
PointerAlignment : Left
SpacesBeforeTrailingComments : 1
SpacesInAngles : Never

32
src/CppParser/ASTNameMangler.cpp

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

48
src/CppParser/ASTNameMangler.h

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

50
src/CppParser/CXXABI.h

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

26
src/CppParser/Parser.h

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

4
tests/dotnet/CSharp/AnotherUnit.cpp

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

4
tests/dotnet/CSharp/AnotherUnit.h

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

64
tests/dotnet/CSharp/CSharp.h

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

28
tests/dotnet/CSharp/CSharpTemplates.h

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

10
tests/dotnet/Common/AnotherUnit.h

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

168
tests/dotnet/Common/Common.h

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

18
tests/dotnet/NamespacesBase/NamespacesBase.h

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

24
tests/dotnet/NamespacesDerived/NamespacesDerived.h

@ -8,13 +8,13 @@ @@ -8,13 +8,13 @@
// Namespace clashes with NamespacesBase.OverlappingNamespace
// Test whether qualified names turn out right.
namespace OverlappingNamespace {
class DLL_API InDerivedLib
{
public:
InDerivedLib();
Base parentNSComponent;
ColorsEnum color;
};
class DLL_API InDerivedLib
{
public:
InDerivedLib();
Base parentNSComponent;
ColorsEnum color;
};
} // namespace OverlappingNamespace
@ -135,11 +135,11 @@ private: @@ -135,11 +135,11 @@ private:
DLL_API bool operator<<(const Base& b, const char* str);
namespace NamespacesBase {
class DLL_API ClassInNamespaceNamedAfterDependency
{
private:
Base base;
};
class DLL_API ClassInNamespaceNamedAfterDependency
{
private:
Base base;
};
} // namespace NamespacesBase
/// 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) {}; @@ -5,30 +5,30 @@ void TestParameterProperties(bool a, const short& b, int* c = nullptr) {};
// Tests various AST helper methods (like FindClass, FindOperator etc.)
namespace Math {
// Tests FindClass("Math::Complex")
struct Complex
// Tests FindClass("Math::Complex")
struct Complex
{
Complex(double r, double i)
: re(r)
, im(i)
{
Complex(double r, double i)
: re(r)
, im(i)
{
}
Complex operator+(Complex& other);
private:
double re, im;
};
}
Complex operator+(Complex& other);
// Tests FindTypedef("Math::Single")
typedef float Single;
private:
double re, im;
};
// Tests FindOperator method
Complex Complex::operator+(Complex& other)
{
return Complex(re + other.re, im + other.im);
}
// Tests FindTypedef("Math::Single")
typedef float Single;
void function();
// Tests FindOperator method
Complex Complex::operator+(Complex& other)
{
return Complex(re + other.re, im + other.im);
}
void function();
} // namespace Math
// Tests Enum.ItemByName
@ -90,9 +90,9 @@ public: @@ -90,9 +90,9 @@ public:
};
namespace HidesClass {
class HiddenInNamespace
{
};
class HiddenInNamespace
{
};
} // namespace HidesClass
void testSignature();

Loading…
Cancel
Save