public LocalReference DeclareLocal(Type type) { var local = new LocalReference(type); ilmarkers.Add(local); return(local); }
protected virtual void ImplementGetObjectData(Type[] interfaces) { this._generated.Add(typeof(ISerializable)); Type[] types = new Type[] { typeof(string), typeof(bool), typeof(bool) }; Type[] typeArray2 = new Type[] { typeof(string), typeof(object) }; MethodInfo info = typeof(SerializationInfo).GetMethod("AddValue", typeArray2); ArgumentReference owner = new ArgumentReference(typeof(SerializationInfo)); ArgumentReference reference2 = new ArgumentReference(typeof(StreamingContext)); EasyMethod method = this.MainTypeBuilder.CreateMethod("GetObjectData", new ReturnReferenceExpression(typeof(void)), new ArgumentReference[] { owner, reference2 }); LocalReference target = method.CodeBuilder.DeclareLocal(typeof(Type)); method.CodeBuilder.AddStatement(new AssignStatement(target, new MethodInvocationExpression(null, typeof(Type).GetMethod("GetType", types), new Expression[] { new FixedReference(this.Context.ProxyObjectReference.AssemblyQualifiedName).ToExpression(), new FixedReference(1).ToExpression(), new FixedReference(0).ToExpression() }))); method.CodeBuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(owner, typeof(SerializationInfo).GetMethod("SetType"), new Expression[] { target.ToExpression() }))); method.CodeBuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(owner, info, new Expression[] { new FixedReference("__interceptor").ToExpression(), this.InterceptorField.ToExpression() }))); method.CodeBuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(owner, info, new Expression[] { new FixedReference("__mixins").ToExpression(), this.MixinField.ToExpression() }))); LocalReference reference4 = method.CodeBuilder.DeclareLocal(typeof(string[])); method.CodeBuilder.AddStatement(new AssignStatement(reference4, new NewArrayExpression(interfaces.Length, typeof(string)))); for (int i = 0; i < interfaces.Length; i++) { method.CodeBuilder.AddStatement(new AssignArrayStatement(reference4, i, new FixedReference(interfaces[i].AssemblyQualifiedName).ToExpression())); } method.CodeBuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(owner, info, new Expression[] { new FixedReference("__interfaces").ToExpression(), reference4.ToExpression() }))); method.CodeBuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(owner, info, new Expression[] { new FixedReference("__baseType").ToExpression(), new TypeTokenExpression(this._baseType) }))); this.CustomizeGetObjectData(method.CodeBuilder, owner, reference2); method.CodeBuilder.AddStatement(new ReturnStatement()); }
public void InstancePropertyReference() { CustomPropertyEmitter propertyEmitter = ClassEmitter.CreateProperty("Property", PropertyKind.Instance, typeof(string)); propertyEmitter.CreateGetMethod(); propertyEmitter.CreateSetMethod(); propertyEmitter.ImplementWithBackingField(); var methodEmitter = GetMethodEmitter(false, typeof(string), new Type[0]); LocalReference oldValueLocal = methodEmitter.DeclareLocal(typeof(string)); PropertyReference propertyWithSelfOwner = new PropertyReference(propertyEmitter.PropertyBuilder); Assert.That(propertyWithSelfOwner.Type, Is.EqualTo(typeof(string))); methodEmitter.AddStatement(new AssignStatement(oldValueLocal, propertyWithSelfOwner.ToExpression())); methodEmitter.AddStatement(new AssignStatement(propertyWithSelfOwner, new ConstReference("New").ToExpression())); methodEmitter.AddStatement(new ReturnStatement(oldValueLocal)); object instance = GetBuiltInstance(); PrivateInvoke.SetPublicProperty(instance, "Property", "Old"); Assert.That(InvokeMethod(), Is.EqualTo("Old")); Assert.That(PrivateInvoke.GetPublicProperty(instance, "Property"), Is.EqualTo("New")); }
public LocalReference DeclareLocal(Type type) { LocalReference reference = new LocalReference(type); this._ilmarkers.Add(reference); return(reference); }
private ImportedInspectorValues ProcessPrefabModifications(IPsiSourceFile currentSourceFile, AssetDocument assetDocument) { var result = new ImportedInspectorValues(); if (assetDocument.HierarchyElement is IPrefabInstanceHierarchy prefabInstanceHierarchy) { foreach (var modification in prefabInstanceHierarchy.PrefabModifications) { if (!(modification.Target is ExternalReference externalReference)) { continue; } if (modification.PropertyPath.Contains(".")) { continue; } var location = new LocalReference(currentSourceFile.PsiStorage.PersistentIndex.NotNull("owningPsiPersistentIndex != null"), PrefabsUtil.GetImportedDocumentAnchor(prefabInstanceHierarchy.Location.LocalDocumentAnchor, externalReference.LocalDocumentAnchor)); result.Modifications[new ImportedValueReference(location, modification.PropertyPath)] = (modification.Value, new AssetReferenceValue(modification.ObjectReference)); } } return(result); }
public bool GetElementsNames(LocalReference location, [NotNull] IDeclaredElement declaredElement, [CanBeNull] out string[] names, out bool isStateMachine) { AssertShellLocks(); var element = GetDataElement(location); if (element is null) { names = null; isStateMachine = false; return(false); } var namesConsumer = new PathConsumer <string>(usage => usage.Name); var anchor = location.LocalDocumentAnchor; var namesAndAnchors = namesConsumer.Elements; AddBottomElement(element, namesConsumer, anchor, declaredElement, out isStateMachine); ProcessPath(element, namesConsumer, anchor); namesAndAnchors.Reverse(); names = namesAndAnchors.ToArray(); return(true); }
public UnityInspectorFindResult(IPsiSourceFile sourceFile, IDeclaredElement declaredElement, InspectorVariableUsage inspectorVariableUsage, LocalReference owningElemetLocation, bool isPrefabModification) : base(sourceFile, declaredElement, owningElemetLocation) { InspectorVariableUsage = inspectorVariableUsage; IsPrefabModification = isPrefabModification; }
public void ProcessSceneHierarchyFromComponentToRoot(LocalReference location, IGameObjectConsumer consumer, bool forcePrefabImportForStartPoint, bool forcePrefabImport) { myLocks.AssertReadAccessAllowed(); var owner = myAssetDocumentHierarchyElementContainer.GetAssetHierarchyFor(location, out var guid); if (owner == null) { return; } if (guid == null) { return; } var hierarchyElement = owner.GetHierarchyElement(guid.Value, location.LocalDocumentAnchor, forcePrefabImportForStartPoint ? myPrefabImportCache : null); if (hierarchyElement is IStrippedHierarchyElement && !forcePrefabImportForStartPoint) { return; } ProcessSceneHierarchyFromComponentToRoot(hierarchyElement, consumer, forcePrefabImport); }
protected virtual void WriteInterceptorInvocationMethod(MethodInfo method, EasyMethod builder) { ArgumentReference[] arguments = builder.Arguments; TypeReference[] args = IndirectReference.WrapIfByRef(builder.Arguments); LocalReference target = builder.CodeBuilder.DeclareLocal(this.Context.Invocation); EasyCallable callable = this._method2Delegate[method] as EasyCallable; FieldReference reference2 = this.ObtainCallableFieldBuilderDelegate(callable); builder.CodeBuilder.AddStatement(new AssignStatement(target, new MethodInvocationExpression(this._method2Invocation, new Expression[] { reference2.ToExpression(), new MethodTokenExpression(this.GetCorrectMethod(method)), this.GetPseudoInvocationTarget(method) }))); LocalReference reference3 = builder.CodeBuilder.DeclareLocal(typeof(object)); LocalReference reference4 = builder.CodeBuilder.DeclareLocal(typeof(object[])); builder.CodeBuilder.AddStatement(new AssignStatement(reference4, new ReferencesToObjectArrayExpression(args))); builder.CodeBuilder.AddStatement(new AssignStatement(reference3, new VirtualMethodInvocationExpression(this.InterceptorField, this.Context.Interceptor.GetMethod("Intercept"), new Expression[] { target.ToExpression(), reference4.ToExpression() }))); for (int i = 0; i < arguments.Length; i++) { if (arguments[i].Type.IsByRef) { builder.CodeBuilder.AddStatement(new AssignStatement(args[i], new ConvertExpression(args[i].Type, new LoadRefArrayElementExpression(i, reference4)))); } } if (builder.ReturnType == typeof(void)) { builder.CodeBuilder.AddStatement(new ReturnStatement()); } else { builder.CodeBuilder.AddStatement(new ReturnStatement(new ConvertExpression(builder.ReturnType, reference3.ToExpression()))); } }
public static bool InstructionsEqual(CodeInstruction left, CodeInstruction right) { //if (DebugVerbosity >= 2) // Debug.Log(string.Format("CMP {0} {1} ==? {2} {3}", left.opcode, left.operand, right.opcode, right.operand)); if (left.opcode != right.opcode) { return(false); } object lopr = left.operand; object ropr = right.operand; if (lopr == null) { return(lopr == ropr); } if (lopr is LocalBuilder) { lopr = new LocalReference((LocalBuilder)lopr); } if (ropr is LocalBuilder) { ropr = new LocalReference((LocalBuilder)ropr); } if (!lopr.Equals(ropr)) { return(false); } return(true); }
public TransformHierarchy(LocalReference location, LocalReference owner, LocalReference parent, int rootIndex) { Location = location; OwningGameObject = owner; ParentTransform = parent; myRootIndex = rootIndex; }
private void AddOverrider(MethodInfo method, Reference invocationHandler) { var overrider = _emitter.CreateMethod(method.Name, MethodAttributes.Public | MethodAttributes.Virtual, method); overrider.AddCustomAttribute(new CustomAttributeBuilder(s_attributeConstructor, new object[0])); Reference targetReference = GetTargetReference(); Expression overriddenMethodToken = new MethodTokenExpression(method); LocalReference argsLocal = CopyArgumentsToLocalVariable(overrider); Expression baseMethodInvoker = GetBaseInvokerExpression(method); TypeReference handlerReference = new TypeReferenceWrapper(invocationHandler, typeof(MethodInvocationHandler)); Expression[] handlerArgs = new Expression[] { targetReference.ToExpression(), overriddenMethodToken, argsLocal.ToExpression(), baseMethodInvoker }; Expression handlerInvocation = new VirtualMethodInvocationExpression(handlerReference, s_handlerInvokeMethod, handlerArgs); if (method.ReturnType != typeof(void)) { overrider.ImplementByReturning(new ConvertExpression(method.ReturnType, typeof(object), handlerInvocation)); } else { overrider.AddStatement(new ExpressionStatement(handlerInvocation)); overrider.AddStatement(new PopStatement()); overrider.ImplementByReturningVoid(); } }
public TransformHierarchy(LocalReference location, LocalReference gameObjectReference, LocalReference parent, int rootIndex, LocalReference prefabInstance, ExternalReference correspondingSourceObject, bool isStripped) : base("Transform", location, gameObjectReference, prefabInstance, correspondingSourceObject, isStripped) { Parent = parent; RootIndex = rootIndex; }
public ScriptComponentHierarchy(LocalReference reference, ExternalReference scriptReference, LocalReference gameObject, LocalReference prefabInstance, ExternalReference correspondingSourceObject , bool isStripped) : base("MonoBehaviour", reference, gameObject, prefabInstance, correspondingSourceObject, isStripped) { ScriptReference = scriptReference; }
public UnityEventHandlerFindResult(IPsiSourceFile sourceFile, IDeclaredElement declaredElement, AssetMethodUsages assetMethodUsages, LocalReference owningElemetLocation, bool isPrefabModification) : base(sourceFile, declaredElement, owningElemetLocation) { AssetMethodUsages = assetMethodUsages; IsPrefabModification = isPrefabModification; }
public IUnityAssetDataElement Build(SeldomInterruptChecker seldomInterruptChecker, IPsiSourceFile currentSourceFile, AssetDocument assetDocument) { if (AssetUtils.IsMonoBehaviourDocument(assetDocument.Buffer)) { var anchor = AssetUtils.GetAnchorFromBuffer(assetDocument.Buffer); if (!anchor.HasValue) { return(null); } var dictionary = new Dictionary <string, IAssetValue>(); var entries = assetDocument.Document.FindRootBlockMapEntries()?.Entries; if (entries == null) { return(null); } foreach (var entry in entries) { var key = entry.Key.GetPlainScalarText(); if (key == null || ourIgnoredMonoBehaviourEntries.Contains(key)) { continue; } foreach (var deserializer in myDeserializers) { try { if (deserializer.TryGetInspectorValue(currentSourceFile, entry.Content, out var result)) { dictionary[key] = result; break; } } catch (Exception e) { myLogger.Error(e, "An error occurred while deserializing value {0}", deserializer.GetType().Name); } } } if (dictionary.TryGetValue(UnityYamlConstants.ScriptProperty, out var scriptValue) && scriptValue is AssetReferenceValue referenceValue) { var location = new LocalReference(currentSourceFile.PsiStorage.PersistentIndex, anchor.Value); var script = referenceValue.Reference; var list = new List <InspectorVariableUsage>(); foreach (var(key, value) in dictionary) { list.Add(new InspectorVariableUsage(location, script, key, value)); } var result = new AssetInspectorValuesDataElement(list); return(result); } } return(null); }
public override void LoadReference(ILGenerator gen) { ArgumentUtility.CheckNotNull("gen", gen); LocalReference local = CreateLocal(gen); local.LoadReference(gen); }
public UnityEventData(string name, LocalReference owningScriptLocation, ExternalReference scriptReference, IEnumerable <AssetMethodUsages> calls) { Name = name; OwningScriptLocation = owningScriptLocation; ScriptReference = scriptReference; Calls = calls.ToList(); }
protected UnityAssetOccurrence(IPsiSourceFile sourceFile, IDeclaredElementPointer <IDeclaredElement> declaredElement, LocalReference owningElementLocation, bool isPrefabModification) { SourceFile = sourceFile; OwningElementLocation = owningElementLocation; PresentationOptions = OccurrencePresentationOptions.DefaultOptions; DeclaredElementPointer = declaredElement; IsPrefabModification = isPrefabModification; }
public InspectorVariableUsage(LocalReference location, IHierarchyReference scriptReference, string name, IAssetValue assetValue) { Location = location; ScriptReference = scriptReference; Name = name; Value = assetValue; }
public UnityScriptsFindResults(IPsiSourceFile sourceFile, IDeclaredElement declaredElement, IScriptUsage scriptUsage, LocalReference owningElemetLocation) : base(sourceFile, declaredElement, owningElemetLocation) { ScriptUsage = scriptUsage; }
public GameObjectHierarchy(LocalReference location, string name, LocalReference prefabInstance, ExternalReference correspondingSourceObject, bool isStripped) { Location = location; Name = name; PrefabInstance = prefabInstance; CorrespondingSourceObject = correspondingSourceObject; IsStripped = isStripped; }
public static MessageReferenceJsonModel ToModel(this LocalReference reference) => reference == null ? null : new MessageReferenceJsonModel { MessageId = reference.MessageId, ChannelId = Optional.FromNullable(reference.ChannelId), GuildId = Optional.FromNullable(reference.GuildId), FailIfNotExists = reference.FailOnInvalid };
public UnityAnimationEventFindResults([NotNull] IPsiSourceFile sourceFile, [NotNull] IDeclaredElement declaredElement, [NotNull] AnimationUsage usage, LocalReference owningElementLocation) : base(sourceFile, declaredElement, owningElementLocation) { Usage = usage; }
public AnimatorStateScriptUsage(LocalReference location, [NotNull] string name, LocalList <long> scriptsAnchors) { Location = location; Name = name; ScriptsAnchors = scriptsAnchors; }
public void DeclareLocal() { var method = ClassEmitter.CreateMethod("Statement", MethodAttributes.Public, typeof(int), new Type[0]); LocalReference local = method.DeclareLocal(typeof(int)); method.ImplementByReturning(local.ToExpression()); Assert.That(BuildInstanceAndInvokeMethod(method), Is.EqualTo(0)); }
public InspectorVariableUsage(LocalReference location, ExternalReference scriptReference, string name, IAssetValue assetValue) { Assertion.Assert(name != null, "name != null"); Location = location; ScriptReference = scriptReference; Name = string.Intern(name); Value = assetValue; }
public static LocalReference GetImportedReference(this LocalReference localReference, IPrefabInstanceHierarchy prefabInstanceHierarchy) { if (localReference.LocalDocumentAnchor == 0) { return(localReference); } return(new LocalReference(prefabInstanceHierarchy.Location.OwningPsiPersistentIndex, GetImportedDocumentAnchor(prefabInstanceHierarchy.Location.LocalDocumentAnchor, localReference.LocalDocumentAnchor))); }
public AssetMethodData(LocalReference location, string methodName, TextRange textRange, EventHandlerArgumentMode mode, string type, IHierarchyReference targetReference) { Location = location; MethodName = methodName; TextRange = textRange; Mode = mode; Type = type; TargetScriptReference = targetReference; }
internal override CodeBase LocalReference(LocalReference visitedObject) { if(_references.ContainsKey(visitedObject)) _references[visitedObject]++; else _references.Add(visitedObject, 1); visitedObject.ValueCode.Visit(this); return null; }
private ImportedUnityEventData ProcessPrefabModifications(IPsiSourceFile currentFile, AssetDocument document) { var result = new ImportedUnityEventData(); if (document.HierarchyElement is IPrefabInstanceHierarchy prefabInstanceHierarchy) { var assetMethodDataToModifiedFields = new OneToSetMap <(LocalReference, string, int), string>(); foreach (var modification in prefabInstanceHierarchy.PrefabModifications) { if (!(modification.Target is ExternalReference externalReference)) { continue; } if (!modification.PropertyPath.Contains("m_PersistentCalls")) { continue; } var location = new LocalReference(currentFile.PsiStorage.PersistentIndex, PrefabsUtil.GetImportedDocumentAnchor(prefabInstanceHierarchy.Location.LocalDocumentAnchor, externalReference.LocalDocumentAnchor)); var parts = modification.PropertyPath.Split('.'); var unityEventName = parts[0]; var dataPart = parts.FirstOrDefault(t => t.StartsWith("data")); if (dataPart == null) { continue; } if (!int.TryParse(dataPart.RemoveStart("data[").RemoveEnd("]"), out var index)) { continue; } result.UnityEventToModifiedIndex.Add((location, unityEventName), index); var last = parts.Last(); if (last.Equals("m_MethodName") && modification.Value is AssetSimpleValue assetSimpleValue) { result.AssetMethodNameInModifications.Add(assetSimpleValue.SimpleValue); } assetMethodDataToModifiedFields.Add((location, unityEventName, index), last); } foreach (var(_, set) in assetMethodDataToModifiedFields) { if (!set.Contains("m_MethodName")) { result.HasEventModificationWithoutMethodName = true; } } } return(result); }
public Reducer(LocalReference[] references, CodeBase body) { _references = references; _map = new FunctionCache<LocalReference, LocalReference>(GetReplacementsForCache); NewBody = GetNewBody(body); }
internal override CodeBase LocalReference(LocalReference visitedObject) => _references.Contains(visitedObject) ? _map[visitedObject] : null;
LocalReference GetReplacementsForCache(LocalReference reference) { var valueCode = reference.ValueCode; return (valueCode.Visit(this) ?? valueCode) .LocalReference(reference.ValueType, true); }
FinalReplacer(Size offset, LocalReference target) { _offset = offset; _target = target; }
public FinalReplacer(LocalReference target) : this(Size.Zero, target) { }
internal override CodeBase LocalReference(LocalReference visitedObject) => visitedObject != _target ? null : CodeBase .TopRef() .ReferencePlus(_offset);