Example #1
0
        public void Analyze(Deque <AnalysisUnit> queue, CancellationToken cancel, Action <int> reportQueueSize = null, int reportQueueInterval = 1)
        {
            if (cancel.IsCancellationRequested)
            {
                return;
            }
            try {
                // Including a marker at the end of the queue allows us to see in
                // the log how frequently the queue empties.
                var endOfQueueMarker  = new AnalysisUnit(null, null);
                int queueCountAtStart = queue.Count;
                int reportInterval    = reportQueueInterval - 1;

                if (queueCountAtStart > 0)
                {
                    queue.Append(endOfQueueMarker);
                }

                while (queue.Count > 0 && !cancel.IsCancellationRequested)
                {
                    _unit = queue.PopLeft();

                    if (_unit == endOfQueueMarker)
                    {
                        AnalysisLog.EndOfQueue(queueCountAtStart, queue.Count);
                        if (reportInterval < 0 && reportQueueSize != null)
                        {
                            reportQueueSize(queue.Count);
                        }

                        queueCountAtStart = queue.Count;
                        if (queueCountAtStart > 0)
                        {
                            queue.Append(endOfQueueMarker);
                        }
                        continue;
                    }

                    AnalysisLog.Dequeue(queue, _unit);
                    if (reportInterval == 0 && reportQueueSize != null)
                    {
                        reportQueueSize(queue.Count);
                        reportInterval = reportQueueInterval - 1;
                    }
                    else if (reportInterval > 0)
                    {
                        reportInterval -= 1;
                    }

                    _unit.IsInQueue = false;
                    SetCurrentUnit(_unit);
                    AnalyzedEntries.Add(_unit.ProjectEntry);
                    _unit.Analyze(this, cancel);
                }

                if (reportQueueSize != null)
                {
                    reportQueueSize(0);
                }

                if (cancel.IsCancellationRequested)
                {
                    AnalysisLog.Cancelled(queue);
                }
            } finally {
                AnalysisLog.Flush();
                AnalyzedEntries.Remove(null);
            }
        }
Example #2
0
 public void TestInitialize()
 {
     AnalysisLog.Reset();
     AssertListener.Initialize();
 }
Example #3
0
        public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
        {
            var callArgs = ArgumentSet.FromArgs(FunctionDefinition, unit, args, keywordArgNames);

            FunctionAnalysisUnit calledUnit;
            bool updateArguments = true;

            if (callArgs.Count == 0 ||
                (ProjectState.Limits.UnifyCallsToNew && Name == "__new__") ||
                _callDepthLimit == 0)
            {
                calledUnit = (FunctionAnalysisUnit)AnalysisUnit;
            }
            else
            {
                if (_allCalls == null)
                {
                    _allCalls = new CallChainSet <FunctionAnalysisUnit>();
                }

                var chain = new CallChain(node, unit, _callDepthLimit);
                if (!_allCalls.TryGetValue(unit.ProjectEntry, chain, _callDepthLimit, out calledUnit))
                {
                    if (unit.ForEval)
                    {
                        // Call expressions that weren't analyzed get the union result
                        // of all calls to this function.
                        var res = AnalysisSet.Empty;
                        foreach (var call in _allCalls.Values)
                        {
                            res = res.Union(call.ReturnValue.TypesNoCopy);
                        }
                        return(res);
                    }
                    else
                    {
                        _callsSinceLimitChange += 1;
                        if (_callsSinceLimitChange >= ProjectState.Limits.DecreaseCallDepth && _callDepthLimit > 1)
                        {
                            _callDepthLimit       -= 1;
                            _callsSinceLimitChange = 0;
                            AnalysisLog.ReduceCallDepth(this, _allCalls.Count, _callDepthLimit);

                            _allCalls.Clear();
                            chain = chain.Trim(_callDepthLimit);
                        }
                        calledUnit = new FunctionAnalysisUnit((FunctionAnalysisUnit)AnalysisUnit, chain, callArgs);
                        _allCalls.Add(unit.ProjectEntry, chain, calledUnit);
                        updateArguments = false;
                    }
                }
            }

            if (updateArguments && calledUnit.UpdateParameters(callArgs))
            {
                AnalysisLog.UpdateUnit(calledUnit);
            }
            if (keywordArgNames != null && keywordArgNames.Any())
            {
                calledUnit.AddNamedParameterReferences(unit, keywordArgNames);
            }

            calledUnit.ReturnValue.AddDependency(unit);
            return(calledUnit.ReturnValue.Types);
        }
