public virtual void WriteNullOp(NullOp s, ExpressionUsage u) { Begin(u.IsObject()); WriteExpression(s.Left, ExpressionUsage.Operand); Write(NullOp); WriteExpression(s.Right, ExpressionUsage.Operand); End(u.IsObject()); }
public static Expression TransformNullOpToConditionalOp(this NullOp s, Essentials types, Namescope scope) { // a ?? b -> (temp = a, temp != null ? temp : b) // OR -> a != null ? a : b var left = s.Left; var right = s.Right; var ind = TryCreateIndirection(scope, ref left); var cond = new ReferenceOp(s.Source, types.Bool, EqualityType.NotEqual, left, new Constant(s.Source, left.ReturnType, null)); var result = new ConditionalOp(s.Source, cond, left, right); return(ind != null ? (Expression) new SequenceOp(ind, result) : result); }
/// <summary> /// NullOp /// If the node represents a null of an entity type it 'flattens' it into a new record, /// with at most one non-null value: for the typeIdProperty, if one is needed. /// If the node represents an null of a non-entity type, no special work is done. /// </summary> /// <param name="op"> The NullOp </param> /// <param name="n"> The current subtree </param> /// <returns> the new subtree </returns> public override Node Visit(NullOp op, Node n) { if (!TypeUtils.IsStructuredType(op.Type)) { if (md.TypeSemantics.IsEnumerationType(op.Type)) { op.Type = TypeHelpers.CreateEnumUnderlyingTypeUsage(op.Type); } else if (md.TypeSemantics.IsStrongSpatialType(op.Type)) { op.Type = TypeHelpers.CreateSpatialUnionTypeUsage(op.Type); } return n; } // Find the new type corresponding to the type var typeInfo = m_typeInfo.GetTypeInfo(op.Type); var newFields = new List<md.EdmProperty>(); var newFieldValues = new List<Node>(); // Add a typeid property if we need one if (typeInfo.HasTypeIdProperty) { newFields.Add(typeInfo.TypeIdProperty); var typeIdType = md.Helper.GetModelTypeUsage(typeInfo.TypeIdProperty); newFieldValues.Add(CreateNullConstantNode(typeIdType)); } var newRecordOp = new NewRecordOp(typeInfo.FlattenedTypeUsage, newFields); return m_command.CreateNode(newRecordOp, newFieldValues); }
/// <summary> /// Copies a NullOp /// </summary> /// <param name="op">The Op to Copy</param> /// <param name="n">The Node that references the Op</param> /// <returns>A copy of the original Node that references a copy of the original Op</returns> public override Node Visit(NullOp op, Node n) { return(m_destCmd.CreateNode(m_destCmd.CreateNullOp(op.Type))); }
/// <summary> /// Visitor pattern method for NullOp /// </summary> /// <param name="op"> The NullOp being visited </param> /// <param name="n"> The Node that references the Op </param> public virtual void Visit(NullOp op, Node n) { VisitConstantOp(op, n); }
// <summary> // Copies a NullOp // </summary> // <param name="op"> The Op to Copy </param> // <param name="n"> The Node that references the Op </param> // <returns> A copy of the original Node that references a copy of the original Op </returns> public override Node Visit(NullOp op, Node n) { return m_destCmd.CreateNode(m_destCmd.CreateNullOp(op.Type)); }