コード例 #1
0
        public override IASTNode VisitTableReferences(SqlServerCommandParser.TableReferencesContext context)
        {
            CollectionValue <TableReferenceSegment> result = new CollectionValue <TableReferenceSegment>();

            foreach (var tableReferenceContext in context.tableReference())
            {
                result.GetValue().Add((TableReferenceSegment)Visit(tableReferenceContext));
            }
            return(result);
        }
コード例 #2
0
        public IPropertyModel AddNewElement()
        {
            var model = new ReferenceByIntProperty(Source, IdPropertyName)
            {
                Title = { Value = "Element" }
            };

            CollectionValue.AddElement(model);
            return(model);
        }
コード例 #3
0
        public override IASTNode VisitColumnNames(MySqlCommandParser.ColumnNamesContext ctx)
        {
            CollectionValue <ColumnSegment> result = new CollectionValue <ColumnSegment>();

            foreach (var each in ctx.columnName())
            {
                result.GetValue().Add((ColumnSegment)Visit(each));
            }
            return(result);
        }
コード例 #4
0
        public override IASTNode VisitTableReferences(MySqlCommandParser.TableReferencesContext ctx)
        {
            CollectionValue <TableReferenceSegment> result = new CollectionValue <TableReferenceSegment>();

            foreach (MySqlCommandParser.EscapedTableReferenceContext each in ctx.escapedTableReference())
            {
                result.GetValue().Add((TableReferenceSegment)Visit(each));
            }
            return(result);
        }
コード例 #5
0
        public override IASTNode VisitMultipleTableNames(MySqlCommandParser.MultipleTableNamesContext ctx)
        {
            CollectionValue <SimpleTableSegment> result = new CollectionValue <SimpleTableSegment>();

            foreach (var each in ctx.tableName())
            {
                result.GetValue().Add((SimpleTableSegment)Visit(each));
            }
            return(result);
        }
コード例 #6
0
        public override IASTNode VisitMultipleTableNames(SqlServerCommandParser.MultipleTableNamesContext context)
        {
            CollectionValue <SimpleTableSegment> result = new CollectionValue <SimpleTableSegment>();

            foreach (var tableNameContext in context.tableName())
            {
                result.GetValue().Add((SimpleTableSegment)Visit(tableNameContext));
            }

            return(result);
        }
コード例 #7
0
        public override IASTNode VisitColumnNames(SqlServerCommandParser.ColumnNamesContext context)
        {
            CollectionValue <ColumnSegment> result = new CollectionValue <ColumnSegment>();

            foreach (var columnName in context.columnNameWithSort())
            {
                result.GetValue().Add((ColumnSegment)Visit(columnName));
            }

            return(result);
        }
コード例 #8
0
        public override IASTNode VisitMultipleTablesClause(SqlServerCommandParser.MultipleTablesClauseContext context)
        {
            CollectionValue <SimpleTableSegment> result = new CollectionValue <SimpleTableSegment>();

            result.Combine((CollectionValue <SimpleTableSegment>)Visit(context.multipleTableNames()));
            CollectionValue <TableReferenceSegment> tableReferences = (CollectionValue <TableReferenceSegment>)Visit(context.tableReferences());

            foreach (var tableReferenceSegment in tableReferences.GetValue())
            {
                result.GetValue().AddAll(tableReferenceSegment.GetTables());
            }
            return(result);
        }
コード例 #9
0
        public override IASTNode VisitInsertValuesClause(SqlServerCommandParser.InsertValuesClauseContext context)
        {
            InsertCommand result = new InsertCommand();

            if (null != context.columnNames())
            {
                SqlServerCommandParser.ColumnNamesContext columnNames    = context.columnNames();
                CollectionValue <ColumnSegment>           columnSegments = (CollectionValue <ColumnSegment>)Visit(columnNames);
                result.InsertColumns = new InsertColumnsSegment(columnNames.Start.StartIndex, columnNames.Stop.StopIndex, columnSegments.GetValue());
            }
            else
            {
                result.InsertColumns = new InsertColumnsSegment(context.Start.StartIndex - 1, context.Stop.StopIndex - 1, new List <ColumnSegment>());
            }
            result.Values.AddAll(CreateInsertValuesSegments(context.assignmentValues()));
            return(result);
        }
