示例#1
0
        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();
            }
        }
示例#2
0
        protected string ScopeTo(AST.Namespace ns)
        {
            var    usingParent = ns;
            string ret         = "";

            while (usingParent != WorkingNamespace && !UsingNamespaces.Contains(usingParent) && !usingParent.IsGlobal)
            {
                ret         = usingParent.Name + ScopeOperator + ret;
                usingParent = usingParent.Parent;
            }
            return(ret);
        }
示例#3
0
 public static string FullName(this AST.Namespace ns, string scopeOperator)
 {
     if (ns.IsGlobal)
     {
         return("");
     }
     else if (ns.Parent.IsGlobal)
     {
         return(ns.Name);
     }
     else
     {
         return(FullName(ns.Parent, scopeOperator) + scopeOperator + ns.Name);
     }
 }
示例#4
0
 public virtual bool Use(AST.Namespace ns, bool abi)
 {
     if (!abi && !UsingNamespaces.Contains(ns))
     {
         UsingNamespaces.Add(ns);
     }
     else if (abi && !UsingABINamespaces.Contains(ns))
     {
         UsingABINamespaces.Add(ns);
     }
     else
     {
         return(false);
     }
     return(true);
 }
示例#5
0
        public override bool Use(AST.Namespace ns, bool abi)
        {
            var added = base.Use(ns, abi);

            if (added)
            {
                if (abi)
                {
                    Line("using ABI.{0};", ns.FullName("."));
                }
                else
                {
                    Line("using {0};", ns.FullName("."));
                }
            }

            return(added);
        }
示例#6
0
文件: CppRender.cs 项目: ETLang/Gluon
        public override bool Use(AST.Namespace ns, bool abi)
        {
            var added = base.Use(ns, abi);

            if (added)
            {
                var oldIndent = Indent;
                Indent = 0;
                if (abi)
                {
                    Line("using namespace ABI::{0};", ns.FullName("::"));
                }
                else
                {
                    Line("using namespace {0};", ns.FullName("::"));
                }
                Indent = oldIndent;
            }
            return(added);
        }
示例#7
0
 public abstract void Namespace(AST.Namespace ns, bool abi, Action content);
示例#8
0
 public void Use(AST.Namespace ns, bool abi = false)
 {
     Insert(new UsingNode(ns, abi));
 }
示例#9
0
文件: CppRender.cs 项目: ETLang/Gluon
        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;
            }
        }
示例#10
0
        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;
        }