Skip to content

Commit 1a73c12

Browse files
authored
Merge pull request #1022 from rokups/fixes
Multiple fixes
2 parents e8e727d + b90fb52 commit 1a73c12

File tree

16 files changed

+127
-141
lines changed

16 files changed

+127
-141
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: cpp
2+
sudo: required
23

34
os:
45
- linux

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ os: Visual Studio 2017
2525

2626
platform:
2727
- x86
28+
- x64
2829

2930
configuration:
3031
- Release

build/Compile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ else
1616
BUILD_CONF=release_x86;
1717
fi
1818

19-
$PREMAKE --file=$CUR_DIR/premake5.lua gmake
19+
$PREMAKE --file=$CUR_DIR/premake5.lua gmake "$@"
2020
config=$BUILD_CONF make -C $CUR_DIR/gmake/
2121

2222
BUILD_CONF_DIR="$(tr '[:lower:]' '[:upper:]' <<< ${BUILD_CONF:0:1})${BUILD_CONF:1}"

build/Helpers.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ function SetupNativeProject()
8484
buildoptions { msvc_buildflags }
8585
defines { msvc_cpp_defines }
8686

87-
filter { "action:gmake" }
87+
filter { "system:linux" }
8888
buildoptions { gcc_buildflags }
89+
links { "stdc++" }
8990

9091
filter { "system:macosx", "language:C++" }
9192
buildoptions { gcc_buildflags, "-stdlib=libc++" }

src/CLI/Generator.cs

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
using CppSharp.Passes;
55
using System;
66
using System.Collections.Generic;
7+
using System.Diagnostics;
78
using System.IO;
89
using System.Linq;
910
using System.Text;
11+
using System.Text.RegularExpressions;
1012
using CppAbi = CppSharp.Parser.AST.CppAbi;
1113

1214
namespace CppSharp
@@ -193,34 +195,7 @@ public void Setup(Driver driver)
193195

194196
private void SetupLinuxOptions(ParserOptions parserOptions)
195197
{
196-
parserOptions.MicrosoftMode = false;
197-
parserOptions.NoBuiltinIncludes = true;
198-
199-
var headersPath = string.Empty;
200-
201-
// Search for the available GCC versions on the provided headers.
202-
var versions = Directory.EnumerateDirectories(Path.Combine(headersPath, "usr/include/c++"));
203-
204-
if (versions.Count() == 0)
205-
throw new Exception("No valid GCC version found on system include paths");
206-
207-
string gccVersionPath = versions.First();
208-
string gccVersion = gccVersionPath.Substring(gccVersionPath.LastIndexOf(Path.DirectorySeparatorChar) + 1);
209-
210-
string[] systemIncludeDirs = {
211-
Path.Combine("usr", "include", "c++", gccVersion),
212-
Path.Combine("usr", "include", "x86_64-linux-gnu", "c++", gccVersion),
213-
Path.Combine("usr", "include", "c++", gccVersion, "backward"),
214-
Path.Combine("usr", "lib", "gcc", "x86_64-linux-gnu", gccVersion, "include"),
215-
Path.Combine("usr", "lib", "gcc", "x86_64-pc-linux-gnu", gccVersion, "include"),
216-
Path.Combine("usr", "include", "x86_64-linux-gnu"),
217-
Path.Combine("usr", "include", "x86_64-pc-linux-gnu"),
218-
Path.Combine("usr", "include")
219-
};
220-
221-
foreach (var dir in systemIncludeDirs)
222-
parserOptions.AddSystemIncludeDirs(Path.Combine(headersPath, dir));
223-
198+
parserOptions.SetupLinux();
224199
parserOptions.AddDefines("_GLIBCXX_USE_CXX11_ABI=" + (options.Cpp11ABI ? "1" : "0"));
225200
}
226201

src/CppParser/ParserGen/ParserGen.cs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,32 +98,7 @@ private void SetupLinuxOptions(ParserOptions options)
9898

9999
var headersPath = Platform.IsLinux ? string.Empty :
100100
Path.Combine(GetSourceDirectory("build"), "headers", "x86_64-linux-gnu");
101-
102-
// Search for the available GCC versions on the provided headers.
103-
var versions = Directory.EnumerateDirectories(Path.Combine(headersPath,
104-
"usr/include/c++"));
105-
106-
if (versions.Count() == 0)
107-
throw new Exception("No valid GCC version found on system include paths");
108-
109-
string gccVersionPath = versions.First();
110-
string gccVersion = gccVersionPath.Substring(
111-
gccVersionPath.LastIndexOf(Path.DirectorySeparatorChar) + 1);
112-
113-
string[] systemIncludeDirs = {
114-
Path.Combine("usr", "include", "c++", gccVersion),
115-
Path.Combine("usr", "include", "x86_64-linux-gnu", "c++", gccVersion),
116-
Path.Combine("usr", "include", "c++", gccVersion, "backward"),
117-
Path.Combine("usr", "lib", "gcc", "x86_64-linux-gnu", gccVersion, "include"),
118-
Path.Combine("usr", "lib", "gcc", "x86_64-pc-linux-gnu", gccVersion, "include"),
119-
Path.Combine("usr", "include", "x86_64-linux-gnu"),
120-
Path.Combine("usr", "include", "x86_64-pc-linux-gnu"),
121-
Path.Combine("usr", "include")
122-
};
123-
124-
foreach (var dir in systemIncludeDirs)
125-
options.AddSystemIncludeDirs(Path.Combine(headersPath, dir));
126-
101+
options.SetupLinux(headersPath);
127102
options.AddDefines("_GLIBCXX_USE_CXX11_ABI=" + (IsGnuCpp11Abi ? "1" : "0"));
128103
}
129104

