示例#1
0
            private static readonly Field[] _emptyFields = new Field[0]; // fields were never initialized before a type was created

            public StructType(CodeContext/*!*/ context, string name, PythonTuple bases, PythonDictionary members)
                : base(context, name, bases, members) {

                foreach (PythonType pt in ResolutionOrder) {
                    StructType st = pt as StructType;
                    if (st != this && st != null) {
                        st.EnsureFinal();
                    }

                    UnionType ut = pt as UnionType;
                    if (ut != null) {
                        ut.EnsureFinal();
                    }
                }

                object pack;
                if (members.TryGetValue("_pack_", out pack)) {
                    if (!(pack is int) || ((int)pack < 0)) {
                        throw PythonOps.ValueError("pack must be a non-negative integer");
                    }
                    _pack = (int)pack;
                }

                object fields;
                if (members.TryGetValue("_fields_", out fields)) {
                    SetFields(fields);
                }

                // TODO: _anonymous_
            }
示例#2
0
            public ArrayType(CodeContext/*!*/ context, string name, PythonTuple bases, PythonDictionary dict)
                : base(context, name, bases, dict) {
                object len;
                int iLen;
                if (!dict.TryGetValue("_length_", out len) || !(len is int) || (iLen = (int)len) < 0) {
                    throw PythonOps.AttributeError("arrays must have _length_ attribute and it must be a positive integer");
                }

                object type;
                if (!dict.TryGetValue("_type_", out type)) {
                    throw PythonOps.AttributeError("class must define a '_type_' attribute");
                }

                _length = iLen;
                _type = (INativeType)type;

                if (_type is SimpleType) {
                    SimpleType st = (SimpleType)_type;
                    if (st._type == SimpleTypeKind.Char) {
                        // TODO: (c_int * 2).value isn't working
                        SetCustomMember(context,
                            "value",
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetCharArrayValue")),
                                NameType.Property | NameType.Python
                            )
                        );

                        SetCustomMember(context,
                            "raw",
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayRaw")),
                                NameType.Property | NameType.Python
                            )
                        );
                    } else if (st._type == SimpleTypeKind.WChar) {
                        SetCustomMember(context,
                            "value",
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayValue")),
                                NameType.Property | NameType.Python
                            )
                        );

                        SetCustomMember(context,
                            "raw",
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayRaw")),
                                NameType.Property | NameType.Python
                            )
                        );
                    }
                }
            }
示例#3
0
            public UnionType(CodeContext/*!*/ context, string name, PythonTuple bases, PythonDictionary members)
                : base(context, name, bases, members) {

                object fields;
                if (members.TryGetValue("_fields_", out fields)) {
                    SetFields(fields);
                }
            }
示例#4
0
            public PointerType(CodeContext/*!*/ context, string name, PythonTuple bases, PythonDictionary members)
                : base(context, name, bases, members) {

                object type;
                if (members.TryGetValue("_type_", out type) && !(type is INativeType)) {
                    throw PythonOps.TypeError("_type_ must be a type");
                }
                _type = (INativeType)type;
                if (_type != null) {
                    _typeFormat = _type.TypeFormat;
                }
            }
示例#5
0
文件: nt.cs 项目: jcteague/ironruby
            private static bool TryGetDictValue(PythonDictionary dict, string name, out object dictTime) {
                if (dict != null && dict.TryGetValue(name, out dictTime)) {
                    dictTime = TryShrinkToInt(dictTime);
                    return true;
                }

                dictTime = null;
                return false;
            }
示例#6
0
            public ArrayType(CodeContext /*!*/ context, string name, PythonTuple bases, PythonDictionary dict)
                : base(context, name, bases, dict)
            {
                int iLen;

                if (!dict.TryGetValue("_length_", out object len) || !(len is int) || (iLen = (int)len) < 0)
                {
                    throw PythonOps.AttributeError("arrays must have _length_ attribute and it must be a positive integer");
                }

                object type;

                if (!dict.TryGetValue("_type_", out type))
                {
                    throw PythonOps.AttributeError("class must define a '_type_' attribute");
                }

                _length = iLen;
                _type   = (INativeType)type;

                if (_type is SimpleType st)
                {
                    if (st._type == SimpleTypeKind.Char)
                    {
                        // TODO: (c_int * 2).value isn't working
                        SetCustomMember(context,
                                        "value",
                                        new ReflectedExtensionProperty(
                                            new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetCharArrayValue")),
                                            NameType.Property | NameType.Python
                                            )
                                        );

                        SetCustomMember(context,
                                        "raw",
                                        new ReflectedExtensionProperty(
                                            new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayRaw")),
                                            NameType.Property | NameType.Python
                                            )
                                        );
                    }
                    else if (st._type == SimpleTypeKind.WChar)
                    {
                        SetCustomMember(context,
                                        "value",
                                        new ReflectedExtensionProperty(
                                            new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayValue")),
                                            NameType.Property | NameType.Python
                                            )
                                        );

                        SetCustomMember(context,
                                        "raw",
                                        new ReflectedExtensionProperty(
                                            new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayRaw")),
                                            NameType.Property | NameType.Python
                                            )
                                        );
                    }
                }
            }
示例#7
0
        public bool __contains__(CodeContext /*!*/ context, object value)
        {
            object dummy;

            return(Dictionary.TryGetValue(value, out dummy));
        }