예제 #1
0
        protected override void AddMethod(DefFunction f)
        {
            string def = f.Definition.Replace(f.Class.FullNativeName, GetClassName()) + "(";

            if (def.StartsWith("virtual "))
            {
                def = def.Substring("virtual ".Length);
            }
            _sb.AppendIndent(def);
            for (int i = 0; i < f.Parameters.Count; i++)
            {
                DefParam param = f.Parameters[i];
                _sb.Append(" ");
                AddNativeMethodParam(param);
                if (i < f.Parameters.Count - 1)
                {
                    _sb.Append(",");
                }
            }
            _sb.Append(" )\n");
            _sb.AppendLine("{");
            _sb.IncreaseIndent();

            _sb.AppendLine("if (doCallFor" + f.CLRName + ")");
            _sb.AppendLine("{");
            _sb.IncreaseIndent();

            CppNativeProxyClassProducer.AddNativeProxyMethodBody(f, "_receiver", _sb);

            _sb.DecreaseIndent();
            _sb.AppendLine("}");
            if (!f.IsVoid)
            {
                _sb.AppendLine("else");
                string ret = null;
                if (f.HasAttribute <DefaultReturnValueAttribute>())
                {
                    ret = f.GetAttribute <DefaultReturnValueAttribute>().Name;
                }
                else
                {
                    throw new Exception("Default return value not set.");
                }
                _sb.AppendLine("\treturn " + ret + ";");
            }

            _sb.DecreaseIndent();
            _sb.AppendLine("}");
        }
예제 #2
0
        protected virtual bool?CheckFunctionForGetProperty(DefFunction f)
        {
            string name = f.HasAttribute <RenameAttribute>() ? f.GetAttribute <RenameAttribute>().Name : f.Name;

            if (f.HasAttribute <CustomIncDeclarationAttribute>() || f.HasAttribute <CustomCppDeclarationAttribute>())
            {
                return(false);
            }

            if (f.TypeName == "bool" &&
                ((name.StartsWith("is") && Char.IsUpper(name[2])) || (name.StartsWith("has") && Char.IsUpper(name[3]))) &&
                f.Parameters.Count == 0)
            {
                return(true);
            }

            return(CheckTypeMemberForGetProperty(f));
        }
예제 #3
0
        public override T GetAttribute <T>()
        {
            T res = base.GetAttribute <T>();

            if (res != null)
            {
                return(res);
            }

            if (BaseFunction != null)
            {
                return(BaseFunction.GetAttribute <T>());
            }
            else
            {
                return(default(T));
            }
        }
예제 #4
0
        protected override void AddMethod(DefFunction f)
        {
            if (f.HasAttribute <CustomIncDeclarationAttribute>())
            {
                string txt = f.GetAttribute <CustomIncDeclarationAttribute>().DeclarationText;
                txt = ReplaceCustomVariables(txt, f);
                _sb.AppendLine(txt);
                _sb.AppendLine();
                return;
            }

            int defcount = 0;

            if (!f.HasAttribute <NoDefaultParamOverloadsAttribute>())
            {
                foreach (DefParam param in f.Parameters)
                {
                    if (param.DefaultValue != null)
                    {
                        defcount++;
                    }
                }
            }

            bool methodIsVirtual = DeclareAsVirtual(f);

            // The main method
            AddComments(f);

            if (AllowMethodIndexAttributes && f.IsVirtual && !f.IsAbstract)
            {
                AddMethodIndexAttribute(f);
            }

            _sb.AppendIndent("");
            if (f.IsStatic)
            {
                _sb.Append("static ");
            }
            if (methodIsVirtual)
            {
                _sb.Append("virtual ");
            }
            _sb.Append(GetCLRTypeName(f) + " " + f.CLRName);
            AddMethodParameters(f, f.Parameters.Count);
            if (DeclareAsOverride(f))
            {
                _sb.Append(" override");
            }
            else if (f.IsAbstract && AllowSubclassing)
            {
                _sb.Append(" abstract");
            }

            _sb.Append(";\n");

            if (AllowMethodOverloads)
            {
                // The overloads (because of default values)
                for (int dc = 1; dc <= defcount; dc++)
                {
                    if (dc < defcount && f.HasAttribute <HideParamsWithDefaultValuesAttribute>())
                    {
                        continue;
                    }

                    AddComments(f);
                    _sb.AppendIndent("");
                    if (f.IsStatic)
                    {
                        _sb.Append("static ");
                    }
                    _sb.Append(GetCLRTypeName(f) + " " + f.CLRName);
                    AddMethodParameters(f, f.Parameters.Count - dc);
                    _sb.Append(";\n");
                }
            }
        }
        protected override void AddOverridableFunction(DefFunction f)
        {
            _wrapper.CppCheckTypeForDependancy(f.Type);
            foreach (DefParam param in f.Parameters)
            {
                _wrapper.CppCheckTypeForDependancy(param.Type);
            }

            _sb.AppendIndent("");
            _sb.Append(f.NativeTypeName + " " + ProxyName + "::" + f.Name + "(");
            AddNativeMethodParams(f);
            _sb.Append(" )");
            if (f.IsConstFunctionCall)
            {
                _sb.Append(" const");
            }
            _sb.Append("\n");
            _sb.AppendLine("{");
            _sb.IncreaseIndent();

            if (!f.IsAbstract)
            {
                _sb.AppendLine("if (_overriden[ " + _methodIndices[f] + " ])");
                _sb.AppendLine("{");
                _sb.IncreaseIndent();
            }

            if (f.HasAttribute <CustomNativeProxyDeclarationAttribute>())
            {
                string txt = f.GetAttribute <CustomNativeProxyDeclarationAttribute>().DeclarationText;
                txt = ReplaceCustomVariables(txt, f).Replace("@MANAGED@", "_managed");
                _sb.AppendLine(txt);
            }
            else
            {
                AddNativeProxyMethodBody(f, "_managed", _sb);
            }

            if (!f.IsAbstract)
            {
                _sb.DecreaseIndent();
                _sb.AppendLine("}");
                _sb.AppendLine("else");
                _sb.AppendIndent("\t");
                if (!f.IsVoid)
                {
                    _sb.Append("return ");
                }
                _sb.Append(f.Class.Name + "::" + f.Name + "(");
                for (int i = 0; i < f.Parameters.Count; i++)
                {
                    DefParam param = f.Parameters[i];
                    _sb.Append(" " + param.Name);
                    if (i < f.Parameters.Count - 1)
                    {
                        _sb.Append(",");
                    }
                }
                _sb.Append(" );\n");
            }

            _sb.DecreaseIndent();
            _sb.AppendLine("}");
        }
