Browse Source

Extend printing and reading of exception types

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1272/head
Dimitar Dobrev 6 years ago
parent
commit
4a4c919fb3
  1. 2
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std-symbols.cpp
  2. 2
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std-symbols.cpp
  3. 17
      src/Generator.Tests/AST/TestAST.cs
  4. 22
      src/Generator/Generators/C/CppTypePrinter.cs
  5. 5
      tests/Native/AST.h

2
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std-symbols.cpp

@ -4,7 +4,7 @@
#include <string> #include <string>
template __declspec(dllexport) std::allocator<char>::allocator() noexcept; template __declspec(dllexport) std::allocator<char>::allocator() noexcept;
template __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string() noexcept; template __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string() noexcept(true);
template __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() noexcept; template __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() noexcept;
template __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char>>& std::basic_string<char, std::char_traits<char>, std::allocator<char>>::assign(const char* const); template __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char>>& std::basic_string<char, std::char_traits<char>, std::allocator<char>>::assign(const char* const);
template __declspec(dllexport) const char* std::basic_string<char, std::char_traits<char>, std::allocator<char>>::data() const noexcept; template __declspec(dllexport) const char* std::basic_string<char, std::char_traits<char>, std::allocator<char>>::data() const noexcept;

2
src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std-symbols.cpp

@ -4,7 +4,7 @@
#include <string> #include <string>
template __declspec(dllexport) std::allocator<char>::allocator() noexcept; template __declspec(dllexport) std::allocator<char>::allocator() noexcept;
template __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string() noexcept; template __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string() noexcept(true);
template __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() noexcept; template __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() noexcept;
template __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char>>& std::basic_string<char, std::char_traits<char>, std::allocator<char>>::assign(const char* const); template __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char>>& std::basic_string<char, std::char_traits<char>, std::allocator<char>>::assign(const char* const);
template __declspec(dllexport) const char* std::basic_string<char, std::char_traits<char>, std::allocator<char>>::data() const noexcept; template __declspec(dllexport) const char* std::basic_string<char, std::char_traits<char>, std::allocator<char>>::data() const noexcept;

17
src/Generator.Tests/AST/TestAST.cs

@ -495,12 +495,21 @@ namespace CppSharp.Generator.Tests.AST
[Test] [Test]
public void TestFunctionSpecifications() public void TestFunctionSpecifications()
{ {
var constExprNoExcept = AstContext.FindFunction("constExprNoExcept").First(); var constExpr = AstContext.FindFunction("constExpr").First();
Assert.IsTrue(constExprNoExcept.IsConstExpr); Assert.IsTrue(constExpr.IsConstExpr);
var functionType = (FunctionType) constExprNoExcept.FunctionType.Type;
Assert.That(functionType.ExceptionSpecType, var noExcept = AstContext.FindFunction("noExcept").First();
Assert.That(((FunctionType) noExcept.FunctionType.Type).ExceptionSpecType,
Is.EqualTo(ExceptionSpecType.BasicNoexcept)); Is.EqualTo(ExceptionSpecType.BasicNoexcept));
var noExceptTrue = AstContext.FindFunction("noExceptTrue").First();
Assert.That(((FunctionType) noExcept.FunctionType.Type).ExceptionSpecType,
Is.EqualTo(ExceptionSpecType.NoexceptTrue).Or.EqualTo(ExceptionSpecType.BasicNoexcept));
var noExceptFalse = AstContext.FindFunction("noExceptFalse").First();
Assert.That(((FunctionType) noExcept.FunctionType.Type).ExceptionSpecType,
Is.EqualTo(ExceptionSpecType.NoexceptFalse).Or.EqualTo(ExceptionSpecType.BasicNoexcept));
var regular = AstContext.FindFunction("testSignature").First(); var regular = AstContext.FindFunction("testSignature").First();
Assert.IsFalse(regular.IsConstExpr); Assert.IsFalse(regular.IsConstExpr);
var regularFunctionType = (FunctionType) regular.FunctionType.Type; var regularFunctionType = (FunctionType) regular.FunctionType.Type;

22
src/Generator/Generators/C/CppTypePrinter.cs

@ -423,10 +423,24 @@ namespace CppSharp.Generators.C
method.OperatorKind == CXXOperatorKind.ExplicitConversion ? method.OperatorKind == CXXOperatorKind.ExplicitConversion ?
$"operator {method.OriginalReturnType.Visit(this)}" : $"operator {method.OriginalReturnType.Visit(this)}" :
method.OriginalName; method.OriginalName;
var exceptionType =
functionType.ExceptionSpecType == ExceptionSpecType.BasicNoexcept || string exceptionType;
functionType.ExceptionSpecType == ExceptionSpecType.NoexceptTrue ? switch (functionType.ExceptionSpecType)
" noexcept" : string.Empty; {
case ExceptionSpecType.BasicNoexcept:
exceptionType = " noexcept";
break;
case ExceptionSpecType.NoexceptFalse:
exceptionType = " noexcept(false)";
break;
case ExceptionSpecType.NoexceptTrue:
exceptionType = " noexcept(true)";
break;
// TODO: research and handle the remaining cases
default:
exceptionType = string.Empty;
break;
}
return $"{returnType}{@class}::{name}({@params}){@const}{exceptionType}"; return $"{returnType}{@class}::{name}({@params}){@const}{exceptionType}";
} }

5
tests/Native/AST.h

@ -204,7 +204,10 @@ typedef ForwardedTemplate<long> l;
template class TestSpecializationArguments<const TestASTEnumItemByName>; template class TestSpecializationArguments<const TestASTEnumItemByName>;
constexpr void constExprNoExcept() noexcept; constexpr void constExpr();
void noExcept() noexcept;
void noExceptTrue() noexcept(true);
void noExceptFalse() noexcept(false);
template <typename T1, typename T2> template <typename T1, typename T2>
bool functionWithSpecInfo(const T1& t11, const T1& t12, const T2& t2); bool functionWithSpecInfo(const T1& t11, const T1& t12, const T2& t2);

Loading…
Cancel
Save