コード例 #1
0
ファイル: Location.cs プロジェクト: thisiscam/formula
        public static int Compare(Location l1, Location l2)
        {
            if (l1.ast == null)
            {
                return(l2.ast == null ? 0 : -1);
            }
            else if (l2.ast == null)
            {
                return(1);
            }
            else if (l1.ast == l2.ast)
            {
                return(0);
            }

            var cmp = ProgramName.Compare(((Program)l1.ast.Root).Name, ((Program)l2.ast.Root).Name);

            if (cmp != 0)
            {
                return(cmp);
            }

            bool move1, move2;

            using (var it1 = l1.ast.Path.GetEnumerator())
            {
                using (var it2 = l2.ast.Path.GetEnumerator())
                {
                    while ((move1 = it1.MoveNext()) & (move2 = it2.MoveNext()))
                    {
                        cmp = it1.Current.AbsolutePos - it2.Current.AbsolutePos;
                        if (cmp != 0)
                        {
                            return(cmp);
                        }
                    }

                    if (move1 && !move2)
                    {
                        return(1);
                    }
                    else if (move2 && !move1)
                    {
                        return(-1);
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
        }
コード例 #2
0
        private static int CompareModules(AST <Node> mod1, AST <Node> mod2)
        {
            var prog1 = (Program)mod1.GetPathParent();
            var prog2 = (Program)mod2.GetPathParent();
            var cmp   = ProgramName.Compare(prog1.Name, prog2.Name);

            if (cmp != 0)
            {
                return(cmp);
            }

            string name1, name2;

            mod1.Node.TryGetStringAttribute(AttributeKind.Name, out name1);
            mod2.Node.TryGetStringAttribute(AttributeKind.Name, out name2);
            return(string.CompareOrdinal(name1, name2));
        }
コード例 #3
0
        public static AST <Program>[] GetProgramsByName(string partialName, Env env)
        {
            partialName = partialName == null ? string.Empty : partialName.ToLowerInvariant();
            var sorted = new Set <AST <Program> >((x, y) => ProgramName.Compare(x.Node.Name, y.Node.Name));

            env.FileRoot.FindAll(
                new NodePred[]
            {
                NodePredFactory.Instance.Star,
                NodePredFactory.Instance.MkPredicate(NodeKind.Program),
            },
                (path, node) =>
            {
                if (string.IsNullOrEmpty(partialName) ||
                    ((Program)node).Name.ToString().Contains(partialName))
                {
                    sorted.Add((AST <Program>)Factory.Instance.ToAST(node));
                }
            },
                canceler.Token);

            env.EnvRoot.FindAll(
                new NodePred[]
            {
                NodePredFactory.Instance.Star,
                NodePredFactory.Instance.MkPredicate(NodeKind.Program),
            },
                (path, node) =>
            {
                if (string.IsNullOrEmpty(partialName) ||
                    ((Program)node).Name.ToString().Contains(partialName))
                {
                    sorted.Add((AST <Program>)Factory.Instance.ToAST(node));
                }
            },
                canceler.Token);

            return(sorted.ToArray());
        }