/// <summary> /// Enumerates all elements in the item, and optionally applies the visitor function /// </summary> /// <param name="self">The item to traverse.</param> /// <param name="visitor">The visitor method. Return <c>false</c> to prevent entering this node.</param> public static IEnumerable <ASTItem> All(this ASTItem self, Func <ASTItem, VisitorState, bool> visitor = null) { if (self is Network) { return(All((Network)self, visitor)); } if (self is Process) { return(All((Process)self, visitor)); } if (self is Bus) { return(All((Bus)self, visitor)); } if (self is Method) { return(All((Method)self, visitor)); } if (self is Statement) { return(All((Statement)self, visitor)); } if (self is Expression) { return(All((Expression)self, visitor)); } throw new Exception($"Unable to visit expression of type {self.GetType().FullName}"); }
/// <summary> /// Sets the target value /// </summary> /// <returns>The target variable or signal.</returns> /// <param name="self">The item to set the element on.</param> /// <param name="target">The value to set</param> public static void SetTarget(this ASTItem self, DataElement target) { if (self is IdentifierExpression) { ((IdentifierExpression)self).Target = target; } else if (self is MemberReferenceExpression) { ((MemberReferenceExpression)self).Target = target; } else if (self is WrappingExpression) { SetTarget(((WrappingExpression)self).Expression, target); } else if (self is Expression && self != ((Expression)self).GetUnwrapped()) { SetTarget(((Expression)self).GetUnwrapped(), target); } else { throw new Exception($"Unable to set target on item of type {self.GetType().FullName}"); } }