Exemplo n.º 1
0
        public override AbstractNode VisitAddQuery([NotNull] GiraphParser.AddQueryContext context)
        {
            AddQueryNode AddNode = new AddQueryNode(context.Start.Line, context.Start.Column);

            // ITS A GRAPH ADD
            if (context.addToGraph() != null)
            {
                AddNode.IsGraph = true;
                if (context.addToGraph().vertexDcls() != null)
                {
                    foreach (var Child in context.addToGraph().vertexDcls().vertexDcl())
                    {
                        AddNode.Dcls.Add(Visit(Child));
                    }
                }
                var test = context.addToGraph().edgeDcls();
                if (context.addToGraph().edgeDcls() != null)
                {
                    foreach (var Child in context.addToGraph().edgeDcls().edgeDcl())
                    {
                        AddNode.Dcls.Add(Visit(Child));
                    }
                }
                // Shared
                AddNode.ToVariable = context.addToGraph().variable().GetText();
            }
            // ITS A COLLECTION ADD
            else if (context.addToColl() != null)
            {
                AddNode.IsColl = true;
                // ITS ALL TYPE
                AddNode.TypeOrVariable.Add(Visit(context.addToColl().collExpression().boolCompOrExp()));
                if (context.addToColl().collExpressionExt() != null)
                {
                    foreach (var item in context.addToColl().collExpressionExt())
                    {
                        AddNode.TypeOrVariable.Add(Visit(item.collExpression().boolCompOrExp()));
                    }
                }
                // Shared
                if (AddNode.IsVariable)
                {
                    AddNode.ToVariable = context.addToColl().variable().GetText();
                }
                else
                {
                    AddNode.ToVariable = context.addToColl().variable().GetText();
                }
            }
            return(AddNode);
        }
        public override void Visit(AddQueryNode node)
        {
            SymbolTable.SetCurrentNode(node);
            // AddQuery is special for graphs, because here it allows for the creations of edges and vertices.
            if (node.IsGraph)
            {
                foreach (var item in node.Dcls)
                {
                    item.Accept(this);
                }
            }
            CheckDeclared(node.ToVariable);

            if (node.WhereCondition != null)
            {
                node.WhereCondition.Accept(this);
            }
        }
 public override void Visit(AddQueryNode node)
 {
 }
Exemplo n.º 4
0
        public static void Load(string appPath, T parent, AddFolderNode addFolderNode, AddQueryNode addQueryNode)
        {
            String[] subdirs = System.IO.Directory.GetDirectories(appPath);
            foreach (string dir in subdirs)
            {
                var dirtree = addFolderNode(parent, dir);
                Load(dir, dirtree, addFolderNode, addQueryNode);
            }

            String[] qFiles = System.IO.Directory.GetFiles(appPath, "*.q");
            foreach (string filename in qFiles)
            {
                try
                {
                    string[] lines = System.IO.File.ReadAllLines(filename, Encoding.Default);
                    if (lines.Length > 0)
                    {
                        string sql       = lines[1].Replace("SQL=", "").Replace(@"\n", "\n");
                        int    sortBy    = int.Parse(lines[2].Replace("SortBy=", ""));
                        int    sortOrder = int.Parse(lines[3].Replace("SortOrder=", ""));
                        addQueryNode(parent, appPath, filename, sql, sortBy, sortOrder);
                    }
                }
                catch { }
            }
        }
Exemplo n.º 5
0
        public override void Visit(AddQueryNode node)
        {
            _symbolTable.SetCurrentNode(node);
            checkCollectionFollowsCollection(node.ToVariable);
            if (node.IsGraph)
            {            //control statement for input to graphs
                AllType?TypeOfTargetCollection = _symbolTable.RetrieveSymbol(node.ToVariable, out bool isCollectionTargetColl, false);
                node.Type = TypeOfTargetCollection.ToString();
                bool IsGraphVertexCollection      = TypeOfTargetCollection == AllType.VERTEX && isCollectionTargetColl;
                bool isGraphEdgeCollection        = TypeOfTargetCollection == AllType.EDGE && isCollectionTargetColl;
                bool isPreDefVerOrEdgeCollInGraph = TypeOfTargetCollection == AllType.GRAPH;
                if (isPreDefVerOrEdgeCollInGraph)
                {                //if declarations are added to the graph.
                    foreach (AbstractNode edgeOrVertexdcl in node.Dcls)
                    {
                        edgeOrVertexdcl.Accept(this);
                    }
                }
                else if (IsGraphVertexCollection || isGraphEdgeCollection)
                {                //if declarations is added to an extended collection on graph - NOT LEGAL
                    foreach (AbstractNode vertexOrEdgedcl in node.Dcls)
                    {
                        if (vertexOrEdgedcl is GraphDeclVertexNode || vertexOrEdgedcl is GraphDeclEdgeNode)
                        {
                            break;
                        }
                    }
                }
            }
            //if the ToVariable is a collection:
            else if (node.IsColl)
            {
                AllType?TypeOfTargetCollection = _symbolTable.RetrieveSymbol(node.ToVariable, out bool isCollectionTargetColl, false);
                node.Type = TypeOfTargetCollection.ToString();
                AllType?typeOfVar = null;

                foreach (var item in node.TypeOrVariable)
                {
                    item.Accept(this);

                    AbstractNode expressionToAdd = item;
                    if ((expressionToAdd is BoolComparisonNode) && expressionToAdd.Children[0] is ExpressionNode)
                    {
                        typeOfVar = (expressionToAdd.Children[0] as ExpressionNode).OverAllType;
                    }
                    else if (expressionToAdd is ExpressionNode)
                    {
                        typeOfVar = (expressionToAdd as ExpressionNode).OverAllType;
                    }
                    else
                    {
                        typeOfVar = expressionToAdd.Type_enum;
                    }
                    bool targetIsGraph = TypeOfTargetCollection == AllType.GRAPH;

                    if (isCollectionTargetColl)
                    {                    //non-declarations are added to an extended collection on graph, or simply a collection.
                        bool AllowedCast = TypeOfTargetCollection == AllType.DECIMAL && typeOfVar == AllType.INT;
                        CheckAllowedCast(TypeOfTargetCollection ?? AllType.UNKNOWNTYPE, typeOfVar ?? AllType.UNKNOWNTYPE);
                    }
                    else if (targetIsGraph)
                    {                    //if variables are added to the graph.
                        bool varIsVertex = typeOfVar == AllType.VERTEX;
                        bool varIsEdge   = typeOfVar == AllType.EDGE;
                        if (varIsEdge || varIsVertex)
                        {
                            //only edge and vertex variables can be added to a graph.
                        }
                        else
                        {
                            _symbolTable.WrongTypeError(node.TypeOrVariable.ToString(), node.ToVariable);
                        }
                    }
                    else
                    {
                        _symbolTable.TargetIsNotCollError(node.ToVariable);
                    }
                }
            }
            else
            {
                Console.WriteLine("Is neither collection or Graph. This should not be possible");
            }
        }
Exemplo n.º 6
0
 public abstract void Visit(AddQueryNode node);