Beispiel #1
0
 public ServerLogicManager()
 {
     m_Logics = new HDictionary <Type, IServerLogic>();
 }
Beispiel #2
0
        private TypeDef TypeDefFromCCIType(CCI.AssemblyNode assembly, CCI.TypeNode type)
        {
            if (!IsCCITypeDefinition(type))
                throw new InvalidOperationException("type is not a definition");

            if (type.DeclaringModule == null || type.DeclaringModule.ContainingAssembly == null ||
                type.DeclaringModule.ContainingAssembly != assembly || type.Name == null)
                throw new InvalidOperationException("type definition not found in assembly");

            if (type is CCI.ArrayType || type is CCI.Reference || type is CCI.Pointer || type is CCI.FunctionPointer)
                throw new InvalidOperationException("type is not a definition");

            if (type is CCI.ClassParameter || type is CCI.TypeParameter)
                throw new InvalidOperationException("unexpected type parameter");

            var parameters = default(AList<ParameterTypeDef>);
            var declType = type;
            do
            {
                if (declType.TemplateArguments != null && declType.TemplateArguments.Count > 0)
                    throw new InvalidOperationException("type is not a definition");
                if (declType.TemplateParameters != null && declType.TemplateParameters.Count > 0)
                {
                    if (parameters == null)
                        parameters = new AList<ParameterTypeDef>();
                    for (var i = 0; i < declType.TemplateParameters.Count; i++)
                    {
                        var p = declType.TemplateParameters[i];
                        if (p.Template != null)
                            throw new InvalidOperationException("invalid class type parameter");
                        if (p is CCI.MethodClassParameter || p is CCI.MethodTypeParameter)
                            throw new InvalidOperationException("invalid class type parameter");
                        var cp = p as CCI.ClassParameter;
                        var tp = p as CCI.TypeParameter;
                        if (cp != null || tp != null)
                        {
                            var variance = default(ParameterVariance);
                            var constraint = default(ParameterConstraint);
                            ParameterConstraintFromCCITypeParameterFlags
                                (cp == null ? tp.TypeParameterFlags : cp.TypeParameterFlags,
                                 out variance,
                                 out constraint);
                            var pextends = default(TypeRef);
                            var pimplements = default(AList<TypeRef>);
                            TypeDerivationFromCCIType(p, out pextends, out pimplements);
                            parameters.Insert
                                (i,
                                 (new ParameterTypeDef
                                     (null,
                                      CustomAttributesFromCCIMember(p),
                                      pextends,
                                      pimplements,
                                      ParameterFlavor.Type,
                                      i,
                                      variance,
                                      constraint)));
                        }
                        else
                            throw new InvalidOperationException("invalid class type parameter");
                    }
                }
                declType = declType.DeclaringType;
            }
            while (declType != null);

            var members = default(AList<MemberDef>);
            for (var i = 0; i < type.Members.Count; i++)
            {
                var member = type.Members[i];
                var method = member as CCI.Method;
                if (method != null)
                {
                    if (members == null)
                        members = new AList<MemberDef>();
                    members.Add(MethodDefFromCCIMethod(method));
                }
                else
                {
                    var field = member as CCI.Field;
                    if (field != null)
                    {
                        if (members == null)
                            members = new AList<MemberDef>();
                        members.Add(FieldDefFromCCIField(field));
                    }
                    else
                    {
                        var prop = member as CCI.Property;
                        if (prop != null)
                        {
                            if (members == null)
                                members = new AList<MemberDef>();
                            members.Add(PropertyDefFromCCIProperty(prop));
                        }
                        else
                        {
                            var evnt = member as CCI.Event;
                            if (evnt != null)
                            {
                                if (members == null)
                                    members = new AList<MemberDef>();
                                members.Add(EventDefFromCCIEvent(evnt));
                            }
                        }
                    }
                }
            }

            // Place members in canonical order
            var signatureToMember = default(Dictionary<MemberSignature, MemberDef>);
            if (members != null)
            {
                var signatures = new List<MemberSignature>();
                signatureToMember = new Dictionary<MemberSignature, MemberDef>();
                for (var i = 0; i < members.Count; i++)
                {
                    var signature = members[i].Signature;
                    if (signatureToMember.ContainsKey(signature))
                        throw new InvalidOperationException("invalid type definition");
                    signatures.Add(signature);
                    signatureToMember.Add(signature, members[i]);
                }
                signatures.Sort((l, r) => l.CompareTo(r));
                members = new AList<MemberDef>();
                for (var i = 0; i < signatures.Count; i++)
                    members.Add(signatureToMember[signatures[i]]);
            }

            var qtn = QualifiedTypeNameFromCCIType(type);
            var extends = default(TypeRef);
            var implements = default(AList<TypeRef>);
            TypeDerivationFromCCIType(type, out extends, out implements);
            var customAttributes = CustomAttributesFromCCIMember(type);

            var annotations = new AList<Annotation>();
            annotations.Add(new TypeInheritanceAnnotation(type.IsAbstract, type.IsSealed));

            if (type is CCI.Interface)
            {
                if (extends != null)
                    throw new InvalidOperationException("invalid interface type definition");
                return new InterfaceTypeDef(annotations, customAttributes, implements, parameters, qtn.Name, members);
            }

            var explicitInterfaceImplementations = default(HDictionary<PolymorphicMethodRef, PolymorphicMethodRef>);
            // NOTE: CLR allows a type to take any implemented method of its base types and bind it to any slot
            // of its base or implemented types. However CCI forgets the type and simply associates
            // the slot with the implemented method.
            foreach (var m in type.Members)
            {
                var implMethod = m as CCI.Method;
                if (implMethod != null)
                {
                    var interfaceMethods = implMethod.ImplementedInterfaceMethods;
                    if (interfaceMethods != null)
                    {
                        foreach (var ifaceMethod in interfaceMethods)
                        {
                            if (explicitInterfaceImplementations == null)
                                explicitInterfaceImplementations =
                                    new HDictionary<PolymorphicMethodRef, PolymorphicMethodRef>();
                            explicitInterfaceImplementations.Add
                                (PolymorphicMethodRefFromCCIMethod(ifaceMethod),
                                 PolymorphicMethodRefFromCCIMethod(implMethod));
                        }
                    }
                }
            }

            var isCallStaticConstructorEarly = (type.Flags & CCI.TypeFlags.BeforeFieldInit) != 0;

            if (global.QualifiedTypeNameToAbbreviation.ContainsKey(qtn))
            {
                var numberFlavor = default(NumberFlavor);
                var handleFlavor = default(HandleFlavor);
                if (global.QualifiedTypeNameToNumberFlavor.TryGetValue(qtn, out numberFlavor))
                    return new NumberTypeDef
                        (annotations,
                         customAttributes,
                         extends,
                         implements,
                         parameters,
                         qtn.Name,
                         members,
                         numberFlavor,
                         explicitInterfaceImplementations,
                         isCallStaticConstructorEarly);
                else if (global.QualifiedTypeNameToHandleFlavor.TryGetValue(qtn, out handleFlavor))
                    return new HandleTypeDef
                        (annotations,
                         customAttributes,
                         extends,
                         implements,
                         parameters,
                         qtn.Name,
                         members,
                         handleFlavor,
                         explicitInterfaceImplementations,
                         isCallStaticConstructorEarly);
                else if (qtn.Equals(global.VoidName))
                    return new VoidTypeDef
                        (annotations,
                         customAttributes,
                         extends,
                         implements,
                         parameters,
                         qtn.Name,
                         members,
                         explicitInterfaceImplementations,
                         isCallStaticConstructorEarly);
                else if (qtn.Equals(global.ObjectName))
                    return new ObjectTypeDef
                        (annotations,
                         customAttributes,
                         extends,
                         implements,
                         parameters,
                         qtn.Name,
                         members,
                         explicitInterfaceImplementations,
                         isCallStaticConstructorEarly);
                else if (qtn.Equals(global.StringName))
                    return new StringTypeDef
                        (annotations,
                         customAttributes,
                         extends,
                         implements,
                         parameters,
                         qtn.Name,
                         members,
                         explicitInterfaceImplementations,
                         isCallStaticConstructorEarly);
                else
                    throw new InvalidOperationException("unrecognised special type");
            }
            else if (qtn.Equals(global.EnumName) || qtn.Equals(global.ValueTypeName) || qtn.Equals(global.DelegateName) ||
                     qtn.Equals(global.MulticastDelegateName) || qtn.Equals(global.ObjectName))
                return new ClassTypeDef
                    (annotations,
                     customAttributes,
                     extends,
                     implements,
                     parameters,
                     qtn.Name,
                     members,
                     explicitInterfaceImplementations,
                     isCallStaticConstructorEarly);
            else if (qtn.Equals(global.NullableConstructorName))
                return new StructTypeDef
                    (annotations,
                     customAttributes,
                     extends,
                     implements,
                     parameters,
                     qtn.Name,
                     members,
                     explicitInterfaceImplementations,
                     isCallStaticConstructorEarly);
            else
            {
                // Follow derivation chain to decide if value or ref type
                var baseType = type.BaseType;
                while (baseType != null)
                {
                    var bqtn = QualifiedTypeNameFromCCIType(baseType);
                    if (bqtn.Equals(global.DelegateName) || bqtn.Equals(global.MulticastDelegateName))
                        // Is a user-defined delegate type
                        return new DelegateTypeDef
                            (annotations,
                             customAttributes,
                             extends,
                             implements,
                             parameters,
                             qtn.Name,
                             members,
                             explicitInterfaceImplementations,
                             isCallStaticConstructorEarly);
                    else if (bqtn.Equals(global.EnumName))
                        // Is a user-defined enumeration
                        return new EnumTypeDef
                            (annotations,
                             customAttributes,
                             extends,
                             implements,
                             qtn.Name,
                             members,
                             explicitInterfaceImplementations,
                             isCallStaticConstructorEarly);
                    else if (bqtn.Equals(global.ValueTypeName))
                        // Is a user-defined struct
                        return new StructTypeDef
                            (annotations,
                             customAttributes,
                             extends,
                             implements,
                             parameters,
                             qtn.Name,
                             members,
                             explicitInterfaceImplementations,
                             isCallStaticConstructorEarly);
                    else if (bqtn.Equals(global.ObjectName))
                        return new ClassTypeDef
                            (annotations,
                             customAttributes,
                             extends,
                             implements,
                             parameters,
                             qtn.Name,
                             members,
                             explicitInterfaceImplementations,
                             isCallStaticConstructorEarly);
                    else
                        baseType = baseType.BaseType;
                }
                throw new InvalidOperationException("type does not derive from object");
            }
            // TODO: CompleteSlotImplementations
        }
 public ServerWorldManager()
 {
     m_Worlds = new HDictionary <int, AbsWorld>();
 }
