예제 #1
0
 public RangeClauseContextWrapper(VBAParser.RangeClauseContext context, IParseTreeVisitorResults inspValues, IUnreachableCaseInspectionFactoryProvider factoryFactory)
     : base(context, inspValues, factoryFactory)
 {
     _isValueRange   = !(context.TO() is null);
     _isLTorGT       = !(context.IS() is null);
     _isRelationalOp = Context.children.Any(ch => ch is ParserRuleContext && ParseTreeValueVisitor.IsLogicalContext(ch));
     _isSingleValue  = !(_isValueRange || _isLTorGT || _isRelationalOp);
     _evalTypeName   = string.Empty;
     IsUnreachable   = false;
     AsFilter        = FilterFactory.Create(Tokens.Long, ValueFactory);
 }
예제 #2
0
        private IRangeClauseExpression GetRangeClauseExpression(VBAParser.RangeClauseContext rangeClause)
        {
            var resultContexts = from ctxt in rangeClause.children
                                 where ctxt is ParserRuleContext && IsResultContext(ctxt)
                                 select ctxt as ParserRuleContext;

            if (!resultContexts.Any())
            {
                return(null);
            }

            if (rangeClause.TO() != null)
            {
                var rangeStartValue = ParseTreeValueResults.GetValue(rangeClause.GetChild <VBAParser.SelectStartValueContext>());
                var rangeEndValue   = ParseTreeValueResults.GetValue(rangeClause.GetChild <VBAParser.SelectEndValueContext>());
                return(new RangeOfValuesExpression((rangeStartValue, rangeEndValue)));
            }
            else if (rangeClause.IS() != null)
            {
                var clauseValue = ParseTreeValueResults.GetValue(resultContexts.First());
                var opSymbol    = rangeClause.GetChild <VBAParser.ComparisonOperatorContext>().GetText();
                return(new IsClauseExpression(clauseValue, opSymbol));
            }
            else if (TryGetLogicSymbol(resultContexts.First(), out string symbol))
            {
                var resultContext = resultContexts.First();
                var clauseValue   = ParseTreeValueResults.GetValue(resultContext);
                if (clauseValue.ParsesToConstantValue)
                {
                    return(new ValueExpression(clauseValue));
                }

                if (resultContext is VBAParser.LogicalNotOpContext)
                {
                    return(new UnaryExpression(clauseValue, symbol));
                }
                else if (resultContext is VBAParser.RelationalOpContext ||
                         resultContext is VBAParser.LogicalEqvOpContext ||
                         resultContext is VBAParser.LogicalImpOpContext)
                {
                    (IParseTreeValue lhs, IParseTreeValue rhs) = CreateLogicPair(clauseValue, symbol, _valueFactory);
                    if (symbol.Equals(Tokens.Like))
                    {
                        return(new LikeExpression(lhs, rhs));
                    }
                    return(new BinaryExpression(lhs, rhs, symbol));
                }
                return(null);
            }
            else
            {
                return(new ValueExpression(ParseTreeValueResults.GetValue(resultContexts.First())));
            }
        }
예제 #3
0
 public IRangeClauseContextWrapper Create(VBAParser.RangeClauseContext range, string typeName, IParseTreeVisitorResults results)
 {
     return(new RangeClauseContextWrapper(range, typeName, results, FactoryProvider));
 }