Exemplo n.º 1
0
        protected override void AddMethodsForField(DefField field)
        {
            _sb.AppendLine(GetCLRTypeName(field) + " get_" + field.Name + "();");
            DefParam param = new DefParam(field, "value");

            _sb.AppendLine("void set_" + field.Name + "(" + param.Type.GetCLRParamTypeName(param) + " value);");
        }
Exemplo n.º 2
0
 protected virtual string GetNativeInvokationTarget(DefField field)
 {
     if (!field.IsStatic)
     {
         if (field.ProtectionType == ProtectionType.Public)
         {
             return(GetNativeInvokationTarget() + "->" + field.Name);
         }
         else if (field.ProtectionType == ProtectionType.Protected)
         {
             string proxyName = NativeProtectedStaticsProxy.GetProtectedStaticsProxyName(_t);
             return("static_cast<" + proxyName + "*>(_native)->" + field.Name);
         }
         else
         {
             throw new Exception("Unexpected");
         }
     }
     else
     {
         if (field.ProtectionType == ProtectionType.Public)
         {
             return(field.Class.FullNativeName + "::" + field.Name);
         }
         else
         {
             return(NativeProtectedStaticsProxy.GetProtectedStaticsProxyName(field.Class) + "::" + field.Name);
         }
     }
 }
Exemplo n.º 3
0
 protected override void AddInterfaceMethodsForField(DefField field)
 {
     _sb.DecreaseIndent();
     _sb.AppendLine(GetProtectionString(field.ProtectionType) + ":");
     _sb.IncreaseIndent();
     base.AddInterfaceMethodsForField(field);
 }
Exemplo n.º 4
0
 protected override void AddStaticField(DefField field)
 {
     base.AddStaticField(field);
     _sb.AppendIndent("");
     if (field.IsConst)
     {
         _sb.Append("const ");
     }
     if (field.IsStatic)
     {
         _sb.Append("static ");
     }
     _sb.Append(GetCLRTypeName(field) + " " + field.Name + " = " + field.Type.GetNativeCallConversion(field.FullNativeName, field) + ";\n\n");
 }
        protected override void AddPropertyField(DefField field)
        {
            //TODO comments for fields
            //AddComments(field);
            string ptype = GetCLRTypeName(field);

            _sb.AppendFormatIndent("property {0} {1}\n{{\n", ptype, ToCamelCase(field.Name));
            _sb.IncreaseIndent();
            _sb.AppendLine(ptype + " get()\n{");
            _sb.AppendLine("\treturn " + NameToPrivate(field) + ";");
            _sb.AppendLine("}");
            _sb.DecreaseIndent();
            _sb.AppendLine("}");
        }
Exemplo n.º 6
0
        protected override void AddMethodsForField(DefField field)
        {
            string managedType = field.Type.GetNativeCallConversion(GetNativeInvokationTarget(field), field);

            _sb.AppendLine(GetCLRTypeName(field) + " " + GetClassName() + "::get_" + field.Name + "()");
            _sb.AppendLine("{");
            _sb.AppendLine("\treturn " + managedType + ";");
            _sb.AppendLine("}");

            DefParam param = new DefParam(field, "value");

            _sb.AppendLine("void " + GetClassName() + "::set_" + field.Name + "(" + param.Type.GetCLRParamTypeName(param) + " value)");
            _sb.AppendLine("{");
            _sb.IncreaseIndent();
            _sb.AppendLine(GetNativeInvokationTarget(field) + " = " + AddParameterConversion(param) + ";");
            _sb.DecreaseIndent();
            _sb.AppendLine("}");
        }