Example #4
0
 private void UpdateOutputLog(string msg)
     => SynchronizationContext.Post(new SendOrPostCallback(updateMsg =>
     {
         AnalysisLog.AppendText((string)updateMsg + Environment.NewLine);
     }), msg);
 public void TestInitialize()
 {
     AnalysisLog.Reset();
     TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}");
 }
Example #6
0
 public void StartAnalysisLog()
 {
     AnalysisLog.Reset();
     AnalysisLog.Output = Console.Out;
 }
Example #7
0
 private void ClearOutputLog()
     => AnalysisLog.Clear();
Example #8
0
 public void StartAnalysisLog()
 {
     AnalysisLog.Reset();
     AnalysisLog.OutputToConsole = true;
 }
Example #9
0
 static BaseAnalysisTest()
 {
     AnalysisLog.Reset();
     AssertListener.Initialize();
 }
Example #10
0
        public void Check()
        {
            ZipFileManager.ZipFileManager zfm = new ZipFileManager.ZipFileManager();
            ClsNameRuleTest cnt = new ClsNameRuleTest();

            ExcelParser.ExcelParser ep = new ExcelParser.ExcelParser();
            string        zipFilePath  = "";
            List <string> filePaths    = null;

            try
            {
                zipFilePath = zfm.UnZip(@"C:\Users\v-misun\Desktop\a\报告.zip");
                filePaths   = zfm.FindFile(zipFilePath, "*知识领域覆盖表*.*");
            }
            catch (Exception x)
            {
                AnalysisLog.AddLog("【系统】" + x.Message);
                return;
            }

            if (filePaths.Count() == 0)
            {
                AnalysisLog.AddLog("【系统】未找到知识领域覆盖表");
                return;
            }
            foreach (var path in filePaths)
            {
                try
                {
                    ep.Init(path);
                }
                catch (Exception x)
                {
                    AnalysisLog.AddLog("【系统】" + x.Message);
                    return;
                }

                try
                {
                    // 数学+自然科学类占总分不得低于15%
                    int score      = ep.GetScore("数学类") + ep.GetScore("自然科学类");
                    int totalScore = ep.GetTotalScore();
                    if ((double)score / (double)totalScore < 0.15)
                    {
                        AnalysisLog.AddLog(string.Format("【期望】数学+自然科学类占总分不得低于15%   【实际】{0:P2}", (double)score / (double)totalScore));
                    }
                }
                catch (Exception x)
                {
                    AnalysisLog.AddLog("【系统】" + x.Message);
                }

                try
                {
                    // 数学类课程名包含或者不得包含规则
                    List <ClassWithScore> classList = ep.GetClassName("数学类");
                    foreach (var c in classList)
                    {
                        bool ret = cnt.TestName(c.ClassName, "数学类");
                        if (ret == false)
                        {
                            AnalysisLog.AddLog(string.Format("【期望】数学类课程名包含或者不得包含规则   【实际】数学类课程名包含{0}", c.ClassName));
                        }
                    }
                }
                catch (Exception x)
                {
                    AnalysisLog.AddLog("【系统】" + x.Message);
                }

                try
                {
                    // 需存在教学大纲
                    List <string>      subjectFilePaths = zfm.FindFile(zipFilePath, "*教学大纲.*");
                    SubjectParserCheck sp = new SubjectParserCheck();
                    if (subjectFilePaths.Count() == 0)
                    {
                        AnalysisLog.AddLog("【系统】无法找到教学大纲");
                    }
                    else
                    {
                        string subjectFilePath = subjectFilePaths[0];
                        sp.Init(subjectFilePath);
                        // 专业核心课在课程大纲出出现
                        List <string> professionalCoreClassList = ep.GetProfessinalCoreClass();
                        if (professionalCoreClassList.Count() > 0)
                        {
                            foreach (var i in professionalCoreClassList)
                            {
                                var ret = sp.FindClass(i);
                                if (ret == false)
                                {
                                    AnalysisLog.AddLog(string.Format("【期望】专业核心课在教学大纲出现  【实际】课程{0}没有出现", i));
                                }
                            }
                        }
                        else
                        {
                            AnalysisLog.AddLog("【期望】专业核心课在教学大纲出现    【实际】未找到专业核心课");
                        }
                    }
                }
                catch (Exception x)
                {
                    AnalysisLog.AddLog("【系统】" + x.Message);
                }

                try
                {
                    // 需存在培养方案
                    List <string>             trainingFilePaths = zfm.FindFile(zipFilePath, "*培养方案.*");
                    TrainingPlan.TrainingPlan tp = new TrainingPlan.TrainingPlan();
                    if (trainingFilePaths.Count() == 0)
                    {
                        AnalysisLog.AddLog("【系统】无法找到培养方案");
                    }
                    else
                    {
                        string trainingFilePath = trainingFilePaths[0];
                        tp.Init(trainingFilePath);
                        // 课程和学分在培养方案中可查询到
                        List <ClassWithScore> allClassWithScore = new List <ClassWithScore>();
                        allClassWithScore.Concat(ep.GetClassName("数学类"));
                        foreach (var i in allClassWithScore)
                        {
                            // 检查是否有课程
                            var isFindClass = tp.FindClass(i.ClassName);
                            if (isFindClass)
                            {
                                var isFindClassAndScore = tp.FindClassAndScore(i.ClassName, i.Score);
                                if (!isFindClassAndScore)
                                {
                                    AnalysisLog.AddLog(string.Format("【期望】课程{0}与学分{1}在培养方案中存在    【实际】课程{0}学分与期望不符合", i.ClassName, i.Score));
                                }
                            }
                            else
                            {
                                AnalysisLog.AddLog(string.Format("【期望】课程{0}与学分{1}在培养方案中存在    【实际】课程{0}不存在", i.ClassName, i.Score));
                            }
                        }
                    }
                }catch (Exception x)
                {
                    AnalysisLog.AddLog("【系统】" + x.Message);
                }
            }
            ep.Dispose();
        }
 static BaseAnalysisTest()
 {
     AnalysisLog.Reset();
 }
        public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
        {
            var callArgs = ArgumentSet.FromArgs(FunctionDefinition, unit, args, keywordArgNames);

            if (keywordArgNames != null && keywordArgNames.Any())
            {
                _analysisUnit.AddNamedParameterReferences(unit, keywordArgNames);
            }

            var res = DoCall(node, unit, _analysisUnit, callArgs);

            if (_derived != null)
            {
                foreach (FunctionInfo derived in _derived)
                {
                    var derivedResult = derived.DoCall(node, unit, derived._analysisUnit, callArgs);
                    res = res.Union(derivedResult);
                }
            }

            if (_analysisUnit.State.Limits.PropagateParameterTypeToBaseMethods &&
                _analysisUnit.Scope.OuterScope is ClassScope parentClass)
            {
                var baseMethods = DDG.LookupBaseMethods(Name, parentClass.Class.Mro, AnalysisUnit.Ast, AnalysisUnit);
                foreach (FunctionInfo baseMethod in baseMethods.OfType <FunctionInfo>())
                {
                    baseMethod.DoCall(node, unit, baseMethod._analysisUnit, callArgs);
                }
            }

            if (_callsWithClosure != null)
            {
                var chain     = new CallChain(node, unit, _callDepthLimit);
                var aggregate = GetAggregate(unit);

                if (!_callsWithClosure.TryGetValue(aggregate, chain, _callDepthLimit, out var calledUnit) &&
                    !unit.ForEval)
                {
                    _callsSinceLimitChange += 1;
                    if (_callsSinceLimitChange >= ProjectState.Limits.DecreaseCallDepth && _callDepthLimit > 1)
                    {
                        _callDepthLimit       -= 1;
                        _callsSinceLimitChange = 0;
                        AnalysisLog.ReduceCallDepth(this, _callsWithClosure.Count, _callDepthLimit);

                        _callsWithClosure.Clear();
                        chain = chain.Trim(_callDepthLimit);
                    }

                    calledUnit = new FunctionClosureAnalysisUnit(aggregate, (FunctionAnalysisUnit)AnalysisUnit, chain);
                    _callsWithClosure.Add(aggregate, chain, calledUnit);
                    calledUnit.Enqueue();
                }

                Debug.Assert(calledUnit != null || unit.ForEval);

                res.Split(v => v.IsResolvable(), out _, out var nonLazy);
                res = DoCall(node, unit, calledUnit, callArgs);
                res = res.Union(nonLazy);
            }

            var context = unit.ForEval ? ResolutionContext.Complete : new ResolutionContext {
                Caller   = this,
                CallArgs = callArgs,
                CallSite = node
            };

            var r = res.Resolve(unit, context, out _);

            return(r);
        }