protected virtual void InternalVerify(VerificationContext context, ASTNode node)
		{
			foreach (var child in node.Children)
			{
				Verifier.Verify(context, child);
			}
		}
		public void Verify(VerificationContext context, ASTNode node)
		{
			var expressionType = context.ResolveExpressionRef(node.GetAttribute<string>("libraryName"), node.GetAttribute<string>("name"));
			if (expressionType.Expression.ResultType == null)
			{
				throw new InvalidOperationException("Invalid forward reference.");
			}

			node.ResultType = expressionType.Expression.ResultType;
		}
        private Symbol ProcessAliasedQuerySource(VerificationContext context, HeD.Engine.Model.Node source)
        {
            var sourceAlias = source.GetAttribute<String>("alias");
            var sourceExpression = source.Children[0] as ASTNode;
            if (sourceExpression == null)
            {
                throw new InvalidOperationException(String.Format("Could not determine source expression for alias '{0}'.", sourceAlias));
            }

            Verifier.Verify(context, sourceExpression);
            return new Symbol(sourceAlias, sourceExpression.ResultType);
        }
		public static void Verify(VerificationContext context, ASTNode node)
		{
			try
			{
				var verifier = NodeVerifierFactory.GetHandler(node.NodeType);

				// Traversal occurs within the verify, because traversal may happen differently depending on the operation.
				verifier.Verify(context, node);
			}
			catch (Exception e)
			{
                context.ReportMessage(e, node);
			}
		}
Exemple #5
0
        public static void Verify(VerificationContext context, ASTNode node)
        {
            try
            {
                var verifier = NodeVerifierFactory.GetHandler(node.NodeType);

                // Traversal occurs within the verify, because traversal may happen differently depending on the operation.
                verifier.Verify(context, node);
            }
            catch (Exception e)
            {
                context.ReportMessage(e, node);
            }
        }
		private void VerifyExpressionNodes(VerificationContext context, Node node)
		{
			var astNode = node as ASTNode;
			if (astNode != null)
			{
				Verifier.Verify(context, astNode);
			}
			else
			{
				foreach (var child in node.Children)
				{
					VerifyExpressionNodes(context, child);
				}
			}
		}
        private void VerifyExpressionNodes(VerificationContext context, Node node)
        {
            var astNode = node as ASTNode;

            if (astNode != null)
            {
                Verifier.Verify(context, astNode);
            }
            else
            {
                foreach (var child in node.Children)
                {
                    VerifyExpressionNodes(context, child);
                }
            }
        }
Exemple #8
0
        public IEnumerable <VerificationException> Verify(Library library)
        {
            // Parameters must be validated without access to parameter definitions, or expression definitions
            var initialContext = new VerificationContext(library.Models, library.Libraries, null, null, null, null, null);

            // Resolve parameter types and verify default expressions
            foreach (var parameter in library.Parameters)
            {
                try
                {
                    parameter.ParameterType = initialContext.ResolveType(parameter.TypeName);

                    if (parameter.Default != null)
                    {
                        Verifier.Verify(initialContext, parameter.Default);
                        initialContext.VerifyType(parameter.Default.ResultType, parameter.ParameterType);
                    }
                }
                catch (Exception e)
                {
                    initialContext.ReportMessage(new VerificationException(String.Format("Exceptions occurred verifying parameter {0}.", parameter.Name), e), null);
                }
            }

            var context = new VerificationContext(library.Models, library.Libraries, library.Parameters, library.Expressions, library.CodeSystems, library.ValueSets, initialContext.Messages);

            // Verify expressions
            foreach (var expression in library.Expressions)
            {
                // If the result type is already set, this expression ref has already been resolved.
                if (expression.Expression.ResultType == null)
                {
                    Verifier.Verify(context, expression.Expression);
                }
            }

            return(context.Messages);
        }
