Browse Source

Add MarkEventsWithUniqueIdPass pass for global event handling.

java
Joao Matos 4 years ago committed by João Matos
parent
commit
0595fcfc9e
  1. 2
      src/Generator/Driver.cs
  2. 31
      src/Generator/Passes/MarkEventsWithUniqueIdPass.cs

2
src/Generator/Driver.cs

@ -291,6 +291,8 @@ namespace CppSharp
} }
Context.TranslationUnitPasses.AddPass(new HandleVariableInitializerPass()); Context.TranslationUnitPasses.AddPass(new HandleVariableInitializerPass());
TranslationUnitPasses.AddPass(new MarkEventsWithUniqueIdPass());
} }
public void ProcessCode() public void ProcessCode()

31
src/Generator/Passes/MarkEventsWithUniqueIdPass.cs

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Passes;
using Type = CppSharp.AST.Type;
namespace CppSharp
{
/// <summary>
/// This pass sets each event in the AST with a global unique ID.
/// </summary>
public class MarkEventsWithUniqueIdPass : TranslationUnitPass
{
private int eventId = 1;
public Dictionary<Event, int> EventIds = new Dictionary<Event, int>();
public override bool VisitEvent(Event @event)
{
if (AlreadyVisited(@event))
return true;
if (@event.GlobalId != 0)
throw new NotSupportedException();
@event.GlobalId = eventId++;
return base.VisitEvent(@event);
}
}
}
Loading…
Cancel
Save