public override IExpression VisitCcIfBlock([NotNull] VBAConditionalCompilationParser.CcIfBlockContext context)
        {
            var ifCondCode           = new ConstantExpression(new StringValue(ParserRuleContextHelper.GetText(context.ccIf(), _stream)));
            var ifCond               = Visit(context.ccIf().ccExpression());
            var ifBlock              = Visit(context.ccBlock());
            var elseIfCodeCondBlocks = context
                                       .ccElseIfBlock()
                                       .Select(elseIf =>
                                               Tuple.Create <IExpression, IExpression, IExpression>(
                                                   new ConstantExpression(new StringValue(ParserRuleContextHelper.GetText(elseIf.ccElseIf(), _stream))),
                                                   Visit(elseIf.ccElseIf().ccExpression()),
                                                   Visit(elseIf.ccBlock()))).ToList();

            IExpression elseCondCode = null;
            IExpression elseBlock    = null;

            if (context.ccElseBlock() != null)
            {
                elseCondCode = new ConstantExpression(new StringValue(ParserRuleContextHelper.GetText(context.ccElseBlock().ccElse(), _stream)));
                elseBlock    = Visit(context.ccElseBlock().ccBlock());
            }
            IExpression endIf = new ConstantExpression(new StringValue(ParserRuleContextHelper.GetText(context.ccEndIf(), _stream)));

            return(new ConditionalCompilationIfExpression(
                       ifCondCode,
                       ifCond,
                       ifBlock,
                       elseIfCodeCondBlocks,
                       elseCondCode,
                       elseBlock,
                       endIf));
        }
Exemple #2
0
        private IExpression VisitLibraryFunction(VBAConditionalCompilationParser.CcExpressionContext context)
        {
            var intrinsicFunction = context.intrinsicFunction();
            var functionName      = ParserRuleContextHelper.GetText(intrinsicFunction.intrinsicFunctionName(), _stream);
            var argument          = Visit(intrinsicFunction.ccExpression());

            return(VBALibrary.CreateLibraryFunction(functionName, argument));
        }
 public override IExpression VisitCcConst([NotNull] VBAConditionalCompilationParser.CcConstContext context)
 {
     return(new ConditionalCompilationConstantExpression(
                new ConstantExpression(new StringValue(ParserRuleContextHelper.GetText(context, _stream))),
                new ConstantExpression(new StringValue(Identifier.GetName(context.ccVarLhs().name()))),
                Visit(context.ccExpression()),
                _symbolTable));
 }
Exemple #4
0
 private IExpression Visit(VBAConditionalCompilationParser.LiteralContext context)
 {
     if (context.HEXLITERAL() != null)
     {
         return(VisitHexLiteral(context));
     }
     else if (context.OCTLITERAL() != null)
     {
         return(VisitOctLiteral(context));
     }
     else if (context.DATELITERAL() != null)
     {
         return(VisitDateLiteral(context));
     }
     else if (context.FLOATLITERAL() != null)
     {
         return(VisitFloatLiteral(context));
     }
     else if (context.INTEGERLITERAL() != null)
     {
         return(VisitIntegerLiteral(context));
     }
     else if (context.STRINGLITERAL() != null)
     {
         return(VisitStringLiteral(context));
     }
     else if (context.TRUE() != null)
     {
         return(new ConstantExpression(new BoolValue(true)));
     }
     else if (context.FALSE() != null)
     {
         return(new ConstantExpression(new BoolValue(false)));
     }
     else if (context.NOTHING() != null || context.NULL() != null)
     {
         return(new ConstantExpression(null));
     }
     else if (context.EMPTY() != null)
     {
         return(new ConstantExpression(EmptyValue.Value));
     }
     throw new Exception(string.Format("Unexpected literal encountered: {0}", ParserRuleContextHelper.GetText(context, _stream)));
 }
 public override IExpression VisitPhysicalLine([NotNull] VBAConditionalCompilationParser.PhysicalLineContext context)
 {
     return(new ConstantExpression(new StringValue(ParserRuleContextHelper.GetText(context, _stream))));
 }