Пример #1
0
 public void RegisterCallbacks(
     AstManager astManager,
     ISolution solution,
     ProjectModelViewHost host,
     DteProtocolModel model
     )
 {
     model.ProjectItem_get_Name.SetWithReadLock(projectItemModel =>
                                                host.GetItemById <IProjectItem>(projectItemModel.Id)?.Name ?? "");
     model.ProjectItem_set_Name.SetWithReadLock(request =>
     {
         var item = host.GetItemById <IProjectItem>(request.Model.Id);
         if (item == null)
         {
             return(Unit.Instance);
         }
         solution.InvokeUnderTransaction(cookie => cookie.Rename(item, request.NewName));
         return(Unit.Instance);
     });
     model.ProjectItem_get_Kind.SetWithReadLock(projectItemModel =>
                                                host.GetItemById <IProjectItem>(projectItemModel.Id)?.Kind switch
     {
         ProjectItemKind.PHYSICAL_FILE => ProjectItemKindModel.PhysicalFile,
         ProjectItemKind.PHYSICAL_DIRECTORY => ProjectItemKindModel.PhysicalFolder,
         ProjectItemKind.PROJECT => ProjectItemKindModel.Project,
         ProjectItemKind.VIRTUAL_DIRECTORY => ProjectItemKindModel.VirtualDirectory,
         _ => ProjectItemKindModel.Unknown,
     });
Пример #2
0
        public void RegisterCallbacks(
            AstManager astManager,
            ISolution solution,
            ProjectModelViewHost host,
            DteProtocolModel model
            )
        {
            model.FileCodeModel_get_CodeElements.SetWithReadLock(projectItemModel =>
            {
                var projectFile = host.GetItemById <IProjectFile>(projectItemModel.Id);
                var psiFile     = projectFile
                                  ?.ToSourceFile()
                                  ?.GetPrimaryPsiFile();
                if (psiFile == null)
                {
                    return(new List <CodeElementModel>());
                }

                var query =
                    from child in psiFile.GetEnvDTEModelChildren()
                    let childId = astManager.GetOrCreateId(child)
                                  let childTypeId = PsiElementRegistrar.GetTypeId(child)
                                                    select new CodeElementModel(childTypeId, childId);
                return(query.ToList());
            });
        }
 public void RegisterCallbacks(
     AstManager astManager,
     ISolution solution,
     ProjectModelViewHost host,
     DteProtocolModel model
     )
 {
     model.Project_get_Name.SetWithReadLock(projectModel => host.GetItemById <IProject>(projectModel.Id)?.Name ?? "");
     model.Project_set_Name.SetWithReadLock(request =>
     {
         string name = request.NewName;
         var project = host.GetItemById <IProject>(request.Model.Id);
         if (project == null)
         {
             return(Unit.Instance);
         }
         solution.InvokeUnderTransaction(cookie => cookie.Rename(project, name));
         return(Unit.Instance);
     });
     model.Project_get_FileName.SetWithReadLock(projectModel =>
                                                host.GetItemById <IProject>(projectModel.Id)?.ProjectFile?.Name ?? "");
     model.Project_Delete.SetWithReadLock(projectModel =>
     {
         var project = host.GetItemById <IProject>(projectModel.Id);
         if (project == null)
         {
             return(Unit.Instance);
         }
         solution.InvokeUnderTransaction(cookie => cookie.Remove(project));
         return(Unit.Instance);
     });
 }
Пример #4
0
        private void FindAndAddAllPreviousSInPreviousNodes(GNode actual, ref List <TNode> resultList, List <TNodeTypeEnum> acceptableType)
        {
            TNode tmp;

            foreach (var p in actual.previousGNodeList)
            {
                if (p.type != GNodeTypeEnum.Ghost)
                {
                    if (resultList.Contains(AstManager.GetInstance().FindNode(p.programLineList[0]))) // jesli resultList zawiera element z tego noda, to ścieżki powrotów się złączyły i należy przerwać powielaną ściężkę
                    {
                        return;
                    }
                    for (int i = p.programLineList.Count() - 1; i >= 0; i--)
                    {
                        tmp = AstManager.GetInstance().FindNode(p.programLineList[i]);
                        if (acceptableType.Contains(tmp.type))
                        {
                            resultList.Add(tmp);
                        }
                    }
                }

                if (p.previousGNodeList.Count() > 0)
                {
                    FindAndAddAllPreviousSInPreviousNodes(p, ref resultList, acceptableType);
                }
            }
        }
Пример #5
0
        private void astCfgButton_Click(object sender, RoutedEventArgs e)
        {
            if (!good)
            {
                return;
            }

            try
            {
                AstManager.GetInstance().GenerateStructures(parsed, pkb);
                addLog("AST Create: Ok");
            }
            catch (Exception ex)
            {
                addLog("AST Create: " + ex.GetType().Name + ": " + ex);
                good = false;
                return;
            }

            try
            {
                CfgManager.GetInstance().GenerateStructure(parsed, pkb);
                addLog("CFG Create: Ok");
            }
            catch (Exception ex)
            {
                addLog("CFG Create: " + ex.GetType().Name + ": " + ex);
                good = false;
                return;
            }
            good = true;
        }
Пример #6
0
        private void FindAndAddAllNextSInNextNodesSpecial(GNode actual, ref List <List <int> > flows, List <int> actualFlow, ref List <int>[] visitedTable, int toInt)
        {
            TNode tmp;

            foreach (var n in actual.nextGNodeList)
            {
                if (!visitedTable[n.index].Contains(n.index))
                {
                    visitedTable[n.index].Add(n.index);

                    if (n.type != GNodeTypeEnum.Ghost)
                    {
                        List <int> newActualFlow = DeepCopy(actualFlow);
                        foreach (var i in n.programLineList)
                        {
                            if (i == toInt)
                            {
                                flows.Add(newActualFlow);
                                return;
                            }
                            tmp = AstManager.GetInstance().FindNode(i);
                            newActualFlow.Add(i);
                        }
                    }
                    if (n.nextGNodeList.Count() > 0)
                    {
                        FindAndAddAllNextSInNextNodesSpecial(n, ref flows, actualFlow, ref visitedTable, toInt);
                    }
                }
            }
        }
 public void RegisterCallbacks(
     AstManager astManager,
     ISolution solution,
     ProjectModelViewHost host,
     DteProtocolModel model
     )
 {
     model.Solution_FileName.SetWithReadLock(() => solution.SolutionFilePath.FullPath);
     model.Solution_Count.SetWithReadLock(() => solution.GetAllProjects().Count);
     model.Solution_Item.SetWithReadLock(index =>
     {
         var projects = solution.GetAllProjects();
         if (projects.Count < index)
         {
             return(new Rider.Model.ProjectModel(-1));
         }
         var project = projects.ElementAt(index - 1);
         int id      = host.GetIdByItem(project);
         return(new Rider.Model.ProjectModel(id));
     });
     model.Solution_get_Projects.SetWithReadLock(() => solution
                                                 .GetAllProjects()
                                                 .Select(host.GetIdByItem)
                                                 .Where(id => id != 0)
                                                 .Select(id => new Rider.Model.ProjectModel(id))
                                                 .AsList());
 }
Пример #8
0
        private void FindAndAddAllNextSInNextNodes(GNode actual, ref List <TNode> resultList, ref List <int>[] visitedTable, List <TNodeTypeEnum> acceptableType)
        {
            TNode tmp;

            foreach (var n in actual.nextGNodeList)
            {
                if (!visitedTable[n.index].Contains(n.index))
                {
                    visitedTable[n.index].Add(n.index);

                    if (n.type != GNodeTypeEnum.Ghost)
                    {
                        foreach (var i in n.programLineList)
                        {
                            tmp = AstManager.GetInstance().FindNode(i);
                            if (acceptableType.Contains(tmp.type) && !resultList.Contains(tmp))
                            {
                                resultList.Add(tmp);
                            }
                        }
                    }
                    if (n.nextGNodeList.Count() > 0)
                    {
                        FindAndAddAllNextSInNextNodes(n, ref resultList, ref visitedTable, acceptableType);
                    }
                }
            }
        }
Пример #9
0
        public List <TNode> PreviousX(TNode p_to, string p_from)
        {
            if (p_to is null)
            {
                return(null);
            }

            List <TNodeTypeEnum> acceptableType = DetermineAcceptableTypes(p_from);
            List <TNode>         candidates;

            if (p_from != "_")
            {
                candidates = AstManager.GetInstance().GetNodes(QueryPreProcessor.GetInstance().declarationsList[p_from]);
            }
            else
            {
                candidates = AstManager.GetInstance().GetNodes("_");
            }
            List <TNode> resultList = new List <TNode>();

            if (candidates is null)
            {
                return(null);
            }

            foreach (var c in candidates)
            {
                if (IsNextX((int)c.programLine, (int)p_to.programLine))
                {
                    resultList.Add(c);
                }
            }

            return(resultList.Count > 0 ? resultList : null);
        }
Пример #10
0
 public void RegisterCallbacks(
     AstManager astManager,
     ISolution solution,
     ProjectModelViewHost host,
     DteProtocolModel model
     )
 {
     AstManager = astManager;
     DoRegisterCallbacks(host, model);
 }
Пример #11
0
 public static QueryProjector GetInstance()
 {
     if (instance == null)
     {
         instance = new QueryProjector();
         instance.queryPreProcessor = QueryPreProcessor.GetInstance();
         instance.queryResult       = QueryResult.GetInstance();
         instance.astManager        = AstManager.GetInstance();
         instance.queryEvaluator    = QueryEvaluator.GetInstance();
     }
     return(instance);
 }
Пример #12
0
        public List <TNode> NextX(TNode p_from, string p_to)
        {
            if (p_from is null)
            {
                return(null);
            }

            List <TNodeTypeEnum> acceptableType = DetermineAcceptableTypes(p_to);


            List <TNode> resultList = new List <TNode>();
            ProcedureCfg cfg        = FindCfg((int)p_from.programLine);

            List <int>[] visitorsTable = new List <int> [cfg.GNodeList.Count()];
            for (int i = 0; i < visitorsTable.Length; i++)
            {
                visitorsTable[i] = new List <int>();
            }
            int   programLinesInNode;
            TNode tmp;

            GNode actual = cfg.GNodeList.Where(p => p.programLineList.Contains((int)p_from.programLine)).FirstOrDefault();

            programLinesInNode = actual.programLineList.Count();

            if (programLinesInNode > 1) // jesli nextS w tym samym nodzie
            {
                for (int i = 0; i < programLinesInNode; i++)
                {
                    if (actual.programLineList[i] == (int)p_from.programLine &&
                        (i + 1) < programLinesInNode)
                    {
                        for (int j = i + 1; j < programLinesInNode; j++)
                        {
                            tmp = AstManager.GetInstance().FindNode(actual.programLineList.ElementAt(j));
                            if (acceptableType.Contains(tmp.type))
                            {
                                resultList.Add(tmp);
                            }
                        }
                    }
                }
            }

            FindAndAddAllNextSInNextNodes(actual, ref resultList, ref visitorsTable, acceptableType);


            return(resultList.Count > 0 ? resultList : null);;
        }
 public void RegisterCallbacks(
     AstManager astManager,
     ISolution solution,
     ProjectModelViewHost host,
     DteProtocolModel model
     )
 {
     model.DTE_Name.SetWithReadLock(() => "JetBrains Rider");
     model.DTE_FileName.SetWithReadLock(() => FileSystemPath
                                        .Parse(AppDomain.CurrentDomain.BaseDirectory)
                                        .Combine(AppDomain.CurrentDomain.FriendlyName)
                                        .FullPath
                                        );
     model.DTE_CommandLineArgs.SetWithReadLock(() => Environment.GetCommandLineArgs().AggregateString(" "));
 }
        private void RegisterCallbacks(
            [NotNull] DteProtocolModel model,
            [NotNull] ISolution solution
            )
        {
            var host = solution.GetComponent <ProjectModelViewHost>();
            // This manager will be stored in closures of callbacks.
            // Since the entire protocol will be deleted on file execution end,
            // this shouldn't cause memory leaks
            var astManager = new AstManager();

            foreach (var provider in solution.GetComponents <IEnvDteCallbackProvider>())
            {
                provider.RegisterCallbacks(astManager, solution, host, model);
            }
        }
Пример #15
0
        public List <TNode> Next(TNode p_from, string p_to)
        {
            if (p_from is null)
            {
                return(null);
            }

            List <TNodeTypeEnum> acceptableType = DetermineAcceptableTypes(p_to);
            TNode        tmp;
            List <TNode> resultList = new List <TNode>();
            ProcedureCfg cfg        = FindCfg((int)p_from.programLine);
            int          programLinesInNode;

            GNode actual = cfg.GNodeList.Where(p => p.programLineList.Contains((int)p_from.programLine)).FirstOrDefault();

            programLinesInNode = actual.programLineList.Count();
            if (programLinesInNode > 1) // jesli next w tym samym nodzie
            {
                for (int i = 0; i < programLinesInNode; i++)
                {
                    if (actual.programLineList[i] == (int)p_from.programLine &&
                        (i + 1) < programLinesInNode)
                    {
                        tmp = AstManager.GetInstance().FindNode(actual.programLineList.ElementAt(i + 1));
                        if (acceptableType.Contains(tmp.type))
                        {
                            resultList.Add(tmp);
                        }

                        return(resultList.Count > 0 ? resultList : null);
                    }
                }
            }
            if (actual.nextGNodeList != null)
            {
                foreach (var nodeNext in actual.nextGNodeList)
                {
                    FindAndAddNextResult(nodeNext, ref resultList, acceptableType);
                }
            }
            else
            {
            }

            return(resultList.Count > 0 ? resultList : null);
        }
Пример #16
0
        private void FindAndAddNextResult(GNode nodeNext, ref List <TNode> resultList, List <TNodeTypeEnum> acceptableType)
        {
            TNode tmp;

            if (nodeNext.type != GNodeTypeEnum.Ghost)
            {
                tmp = AstManager.GetInstance().FindNode(nodeNext.programLineList[0]);
                if (acceptableType.Contains(tmp.type))
                {
                    resultList.Add(tmp);
                }
                return;
            }

            foreach (var p in nodeNext.nextGNodeList)
            {
                FindAndAddNextResult(p, ref resultList, acceptableType);
            }
        }
Пример #17
0
        public List <TNode> Previous(TNode p_to, string p_from)
        {
            if (p_to is null)
            {
                return(null);
            }
            List <TNodeTypeEnum> acceptableType = DetermineAcceptableTypes(p_from);

            List <TNode> resultList = new List <TNode>();
            TNode        tmp;
            ProcedureCfg cfg = FindCfg((int)p_to.programLine);
            int          programLinesInNode;

            GNode actual = cfg.GNodeList.Where(p => p.programLineList.Contains((int)p_to.programLine)).FirstOrDefault();

            programLinesInNode = actual.programLineList.Count();
            if (programLinesInNode > 1) // jesli previous w tym samym nodzie
            {
                for (int i = 0; i < programLinesInNode; i++)
                {
                    if (actual.programLineList[i] == (int)p_to.programLine &&
                        i != 0)
                    {
                        tmp = AstManager.GetInstance().FindNode(actual.programLineList.ElementAt(i - 1));
                        if (acceptableType.Contains(tmp.type))
                        {
                            resultList.Add(tmp);
                        }
                    }
                }
            }

            if (actual.previousGNodeList != null && !resultList.Any())
            {
                foreach (var nodePrevious in actual.previousGNodeList)
                {
                    FindAndAddPreviousResult(nodePrevious, ref resultList, acceptableType);
                }
            }

            return(resultList.Count > 0 ? resultList : null);
        }
Пример #18
0
        public bool IsNext(int p1, int p2)
        {
            if (OutOfRange(p1) || OutOfRange(p2))
            {
                return(false);
            }
            List <TNode> nextList = this.Next(AstManager.GetInstance().FindNode(p1), p2.ToString());

            if (nextList != null)
            {
                foreach (var v in nextList)
                {
                    if (v.programLine == p2)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #19
0
        static void Main(string[] args)
        {
            string SourceCode = "";
            PkbAPI pkb;

            if (args.Length == 0)
            {
                Console.WriteLine("No parameter with path to file");
                Console.WriteLine("Program exit.");
                return;
            }

            string path = args[0];

            try
            {
                SourceCode = File.ReadAllText(path);
                Console.WriteLine("File ok: " + path);

                SourceCode = ParserByTombs.Instance.Parse(SourceCode);
                Console.WriteLine("Source Parsed ok");

                pkb = ParserByTombs.Instance.pkb;
                QueryEvaluator.GetInstance().pkb = pkb;
                QueryProjector.GetInstance().Pkb = pkb;
                Console.WriteLine("PKB ok");

                AstManager.GetInstance().GenerateStructures(SourceCode, pkb);
                Console.WriteLine("AST ok");

                CfgManager.GetInstance().GenerateStructure(SourceCode, pkb);
                Console.WriteLine("CFG ok");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Before");
                Console.WriteLine(ex.GetType().Name + ": " + ex);
            }
            Console.WriteLine("Ready");

            int i = 0;

            while (true)
            {
                string answer = "";
                string query  = Console.ReadLine();
                query += " " + Console.ReadLine();

                try
                {
                    query = QueryPreProcessor.GetInstance().Parse(query);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("#" + ex.GetType().Name + ": " + ex.Message);
                    continue;
                }

                try
                {
                    List <Condition> conditionsList = QueryPreProcessor.GetInstance().conditionsList;
                    QueryEvaluator.GetInstance().Evaluate(conditionsList);
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    try
                    {
                        QueryResult    queryResult    = QueryResult.GetInstance();
                        QueryProjector queryProjector = QueryProjector.GetInstance();
                        answer = queryProjector.PrintResult();
                    }
                    catch (Exception ex)
                    {
                        answer = "none";
                    }
                }
                Console.WriteLine(answer);
            }

            Console.WriteLine("Program exit.");
            return;
        }