示例#1
0
        public static UnifiedClassDefinition CreateClass(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "class");
            var constNode = node.NthElement(1);
            var constrain = constNode.Name() != "nil"
                                    ? UnifiedExtendConstrain.Create(
                UnifiedType.Create(constNode.Value))
                                    : null;

            return(UnifiedClassDefinition.Create(
                       null, null, CreateSymbol(node.NthElement(0)), null,
                       constrain.ToSet <UnifiedTypeConstrain>(),
                       CreateScope(node.NthElement(2))));
        }
        CreateDictionary(IEnumerable <Constraint> constraints)
        {
            var dic = new Dictionary <string, IList <UnifiedTypeConstrain> >();

            foreach (var c in constraints)
            {
                var list = null as IList <UnifiedTypeConstrain>;
                if (dic.TryGetValue(c.TypeParameter.Identifier, out list)
                    == false)
                {
                    dic[c.TypeParameter.Identifier] =
                        list = new List <UnifiedTypeConstrain>();
                }
                var types = c.BaseTypes.Select(LookupType);
                foreach (var type in types)
                {
                    list.Add(UnifiedExtendConstrain.Create(type));
                }
            }
            return(dic);
        }