public static UnifiedClassDefinition CreateClassDefinition(
            Construct construct)
        {
            var klass = UnifiedClassDefinition.Create();

            ParseClass(construct, klass.Body);
            return(klass);
        }
Exemple #2
0
 public static UnifiedClassDefinition CreateModule(XElement node)
 {
     Contract.Requires(node != null);
     Contract.Requires(node.Name() == "module");
     return(UnifiedClassDefinition.Create(
                null, null, CreateSymbol(node.NthElement(0)), null,
                null,
                CreateScope(node.NthElement(1))));
 }
Exemple #3
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))));
        }
Exemple #4
0
        public UnifiedElement VisitTypeDeclaration(
            TypeDeclaration dec, object data)
        {
            var attrs      = dec.Attributes.AcceptVisitorAsAttrs(this, data);
            var mods       = LookupModifiers(dec.Modifiers);
            var name       = UnifiedVariableIdentifier.Create(dec.Name);
            var typeParams = dec.TypeParameters.AcceptVisitorAsTypeParams(
                this, data);

            if (typeParams.Count == 0)
            {
                typeParams = null;
            }
            var extends = dec.BaseTypes.AcceptVisitorAsConstrains(this, data);
            var body    = UnifiedBlock.Create();

            foreach (var node in dec.Members)
            {
                var uExpr = node.TryAcceptForExpression(this);
                if (uExpr != null)
                {
                    body.Add(uExpr);
                }
            }
            // set constraint
            var dic = CreateDictionary(dec.Constraints);

            if (typeParams != null)
            {
                foreach (
                    var generic in
                    typeParams.Descendants <UnifiedGenericParameter>(

                        ))
                {
                    var tName = GetTypeName(generic.Type);
                    if (dic.ContainsKey(tName))
                    {
                        foreach (var c in dic[tName])
                        {
                            if (generic.Constrains == null)
                            {
                                generic.Constrains =
                                    UnifiedSet <UnifiedTypeConstrain> .Create();
                            }
                            generic.Constrains.Add(c.DeepCopy());
                        }
                    }
                }
            }
            foreach (
                var generic in
                extends.Descendants <UnifiedGenericParameter>())
            {
                var tName = GetTypeName(generic.Type);
                if (dic.ContainsKey(tName))
                {
                    foreach (var c in dic[tName])
                    {
                        if (generic.Constrains == null)
                        {
                            generic.Constrains =
                                UnifiedSet <UnifiedTypeConstrain> .Create();
                        }
                        generic.Constrains.Add(c.DeepCopy());
                    }
                }
            }

            switch (dec.ClassType)
            {
            case ClassType.Class:
                return(UnifiedClassDefinition.Create(
                           attrs, mods, name, typeParams, extends, body));

            case ClassType.Struct:
                return(UnifiedStructDefinition.Create(
                           attrs, mods, name, typeParams, extends, body));

            case ClassType.Interface:
                return(UnifiedInterfaceDefinition.Create(
                           attrs, mods, name, typeParams, extends, body));

            case ClassType.Enum:
                return(UnifiedEnumDefinition.Create(
                           attrs, mods, name, typeParams, extends, body));
            }
            var msg = "LookupClassKind : " + dec.ClassType + "には対応していません。";

            throw new InvalidOperationException(msg);
        }