From 8d322ad53e36df83ccbf040fc49e339446db95fb Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sun, 29 Jan 2017 09:46:10 +0200 Subject: [PATCH] Properly handled signed chars in the AST. --- src/AST/CppTypePrinter.cs | 1 + src/AST/Type.cs | 3 +- src/CppParser/AST.h | 1 + src/CppParser/Bindings/CLI/AST.h | 39 ++++++++++--------- .../CppSharp.CppParser.cs | 39 ++++++++++--------- .../i686-pc-win32-msvc/CppSharp.CppParser.cs | 39 ++++++++++--------- .../CppSharp.CppParser.cs | 39 ++++++++++--------- .../CppSharp.CppParser.cs | 39 ++++++++++--------- .../x86_64-linux-gnu/CppSharp.CppParser.cs | 39 ++++++++++--------- .../CppSharp.CppParser.cs | 39 ++++++++++--------- src/CppParser/Parser.cpp | 2 +- src/Generator/Generators/CLI/CLIMarshal.cs | 1 + .../Generators/CLI/CLITypePrinter.cs | 1 + .../Generators/CSharp/CSharpTypePrinter.cs | 1 + src/Parser/ASTConverter.cs | 2 + 15 files changed, 150 insertions(+), 135 deletions(-) diff --git a/src/AST/CppTypePrinter.cs b/src/AST/CppTypePrinter.cs index 2ebed004..4dfe0cfb 100644 --- a/src/AST/CppTypePrinter.cs +++ b/src/AST/CppTypePrinter.cs @@ -119,6 +119,7 @@ namespace CppSharp.AST case PrimitiveType.Char32: return "char32_t"; case PrimitiveType.WideChar: return "wchar_t"; case PrimitiveType.Char: return "char"; + case PrimitiveType.SChar: return "signed char"; case PrimitiveType.UChar: return "unsigned char"; case PrimitiveType.Short: return "short"; case PrimitiveType.UShort: return "unsigned short"; diff --git a/src/AST/Type.cs b/src/AST/Type.cs index 2e603141..ca04d63b 100644 --- a/src/AST/Type.cs +++ b/src/AST/Type.cs @@ -1112,6 +1112,7 @@ namespace CppSharp.AST Bool, WideChar, Char, + SChar, UChar, Char16, Char32, @@ -1131,7 +1132,7 @@ namespace CppSharp.AST LongDouble, Float128, IntPtr, - UIntPtr, + UIntPtr } /// diff --git a/src/CppParser/AST.h b/src/CppParser/AST.h index bd9b9fb8..611393e4 100644 --- a/src/CppParser/AST.h +++ b/src/CppParser/AST.h @@ -290,6 +290,7 @@ enum class PrimitiveType Bool, WideChar, Char, + SChar, UChar, Char16, Char32, diff --git a/src/CppParser/Bindings/CLI/AST.h b/src/CppParser/Bindings/CLI/AST.h index 9beffdd9..fa49e6e5 100644 --- a/src/CppParser/Bindings/CLI/AST.h +++ b/src/CppParser/Bindings/CLI/AST.h @@ -360,25 +360,26 @@ namespace CppSharp Bool = 2, WideChar = 3, Char = 4, - UChar = 5, - Char16 = 6, - Char32 = 7, - Short = 8, - UShort = 9, - Int = 10, - UInt = 11, - Long = 12, - ULong = 13, - LongLong = 14, - ULongLong = 15, - Int128 = 16, - UInt128 = 17, - Half = 18, - Float = 19, - Double = 20, - LongDouble = 21, - Float128 = 22, - IntPtr = 23 + SChar = 5, + UChar = 6, + Char16 = 7, + Char32 = 8, + Short = 9, + UShort = 10, + Int = 11, + UInt = 12, + Long = 13, + ULong = 14, + LongLong = 15, + ULongLong = 16, + Int128 = 17, + UInt128 = 18, + Half = 19, + Float = 20, + Double = 21, + LongDouble = 22, + Float128 = 23, + IntPtr = 24 }; public enum struct ExceptionSpecType diff --git a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs index 8b258803..4c952f0c 100644 --- a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs @@ -253,25 +253,26 @@ namespace CppSharp Bool = 2, WideChar = 3, Char = 4, - UChar = 5, - Char16 = 6, - Char32 = 7, - Short = 8, - UShort = 9, - Int = 10, - UInt = 11, - Long = 12, - ULong = 13, - LongLong = 14, - ULongLong = 15, - Int128 = 16, - UInt128 = 17, - Half = 18, - Float = 19, - Double = 20, - LongDouble = 21, - Float128 = 22, - IntPtr = 23 + SChar = 5, + UChar = 6, + Char16 = 7, + Char32 = 8, + Short = 9, + UShort = 10, + Int = 11, + UInt = 12, + Long = 13, + ULong = 14, + LongLong = 15, + ULongLong = 16, + Int128 = 17, + UInt128 = 18, + Half = 19, + Float = 20, + Double = 21, + LongDouble = 22, + Float128 = 23, + IntPtr = 24 } public enum ExceptionSpecType diff --git a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs index bf17e2c7..c6831d91 100644 --- a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs @@ -253,25 +253,26 @@ namespace CppSharp Bool = 2, WideChar = 3, Char = 4, - UChar = 5, - Char16 = 6, - Char32 = 7, - Short = 8, - UShort = 9, - Int = 10, - UInt = 11, - Long = 12, - ULong = 13, - LongLong = 14, - ULongLong = 15, - Int128 = 16, - UInt128 = 17, - Half = 18, - Float = 19, - Double = 20, - LongDouble = 21, - Float128 = 22, - IntPtr = 23 + SChar = 5, + UChar = 6, + Char16 = 7, + Char32 = 8, + Short = 9, + UShort = 10, + Int = 11, + UInt = 12, + Long = 13, + ULong = 14, + LongLong = 15, + ULongLong = 16, + Int128 = 17, + UInt128 = 18, + Half = 19, + Float = 20, + Double = 21, + LongDouble = 22, + Float128 = 23, + IntPtr = 24 } public enum ExceptionSpecType diff --git a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs index b169f744..965bc021 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs @@ -253,25 +253,26 @@ namespace CppSharp Bool = 2, WideChar = 3, Char = 4, - UChar = 5, - Char16 = 6, - Char32 = 7, - Short = 8, - UShort = 9, - Int = 10, - UInt = 11, - Long = 12, - ULong = 13, - LongLong = 14, - ULongLong = 15, - Int128 = 16, - UInt128 = 17, - Half = 18, - Float = 19, - Double = 20, - LongDouble = 21, - Float128 = 22, - IntPtr = 23 + SChar = 5, + UChar = 6, + Char16 = 7, + Char32 = 8, + Short = 9, + UShort = 10, + Int = 11, + UInt = 12, + Long = 13, + ULong = 14, + LongLong = 15, + ULongLong = 16, + Int128 = 17, + UInt128 = 18, + Half = 19, + Float = 20, + Double = 21, + LongDouble = 22, + Float128 = 23, + IntPtr = 24 } public enum ExceptionSpecType diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs index 1560124f..db819292 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs @@ -253,25 +253,26 @@ namespace CppSharp Bool = 2, WideChar = 3, Char = 4, - UChar = 5, - Char16 = 6, - Char32 = 7, - Short = 8, - UShort = 9, - Int = 10, - UInt = 11, - Long = 12, - ULong = 13, - LongLong = 14, - ULongLong = 15, - Int128 = 16, - UInt128 = 17, - Half = 18, - Float = 19, - Double = 20, - LongDouble = 21, - Float128 = 22, - IntPtr = 23 + SChar = 5, + UChar = 6, + Char16 = 7, + Char32 = 8, + Short = 9, + UShort = 10, + Int = 11, + UInt = 12, + Long = 13, + ULong = 14, + LongLong = 15, + ULongLong = 16, + Int128 = 17, + UInt128 = 18, + Half = 19, + Float = 20, + Double = 21, + LongDouble = 22, + Float128 = 23, + IntPtr = 24 } public enum ExceptionSpecType diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs index 01c63de4..573c3702 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs @@ -253,25 +253,26 @@ namespace CppSharp Bool = 2, WideChar = 3, Char = 4, - UChar = 5, - Char16 = 6, - Char32 = 7, - Short = 8, - UShort = 9, - Int = 10, - UInt = 11, - Long = 12, - ULong = 13, - LongLong = 14, - ULongLong = 15, - Int128 = 16, - UInt128 = 17, - Half = 18, - Float = 19, - Double = 20, - LongDouble = 21, - Float128 = 22, - IntPtr = 23 + SChar = 5, + UChar = 6, + Char16 = 7, + Char32 = 8, + Short = 9, + UShort = 10, + Int = 11, + UInt = 12, + Long = 13, + ULong = 14, + LongLong = 15, + ULongLong = 16, + Int128 = 17, + UInt128 = 18, + Half = 19, + Float = 20, + Double = 21, + LongDouble = 22, + Float128 = 23, + IntPtr = 24 } public enum ExceptionSpecType diff --git a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs index 87596a10..9f309eda 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs @@ -253,25 +253,26 @@ namespace CppSharp Bool = 2, WideChar = 3, Char = 4, - UChar = 5, - Char16 = 6, - Char32 = 7, - Short = 8, - UShort = 9, - Int = 10, - UInt = 11, - Long = 12, - ULong = 13, - LongLong = 14, - ULongLong = 15, - Int128 = 16, - UInt128 = 17, - Half = 18, - Float = 19, - Double = 20, - LongDouble = 21, - Float128 = 22, - IntPtr = 23 + SChar = 5, + UChar = 6, + Char16 = 7, + Char32 = 8, + Short = 9, + UShort = 10, + Int = 11, + UInt = 12, + Long = 13, + ULong = 14, + LongLong = 15, + ULongLong = 16, + Int128 = 17, + UInt128 = 18, + Half = 19, + Float = 20, + Double = 21, + LongDouble = 22, + Float128 = 23, + IntPtr = 24 } public enum ExceptionSpecType diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index fb405eec..c324903d 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -1875,7 +1875,7 @@ static PrimitiveType WalkBuiltinType(const clang::BuiltinType* Builtin) case clang::BuiltinType::Void: return PrimitiveType::Void; case clang::BuiltinType::Bool: return PrimitiveType::Bool; - case clang::BuiltinType::SChar: + case clang::BuiltinType::SChar: return PrimitiveType::SChar; case clang::BuiltinType::Char_S: return PrimitiveType::Char; case clang::BuiltinType::UChar: diff --git a/src/Generator/Generators/CLI/CLIMarshal.cs b/src/Generator/Generators/CLI/CLIMarshal.cs index ed2485da..e7fa0d0e 100644 --- a/src/Generator/Generators/CLI/CLIMarshal.cs +++ b/src/Generator/Generators/CLI/CLIMarshal.cs @@ -213,6 +213,7 @@ namespace CppSharp.Generators.CLI case PrimitiveType.Bool: case PrimitiveType.Char: case PrimitiveType.WideChar: + case PrimitiveType.SChar: case PrimitiveType.UChar: case PrimitiveType.Short: case PrimitiveType.UShort: diff --git a/src/Generator/Generators/CLI/CLITypePrinter.cs b/src/Generator/Generators/CLI/CLITypePrinter.cs index 52cbaa1a..f3f19874 100644 --- a/src/Generator/Generators/CLI/CLITypePrinter.cs +++ b/src/Generator/Generators/CLI/CLITypePrinter.cs @@ -208,6 +208,7 @@ namespace CppSharp.Generators.CLI case PrimitiveType.Char32: case PrimitiveType.WideChar: return "System::Char"; case PrimitiveType.Char: return Options.MarshalCharAsManagedChar ? "System::Char" : "char"; + case PrimitiveType.SChar: return "signed char"; case PrimitiveType.UChar: return "unsigned char"; case PrimitiveType.Short: return "short"; case PrimitiveType.UShort: return "unsigned short"; diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs index 181963e3..22135516 100644 --- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs @@ -582,6 +582,7 @@ namespace CppSharp.Generators.CSharp ContextKind != CSharpTypePrinterContextKind.Native ? "char" : "sbyte"; + case PrimitiveType.SChar: return "sbyte"; case PrimitiveType.UChar: return "byte"; case PrimitiveType.Short: case PrimitiveType.UShort: diff --git a/src/Parser/ASTConverter.cs b/src/Parser/ASTConverter.cs index 5b73b42f..916f37cd 100644 --- a/src/Parser/ASTConverter.cs +++ b/src/Parser/ASTConverter.cs @@ -730,6 +730,8 @@ namespace CppSharp return AST.PrimitiveType.Char; case PrimitiveType.UChar: return AST.PrimitiveType.UChar; + case PrimitiveType.SChar: + return AST.PrimitiveType.SChar; case PrimitiveType.Char16: return AST.PrimitiveType.Char16; case PrimitiveType.Char32: