Example #1
0
        private static PreparedFunction PreparePInvokeMethod(
            IPrepareContext prepareContext,
            string methodName,
            string rawMethodName,
            TypeReference returnType,
            Parameter[] parameters,
            PInvokeInfo pinvokeInfo)
        {
            // TODO: Switch DllImport.Value include direction to library direction.
            if (string.IsNullOrWhiteSpace(pinvokeInfo.Module.Name))
            {
                throw new InvalidProgramSequenceException(
                          "Not given DllImport attribute argument. Name={0}",
                          methodName);
            }

            prepareContext.RegisterPrivateIncludeFile(pinvokeInfo.Module.Name);

            return(new PreparedFunction(
                       methodName,
                       rawMethodName,
                       returnType,
                       parameters,
                       false,
                       null));
        }
Example #2
0
        private static PreparedMethodInformation PrepareMethod(
            IPrepareContext prepareContext,
            IMethodInformation method)
        {
            var returnType = method.ReturnType;
            var parameters = method.Parameters;

            prepareContext.RegisterType(returnType);
            foreach (var parameter in parameters)
            {
                prepareContext.RegisterType(parameter.TargetType);
            }

            // Pure abstract method (ignored.)
            if (method.IsVirtual && method.IsAbstract)
            {
                Debug.Assert(!method.HasBody);
                return(null);
            }

            // Delegate constructor (ignored, it will be handled by the AssemblyWriter.)
            if (method.IsConstructor && method.DeclaringType.IsDelegate &&
                (method.Parameters.Length == 3) &&
                method.Parameters[1].TargetType.IsObjectType &&
                method.Parameters[2].TargetType.IsIntPtrType)
            {
                // Debug.Assert(!method.HasBody);  // Depended for the compiler (it has no body for Roslyn)
                return(null);
            }

            // internalcall or DllImport
            if (method.IsExtern)
            {
                Debug.Assert(!method.HasBody);

                var pinvokeInfo = method.PInvokeInfo;
                if (pinvokeInfo != null)
                {
                    // TODO: Switch DllImport.Value include direction to library direction.
                    if (string.IsNullOrWhiteSpace(pinvokeInfo.Module.Name))
                    {
                        throw new InvalidProgramSequenceException(
                                  "Not given DllImport attribute argument. Name={0}",
                                  method.FriendlyName);
                    }

                    prepareContext.RegisterPrivateIncludeFile(pinvokeInfo.Module.Name);
                }

                // Construct dummy information.
                return(new PreparedMethodInformation(
                           method,
                           null,
                           null,
                           null,
                           null,
                           null));
            }

            Debug.Assert(method.HasBody);

            return(PrepareMethodBody(
                       prepareContext,
                       method));
        }