Beispiel #1
0
        public static IList<SyntaxTree> Sort(Compilation c, ErrorAggregator aggregator)
        {
            List<SyntaxTreeRelationship> rawList = new List<SyntaxTreeRelationship>();

            foreach (var tree in c.SyntaxTrees)
            {
                SyntaxTreeRelationship relation = new SyntaxTreeRelationship(tree);
                SemanticModel model = c.GetSemanticModel(tree);
                TypeWalker w = new TypeWalker(model, relation);
                w.Visit(tree.GetRoot());
                rawList.Add(relation);
            }

            int max = rawList.Count;

            List<SyntaxTree> sortedList = new List<SyntaxTree>();

            for (int times = 0; times < max; times++)
            {
                for (var i = 0; i < rawList.Count; i++)
                {
                    if (IsIndependent(rawList, i))
                    {
                        sortedList.Add(rawList[i].Tree);
                        rawList.RemoveAt(i);
                    }
                }
            }

            if (rawList.Count > 0)
            {
                CompileIssue issue = CompileIssue.CreateNoLocationIssue(IssueType.Error, IssueId.CrossRef);
                aggregator.AppendIssue(issue);

                //Note:use original order. use sortedList will miss cross ref class.
                return rawList.ConvertAll(r => r.Tree);
            }

            return sortedList;
        }
Beispiel #2
0
        public static IList <SyntaxTree> Sort(Compilation c, ErrorAggregator aggregator)
        {
            List <SyntaxTreeRelationship> rawList = new List <SyntaxTreeRelationship>();

            foreach (var tree in c.SyntaxTrees)
            {
                SyntaxTreeRelationship relation = new SyntaxTreeRelationship(tree);
                SemanticModel          model    = c.GetSemanticModel(tree);
                TypeWalker             w        = new TypeWalker(model, relation);
                w.Visit(tree.GetRoot());
                rawList.Add(relation);
            }

            int max = rawList.Count;

            List <SyntaxTree> sortedList = new List <SyntaxTree>();

            for (int times = 0; times < max; times++)
            {
                for (var i = 0; i < rawList.Count; i++)
                {
                    if (IsIndependent(rawList, i))
                    {
                        sortedList.Add(rawList[i].Tree);
                        rawList.RemoveAt(i);
                    }
                }
            }

            if (rawList.Count > 0)
            {
                CompileIssue issue = CompileIssue.CreateNoLocationIssue(IssueType.Error, IssueId.CrossRef);
                aggregator.AppendIssue(issue);

                //Note:use original order. use sortedList will miss cross ref class.
                return(rawList.ConvertAll(r => r.Tree));
            }

            return(sortedList);
        }