From 1cd9f0a16ce76ddb64758cd7b5c4daa1b0c3f987 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Sat, 10 May 2014 14:31:35 +0300 Subject: [PATCH] Remove PrimitiveTypes Int8 and UInt8 As enum PrimitiveType is supposed to represent C++ types, having Int8 and UInt8 there is not correct. This patch removes those values. As Int8 and UInt8 were set to be equivalent to Char and UChar, we can just change all references to Int8 and UInt8 to Char and UChar. This doesn't change the behavior, but makes it clearer that the types for 'char' and 'unsigned char' are not necessarily 8 bits. Signed-off-by: Tomi Valkeinen --- src/AST/Type.cs | 8 +++----- src/Core/Parser/ASTConverter.cs | 8 ++++---- src/CppParser/AST.h | 6 ++---- src/CppParser/Bindings/CLI/AST.h | 2 -- src/CppParser/Bindings/CSharp/i686-pc-win32/AST.cs | 2 -- src/CppParser/Parser.cpp | 4 ++-- src/Generator/Generators/CLI/CLIMarshal.cs | 8 ++++---- src/Generator/Generators/CLI/CLISourcesTemplate.cs | 2 +- src/Generator/Generators/CLI/CLITypePrinter.cs | 4 ++-- src/Generator/Generators/CSharp/CSharpMarshal.cs | 8 ++++---- src/Generator/Generators/CSharp/CSharpTextTemplate.cs | 2 +- src/Generator/Generators/CSharp/CSharpTypePrinter.cs | 4 ++-- src/Generator/Types/CppTypePrinter.cs | 4 ++-- src/Parser/Parser.cpp | 4 ++-- 14 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/AST/Type.cs b/src/AST/Type.cs index 1bff7a06..f5af7722 100644 --- a/src/AST/Type.cs +++ b/src/AST/Type.cs @@ -657,10 +657,8 @@ namespace CppSharp.AST Void, Bool, WideChar, - Int8, - Char = Int8, - UInt8, - UChar = UInt8, + Char, + UChar, Int16, UInt16, Int32, @@ -697,7 +695,7 @@ namespace CppSharp.AST switch (Type) { case PrimitiveType.Bool: - case PrimitiveType.UInt8: + case PrimitiveType.UChar: case PrimitiveType.UInt16: case PrimitiveType.UInt32: case PrimitiveType.ULong: diff --git a/src/Core/Parser/ASTConverter.cs b/src/Core/Parser/ASTConverter.cs index 81c3848e..71571a5e 100644 --- a/src/Core/Parser/ASTConverter.cs +++ b/src/Core/Parser/ASTConverter.cs @@ -556,10 +556,10 @@ namespace CppSharp return AST.PrimitiveType.Bool; case PrimitiveType.WideChar: return AST.PrimitiveType.WideChar; - case PrimitiveType.Int8: - return AST.PrimitiveType.Int8; - case PrimitiveType.UInt8: - return AST.PrimitiveType.UInt8; + case PrimitiveType.Char: + return AST.PrimitiveType.Char; + case PrimitiveType.UChar: + return AST.PrimitiveType.UChar; case PrimitiveType.Int16: return AST.PrimitiveType.Int16; case PrimitiveType.UInt16: diff --git a/src/CppParser/AST.h b/src/CppParser/AST.h index 1da02a87..bc136726 100644 --- a/src/CppParser/AST.h +++ b/src/CppParser/AST.h @@ -234,10 +234,8 @@ enum struct PrimitiveType Void, Bool, WideChar, - Int8, - Char = Int8, - UInt8, - UChar = UInt8, + Char, + UChar, Int16, UInt16, Int32, diff --git a/src/CppParser/Bindings/CLI/AST.h b/src/CppParser/Bindings/CLI/AST.h index ee202111..991637e1 100644 --- a/src/CppParser/Bindings/CLI/AST.h +++ b/src/CppParser/Bindings/CLI/AST.h @@ -237,9 +237,7 @@ namespace CppSharp Void = 1, Bool = 2, WideChar = 3, - Int8 = 4, Char = 4, - UInt8 = 5, UChar = 5, Int16 = 6, UInt16 = 7, diff --git a/src/CppParser/Bindings/CSharp/i686-pc-win32/AST.cs b/src/CppParser/Bindings/CSharp/i686-pc-win32/AST.cs index 4af8adc1..e3b94021 100644 --- a/src/CppParser/Bindings/CSharp/i686-pc-win32/AST.cs +++ b/src/CppParser/Bindings/CSharp/i686-pc-win32/AST.cs @@ -165,9 +165,7 @@ namespace CppSharp Void = 1, Bool = 2, WideChar = 3, - Int8 = 4, Char = 4, - UInt8 = 5, UChar = 5, Int16 = 6, UInt16 = 7, diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index 64694956..c7852508 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -1321,10 +1321,10 @@ static PrimitiveType WalkBuiltinType(const clang::BuiltinType* Builtin) case clang::BuiltinType::Bool: return PrimitiveType::Bool; case clang::BuiltinType::SChar: - case clang::BuiltinType::Char_S: return PrimitiveType::Int8; + case clang::BuiltinType::Char_S: return PrimitiveType::Char; case clang::BuiltinType::UChar: - case clang::BuiltinType::Char_U: return PrimitiveType::UInt8; + case clang::BuiltinType::Char_U: return PrimitiveType::UChar; case clang::BuiltinType::WChar_S: case clang::BuiltinType::WChar_U: return PrimitiveType::WideChar; diff --git a/src/Generator/Generators/CLI/CLIMarshal.cs b/src/Generator/Generators/CLI/CLIMarshal.cs index 3e0978e6..08bc3a91 100644 --- a/src/Generator/Generators/CLI/CLIMarshal.cs +++ b/src/Generator/Generators/CLI/CLIMarshal.cs @@ -156,8 +156,8 @@ namespace CppSharp.Generators.CLI case PrimitiveType.Void: return true; case PrimitiveType.Bool: - case PrimitiveType.Int8: - case PrimitiveType.UInt8: + case PrimitiveType.Char: + case PrimitiveType.UChar: case PrimitiveType.Int16: case PrimitiveType.UInt16: case PrimitiveType.Int32: @@ -497,8 +497,8 @@ namespace CppSharp.Generators.CLI case PrimitiveType.Void: return true; case PrimitiveType.Bool: - case PrimitiveType.Int8: - case PrimitiveType.UInt8: + case PrimitiveType.Char: + case PrimitiveType.UChar: case PrimitiveType.Int16: case PrimitiveType.UInt16: case PrimitiveType.Int32: diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index af2a89b8..3feaf045 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -990,7 +990,7 @@ namespace CppSharp.Generators.CLI if (Driver.Options.MarshalCharAsManagedChar) { foreach (var param in method.Parameters.Where( - p => p.Type.IsPrimitiveType(PrimitiveType.Int8))) + p => p.Type.IsPrimitiveType(PrimitiveType.Char))) { WriteLine("if ({0} < System::Char::MinValue || {0} > System::SByte::MaxValue)", param.Name); WriteLineIndent( diff --git a/src/Generator/Generators/CLI/CLITypePrinter.cs b/src/Generator/Generators/CLI/CLITypePrinter.cs index 89663c93..c9540168 100644 --- a/src/Generator/Generators/CLI/CLITypePrinter.cs +++ b/src/Generator/Generators/CLI/CLITypePrinter.cs @@ -189,8 +189,8 @@ namespace CppSharp.Generators.CLI case PrimitiveType.Void: return "void"; case PrimitiveType.Char16: case PrimitiveType.WideChar: return "System::Char"; - case PrimitiveType.Int8: return Options.MarshalCharAsManagedChar ? "System::Char" : "char"; - case PrimitiveType.UInt8: return "unsigned char"; + case PrimitiveType.Char: return Options.MarshalCharAsManagedChar ? "System::Char" : "char"; + case PrimitiveType.UChar: return "unsigned char"; case PrimitiveType.Int16: return "short"; case PrimitiveType.UInt16: return "unsigned short"; case PrimitiveType.Int32: return "int"; diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 4f1bec47..3bff415f 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -187,8 +187,8 @@ namespace CppSharp.Generators.CSharp case PrimitiveType.Void: return true; case PrimitiveType.Bool: - case PrimitiveType.Int8: - case PrimitiveType.UInt8: + case PrimitiveType.Char: + case PrimitiveType.UChar: case PrimitiveType.Int16: case PrimitiveType.UInt16: case PrimitiveType.Int32: @@ -509,8 +509,8 @@ namespace CppSharp.Generators.CSharp case PrimitiveType.Void: return true; case PrimitiveType.Bool: - case PrimitiveType.Int8: - case PrimitiveType.UInt8: + case PrimitiveType.Char: + case PrimitiveType.UChar: case PrimitiveType.Int16: case PrimitiveType.UInt16: case PrimitiveType.Int32: diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 1116f439..1c47fb44 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2079,7 +2079,7 @@ namespace CppSharp.Generators.CSharp if (Driver.Options.MarshalCharAsManagedChar) { foreach (var param in method.Parameters.Where( - p => p.Type.IsPrimitiveType(PrimitiveType.Int8))) + p => p.Type.IsPrimitiveType(PrimitiveType.Char))) { WriteLine("if ({0} < char.MinValue || {0} > sbyte.MaxValue)", param.Name); WriteLineIndent( diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs index c89e8784..5bd43a9d 100644 --- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs @@ -386,8 +386,8 @@ namespace CppSharp.Generators.CSharp case PrimitiveType.Void: return "void"; case PrimitiveType.Char16: case PrimitiveType.WideChar: return "char"; - case PrimitiveType.Int8: return driverOptions.MarshalCharAsManagedChar ? "char" : "sbyte"; - case PrimitiveType.UInt8: return "byte"; + case PrimitiveType.Char: return driverOptions.MarshalCharAsManagedChar ? "char" : "sbyte"; + case PrimitiveType.UChar: return "byte"; case PrimitiveType.Int16: return "short"; case PrimitiveType.UInt16: return "ushort"; case PrimitiveType.Int32: return "int"; diff --git a/src/Generator/Types/CppTypePrinter.cs b/src/Generator/Types/CppTypePrinter.cs index fcbd3387..39a73d87 100644 --- a/src/Generator/Types/CppTypePrinter.cs +++ b/src/Generator/Types/CppTypePrinter.cs @@ -104,8 +104,8 @@ namespace CppSharp.Types case PrimitiveType.Void: return "void"; case PrimitiveType.Char16: case PrimitiveType.WideChar: return "char"; - case PrimitiveType.Int8: return "char"; - case PrimitiveType.UInt8: return "unsigned char"; + case PrimitiveType.Char: return "char"; + case PrimitiveType.UChar: return "unsigned char"; case PrimitiveType.Int16: return "short"; case PrimitiveType.UInt16: return "unsigned short"; case PrimitiveType.Int32: return "int"; diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index 2614065a..6d1f8a3d 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -1325,10 +1325,10 @@ static CppSharp::AST::PrimitiveType WalkBuiltinType(const clang::BuiltinType* Bu case clang::BuiltinType::Bool: return PrimitiveType::Bool; case clang::BuiltinType::SChar: - case clang::BuiltinType::Char_S: return PrimitiveType::Int8; + case clang::BuiltinType::Char_S: return PrimitiveType::Char; case clang::BuiltinType::UChar: - case clang::BuiltinType::Char_U: return PrimitiveType::UInt8; + case clang::BuiltinType::Char_U: return PrimitiveType::UChar; case clang::BuiltinType::WChar_S: case clang::BuiltinType::WChar_U: return PrimitiveType::WideChar;