From 3c27e0fad603b789a7889fba1284296bf93ecdb2 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Fri, 7 Feb 2014 16:04:36 -0500 Subject: [PATCH] Improved generation of enumerations from macros. We now keep track if a certain macro has already been generated in an enum and skip it in future calls to GenerateEnumFromMacros. --- src/AST/Preprocessor.cs | 3 +++ src/Generator/Library.cs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/AST/Preprocessor.cs b/src/AST/Preprocessor.cs index 84c6d3e6..d1054fb1 100644 --- a/src/AST/Preprocessor.cs +++ b/src/AST/Preprocessor.cs @@ -49,6 +49,9 @@ // Contains the macro definition text. public string Expression; + // Backing enumeration if one was generated. + public Enumeration Enumeration; + public override T Visit(IDeclVisitor visitor) { return visitor.VisitMacroDefinition(this); diff --git a/src/Generator/Library.cs b/src/Generator/Library.cs index cf2492dd..903c25df 100644 --- a/src/Generator/Library.cs +++ b/src/Generator/Library.cs @@ -136,8 +136,13 @@ namespace CppSharp var match = regex.Match(macro.Name); if (!match.Success) continue; + if (macro.Enumeration != null) + continue; + var item = GenerateEnumItemFromMacro(context, macro); @enum.AddItem(item); + + macro.Enumeration = @enum; } if (@enum.Items.Count > 0)