@@ -237,4 +212,4 @@ public static void Main(string[] args)
237212
}
238213
}
239214
}
240-
}
215+
}

src/Generator.Tests/GeneratorTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public virtual void Setup(Driver driver)
2828
options.GeneratorKind = kind;
2929
options.OutputDir = Path.Combine(GetOutputDirectory(), "gen", name);
3030
options.Quiet = true;
31+
options.GenerateDebugOutput = true;
3132
var testModule = options.AddModule(name);
3233
testModule.SharedLibraryName = $"{name}.Native";
3334

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,27 @@ public override bool VisitDeclContext(DeclarationContext context)
203203
return true;
204204
}
205205

206+
private IEnumerable<Class> EnumerateClasses()
207+
{
208+
foreach (var tu in TranslationUnits)
209+
{
210+
foreach (var cls in EnumerateClasses(tu))
211+
yield return cls;
212+
}
213+
}
214+
215+
private IEnumerable<Class> EnumerateClasses(DeclarationContext context)
216+
{
217+
foreach (var cls in context.Classes)
218+
yield return cls;
219+
220+
foreach (var ns in context.Namespaces)
221+
{
222+
foreach (var cls in EnumerateClasses(ns))
223+
yield return cls;
224+
}
225+
}
226+
206227
void GenerateNamespaceFunctionsAndVariables(DeclarationContext context)
207228
{
208229
var hasGlobalVariables = !(context is Class) && context.Variables.Any(
@@ -213,7 +234,12 @@ void GenerateNamespaceFunctionsAndVariables(DeclarationContext context)
213234

214235
PushBlock(BlockKind.Functions);
215236
var parentName = SafeIdentifier(context.TranslationUnit.FileNameWithoutExtension);
216-
WriteLine("public unsafe partial class {0}", parentName);
237+
238+
var keyword = "class";
239+
var classes = EnumerateClasses().ToList();
240+
if (classes.FindAll(cls => cls.IsValueType && cls.Name == parentName && context.QualifiedLogicalName == cls.Namespace.QualifiedLogicalName).Any())
241+
keyword = "struct";
242+
WriteLine($"public unsafe partial {keyword} {parentName}");
217243
WriteStartBraceIndent();
218244

219245
PushBlock(BlockKind.InternalsClass);
@@ -3233,4 +3259,4 @@ internal class SymbolNotFoundException : Exception
32333259
public SymbolNotFoundException(string msg) : base(msg)
32343260
{}
32353261
}
3236-
}
3262+
}

src/Generator/Generators/CodeGenerator.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ protected CodeGenerator(BindingContext context, IEnumerable<TranslationUnit> uni
6161

6262
public abstract void Process();
6363

64-
public override string Generate()
65-
{
66-
if (Options.IsCSharpGenerator && Options.CompileCode && !Options.GenerateDebugOutput)
67-
return base.GenerateUnformatted();
68-
69-
return base.Generate();
70-
}
71-
7264
public virtual void GenerateFilePreamble(CommentKind kind, string generatorName = "CppSharp")
7365
{
7466
var lines = new List<string>
@@ -91,16 +83,19 @@ public virtual void GenerateFilePreamble(CommentKind kind, string generatorName
9183
public virtual void GenerateDeclarationCommon(Declaration decl)
9284
{
9385
if (decl.Comment != null)
94-
{
9586
GenerateComment(decl.Comment);
96-
GenerateDebug(decl);
97-
}
87+
88+
GenerateDebug(decl);
9889
}
9990

10091
public virtual void GenerateDebug(Declaration decl)
10192
{
10293
if (Options.GenerateDebugOutput && !string.IsNullOrWhiteSpace(decl.DebugText))
103-
WriteLine("// DEBUG: " + decl.DebugText);
94+
{
95+
var debugText = decl.DebugText;
96+
debugText = Regex.Replace(debugText.Trim(), "\r?\n", "\n// DEBUG: ");
97+
WriteLine($"// DEBUG: {debugText}");
98+
}
10499
}
105100

106101
#endregion

src/Generator/Passes/CleanInvalidDeclNamesPass.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public override bool VisitDeclaration(Declaration decl)
5353
(method == null || method.Kind == CXXMethodKind.Normal))
5454
decl.Name = CheckName(decl.Name);
5555

56-
StringHelpers.CleanupText(ref decl.DebugText);
5756
return true;
5857
}
5958

0 commit comments

Comments
 (0)