Beispiel #1
0
        private void 打开项目ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog FBD = new FolderBrowserDialog();

            // if (FBD.ShowDialog() == DialogResult.OK || FBD.ShowDialog() == DialogResult.Yes)
            // {
            try
            {
                FBD.ShowDialog();
                if (FBD.SelectedPath != null)
                {
                    SetToDefault();
                    string beginPath = FBD.SelectedPath;
                    rootPath = beginPath;
                    DirectoryInfo    tempDI = new DirectoryInfo(beginPath);
                    EveryProjectInfo tempPI = CreateInfo(tempDI);
                    CreateTree(null, tempPI);
                }
            }
            catch
            {
                AppendDebugArea("打开地址不对!\n");
            }
            // }
        }
Beispiel #2
0
        /// <summary>
        /// 使用Splint分析整个工程
        /// </summary>
        private void UseSplintToAnalyzeProjectFile()
        {
            string commandLine = "";

            for (int i = 0; i <= projectInfoList.length() - 1; i++)
            {
                commandLine += projectInfoList.getProjectInfoAt(i).fileInfo.FullName;
                commandLine += " ";
            }
            string ans = myRunProcess.Run(@".\splint.exe", ff.getFlagCommand() + commandLine);

            AppendDebugArea("项目使用Splint分析完毕\n");

            string[] ansArray = ans.Split(new[] { "\r\n" }, StringSplitOptions.None);
            // string[] ajustedArray=adjustAnsArray(ansArray);
            string adjustedString = adjustAnsArray(ansArray);

            projectWholeAns = adjustedString;

            for (int i = 0; i <= projectInfoList.length() - 1; i++)
            {
                projectInfoList.getProjectInfoAt(i).ans = adjustedString;
            }
            curProjectInfo = projectInfoList.getProjectInfoAt(projectInfoList.length() - 1);
        }
Beispiel #3
0
        private void 用Splint生成本项目ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EveryProjectInfo temp = new EveryProjectInfo();

            if (projectInfoList.length() > 0)
            {
                TB_DebugInfo.Text = "";//Clear
                for (int i = 0; i <= projectInfoList.length() - 1; i++)
                {
                    temp = projectInfoList.getProjectInfoAt(i);
                    if (temp != null)
                    {
                        UseSplintToAnalyzeSingleFile(temp);
                    }
                }
                if (temp != null)
                {
                    curProjectInfo = temp;
                    SetAnalysisAnsOnly(curProjectInfo.ans);
                    SetCodeArea(curProjectInfo.fileInfo.Name, curProjectInfo.Code);
                    if (TV_ProjectInfo.SelectedNode != null)
                    {
                        TV_ProjectInfo.SelectedNode.Checked = false;
                    }
                    //Focus到调试窗口
                    ChangeFocusOfTreeView();
                }
            }
            else
            {
                AppendDebugArea("当前打开目录为空!\n");
            }
        }
Beispiel #4
0
        private EveryProjectInfo CreateInfo(DirectoryInfo di)
        {
            //代码,文件信息
            EveryProjectInfo everyProjectInfo = new EveryProjectInfo();

            everyProjectInfo.directoryInfo = di;
            everyProjectInfo.infoType      = EveryProjectInfo.projectInfoType.dInfo;
            return(everyProjectInfo);
        }
Beispiel #5
0
        /// <summary>
        /// 打开文件后创建文件信息
        /// </summary>
        /// <param name="fi"></param>
        /// <returns></returns>
        private EveryProjectInfo CreateInfo(FileInfo fi)
        {
            //代码,文件信息
            EveryProjectInfo everyProjectInfo = new EveryProjectInfo();

            everyProjectInfo.fileInfo = fi;
            everyProjectInfo.Code     = ReadCodeFromFile(fi);
            everyProjectInfo.infoType = EveryProjectInfo.projectInfoType.fInfo;
            return(everyProjectInfo);
        }
Beispiel #6
0
 public void updateProjectInfo(EveryProjectInfo fi)
 {
     for (int i = ProjectInfoL.Count - 1; i >= 0; i--)
     {
         if (ProjectInfoL[i].fileInfo.FullName == fi.fileInfo.FullName)
         {
             ProjectInfoL[i] = fi;
         }
     }
 }
