Browse Source

Threw an exception when there are parsing errors, and handled it in the test clients.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/600/head
Dimitar Dobrev 10 years ago
parent
commit
01e872b30d
  1. 15
      examples/SDL/SDL.cs
  2. 12
      src/Core/Parser/ParserException.cs
  3. 73
      src/CppParser/Bindings/ParserGen.cs
  4. 16
      src/CppParser/Bootstrap/Bootstrap.cs
  5. 3
      src/Generator/Driver.cs
  6. 15
      tests/CLI/CLI.cs
  7. 12
      tests/CSharp/CSharp.cs
  8. 15
      tests/Common/Common.cs
  9. 13
      tests/Encodings/Encodings.cs
  10. 12
      tests/NamespacesBase/NamespacesBase.cs
  11. 15
      tests/NamespacesDerived/NamespacesDerived.cs
  12. 13
      tests/StandardLib/StandardLib.cs
  13. 15
      tests/TypeMaps/TypeMaps.cs
  14. 15
      tests/VTables/VTables.cs

15
examples/SDL/SDL.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using CppSharp.AST;
using System;
using CppSharp.AST;
using CppSharp.Passes;
namespace CppSharp
@ -66,9 +67,17 @@ namespace CppSharp @@ -66,9 +67,17 @@ namespace CppSharp
static class Program
{
public static void Main(string[] args)
public static int Main(string[] args)
{
ConsoleDriver.Run(new SDL());
try
{
ConsoleDriver.Run(new SDL());
return 0;
}
catch (ArgumentException)
{
return 1;
}
}
}
}

12
src/Core/Parser/ParserException.cs

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
using System;
namespace CppSharp
{
public class ParserException : Exception
{
public ParserException(string message)
: base(message)
{
}
}
}

73
src/CppParser/Bindings/ParserGen.cs

@ -149,42 +149,51 @@ namespace CppSharp @@ -149,42 +149,51 @@ namespace CppSharp
{
}
public static void Main(string[] args)
public static int Main(string[] args)
{
if (Platform.IsWindows)
try
{
Console.WriteLine("Generating the C++/CLI parser bindings for Windows...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CLI, "i686-pc-win32-msvc",
CppAbi.Microsoft));
Console.WriteLine();
Console.WriteLine("Generating the C# parser bindings for Windows...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "i686-pc-win32-msvc",
CppAbi.Microsoft));
Console.WriteLine();
if (Platform.IsWindows)
{
Console.WriteLine("Generating the C++/CLI parser bindings for Windows...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CLI, "i686-pc-win32-msvc",
CppAbi.Microsoft));
Console.WriteLine();
Console.WriteLine("Generating the C# parser bindings for Windows...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "i686-pc-win32-msvc",
CppAbi.Microsoft));
Console.WriteLine();
}
var osxHeadersPath = Path.Combine(GetSourceDirectory("build"), @"headers\osx");
if (Directory.Exists(osxHeadersPath) || Platform.IsMacOS)
{
Console.WriteLine("Generating the C# parser bindings for OSX...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "i686-apple-darwin12.4.0",
CppAbi.Itanium));
Console.WriteLine();
Console.WriteLine("Generating the C# parser bindings for OSX...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "x86_64-apple-darwin12.4.0",
CppAbi.Itanium));
Console.WriteLine();
}
if (Directory.Exists(LINUX_INCLUDE_BASE_DIR))
{
Console.WriteLine("Generating the C# parser bindings for Linux...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "x86_64-linux-gnu",
CppAbi.Itanium));
Console.WriteLine();
}
return 0;
}
var osxHeadersPath = Path.Combine(GetSourceDirectory("build"), @"headers\osx");
if (Directory.Exists(osxHeadersPath) || Platform.IsMacOS)
{
Console.WriteLine("Generating the C# parser bindings for OSX...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "i686-apple-darwin12.4.0",
CppAbi.Itanium));
Console.WriteLine();
Console.WriteLine("Generating the C# parser bindings for OSX...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "x86_64-apple-darwin12.4.0",
CppAbi.Itanium));
Console.WriteLine();
}
if (Directory.Exists(LINUX_INCLUDE_BASE_DIR))
catch (ArgumentException)
{
Console.WriteLine("Generating the C# parser bindings for Linux...");
ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "x86_64-linux-gnu",
CppAbi.Itanium));
Console.WriteLine();
return 1;
}
}
}

