Beispiel #1
0
        public static UnifiedType CreateStructOrUnionSpecifier(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "struct_or_union_specifier");

            /*	struct_or_union_specifier
             * : struct_or_union IDENTIFIER? '{' struct_declaration_list '}'
             * | struct_or_union IDENTIFIER
             */
            // 構造体の定義と宣言の両方をこのメソッドで作成
            // 常に UnifiedType を返すが、
            // 構造体定義をしている場合だけ関数の呼び出し元で UnifiedType の中身をとりだす

            // typedef "struct {}" data; -> クラス?
            // "struct data {}"; -> クラス
            // "struct data" a; -> 型

            var isStruct   = CreateStructOrUnion(node.FirstElement()) == "struct";
            var identifier = node.Element("IDENTIFIER");
            var typeName   = identifier == null
                                                                   ? null
                                                                   : UnifiedVariableIdentifier.Create(
                identifier.Value);

            // 型の場合
            if (node.Elements().Count() == 2)
            {
                var baseType = UnifiedType.Create(typeName);
                return(isStruct ? baseType.WrapStruct() : baseType.WrapUnion());
            }

            // struct or union の定義がある場合
            var body =
                CreateStructDeclarationList(
                    node.Element("struct_declaration_list"));
            var structOrUnion = isStruct
                                                                                ? (UnifiedClassLikeDefinition)
                                UnifiedStructDefinition.
                                Create(
                name: typeName,
                body: body)
                                                                                : UnifiedUnionDefinition.Create(
                name: typeName, body: body);

            // TODO struct or unionはあくまでもTypeとして返すののか?
            return(UnifiedType.Create(structOrUnion));
        }
 public override bool Visit(
         UnifiedStructDefinition element, VisitorArgument arg)
 {
     return Visit(element, arg, "class");
 }
 public override bool Visit(
         UnifiedStructDefinition element, VisitorArgument arg)
 {
     throw new NotImplementedException();
 }
Beispiel #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);
        }
 public override bool Visit(
     UnifiedStructDefinition element, VisitorArgument arg)
 {
     return(Visit(element, arg, "class"));
 }
Beispiel #6
0
 public override bool Visit(
     UnifiedStructDefinition element, VisitorArgument arg)
 {
     throw new NotImplementedException();
 }