Browse Source

Fixed the generated code when having long doubles in the origin.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/661/head
Dimitar Dobrev 9 years ago
parent
commit
3eb259f151
  1. 1
      src/AST/Type.cs
  2. 2
      src/Core/Parser/ASTConverter.cs
  3. 1
      src/CppParser/AST.h
  4. 3
      src/CppParser/Bindings/CLI/AST.h
  5. 3
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs
  6. 3
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs
  7. 3
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs
  8. 3
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs
  9. 3
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/AST.cs
  10. 1
      src/CppParser/Parser.cpp
  11. 1
      src/Generator/Generators/CLI/CLIMarshal.cs
  12. 1
      src/Generator/Generators/CLI/CLITypePrinter.cs
  13. 8
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  14. 2
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  15. 1
      src/Generator/Types/CppTypePrinter.cs
  16. 13
      src/Generator/Types/Types.cs
  17. 6
      tests/Common/Common.h

1
src/AST/Type.cs

@ -941,6 +941,7 @@ namespace CppSharp.AST @@ -941,6 +941,7 @@ namespace CppSharp.AST
ULongLong,
Float,
Double,
LongDouble,
IntPtr,
UIntPtr,
Char16

2
src/Core/Parser/ASTConverter.cs

@ -661,6 +661,8 @@ namespace CppSharp @@ -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:

1
src/CppParser/AST.h

@ -254,6 +254,7 @@ enum class PrimitiveType @@ -254,6 +254,7 @@ enum class PrimitiveType
ULongLong,
Float,
Double,
LongDouble,
IntPtr
};

3
src/CppParser/Bindings/CLI/AST.h

@ -332,7 +332,8 @@ namespace CppSharp @@ -332,7 +332,8 @@ namespace CppSharp
ULongLong = 13,
Float = 14,
Double = 15,
IntPtr = 16
LongDouble = 16,
IntPtr = 17
};
public enum struct MacroLocation

3
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs

@ -231,7 +231,8 @@ namespace CppSharp @@ -231,7 +231,8 @@ namespace CppSharp
ULongLong = 13,
Float = 14,
Double = 15,
IntPtr = 16
LongDouble = 16,
IntPtr = 17
}
public enum MacroLocation

3
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs

@ -231,7 +231,8 @@ namespace CppSharp @@ -231,7 +231,8 @@ namespace CppSharp
ULongLong = 13,
Float = 14,
Double = 15,
IntPtr = 16
LongDouble = 16,
IntPtr = 17
}
public enum MacroLocation

3
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/AST.cs

@ -231,7 +231,8 @@ namespace CppSharp @@ -231,7 +231,8 @@ namespace CppSharp
ULongLong = 13,
Float = 14,
Double = 15,
IntPtr = 16
LongDouble = 16,
IntPtr = 17
}
public enum MacroLocation

3
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs

@ -231,7 +231,8 @@ namespace CppSharp @@ -231,7 +231,8 @@ namespace CppSharp
ULongLong = 13,
Float = 14,
Double = 15,
IntPtr = 16
LongDouble = 16,
IntPtr = 17
}
public enum MacroLocation

3
src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/AST.cs

@ -231,7 +231,8 @@ namespace CppSharp @@ -231,7 +231,8 @@ namespace CppSharp
ULongLong = 13,
Float = 14,
Double = 15,
IntPtr = 16
LongDouble = 16,
IntPtr = 17
}
public enum MacroLocation

1
src/CppParser/Parser.cpp

@ -1699,6 +1699,7 @@ static PrimitiveType WalkBuiltinType(const clang::BuiltinType* Builtin) @@ -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;

1
src/Generator/Generators/CLI/CLIMarshal.cs

@ -222,6 +222,7 @@ namespace CppSharp.Generators.CLI @@ -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;

1
src/Generator/Generators/CLI/CLITypePrinter.cs

@ -219,6 +219,7 @@ namespace CppSharp.Generators.CLI @@ -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*";

8
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -799,6 +799,13 @@ namespace CppSharp.Generators.CSharp @@ -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 @@ -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)
{

2
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -552,6 +552,8 @@ namespace CppSharp.Generators.CSharp @@ -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*";

1
src/Generator/Types/CppTypePrinter.cs

@ -119,6 +119,7 @@ namespace CppSharp.Types @@ -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";

13
src/Generator/Types/Types.cs

@ -24,6 +24,17 @@ namespace CppSharp @@ -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 @@ -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;

6
tests/Common/Common.h

@ -1167,3 +1167,9 @@ class HasSystemBase : public std::string @@ -1167,3 +1167,9 @@ class HasSystemBase : public std::string
};
typedef SpecialisesVoid<std::vector<std::string>> SpecialisesWithNestedSystemTypes;
struct HasLongDoubles
{
long double simple;
long double array[4];
};

Loading…
Cancel
Save