16
src/CppParser/Bootstrap/Bootstrap.cs

@ -75,11 +75,19 @@ namespace CppSharp @@ -75,11 +75,19 @@ namespace CppSharp
{
}
public static void Main(string[] args)
public static int Main(string[] args)
{
Console.WriteLine("Generating parser bootstrap code...");
ConsoleDriver.Run(new Bootstrap());
Console.WriteLine();
try
{
Console.WriteLine("Generating parser bootstrap code...");
ConsoleDriver.Run(new Bootstrap());
Console.WriteLine();
return 0;
}
catch (ArgumentException)
{
return 1;
}
}
}

3
src/Generator/Driver.cs

@ -14,7 +14,6 @@ using CppSharp.Types; @@ -14,7 +14,6 @@ using CppSharp.Types;
using Microsoft.CSharp;
using CppSharp.Parser;
using System.CodeDom;
using System;
namespace CppSharp
{
@ -475,7 +474,7 @@ namespace CppSharp @@ -475,7 +474,7 @@ namespace CppSharp
if (!driver.ParseCode())
{
Log.Error("CppSharp has encountered an error while parsing code.");
return;
throw new ParserException("Error parsing code.");
}
if (!options.Quiet)

15
tests/CLI/CLI.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using CppSharp.AST;
using System;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Utils;
@ -22,9 +23,17 @@ namespace CppSharp.Tests @@ -22,9 +23,17 @@ namespace CppSharp.Tests
{
}
public static void Main(string[] args)
public static int Main(string[] args)
{
ConsoleDriver.Run(new CLITestsGenerator(GeneratorKind.CLI));
try
{
ConsoleDriver.Run(new CLITestsGenerator(GeneratorKind.CLI));
return 0;
}
catch (ArgumentException)
{
return 1;
}
}
}
}

12
tests/CSharp/CSharp.cs

@ -157,9 +157,17 @@ namespace CppSharp.Tests @@ -157,9 +157,17 @@ namespace CppSharp.Tests
RenameCasePattern.UpperCamelCase).VisitLibrary(driver.ASTContext);
}
public static void Main(string[] args)
public static int Main(string[] args)
{
ConsoleDriver.Run(new CSharpTestsGenerator(GeneratorKind.CSharp));
try
{
ConsoleDriver.Run(new CSharpTestsGenerator(GeneratorKind.CSharp));
return 0;
}
catch (ArgumentException)
{
return 1;
}
}
}
}

15
tests/Common/Common.cs

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
using System;
using System.Linq;
using CppSharp.AST;
using CppSharp.Generators;
@ -78,10 +79,18 @@ namespace CppSharp.Tests @@ -78,10 +79,18 @@ namespace CppSharp.Tests
e => string.IsNullOrEmpty(e.Name)).Name = "RenamedEmptyEnum";
}
public static void Main(string[] args)
public static int Main(string[] args)
{
ConsoleDriver.Run(new CommonTestsGenerator(GeneratorKind.CLI));
ConsoleDriver.Run(new CommonTestsGenerator(GeneratorKind.CSharp));
try
{
ConsoleDriver.Run(new CommonTestsGenerator(GeneratorKind.CLI));
ConsoleDriver.Run(new CommonTestsGenerator(GeneratorKind.CSharp));
return 0;
}
catch (ArgumentException)
{
return 1;
}
}
}
}

