コード例 #1
0
ファイル: Ast.java プロジェクト: RobertStanforth/CostaRica
  /**
   * @param instanceFrame instance frame
   * @return iterable over instance members of the frame, including those nested in namespaces
   */
  public static Iterable<? extends INamedElement> instanceMembers(
      final IInstanceFrame instanceFrame) {
    final List<INamedElement> members = new ArrayList<>();

    // Iterate over the member functions of the frame, including those nested in namespaces.
    final Deque<INamedElement> queue = new LinkedList<>();
    queue.addLast(instanceFrame);
    while (!queue.isEmpty()) {
      final INamedElement cur = queue.getFirst();
      queue.removeFirst();

      final INamedElementContainer contCur = (INamedElementContainer) cur;
      for (final INamedElement member : contCur.members())
        if (Ast.membership(member)
            == (contCur == instanceFrame
                ? ScopeMembership.InstanceMember
                : ScopeMembership.StaticMember)) {
          members.add(member);
          if (member instanceof INamedElementContainer) {
            // Tail-recursively treat this nested namespace.
            queue.addLast(member);
          }
        }
    }

    return members;
  }
コード例 #2
0
ファイル: Ast.java プロジェクト: RobertStanforth/CostaRica
 /**
  * @param fn function
  * @return eventual overrides of the function, unifying those differing only in generic derivation
  */
 public static Iterable<? extends IFunction> eventualOverrides(final IFunction fn) {
   // Iterate over the eventually overridden functions,
   // unifying those differing only through generic derivation.
   final Set<IFunction> processedEO = new LinkedHashSet<>();
   final Deque<IFunction> queueEO = new LinkedList<>();
   queueEO.addLast(fn);
   while (!queueEO.isEmpty()) {
     final IFunction fnEO = queueEO.getFirst();
     queueEO.removeFirst();
     if (!processedEO.contains(fnEO)) {
       processedEO.add(fnEO);
       // Tail-recurse on the function's direct overrides.
       for (final ResolvedName directOverride : fnEO.directOverrides())
         queueEO.addLast((IFunction) directOverride.namedElement());
     }
   }
   return processedEO;
 }