Beispiel #7
0
        public EveryProjectInfo getProjectInfoAt(int index)
        {
            EveryProjectInfo temp = new EveryProjectInfo();

            if (index <= ProjectInfoL.Count - 1)
            {
                temp = ProjectInfoL[index];
                return(temp);
            }
            return(null);
        }
Beispiel #8
0
        /// <summary>
        /// 使用Splint分析特定文件,注意判空。
        /// </summary>
        /// <param name="fi"></param>
        private void UseSplintToAnalyzeSingleFile(EveryProjectInfo fi)
        {
            string ans = myRunProcess.Run(@".\splint.exe", ff.getFlagCommand() + fi.fileInfo.FullName);

            string[] ansArray = ans.Split(new[] { "\r\n" }, StringSplitOptions.None);
            ansArray1 = ansArray;
            // string[] ajustedArray=adjustAnsArray(ansArray);
            string adjustedString = adjustAnsArray(ansArray);

            fi.ans = adjustedString;
            projectInfoList.updateProjectInfo(fi);
            AppendDebugArea(fi.fileInfo.Name + "使用Splint分析完毕\n");
        }
Beispiel #9
0
        private void SetToDefault()
        {
            analyzed = false;
            TV_ProjectInfo.Nodes.Clear();

            SetCodeOnly("");

            TB_DebugInfo.Text     = "";
            TB_AnalyzeResult.Text = "";
            L_SourceFileName.Text = "源文件名";
            projectInfoList       = new ProjectInfoList();
            curProjectInfo        = null;
            projectWholeAns       = "";
            rootPath = "";
        }
Beispiel #10
0
        /// <summary>
        /// Itemheader or FileInfoName
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        //public FileInfo FindFileInfoByTreeViewItemName(string name)
        //{


        //}
        public void RegisterProjecInfo(EveryProjectInfo tempEPI)
        {
            for (int i = ProjectInfoL.Count - 1; i >= 0; i--)
            {
                if (ProjectInfoL[i].infoType == EveryProjectInfo.projectInfoType.fInfo)
                {
                    if (ProjectInfoL[i].fileInfo.FullName == tempEPI.fileInfo.FullName)
                    {
                        ProjectInfoL[i] = tempEPI;
                        return;
                    }
                }
            }
            ProjectInfoL.Add(tempEPI);
            return;
        }
Beispiel #11
0
 /// <summary>
 /// 双击输出结果是使用
 /// </summary>
 private void AnalyzeResult_NodeMouseDoubleClick(EveryProjectInfo e)
 {
     if (e.fileInfo.Name.EndsWith(".c") || e.fileInfo.Name.EndsWith(".h"))
     {
         curProjectInfo = e;
         if (curProjectInfo == null)
         {
             AppendDebugArea("读取出错,重置数据!\n");
             SetToDefault();
         }
         else
         {
             SetCodeArea(curProjectInfo.fileInfo.Name, curProjectInfo.Code);
         }
     }
 }
Beispiel #12
0
        /// <summary>
        /// 自动创建TreeView节点。
        /// </summary>
        /// <param name="parNode"></param>
        /// <param name="everyProjectInfo"></param>
        private void CreateNode(TreeNode parNode, EveryProjectInfo everyProjectInfo)
        {
            TreeNode tempTreeNode = new TreeNode();

            SetNodeInfo(tempTreeNode, everyProjectInfo.fileInfo);
            if (parNode == null)
            {
                TV_ProjectInfo.Nodes.Add(tempTreeNode);
                everyProjectInfo.treeItem = tempTreeNode;
            }
            else
            {
                parNode.Nodes.Add(tempTreeNode);
                everyProjectInfo.treeItem = tempTreeNode;
            }
        }
Beispiel #13
0
 private void TV_ProjectInfo_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
 {
     if (e.Node.Name.EndsWith(".c") || e.Node.Name.EndsWith(".h"))
     {
         EveryProjectInfo temp = projectInfoList.getProjectInfoByFullName(e.Node.Name);
         if (temp != curProjectInfo)
         {
             curProjectInfo = temp;
             if (curProjectInfo == null)
             {
                 AppendDebugArea("读取出错,重置数据!\n");
                 SetToDefault();
             }
             else
             {
                 SetCodeArea(curProjectInfo.fileInfo.Name, curProjectInfo.Code);
                 SetAnalysisAnsOnly(curProjectInfo.ans);
             }
         }
     }
 }
Beispiel #14
0
        private void 打开文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog OFD = new OpenFileDialog();

            OFD.Filter = "(*.c,*.h)|*.c|(*.c,*.h)|*.h";
            if (OFD.ShowDialog() == DialogResult.OK)
            {
                //清空
                SetToDefault();

                FileInfo         SingleFileInformation = new FileInfo(OFD.FileName);
                EveryProjectInfo tempProjectInfo       = CreateInfo(SingleFileInformation); //生成INFO
                rootPath = tempProjectInfo.fileInfo.FullName;                               //保存文件地址
                CreateNode(null, tempProjectInfo);                                          //添加到Tree
                projectInfoList.RegisterProjecInfo(tempProjectInfo);
                curProjectInfo = tempProjectInfo;
                SetCodeArea(curProjectInfo.fileInfo.Name, curProjectInfo.Code);
                ChangeSourceFileNameLabel(curProjectInfo.fileInfo.Name);
                TB_CodeArea.Focus();
            }
        }
Beispiel #15
0
 private void 用Splint整体分析项目文件ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (projectInfoList.length() > 0)
     {
         TB_AnalyzeResult.Text = "";
         TB_CodeArea.Text      = "";
         TB_DebugInfo.Text     = "";
         EveryProjectInfo temp = new EveryProjectInfo();
         UseSplintToAnalyzeProjectFile();
         SetAnalysisAnsOnly(curProjectInfo.ans);
         SetCodeArea(curProjectInfo.fileInfo.Name, curProjectInfo.Code);
         if (TV_ProjectInfo.SelectedNode != null)
         {
             TV_ProjectInfo.SelectedNode.Checked = false;
         }
         analyzed = true;
         //Focus到调试窗口
         ChangeFocusOfTreeView();
     }
     else
     {
         AppendDebugArea("Error:No file opened");
     }
 }
Beispiel #16
0
        private void TB_AnalyzeResult_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (TB_AnalyzeResult.Text != "")
            {
                int    lineIndex      = TB_AnalyzeResult.SelectionStart;
                int    line           = TB_AnalyzeResult.GetLineFromCharIndex(lineIndex);
                string pattern        = @"\(\d+?,\d+?\)";
                string thisLineString = TB_AnalyzeResult.Lines[line];

                //Match match = System.Text.RegularExpressions.Regex.Match(thisLineString, pattern);
                //if (match.Success == true && thisLineString.Contains(curProjectInfo.fileInfo.FullName))
                //{
                //    string value = match.Groups[0].Value;
                //    char[] charValue = value.ToCharArray();
                //    char[] tempCharArray = new char[1000];
                //    int index = value.IndexOf(',');
                //    for (int i = 1; i <= index - 1; i++)
                //    {
                //        tempCharArray[i - 1] = charValue[i];
                //    }
                //    int codeLine = Convert.ToInt32(new string(tempCharArray));

                //    TB_CodeArea.Selection.Start = TB_CodeArea.Lines[codeLine - 1].StartPosition;
                //    TB_CodeArea.Selection.End = TB_CodeArea.Lines[codeLine - 1].EndPosition;
                //    //   TB_CodeArea.SelectionStart = TB_CodeArea.GetFirstCharIndexFromLine(codeLine - 1);
                //    //   TB_CodeArea.SelectionLength = TB_CodeArea.Lines[codeLine - 1].Length;
                //    TB_CodeArea.Focus();
                //}
                int   flag  = 0;
                Match match = System.Text.RegularExpressions.Regex.Match(thisLineString, pattern);
                if (match.Success == true)
                {
                    EveryProjectInfo tempEPI = new EveryProjectInfo();
                    for (int i = 0; i < projectInfoList.length(); i++)
                    {
                        tempEPI = projectInfoList.getProjectInfoAt(i);
                        if (tempEPI.infoType == EveryProjectInfo.projectInfoType.fInfo)
                        {
                            if (thisLineString.Contains(tempEPI.fileInfo.FullName) == true)
                            {
                                flag = 1;
                                break;
                            }
                        }
                    }
                    if (flag == 1)
                    {
                        string value         = match.Groups[0].Value;
                        char[] charValue     = value.ToCharArray();
                        char[] tempCharArray = new char[1000];
                        int    index         = value.IndexOf(',');
                        for (int i = 1; i <= index - 1; i++)
                        {
                            tempCharArray[i - 1] = charValue[i];
                        }
                        int codeLine = Convert.ToInt32(new string(tempCharArray));
                        AnalyzeResult_NodeMouseDoubleClick(tempEPI);
                        TB_CodeArea.Selection.Start = TB_CodeArea.Lines[codeLine - 1].StartPosition;
                        TB_CodeArea.Selection.End   = TB_CodeArea.Lines[codeLine - 1].EndPosition;
                        //   TB_CodeArea.SelectionStart = TB_CodeArea.GetFirstCharIndexFromLine(codeLine - 1);
                        //   TB_CodeArea.SelectionLength = TB_CodeArea.Lines[codeLine - 1].Length;
                        TB_CodeArea.Focus();
                    }
                }
            }
        }
Beispiel #17
0
        private void CreateTree(TreeNode parNode, EveryProjectInfo everyProjectInfo)
        {
            TreeNode tempTreeNode = new TreeNode();

            if (everyProjectInfo.infoType == EveryProjectInfo.projectInfoType.dInfo)
            {
                SetNodeInfo(tempTreeNode, everyProjectInfo.directoryInfo);
            }
            else if (everyProjectInfo.infoType == EveryProjectInfo.projectInfoType.fInfo)
            {
                SetNodeInfo(tempTreeNode, everyProjectInfo.fileInfo);
            }

            if (parNode == null)
            {
                TV_ProjectInfo.Nodes.Add(tempTreeNode);
                everyProjectInfo.treeItem = tempTreeNode;

                if (everyProjectInfo.infoType == EveryProjectInfo.projectInfoType.dInfo)
                {
                    //文件夹
                    foreach (string dirPath in Directory.GetDirectories(everyProjectInfo.directoryInfo.FullName))
                    {
                        DirectoryInfo    tempDI = new DirectoryInfo(dirPath);
                        EveryProjectInfo tempPI = CreateInfo(tempDI);
                        CreateTree(tempTreeNode, tempPI);
                    }
                    //文件
                    foreach (string filePath in Directory.GetFiles(everyProjectInfo.directoryInfo.FullName))
                    {
                        FileInfo tempDI = new FileInfo(filePath);
                        if (tempDI.Name.EndsWith(".c") || tempDI.Name.EndsWith(".h"))
                        {
                            EveryProjectInfo tempPI      = CreateInfo(tempDI);
                            TreeNode         sonTreeNode = new TreeNode();
                            SetNodeInfo(sonTreeNode, tempDI);

                            tempTreeNode.Nodes.Add(sonTreeNode);
                            tempPI.treeItem = sonTreeNode;
                            projectInfoList.RegisterProjecInfo(tempPI);
                            //  curProjectInfo = tempPI;
                        }
                    }
                }
                else
                {
                    projectInfoList.RegisterProjecInfo(everyProjectInfo);
                    // curProjectInfo = everyProjectInfo;
                }
            }
            else
            {
                parNode.Nodes.Add(tempTreeNode);
                everyProjectInfo.treeItem = tempTreeNode;
                if (everyProjectInfo.infoType == EveryProjectInfo.projectInfoType.dInfo)
                {
                    foreach (string dirPath in Directory.GetDirectories(everyProjectInfo.directoryInfo.FullName))
                    {
                        DirectoryInfo    tempDI = new DirectoryInfo(dirPath);
                        EveryProjectInfo tempPI = CreateInfo(tempDI);
                        CreateTree(tempTreeNode, tempPI);
                    }
                    //如果是文件的话,继续扩展
                    foreach (string filePath in Directory.GetFiles(everyProjectInfo.directoryInfo.FullName))
                    {
                        FileInfo tempDI = new FileInfo(filePath);
                        if (tempDI.Name.EndsWith(".c") || tempDI.Name.EndsWith(".h"))
                        {
                            EveryProjectInfo tempPI      = CreateInfo(tempDI);
                            TreeNode         sonTreeNode = new TreeNode();
                            SetNodeInfo(sonTreeNode, tempDI);
                            tempTreeNode.Nodes.Add(sonTreeNode);
                            tempPI.treeItem = sonTreeNode;
                            projectInfoList.RegisterProjecInfo(tempPI);
                            //  curProjectInfo = tempPI ;
                        }
                    }
                }
                else
                {
                    projectInfoList.RegisterProjecInfo(everyProjectInfo);
                    // curProjectInfo = everyProjectInfo;
                }
            }
        }