Checks that each label is defined only once within each scope.
513086
function reportDuplicateLabels( ast, session ) {

    let check;

    function checkExpressionWithClonedEnv( node, env ) {

        check( node.expression, util.clone( env ) );

    }

    check = session.buildVisitor( {
        rule( node ) {

            check( node.expression, {} );

        },

        choice( node, env ) {

            node.alternatives.forEach( alternative => {

                check( alternative, util.clone( env ) );

            } );

        },

        action: checkExpressionWithClonedEnv,

        labeled( node, env ) {

            const label = node.label;

            if ( label && __hasOwnProperty.call( env, label ) ) {

                const start = env[ label ].start;

                session.error(
                    `Label "${ label }" is already defined at line ${ start.line }, column ${ start.column }.`,
                    node.location
                );

            }

            check( node.expression, env );

            if ( label ) env[ label ] = node.location;

        },

        text: checkExpressionWithClonedEnv,
        simple_and: checkExpressionWithClonedEnv,
        simple_not: checkExpressionWithClonedEnv,
        optional: checkExpressionWithClonedEnv,
        zero_or_more: checkExpressionWithClonedEnv,
        one_or_more: checkExpressionWithClonedEnv,
        group: checkExpressionWithClonedEnv
    } );

    check( ast );

}
1358999
def _validate_singletons(self, boxes):
        """"""
        count = self._collect_box_count(boxes)
        # Which boxes occur more than once?
        multiples = [box_id for box_id, bcount in count.items() if bcount > 1]
        if 'dtbl' in multiples:
            raise IOError('There can only be one dtbl box in a file.')
1259350
def get_by_label(self, label):
        
        return next((x for x in self if x.label == label), None)
754658
private static boolean matchLabel(Node target, String label) {
    if (label == null) {
      return true;
    }
    while (target.isLabel()) {
      if (target.getFirstChild().getString().equals(label)) {
        return true;
      }
      target = target.getParent();
    }
    return false;
  }
979376
def cleanup_local_labels(block):
    
    global PROC_COUNTER

    stack = [[]]
    hashes = [{}]
    stackprc = [PROC_COUNTER]
    used = [{}]  # List of hashes of unresolved labels per scope

    MEMORY = block.mem

    for cell in MEMORY:
        if cell.inst.upper() == 'PROC':
            stack += [[]]
            hashes += [{}]
            stackprc += [PROC_COUNTER]
            used += [{}]
            PROC_COUNTER += 1
            continue

        if cell.inst.upper() == 'ENDP':
            if len(stack) > 1:  # There might be unbalanced stack due to syntax errors
                for label in used[-1].keys():
                    if label in stack[-1]:
                        newlabel = hashes[-1][label]
                        for cell in used[-1][label]:
                            cell.replace_label(label, newlabel)

                stack.pop()
                hashes.pop()
                stackprc.pop()
                used.pop()
            continue

        tmp = cell.asm.strip()
        if tmp.upper()[:5] == 'LOCAL':
            tmp = tmp[5:].split(',')
            for lbl in tmp:
                lbl = lbl.strip()
                if lbl in stack[-1]:
                    continue
                stack[-1] += [lbl]
                hashes[-1][lbl] = 'PROC%i.' % stackprc[-1] + lbl
                if used[-1].get(lbl, None) is None:
                    used[-1][lbl] = []

            cell.asm = ';' + cell.asm  # Remove it
            continue

        if cell.is_label:
            label = cell.inst
            for i in range(len(stack) - 1, -1, -1):
                if label in stack[i]:
                    label = hashes[i][label]
                    cell.asm = label + ':'
                    break
            continue

        for label in cell.used_labels:
            labelUsed = False
            for i in range(len(stack) - 1, -1, -1):
                if label in stack[i]:
                    newlabel = hashes[i][label]
                    cell.replace_label(label, newlabel)
                    labelUsed = True
                    break

            if not labelUsed:
                if used[-1].get(label, None) is None:
                    used[-1][label] = []

                used[-1][label] += [cell]

    for i in range(len(MEMORY) - 1, -1, -1):
        if MEMORY[i].asm[0] == ';':
            MEMORY.pop(i)

    block.mem = MEMORY
    block.asm = [x.asm for x in MEMORY if len(x.asm.strip())]