Exemplo n.º 7
0
        protected override void AddPropertyField(DefField field)
        {
            //TODO comments for fields
            //AddComments(field);

            string ptype;

            if (field.IsNativeArray)
            {
                if (field.Type.HasAttribute <NativeValueContainerAttribute>() ||
                    (field.Type.IsValueType && !field.Type.HasWrapType(WrapTypes.NativePtrValueType)))
                {
                    DefParam tmpParam = new DefParam(field, field.Name);
                    switch (field.PassedByType)
                    {
                    case PassedByType.Value:
                        tmpParam.PassedByType = PassedByType.Pointer;
                        break;

                    case PassedByType.Pointer:
                        tmpParam.PassedByType = PassedByType.PointerPointer;
                        break;

                    default:
                        throw new Exception("Unexpected");
                    }

                    ptype = tmpParam.CLRTypeName;
                    _sb.AppendIndent("");
                    if (field.IsStatic)
                    {
                        _sb.Append("static ");
                    }
                    _sb.AppendFormat("property {0} {1}\n", ptype, field.Name);
                    _sb.AppendLine("{");

                    _sb.AppendLine(GetProtectionString(field.ProtectionType) + ":");
                    _sb.AppendLine("\t" + ptype + " get();");

                    _sb.AppendLine("}");
                }
                else
                {
                    ptype = field.CLRTypeName;
                    _sb.AppendIndent("");
                    if (field.IsStatic)
                    {
                        _sb.Append("static ");
                    }
                    _sb.AppendFormat("property {0} {1}[int]\n", ptype, field.Name);
                    _sb.AppendLine("{");

                    _sb.AppendLine(GetProtectionString(field.ProtectionType) + ":");
                    _sb.AppendLine("\t" + ptype + " get(int index);");
                    _sb.AppendLine("\tvoid set(int index, " + ptype + " value);");

                    _sb.AppendLine("}");
                }
            }
            else if (_cachedMembers.Contains(field))
            {
                ptype = field.CLRTypeName;
                _sb.AppendIndent("");
                if (field.IsStatic)
                {
                    _sb.Append("static ");
                }
                _sb.AppendFormat("property {0} {1}\n", ptype, field.Name);
                _sb.AppendLine("{");

                _sb.AppendLine(GetProtectionString(field.ProtectionType) + ":");
                _sb.AppendLine("\t" + ptype + " get();");

                _sb.AppendLine("}");
            }
            else
            {
                ptype = GetCLRTypeName(field);
                _sb.AppendIndent("");
                if (field.IsStatic)
                {
                    _sb.Append("static ");
                }
                _sb.AppendFormat("property {0} {1}\n", ptype, field.Name);
                _sb.AppendLine("{");

                _sb.AppendLine(GetProtectionString(field.ProtectionType) + ":");
                _sb.AppendLine("\t" + ptype + " get();");

                if ( // SharedPtrs can be copied by value. Let all be copied by value just to be sure (field.PassedByType == PassedByType.Pointer || field.Type.IsValueType)
                    !IsReadOnly && !field.Type.HasAttribute <ReadOnlyForFieldsAttribute>() &&
                    !field.IsConst)
                {
                    _sb.AppendLine(GetProtectionString(field.ProtectionType) + ":");
                    _sb.AppendLine("\tvoid set(" + ptype + " value);");
                }

                _sb.AppendLine("}");
            }
        }
 protected override string GetNativeInvokationTarget(DefField field)
 {
     return("static_cast<" + ProxyName + "*>(_native)->" + _t.FullNativeName + "::" + field.Name);
 }
Exemplo n.º 9
0
 protected virtual void AddInterfaceMethodsForField(DefField field)
 {
     AddMethodsForField(field);
 }
Exemplo n.º 10
0
 protected virtual void AddInterfacePropertyField(DefField field)
 {
     AddPropertyField(field);
 }
Exemplo n.º 11
0
 protected virtual void AddPropertyField(DefField field)
 {
 }
Exemplo n.º 12
0
 protected virtual void AddMethodsForField(DefField field)
 {
 }
Exemplo n.º 13
0
 protected virtual void AddStaticField(DefField field)
 {
 }
