public static QueryIterator createRetrieveQuery(Stella_Object query) {
    { Surrogate testValue000 = Stella_Object.safePrimaryType(query);

      if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_QUERY_ITERATOR)) {
        { QueryIterator query000 = ((QueryIterator)(query));

          return (query000);
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_PROPOSITION)) {
        { Proposition query000 = ((Proposition)(query));

          return (Logic.createRetrieveQuery(Proposition.propositionToCons(query000)));
        }
      }
      else if (testValue000 == Logic.SGT_STELLA_CONS) {
        { Cons query000 = ((Cons)(query));

          { Stella_Object iovariables = null;
            Stella_Object queryproposition = null;
            PropertyList options = null;

            { Object [] caller_MV_returnarray = new Object[2];

              iovariables = Logic.parseQueryAndOptions(query000, caller_MV_returnarray);
              queryproposition = ((Stella_Object)(caller_MV_returnarray[0]));
              options = ((PropertyList)(caller_MV_returnarray[1]));
            }
            if ((iovariables == null) &&
                (queryproposition == null)) {
              if (Logic.$MOST_RECENT_QUERY$ == null) {
                { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

                  { Object old$PrintreadablyP$000 = Stella.$PRINTREADABLYp$.get();

                    try {
                      Native.setBooleanSpecial(Stella.$PRINTREADABLYp$, true);
                      stream000.nativeStream.println("PARSING ERROR: No preceding context for follow-up retrieval.");
                      Logic.helpSignalPropositionError(stream000, Logic.KWD_ERROR);

                    } finally {
                      Stella.$PRINTREADABLYp$.set(old$PrintreadablyP$000);
                    }
                  }
                  throw ((ParsingError)(ParsingError.newParsingError(stream000.theStringReader()).fillInStackTrace()));
                }
              }
              QueryIterator.processQueryOptions(Logic.$MOST_RECENT_QUERY$, options);
              return (Logic.$MOST_RECENT_QUERY$);
            }
            else if (iovariables == null) {
              { OutputStringStream stream001 = OutputStringStream.newOutputStringStream();

                { Object old$PrintreadablyP$001 = Stella.$PRINTREADABLYp$.get();

                  try {
                    Native.setBooleanSpecial(Stella.$PRINTREADABLYp$, true);
                    stream001.nativeStream.println("PARSING ERROR: Missing IO-variable specification in retrieval query: `" + query000 + "'.");
                    Logic.helpSignalPropositionError(stream001, Logic.KWD_ERROR);

                  } finally {
                    Stella.$PRINTREADABLYp$.set(old$PrintreadablyP$001);
                  }
                }
                throw ((ParsingError)(ParsingError.newParsingError(stream001.theStringReader()).fillInStackTrace()));
              }
            }
            else {
              return (Logic.makeQuery(iovariables, queryproposition, Stella.NIL, options));
            }
          }
        }
      }
      else {
        { OutputStringStream stream002 = OutputStringStream.newOutputStringStream();

          { Object old$PrintreadablyP$002 = Stella.$PRINTREADABLYp$.get();

            try {
              Native.setBooleanSpecial(Stella.$PRINTREADABLYp$, true);
              stream002.nativeStream.println("PARSING ERROR: Illegal retrieval query: `" + query + "'.");
              Logic.helpSignalPropositionError(stream002, Logic.KWD_ERROR);

            } finally {
              Stella.$PRINTREADABLYp$.set(old$PrintreadablyP$002);
            }
          }
          throw ((ParsingError)(ParsingError.newParsingError(stream002.theStringReader()).fillInStackTrace()));
        }
      }
    }
  }