public override void OnGUI() { using (gui.Horizontal()) { var current = memberValue; var newValue = GetField()(niceName, current); { if (!VectorEquals(current, newValue)) { memberValue = newValue; } } gui.Space(12f); Foldout(); gui.Space(-10f); } if (foldout) { using (gui.Horizontal()) { DoButtons(); gui.Space(25f); } } }
/// <summary> /// Lowers get field operations into separate SSA values. /// </summary> private static void Lower( SSARewriterContext <FieldRef> context, LoweringData _, GetField getField) { if (getField.Type is StructureType structureType) { foreach (var(_, fieldAccess) in structureType) { // Get the source value var value = context.GetValue( context.Block, new FieldRef( getField.ObjectValue, new FieldSpan( getField.FieldSpan.Index + fieldAccess.Index))); // Bind the mapped SSA value context.SetValue( context.Block, new FieldRef(getField, fieldAccess), value); } context.Remove(getField); } else { var getFieldValue = context.GetValue( context.Block, new FieldRef(getField.ObjectValue, getField.FieldSpan)); context.ReplaceAndRemove(getField, getFieldValue); } }
private static bool AreDifferentOperators(GetField firstOperator, GetField secondOperator, int[] calls, int i, int j, LocalOperation[] localOperations) { if (firstOperator.FieldName != secondOperator.FieldName) { return(true); } if (!firstOperator.Instance.Equals(secondOperator.Instance)) { return(true); } var definitions = new HashSet <LocalVariable> { firstOperator.Instance }; var isReassigned = false; for (var index = calls[i] + 1; index < calls[j]; index++) { var op = localOperations[index]; var def = op.GetDefinition(); if (def == null) { continue; } if (!definitions.Contains(def)) { continue; } isReassigned = true; break; } return(isReassigned); }
/// <summary cref="IBackendCodeGenerator.GenerateCode(GetField)"/> public void GenerateCode(GetField value) { var source = Load(value.ObjectValue); var target = Allocate(value); var span = value.FieldSpan; if (!span.HasSpan) { // Extract primitive value from the given target using var statement = BeginStatement(target); statement.AppendArgument(source); statement.AppendField(span.Access); } else { // Result is a structure type Declare(target); for (int i = 0; i < span.Span; ++i) { using var statement = BeginStatement(target, i); statement.AppendArgument(source); statement.AppendField(span.Access.Add(i)); } } }
/// <summary cref="IValueVisitor.Visit(GetField)"/> public void Visit(GetField value) { var source = Load(value.ObjectValue); var target = Allocate(value); using (var statement = BeginStatement(target)) { statement.AppendArgument(source); statement.AppendField(value.FieldIndex); } }
public static void WriteEnum <T>(string enumName, string group, IEnumerable <T> values, Validator <T> validator, GetField <T> getNameDelegate, GetField <T> getIdDelegate) { WriteEnum(enumName, group, values, false, validator, getNameDelegate, null, null, getIdDelegate); }
/// <summary> /// Lowers set field operations into separate SSA values. /// </summary> protected static void Lower( RewriterContext context, TypeLowering <TType> typeConverter, GetField getValue) { var builder = context.Builder; var location = getValue.Location; // Compute the new base index var span = typeConverter.ComputeSpan(getValue, getValue.FieldSpan); // Check whether we have to extract a nested type implementation Value newValue; if (typeConverter[getValue] is TType) { // We have to extract multiple elements from this structure var instance = builder.CreateDynamicStructure(location, span.Span); for (int i = 0; i < span.Span; ++i) { var viewField = builder.CreateGetField( location, getValue.ObjectValue, new FieldSpan(span.Index + i)); instance.Add(viewField); } newValue = instance.Seal(); } else { // Simple field access newValue = builder.CreateGetField( location, getValue.ObjectValue, span); } context.ReplaceAndRemove(getValue, newValue); }
public void LoadField(string fieldName, ClosureEntities closureEntities) { var firstVar = _evaluator.Pop(); var vreg = SetNewVReg(); var computedType = firstVar.ComputedType(); if (computedType.GetClrType(closureEntities).IsByRef) { computedType = new TypeDescription(computedType.GetClrType(closureEntities).GetElementType()); } vreg.FixedType = new TypeDescription( computedType.GetClrType(closureEntities).LocateField(fieldName).FieldType); var assignment = new GetField { AssignedTo = vreg, FieldName = fieldName, Instance = (LocalVariable)firstVar }; AddOperation(assignment); }
/// <summary cref="IBackendCodeGenerator.GenerateCode(GetField)"/> public void GenerateCode(GetField value) { var source = LoadAs <CompoundRegister>(value.ObjectValue); if (!value.FieldSpan.HasSpan) { Bind(value, source.Children[value.FieldSpan.Index]); } else { int span = value.FieldSpan.Span; var childRegisters = ImmutableArray.CreateBuilder <Register>(span); for (int i = 0; i < span; ++i) { childRegisters.Add(source.Children[i + value.FieldSpan.Index]); } Bind( value, new CompoundRegister( value.Type as StructureType, childRegisters.MoveToImmutable())); } }
public void Visit(GetField value) { }
/// <summary cref="IValueVisitor.Visit(GetField)"/> public void Visit(GetField value) => CodeGenerator.GenerateCode(value);
/// <summary cref="IValueVisitor.Visit(GetField)"/> public void Visit(GetField value) => MakeCompoundRegisterLoad(value, value.FieldIndex);
public static void WriteEnum <T>( string enumName, string group, IEnumerable <T> values, bool hexadecimal, Validator <T> validator, GetField <T> getNameDelegate, GetField <T> getCommentDelegate, GetField <T, string> getDuplNameDelegate, GetField <T> getIdDelegate) { var dir = Path.Combine(Dir, group); Directory.CreateDirectory(dir); string file = Path.Combine(dir, enumName + ".cs"); Console.Write("Writing enum {0} to {1}...", enumName, new DirectoryInfo(file).FullName); bool first = true; using (var writer = new CodeFileWriter(new StreamWriter(file), "WCell.Constants." + group, enumName, "enum")) { var lines = new List <string>(values.Count()); var names = new Dictionary <string, int>(values.Count()); foreach (var item in values) { if (item == null || !validator(item)) { continue; } string name = getNameDelegate(item).Replace("%", "Percent"); name = name.Replace("'s", "s"); string[] parts = Regex.Split(name, @"\s+|[^\w\d_]+", RegexOptions.None); for (int i = 0; i < parts.Length; i++) { string part = parts[i]; if (part.Length == 0) { continue; } //if (part.Length > 1) { // part = part.ToLower(); string firstChar = part[0] + ""; part = firstChar.ToUpper() + part.Substring(1); //} //else { // part = part.ToUpper(); //} parts[i] = part; } name = string.Join("", parts); // against digits at the start Match numMatch = NumRegex.Match(name); if (numMatch.Success) { string num = GetNumString(numMatch.Value); if (name.Length > num.Length) { name = num + name.Substring(numMatch.Value.Length, 1).ToUpper() + name.Substring(numMatch.Value.Length + 1); } else { name = num; } } int count; if (!names.TryGetValue(name, out count)) { names.Add(name, 1); } else { names.Remove(name); names.Add(name, ++count); string duplName = null; if (getDuplNameDelegate != null) { duplName = getDuplNameDelegate(item, name); } if (duplName != null) { name = duplName; } else { name = name + "_" + count; } } string val = getIdDelegate(item); if (hexadecimal) { try { int ival = Convert.ToInt32(val); val = string.Format("0x{0:x}", ival); } catch { }; } if (first) { first = false; if (long.Parse(val) > 0) { writer.WriteLine("None = 0,"); } } string comment = ""; if (getCommentDelegate != null) { comment = getCommentDelegate(item); if (comment != null) { string[] commentLines = comment.Split(new string[] { "\n", "\r\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); if (commentLines.Length > 0) { writer.StartSummary(); foreach (string line in commentLines) { writer.WriteXmlCommentLine(line); } writer.EndSummary(); } } } writer.WriteLine(string.Format("{0} = {1},", name, val)); } writer.WriteLine("End"); writer.Finish(); Console.WriteLine(" Done."); } }
internal static FieldInfo?Find(ExpressionSyntax expression, SemanticModel semanticModel, CancellationToken cancellationToken) { if (GetField.Match(expression, semanticModel, cancellationToken) is { Member : { ReflectedType : { } reflectedType, Symbol : IFieldSymbol symbol } })
private Pluck GetUserFullName(GetField field) { return(_userTable.Get(field).Pluck(nameof(User.FullName))); }
public static void WriteEnum <T>( string enumName, string enumSuffix, string group, IEnumerable <T> values, bool hexadecimal, Validator <T> validator, GetField <T> getNameDelegate, GetField <T> getCommentDelegate, GetField <T, string> getDuplNameDelegate, GetField <T> getIdDelegate) { Init(); var dir = Path.Combine(Dir, group); Directory.CreateDirectory(dir); var file = Path.Combine(dir, enumName + ".cs"); Console.Write("Writing enum {0} to {1}...", enumName, new DirectoryInfo(file).FullName); var first = true; using (var writer = new CodeFileWriter(file, "WCell.Constants." + group, enumName, "enum", enumSuffix)) { try { var names = new Dictionary <string, int>(values.Count()); foreach (T item in values) { if (item == null || item.Equals(default(T)) || !validator(item)) { continue; } var name = getNameDelegate(item); if (name == null) { throw new Exception(string.Format("Name for Item {0} in {1}/{2} was null.", item, group, enumName)); } name = BeautifyName(name); int count; if (!names.TryGetValue(name, out count)) { names.Add(name, 1); } else { names.Remove(name); names.Add(name, ++count); string duplName = null; if (getDuplNameDelegate != null) { duplName = getDuplNameDelegate(item, name); } if (duplName != null) { name = duplName; } else { name = name + "_" + count; } } var val = getIdDelegate(item); if (hexadecimal) { int ival; if (int.TryParse(val, out ival)) { val = string.Format("0x{0:x}", ival); } } if (first) { first = false; long id; if (!long.TryParse(val, out id)) { throw new InvalidDataException("Invalid ID was not numeric: " + val); } if (id > 0) { writer.WriteLine("None = 0,"); } } string comment; if (getCommentDelegate != null) { comment = getCommentDelegate(item); if (comment != null) { var commentLines = comment.Split(new[] { "\n", "\r\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); if (commentLines.Length > 0) { writer.StartSummary(); foreach (string line in commentLines) { writer.WriteXmlCommentLine(line); } writer.EndSummary(); } } } writer.WriteLine(string.Format("{0} = {1},", name, val)); } writer.WriteLine("End"); writer.Finish(); Console.WriteLine(" Done."); } catch (Exception ex) { writer.OnException(ex); } } }