/// <summary> /// Parse out declaring type fullname from given method /// </summary> /// <param name="method">Method from where type is parsed out</param> /// <returns>Declaring type fullname</returns> public static string GetDeclaringType(MethodID method) { if (method == null) { return(null); } string path, description; GetParts(method, out path, out description); return(GetDeclaringType(path)); }
/// <summary> /// Removes the specified method from container. /// </summary> /// <param name="method">The identifier of removed method.</param> public void RemoveItem(MethodID method) { MethodItem item; if (!_methodIds.TryGetValue(method, out item)) { //nothing to remove return; } _methodIds.Remove(method); _methodPaths.Remove(Naming.GetMethodPath(method).ShortSignature, item); }
/// <summary> /// Resolve dynamic (it means here virtual) method. /// </summary> /// <param name="method">Method to be resolved.</param> /// <param name="dynamicArgumentInfo">Descriptors of arguments available during method invokation.</param> /// <returns>Identifier of resolved method.</returns> internal MethodID DynamicResolve(MethodID method, InstanceInfo[] dynamicArgumentInfo) { //resolving of .NET objects depends only on called object type var calledObjectType = dynamicArgumentInfo[0] as TypeDescriptor; var methodImplementation = tryDynamicResolve(calledObjectType, method); if (methodImplementation == null) { Loader.AppDomain.Warning("Doesn't have {0} implementation for: {1}", calledObjectType, method); } return(methodImplementation); }
/// <summary> /// Set importing constructor of component. /// </summary> /// <param name="importingParameters">Parameters of import.</param> public void SetImportingCtor(params TypeDescriptor[] importingParameters) { var parameters = new ParameterTypeInfo[importingParameters.Length]; for (int i = 0; i < parameters.Length; ++i) { var importType = importingParameters[i]; parameters[i] = ParameterTypeInfo.Create("p", importType); addPreImport(importType); } _importingCtor = Naming.Method(ComponentType, Naming.CtorName, false, parameters); }
/// <summary> /// Search generic method according to given method identifier. /// </summary> /// <param name="method">The searched method identifier.</param> /// <param name="searchPath">Path where generic arguments can be found.</param> /// <returns>Generator of method if available, <c>null</c> otherwise.</returns> public GeneratorBase AccordingGenericId(MethodID method, PathInfo searchPath) { var overloads = accordingPath(searchPath); foreach (var overload in overloads) { if (overload.Info.MethodID.Equals(method)) { return(overload.Generator); } } return(null); }
/// <summary> /// Get parsed method identifier parts /// </summary> /// <param name="method">Parsed method</param> /// <param name="path">Method path part output</param> /// <param name="paramDescription">Parameter description part output</param> public static void GetParts(MethodID method, out string path, out string paramDescription) { var parts = method.MethodString.Split(new char[] { PartDelimiter }, 2); path = parts[0]; if (parts.Length > 1) { paramDescription = parts[1]; } else { paramDescription = null; } }
/// <summary> /// Get defining assembly cached for given method. If it is not cached, provider is used and its result is cached /// </summary> /// <param name="method">Identifier of method which assembly is searched</param> /// <param name="provider">Provider that will be used in case of missing cached defining assembly</param> /// <returns>Defining assembly of given method</returns> internal AssemblyProvider GetCachedDefiningAssembly(MethodID method, DefiningAssemblyProvider provider) { AssemblyProvider cached; if (!_cachedDefiners.TryGetValue(method, out cached)) { cached = provider(method); if (cached != null) { _cachedDefiners[method] = cached; } } return(cached); }
/// <summary> /// Resolve method generator with exact method ID (no generic method searches). /// </summary> /// <param name="method">Resolved method.</param> /// <param name="definingAssembly">Assembly where method is defined.</param> /// <returns>Generator for resolved method, or null, if there is no available generator.</returns> private GeneratorBase tryStaticExplicitResolve(MethodID method, out AssemblyProvider definingAssembly) { foreach (var assembly in _assemblies.Providers) { var generator = assembly.GetMethodGenerator(method); if (generator != null) { definingAssembly = assembly; return(generator); } } definingAssembly = null; return(null); }
/// <summary> /// Gets identifier of implementing method for given abstract method. /// </summary> /// <param name="methodID">The abstract method identifier.</param> /// <param name="methodSearchPath">The method search path.</param> /// <param name="implementingTypePath">The implementing type path.</param> /// <param name="alternativeImplementer">The alternative implementer which can define requested method.</param> /// <returns>Identifier of implementing method.</returns> /// <inheritdoc /> public override MethodID GetGenericImplementation(MethodID methodID, PathInfo methodSearchPath, PathInfo implementingTypePath, out PathInfo alternativeImplementer) { alternativeImplementer = null; //get method implemented on type described by dynamicInfo var implementingMethod = Naming.ChangeDeclaringType(implementingTypePath.Name, methodID, false); var item = getMethodItemFromGeneric(implementingMethod, methodSearchPath); if (item == null) { return(null); } return(item.Info.MethodID); }
/// <summary> /// Search method according to given method identifier. /// </summary> /// <param name="method">The searched method identifier.</param> /// <returns>Generator of method if available, <c>null</c> otherwise.</returns> /// <exception cref="System.NotSupportedException">Cannot get method with generic parameters</exception> public GeneratorBase AccordingId(MethodID method) { MethodItem item; if (_methodIds.TryGetValue(method, out item)) { if (item.Info.HasGenericParameters) { throw new NotSupportedException("Cannot get method with generic parameters " + method); } return(item.Generator); } //method hasn't been found return(null); }
/// <summary> /// Gets the implementation of virtual method. /// </summary> /// <param name="method">The method which implementation is searched.</param> /// <param name="methodSearchPath">Path of searched method with generic arguments.</param> /// <param name="implementingTypePath">Path of implementing type.</param> /// <returns>Implementing method identifier if found, <c>null</c> otherwise.</returns> public MethodID GetGenericImplementation(MethodID method, PathInfo methodSearchPath, PathInfo implementingTypePath) { var implementationEntry = Tuple.Create(implementingTypePath.Signature, methodSearchPath.Signature); MethodItem implementation; if (!_genericImplementations.TryGetValue(implementationEntry, out implementation)) { //implementation not found return(null); } var implementingMethod = Naming.ChangeDeclaringType(implementingTypePath.Name, method, false); var implementingMethodPath = Naming.GetMethodPath(implementingMethod); var genericImplementation = implementation.Make(implementingMethodPath); return(genericImplementation.Info.MethodID); }
/// <summary> /// Gets the test result from test defined in assembly. /// </summary> /// <param name="assembly">The assembly.</param> /// <param name="entryMethod">The entry method of test.</param> /// <param name="entryArguments">The entry method arguments.</param> /// <returns>TestResult.</returns> public static TestResult GetResult(this TestingAssembly assembly, MethodID entryMethod, params Instance[] entryArguments) { if (!assembly.IsBuilded) { assembly.Build(); } var result = assembly.Machine.Run(assembly.Loader, entryMethod, entryArguments); foreach (var action in assembly.UserActions) { action(result); } var view = processEdits(assembly.Runtime, result, assembly.EditActions); return(new TestResult(view, result)); }
/// <summary> /// Gets code base in context of given method. /// </summary> /// <param name="entryMethod">The context entry method.</param> /// <returns>Code base if available, empty <c>string</c> otherwise.</returns> private string getCodeBase(MethodID entryMethod) { var entryAssembly = _loader.AppDomain.GetDefiningAssemblyProvider(entryMethod); if (entryAssembly == null) { return(""); } var codeBase = entryAssembly.FullPathMapping; if (codeBase == null) { return(""); } return(Path.GetDirectoryName(codeBase)); }
/// <summary> /// Get assembly which defines given method. /// </summary> /// <param name="method">Method which assembly is searched.</param> /// <returns>Assembly provider where method is defined.</returns> internal AssemblyProvider GetDefiningAssemblyProvider(MethodID method) { var definingAssemblyProvider = Cache.GetCachedDefiningAssembly(method, (x) => { foreach (var assemblyProvider in _assemblies.Providers) { var generator = assemblyProvider.GetMethodGenerator(method); if (generator != null) { return(assemblyProvider); } } return(null); }); return(definingAssemblyProvider); }
public static MethodInfo getMethod(Type type, MethodID id) { TypeMembers tmember = getMembers(type); var arr = tmember.methods; if (arr != null) { for (var i = -1; i < arr.Length; i++) { MethodInfo curr; if (i == -1) { if (id.index >= 0 && arr.Length > id.index) { curr = arr[id.index]; } else { continue; } } else { curr = arr[i]; } if (curr.Name == id.name) // method name { if (matchReturnType(curr.ReturnType, id.retTypeName, id.retTypeFlag) && matchParameters(curr.GetParameters(), id.paramTypeNames, id.paramFlags)) { if (i != -1) { id.index = i; } return(curr); } } } } Debug.LogError(new StringBuilder().AppendFormat("GenericTypeCache.getMethod({0}, {1}) fail", type.Name, id.name)); return(null); }
/// <summary> /// Get generator cached for given method. If it is not cached, provider is used and its result is cached /// </summary> /// <param name="method">Identifier of required method</param> /// <param name="provider">Provider that will be used in case of missing cached method generator</param> /// <returns>Generator for specified method</returns> internal GeneratorBase GetCachedGenerator(MethodID method, GeneratorProvider provider) { GeneratorBase cached; if (!_cachedMethods.TryGetValue(method, out cached)) { //method is not cached yet - create it AssemblyProvider definingAssembly; cached = provider(method, out definingAssembly); if (cached != null) { _methodIdIndex.Add(method); _cachedMethods[method] = cached; _cachedDefiners[method] = definingAssembly; } } return(cached); }
/// <summary> /// Statics the call. /// </summary> /// <param name="sharedInstanceInfo">The shared instance information.</param> /// <param name="methodID">The method identifier.</param> /// <param name="arguments">The arguments.</param> /// <returns>CallBuilder.</returns> /// <exception cref="System.NotSupportedException">Initializers doesn't support dynamic resolving</exception> public override CallBuilder StaticCall(InstanceInfo sharedInstanceInfo, MethodID methodID, Arguments arguments) { var sharedThisVar = getSharedVar(sharedInstanceInfo); var initializerID = Context.Settings.GetSharedInitializer(sharedInstanceInfo); if (initializerID != null && initializerID.NeedsDynamicResolving) { throw new NotSupportedException("Initializers doesn't support dynamic resolving"); } var ensureInitialization = new EnsureInitialized(sharedThisVar, sharedInstanceInfo, initializerID); arguments.Initialize(sharedThisVar); emitInstruction(ensureInitialization); return(emitCall(methodID, arguments)); }
/// <summary> /// When overridden it can inject any generator for any method. Injected generator /// wont be binded with <see cref="MethodID" /> in methods cache. /// </summary> /// <param name="name">Name of resolved method.</param> /// <param name="argumentValues">Arguments of resolved method.</param> /// <returns><c>null</c> if there is no injected generator, injected generator otherwise.</returns> public override GeneratorBase GetOverridingGenerator(MethodID name, Instance[] argumentValues) { if (argumentValues.Length == 0) { return(null); } var thisArgument = argumentValues[0]; GeneratorBase generator; _overridingGenerators.TryGetValue(thisArgument, out generator); if (thisArgument.Info.TypeName == Runtime.Null.TypeInfo.TypeName) { return(_nullCallHandler); } return(generator); }
/// <summary> /// Calls the with return. /// </summary> /// <param name="calledInstance">The called instance.</param> /// <param name="methodID">The method identifier.</param> /// <param name="arguments">The arguments.</param> /// <returns>InstanceRef.</returns> internal InstanceRef CallWithReturn(InstanceRef calledInstance, MethodID methodID, InstanceRef[] arguments) { checkNull(methodID); var inst = getStorage(calledInstance); var args = getArgumentStorages(arguments); var resultStorage = getFreeStorage("ret"); //TODO determine result type var resultInstance = new InstanceRef(this, null, true); _instanceStorages.Add(resultInstance, resultStorage); emit((e) => { e.Call(methodID, inst, args); e.AssignReturnValue(resultStorage, resultInstance.Type); }); return(resultInstance); }
/// <summary> /// Handler called for methods that has been invalidated. /// </summary> /// <param name="invalidatedMethod">Identifier of invalidated method.</param> private void methodInvalidated(MethodID invalidatedMethod) { _vs.Log.Message("Method invalidation {0}", invalidatedMethod); if (!_guiManager.AutoRefresh) { return; } if (_currentResult == null) { return; } if (!_currentResult.Uses(invalidatedMethod)) { return; } requireRedraw(); }
/// <summary> /// Handler called whenever composition point is selected /// </summary> private void onCompositionPointSelected() { var compositionPoint = _guiManager.SelectedCompositionPoint; if (compositionPoint == null) { setDefaultCompositionPoint(); } else { _entryMethod = _guiManager.SelectedCompositionPoint.EntryMethod; _entryArgumentsProvider = (m) => { var thisObj = m.CreateInstance(compositionPoint.DeclaringComponent); return(new[] { thisObj }); }; } refreshDrawing(); }
/// <summary> /// Get count of parameters of method from specified ID /// </summary> /// <param name="method">Method which parameter count is required</param> /// <returns>Number of parameters of given method</returns> public static int GetMethodParamCount(MethodID method) { var parts = method.MethodString; var count = 0; for (var i = parts.Length - 1; i >= 0; --i) { var ch = parts[i]; if (ch == Naming.PartDelimiter) { break; } if (ch == Naming.ParamDelimiter) { count++; } } return(count); }
/// <summary> /// Creates the none composition point item. /// </summary> /// <returns>Created item.</returns> private ComboBoxItem createNoCompositionPointItem() { var itemContent = new TextBlock(); itemContent.Text = "None"; var item = new ComboBoxItem(); item.Content = itemContent; item.Selected += (e, s) => { onCompositionPointSelected(null); }; item.PreviewMouseDown += (e, s) => { _desiredCompositionPointMethod = null; }; return(item); }
/// <summary> /// Get generator for given name and arguments. /// </summary> /// <param name="method">Name of method generator.</param> /// <param name="arguments">Arguments of call.</param> /// <returns>Instruction generator for given name.</returns> private GeneratorBase getGenerator(ref MethodID method, InstanceInfo[] arguments) { if (method.NeedsDynamicResolving) { method = _loader.DynamicResolve(method, arguments); } if (method == null) { return(null); } GeneratorBase resolved; if (!_methods.TryGetValue(method, out resolved)) { //register resolved method resolved = _loader.StaticResolve(method); _methods[method] = resolved; } return(resolved); }
/// <summary> /// Check if the scope is doable /// </summary> /// <param name="proposedScope"></param> /// <returns></returns> public string ScopeCheck(string proposedScope) { if (proposedScope == SMFlowContainer.NOSCOPE || string.IsNullOrEmpty(MethodID)) { return(proposedScope); } string methodPath = string.Empty; if (MethodID.Contains('.')) { U.SplitMethodID(MethodID, out methodPath); int lastPeriod = methodPath.LastIndexOf('.'); if (lastPeriod > 0) { methodPath = methodPath.Substring(0, lastPeriod); } else { methodPath = string.Empty; } } return(SMFlowContainer.DetermineScope(proposedScope, methodPath)); }
/// <summary> /// Resolve method generator with generic search on given method ID. /// </summary> /// <param name="method">Resolved method.</param> /// <param name="definingAssembly">Assembly where method is defined.</param> /// <returns>Generator for resolved method, or null, if there is no available generator.</returns> private GeneratorBase tryStaticGenericResolve(MethodID method, out AssemblyProvider definingAssembly) { definingAssembly = null; var searchPath = Naming.GetMethodPath(method); if (!searchPath.HasGenericArguments) { //there is no need for generic resolving return(null); } foreach (var assembly in _assemblies.Providers) { var generator = assembly.GetGenericMethodGenerator(method, searchPath); if (generator != null) { definingAssembly = assembly; return(generator); } } return(null); }
/// <summary> /// Gets identifier of implementing method for given abstract method. /// </summary> /// <param name="method">The abstract method identifier.</param> /// <param name="dynamicInfo">The dynamic information.</param> /// <param name="alternativeImplementer">The alternative implementer which can define requested method.</param> /// <returns>Identifier of implementing method.</returns> public override MethodID GetImplementation(MethodID method, TypeDescriptor dynamicInfo, out TypeDescriptor alternativeImplementer) { //we may have explicit definition alternativeImplementer = null; var explicitImplementation = _runtimeMethods.GetImplementation(method, dynamicInfo); if (explicitImplementation != null) { return(explicitImplementation); } //or there is implicit .NET definition var signature = PathInfo.GetSignature(dynamicInfo); var isNativeObject = _directSignatures.Contains(signature); if (!isNativeObject) { //implicit definition is there only for native objects return(null); } //we can use native implementation return(method); //note that using dynamic flag is a hack }
public static string GetMethodName(MethodID id) { return methodNames[(int)id]; }
/// <summary> /// Set environment to run default composition point /// </summary> private void setDefaultCompositionPoint() { _entryMethod = Method.EntryInfo.MethodID; _entryArgumentsProvider = getDefaultArguments; }
public static MethodInfo getMethod(Type type, MethodID id) { TypeMembers tmember = getMembers(type); var arr = tmember.methods; if (arr != null) { for (var i = -1; i < arr.Length; i++) { MethodInfo curr; if (i == -1) { if (id.index >= 0 && arr.Length > id.index) curr = arr[id.index]; else continue; } else { curr = arr[i]; } if (curr.Name == id.name) // method name { if (matchReturnType(curr.ReturnType, id.retTypeName, id.retTypeFlag) && matchParameters(curr.GetParameters(), id.paramTypeNames, id.paramFlags)) { if (i != -1) id.index = i; return curr; } } } } Debug.LogError(new StringBuilder().AppendFormat("GenericTypeCache.getMethod({0}, {1}) fail", type.Name, id.name)); return null; }
/// <summary> /// Gets the method generator for given method identifier. /// For performance purposes no generic search has to be done. /// </summary> /// <param name="method">The method identifier.</param> /// <returns>GeneratorBase.</returns> public override GeneratorBase GetMethodGenerator(MethodID method) { requireBuilded(); return(_methods.AccordingId(method)); }
/// <summary> /// Gets the generic method generator for given method identifier. /// Generic has to be resolved according to given search path. /// </summary> /// <param name="method">The method.</param> /// <param name="searchPath">The search path.</param> /// <returns>GeneratorBase.</returns> public override GeneratorBase GetGenericMethodGenerator(MethodID method, PathInfo searchPath) { requireBuilded(); return(_methods.AccordingGenericId(method, searchPath)); }