コード例 #10
0
        public override IASTNode VisitCreateDefinitionClause(SqlServerCommandParser.CreateDefinitionClauseContext context)
        {
            CollectionValue <ICreateDefinitionSegment> result = new CollectionValue <ICreateDefinitionSegment>();

            foreach (var createTableDefinitionContext in context.createTableDefinitions().createTableDefinition())
            {
                if (null != createTableDefinitionContext.columnDefinition())
                {
                    result.GetValue().Add((ColumnDefinitionSegment)Visit(createTableDefinitionContext.columnDefinition()));
                }
                if (null != createTableDefinitionContext.tableConstraint())
                {
                    result.GetValue().Add((ConstraintDefinitionSegment)Visit(createTableDefinitionContext.tableConstraint()));
                }
            }
            return(result);
        }
コード例 #11
0
        public override IASTNode VisitUpdate(SqlServerCommandParser.UpdateContext context)
        {
            UpdateCommand result = new UpdateCommand();
            CollectionValue <TableReferenceSegment> tableReferences = (CollectionValue <TableReferenceSegment>)Visit(context.tableReferences());

            foreach (var tableReferenceSegment in tableReferences.GetValue())
            {
                result.Tables.AddAll(tableReferenceSegment.GetTables());
            }
            result.SetAssignment = (SetAssignmentSegment)Visit(context.setAssignmentsClause());
            if (null != context.whereClause())
            {
                result.Where = (WhereSegment)Visit(context.whereClause());
            }
            result.SetParameterCount(GetCurrentParameterIndex());
            return(result);
        }
コード例 #12
0
        public void TestDataValues()
        {
            var collection = new CollectionValue();

            collection.AddValue(new BoolValue(true));
            collection.AddValue(new BoolValue(false));
            collection.AddValue(new BoolValue());
            collection.AddValue(new CharValue('a'));
            collection.AddValue(new CharValue('b'));
            collection.AddValue(new CharValue());
            collection.AddValue(new DateTimeValue(DateTime.Now));
            collection.AddValue(new DateTimeValue());
            collection.AddValue(new DecimalValue(12.345m));
            collection.AddValue(new DoubleValue(123.45678901));
            collection.AddValue(new DoubleValue());
            collection.AddValue(new IntValue(1234));
            collection.AddValue(new IntValue());
            collection.AddValue(new StringValue("abcdef"));
            collection.AddValue(new StringValue());
            collection.AddValue(new DictionaryEntryValue("chiave", "valore"));
            collection.AddValue(new DictionaryEntryValue());
            collection.AddValue(new VirtualPathValue(new VirtualPath(@"\file.txt")));
            collection.AddValue(new VirtualPathValue(new VirtualPath()));

            var collectionSTR  = collection.WriteToStringValue();
            var collection_bis = new CollectionValue();

            collection_bis.ReadFromStringValue(collectionSTR);

            var emptyCoolection     = new CollectionValue();
            var emptyCoolectionSTR  = emptyCoolection.WriteToStringValue();
            var emptyCoolection_bis = new CollectionValue();

            emptyCoolection_bis.ReadFromStringValue(emptyCoolectionSTR);

            //var ssss = new StringValue();
            //var sxxxxx =ssss.WriteToStringValue();
            //var sssss = new StringValue();
            //sssss.ReadFromStringValue(sxxxxx);

            //var s123 = new StringValue("abcdef");
            //var s123STR = s123.WriteToStringValue();
            //var s123_bis = new StringValue();
            //s123_bis.ReadFromStringValue(s123STR);
        }
コード例 #13
0
        public override IASTNode VisitCreateTable(SqlServerCommandParser.CreateTableContext context)
        {
            CreateTableCommand result = new CreateTableCommand((SimpleTableSegment)Visit(context.tableName()));

            if (null != context.createDefinitionClause())
            {
                CollectionValue <ICreateDefinitionSegment> createDefinitions = (CollectionValue <ICreateDefinitionSegment>)Visit(context.createDefinitionClause());
                foreach (var createDefinitionSegment in createDefinitions.GetValue())
                {
                    if (createDefinitionSegment is ColumnDefinitionSegment columnDefinitionSegment)
                    {
                        result.ColumnDefinitions.Add(columnDefinitionSegment);
                    }
                    else if (createDefinitionSegment is ConstraintDefinitionSegment constraintDefinitionSegment)
                    {
                        result.ConstraintDefinitions.Add(constraintDefinitionSegment);
                    }
                }
            }
            return(result);
        }