Exemple #9
0
        public static Library ResolveLibrary(LibraryRef libraryRef, VerificationContext context)
        {
            Library library;

            if (!_libraries.TryGetValue(libraryRef.Name, out library))
            {
                if (context == null)
                {
                    throw new InvalidOperationException("Cannot perform type verification on a library without a verification context.");
                }

                if (resolvingLibraries.Contains(libraryRef.Name))
                {
                    throw new InvalidOperationException(String.Format("Circular library reference to library {0}.", libraryRef.Name));
                }

                resolvingLibraries.Push(libraryRef.Name);
                try
                {
                    library = LibraryReaderFactory.GetHandler(libraryRef.MediaType).Read(libraryRef);
                    var verifier = new LibraryVerifier();
                    IEnumerable <VerificationException> results = verifier.Verify(library);
                    context.Messages.AddRange(results);
                    _libraries.Add(libraryRef.Name, library);

                    if (results.Any(r => !r.IsWarning))
                    {
                        throw new InvalidOperationException(String.Format("Errors encountered while verifying library {0}.", libraryRef.Name));
                    }
                }
                finally
                {
                    resolvingLibraries.Pop();
                }
            }

            return(library);
        }
		public IEnumerable<VerificationException> Verify(Library library)
		{
			// Parameters must be validated without access to parameter definitions, or expression definitions
			var initialContext = new VerificationContext(library.Models, library.Libraries, null, null, null, null, null);

			// Resolve parameter types and verify default expressions
			foreach (var parameter in library.Parameters)
			{
				try
				{
					parameter.ParameterType = initialContext.ResolveType(parameter.TypeName);

					if (parameter.Default != null)
					{
						Verifier.Verify(initialContext, parameter.Default);
					    initialContext.VerifyType(parameter.Default.ResultType, parameter.ParameterType);
					}
				}
				catch (Exception e)
				{
					initialContext.ReportMessage(new VerificationException(String.Format("Exceptions occurred verifying parameter {0}.", parameter.Name), e), null);
				}
			}

			var context = new VerificationContext(library.Models, library.Libraries, library.Parameters, library.Expressions, library.CodeSystems, library.ValueSets, initialContext.Messages);

			// Verify expressions
			foreach (var expression in library.Expressions)
			{
				// If the result type is already set, this expression ref has already been resolved.
				if (expression.Expression.ResultType == null)
				{
					Verifier.Verify(context, expression.Expression);
				}
			}

            return context.Messages;
		}
		public static Library ResolveLibrary(LibraryRef libraryRef, VerificationContext context)
		{
			Library library;
			if (!_libraries.TryGetValue(libraryRef.Name, out library))
			{
				if (context == null)
				{
					throw new InvalidOperationException("Cannot perform type verification on a library without a verification context.");
				}

				if (resolvingLibraries.Contains(libraryRef.Name))
				{
					throw new InvalidOperationException(String.Format("Circular library reference to library {0}.", libraryRef.Name));
				}

				resolvingLibraries.Push(libraryRef.Name);
				try
				{
					library = LibraryReaderFactory.GetHandler(libraryRef.MediaType).Read(libraryRef);
					var verifier = new LibraryVerifier();
					IEnumerable<VerificationException> results = verifier.Verify(library);
					context.Messages.AddRange(results);
					_libraries.Add(libraryRef.Name, library);

					if (results.Any(r => !r.IsWarning))
					{
						throw new InvalidOperationException(String.Format("Errors encountered while verifying library {0}.", libraryRef.Name));
					}
				}
				finally
				{
					resolvingLibraries.Pop();
				}
			}

			return library;
		}
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			var source = node.Children[0];
			var element = node.Children[1];

			var sourceListType = source.ResultType as ListType;
			if (sourceListType != null)
			{
				context.VerifyType(element.ResultType, sourceListType.ElementType);

				node.ResultType = DataTypes.Boolean;
			}

			var sourceIntervalType = source.ResultType as IntervalType;
			if (sourceIntervalType != null)
			{
				context.VerifyType(element.ResultType, sourceIntervalType.PointType);

				node.ResultType = DataTypes.Boolean;
			}

			if (node.ResultType == null)
			{
				throw new InvalidOperationException("Expected an argument of type list or interval.");
			}
		}
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			var source = node.Children[0];
			var index = node.Children[1];

			var sourceListType = source.ResultType as ListType;
			if (sourceListType != null)
			{
				node.ResultType = sourceListType.ElementType;
			}
			else
			{
				context.VerifyType(source.ResultType, DataTypes.String);
				node.ResultType = DataTypes.String;
			}

			context.VerifyType(index.ResultType, DataTypes.Integer);
		}
		public void Verify(VerificationContext context, ASTNode node)
		{
			var comparand = node.Children.FirstOrDefault(n => n.Name == "comparand");

			DataType comparisonType = null;
			if (comparand != null)
			{
				Verifier.Verify(context, comparand);
				comparisonType = comparand.ResultType;
			}
			else
			{
				comparisonType = DataTypes.Boolean;
			}

			DataType resultType = null;

			foreach (var caseItem in ((Node)node).Children.Where(n => n.Name == "caseItem"))
			{
				var when = caseItem.Children[0] as ASTNode;
				var then = caseItem.Children[1] as ASTNode;

				Verifier.Verify(context, when);
				context.VerifyType(when.ResultType, comparisonType);

				Verifier.Verify(context, then);
				if (resultType == null)
				{
					resultType = then.ResultType;
					if (resultType == null)
					{
						throw new InvalidOperationException("Could not determine result type for case expression based on then element of first case item.");
					}
				}
				else
				{
					context.VerifyType(then.ResultType, resultType);
				}
			}

			var elseNode = node.Children.FirstOrDefault(n => n.Name == "else") as ASTNode;
			if (elseNode != null)
			{
				Verifier.Verify(context, elseNode);
				context.VerifyType(elseNode.ResultType, resultType);
			}

			node.ResultType = resultType;
		}
        private void VerifyResponseBindings(VerificationContext context, Node node, Dictionary <string, ParameterDef> containers)
        {
            // foreach action
            // If DeclareResponseAction
            // Create a parameter with that name
            // If CollectInformationAction
            // Create a property on the appropriate parameter with the correct type
            // Name = responseBinding.property
            // Type = responseCardinality = Single ? responseDataType : List<responseDataType>

            try
            {
                switch (node.NodeType.GetLocalName())
                {
                case "DeclareResponseAction":
                {
                    var containerName = node.GetAttribute <string>("name");
                    var container     = new ParameterDef {
                        Name = containerName, ParameterType = new ObjectType(containerName + "Type", new List <PropertyDef> {
                            })
                    };
                    containers.Add(container.Name, container);
                }
                break;

                case "CollectInformationAction":
                {
                    var responseBinding = node.Children.FirstOrDefault(c => c.Name == "responseBinding");
                    if (responseBinding != null)
                    {
                        var containerName = responseBinding.GetAttribute <string>("container");
                        if (String.IsNullOrEmpty(containerName))
                        {
                            containerName = "Responses";
                        }

                        if (!containers.ContainsKey(containerName))
                        {
                            throw new InvalidOperationException(String.Format("Could not resolve response container name {0}.", containerName));
                        }

                        var container     = containers[containerName];
                        var containerType = (ObjectType)container.ParameterType;

                        DataType responseType         = null;
                        var      responseName         = responseBinding.GetAttribute <string>("property");
                        var      documentationConcept = node.Children.FirstOrDefault(c => c.Name == "documentationConcept");
                        if (documentationConcept != null)
                        {
                            var responseDataType = documentationConcept.Children.FirstOrDefault(c => c.Name == "responseDataType");
                            if (responseDataType != null)
                            {
                                responseType = context.ResolveType(responseDataType.GetAttribute <string>("value"));
                            }
                            else
                            {
                                responseType = DataTypes.String;
                            }

                            var responseCardinality = documentationConcept.Children.FirstOrDefault(c => c.Name == "responseCardinality");
                            if (responseCardinality != null)
                            {
                                if (responseCardinality.GetAttribute <string>("value") == "Multiple")
                                {
                                    responseType = new ListType(responseType);
                                }
                            }
                        }

                        if (responseType == null)
                        {
                            responseType = DataTypes.String;
                        }

                        if (containerType.Properties.FirstOrDefault(pd => pd.Name == responseName) != null)
                        {
                            throw new InvalidOperationException(String.Format("The response container {0} already has a response named {1}.", container.Name, responseName));
                        }

                        containerType.Properties.Add(new PropertyDef(responseName, responseType));
                    }
                }
                break;
                }
            }
            catch (Exception e)
            {
                context.ReportMessage(e, node);
            }

            foreach (var child in node.Children)
            {
                VerifyResponseBindings(context, child, containers);
            }
        }
		public void Verify(VerificationContext context, ASTNode node)
		{
            var valueNode = ((Node)node).Children.FirstOrDefault(c => c.Name == "value");

            if (valueNode == null)
            {
                throw new InvalidOperationException("Could not resolve value element for complex literal.");
            }

            var resultType = context.ResolveType(valueNode.NodeType);

            node.ResultType = resultType;
		}
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			var child = node.Children[0];
			var childListType = child.ResultType as ListType;
			if (childListType == null)
			{
				throw new InvalidOperationException("Expected an expression of a list type.");
			}

			node.ResultType = GetResultType(child);
		}
        protected override void InternalVerify(VerificationContext context, ASTNode node)
        {
            base.InternalVerify(context, node);

            var testType = context.ResolveType(node.GetAttribute<string>("isType"));

            node.ResultType = DataTypes.Boolean;
        }
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			var dataTypes = new List<DataType>();
			foreach (var child in node.Children)
			{
				if (child.ResultType == null)
				{
					throw new InvalidOperationException(String.Format("Could not determine type of '{0}' expression.", child.Name));
				}

				dataTypes.Add(child.ResultType);
			}

			var op = context.ResolveCall(GetOperatorName(node), new Signature(dataTypes));

			node.ResultType = op.ResultType;
		}
		public void Verify(VerificationContext context, ASTNode node)
		{
			Verifier.Verify(context, node.Children[0]);
			Verifier.Verify(context, node.Children[1]);

			var comparandType = node.Children[0].ResultType;
			context.VerifyType(node.Children[1].ResultType, comparandType);

			node.ResultType = comparandType;
		}
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			DataType operandType = null;

			foreach (var child in node.Children)
			{
				if (operandType == null)
				{
					operandType = child.ResultType;
				}
				else
				{
					context.VerifyType(child.ResultType, operandType);
				}
			}

			node.ResultType = operandType;
		}
		public void Verify(VerificationContext context, ASTNode node)
		{
			Verifier.Verify(context, node.Children[0]);

			context.VerifyType(node.Children[0].ResultType, DataTypes.Boolean);

			node.ResultType = DataTypes.Boolean;
		}
		public void Verify(VerificationContext context, ASTNode node)
		{
			node.ResultType = context.ResolveType(node.GetAttribute<string>("valueType"));
		}
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			foreach (var child in node.Children)
			{
				context.VerifyType(child.ResultType, GetOperandType());
			}

			node.ResultType = GetResultType();
		}
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			var left = node.Children[0];
			var right = node.Children[1];

			var leftIntervalType = left.ResultType as IntervalType;
			if (leftIntervalType != null)
			{
				context.VerifyType(right.ResultType, leftIntervalType);
				node.ResultType = DataTypes.Boolean;
			}
			else
			{
				throw new InvalidOperationException("List type expected.");
			}
		}
		public void Verify(VerificationContext context, ASTNode node)
		{
			var parameterDef = context.ResolveParameterRef(node.GetAttribute<string>("libraryName"), node.GetAttribute<string>("name"));
			node.ResultType = parameterDef.ParameterType;
		}
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			if (node.Children.Count == 0)
			{
				throw new InvalidOperationException("Expected at least one child argument.");
			}

			DataType operandType = null;
			foreach (var child in node.Children)
			{
				if (operandType == null)
				{
					operandType = child.ResultType;

					if (!(operandType is ListType || operandType is IntervalType))
					{
						throw new InvalidOperationException("List or interval type expected.");
					}
				}
				else
				{
					context.VerifyType(child.ResultType, operandType);
				}
			}

			node.ResultType = operandType;
		}
        protected override void InternalVerify(VerificationContext context, ASTNode node)
        {
            base.InternalVerify(context, node);

			node.ResultType = context.ResolveType(node.GetAttribute<String>("valueType"));
        }
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			var source = node.Children[0];
			var sourceIntervalType = source.ResultType as IntervalType;
			if (sourceIntervalType == null)
			{
				throw new InvalidOperationException("Interval type expected.");
			}

			node.ResultType = sourceIntervalType.PointType;
		}
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			var child = node.Children[0];
			var intervalType = child.ResultType as IntervalType;
			if (intervalType != null)
			{
				var lengthOperator = context.ResolveCall("Subtract", new Signature(new DataType[] { intervalType.PointType, intervalType.PointType }));
				node.ResultType = lengthOperator.ResultType;
			}
			else
			{
				context.VerifyType(child.ResultType, DataTypes.String);
				node.ResultType = DataTypes.Integer;
			}
		}
		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;
		}
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			var source = node.Children[0];
			var sourceListType = source.ResultType as ListType;
			if (sourceListType == null)
			{
				throw new InvalidOperationException("Source must be a list value.");
			}

			node.ResultType = sourceListType.ElementType;

            var orderBy = node.GetAttribute<string>("orderBy");
            if (!String.IsNullOrEmpty(orderBy))
            {
                context.ResolveProperty(node.ResultType, orderBy);
            }
		}
        public IEnumerable <VerificationException> Verify(Artifact artifact)
        {
            // Parameters must be validated without access to parameter definitions, or expression definitions
            var initialContext = new VerificationContext(artifact.Models, null, null, null);

            // Resolve parameter types and verify default expressions
            foreach (var parameter in artifact.Parameters)
            {
                try
                {
                    parameter.ParameterType = initialContext.ResolveType(parameter.TypeName);

                    if (parameter.Default != null)
                    {
                        Verifier.Verify(initialContext, parameter.Default);
                        initialContext.VerifyType(parameter.Default.ResultType, parameter.ParameterType);
                    }
                }
                catch (Exception e)
                {
                    initialContext.ReportMessage(new VerificationException(String.Format("Exceptions occurred verifying parameter {0}.", parameter.Name), e), null);
                }
            }

            var context = new VerificationContext(artifact.Models, artifact.Parameters, artifact.Expressions, initialContext.Messages);

            // Verify expressions
            foreach (var expression in artifact.Expressions)
            {
                // If the result type is already set, this expression ref has already been resolved.
                if (expression.Expression.ResultType == null)
                {
                    Verifier.Verify(context, expression.Expression);
                }
            }

            // Verify conditions
            foreach (var condition in artifact.Conditions)
            {
                Verifier.Verify(context, condition);

                if (!DataTypes.Equal(condition.ResultType, DataTypes.Boolean))
                {
                    context.ReportMessage(new InvalidOperationException("Condition must evaluate to a value of type boolean."), condition);
                }
            }

            // Verify trigger expressions
            foreach (var trigger in artifact.Triggers)
            {
                VerifyExpressionNodes(context, trigger);
            }

            // Verify action conditions
            if (artifact.ActionGroup != null)
            {
                var containers = new Dictionary <string, ParameterDef>();

                // Verify documentation template conditions and binding expressions
                VerifyResponseBindings(context, artifact.ActionGroup, containers);

                foreach (var parameter in containers.Values)
                {
                    context.AddParameterDef(parameter);
                }

                VerifyExpressionNodes(context, artifact.ActionGroup);
            }

            return(context.Messages);
        }
		public void Verify(VerificationContext context, ASTNode node)
		{
			node.ResultType = context.ResolveType((String)node.Attributes["valueType"]);
		}
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			var leftType = node.Children[0].ResultType;
			var rightType = node.Children[1].ResultType;

			if (leftType is ScalarType || rightType is ScalarType)
			{
				var op = context.ResolveCall(GetOperatorName(), new Signature(new[] { leftType, rightType }));
				node.ResultType = op.ResultType;
			}
			else
			{
				if (DataTypes.Equal(leftType, rightType))
				{
					node.ResultType = DataTypes.Boolean;
				}
				else
				{
					throw 
						new InvalidOperationException
						(
							String.Format
							(
								"Cannot resolve operator {0} for operands of type {1} and {2}", 
								GetOperatorName(),
								leftType != null ? leftType.Name : "<unknown>", 
								rightType != null ? rightType.Name : "<unknown>"
							)
						);
				}
			}
		}
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);
			var conditionNode = node.Children[0];
			var thenNode = node.Children[1];
			var elseNode = node.Children[2];

			context.VerifyType(conditionNode.ResultType, DataTypes.Boolean);

			var resultType = thenNode.ResultType;

			if (resultType == null)
			{
				throw new InvalidOperationException("Could not determine type of then expression for conditional.");
			}

			context.VerifyType(elseNode.ResultType, resultType);

			node.ResultType = resultType;
		}