Browse Source

Add PrimitiveTypes Long and ULong

The enum PrimitiveType represents, according to the comment, "the C++
built-in types.". However, it does not contain values for C++'s "long"
or "unsigned long", and the parser converts long to int. This is not
correct, and is a problem with 64bit support.

This patch adds Long and ULong values to PrimitiveType, and adds those
to all the switch-cases all around the code. For now Long and ULong are
handled exactly like Int and UInt, so this patch does not change
behavior.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
pull/252/head
Tomi Valkeinen 12 years ago committed by triton
parent
commit
3902dd4acc
  1. 3
      src/AST/Type.cs
  2. 4
      src/Core/Parser/ASTConverter.cs
  3. 2
      src/CppParser/AST.h
  4. 12
      src/CppParser/Bindings/CLI/AST.h
  5. 12
      src/CppParser/Bindings/CSharp/i686-pc-win32/AST.cs
  6. 4
      src/CppParser/Parser.cpp
  7. 4
      src/Generator/Generators/CLI/CLIMarshal.cs
  8. 2
      src/Generator/Generators/CLI/CLITypePrinter.cs
  9. 6
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  10. 2
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  11. 2
      src/Generator/Types/CppTypePrinter.cs
  12. 4
      src/Parser/Parser.cpp

3
src/AST/Type.cs

@ -665,6 +665,8 @@ namespace CppSharp.AST @@ -665,6 +665,8 @@ namespace CppSharp.AST
UInt16,
Int32,
UInt32,
Long,
ULong,
Int64,
UInt64,
Float,
@ -698,6 +700,7 @@ namespace CppSharp.AST @@ -698,6 +700,7 @@ namespace CppSharp.AST
case PrimitiveType.UInt8:
case PrimitiveType.UInt16:
case PrimitiveType.UInt32:
case PrimitiveType.ULong:
case PrimitiveType.UInt64:
return true;
}

4
src/Core/Parser/ASTConverter.cs

@ -568,6 +568,10 @@ namespace CppSharp @@ -568,6 +568,10 @@ namespace CppSharp
return AST.PrimitiveType.Int32;
case PrimitiveType.UInt32:
return AST.PrimitiveType.UInt32;
case PrimitiveType.Long:
return AST.PrimitiveType.Long;
case PrimitiveType.ULong:
return AST.PrimitiveType.ULong;
case PrimitiveType.Int64:
return AST.PrimitiveType.Int64;
case PrimitiveType.UInt64:

2
src/CppParser/AST.h

@ -242,6 +242,8 @@ enum struct PrimitiveType @@ -242,6 +242,8 @@ enum struct PrimitiveType
UInt16,
Int32,
UInt32,
Long,
ULong,
Int64,
UInt64,
Float,

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

@ -245,11 +245,13 @@ namespace CppSharp @@ -245,11 +245,13 @@ namespace CppSharp
UInt16 = 7,
Int32 = 8,
UInt32 = 9,
Int64 = 10,
UInt64 = 11,
Float = 12,
Double = 13,
IntPtr = 14
Long = 10,
ULong = 11,
Int64 = 12,
UInt64 = 13,
Float = 14,
Double = 15,
IntPtr = 16
};
public enum struct RawCommentKind

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

@ -173,11 +173,13 @@ namespace CppSharp @@ -173,11 +173,13 @@ namespace CppSharp
UInt16 = 7,
Int32 = 8,
UInt32 = 9,
Int64 = 10,
UInt64 = 11,
Float = 12,
Double = 13,
IntPtr = 14
Long = 10,
ULong = 11,
Int64 = 12,
UInt64 = 13,
Float = 14,
Double = 15,
IntPtr = 16
}
public enum RawCommentKind

4
src/CppParser/Parser.cpp

@ -1335,8 +1335,8 @@ static PrimitiveType WalkBuiltinType(const clang::BuiltinType* Builtin) @@ -1335,8 +1335,8 @@ static PrimitiveType WalkBuiltinType(const clang::BuiltinType* Builtin)
case clang::BuiltinType::Int: return PrimitiveType::Int32;
case clang::BuiltinType::UInt: return PrimitiveType::UInt32;
case clang::BuiltinType::Long: return PrimitiveType::Int32;
case clang::BuiltinType::ULong: return PrimitiveType::UInt32;
case clang::BuiltinType::Long: return PrimitiveType::Long;
case clang::BuiltinType::ULong: return PrimitiveType::ULong;
case clang::BuiltinType::LongLong: return PrimitiveType::Int64;
case clang::BuiltinType::ULongLong: return PrimitiveType::UInt64;

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