13
tests/Encodings/Encodings.cs

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
using System;
using System.Text;
using CppSharp.AST;
using CppSharp.Generators;
@ -22,9 +23,17 @@ namespace CppSharp.Tests @@ -22,9 +23,17 @@ namespace CppSharp.Tests
}
public static void Main(string[] args)
public static int Main(string[] args)
{
ConsoleDriver.Run(new EncodingsTestsGenerator(GeneratorKind.CSharp));
try
{
ConsoleDriver.Run(new EncodingsTestsGenerator(GeneratorKind.CSharp));
return 0;
}
catch (ArgumentException)
{
return 1;
}
}
}
}

12
tests/NamespacesBase/NamespacesBase.cs

@ -33,9 +33,17 @@ namespace CppSharp.Tests @@ -33,9 +33,17 @@ namespace CppSharp.Tests
}
public class NamespacesBase {
public static void Main(string[] args)
public static int Main(string[] args)
{
ConsoleDriver.Run(new NamespacesBaseTests(GeneratorKind.CSharp));
try
{
ConsoleDriver.Run(new NamespacesBaseTests(GeneratorKind.CSharp));
return 0;
}
catch (ArgumentException)
{
return 1;
}
}
}
}

15
tests/NamespacesDerived/NamespacesDerived.cs

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
using System;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Passes;
@ -40,10 +41,18 @@ namespace CppSharp.Tests @@ -40,10 +41,18 @@ namespace CppSharp.Tests
public class NamespacesDerived {
public static void Main(string[] args)
public static int Main(string[] args)
{
ConsoleDriver.Run(new NamespacesBaseTests(GeneratorKind.CSharp));
ConsoleDriver.Run(new NamespacesDerivedTests(GeneratorKind.CSharp));
try
{
ConsoleDriver.Run(new NamespacesBaseTests(GeneratorKind.CSharp));
ConsoleDriver.Run(new NamespacesDerivedTests(GeneratorKind.CSharp));
return 0;
}
catch (ArgumentException)
{
return 1;
}
}
}

13
tests/StandardLib/StandardLib.cs

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
using System;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Utils;
@ -16,9 +17,17 @@ namespace CppSharp.Tests @@ -16,9 +17,17 @@ namespace CppSharp.Tests
ctx.SetClassAsValueType("IntWrapperValueType");
}
public static void Main(string[] args)
public static int Main(string[] args)
{
ConsoleDriver.Run(new StandardLibTestsGenerator(GeneratorKind.CLI));
try
{
ConsoleDriver.Run(new StandardLibTestsGenerator(GeneratorKind.CLI));
return 0;
}
catch (ArgumentException)
{
return 1;
}
}
}
}

15
tests/TypeMaps/TypeMaps.cs

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
using System;
using System.Linq;
using CppSharp.AST;
using CppSharp.Generators;
@ -27,10 +28,18 @@ namespace CppSharp.Tests @@ -27,10 +28,18 @@ namespace CppSharp.Tests
ctx.IgnoreClassWithName("IgnoredType");
}
public static void Main(string[] args)
public static int Main(string[] args)
{
ConsoleDriver.Run(new TypeMaps(GeneratorKind.CLI));
ConsoleDriver.Run(new TypeMaps(GeneratorKind.CSharp));
try
{
ConsoleDriver.Run(new TypeMaps(GeneratorKind.CLI));
ConsoleDriver.Run(new TypeMaps(GeneratorKind.CSharp));
return 0;
}
catch (ArgumentException)
{
return 1;
}
}
}
}

15
tests/VTables/VTables.cs

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
using System;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Passes;
@ -23,10 +24,18 @@ namespace CppSharp.Tests @@ -23,10 +24,18 @@ namespace CppSharp.Tests
}
public static void Main(string[] args)
public static int Main(string[] args)
{
ConsoleDriver.Run(new VTableTests(GeneratorKind.CLI));
ConsoleDriver.Run(new VTableTests(GeneratorKind.CSharp));
try
{
ConsoleDriver.Run(new VTableTests(GeneratorKind.CLI));
ConsoleDriver.Run(new VTableTests(GeneratorKind.CSharp));
return 0;
}
catch (ArgumentException)
{
return 1;
}
}
}
}

Loading…
Cancel
Save