'Return completion info for all top-level names matching the
given prefix and ilk in all selected blobs in this lib.
"prefix" is a 3-character prefix with which to filter top-level
names. If None (or not specified), results are not filtered
based on the prefix.
"ilk" is a symbol type (e.g. "class", "variable", "function")
with which to filter results. If None (or not specified),
results of any ilk are returned.
"ctlr" (optional) is an EvalController instance. If
specified it should be used in the normal way (logging,
checking .is_aborted()).
Returns a list of 2-tuples: (<ilk>, <name>).
Note: the list is not sorted, because often some special sorting
is required for the different completion evaluators that might use
this API.'

def toplevel_cplns(self, prefix=None, ilk=None, ctlr=None):

    cplns = []
    if (prefix is None):
        toplevelname_index = self.catalogs_zone.toplevelname_index
        if (self.lang in toplevelname_index):
            if (ilk is not None):
                try:
                    bfrft = toplevelname_index[self.lang][ilk]
                except KeyError:
                    pass
                else:
                    if (self.selection_res_id_set is None):
                        cplns += [(ilk, t) for t in bfrft]
                    else:
                        cplns += [(ilk, t) for (t, bfr) in bfrft.iteritems() if self.selection_res_id_set.intersection(bfr)]
            elif (self.selection_res_id_set is None):
                for (i, bfrft) in toplevelname_index[self.lang].iteritems():
                    cplns += [(i, t) for t in bfrft]
            else:
                for (i, bfrft) in toplevelname_index[self.lang].iteritems():
                    cplns += [(i, t) for (t, bfr) in bfrft.iteritems() if self.selection_res_id_set.intersection(bfr)]
    else:
        toplevelprefix_index = self.catalogs_zone.toplevelprefix_index
        if (self.lang in toplevelprefix_index):
            if (ilk is not None):
                try:
                    tfr = toplevelprefix_index[self.lang][ilk][prefix]
                except KeyError:
                    pass
                else:
                    if (self.selection_res_id_set is None):
                        cplns += [(ilk, t) for toplevelnames in tfr.itervalues() for t in toplevelnames]
                    else:
                        cplns += [(ilk, t) for r in self.selection_res_id_set.intersection(tfr) for t in tfr[r]]
            elif (self.selection_res_id_set is None):
                for (i, tfrfp) in toplevelprefix_index[self.lang].iteritems():
                    if (prefix not in tfrfp):
                        continue
                    cplns += [(i, t) for toplevelnames in tfrfp[prefix].itervalues() for t in toplevelnames]
            else:
                for (i, tfrfp) in toplevelprefix_index[self.lang].iteritems():
                    if (prefix not in tfrfp):
                        continue
                    tfr = tfrfp[prefix]
                    cplns += [(i, t) for r in self.selection_res_id_set.intersection(tfr) for t in tfr[r]]
    return cplns