@ -162,6 +162,8 @@ namespace CppSharp.Generators.CLI @@ -162,6 +162,8 @@ namespace CppSharp.Generators.CLI
case PrimitiveType.UInt16:
case PrimitiveType.Int32:
case PrimitiveType.UInt32:
case PrimitiveType.Long:
case PrimitiveType.ULong:
case PrimitiveType.Int64:
case PrimitiveType.UInt64:
case PrimitiveType.Float:
@ -501,6 +503,8 @@ namespace CppSharp.Generators.CLI @@ -501,6 +503,8 @@ namespace CppSharp.Generators.CLI
case PrimitiveType.UInt16:
case PrimitiveType.Int32:
case PrimitiveType.UInt32:
case PrimitiveType.Long:
case PrimitiveType.ULong:
case PrimitiveType.Int64:
case PrimitiveType.UInt64:
case PrimitiveType.Float:

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

@ -195,6 +195,8 @@ namespace CppSharp.Generators.CLI @@ -195,6 +195,8 @@ namespace CppSharp.Generators.CLI
case PrimitiveType.UInt16: return "unsigned short";
case PrimitiveType.Int32: return "int";
case PrimitiveType.UInt32: return "unsigned int";
case PrimitiveType.Long: return "int";
case PrimitiveType.ULong: return "unsigned int";
case PrimitiveType.Int64: return "long long";
case PrimitiveType.UInt64: return "unsigned long long";
case PrimitiveType.Float: return "float";

6
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -193,6 +193,8 @@ namespace CppSharp.Generators.CSharp @@ -193,6 +193,8 @@ namespace CppSharp.Generators.CSharp
case PrimitiveType.UInt16:
case PrimitiveType.Int32:
case PrimitiveType.UInt32:
case PrimitiveType.Long:
case PrimitiveType.ULong:
case PrimitiveType.Int64:
case PrimitiveType.UInt64:
case PrimitiveType.Float:
@ -513,6 +515,8 @@ namespace CppSharp.Generators.CSharp @@ -513,6 +515,8 @@ namespace CppSharp.Generators.CSharp
case PrimitiveType.UInt16:
case PrimitiveType.Int32:
case PrimitiveType.UInt32:
case PrimitiveType.Long:
case PrimitiveType.ULong:
case PrimitiveType.Int64:
case PrimitiveType.UInt64:
case PrimitiveType.Float:
@ -524,7 +528,7 @@ namespace CppSharp.Generators.CSharp @@ -524,7 +528,7 @@ namespace CppSharp.Generators.CSharp
return false;
}
return false;
throw new NotImplementedException();
}
public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)

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

@ -392,6 +392,8 @@ namespace CppSharp.Generators.CSharp @@ -392,6 +392,8 @@ namespace CppSharp.Generators.CSharp
case PrimitiveType.UInt16: return "ushort";
case PrimitiveType.Int32: return "int";
case PrimitiveType.UInt32: return "uint";
case PrimitiveType.Long: return "int";
case PrimitiveType.ULong: return "uint";
case PrimitiveType.Int64: return "long";
case PrimitiveType.UInt64: return "ulong";
case PrimitiveType.Float: return "float";

2
src/Generator/Types/CppTypePrinter.cs

@ -110,6 +110,8 @@ namespace CppSharp.Types @@ -110,6 +110,8 @@ namespace CppSharp.Types
case PrimitiveType.UInt16: return "unsigned short";
case PrimitiveType.Int32: return "int";
case PrimitiveType.UInt32: return "unsigned int";
case PrimitiveType.Long: return "int";
case PrimitiveType.ULong: return "unsigned int";
case PrimitiveType.Int64: return "long long";
case PrimitiveType.UInt64: return "unsigned long long";
case PrimitiveType.Float: return "float";

4
src/Parser/Parser.cpp

@ -1341,8 +1341,8 @@ static CppSharp::AST::PrimitiveType WalkBuiltinType(const clang::BuiltinType* Bu @@ -1341,8 +1341,8 @@ static CppSharp::AST::PrimitiveType WalkBuiltinType(const clang::BuiltinType* Bu
case clang::BuiltinType::Int: return PrimitiveType::Int32;
case clang::BuiltinType::UInt: return PrimitiveType::UInt32;
case clang::BuiltinType::Long: return PrimitiveType::Int32;
case clang::BuiltinType::ULong: return PrimitiveType::UInt32;
case clang::BuiltinType::Long: return PrimitiveType::Long;
case clang::BuiltinType::ULong: return PrimitiveType::ULong;
case clang::BuiltinType::LongLong: return PrimitiveType::Int64;
case clang::BuiltinType::ULongLong: return PrimitiveType::UInt64;

Loading…
Cancel
Save