示例#1
0
        /// <summary>
        /// Builds the method signature parameters.
        /// </summary>
        /// <param name="self">The self.</param>
        /// <param name="builder">The builder.</param>
        private static void BuildMethodSignatureParameters(NMethod self, StringBuilder builder)
        {
            // BuildMethodSignatureGenericParameters(self, builder);

            builder.Append("(");
            var parameters = self.Parameters;

            for (int i = 0; i < parameters.Count; i++)
            {
                var parameter = parameters[i];
                if (i > 0)
                {
                    builder.Append(", ");
                }
                if (parameter.ParameterType.IsSentinel)
                {
                    builder.Append("..., ");
                }
                builder.Append(parameter.ParameterTypeName);
                if (parameter.ParameterType.IsPointer)
                {
                    builder.Append("*");
                }
            }
            builder.Append(")");
        }
示例#2
0
        /// <summary>
        /// Adds the parameter.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="parameterDef">The parameter def.</param>
        private void AddParameter(NMethod method, ParameterDefinition parameterDef)
        {
            var parameter = new NParameter {
                Name = parameterDef.Name
            };

            parameter.FullName      = parameter.Name;
            parameter.IsIn          = parameterDef.IsIn;
            parameter.IsOut         = parameterDef.IsOut;
            parameter.IsOptional    = parameterDef.IsOptional;
            parameter.IsReturnValue = parameterDef.IsReturnValue;
            parameter.ParameterType = GetTypeReference(parameterDef.ParameterType);
            method.AddParameter(parameter);
        }
示例#3
0
 /// <summary>
 /// Builds the method signature parameters.
 /// </summary>
 /// <param name="self">The self.</param>
 /// <param name="builder">The builder.</param>
 private static void BuildMethodSignatureGenericParameters(NMethod self, StringBuilder builder)
 {
     if (self.GenericParameters.Count > 0)
     {
         builder.Append("<");
         for (int i = 0; i < self.GenericParameters.Count; i++)
         {
             var genericParameter = self.GenericParameters[i];
             if (i > 0)
             {
                 builder.Append(", ");
             }
             builder.Append(genericParameter.Name);
         }
         builder.Append(">");
     }
 }
示例#4
0
文件: FPod.cs 项目: syatanic/fantom
        /// <summary>
        /// Map a fcode method signature to a .NET method emit signature.
        /// </summary>
        public NMethod ncall(int index, int opcode)
        {
            if (m_ncalls == null)
            {
                m_ncalls = new NMethod[m_methodRefs.size()];
            }
            NMethod x = m_ncalls[index];

            if (x == null || opcode == FConst.CallNonVirtual) // don't use cache on nonvirt (see below)
            {
                int[]  m     = methodRef(index).val;
                string type  = nname(m[0]);
                string mName = name(m[1]);

                // if the type signature is java/lang then we route
                // to static methods on FanObj, FanFloat, etc
                string impl         = FanUtil.toDotnetImplTypeName(type);
                bool   explicitSelf = false;
                bool   isStatic     = false;
                if (type != impl)
                {
                    explicitSelf = opcode == FConst.CallVirtual;
                    isStatic     = explicitSelf;
                }
                else
                {
                    // if no object method than ok to use cache
                    if (x != null)
                    {
                        return(x);
                    }
                }

                // equals => Equals
                if (!explicitSelf)
                {
                    mName = FanUtil.toDotnetMethodName(mName);
                }

                string[] pars;
                if (explicitSelf)
                {
                    pars    = new string[m.Length - 2];
                    pars[0] = type;
                    for (int i = 1; i < pars.Length; i++)
                    {
                        pars[i] = nname(m[i + 2]);
                    }
                }
                else
                {
                    pars = new string[m.Length - 3];
                    for (int i = 0; i < pars.Length; i++)
                    {
                        pars[i] = nname(m[i + 3]);
                    }
                }

                string ret = nname(m[2]);
                if (opcode == FConst.CallNew)
                {
                    ret = type;                   // factory
                }
                // Handle static mixin calls
                if (opcode == FConst.CallMixinStatic)
                {
                    impl += "_";
                }

                x            = new NMethod();
                x.parentType = impl;
                x.methodName = mName;
                x.returnType = ret;
                x.paramTypes = pars;
                x.isStatic   = isStatic;

                // we don't cache nonvirtuals on Obj b/c of conflicting signatures:
                // - CallVirtual: Obj.toStr => static FanObj.toStr(Object)
                // - CallNonVirtual: Obj.toStr => FanObj.toStr()
                if (type == impl || opcode != FConst.CallNonVirtual)
                {
                    m_ncalls[index] = x;
                }
            }
            return(x);
        }
示例#5
0
文件: FPod.cs 项目: nomit007/f4
        /// <summary>
        /// Map a fcode method signature to a .NET method emit signature.
        /// </summary>
        public NMethod ncall(int index, int opcode)
        {
            if (m_ncalls == null) m_ncalls = new NMethod[m_methodRefs.size()];
              NMethod x = m_ncalls[index];
              if (x == null || opcode == FConst.CallNonVirtual) // don't use cache on nonvirt (see below)
              {
            int[] m = methodRef(index).val;
            string type  = nname(m[0]);
            string mName = name(m[1]);

            // if the type signature is java/lang then we route
            // to static methods on FanObj, FanFloat, etc
            string impl = FanUtil.toDotnetImplTypeName(type);
            bool explicitSelf = false;
            bool isStatic = false;
            if (type != impl)
            {
              explicitSelf = opcode == FConst.CallVirtual;
              isStatic = explicitSelf;
            }
            else
            {
              // if no object method than ok to use cache
              if (x != null) return x;
            }

            // equals => Equals
            if (!explicitSelf)
              mName = FanUtil.toDotnetMethodName(mName);

            string[] pars;
            if (explicitSelf)
            {
              pars = new string[m.Length-2];
              pars[0] = type;
              for (int i=1; i<pars.Length; i++) pars[i] = nname(m[i+2]);
            }
            else
            {
              pars = new string[m.Length-3];
              for (int i=0; i<pars.Length; i++) pars[i] = nname(m[i+3]);
            }

            string ret = nname(m[2]);
            if (opcode == FConst.CallNew) ret = type; // factory

            // Handle static mixin calls
            if (opcode == FConst.CallMixinStatic) impl += "_";

            x = new NMethod();
            x.parentType = impl;
            x.methodName = mName;
            x.returnType = ret;
            x.paramTypes = pars;
            x.isStatic   = isStatic;

            // we don't cache nonvirtuals on Obj b/c of conflicting signatures:
            // - CallVirtual: Obj.toStr => static FanObj.toStr(Object)
            // - CallNonVirtual: Obj.toStr => FanObj.toStr()
            if (type == impl || opcode != FConst.CallNonVirtual)
              m_ncalls[index] = x;
              }
              return x;
        }