diff --git a/src/AST/Type.cs b/src/AST/Type.cs index 436ecec9..ec041282 100644 --- a/src/AST/Type.cs +++ b/src/AST/Type.cs @@ -941,6 +941,7 @@ namespace CppSharp.AST ULongLong, Float, Double, + LongDouble, IntPtr, UIntPtr, Char16 diff --git a/src/Core/Parser/ASTConverter.cs b/src/Core/Parser/ASTConverter.cs index d64f70a0..8824ccd0 100644 --- a/src/Core/Parser/ASTConverter.cs +++ b/src/Core/Parser/ASTConverter.cs @@ -661,6 +661,8 @@ namespace CppSharp return AST.PrimitiveType.Float; case PrimitiveType.Double: return AST.PrimitiveType.Double; + case PrimitiveType.LongDouble: + return AST.PrimitiveType.LongDouble; case PrimitiveType.IntPtr: return AST.PrimitiveType.IntPtr; default: diff --git a/src/CppParser/AST.h b/src/CppParser/AST.h index dbb85392..c9888861 100644 --- a/src/CppParser/AST.h +++ b/src/CppParser/AST.h @@ -254,6 +254,7 @@ enum class PrimitiveType ULongLong, Float, Double, + LongDouble, IntPtr }; diff --git a/src/CppParser/Bindings/CLI/AST.h b/src/CppParser/Bindings/CLI/AST.h index 7602bdca..a74b21d2 100644 --- a/src/CppParser/Bindings/CLI/AST.h +++ b/src/CppParser/Bindings/CLI/AST.h @@ -332,7 +332,8 @@ namespace CppSharp ULongLong = 13, Float = 14, Double = 15, - IntPtr = 16 + LongDouble = 16, + IntPtr = 17 }; public enum struct MacroLocation diff --git a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs index ce40ea9a..31ca4698 100644 --- a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs +++ b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs @@ -231,7 +231,8 @@ namespace CppSharp ULongLong = 13, Float = 14, Double = 15, - IntPtr = 16 + LongDouble = 16, + IntPtr = 17 } public enum MacroLocation diff --git a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs index de94def6..d743fbd1 100644 --- a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs +++ b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs @@ -231,7 +231,8 @@ namespace CppSharp ULongLong = 13, Float = 14, Double = 15, - IntPtr = 16 + LongDouble = 16, + IntPtr = 17 } public enum MacroLocation diff --git a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs index 4b139323..920108d5 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs @@ -231,7 +231,8 @@ namespace CppSharp ULongLong = 13, Float = 14, Double = 15, - IntPtr = 16 + LongDouble = 16, + IntPtr = 17 } public enum MacroLocation diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs index 4a2e8cde..27d75bdd 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs @@ -231,7 +231,8 @@ namespace CppSharp ULongLong = 13, Float = 14, Double = 15, - IntPtr = 16 + LongDouble = 16, + IntPtr = 17 } public enum MacroLocation diff --git a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/AST.cs b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/AST.cs index fd14799d..4402c17e 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/AST.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/AST.cs @@ -231,7 +231,8 @@ namespace CppSharp ULongLong = 13, Float = 14, Double = 15, - IntPtr = 16 + LongDouble = 16, + IntPtr = 17 } public enum MacroLocation diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index 21038e63..a5c9b4a9 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -1699,6 +1699,7 @@ static PrimitiveType WalkBuiltinType(const clang::BuiltinType* Builtin) case clang::BuiltinType::Float: return PrimitiveType::Float; case clang::BuiltinType::Double: return PrimitiveType::Double; + case clang::BuiltinType::LongDouble: return PrimitiveType::LongDouble; case clang::BuiltinType::NullPtr: return PrimitiveType::Null; diff --git a/src/Generator/Generators/CLI/CLIMarshal.cs b/src/Generator/Generators/CLI/CLIMarshal.cs index 92d8e37f..0f421bf6 100644 --- a/src/Generator/Generators/CLI/CLIMarshal.cs +++ b/src/Generator/Generators/CLI/CLIMarshal.cs @@ -222,6 +222,7 @@ namespace CppSharp.Generators.CLI case PrimitiveType.ULongLong: case PrimitiveType.Float: case PrimitiveType.Double: + case PrimitiveType.LongDouble: case PrimitiveType.Null: Context.Return.Write(Context.ReturnVarName); return true; diff --git a/src/Generator/Generators/CLI/CLITypePrinter.cs b/src/Generator/Generators/CLI/CLITypePrinter.cs index 4af2de7e..4c80ef2d 100644 --- a/src/Generator/Generators/CLI/CLITypePrinter.cs +++ b/src/Generator/Generators/CLI/CLITypePrinter.cs @@ -219,6 +219,7 @@ namespace CppSharp.Generators.CLI case PrimitiveType.ULongLong: return "unsigned long long"; case PrimitiveType.Float: return "float"; case PrimitiveType.Double: return "double"; + case PrimitiveType.LongDouble: return "long double"; case PrimitiveType.IntPtr: return "IntPtr"; case PrimitiveType.UIntPtr: return "UIntPtr"; case PrimitiveType.Null: return "void*"; diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 7df4cc3f..4c57182b 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -799,6 +799,13 @@ namespace CppSharp.Generators.CSharp if (decl != null && decl.TranslationUnit.IsSystemHeader) return; + var arrayType = field.QualifiedType.Type.Desugar() as ArrayType; + // we do not support long double yet because its representation in C# is problematic + if ((arrayType != null && arrayType.SizeType == ArrayType.ArraySize.Constant && + arrayType.Type.IsPrimitiveType(PrimitiveType.LongDouble)) || + field.QualifiedType.Type.IsPrimitiveType(PrimitiveType.LongDouble)) + return; + var safeIdentifier = Helpers.SafeIdentifier(field.Name); if(safeIdentifier.All(c => c.Equals('_'))) @@ -836,7 +843,6 @@ namespace CppSharp.Generators.CSharp // Workaround a bug in Mono when handling fixed arrays in P/Invoke declarations. // https://bugzilla.xamarin.com/show_bug.cgi?id=33571 - var arrayType = field.QualifiedType.Type.Desugar() as ArrayType; if (arrayType != null && arrayType.SizeType == ArrayType.ArraySize.Constant && arrayType.Size > 0) { diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs index fd5b35de..9e697848 100644 --- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs @@ -552,6 +552,8 @@ namespace CppSharp.Generators.CSharp return GetIntString(primitive, driver.TargetInfo); case PrimitiveType.Float: return "float"; case PrimitiveType.Double: return "double"; + // not really supported yet but it's closest, and we don't want crashes when parsing long doubles + case PrimitiveType.LongDouble: return "decimal"; case PrimitiveType.IntPtr: return IntPtrType; case PrimitiveType.UIntPtr: return "global::System.UIntPtr"; case PrimitiveType.Null: return "void*"; diff --git a/src/Generator/Types/CppTypePrinter.cs b/src/Generator/Types/CppTypePrinter.cs index c50d1158..1a56dae1 100644 --- a/src/Generator/Types/CppTypePrinter.cs +++ b/src/Generator/Types/CppTypePrinter.cs @@ -119,6 +119,7 @@ namespace CppSharp.Types case PrimitiveType.ULongLong: return "unsigned long long"; case PrimitiveType.Float: return "float"; case PrimitiveType.Double: return "double"; + case PrimitiveType.LongDouble: return "long double"; case PrimitiveType.IntPtr: return "void*"; case PrimitiveType.UIntPtr: return "uintptr_t"; case PrimitiveType.Null: return "std::nullptr_t"; diff --git a/src/Generator/Types/Types.cs b/src/Generator/Types/Types.cs index 498dea3c..4ed54be1 100644 --- a/src/Generator/Types/Types.cs +++ b/src/Generator/Types/Types.cs @@ -24,6 +24,17 @@ namespace CppSharp IsIgnored = true; } + public override bool VisitPrimitiveType(PrimitiveType type, TypeQualifiers quals) + { + // we do not support long double yet because its high-level representation is often problematic + if (type == PrimitiveType.LongDouble) + { + Ignore(); + return false; + } + return base.VisitPrimitiveType(type, quals); + } + public override bool VisitDeclaration(Declaration decl) { if (AlreadyVisited(decl)) @@ -129,7 +140,7 @@ namespace CppSharp return true; PrimitiveType primitive; - if (arrayElemType.IsPrimitiveType(out primitive) || + if ((arrayElemType.IsPrimitiveType(out primitive) && primitive != PrimitiveType.LongDouble) || arrayElemType.IsPointerToPrimitiveType()) return true; diff --git a/tests/Common/Common.h b/tests/Common/Common.h index fa072262..7fe047eb 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -1167,3 +1167,9 @@ class HasSystemBase : public std::string }; typedef SpecialisesVoid> SpecialisesWithNestedSystemTypes; + +struct HasLongDoubles +{ + long double simple; + long double array[4]; +};