Browse Source

Used LINQ to simplify the searching.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/128/head
Dimitar Dobrev 12 years ago
parent
commit
71d9da0733
  1. 37
      src/AST/ASTContext.cs

37
src/AST/ASTContext.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
namespace CppSharp.AST namespace CppSharp.AST
{ {
@ -50,61 +51,37 @@ namespace CppSharp.AST
/// Finds an existing enum in the library modules. /// Finds an existing enum in the library modules.
public IEnumerable<Enumeration> FindEnum(string name) public IEnumerable<Enumeration> FindEnum(string name)
{ {
foreach (var module in TranslationUnits) return TranslationUnits.Select(module => module.FindEnum(name)).Where(type => type != null);
{
var type = module.FindEnum(name);
if (type != null) yield return type;
}
} }
/// Finds the complete declaration of an enum. /// Finds the complete declaration of an enum.
public Enumeration FindCompleteEnum(string name) public Enumeration FindCompleteEnum(string name)
{ {
foreach (var @enum in FindEnum(name)) return FindEnum(name).FirstOrDefault(@enum => !@enum.IsIncomplete);
if (!@enum.IsIncomplete)
return @enum;
return null;
} }
/// Finds an existing struct/class in the library modules. /// Finds an existing struct/class in the library modules.
public IEnumerable<Class> FindClass(string name, bool create = false) public IEnumerable<Class> FindClass(string name, bool create = false)
{ {
foreach (var module in TranslationUnits) return TranslationUnits.Select(module => module.FindClass(name)).Where(type => type != null);
{
var type = module.FindClass(name);
if (type != null) yield return type;
}
} }
/// Finds the complete declaration of a class. /// Finds the complete declaration of a class.
public Class FindCompleteClass(string name) public Class FindCompleteClass(string name)
{ {
foreach (var @class in FindClass(name)) return FindClass(name).FirstOrDefault(@class => !@class.IsIncomplete);
if (!@class.IsIncomplete)
return @class;
return null;
} }
/// Finds an existing function in the library modules. /// Finds an existing function in the library modules.
public IEnumerable<Function> FindFunction(string name) public IEnumerable<Function> FindFunction(string name)
{ {
foreach (var module in TranslationUnits) return TranslationUnits.Select(module => module.FindFunction(name)).Where(type => type != null);
{
var type = module.FindFunction(name);
if (type != null) yield return type;
}
} }
/// Finds an existing typedef in the library modules. /// Finds an existing typedef in the library modules.
public IEnumerable<TypedefDecl> FindTypedef(string name) public IEnumerable<TypedefDecl> FindTypedef(string name)
{ {
foreach (var module in TranslationUnits) return TranslationUnits.Select(module => module.FindTypedef(name)).Where(type => type != null);
{
var type = module.FindTypedef(name);
if (type != null) yield return type;
}
} }
/// Finds an existing declaration by name. /// Finds an existing declaration by name.

Loading…
Cancel
Save