Skip to content

Commit ae6a373

Browse files
committed
Removed unused STD enumerations from generation.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 0c78ba2 commit ae6a373

File tree

10 files changed

+37
-126
lines changed

10 files changed

+37
-126
lines changed

src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -495,31 +495,6 @@ public partial struct __Internal
495495

496496
public unsafe partial class BasicString<_CharT, _Traits, _Allocator> : IDisposable
497497
{
498-
internal enum ShortMask
499-
{
500-
ShortMask = 0
501-
}
502-
503-
internal enum LongMask
504-
{
505-
LongMask = 0
506-
}
507-
508-
internal enum MinCap
509-
{
510-
MinCap = 0
511-
}
512-
513-
internal enum NWords
514-
{
515-
NWords = 0
516-
}
517-
518-
internal enum Alignment
519-
{
520-
Alignment = 0
521-
}
522-
523498
public global::System.IntPtr __Instance { get; protected set; }
524499

525500
protected int __PointerAdjustment;

src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -641,15 +641,6 @@ public partial struct __Internal
641641

642642
public unsafe partial class StringVal<_Val_types>
643643
{
644-
public enum BUF_SIZE
645-
{
646-
BUF_SIZE = 0
647-
}
648-
649-
public enum ALLOC_MASK
650-
{
651-
ALLOC_MASK = 0
652-
}
653644
}
654645
}
655646

@@ -711,11 +702,6 @@ public unsafe partial struct __Internal
711702

712703
public unsafe partial class TreeVal<_Val_types>
713704
{
714-
public enum Redbl
715-
{
716-
Red = 0,
717-
Black = 0
718-
}
719705
}
720706
}
721707

@@ -736,16 +722,6 @@ public unsafe partial class Map<_Kty, _Ty, _Pr, _Alloc>
736722
}
737723
}
738724

739-
namespace Std
740-
{
741-
[Flags]
742-
public enum CodecvtMode
743-
{
744-
ConsumeHeader = 4,
745-
GenerateHeader = 2
746-
}
747-
}
748-
749725
namespace Std
750726
{
751727
}

src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -495,31 +495,6 @@ public partial struct __Internal
495495

496496
public unsafe partial class BasicString<_CharT, _Traits, _Allocator> : IDisposable
497497
{
498-
internal enum ShortMask
499-
{
500-
ShortMask = 0
501-
}
502-
503-
internal enum LongMask
504-
{
505-
LongMask = 0
506-
}
507-
508-
internal enum MinCap
509-
{
510-
MinCap = 0
511-
}
512-
513-
internal enum NWords
514-
{
515-
NWords = 0
516-
}
517-
518-
internal enum Alignment
519-
{
520-
Alignment = 0
521-
}
522-
523498
public global::System.IntPtr __Instance { get; protected set; }
524499

525500
protected int __PointerAdjustment;

src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,6 @@ public partial struct __Internal
483483

484484
public unsafe partial class BasicString<_CharT, _Traits, _Alloc> : IDisposable
485485
{
486-
internal enum S_localCapacity
487-
{
488-
S_localCapacity = 0
489-
}
490-
491486
public global::System.IntPtr __Instance { get; protected set; }
492487

493488
protected int __PointerAdjustment;

src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -641,15 +641,6 @@ public partial struct __Internal
641641

642642
public unsafe partial class StringVal<_Val_types>
643643
{
644-
public enum BUF_SIZE
645-
{
646-
BUF_SIZE = 0
647-
}
648-
649-
public enum ALLOC_MASK
650-
{
651-
ALLOC_MASK = 0
652-
}
653644
}
654645
}
655646

@@ -711,11 +702,6 @@ public unsafe partial struct __Internal
711702

712703
public unsafe partial class TreeVal<_Val_types>
713704
{
714-
public enum Redbl
715-
{
716-
Red = 0,
717-
Black = 0
718-
}
719705
}
720706
}
721707

@@ -736,16 +722,6 @@ public unsafe partial class Map<_Kty, _Ty, _Pr, _Alloc>
736722
}
737723
}
738724

739-
namespace Std
740-
{
741-
[Flags]
742-
public enum CodecvtMode
743-
{
744-
ConsumeHeader = 4,
745-
GenerateHeader = 2
746-
}
747-
}
748-
749725
namespace Std
750726
{
751727
}

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3007,7 +3007,7 @@ public override bool VisitTypedefNameDecl(TypedefNameDecl typedef)
30073007

30083008
public override bool VisitEnumDecl(Enumeration @enum)
30093009
{
3010-
if (@enum.IsIncomplete)
3010+
if (@enum.IsIncomplete || @enum.Ignore)
30113011
return true;
30123012

30133013
PushBlock(BlockKind.Enum);

src/Generator/Passes/CleanCommentsPass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public bool VisitParagraphCommand(ParagraphComment comment)
7171
var textComment = (TextComment) item;
7272

7373
if (textComment.Text.StartsWith("<", StringComparison.Ordinal))
74-
textComment.Text = $"{textComment.Text}{">"}";
74+
textComment.Text = $"{textComment.Text}>";
7575
else if (textComment.Text.StartsWith(">", StringComparison.Ordinal))
7676
textComment.Text = textComment.Text.Substring(1);
7777
}

