Esempio n. 1
0
        public string List <T>(IEnumerable <T> items, CodeListStyle style, Func <T, string> exp)
        {
            var enumerator = items.GetEnumerator();

            if (!enumerator.MoveNext())
            {
                return("");
            }

            var argNode = new PascalTree();

            var currentTarget = Target;
            var currentIndex  = Index;

            Target = argNode;
            Index  = 0;

            List(style, () =>
            {
                foreach (var item in items)
                {
                    ListItem(exp(item));
                }
            });

            Target = currentTarget;
            Index  = currentIndex;

            return(InlineNode(argNode));
        }
Esempio n. 2
0
 public void InsertAndPushTarget(PascalTree node)
 {
     Target.Children.Insert(Index, node);
     _ancestors.Add(Target);
     Target = node;
     Index  = node.Children.Count;
 }
Esempio n. 3
0
        public static IEnumerable <AST.Namespace> GetAllExternalReferencedNamespaces(this PascalTree tree)
        {
            List <AST.Namespace>          refs    = new List <AST.Namespace>();
            Action <INode, AST.Namespace> recurse = null;

            recurse = (node, currentNS) =>
            {
                var tn  = node as TypeRefNode;
                var nsn = node as NamespaceNode;
                var bn  = node as PascalTree;

                if (tn != null && !tn.Type.Namespace.IsWithin(currentNS))
                {
                    refs.Add(tn.Type.Namespace);
                }

                if (nsn != null)
                {
                    currentNS = nsn.Namespace;
                }

                if (bn != null)
                {
                    foreach (var child in bn.Children)
                    {
                        recurse(child, currentNS);
                    }
                }
            };

            recurse(tree, null);
            return(refs.Distinct());
        }
Esempio n. 4
0
        public string Signature(AST.ICallSignature d, bool?abi = null)
        {
            var sigNode = new PascalTree();

            InsertAndPushTarget(sigNode);

            var useabi = abi ?? Strata == ApiStrata.ABI;

            if (useabi)
            {
                Code("HRESULT");
            }
            else
            {
                Code(VariableType(d.Return, AST.VariableContext.Return, useabi));
            }

            Code("(");
            List(useabi ? CodeListStyle.Compact : CodeListStyle.SingleLine, () =>
            {
                foreach (var arg in useabi ? d.GetABIParametersCpp(true) : d.Parameters)
                {
                    ListItem(VariableType(arg, useabi));
                }
            });
            Code(")");

            PopTarget();
            Index--;
            Delete();

            return(InlineNode(sigNode));
        }
Esempio n. 5
0
 public static IEnumerable <T> GetAllNodes <T>(this PascalTree tree) where T : INode
 {
     foreach (var child in tree.ForwardTraversal)
     {
         if (child is T)
         {
             yield return((T)child);
         }
     }
 }
Esempio n. 6
0
        public string DeclParameters(bool defaultValues, params object[] args)
        {
            var argNode = new PascalTree();

            var currentTarget = Target;
            var currentIndex  = Index;

            Target = argNode;
            Index  = 0;

            List(() =>
            {
                Action <object> handleObject = null;
                handleObject = o =>
                {
                    var str  = o as string;
                    var ivar = o as AST.IVariable;
                    var coll = o as IEnumerable;

                    if (str != null)
                    {
                        ListItem(str);
                    }
                    if (ivar != null)
                    {
                        DeclParameter(ivar, defaultValues);
                        NextListItem();
                    }
                    if (coll != null)
                    {
                        foreach (var item in coll)
                        {
                            handleObject(item);
                        }
                    }
                };

                foreach (var arg in args)
                {
                    handleObject(arg);
                }
            });

            Target = currentTarget;
            Index  = currentIndex;

            return(InlineNode(argNode));
        }
Esempio n. 7
0
        public string ForEach <T>(IEnumerable <T> items, Action <T> fn)
        {
            var argNode = new PascalTree();

            var currentTarget = Target;
            var currentIndex  = Index;

            Target = argNode;
            Index  = 0;

            foreach (var item in items)
            {
                fn(item);
            }

            Target = currentTarget;
            Index  = currentIndex;

            return(InlineNode(argNode));
        }
Esempio n. 8
0
 public PascalTreeWriter(PascalTree tree)
 {
     Tree   = tree;
     Target = tree;
     Index  = tree.Children.Count;
 }
Esempio n. 9
0
 public CsTreeWriter(PascalTree tree, bool targetMono = false) : base(tree)
 {
     TargetMono = targetMono;
 }
Esempio n. 10
0
 public static IEnumerable <AST.Namespace> GetAllReferencedNamespaces(this PascalTree tree)
 {
     return(GetAllNodes <TypeRefNode>(tree).Select(n => n.Type.Namespace).Distinct());
 }
Esempio n. 11
0
 public CppTreeWriter(PascalTree tree, GeneratorSettingsCpp settings) : base(tree)
 {
     Settings = settings;
 }