CppParser: fix memory corruption issue

There are multiple places in the parser which do something similar to
this:

Foo *ptr = 0;

if (...) {
    Foo val = ...;
    ptr = &val;
}

func(ptr);

In other words, the code takes a pointer to a local variable, and the
pointer is used even after the local variable's scope has ended.

This causes a crash on Linux. For some reason this works fine on Windows
+ Visual studio.

This patchs moves the variable ("val" in the above example) to outer
scopes, so that its life time is extended to cover the use.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
CppParser: fix warning about RawCommentKind

Fix the following warning by renaming RawComment::RawCommentKind to
Kind.

In file included from ../../../src/CppParser/AST.cpp:8:0:
../../../src/CppParser/AST.h:780:20: warning: declaration of ‘CppSharp::CppParser::AST::RawCommentKind CppSharp::CppParser::AST::RawComment::RawCommentKind’ [-fpermissive]
     RawCommentKind RawCommentKind;
                    ^
../../../src/CppParser/AST.h:765:13: warning: changes meaning of ‘RawCommentKind’ from ‘enum class CppSharp::CppParser::AST::RawCommentKind’ [-fpermissive]
 enum struct RawCommentKind
             ^

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
CppParser: fix warning about FullComment

Fix the following warning by renaming RawComment::FullComment to
FullCommentBlock.

In file included from ../../../src/CppParser/AST.cpp:8:0:
../../../src/CppParser/AST.h:783:18: warning: declaration of ‘CppSharp::CppParser::AST::FullComment* CppSharp::CppParser::AST::RawComment::FullComment’ [-fpermissive]
     FullComment* FullComment;
                  ^
../../../src/CppParser/AST.h:760:15: warning: changes meaning of ‘FullComment’ from ‘struct CppSharp::CppParser::AST::FullComment’ [-fpermissive]
 struct CS_API FullComment : public Comment
               ^

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
CppParser: fix warning about Parser

Fix the following warning by renaming ParserResult::Parser to
CodeParser.

In file included from ../../../src/CppParser/Parser.h:16:0,
                 from ../../../src/CppParser/Comments.cpp:8:
../../../src/CppParser/CppParser.h:86:13: warning: declaration of ‘CppSharp::CppParser::Parser* CppSharp::CppParser::ParserResult::Parser’ [-fpermissive]
     Parser* Parser;
             ^
../../../src/CppParser/CppParser.h:73:8: warning: changes meaning of ‘Parser’ from ‘struct CppSharp::CppParser::Parser’ [-fpermissive]
 struct Parser;
        ^

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
Update windows bindings
build: remove -fpermissive from non-VS builds

Now that the warnings have been fixed, we no longer need -fpermissive to
compile CppParser with gcc.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
Merge pull request #261 from tomba/parser-mem-fix

CppParser: fix memory corruption issue
Merge pull request #262 from tomba/fix-warnings

Fix CppParser compile warnings
Updated the OSX parser bindings.
Remove PrimitiveTypeExtensions.ConvertToType

C++ types cannot be converted to C# types without knowing details of the
target (e.g. what is the size of "long") and
PrimitiveTypeExtensions.ConvertToType does not handle that correctly.

However, ConvertToType is not used anywhere, so let's just remove it so
that no one will use the method.

We could also fix the method, but it's an extension method for
PrimitiveType, and I don't think such an extension method should be used
for the task, as you would also need to pass it information about the
target system.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
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>
Fix CLITypePrinter's use of Long and ULong

CLITypePrinter outputs C++ code, so the proper type to be written for
Long and ULong are "long" and "unsigned long", not "int" and "unsigned
int".

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
Fix CppTypePrinter use of Long and ULong

CppTypePrinter outputs C++ code, so the proper type to be written for
Long and ULong are "long" and "unsigned long", not "int" and "unsigned
int".

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
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 <tomi.valkeinen@iki.fi>
Rename PrimitiveType Int16 and UInt16 to Short and UShort

As enum PrimitiveType is supposed to represent C++ types, having Int16
and UInt16 there is not correct.

This patch renames those values to Short and UShort.

This doesn't change the behavior, but makes it clearer that the types
for 'short' and 'unsigned short' are not necessarily 16 bits.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
Rename PrimitiveType Int64 and UInt64 to LongLong and ULongLong

As enum PrimitiveType is supposed to represent C++ types, having Int64
and UInt64 there is not correct.

This patch renames those values to LongLong and ULongLong.

This doesn't change the behavior, but makes it clearer that the types
for 'long long' and 'unsigned long long' are not necessarily 64 bits.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
Rename PrimitiveType Int32 and UInt32 to Int and UInt

As enum PrimitiveType is supposed to represent C++ types, having Int32
and UInt32 there is not correct.

This patch renames those values to Int and UInt.

This doesn't change the behavior, but makes it clearer that the types
for 'int' and 'unsigned int' are not necessarily 32 bits.
Pass Driver to CSharpTypePrinter

We need Driver.TargeInfo in CSharpTypePrinter so that we can find out the
widths of the integer types.

This patch changes CSharpTypePrinter to get the Driver reference in its
constructor. As all the other constructor parameters can be found from the
Driver reference, we can remove all the other parameters.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
CSharpTypePrinter: use type width to convert C++ types to C# types

We need to convert C++ integer types to C# types using the TargetInfo, as the
type bitwidths depend on the target architecture.

This fixes the main 64bit issue, which is that on 64bit Linux the current code
converts C++'s long to System.Int32, instead of System.Int64.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
Update CppParser bindings

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>