コード例 #14
0
        public override IASTNode VisitAddColumnSpecification(SqlServerCommandParser.AddColumnSpecificationContext context)
        {
            CollectionValue <AddColumnDefinitionSegment> result = new CollectionValue <AddColumnDefinitionSegment>();

            if (null != context.alterColumnAddOptions())
            {
                foreach (var alterColumnAddOptionContext in context.alterColumnAddOptions().alterColumnAddOption())
                {
                    if (null != alterColumnAddOptionContext.columnDefinition())
                    {
                        AddColumnDefinitionSegment addColumnDefinition = new AddColumnDefinitionSegment(
                            alterColumnAddOptionContext.columnDefinition().Start.StartIndex, alterColumnAddOptionContext.columnDefinition().Stop.StopIndex,
                            new List <ColumnDefinitionSegment>()
                        {
                            (ColumnDefinitionSegment)Visit(alterColumnAddOptionContext.columnDefinition())
                        });
                        result.GetValue().Add(addColumnDefinition);
                    }
                }
            }
            return(result);
        }
コード例 #15
0
        public override IASTNode VisitAlterDefinitionClause(SqlServerCommandParser.AlterDefinitionClauseContext context)
        {
            CollectionValue <IAlterDefinitionSegment> result = new CollectionValue <IAlterDefinitionSegment>();

            if (null != context.addColumnSpecification())
            {
                var addColumnDefinitionSegments = ((CollectionValue <AddColumnDefinitionSegment>)Visit(context.addColumnSpecification())).GetValue();
                foreach (var addColumnDefinitionSegment in addColumnDefinitionSegments)
                {
                    result.GetValue().Add(addColumnDefinitionSegment);
                }
            }
            if (null != context.modifyColumnSpecification())
            {
                result.GetValue().Add((ModifyColumnDefinitionSegment)Visit(context.modifyColumnSpecification()));
            }
            if (null != context.alterDrop() && null != context.alterDrop().dropColumnSpecification())
            {
                result.GetValue().Add((DropColumnDefinitionSegment)Visit(context.alterDrop().dropColumnSpecification()));
            }
            return(result);
        }
コード例 #16
0
        /// <summary>
        /// 计算,并创建新的集合
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="environment"></param>
        /// <returns></returns>
        public static IExpr EvaluateColletionValue(CollectionValue expr, EvalContext environment)
        {
            if (expr.IsCertain == true)
            {
                return(expr);
            }
            List <IValue> vs = new List <IValue>();

            //var que = from x in ls.Contents select Calculate(x);
            try
            {
                foreach (var v in (IEnumerable <IValue>)expr)
                {
                    if (v.IsCertain)
                    {
                        vs.Add(v);
                    }
                    else
                    {
                        var val = environment.Evaluate(v);
                        if (val is IValue)
                        {
                            vs.Add((IValue)val);
                        }
                        else//值是一个表达式
                        {
                            ExceptionHelper.RaiseNotValue(expr, v);
                        }
                    }
                }
                var res = expr.CreateNew();
                res.Reset(vs);
                return(res);
            }
            catch (ExprException ex)
            {
                throw ex;
            }
        }
コード例 #17
0
        public override IASTNode VisitSelectClause(MySqlCommandParser.SelectClauseContext ctx)
        {
            SelectCommand result = new SelectCommand();

            result.Projections = (ProjectionsSegment)Visit(ctx.projections());
            if (null != ctx.selectSpecification())
            {
                result.Projections.SetDistinctRow(IsDistinct(ctx));
            }
            if (null != ctx.fromClause())
            {
                CollectionValue <TableReferenceSegment> tableReferences = (CollectionValue <TableReferenceSegment>)Visit(ctx.fromClause());
                foreach (TableReferenceSegment each in tableReferences.GetValue())
                {
                    result.TableReferences.Add(each);
                }
            }
            if (null != ctx.whereClause())
            {
                result.Where = (WhereSegment)Visit(ctx.whereClause());
            }
            if (null != ctx.groupByClause())
            {
                result.GroupBy = (GroupBySegment)Visit(ctx.groupByClause());
            }
            if (null != ctx.orderByClause())
            {
                result.OrderBy = (OrderBySegment)Visit(ctx.orderByClause());
            }
            if (null != ctx.limitClause())
            {
                result.Limit = (LimitSegment)Visit(ctx.limitClause());
            }
            if (null != ctx.lockClause())
            {
                result.Lock = (LockSegment)Visit(ctx.lockClause());
            }
            return(result);
        }
