public void Namespace(AST.Namespace ns, bool abi, Action content) { NamespaceNode prev = null; if (Index > 0) { prev = Target.Children[Index - 1] as NamespaceNode; } if (prev != null && prev.Namespace == ns && prev.Abi == abi) { _ancestors.Add(Target); Target = prev; Index = Target.Children.Count; content(); PopTarget(); } else if (prev != null && prev.Abi == abi && ns.IsWithin(prev.Namespace)) { _ancestors.Add(Target); Target = prev; Index = Target.Children.Count; Namespace(ns, abi, content); PopTarget(); } else { InsertAndPushTarget(new NamespaceNode(ns, abi)); content(); PopTarget(); } }
public override void Namespace(AST.Namespace ns, bool abi, Action content) { if (ns != null && ns.IsGlobal) { ns = null; } var top = _nestedNS.Count != 0 ? _nestedNS.Peek() : null; if (_nestedNS.Count != 0 && WorkingABINamespace != abi) { throw new InvalidOperationException("abi mismatch in nested namespaces"); } if (ns != null && top != null && !ns.IsWithin(top)) { throw new InvalidOperationException("namespace is not properly nested"); } if (ns == top) { content(); return; } WorkingABINamespace = abi; List <AST.Namespace> scopeList = new List <AST.Namespace>(); for (var nsi = ns; nsi != top && !nsi.IsGlobal; nsi = nsi.Parent) { scopeList.Insert(0, nsi); } if (abi && _nestedNS.Count == 0) { BeginNamespace("ABI"); } foreach (var nsi in scopeList) { BeginNamespace(nsi.Name); } WorkingNamespace = ns; _nestedNS.Push(ns); content(); _nestedNS.Pop(); WorkingNamespace = top; foreach (var nsi in scopeList) { EndNamespace(); } if (abi && _nestedNS.Count == 0) { EndNamespace(); } if (abi && _nestedNS.Count == 0) { WorkingABINamespace = false; } }
public override void Namespace(AST.Namespace ns, bool abi, Action content) { if (ns != null && ns.IsGlobal) { ns = null; } var top = _nestedNS.Count != 0 ? _nestedNS.Peek() : null; if (_nestedNS.Count != 0 && WorkingABINamespace != abi) { throw new InvalidOperationException("abi mismatch in nested namespaces"); } if (ns != null && top != null && !ns.IsWithin(top)) { throw new InvalidOperationException("namespace is not properly nested"); } if (ns == top) { content(); return; } WorkingABINamespace = abi; string nsname = ""; for (AST.Namespace nsi = ns; nsi != top && !nsi.IsGlobal; nsi = nsi.Parent) { if (!string.IsNullOrEmpty(nsname)) { nsname = nsi.Name + "." + nsname; } else { nsname = nsi.Name; } } if (abi && _nestedNS.Count == 0) { if (string.IsNullOrEmpty(nsname)) { nsname = "ABI"; } else { nsname = "ABI." + nsname; } } WorkingNamespace = ns; _nestedNS.Push(ns); BeginNamespace(nsname); content(); EndNamespace(); _nestedNS.Pop(); WorkingNamespace = top; }