diff --git a/src/AST/ClassExtensions.cs b/src/AST/ClassExtensions.cs index 76ad2c81..a3eedbbc 100644 --- a/src/AST/ClassExtensions.cs +++ b/src/AST/ClassExtensions.cs @@ -184,13 +184,13 @@ namespace CppSharp.AST Class @interface = null; if (specialization == null) { - @interface = @class.Namespace.Classes.Find( + @interface = @class.Namespace.Classes.FirstOrDefault( c => c.OriginalClass == @class && c.IsInterface); } else { Class template = specialization.TemplatedDecl.TemplatedClass; - Class templatedInterface = @class.Namespace.Classes.Find( + Class templatedInterface = @class.Namespace.Classes.FirstOrDefault( c => c.OriginalClass == template && c.IsInterface); if (templatedInterface != null) @interface = templatedInterface.Specializations.FirstOrDefault( diff --git a/src/AST/DeclIterator.cs b/src/AST/DeclIterator.cs deleted file mode 100644 index c94584f9..00000000 --- a/src/AST/DeclIterator.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -namespace CppSharp.AST -{ - public struct DeclIterator : IEnumerable where T : Declaration - { - private readonly List Declarations; - - public DeclIterator(List declarations) - { - Declarations = declarations; - } - - public int Count - { - get { return Declarations.OfType().ToArray().Length; } - } - - public T this[int index] - { - get { return Declarations.OfType().ToArray()[index]; } - } - - public void Add(T declaration) - { - Declarations.Add(declaration); - } - - public void AddRange(IEnumerable range) - { - Declarations.AddRange(range); - } - - public T Find(Func predicate) - { - return Declarations.OfType().SingleOrDefault(predicate); - } - - public int FindIndex(Predicate predicate) - { - return Declarations.OfType().ToList().FindIndex(predicate); - } - - public bool Exists(Func predicate) - { - return Declarations.OfType().Any(predicate); - } - - public IEnumerator GetEnumerator() - { - return Declarations.OfType().GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - public void Replace(T decl, T newDecl) - { - Declarations[Declarations.FindIndex(d => d == decl)] = newDecl; - } - } -} diff --git a/src/AST/DeclarationsList.cs b/src/AST/DeclarationsList.cs new file mode 100644 index 00000000..3e22c228 --- /dev/null +++ b/src/AST/DeclarationsList.cs @@ -0,0 +1,145 @@ +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace CppSharp.AST +{ + public class DeclarationsList : ObservableCollection + { + public IEnumerable Namespaces => OfType(Kind.Namespace); + + public IEnumerable Enums => OfType(Kind.Enum); + + public IEnumerable Functions => OfType(Kind.Function); + + public IEnumerable Classes => OfType(Kind.Class); + + public IEnumerable