コード例 #18
0
ファイル: MapDisplay.cs プロジェクト: Oshhcar/GramaticasCQL
        public override object GetValor(Entorno e, LinkedList <Salida> log, LinkedList <Error> errores)
        {
            Expresion clave = (Expresion)Collection.ElementAt(0).Clave;
            Expresion valor = (Expresion)Collection.ElementAt(0).Valor;

            object valClave = clave.GetValor(e, log, errores);
            object valValor = valor.GetValor(e, log, errores);

            if (valClave != null && valValor != null)
            {
                if (valClave is Throw)
                {
                    return(valClave);
                }

                if (valValor is Throw)
                {
                    return(valValor);
                }

                Tipo = new Tipo(clave.Tipo, valor.Tipo);

                Collection map = new Collection(new Tipo(clave.Tipo, valor.Tipo));
                map.Insert(valClave, valValor);

                for (int i = 1; i < Collection.Count(); i++)
                {
                    CollectionValue value = Collection.ElementAt(i);
                    clave    = (Expresion)value.Clave;
                    valor    = (Expresion)value.Valor;
                    valClave = clave.GetValor(e, log, errores);
                    valValor = valor.GetValor(e, log, errores);

                    if (valClave != null && valValor != null)
                    {
                        if (valClave is Throw)
                        {
                            return(valClave);
                        }

                        if (valValor is Throw)
                        {
                            return(valValor);
                        }

                        if (map.Tipo.Clave.Equals(clave.Tipo) && map.Tipo.Valor.Equals(valor.Tipo))
                        {
                            if (map.Get(valClave) == null)
                            {
                                map.Insert(valClave, valValor);
                            }
                            else
                            {
                                errores.AddLast(new Error("Semántico", "Ya existe un valor con la clave: " + valClave.ToString() + " en Map.", Linea, Columna));
                            }
                        }
                        else
                        {
                            Casteo cast1 = new Casteo(map.Tipo.Clave, new Literal(clave.Tipo, valClave, 0, 0), 0, 0)
                            {
                                Mostrar = false
                            };

                            Casteo cast2 = new Casteo(map.Tipo.Valor, new Literal(valor.Tipo, valValor, 0, 0), 0, 0)
                            {
                                Mostrar = false
                            };

                            valClave = cast1.GetValor(e, log, errores);
                            valValor = cast2.GetValor(e, log, errores);

                            if (valClave != null && valValor != null)
                            {
                                if (valClave is Throw)
                                {
                                    return(valClave);
                                }

                                if (valValor is Throw)
                                {
                                    return(valValor);
                                }

                                if (map.Get(valClave) == null)
                                {
                                    map.Insert(valClave, valValor);
                                }
                                else
                                {
                                    errores.AddLast(new Error("Semántico", "Ya existe un valor con la clave: " + valClave.ToString() + " en Map.", Linea, Columna));
                                }

                                continue;
                            }

                            errores.AddLast(new Error("Semántico", "Los tipos no coinciden con la clave:valor del Map.", Linea, Columna));
                        }
                        //continue;
                    }
                    //return null;
                }

                return(map);
            }
            return(null);
        }
コード例 #19
0
 public void Duplicate(int source, int destination) => CollectionValue.Duplicate(source, destination);
コード例 #20
0
 public void Move(int oldIndex, int newIndex)
 {
     CollectionValue.Move(oldIndex, newIndex);
 }
コード例 #21
0
 public void RemoveElementAt(int index)
 {
     CollectionValue.RemoveAt(index);
 }
コード例 #22
0
 public IPropertyModel AddNewElement()
 {
     return(CollectionValue.AddNewElement());
 }
コード例 #23
0
 public IPropertyModel AddNewElement() => CollectionValue.AddNewElement();
