Browse Source

Merge pull request #251 from tomba/misc-improvements

Misc improvements
pull/253/head
João Matos 11 years ago
parent
commit
f291eaff04
  1. 4
      build/Helpers.lua
  2. 2
      build/Tests.lua
  3. 6
      build/premake4.lua
  4. 0
      build/premake5-osx
  5. 2
      src/AST/Type.cs
  6. 0
      src/CppParser/Bindings/CSharp/i686-pc-win32/AST.cs
  7. 0
      src/CppParser/Bindings/CSharp/i686-pc-win32/CppParser.cs
  8. 0
      src/CppParser/Bindings/CSharp/i686-pc-win32/Target.cs
  9. 7
      src/CppParser/Bindings/ParserGen.cs
  10. 6
      src/CppParser/Bindings/premake4.lua
  11. 1
      src/CppParser/Helpers.h
  12. 2
      src/Generator.Tests/Generator.Tests.lua
  13. 14
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  14. 7
      src/Generator/Options.cs

4
build/Helpers.lua

@ -31,6 +31,10 @@ function os.is_windows() @@ -31,6 +31,10 @@ function os.is_windows()
return os.is("windows")
end
function os.is_linux()
return os.is("linux")
end
function string.starts(str, start)
return string.sub(str, 1, string.len(start)) == start
end

2
build/Tests.lua

@ -92,7 +92,7 @@ function LinkNUnit() @@ -92,7 +92,7 @@ function LinkNUnit()
links
{
"NUnit.Framework",
"nunit.framework",
"NSubstitute"
}
end

6
build/premake4.lua

@ -16,9 +16,8 @@ solution "CppSharp" @@ -16,9 +16,8 @@ solution "CppSharp"
flags { common_flags }
location (builddir)
objdir (builddir .. "/obj/")
objdir (path.join(builddir, "obj"))
targetdir (libdir)
libdirs { libdir }
debugdir (bindir)
-- startproject "Generator"
@ -31,9 +30,6 @@ solution "CppSharp" @@ -31,9 +30,6 @@ solution "CppSharp"
configuration "windows"
defines { "WINDOWS" }
configuration "x64"
defines { "IS_64_BIT" }
configuration {}
if string.starts(action, "vs") then

0
build/premake5 → build/premake5-osx

2
src/AST/Type.cs

@ -232,7 +232,7 @@ namespace CppSharp.AST @@ -232,7 +232,7 @@ namespace CppSharp.AST
RVReference
}
public new bool IsReference
public bool IsReference
{
get
{

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

0
src/CppParser/Bindings/CSharp/CppParser.cs → src/CppParser/Bindings/CSharp/i686-pc-win32/CppParser.cs

0
src/CppParser/Bindings/CSharp/Target.cs → src/CppParser/Bindings/CSharp/i686-pc-win32/Target.cs

7
src/CppParser/Bindings/ParserGen.cs

@ -121,12 +121,12 @@ namespace CppSharp @@ -121,12 +121,12 @@ namespace CppSharp
public static void Main(string[] args)
{
Console.WriteLine("Generating the C++/CLI parser bindings...");
Console.WriteLine("Generating the C++/CLI parser bindings for Windows...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CLI, "i686-pc-win32",
CppAbi.Microsoft));
Console.WriteLine();
Console.WriteLine("Generating the C# parser bindings...");
Console.WriteLine("Generating the C# parser bindings for Windows...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "i686-pc-win32",
CppAbi.Microsoft));
@ -136,6 +136,7 @@ namespace CppSharp @@ -136,6 +136,7 @@ namespace CppSharp
// of libcxx since the one provided by the Mac SDK is not compatible with a recent
// Clang frontend that we use to parse it.
Console.WriteLine("Generating the C# parser bindings for OSX...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "i686-apple-darwin12.4.0",
CppAbi.Itanium));
}
@ -156,7 +157,7 @@ namespace CppSharp @@ -156,7 +157,7 @@ namespace CppSharp
public override bool VisitFunctionDecl(Function function)
{
if (function.Ignore)
if (function.GenerationKind == GenerationKind.None)
return false;
if (function.Parameters.Any(param => IsStdType(param.QualifiedType)))

6
src/CppParser/Bindings/premake4.lua

@ -26,10 +26,12 @@ project "CppSharp.Parser.CSharp" @@ -26,10 +26,12 @@ project "CppSharp.Parser.CSharp"
links { "CppSharp.Runtime" }
if os.is_osx() then
if os.is_windows() then
files { "CSharp/i686-pc-win32/**.cs" }
elseif os.is_osx() then
files { "CSharp/i686-apple-darwin12.4.0/**.cs" }
else
files { "CSharp/*.cs" }
print "Unknown architecture"
end
configuration ""

1
src/CppParser/Helpers.h

@ -56,3 +56,4 @@ @@ -56,3 +56,4 @@
#define DEF_STRING(klass, name) \
const char* klass::get##name() { return name.c_str(); } \
void klass::set##name(const char* s) { name = s; }

2
src/Generator.Tests/Generator.Tests.lua

@ -20,6 +20,6 @@ project "CppSharp.Generator.Tests" @@ -20,6 +20,6 @@ project "CppSharp.Generator.Tests"
"CppSharp",
"CppSharp.AST",
"CppSharp.Generator",
"NUnit.Framework",
"nunit.framework",
"NSubstitute"
}

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

