private void AddClassLevelVaribles(Tokenizer tokenizer) { while (tokenizer.Current is Keyword keyword && ( keyword == Keyword.Static || keyword == Keyword.Field)) { tokenizer.Move().CurrentIs(VaribleType.IsValid); var type = new VaribleType(tokenizer.GetCurrentThenMove()); tokenizer.CurrentIsIdentifier(); AddVarible(keyword, new Varible(type, tokenizer.GetCurrentThenMove() as Identifier)); while (tokenizer.Current.Equals(Symbol.Commna)) { tokenizer.Move().CurrentIsIdentifier(); AddVarible(keyword, new Varible(type, tokenizer.GetCurrentThenMove() as Identifier)); } tokenizer.CurrentIs(Symbol.SemiColon).Move(); } void AddVarible(Keyword keyword, Varible varible) { if (keyword == Keyword.Field) { Fields.Add(varible); } else { StaticFields.Add(varible); } } }
/// <summary> /// Retrieve a Field based off of its field name (tag element). /// This is only for static fields - use an integer to search custom fields. /// </summary> /// <param name="fieldName">Name of the field. Use the tag, not the display name ("Date_Created" rather than "Date Created" for example)</param> /// <returns>StaticField if found, otherwise null</returns> public StaticField this[string fieldName] { get { return(StaticFields.FirstOrDefault(f => f.Name == fieldName)); } set { StaticFields.RemoveAll(f => f.Name == fieldName && f is StaticField); StaticFields.Add(value); } }
private StaticField GetStaticField(string fieldName) { StaticField field; if (StaticFields.TryGetValue(fieldName, out field)) { return(field); } throw new FieldNotFoundException(string.Format("Static field {0} not found in class {1}.", fieldName, Name)); }
private void ResolveStaticFields(IEnumerable <StaticField> staticFields) { foreach (var staticField in staticFields) { if (!StaticFields.ContainsKey(staticField.Info.Name) && !staticField.Info.AccessFlags.HasFlag(FieldAccessFlags.Private)) { StaticFields.Add(staticField.Info.Name, staticField); } } }
private void AddStaticInitializer() { JasminFunctionModule staticInitializer = new JasminFunctionModule() .WithModifiers(JasminModifier.Static) .WithName(JasminReferenceConstants.MethodClInit) .WithReturnType(JasminReferenceConstants.JavaVoidPrimitive); StaticFields.Where(field => field.IsInitialized) .ForEach(field => { staticInitializer.WithInstructions(field.ValueInstructions); }); staticInitializer.WithInstructions(Instructions.ReturnInstruction); _functions.Add(staticInitializer); }
internal DllTypeData(TypeDefinition def, DllConfig config) { _config = config; foreach (var i in def.Interfaces) { ImplementingInterfaces.Add(DllTypeRef.From(i.InterfaceType)); } This = DllTypeRef.From(def); Type = def.IsEnum ? TypeEnum.Enum : (def.IsInterface ? TypeEnum.Interface : (def.IsValueType ? TypeEnum.Struct : TypeEnum.Class)); Info = new TypeInfo { Refness = def.IsValueType ? Refness.ValueType : Refness.ReferenceType }; if (def.BaseType != null) { Parent = DllTypeRef.From(def.BaseType); } // TODO: Parse this eventually TypeDefIndex = -1; if (_config.ParseTypeAttributes && def.HasCustomAttributes) { Attributes.AddRange(def.CustomAttributes.Select(ca => new DllAttribute(ca)).Where(a => !string.IsNullOrEmpty(a.Name))); } Layout = (ITypeData.LayoutKind)(def.Attributes & TypeAttributes.LayoutMask); if (_config.ParseTypeFields) { InstanceFields.AddRange(def.Fields.Where(f => !f.IsStatic).Select(f => new DllField(f))); StaticFields.AddRange(def.Fields.Where(f => f.IsStatic).Select(f => new DllField(f))); } if (_config.ParseTypeProperties) { Properties.AddRange(def.Properties.Select(p => new DllProperty(p))); } if (_config.ParseTypeMethods) { var mappedBaseMethods = new HashSet <MethodDefinition>(); var methods = def.Methods.Select(m => DllMethod.From(m, ref mappedBaseMethods)).ToList(); // It's important that Foo.IBar.func() goes after func() (if present) Methods.AddRange(methods.Where(m => m.ImplementedFrom is null)); Methods.AddRange(methods.Where(m => m.ImplementedFrom != null)); } }
/// <summary> /// Returns the value of the member of the specified name. /// </summary> /// <param name="context">The runtime context.</param> /// <param name="name">The name of the member.</param> /// <returns>The value of the member <paramref name="name"/>.</returns> IScriptObject IMemberObject.GetMember(RuntimeContexts.RuntimeContext context, string name) { IScriptObject value; string rename; var cls = context.Class as ClassObject; if (cls != null) { rename = ClassHelper.RenamePrivate(name, cls.Name); if (StaticFields.TryGetValue(rename, out value)) { return(value); } } { rename = name; if (StaticFields.TryGetValue(rename, out value)) { return(value); } } if (cls == this || ClassHelper.IsExtendedFrom(this, cls) || ClassHelper.IsExtendedFrom(cls, this)) { rename = ClassHelper.RenameProtected(name); if (StaticFields.TryGetValue(rename, out value)) { return(value); } } { var member = GetMember(context, name, true); var mtd = member as ClassMethod; if (mtd != null) { return(new BoundMethod(null, mtd)); } var proget = member as PropertyGetter; if (proget != null) { return(proget.GetProperty(null)); } } throw new InvalidOperationException( string.Format(ExceptionResource.MemberNotFound, name)); }
internal void AddFields(FieldInfo[] fields) { int instanceFieldsLength = InstanceFields.Count; int i = 0; foreach (var field in fields) { if (field.AccessFlags.HasFlag(FieldAccessFlags.Static)) { StaticFields.Add(field.Name, new StaticField(field)); } else { InstanceFields.Add(field.Name, new InstanceField(field, instanceFieldsLength + i)); i++; } } }
/// <summary> /// Sets the value of the member of the specified name to the specified value. /// </summary> /// <param name="context">The runtime context.</param> /// <param name="name">The name of the member.</param> /// <param name="value">The value to set.</param> void IMemberObject.SetMember(RuntimeContexts.RuntimeContext context, string name, IScriptObject value) { string rename; var cls = context.Class as ClassObject; if (cls != null) { rename = ClassHelper.RenamePrivate(name, cls.Name); if (StaticFields.ContainsKey(rename)) { StaticFields[rename] = value; return; } } { rename = name; if (StaticFields.ContainsKey(rename)) { StaticFields[rename] = value; return; } } if (cls == this || ClassHelper.IsExtendedFrom(this, cls) || ClassHelper.IsExtendedFrom(cls, this)) { rename = ClassHelper.RenameProtected(name); if (StaticFields.ContainsKey(rename)) { StaticFields[rename] = value; return; } } { var member = SetMember(context, name, true); var proset = member as PropertySetter; if (proset != null) { proset.SetProperty(this, value); return; } } throw new InvalidOperationException( string.Format(ExceptionResource.MemberNotFound, name)); }
private IList <MemoryElement> populateData(int numTotalElements) { var treeElements = new List <MemoryElement>(numTotalElements + 1); var root = new MemoryElement("Root", -1, 0, "Root", "Root", 0f); treeElements.Add(root); if (_unpackedCrawl == null) { return(treeElements); } ThingInMemory[] tmp = _unpackedCrawl.allObjects; for (int i = 0; i < numTotalElements; ++i) { if (tmp[i] is NativeUnityEngineObject) { NativeUnityEngineObject nuo = tmp[i] as NativeUnityEngineObject; root = new MemoryElement(nuo.caption, 0, nuo.instanceID, nuo.className, "Native", tmp[i].size); } else if (tmp[i] is ManagedObject) { ManagedObject mo = tmp[i] as ManagedObject; root = new MemoryElement(mo.caption, 0, 0, "Managed", "Managed", mo.size); } else if (tmp[i] is GCHandle) { GCHandle gch = tmp[i] as GCHandle; root = new MemoryElement(gch.caption, 0, 0, "GC Handle", "GC Handle", gch.size); } else if (tmp[i] is StaticFields) { StaticFields sf = tmp[i] as StaticFields; root = new MemoryElement(sf.caption, 0, 0, "GC Handle", sf.typeDescription.name, sf.size); } root.memData = tmp[i]; treeElements.Add(root); } return(treeElements); }
private void Other(TypeInfo ty, string var, VAL val) { string constKey = ToConstKey(var); string defaultKey = ToDefaultKey(var); Comment comment = new Comment(var) { Alignment = Alignment.Top }; //const key field Field field = new Field(new TypeInfo(typeof(string)), constKey, new Value(var)) { Modifier = Modifier.Public | Modifier.Const, }; ConstKeyFields.Add(field); //default value field Modifier modifier = Modifier.Public | Modifier.Const; string value = val.ToString(); if (val.IsList) { modifier = Modifier.Public | Modifier.Readonly | Modifier.Static; value = $"new {ty} " + value; } field = new Field(ty, defaultKey) { Modifier = modifier, UserValue = value, Comment = comment }; DefaultValueFields.Add(field); StaticFields.Add(createField(TOKEY(var), ty, var)); StaticProperties.Add(createProperty(toPascal(var), ty, var)); StaticMethods.Add(createMethod(toPascal(var), ty, var)); }
public FakeDebuggerRuntime(DmdRuntime runtime) { this.runtime = runtime ?? throw new ArgumentNullException(nameof(runtime)); staticFields = new StaticFields(); }
// TODO: remove public override ClrStaticField?GetStaticFieldByName(string name) => StaticFields.FirstOrDefault(f => f.Name == name);