src/Generator/Passes/IgnoreSystemDeclarationsPass.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public IgnoreSystemDeclarationsPass()
1616
VisitOptions.VisitClassProperties = false;
1717
VisitOptions.VisitFunctionParameters = false;
1818
VisitOptions.VisitFunctionReturnType = false;
19-
VisitOptions.VisitNamespaceEnums = false;
2019
VisitOptions.VisitNamespaceEvents = false;
2120
VisitOptions.VisitNamespaceTemplates = false;
2221
VisitOptions.VisitNamespaceTypedefs = false;
@@ -114,6 +113,17 @@ private static IEnumerable<ClassTemplateSpecialization> GetCharSpecializations(C
114113
s.Arguments[0].Type.Type.Desugar().IsPrimitiveType(PrimitiveType.Char));
115114
}
116115

116+
public override bool VisitEnumDecl(Enumeration @enum)
117+
{
118+
if (!base.VisitEnumDecl(@enum))
119+
return false;
120+
121+
if (@enum.TranslationUnit.IsSystemHeader)
122+
@enum.ExplicitlyIgnore();
123+
124+
return true;
125+
}
126+
117127
public override bool VisitFunctionDecl(Function function)
118128
{
119129
if (!base.VisitFunctionDecl(function))

src/Generator/Passes/MarkUsedClassInternalsPass.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,28 @@ public override bool VisitClassDecl(Class @class)
2828
if (!base.VisitClassDecl(@class) || @class.Ignore || @class.IsDependent)
2929
return false;
3030

31-
MarkUsedFieldTypes(@class, new HashSet<Class>());
31+
MarkUsedFieldTypes(@class, new HashSet<DeclarationContext>());
3232

3333
return true;
3434
}
3535

36-
private static void MarkUsedFieldTypes(Class @class, HashSet<Class> visitedClasses)
36+
private static void MarkUsedFieldTypes(DeclarationContext declContext,
37+
HashSet<DeclarationContext> visitedDeclarationContexts)
3738
{
38-
if (visitedClasses.Contains(@class))
39+
if (visitedDeclarationContexts.Contains(declContext))
3940
return;
4041

41-
visitedClasses.Add(@class);
42+
visitedDeclarationContexts.Add(declContext);
43+
44+
DeclarationContext decl = null;
45+
var @class = declContext as Class;
46+
if (@class == null)
47+
return;
4248

43-
Class type = null;
4449
foreach (var field in @class.Layout.Fields.Where(
45-
f => f.QualifiedType.Type.TryGetClass(out type)))
50+
f => f.QualifiedType.Type.TryGetDeclaration(out decl)))
4651
{
47-
DeclarationContext declarationContext = type;
52+
DeclarationContext declarationContext = decl;
4853
do
4954
{
5055
if (declarationContext.Ignore)
@@ -58,7 +63,7 @@ private static void MarkUsedFieldTypes(Class @class, HashSet<Class> visitedClass
5863
declarationContext = declarationContext.Namespace;
5964
} while (declarationContext != null);
6065

61-
MarkUsedFieldTypes(type, visitedClasses);
66+
MarkUsedFieldTypes(decl, visitedDeclarationContexts);
6267
}
6368
}
6469
}

tests/CSharp/CSharp.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,18 @@ public override void Preprocess(Driver driver, ASTContext ctx)
4040
ctx.SetClassAsValueType("StructTestArrayTypeFromTypedef");
4141
ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor");
4242

43-
var macroRegex = new Regex(@"(MY_MACRO_TEST_.*)");
44-
List<string> list = new List<string>();
45-
foreach (TranslationUnit unit in ctx.TranslationUnits)
46-
{
47-
if (unit.FilePath == "<invalid>" || unit.FileName == "CSharp.h")
48-
foreach (var macro in unit.PreprocessedEntities.OfType<MacroDefinition>())
49-
{
50-
Match match = macroRegex.Match(macro.Name);
51-
if (match.Success) list.Add(macro.Name);
52-
}
53-
}
43+
var macroRegex = new Regex("(MY_MACRO_TEST_.*)");
44+
var list = (from unit in ctx.TranslationUnits
45+
where !unit.IsValid || unit.FileName == "CSharp.h"
46+
from macro in unit.PreprocessedEntities.OfType<MacroDefinition>()
47+
where macroRegex.IsMatch(macro.Name)
48+
select macro.Name).ToList();
5449
var enumTest = ctx.GenerateEnumFromMacros("MyMacroTestEnum", list.ToArray());
55-
enumTest.Namespace = new Namespace() {Name = "MacroTest"};
50+
enumTest.Namespace = new Namespace()
51+
{
52+
Name = "MacroTest",
53+
Namespace = ctx.TranslationUnits.First(u => u.IsValid && !u.IsSystemHeader)
54+
};
5655
}
5756

5857
public override void Postprocess(Driver driver, ASTContext ctx)

0 commit comments

Comments
 (0)