@ -1404,14 +1404,14 @@ namespace CppSharp.Generators.CSharp @@ -1404,14 +1404,14 @@ namespace CppSharp.Generators.CSharp
var vfptr = @class.Layout.VFTables[tableIndex];
var size = vfptr.Layout.Components.Count;
WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});",
tableIndex, size, Driver.Options.Is32Bit ? 4 : 8);
tableIndex, size, Driver.TargetInfo.PointerWidth / 8);
WriteLine("_NewVTables[{0}] = vfptr{0}.ToPointer();", tableIndex);
for (int entryIndex = 0; entryIndex < vfptr.Layout.Components.Count; entryIndex++)
{
var entry = vfptr.Layout.Components[entryIndex];
var offsetInBytes = VTables.GetVTableComponentIndex(@class, entry)
* (Driver.Options.Is32Bit ? 4 : 8);
* (Driver.TargetInfo.PointerWidth / 8);
if (entry.Ignore)
WriteLine("*(void**)(vfptr{0} + {1}) = *(void**)(native->vfptr{0} + {1});",
tableIndex, offsetInBytes);
@ -1434,14 +1434,14 @@ namespace CppSharp.Generators.CSharp @@ -1434,14 +1434,14 @@ namespace CppSharp.Generators.CSharp
// reserve space for the offset-to-top and RTTI pointers as well
var size = entries.Count;
WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});", 0, size, Driver.Options.Is32Bit ? 4 : 8);
WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});", 0, size, Driver.TargetInfo.PointerWidth / 8);
WriteLine("_NewVTables[0] = vfptr0.ToPointer();");
for (int i = 0; i < entries.Count; i++)
{
var entry = entries[i];
var offsetInBytes = VTables.GetVTableComponentIndex(@class, entry)
* (Driver.Options.Is32Bit ? 4 : 8);
* (Driver.TargetInfo.PointerWidth / 8);
if (entry.Ignore)
WriteLine("*(void**)(vfptr0 + {0}) = *(void**)(native->vfptr0 + {0});", offsetInBytes);
else
@ -2104,17 +2104,17 @@ namespace CppSharp.Generators.CSharp @@ -2104,17 +2104,17 @@ namespace CppSharp.Generators.CSharp
private void GenerateVirtualTableFunctionCall(Method method, Class @class)
{
string delegateId;
Write(GetVirtualCallDelegate(method, @class, Driver.Options.Is32Bit, out delegateId));
Write(GetVirtualCallDelegate(method, @class, out delegateId));
GenerateFunctionCall(delegateId, method.Parameters, method);
}
public string GetVirtualCallDelegate(Method method, Class @class,
bool is32Bit, out string delegateId)
out string delegateId)
{
var virtualCallBuilder = new StringBuilder();
var i = VTables.GetVTableIndex(method, @class);
virtualCallBuilder.AppendFormat("void* slot = *(void**) ((({0}.Internal*) {1})->vfptr0 + {2} * {3});",
@class.BaseClass.Name, Helpers.InstanceIdentifier, i, is32Bit ? 4 : 8);
@class.BaseClass.Name, Helpers.InstanceIdentifier, i, Driver.TargetInfo.PointerWidth / 8);
virtualCallBuilder.AppendLine();
string @delegate = GetVTableMethodDelegateName((Method) method.OriginalFunction);

7
src/Generator/Options.cs

@ -44,11 +44,6 @@ namespace CppSharp @@ -44,11 +44,6 @@ namespace CppSharp
Encoding = Encoding.ASCII;
CodeFiles = new List<string>();
Is32Bit = true;
#if IS_64_BIT
Is32Bit = false;
#endif
}
// General options
@ -173,8 +168,6 @@ namespace CppSharp @@ -173,8 +168,6 @@ namespace CppSharp
get { return GeneratorKind == GeneratorKind.CLI; }
}
public bool Is32Bit { get; set; }
public List<string> CodeFiles { get; private set; }
public readonly List<string> DependentNameSpaces = new List<string>();
public bool MarshalCharAsManagedChar { get; set; }

Loading…
Cancel
Save