コード例 #1
0
 public SelectCaseStmtContextWrapper(VBAParser.SelectCaseStmtContext selectCaseContext, IParseTreeVisitorResults inspValues, IUnreachableCaseInspectionFactoryProvider factoryFactory)
     : base(selectCaseContext, inspValues, factoryFactory)
 {
     _selectCaseContext      = selectCaseContext;
     _unreachableResults     = new List <ParserRuleContext>();
     _mismatchResults        = new List <ParserRuleContext>();
     _caseElseResults        = new List <ParserRuleContext>();
     _inspectionRangeFactory = factoryFactory.CreateIRangeClauseContextWrapperFactory();
     SetEvaluationTypeName(Context, ParseTreeValueResults, FilterFactory);
 }
コード例 #2
0
 public UnreachableCaseInspector(VBAParser.SelectCaseStmtContext selectCaseContext,
                                 IParseTreeVisitorResults inspValues,
                                 IParseTreeValueFactory valueFactory,
                                 Func <string, ParserRuleContext, string> GetVariableTypeName = null)
 {
     _valueFactory    = valueFactory;
     _caseClauses     = selectCaseContext.caseClause();
     _caseElseContext = selectCaseContext.caseElseClause();
     GetVariableDeclarationTypeName = GetVariableTypeName;
     ParseTreeValueResults          = inspValues;
     SetSelectExpressionTypeName(selectCaseContext as ParserRuleContext, inspValues);
 }
コード例 #3
0
 public void Resolve(VBAParser.SelectCaseStmtContext context)
 {
     ResolveDefault(context.selectExpression().expression());
     if (context.caseClause() == null)
     {
         return;
     }
     foreach (var caseClause in context.caseClause())
     {
         foreach (var rangeClause in caseClause.rangeClause())
         {
             if (rangeClause.expression() != null)
             {
                 ResolveDefault(rangeClause.expression());
             }
             else
             {
                 ResolveDefault(rangeClause.selectStartValue().expression());
                 ResolveDefault(rangeClause.selectEndValue().expression());
             }
         }
     }
 }
コード例 #4
0
 public override void EnterSelectCaseStmt(VBAParser.SelectCaseStmtContext context)
 {
     _resolver.Resolve(context);
 }
コード例 #5
0
 public IUnreachableCaseInspector Create(VBAParser.SelectCaseStmtContext selectStmt, IParseTreeVisitorResults results, IParseTreeValueFactory valueFactory, Func <string, ParserRuleContext, string> func = null)
 {
     return(new UnreachableCaseInspector(selectStmt, results, valueFactory, func));
 }
コード例 #6
0
 public ISelectCaseStmtContextWrapper Create(VBAParser.SelectCaseStmtContext selectStmt, IParseTreeVisitorResults results)
 {
     return(new SelectCaseStmtContextWrapper(selectStmt, results, FactoryProvider));
 }
コード例 #7
0
 public override void EnterSelectCaseStmt([NotNull] VBAParser.SelectCaseStmtContext context)
 {
     _contexts.Add(new QualifiedContext <ParserRuleContext>(CurrentModuleName, context));
 }
コード例 #8
0
        private string DeriveTypeFromCaseClauses(IParseTreeVisitorResults inspValues, VBAParser.SelectCaseStmtContext selectStmt)
        {
            var caseClauseTypeNames = new List <string>();

            foreach (var caseClause in selectStmt.caseClause())
            {
                foreach (var range in caseClause.rangeClause())
                {
                    if (TryDetectTypeHint(range.GetText(), out string hintTypeName))
                    {
                        caseClauseTypeNames.Add(hintTypeName);
                    }
                    else
                    {
                        var inspRange = _inspectionRangeFactory.Create(range, inspValues);
                        var types     = inspRange.ResultContexts.Select(rc => inspValues.GetTypeName(rc))
                                        .Where(tp => InspectableTypes.Contains(tp));
                        caseClauseTypeNames.AddRange(types);
                    }
                }
            }

            if (TryDetermineEvaluationTypeFromTypes(caseClauseTypeNames, out string evalTypeName))
            {
                return(evalTypeName);
            }
            return(string.Empty);
        }
コード例 #9
0
 public override void EnterSelectCaseStmt(VBAParser.SelectCaseStmtContext context)
 {
     CheckContext(context, context.END_SELECT());
     base.EnterSelectCaseStmt(context);
 }
コード例 #10
0
        private string DeriveTypeFromCaseClauses(IParseTreeVisitorResults inspValues, VBAParser.SelectCaseStmtContext selectStmt)
        {
            var caseClauseTypeNames = new List <string>();

            foreach (var caseClause in selectStmt.caseClause())
            {
                foreach (var range in caseClause.rangeClause())
                {
                    if (TryDetectTypeHint(range.GetText(), out string hintTypeName))
                    {
                        caseClauseTypeNames.Add(hintTypeName);
                    }
                    else
                    {
                        var typeNames = from context in range.children
                                        where context is ParserRuleContext &&
                                        IsResultContext(context)
                                        select inspValues.GetValueType(context as ParserRuleContext);

                        caseClauseTypeNames.AddRange(typeNames);
                        caseClauseTypeNames.RemoveAll(tp => !InspectableTypes.Contains(tp));
                    }
                }
            }

            if (TryGetSelectExpressionTypeNameFromTypes(caseClauseTypeNames, out string evalTypeName))
            {
                return(evalTypeName);
            }
            return(string.Empty);
        }