Created
January 15, 2019 02:21
-
-
Save Alan-FGR/e686d4de674b7b0ea91f8f746821e707 to your computer and use it in GitHub Desktop.
Hacky hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using CppSharp; | |
using CppSharp.AST; | |
using CppSharp.Generators; | |
public class AstHack : ILibrary | |
{ | |
public static ASTContext GetAst(IEnumerable<Module> modules) | |
{ | |
modules_ = modules; | |
try | |
{ | |
ConsoleDriver.Run(new AstHack()); | |
} | |
catch (Exception e) | |
{ | |
if(e.Message == "hack") | |
return context_; | |
throw; | |
} | |
return null; | |
} | |
private static ASTContext context_; | |
private static IEnumerable<Module> modules_; | |
public void Setup(Driver driver) | |
{ | |
//workaround | |
driver.ParserOptions.NoBuiltinIncludes = true; | |
driver.ParserOptions.SetupMSVC(); | |
driver.ParserOptions.ToolSetToUse = 191500000; | |
var options = driver.Options; | |
foreach (Module m in modules_) | |
options.Modules.Add(m); | |
driver.Options.DryRun = true; | |
} | |
public void SetupPasses(Driver driver){} | |
public void Postprocess(Driver driver, ASTContext ctx){} | |
public void Preprocess(Driver driver, ASTContext ctx) | |
{ | |
context_ = ctx; | |
throw new Exception("hack"); | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var module = new Module("PhysX"); | |
module.IncludeDirs.Add("C:\\Projects\\PhysX\\physx\\include"); | |
module.IncludeDirs.Add("C:\\Projects\\PhysX\\pxshared\\include"); | |
module.Headers.Add("PxShape.h"); | |
module.LibraryDirs.Add("C:\\Projects\\minBND\\Tests"); | |
module.Defines.Add("_DEBUG"); | |
//module.Libraries.Add("Test.lib"); | |
var ast = AstHack.GetAst(new[]{module}); | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment