Пример #1
0
        /// <summary>
        /// Generates the classes' code and inserts it before all other code already generated.
        /// </summary>
        /// <seealso cref="GenerateCode"/>
        public virtual void GenerateCodeAtBeginning()
        {
            SourceCodeStringBuilder orig = _codeBuilder;

            _codeBuilder = new SourceCodeStringBuilder(MetaDef.CodeStyleDef);

            GenerateCode();

            orig.InsertAt(0, _codeBuilder.ToString());
            _codeBuilder = orig;
        }
        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();
        }
 public override void GenerateCode()
 {
     if (_classDefinition.IsInterface)
     {
         SourceCodeStringBuilder tempsb = _codeBuilder;
         _codeBuilder = new SourceCodeStringBuilder(this.MetaDef.CodeStyleDef);
         base.GenerateCode();
         string fname = _classDefinition.FullyQualifiedCLRName.Replace(_classDefinition.CLRName, _classDefinition.Name);
         string res   = _codeBuilder.ToString().Replace(_classDefinition.FullyQualifiedCLRName + "::", fname + "::");
         _codeBuilder = tempsb;
         _codeBuilder.AppendLine(res);
     }
     else
     {
         base.GenerateCode();
     }
 }
Пример #4
0
        public ClassCodeProducer(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb) : base(metaDef)
        {
            this._wrapper    = wrapper;
            _classDefinition = t;
            _codeBuilder     = sb;

            foreach (ClassDefinition iface in _classDefinition.GetInterfaces())
            {
                AddTypeDependancy(iface);
                _interfaces.Add(iface);
            }

            if (_classDefinition.IsInterface)
            {
                // Declaring an overridable class for interface
                _interfaces.Add(_classDefinition);
            }
        }
 public NativeDirectorClassCppProducer(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb)
     : base(metaDef, wrapper, t, sb)
 {
 }
 public OverridableClassCppProducer(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb)
     : base(metaDef, wrapper, t, sb)
 {
     _wrapper.AddPostClassProducer(new NativeProxyClassCppProducer(metaDef, _wrapper, _classDefinition, _codeBuilder));
 }
 public CppSubclassingClassProducer(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb, ClassDefinition[] additionalInterfaces)
     : base(metaDef, wrapper, t, sb)
 {
     this._additionalInterfaces = additionalInterfaces;
 }
Пример #8
0
 public ClassCppProducer(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb)
     : base(metaDef, wrapper, t, sb)
 {
     //if (AllowSubclassing)
     //{
     //    _wrapper.PreClassProducers.Add(new CppNativeProtectedTypesProxy(_wrapper, _t, _sb));
     //}
 }
 public NativePtrValueClassInclProducer(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb)
     : base(metaDef, wrapper, t, sb)
 {
 }
Пример #10
0
        public ClassInclProducer(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb)
            : base(metaDef, wrapper, t, sb)
        {
            AddPreDeclarations();

            if (_classDefinition.BaseClass != null)
            {
                AddTypeDependancy(_classDefinition.BaseClass);
            }

            if (AllowSubclassing)
            {
                _wrapper.AddPreClassProducer(new NativeProtectedTypesProxy(metaDef, _wrapper, _classDefinition, _codeBuilder));
                _wrapper.AddPostClassProducer(new NativeProtectedStaticsProxy(metaDef, _wrapper, _classDefinition, _codeBuilder));
                //_wrapper.PreClassProducers.Add(new IncNativeProtectedTypesProxy(_wrapper, _t, _code));
            }
        }
Пример #11
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);
                }
            }
        }
 public NonOverridableClassInclProducer(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb)
     : base(metaDef, wrapper, t, sb)
 {
 }
 public CLRHandleClassCppProducer(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb)
     : base(metaDef, wrapper, t, sb)
 {
 }
Пример #14
0
 public SingletonClassInclProducer(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb)
     : base(metaDef, wrapper, t, sb)
 {
 }
        //protected List<DefFunction> _protectedFunctions = new List<DefFunction>();

        public NativeProxyClassProducer(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb)
            : base(metaDef, wrapper, t, sb)
        {
            //SearchProtectedFunctions(_t);
        }
 public ReadOnlyStructClassInclProducer(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb)
     : base(metaDef, wrapper, t, sb)
 {
 }
 public NativeProtectedTypesProxy(MetaDefinition metaDef, Wrapper wrapper, ClassDefinition t, SourceCodeStringBuilder sb)
     : base(metaDef, wrapper, t, sb)
 {
 }