* @param localP
   * @return Cons
   */
  public static Cons callListUndefinedRelations(Module module, boolean localP) {
    { Cons undefined = Stella.NIL;

      Logic.finalizeObjects();
      { Stella_Object term = null;
        Iterator iter000 = Logic.allNamedTerms(module, localP);

        while (iter000.nextP()) {
          term = iter000.value;
          { Surrogate testValue000 = Stella_Object.safePrimaryType(term);

            if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_NAMED_DESCRIPTION)) {
              { NamedDescription term000 = ((NamedDescription)(term));

                if (!NamedDescription.definedRelationP(term000)) {
                  undefined = Cons.cons(term000, undefined);
                }
              }
            }
            else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_LOGIC_OBJECT)) {
              { LogicObject term000 = ((LogicObject)(term));

                { Object old$Module$000 = Stella.$MODULE$.get();
                  Object old$Context$000 = Stella.$CONTEXT$.get();

                  try {
                    Native.setSpecial(Stella.$MODULE$, ((module == null) ? term000.homeModule() : module));
                    Native.setSpecial(Stella.$CONTEXT$, ((Module)(Stella.$MODULE$.get())));
                    if (Logic.applyCachedAsk(Cons.cons(Logic.SYM_LOGIC_pX, Stella.NIL), Cons.list$(Cons.cons(Logic.SYM_PL_KERNEL_KB_RELATION, Cons.cons(Logic.SYM_LOGIC_pX, Cons.cons(Stella.NIL, Stella.NIL)))), Cons.consList(Cons.cons(term000, Stella.NIL)), Cons.consList(Stella.NIL), Logic.SYM_LOGIC_F_CALL_LIST_UNDEFINED_RELATIONS_QUERY_000, new Object[1])) {
                      undefined = Cons.cons(term000, undefined);
                    }

                  } finally {
                    Stella.$CONTEXT$.set(old$Context$000);
                    Stella.$MODULE$.set(old$Module$000);
                  }
                }
              }
            }
            else {
            }
          }
        }
      }
      return (undefined);
    }
  }