Beispiel #4
0
        private CustomAttribute CustomAttributeFromCCIAttribute(CCI.AttributeNode attribute)
        {
            var typeRef = TypeRefFromCCIType(attribute.Type);
            var namedTypeRef = typeRef as NamedTypeRef;
            if (namedTypeRef == null)
                throw new InvalidOperationException("invalid attribute");
            if (namedTypeRef.Arguments.Count > 0)
                throw new InvalidOperationException("invalid attribute");

            var positional = default(AList<object>);
            var named = default(HDictionary<string, object>);

            if (attribute.Expressions != null)
            {
                for (var i = 0; i < attribute.Expressions.Count; i++)
                {
                    var expr = attribute.Expressions[i];
                    var namedExpr = expr as CCI.NamedArgument;
                    if (namedExpr == null)
                    {
                        var litExpr = expr as CCI.Literal;
                        if (litExpr != null)
                        {
                            if (positional == null)
                                positional = new AList<object>();
                            positional.Add(litExpr.Value);
                        }
                        // else: ignare
                    }
                    else if (namedExpr.Name != null)
                    {
                        var litExpr = namedExpr.Value as CCI.Literal;
                        if (litExpr != null)
                        {
                            if (named == null)
                                named = new HDictionary<string, object>();
                            named.Add(namedExpr.Name.Name, litExpr.Value);
                        }
                        // else: ignore
                    }
                    // else: ignore
                }
            }
            return new CustomAttribute(namedTypeRef.Name, positional, named);
        }