211789
def _estimate_label_shape(self):
        """"""
        max_count = 0
        self.reset()
        try:
            while True:
                label, _ = self.next_sample()
                label = self._parse_label(label)
                max_count = max(max_count, label.shape[0])
        except StopIteration:
            pass
        self.reset()
        return (max_count, label.shape[1])
396982
def call_only_once(func):
    '''
    
    '''

    def new_func(*args, **kwargs):
        if not new_func._called:
            new_func._called = True
            return func(*args, **kwargs)

    new_func._called = False
    return new_func
652574
def p_scope_pointer(self, p):
        ''
        scope = () if p[1].var.scope is None else p[1].var.scope.labellist
        p[0] = IdentifierScope(scope + (IdentifierScopeLabel(p[1].var.name,
                                                             p[1].ptr, lineno=p.lineno(1)),), lineno=p.lineno(1))
        p.set_lineno(0, p.lineno(1))
1081236
private boolean scopeContainsInstances(GraqlCompute query, ConceptId... ids) {
        for (ConceptId id : ids) {
            Thing thing = tx.getConcept(id);
            if (thing == null || !scopeTypeLabels(query).contains(thing.type().label())) return false;
        }
        return true;
    }
612615
def get_scope(self, which, labels):
        

        try:
            scope_choice = labels[self.SCOPE_LABEL]
        except (KeyError, TypeError):
            self.log.debug("no distribution scope set for %s image", which)
            raise NothingToCheck

        try:
            scope = self.SCOPE_NAME.index(scope_choice)
        except ValueError:
            self.log.warning("invalid label %s=%s for %s image",
                             self.SCOPE_LABEL, scope_choice, which)
            raise NothingToCheck

        return scope
659755
private static Multimap<Variable, Type> getInstanceVarTypeMap(
            Set<Fragment> allFragments, Map<Variable, Type> labelVarTypeMap) {
        Multimap<Variable, Type> instanceVarTypeMap = HashMultimap.create();
        int oldSize;
        do {
            oldSize = instanceVarTypeMap.size();
            allFragments.stream()
                    .filter(fragment -> labelVarTypeMap.containsKey(fragment.start())) // restrict to types
                    .filter(fragment -> fragment instanceof InIsaFragment || fragment instanceof InSubFragment) //
                    .forEach(fragment -> instanceVarTypeMap.put(fragment.end(), labelVarTypeMap.get(fragment.start())));
        } while (oldSize != instanceVarTypeMap.size());
        return instanceVarTypeMap;
    }
1345687
public int getNumberOfLabelsUsed() {
        if (labels != null && !labels.isEmpty())
            return labels.size();
        else
            return ((Long) (maxCount + 1)).intValue();
    }
896866
private void cleanUpLabels() {
        int id = 0;
        for (Iterator<Label> i = labels.iterator(); i.hasNext();) {
            Label label = i.next();
            if (label.isEmpty()) {
                i.remove();
            } else {
                label.compact();
                label.id = id++;
            }
        }
    }
1037276
def labels(self):
        
        return [x for x in self[self.current_scope].values() if x.class_ == CLASS.label]
560586
def in_labelset(xmrs, nodeids, label=None):
    
    nodeids = set(nodeids)
    if label is None:
        label = xmrs.ep(next(iter(nodeids))).label
    return nodeids.issubset(xmrs._vars[label]['refs']['LBL'])
1225401
def _collected_label(collect, label):
    """"""
    if not collect.__name__.startswith('<'):
        return label + ' ' + collect.__name__
    else:
        return label
952637
private ImmutableSet<Label> scopeTypeLabels(GraqlCompute query) {
        return scopeTypes(query).map(SchemaConcept::label).collect(CommonUtil.toImmutableSet());
    }