Exemplo n.º 1
0
		public void Verify(VerificationContext context, ASTNode node)
		{
			// Verify source
			Verifier.Verify(context, node.Children[0]);

			var objectType = node.Children[0].ResultType as ObjectType;
			if (objectType == null)
			{
				throw new InvalidOperationException("The source expression for an object redefine must evaluate to a value of a structured type.");
			}

			// Push the source into context as a symbol
			context.PushSymbol(new Symbol(node.GetAttribute<string>("Scope", VerificationContext.Current), objectType));
			try
			{
				// foreach property
				for (int i = 1; i < ((Node)node).Children.Count; i++)
				{
					// Verify the property exists
					var child = ((Node)node).Children[i];
					var childPropertyType = context.ResolveProperty(objectType, child.GetAttribute<string>("name"));

					// Verify the value
					var value = (ASTNode)child.Children[0];
					Verifier.Verify(context, value);

					// Verify the value type is appropriate for the property type
					context.VerifyType(value.ResultType, childPropertyType);
				}
			}
			finally
			{
				context.PopSymbol();
			}

			node.ResultType = objectType;
		}
Exemplo n.º 2
0
		public void Verify(VerificationContext context, ASTNode node)
		{
			var source = node.Children[0];
			var condition = node.Children[1];

			Verifier.Verify(context, source);
			var sourceListType = source.ResultType as ListType;
			if (sourceListType == null)
			{
				throw new InvalidOperationException("Filter expression source must be a list type expression.");
			}

			context.PushSymbol(new Symbol(node.GetAttribute<string>("scope", VerificationContext.Current), sourceListType.ElementType));
			try
			{
				Verifier.Verify(context, condition);
				context.VerifyType(condition.ResultType, DataTypes.Boolean);
			}
			finally
			{
				context.PopSymbol();
			}

			node.ResultType = sourceListType;
		}
Exemplo n.º 3
0
        public void Verify(VerificationContext context, HeD.Engine.Model.ASTNode node)
        {
            Symbol sourceSymbol = null;

            // foreach source
                // add to the output context
            var sources = ((Node)node).Children.Where(c => c.Name == "source").ToList();
            foreach (var source in sources)
            {
                if (sourceSymbol == null)
                {
                    sourceSymbol = ProcessAliasedQuerySource(context, source);
                }
                else
                {
                    throw new NotImplementedException("Multi-source query verification is not implemented.");
                }
            }

            if (sourceSymbol == null)
            {
                throw new InvalidOperationException("Could not determine query source type.");
            }

            var sourceSymbolListType = sourceSymbol.DataType as ListType;
            var sourceSymbolElementType = sourceSymbolListType != null ? sourceSymbolListType.ElementType : null;
            var sourceElementSymbol = sourceSymbolElementType != null ? new Symbol(sourceSymbol.Name, sourceSymbolElementType) : null;

            context.PushSymbol(sourceElementSymbol ?? sourceSymbol);
            try
            {
                // foreach define
                    // add to the current scope
                var defines = ((Node)node).Children.Where(c => c.Name == "define").ToList();
                foreach (var define in defines)
                {
                    throw new NotImplementedException("Query defines are not implemented.");
                }

                // verify each with/without clause
                var relationships = ((Node)node).Children.Where(c => c.Name == "relationship").ToList();
                foreach (var relationship in relationships)
                {
                    var relatedSourceSymbol = ProcessAliasedQuerySource(context, relationship);
                    var relatedSourceSymbolListType = relatedSourceSymbol.DataType as ListType;
                    var relatedSourceSymbolElementType = relatedSourceSymbolListType != null ? relatedSourceSymbolListType.ElementType : null;
                    var relatedSourceElementSymbol = relatedSourceSymbolElementType != null ? new Symbol(relatedSourceSymbol.Name, relatedSourceSymbolElementType) : null;

                    context.PushSymbol(relatedSourceElementSymbol ?? relatedSourceSymbol);
                    try
                    {
                        var suchThat = relationship.Children[1] as ASTNode;
                        if (suchThat == null)
                        {
                            throw new InvalidOperationException(String.Format("Could not determine such that for relationship '{0}'.", relatedSourceSymbol.Name));
                        }

                        Verifier.Verify(context, suchThat);
                        context.VerifyType(suchThat.ResultType, DataTypes.Boolean);
                    }
                    finally
                    {
                        context.PopSymbol();
                    }
                }

                // verify the where clause
                var whereClause = ((Node)node).Children.Where(c => c.Name == "where").FirstOrDefault() as ASTNode;
                if (whereClause != null)
                {
                    Verifier.Verify(context, whereClause);
                    context.VerifyType(whereClause.ResultType, DataTypes.Boolean);
                }

                // verify the return clause
                var returnClause = ((Node)node).Children.Where(c => c.Name == "return").FirstOrDefault();
                if (returnClause != null)
                {
                    throw new NotImplementedException("Return clause is not implemented.");
                }

                // verify the sort clause
                var sortClause = ((Node)node).Children.Where(c => c.Name == "sort").FirstOrDefault();
                if (sortClause != null)
                {
                    throw new NotImplementedException("Sort clause is not implemented.");
                }

                node.ResultType = sourceSymbol.DataType;
            }
            finally
            {
                context.PopSymbol();
            }
        }