/// <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}"); } }
/// <summary> /// Specialized helper constructor /// </summary> /// <param name="target">The member that is being referenced</param> public MemberReferenceExpression(DataElement target) { this.Target = target; this.SourceResultType = target.CecilType; }
/// <summary> /// Specialized helper constructor /// </summary> /// <param name="target">The item the identifier resolves to</param> public IdentifierExpression(DataElement target) { this.Target = target; this.SourceResultType = target.CecilType; }
/// <summary> /// Constructs a new variable /// </summary> /// <param name="name">The variable name.</param> /// <param name="defaultValue">The default value</param> /// <param name="arrayLengthSource">The item indicating the array length source, if this constant references an array length</param> public Constant(string name, object defaultValue = null, DataElement arrayLengthSource = null) { this.Name = name; this.DefaultValue = defaultValue; this.ArrayLengthSource = arrayLengthSource; }
/// <summary> /// Sets the default value for a field /// </summary> /// <param name="network">The top-level network.</param> /// <param name="proc">The process where the method is located.</param> /// <param name="item">The data element to set the default value for.</param> /// <param name="value">The value to set.</param> /// <param name="is_static">A flag indicating if the variable default is statically defined.</param> protected virtual void SetDataElementDefaultValue(NetworkState network, ProcessState proc, DataElement item, object value, bool is_static) { item.DefaultValue = value; }