Ejemplo n.º 1
0
        /// <summary>
        /// Generates the code for declarations (fields, methods, property) with CLR protection level <c>protected</c>.
        /// </summary>
        protected virtual void GenerateCodeProtectedDeclarations()
        {
            if (AllowSubclassing)
            {
                foreach (MemberFieldDefinition field in _classDefinition.ProtectedFields)
                {
                    if (!field.IsIgnored)
                    {
                        //if (CheckTypeMemberForGetProperty(field) == false)
                        //    AddMethodsForField(field);
                        //else
                        GenerateCodePropertyField(field);

                        _codeBuilder.AppendEmptyLine();
                    }
                }

                foreach (MemberMethodDefinition f in _classDefinition.ProtectedMethods)
                {
                    if (f.IsDeclarableFunction && (AllowProtectedMembers || f.IsStatic || !f.IsVirtual))
                    {
                        GenerateCodeMethod(f);
                        _codeBuilder.Append("\n");
                    }
                }
            }
        }
        public static void AddMethodHandlersClass(ClassDefinition type, SourceCodeStringBuilder sb)
        {
            if (!type.HasWrapType(WrapTypes.NativeDirector))
            {
                throw new Exception("Unexpected");
            }

            if (type.IsNested)
            {
                sb.AppendIndent("public: ");
            }
            else
            {
                sb.AppendIndent("public ");
            }

            sb.Append("ref class " + type.Name + " abstract sealed\n");
            sb.AppendLine("{");
            sb.AppendLine("public:");
            sb.IncreaseIndent();

            foreach (MemberMethodDefinition f in type.PublicMethods)
            {
                if (f.IsDeclarableFunction && f.IsVirtual)
                {
                    //if (f.Parameters.Count > 0)
                    //{
                    //    AddEventArgsClass(f, sb);
                    //}

                    sb.AppendIndent("delegate static " + f.MemberTypeCLRName + " " + f.CLRName + "Handler(");
                    for (int i = 0; i < f.Parameters.Count; i++)
                    {
                        ParamDefinition param = f.Parameters[i];
                        sb.Append(" " + param.Type.GetCLRParamTypeName(param) + " " + param.Name);
                        if (i < f.Parameters.Count - 1)
                        {
                            sb.Append(",");
                        }
                    }
                    sb.Append(" );\n");
                }
            }

            sb.DecreaseIndent();
            sb.AppendLine("};");
            sb.AppendEmptyLine();
        }
Ejemplo n.º 3
0
        public static void AddNativeProxyMethodBody(MemberMethodDefinition f, string managedTarget, SourceCodeStringBuilder sb)
        {
            string managedCall;
            string fullPostConv = null;

            if (f.IsPropertyGetAccessor)
            {
                sb.AppendLine(f.MemberTypeCLRName + " mp_return = " + managedTarget + "->" + MemberPropertyDefinition.GetPropertyName(f) + ";");
                managedCall = "mp_return";
            }
            else if (f.IsPropertySetAccessor)
            {
                ParamDefinition param = f.Parameters[0];
                managedCall = managedTarget + "->" + MemberPropertyDefinition.GetPropertyName(f) + " = " + param.Type.ProduceNativeCallConversionCode(param.Name, param);
            }
            else
            {
                string pre, post, conv;

                foreach (ParamDefinition param in f.Parameters)
                {
                    param.Type.ProduceNativeParamConversionCode(param, out pre, out conv, out post);
                    if (!String.IsNullOrEmpty(pre))
                    {
                        sb.AppendLine(pre);
                    }

                    if (!String.IsNullOrEmpty(post))
                    {
                        fullPostConv += post + "\n";
                    }
                }

                bool explicitCast = f.HasAttribute <ExplicitCastingForParamsAttribute>();

                if (!f.HasReturnValue)
                {
                    sb.AppendIndent(f.MemberTypeCLRName + " mp_return = " + managedTarget + "->" + f.CLRName + "(");
                    for (int i = 0; i < f.Parameters.Count; i++)
                    {
                        ParamDefinition param = f.Parameters[i];
                        param.Type.ProduceNativeParamConversionCode(param, out pre, out conv, out post);
                        sb.Append(" ");
                        if (explicitCast)
                        {
                            sb.Append("(" + param.MemberTypeCLRName + ")");
                        }
                        sb.Append(conv);
                        if (i < f.Parameters.Count - 1)
                        {
                            sb.Append(",");
                        }
                    }
                    sb.Append(" );\n");
                    managedCall = "mp_return";

                    if (!String.IsNullOrEmpty(fullPostConv))
                    {
                        sb.AppendLine(fullPostConv);
                    }
                }
                else
                {
                    managedCall = managedTarget + "->" + f.CLRName + "(";
                    for (int i = 0; i < f.Parameters.Count; i++)
                    {
                        ParamDefinition param = f.Parameters[i];
                        param.Type.ProduceNativeParamConversionCode(param, out pre, out conv, out post);
                        managedCall += " ";
                        if (explicitCast)
                        {
                            managedCall += "(" + param.MemberTypeCLRName + ")";
                        }
                        managedCall += conv;
                        if (i < f.Parameters.Count - 1)
                        {
                            managedCall += ",";
                        }
                    }
                    managedCall += " )";
                }
            }

            if (!f.HasReturnValue)
            {
                if (f.MemberType is IDefString)
                {
                    sb.AppendLine("SET_NATIVE_STRING( Mogre::Implementation::cachedReturnString, " + managedCall + " )");
                    sb.AppendLine("return Mogre::Implementation::cachedReturnString;");
                }
                else
                {
                    string          returnExpr;
                    string          newname, expr, postcall;
                    ParamDefinition param = new ParamDefinition(f.MetaDef, f, managedCall);
                    expr     = f.MemberType.ProducePreCallParamConversionCode(param, out newname);
                    postcall = f.MemberType.ProducePostCallParamConversionCleanupCode(param);
                    if (!String.IsNullOrEmpty(expr))
                    {
                        sb.AppendLine(expr);
                        if (String.IsNullOrEmpty(postcall))
                        {
                            returnExpr = newname;
                        }
                        else
                        {
                            throw new Exception("Unexpected");
                        }
                    }
                    else
                    {
                        returnExpr = newname;
                    }

                    if (IsCachedFunction(f))
                    {
                        sb.AppendLine("STATIC_ASSERT( sizeof(" + f.MemberType.FullyQualifiedNativeName + ") <= CACHED_RETURN_SIZE )");
                        sb.AppendLine("memcpy( Mogre::Implementation::cachedReturn, &" + returnExpr + ", sizeof(" + f.MemberType.FullyQualifiedNativeName + ") );");
                        sb.AppendLine("return *reinterpret_cast<" + f.MemberType.FullyQualifiedNativeName + "*>(Mogre::Implementation::cachedReturn);");
                    }
                    else
                    {
                        sb.AppendLine("return " + returnExpr + ";");
                    }
                }
            }
            else
            {
                sb.AppendLine(managedCall + ";");

                if (!String.IsNullOrEmpty(fullPostConv))
                {
                    sb.AppendLine(fullPostConv);
                }
            }
        }