Exemplo n.º 14
0
        protected override void AddPropertyField(DefField field)
        {
            string ptype = GetCLRTypeName(field);
            string pname = GetClassName() + "::" + field.Name;

            if (field.IsNativeArray)
            {
                if (field.Type.HasAttribute <NativeValueContainerAttribute>() ||
                    (field.Type.IsValueType && !field.Type.HasWrapType(WrapTypes.NativePtrValueType)))
                {
                    DefParam tmpParam = new DefParam(field, field.Name + "_array");
                    switch (field.PassedByType)
                    {
                    case PassedByType.Value:
                        tmpParam.PassedByType = PassedByType.Pointer;
                        break;

                    case PassedByType.Pointer:
                        tmpParam.PassedByType = PassedByType.PointerPointer;
                        break;

                    default:
                        throw new Exception("Unexpected");
                    }

                    ptype = GetCLRTypeName(tmpParam);
                    string managedType = field.Type.GetNativeCallConversion(GetNativeInvokationTarget(field), tmpParam);

                    _sb.AppendLine(ptype + " " + pname + "::get()");
                    _sb.AppendLine("{");
                    _sb.AppendLine("\treturn " + managedType + ";");
                    _sb.AppendLine("}");
                }
                else
                {
                    string managedType = field.Type.GetNativeCallConversion(GetNativeInvokationTarget(field) + "[index]", field);

                    _sb.AppendLine(ptype + " " + pname + "::get(int index)");
                    _sb.AppendLine("{");
                    _sb.AppendLine("\tif (index < 0 || index >= " + field.ArraySize + ") throw gcnew IndexOutOfRangeException();");
                    _sb.AppendLine("\treturn " + managedType + ";");
                    _sb.AppendLine("}");
                    _sb.AppendLine("void " + pname + "::set(int index, " + ptype + " value )");
                    _sb.AppendLine("{");
                    _sb.IncreaseIndent();
                    _sb.AppendLine("if (index < 0 || index >= " + field.ArraySize + ") throw gcnew IndexOutOfRangeException();");
                    string param = AddParameterConversion(new DefParam(field, "value"));
                    _sb.AppendLine(GetNativeInvokationTarget(field) + "[index] = " + param + ";");
                    _sb.DecreaseIndent();
                    _sb.AppendLine("}");
                }
            }
            else if (_cachedMembers.Contains(field))
            {
                string managedType;
                if (field.Type.IsSTLContainer)
                {
                    managedType = GetNativeInvokationTarget(field);
                }
                else
                {
                    managedType = field.Type.GetNativeCallConversion(GetNativeInvokationTarget(field), field);
                }
                string priv = NameToPrivate(field);

                _sb.AppendLine(ptype + " " + pname + "::get()");
                _sb.AppendLine("{");
                if (!field.IsStatic)
                {
                    _sb.AppendLine("\treturn ( CLR_NULL == " + priv + " ) ? (" + priv + " = " + managedType + ") : " + priv + ";");
                }
                else
                {
                    _sb.AppendLine("\treturn " + priv + ";");
                }
                _sb.AppendLine("}");
            }
            else
            {
                string managedType = field.Type.GetNativeCallConversion(GetNativeInvokationTarget(field), field);

                _sb.AppendLine(ptype + " " + pname + "::get()");
                _sb.AppendLine("{");
                _sb.AppendLine("\treturn " + managedType + ";");
                _sb.AppendLine("}");

                if ( // SharedPtrs can be copied by value. Let all be copied by value just to be sure (field.PassedByType == PassedByType.Pointer || field.Type.IsValueType)
                    !IsReadOnly && !field.Type.HasAttribute <ReadOnlyForFieldsAttribute>() &&
                    !field.IsConst)
                {
                    _sb.AppendLine("void " + pname + "::set( " + ptype + " value )");
                    _sb.AppendLine("{");
                    _sb.IncreaseIndent();
                    string param = AddParameterConversion(new DefParam(field, "value"));
                    _sb.AppendLine(GetNativeInvokationTarget(field) + " = " + param + ";");
                    _sb.DecreaseIndent();
                    _sb.AppendLine("}");
                }
            }
        }