Antlr4.Semantics.SymbolChecks.CheckForLabelConflicts C# (CSharp) Method

CheckForLabelConflicts() public method

public CheckForLabelConflicts ( ICollection rules ) : void
rules ICollection
return void
        public virtual void CheckForLabelConflicts(ICollection<Rule> rules)
        {
            foreach (Rule r in rules)
            {
                CheckForAttributeConflicts(r);
                if (r is LeftRecursiveRule) {
                    // Label conflicts for left recursive rules need to be checked
                    // prior to the left recursion elimination step.
                    continue;
                }

                IDictionary<string, LabelElementPair> labelNameSpace =
                    new Dictionary<string, LabelElementPair>();
                for (int i = 1; i <= r.numberOfAlts; i++)
                {
                    if (r.HasAltSpecificContexts())
                    {
                        labelNameSpace.Clear();
                    }

                    Alternative a = r.alt[i];
                    foreach (IList<LabelElementPair> pairs in a.labelDefs.Values)
                    {
                        foreach (LabelElementPair p in pairs)
                        {
                            CheckForLabelConflict(r, p.label);
                            string name = p.label.Text;
                            LabelElementPair prev;
                            if (!labelNameSpace.TryGetValue(name, out prev) || prev == null)
                                labelNameSpace[name] = p;
                            else
                                CheckForTypeMismatch(prev, p);
                        }
                    }
                }
            }
        }