/// <summary> /// Declares a method. /// </summary> /// <param name="methodBase">The method to declare.</param> /// <param name="created">True, if the method has been created.</param> /// <returns>The declared method.</returns> public Method Declare(MethodBase methodBase, out bool created) { Debug.Assert(methodBase != null, "Invalid method base"); // Synchronize all accesses below using a read scope using var readScope = irLock.EnterUpgradeableReadScope(); // Check for existing method if (methods.TryGetHandle(methodBase, out MethodHandle handle)) { created = false; return(methods[handle]); } var externalAttribute = methodBase.GetCustomAttribute <ExternalAttribute>(); var methodName = externalAttribute?.Name ?? methodBase.Name; handle = MethodHandle.Create(methodName); var declaration = new MethodDeclaration( handle, CreateType(methodBase.GetReturnType()), methodBase); // Declare a new method sync using a write scope using var writeScope = readScope.EnterWriteScope(); return(Declare_Sync(declaration, out created)); }
/// <summary> /// Declares a method. /// </summary> /// <param name="methodBase">The method to declare.</param> /// <param name="created">True, if the method has been created.</param> /// <returns>The declared method.</returns> public Method Declare(MethodBase methodBase, out bool created) { Debug.Assert(methodBase != null, "Invalid method base"); // Check for existing method irLock.EnterUpgradeableReadLock(); try { if (methods.TryGetHandle(methodBase, out MethodHandle handle)) { created = false; return(methods[handle]); } var externalAttribute = methodBase.GetCustomAttribute < ExternalAttribute>(); var methodName = externalAttribute?.Name ?? methodBase.Name; handle = MethodHandle.Create(methodName); var declaration = new MethodDeclaration( handle, CreateType(methodBase.GetReturnType()), methodBase); return(Declare(declaration, out created)); } finally { irLock.ExitUpgradeableReadLock(); } }
/// <summary> /// Constructs a new method declaration with an implicit handle. /// </summary> /// <param name="name">The method name.</param> /// <param name="returnType">The return type.</param> /// <param name="flags">Custom method flags.</param> public MethodDeclaration( string name, TypeNode returnType, MethodFlags flags) : this(MethodHandle.Create(name), returnType, flags) { }