コード例 #24
0
ファイル: Asignacion.cs プロジェクト: Oshhcar/ServidorCQL
        public override object Ejecutar(Entorno e, bool funcion, bool ciclo, bool sw, bool tc, LinkedList <Salida> log, LinkedList <Error> errores)
        {
            Object valExpr = Expr.GetValor(e, log, errores);

            if (valExpr != null)
            {
                if (valExpr is Throw)
                {
                    return(valExpr);
                }

                if (Target is Identificador iden)
                {
                    Simbolo sim = Target.GetSimbolo(e);

                    if (sim != null)
                    {
                        if (sim.Tipo.Equals(Expr.Tipo))
                        {
                            sim.Valor = valExpr;
                            return(null);
                        }
                        else
                        {
                            if (sim.Tipo.IsCollection() && Expr.Tipo.IsCollection() && iden.IsId2)
                            {
                                if (sim.Tipo.EqualsCollection(Expr.Tipo))
                                {
                                    if (valExpr is Collection collection)
                                    {
                                        sim.Tipo.Clave = collection.Tipo.Clave;
                                        sim.Tipo.Valor = collection.Tipo.Valor;
                                        sim.Valor      = collection;
                                        return(null);
                                    }
                                }
                            }
                            else
                            {
                                Casteo cast = new Casteo(sim.Tipo, new Literal(Expr.Tipo, valExpr, 0, 0), 0, 0)
                                {
                                    Mostrar = false
                                };
                                valExpr = cast.GetValor(e, log, errores);

                                if (valExpr != null)
                                {
                                    if (valExpr is Throw)
                                    {
                                        return(valExpr);
                                    }

                                    sim.Valor = valExpr;
                                    return(null);
                                }
                            }
                        }

                        errores.AddLast(new Error("Semántico", "El valor no corresponde al tipo de la variable.", Linea, Columna));
                        return(null);
                    }
                    if (iden.IsId2)
                    {
                        errores.AddLast(new Error("Semántico", "No se ha declarado una variable con el id: " + Target.GetId() + ".", Linea, Columna));
                    }
                    else
                    {
                        return(new Throw("ColumnException", Linea, Columna));
                    }
                }
                else if (Target is AtributoRef atributo)
                {
                    atributo.GetObjeto = true;

                    object obj = atributo.GetValor(e, log, errores);

                    if (obj != null)
                    {
                        if (obj is Throw)
                        {
                            return(obj);
                        }

                        Simbolo sim = (Simbolo)obj;

                        if (sim.Tipo.Equals(Expr.Tipo))
                        {
                            sim.Valor = valExpr;
                            return(null);
                        }
                        else
                        {
                            Casteo cast = new Casteo(sim.Tipo, new Literal(Expr.Tipo, valExpr, 0, 0), 0, 0)
                            {
                                Mostrar = false
                            };
                            valExpr = cast.GetValor(e, log, errores);

                            if (valExpr != null)
                            {
                                if (valExpr is Throw)
                                {
                                    return(valExpr);
                                }

                                sim.Valor = valExpr;
                                return(null);
                            }
                        }

                        errores.AddLast(new Error("Semántico", "El valor no corresponde al tipo de la variable.", Linea, Columna));
                        return(null);
                    }
                    errores.AddLast(new Error("Semántico", "No se ha declarado una variable con el id: " + Target.GetId() + ".", Linea, Columna));
                }
                else if (Target is Acceso acceso)
                {
                    acceso.GetCollection = true;

                    object obj = acceso.GetValor(e, log, errores);

                    if (obj != null)
                    {
                        if (obj is Throw)
                        {
                            return(obj);
                        }

                        CollectionValue collection = (CollectionValue)obj;

                        if (acceso.Tipo.Equals(Expr.Tipo))
                        {
                            if (acceso.Collec != null)
                            {
                                if (acceso.Collec.Tipo.IsSet())
                                {
                                    if (acceso.Collec.Contains(valExpr))
                                    {
                                        errores.AddLast(new Error("Semántico", "Ya existe el valor: " + valExpr.ToString() + " en el Set.", Linea, Columna));
                                        return(null);
                                    }
                                }
                            }

                            collection.Valor = valExpr;
                            return(null);
                        }
                        else
                        {
                            Casteo cast = new Casteo(acceso.Tipo, new Literal(Expr.Tipo, valExpr, 0, 0), 0, 0)
                            {
                                Mostrar = false
                            };
                            valExpr = cast.GetValor(e, log, errores);

                            if (valExpr != null)
                            {
                                if (valExpr is Throw)
                                {
                                    return(valExpr);
                                }

                                if (acceso.Collec != null)
                                {
                                    if (acceso.Collec.Tipo.IsSet())
                                    {
                                        if (acceso.Collec.Contains(valExpr))
                                        {
                                            errores.AddLast(new Error("Semántico", "Ya existe el valor: " + valExpr.ToString() + " en el Set.", Linea, Columna));
                                            return(null);
                                        }
                                    }
                                }

                                collection.Valor = valExpr;
                                return(null);
                            }
                        }

                        errores.AddLast(new Error("Semántico", "El valor no corresponde al tipo de la variable.", Linea, Columna));
                        return(null);
                    }
                    errores.AddLast(new Error("Semántico", "No se ha declarado una variable con el id: " + Target.GetId() + ".", Linea, Columna));
                }
            }
            return(null);
        }