예제 #6
0
        protected override void AddMethod(DefFunction f)
        {
            if (f.HasAttribute <CustomCppDeclarationAttribute>())
            {
                if (f.IsAbstract && AllowSubclassing)
                {
                    return;
                }
                else
                {
                    string txt = f.GetAttribute <CustomCppDeclarationAttribute>().DeclarationText;
                    txt = ReplaceCustomVariables(txt, f);
                    _sb.AppendLine(txt);
                    _sb.AppendLine();
                    return;
                }
            }

            int defcount = 0;

            if (!f.HasAttribute <NoDefaultParamOverloadsAttribute>())
            {
                foreach (DefParam param in f.Parameters)
                {
                    if (param.DefaultValue != null)
                    {
                        defcount++;
                    }
                }
            }

            bool methodIsVirtual = DeclareAsVirtual(f);

            for (int dc = 0; dc <= defcount; dc++)
            {
                if (dc == 0 && f.IsAbstract && AllowSubclassing)
                {
                    //It's abstract, no body definition
                    continue;
                }

                if (!AllowMethodOverloads && dc > 0)
                {
                    continue;
                }

                if (dc < defcount && f.HasAttribute <HideParamsWithDefaultValuesAttribute>())
                {
                    continue;
                }

                _sb.AppendIndent(GetCLRTypeName(f) + " " + GetClassName() + "::" + f.CLRName);
                AddMethodParameters(f, f.Parameters.Count - dc);
                _sb.Append("\n");
                _sb.AppendLine("{");
                _sb.IncreaseIndent();

                bool isVirtualOverload = dc > 0 && methodIsVirtual && AllowVirtualMethods;

                if (isVirtualOverload)
                {
                    // Overloads (because of default values)
                    // main method is virtual, call it with CLR default values if _isOverriden=true,
                    // else do a normal native call

                    _sb.AppendLine("if (_isOverriden)");
                    _sb.AppendLine("{");
                    _sb.IncreaseIndent();

                    bool hasPostConversions = false;
                    for (int i = f.Parameters.Count - dc; i < f.Parameters.Count; i++)
                    {
                        DefParam p = f.Parameters[i];
                        if (!String.IsNullOrEmpty(p.CLRDefaultValuePreConversion))
                        {
                            _sb.AppendLine(p.CLRDefaultValuePreConversion);
                        }
                        if (!String.IsNullOrEmpty(p.CLRDefaultValuePostConversion))
                        {
                            hasPostConversions = true;
                        }

                        string  n1, n2, n3;
                        DefType dependancy;
                        p.Type.GetDefaultParamValueConversion(p, out n1, out n2, out n3, out dependancy);
                        if (dependancy != null)
                        {
                            AddTypeDependancy(dependancy);
                        }
                    }

                    _sb.AppendIndent("");
                    if (!f.IsVoid)
                    {
                        if (hasPostConversions)
                        {
                            _sb.Append(GetCLRTypeName(f) + " mp_return = ");
                        }
                        else
                        {
                            _sb.Append("return ");
                        }
                    }

                    _sb.Append(f.CLRName + "(");
                    for (int i = 0; i < f.Parameters.Count; i++)
                    {
                        DefParam p = f.Parameters[i];
                        _sb.Append(" ");
                        if (i < f.Parameters.Count - dc)
                        {
                            _sb.Append(p.Name);
                        }
                        else
                        {
                            _sb.Append(p.CLRDefaultValue);
                        }
                        if (i < f.Parameters.Count - 1)
                        {
                            _sb.Append(",");
                        }
                    }
                    _sb.Append(" );\n");

                    for (int i = f.Parameters.Count - dc; i < f.Parameters.Count; i++)
                    {
                        DefParam p = f.Parameters[i];
                        if (!String.IsNullOrEmpty(p.CLRDefaultValuePostConversion))
                        {
                            _sb.AppendLine(p.CLRDefaultValuePostConversion);
                        }
                    }

                    if (!f.IsVoid && hasPostConversions)
                    {
                        _sb.AppendLine("return mp_return;");
                    }

                    _sb.DecreaseIndent();
                    _sb.AppendLine("}");
                    _sb.AppendLine("else");
                    _sb.AppendLine("{");
                    _sb.IncreaseIndent();
                }

                AddMethodBody(f, f.Parameters.Count - dc);

                if (isVirtualOverload)
                {
                    _sb.DecreaseIndent();
                    _sb.AppendLine("}");
                }

                _sb.DecreaseIndent();
                _sb.AppendLine("}");
            }
        }