public object Translate(TranslationContext context, ASTNode node)
		{
			var result = new SQLModel.TableExpression();
			var sqlContext = (SQLTranslationContext)context;
			result.TableName = sqlContext.GetExpressionObjectName(String.Format("{0}.{1}", node.GetAttribute<string>("libraryName", sqlContext.ArtifactName), node.GetAttribute<string>("name")));

			// If the expression being referenced is scalar, it will be automatically promoted to a query by the expression def translation
			// In this case, it must be demoted back to a scalar expression with a subquery access.
			if (!(node.ResultType is ListType) && !(node.ResultType is ObjectType))
			{
				var selectExpression = new SQLModel.SelectExpression();
				selectExpression.SelectClause = new SQLModel.SelectClause();
				selectExpression.SelectClause.Columns.Add(new SQLModel.ColumnExpression(new SQLModel.QualifiedFieldExpression("value")));
				selectExpression.FromClause = new SQLModel.CalculusFromClause(new SQLModel.TableSpecifier(result));

				// If the result type is also boolean, the expression will be converted to a 1 or 0, so it must be demoted back to an actual boolean-valued expression
				if (DataTypes.Equal(node.ResultType, DataTypes.Boolean))
				{
					return SQLTranslationUtilities.DemoteBooleanValuedExpression(selectExpression);
				}

				return selectExpression;
			}

			return result;
		}
		protected virtual void InternalVerify(VerificationContext context, ASTNode node)
		{
			foreach (var child in node.Children)
			{
				Verifier.Verify(context, child);
			}
		}
		private CREFModel.DynamicRuleDynamicRuleCriteria TranslateCriteria(TranslationContext context, ASTNode condition)
		{
			var result = new CREFModel.DynamicRuleDynamicRuleCriteria();

			result.Item = context.TranslateNode(condition);

			return result;
		}
		public object Translate(TranslationContext context, ASTNode node)
		{
			var result = new CREFModel.ExpressionReference();

			result.Name = node.GetAttribute<string>("name");

			return result;
		}
		public static Node ReadNode(XElement element)
		{
			var nodeName = element.Name.LocalName;
			var nodeType = element.GetSchemaInfo().SchemaType;

			Node result = null;
			ASTNode astResult = null;

			if (IsExpression(nodeType))
			{
				astResult = new ASTNode();
				result = astResult;
			}
			else
			{
				result = new Node();
			}

			result.Name = nodeName;
			result.NodeType = nodeType.QualifiedName.ToString();
			var lineInfo = element as IXmlLineInfo;
			if (lineInfo != null && lineInfo.HasLineInfo())
			{
				result.Line = lineInfo.LineNumber;
				result.LinePos = lineInfo.LinePosition;
			}

			result.Attributes = new Dictionary<string, object>();
			foreach (var a in element.Attributes())
			{
				var schemaInfo = a.GetSchemaInfo();
				if (schemaInfo != null && schemaInfo.SchemaType != null && schemaInfo.SchemaType.QualifiedName != null && schemaInfo.SchemaType.QualifiedName.Name == "QName")
				{
					result.Attributes.Add(a.Name.LocalName, element.ExpandName(a.Value));
				}
				else
				{
					result.Attributes.Add(a.Name.LocalName, a.Value);
				}
			}

			result.Children = new List<Node>();
			foreach (var e in element.Elements())
			{
				if (e.Name.LocalName == "description" && astResult != null)
				{
					astResult.Description = e.Value;
				}
				else
				{
					result.Children.Add(ReadNode(e));
				}
			}

			return result;
		}
		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;
		}
		public object Translate(TranslationContext context, ASTNode node)
		{
			var result = new CREFModel.ParameterExpression();

			result.Name = node.GetAttribute<string>("name");

			// TODO: Default value?

			return result;
		}
		protected object TranslateCodeReference(TranslationContext context, ObjectType sourceType, ASTNode node, string path)
		{
			// Reference the Codes property with a First expression
			var result = GetPropertyExpression(context, node, "Codes");

			result = GetFirstExpression(context, result);

			// TODO: Issue a warning that an arbitrary Code is being selected

			return result;
		}
		public object Translate(TranslationContext context, ASTNode node)
		{
			var result = new SQLModel.TableExpression();

			// TODO: Handle Cardinality
			// TODO: Handle whether we are in a FromClause context.
			var sqlContext = (SQLTranslationContext)context;
			result.TableName = sqlContext.GetExpressionObjectName(String.Format("{0}.{1}", node.GetAttribute<string>("libraryName", sqlContext.ArtifactName), node.GetAttribute<string>("name")));

			return result;
		}
		protected object GetPropertyExpression(TranslationContext context, ASTNode node, string path)
		{
			var result = new SQLModel.PropertyExpression();
			result.Path = path;

			if (node.Children.Count > 0)
			{
				result.Item = context.TranslateNode(node.Children[0]);
			}

			return result;
		}
示例#11
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.BinaryExpression();
            result.Operator = GetOperator();
            result.OperatorSpecified = true;

            foreach (var child in node.Children)
            {
                result.Items.Add(context.TranslateNode(child));
            }

            return result;
        }
