Example #1
0
        protected int GetVirtualMethodOverloadIndex(IMethodSymbol method)
        {
            if (!IsVirtualMethod(method))
            {
                throw new Exception("Method must be virtual: " + method.FullName());
            }
            if (method.OverriddenMethod != null)
            {
                return(GetVirtualMethodOverloadIndex(method.OverriddenMethod));
            }
            else
            {
                bool found = false;
                int  index = 0;
                foreach (var member in method.ContainingType.GetMembers())
                {
                    var memberMethod = member as IMethodSymbol;
                    if (memberMethod == null)
                    {
                        continue;
                    }
                    if (method.IsEqual(memberMethod) || (method.IsGenericMethod && method.ConstructedFrom.IsEqual(memberMethod)))
                    {
                        found = true;
                        break;
                    }
                    if (method.Name == memberMethod.Name)
                    {
                        ++index;
                    }
                }

                if (!found)
                {
                    throw new Exception("Failed to find virtual method index (this should never happen)");
                }
                return(index);
            }
        }
Example #2
0
        protected bool GetNativeExternName(IMethodSymbol method, NativeTarget target, out string name)
        {
            var attribute = GetNativeExternAttribute(method, target);

            if (attribute != null)
            {
                var constant = attribute.ConstructorArguments[1];
                if (constant.Value == null)
                {
                    name = method.Name;
                }
                else
                {
                    name = constant.Value.ToString();
                }
                return(true);
            }
            else if (!IsInternalCall(method))
            {
                throw new NotSupportedException("Unsupported extern method invoke: " + method.FullName());
            }

            name = null;
            return(false);
        }
Example #3
0
        private string GetVTableMethodFullName(IMethodSymbol method)
        {
            if (!IsVirtualMethod(method))
            {
                throw new NotSupportedException("Non virtual method has no vtable method name: " + method.FullName());
            }
            CheckIfSpecialMethod(method);
            int    vTableIndex = GetVirtualMethodOverloadIndex(method);
            string methodName;

            if (method.IsGenericMethod)
            {
                methodName = method.Name();
            }
            else
            {
                methodName = method.Name;
            }
            ParseImplementationDetail(ref methodName);
            return($"vTable_{methodName}_{vTableIndex}");
        }