Esempio n. 1
0
        public override object VisitArray([NotNull] ArrayContext context)
        {
            var type   = "var";
            var result = new Result();

            for (int i = 0; i < context.expression().Length; i++)
            {
                var r = (Result)Visit(context.expression(i));
                if (i == 0)
                {
                    type         = (string)r.data;
                    result.text += r.text;
                }
                else
                {
                    if (type != (string)r.data)
                    {
                        type = "object";
                    }
                    result.text += "," + r.text;
                }
            }
            result.data = type + "[]";
            result.text = $"(new {result.data}{{ {result.text} }})";
            return(result);
        }
Esempio n. 2
0
        public IBuildContext BuildSequence(ExpressionBuilder builder, BuildInfo buildInfo)
        {
            var sequence = Find(builder, buildInfo, (index, type) =>
            {
                var query      = buildInfo.SelectQuery;
                var innerQuery = new SelectQuery {
                    ParentSelect = query
                };

                query.Select.From.Table(innerQuery);

                if (!builder.MappingSchema.IsScalarType(type))
                {
                    throw new LinqToDBException("Non-scalar IEnumerable sources currently not supported");
                }

                var array = new ArrayContext(builder, buildInfo, query, type);

                IEnumerable <ISqlExpression> elements;

                switch (index)
                {
                case 1:
                case 2:
                    elements = BuildElements(type, (IEnumerable)((ConstantExpression)buildInfo.Expression).Value);
                    break;

                case 3:
//						buildInfo.JoinType = JoinType.CrossApply;
                    elements = BuildElements(builder, buildInfo, ((NewArrayExpression)buildInfo.Expression).Expressions);
                    break;

                default:
                    throw new InvalidOperationException();
                }

                var isFirst = true;

                foreach (var itemSql in elements)
                {
                    var currentQuery = isFirst ? innerQuery : new SelectQuery();

                    currentQuery.Select.AddNew(itemSql);

                    if (!isFirst)
                    {
                        innerQuery.AddUnion(currentQuery, true);
                    }

                    isFirst = false;
                }

                query.Select.Columns.Add(new SqlColumn(query, innerQuery.Select.Columns[0], "Item"));

                return(array);
            });

            return(sequence);
        }
Esempio n. 3
0
    public ArrayContext array()
    {
        ArrayContext _localctx = new ArrayContext(Context, State);

        EnterRule(_localctx, 6, RULE_array);
        int _la;

        try {
            State = 44;
            ErrorHandler.Sync(this);
            switch (Interpreter.AdaptivePredict(TokenStream, 3, Context))
            {
            case 1:
                EnterOuterAlt(_localctx, 1);
                {
                    State = 31; Match(T__4);
                    State = 32; value();
                    State = 37;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                    while (_la == T__1)
                    {
                        {
                            {
                                State = 33; Match(T__1);
                                State = 34; value();
                            }
                        }
                        State = 39;
                        ErrorHandler.Sync(this);
                        _la = TokenStream.LA(1);
                    }
                    State = 40; Match(T__5);
                }
                break;

            case 2:
                EnterOuterAlt(_localctx, 2);
                {
                    State = 42; Match(T__4);
                    State = 43; Match(T__5);
                }
                break;
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
Esempio n. 4
0
        public ArrayContext array()
        {
            ArrayContext _localctx = new ArrayContext(_ctx, State);

            EnterRule(_localctx, 18, RULE_array);
            try {
                int _alt;
                EnterOuterAlt(_localctx, 1);
                {
                    State = 98;
                    _errHandler.Sync(this);
                    _alt = 1;
                    do
                    {
                        switch (_alt)
                        {
                        case 1:
                        {
                            {
                                State = 96; Match(IDENTIFIER);
                                State = 97; Match(COMMA_SYM);
                            }
                        }
                        break;

                        default:
                            throw new NoViableAltException(this);
                        }
                        State = 100;
                        _errHandler.Sync(this);
                        _alt = Interpreter.AdaptivePredict(_input, 11, _ctx);
                    } while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber);
                    State = 102; Match(IDENTIFIER);
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                _errHandler.ReportError(this, re);
                _errHandler.Recover(this, re);
            }
            finally {
                ExitRule();
            }
            return(_localctx);
        }
Esempio n. 5
0
    public ArrayContext array()
    {
        ArrayContext _localctx = new ArrayContext(Context, State);

        EnterRule(_localctx, 0, RULE_array);
        int _la;

        try {
            EnterOuterAlt(_localctx, 1);
            {
                State = 10; Match(T__0);
                State = 11; value();
                State = 16;
                ErrorHandler.Sync(this);
                _la = TokenStream.LA(1);
                while (_la == T__1)
                {
                    {
                        {
                            State = 12; Match(T__1);
                            State = 13; value();
                        }
                    }
                    State = 18;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                }
                State = 19; Match(T__2);
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
        /// <summary>
        /// Enters a new context. 
        /// The context contains an environment for symbol lookup in attribute expressions. 
        /// </summary>
        public void EnterContext()
        {
            // Save symbol context
            SavedContext c = new SavedContext();
            c.symbolStore = symbolStore;
            c.pointerSymbolStore = pointerSymbolStore;
            outerContexts.Push(c);
            symbolStore = null;
            pointerSymbolStore = null;

            // Save array context
            ArrayContext arrayContext = new ArrayContext();
            arrayContext.arrayLevel = arrayLevel;
            arrayContext.arraySizes = arraySizes;
            arrayContext.arrayLengths = arrayLengths;
            outerArrayContexts.Push(arrayContext);

            arrayLevel = 0;
            arraySizes = null;
            arrayLengths = null;

            // Save sequence context
            SequenceContext sequenceContext = new SequenceContext();
            sequenceContext.sequenceLevel = sequenceLevel;
            sequenceContext.sequenceSizes = sequenceSizes;
            sequenceContext.sequenceLengths = sequenceLengths;
            outerSequenceContexts.Push(sequenceContext);

            sequenceLevel = 0;
            sequenceSizes = null;
            sequenceLengths = null;
        }
Esempio n. 7
0
	public ArrayContext array() {
		ArrayContext _localctx = new ArrayContext(Context, State);
		EnterRule(_localctx, 6, RULE_array);
		int _la;
		try {
			State = 92;
			switch ( Interpreter.AdaptivePredict(TokenStream,4,Context) ) {
			case 1:
				EnterOuterAlt(_localctx, 1);
				{
				State = 79; Match(LeftBracket);
				State = 80; value();
				State = 85;
				ErrorHandler.Sync(this);
				_la = TokenStream.La(1);
				while (_la==Comma) {
					{
					{
					State = 81; Match(Comma);
					State = 82; value();
					}
					}
					State = 87;
					ErrorHandler.Sync(this);
					_la = TokenStream.La(1);
				}
				State = 88; Match(RightBracket);
				}
				break;
			case 2:
				EnterOuterAlt(_localctx, 2);
				{
				State = 90; Match(LeftBracket);
				State = 91; Match(RightBracket);
				}
				break;
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}