示例#12
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);
			}
		}
		public object Translate(TranslationContext context, ASTNode node)
		{
			var result = new CREFModel.ValueExpression();

			if (DataTypes.Equal(node.ResultType, DataTypes.String))
			{
				result.Type = Model.ValueType.String;
				result.TypeSpecified = true;
				result.Value = node.GetAttribute<string>("value");
			}
			else if (DataTypes.Equal(node.ResultType, DataTypes.Integer))
			{
				result.Type = Model.ValueType.Int32;
				result.TypeSpecified = true;
				result.Value = node.GetAttribute<string>("value");
			}
			else if (DataTypes.Equal(node.ResultType, DataTypes.Boolean))
			{
				result.Type = Model.ValueType.Boolean;
				result.TypeSpecified = true;
				result.Value = node.GetAttribute<string>("value");
			}
			else if (DataTypes.Equal(node.ResultType, DataTypes.Decimal))
			{
				result.Type = Model.ValueType.Decimal;
				result.TypeSpecified = true;
				result.Value = node.GetAttribute<string>("value");
			}
			else if (DataTypes.Equal(node.ResultType, DataTypes.DateTime))
			{
				result.Type = Model.ValueType.Date;
				result.TypeSpecified = true;
				result.Value = node.GetAttribute<string>("value"); // TODO: Convert to format expected by CREF
			}
			else
			{
				throw new NotSupportedException(String.Format("Unsupported literal type: {0}.", node.ResultType.Name));
			}

			return result;
		}
		public object Translate(TranslationContext context, ASTNode node)
		{
			if (DataTypes.Equal(node.ResultType, DataTypes.Boolean))
			{
				return new Model.BinaryExpression(new Model.ValueExpression(1), "iEqual", new Model.ValueExpression(Boolean.Parse(node.GetAttribute<string>("value")) ? 1 : 0));
			}
			else if (DataTypes.Equal(node.ResultType, DataTypes.DateTime))
			{
				// TODO: Convert to format expected by T-SQL
				return new Model.CallExpression("convert", new Model.Expression[] { new Model.IdentifierExpression("datetime"), new Model.ValueExpression(node.GetAttribute<string>("value")) }); 
			}
			else
			{
				var result = new Model.ValueExpression();

				if (DataTypes.Equal(node.ResultType, DataTypes.String))
				{
					result.Token = Model.TokenType.String;
					result.Value = node.GetAttribute<string>("value");
				}
				else if (DataTypes.Equal(node.ResultType, DataTypes.Integer))
				{
					result.Token = Model.TokenType.Integer;
					result.Value = Int32.Parse(node.GetAttribute<string>("value"));
				}
				else if (DataTypes.Equal(node.ResultType, DataTypes.Decimal))
				{
					result.Token = Model.TokenType.Decimal;
					result.Value = Decimal.Parse(node.GetAttribute<string>("value"));
				}
				else
				{
					throw new NotSupportedException(String.Format("Unsupported literal type: {0}.", node.ResultType.Name));
				}

				return result;
			}
		}
示例#15
0
        protected override DataType GetResultType(ASTNode node)
        {
            var listType = node.ResultType as ListType;
            if (!(listType.ElementType is IntervalType))
            {
                throw new InvalidOperationException("Collapse operator must be invoked on a list of intervals.");
            }

            return listType;
        }
示例#16
0
        protected override DataType GetResultType(ASTNode node)
        {
            var listType = node.ResultType as ListType;
            var childListType = listType.ElementType as ListType;
            if (childListType == null)
            {
                throw new InvalidOperationException("Expand operator must be invoked on a list of lists.");
            }

            return childListType;
        }
示例#17
0
		protected abstract DataType GetResultType(ASTNode node);
示例#18
0
		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);
		}
示例#19
0
		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;
		}
示例#20
0
		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;
		}
示例#21
0
		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;
		}
示例#22
0
 public void Verify(VerificationContext context, HeD.Engine.Model.ASTNode node)
 {
     // TODO: Implement generic identifier resolution. In theory, this isn't necessary because the CQL-to-ELM translator should never spit out this type of node.
     throw new InvalidOperationException(String.Format("Could not resolve identifier {0}{1}.", node.GetAttribute <String>("libraryName") ?? "", node.GetAttribute <String>("name")));
 }
示例#23
0
		protected override DataType GetResultType(ASTNode node)
		{
			return DataTypes.Boolean;
		}
		public object TransformModelPath(ObjectType type, ASTNode node, string path)
		{
			var translator = ModelTranslatorFactory.GetHandler(type.Name);

			return translator.TransformModelPath(this, type, node, path);
		}
示例#25
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)
                {
                    var returnElement = returnClause.Children.Where(c => c.Name == "expression").FirstOrDefault() as ASTNode;
                    if (returnElement == null)
                    {
                        throw new InvalidOperationException("Could not resolve return expression for return clause.");
                    }

                    Verifier.Verify(context, returnElement);
                    if (sourceSymbolListType != null)
                    {
                        node.ResultType = new ListType(returnElement.ResultType);
                    }
                    else
                    {
                        node.ResultType = returnElement.ResultType;
                    }
                }
                else
                {
                    node.ResultType = sourceSymbol.DataType;
                }

                // 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.");
                }
            }
            finally
            {
                context.PopSymbol();
            }
        }
示例#26
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;
		}
示例#27
0
		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.");
			}
		}
示例#28
0
 public void Verify(VerificationContext context, HeD.Engine.Model.ASTNode node)
 {
     throw new NotImplementedException();
 }
示例#29
0
		public void Verify(VerificationContext context, ASTNode node)
		{
			node.ResultType = context.ResolveType((String)node.Attributes["valueType"]);
		}
		public object TranslateNode(ASTNode node)
		{
			var translator = NodeTranslatorFactory.GetHandler(node.NodeType);

			return translator.Translate(this, node);
		}
示例#31
0
		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);
		}
		private Model.Statement TranslateCondition(SQLTranslationContext context, string artifactName, string conditionName, ASTNode condition)
		{
			var result = new SQLModel.CreateViewStatement();
			result.ViewName = context.GetExpressionObjectName(String.Format("{0}.{1}", artifactName, conditionName));
			result.Expression = SQLTranslationUtilities.EnsureSelectExpression(context.TranslateNode(condition));
			return result;
		}
示例#33
0
		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.");
			}
		}