コード例 #1
0
ファイル: Parser.cs プロジェクト: altseed/LanguageTranslator
        private void ParseStrcut(string namespace_, StructDeclarationSyntax structSyntax, SemanticModel semanticModel)
        {
            var structDef = new StructDef();

            structDef.Internal = structSyntax;

            structDef.Namespace = namespace_;
            structDef.Name      = structSyntax.Identifier.ValueText;

            var fullName = namespace_ + "." + structDef.Name;

            {
                var partial = definitions.Structs.FirstOrDefault(x => x.Namespace + "." + x.Name == fullName);
                if (partial != null)
                {
                    structDef = partial;
                }
            }

            if (TypesNotParsed.Contains(fullName))
            {
                return;
            }

            // Summary
            var declaredSymbol = semanticModel.GetDeclaredSymbol(structSyntax);
            var xml            = declaredSymbol?.GetDocumentationCommentXml();

            structDef.Summary = SummaryComment.Parse(xml);

            ParseTypeDeclaration(structDef, structSyntax, semanticModel);

            definitions.Structs.Add(structDef);
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: altseed/LanguageTranslator
        private PropertyDef ParseProperty(PropertyDeclarationSyntax propertySyntax, SemanticModel semanticModel)
        {
            var propertyDef = new PropertyDef();

            propertyDef.Internal = propertySyntax;

            propertyDef.Name        = propertySyntax.Identifier.ValueText;
            propertyDef.Type        = ParseTypeSpecifier(propertySyntax.Type, semanticModel);
            propertyDef.AccessLevel = ParseAccessLevel(propertySyntax.Modifiers) ?? AccessLevel.Private;
            propertyDef.IsStatic    = propertySyntax.Modifiers.Any(x => x.ValueText == "static");

            foreach (var accessor in propertySyntax.AccessorList.Accessors)
            {
                var acc = new AccessorDef();
                acc.Internal    = accessor;
                acc.AccessLevel = ParseAccessLevel(accessor.Modifiers) ?? propertyDef.AccessLevel;

                if (accessor.Keyword.Text == "get")
                {
                    propertyDef.Getter = acc;
                }
                else if (accessor.Keyword.Text == "set")
                {
                    propertyDef.Setter = acc;
                }
            }

            // Summary
            var declaredSymbol = semanticModel.GetDeclaredSymbol(propertySyntax);
            var xml            = declaredSymbol?.GetDocumentationCommentXml();

            propertyDef.Summary = SummaryComment.Parse(xml);

            return(propertyDef);
        }
コード例 #3
0
ファイル: Parser.cs プロジェクト: altseed/LanguageTranslator
        private void ParseEnum(string namespace_, EnumDeclarationSyntax enumSyntax, SemanticModel semanticModel)
        {
            var enumDef = new EnumDef();

            // 名称
            enumDef.Name = enumSyntax.Identifier.ValueText;

            // ネームスペース
            enumDef.Namespace = namespace_;

            // swig
            enumDef.IsDefinedBySWIG = namespace_.Contains(swig_namespace_keyword);

            foreach (var member in enumSyntax.Members)
            {
                var def = ParseEnumMember(member, semanticModel);
                enumDef.Members.Add(def);
            }

            // Summary
            var declaredSymbol = semanticModel.GetDeclaredSymbol(enumSyntax);
            var xml            = declaredSymbol?.GetDocumentationCommentXml();

            enumDef.Summary = SummaryComment.Parse(xml);

            definitions.Enums.Add(enumDef);
        }
コード例 #4
0
ファイル: Parser.cs プロジェクト: altseed/LanguageTranslator
        private FieldDef ParseField(FieldDeclarationSyntax fieldSyntax, SemanticModel semanticModel)
        {
            var fieldDef = new FieldDef();

            if (fieldSyntax.Declaration.Variables.Count != 1)
            {
                var span = fieldSyntax.SyntaxTree.GetLineSpan(fieldSyntax.Declaration.Variables.Span);
                throw new ParseException(string.Format("{0} : 変数の複数同時宣言は禁止です。", span));
            }

            var declaration = fieldSyntax.Declaration;
            var variable    = fieldSyntax.Declaration.Variables[0];

            // 主にfixed配列対象
            ArgumentSyntax arguments = null;

            if (variable.ArgumentList != null)
            {
                arguments = variable.ArgumentList.Arguments.FirstOrDefault();
            }

            var type = ParseTypeSpecifier(declaration.Type, semanticModel);

            // 無理やり書き換える
            if (arguments != null)
            {
                if (type is SimpleType)
                {
                    var at = new ArrayType();
                    at.BaseType = (SimpleType)type;
                    type        = at;
                }

                fieldDef.Argument = arguments.ToString();
            }

            fieldDef.Internal    = fieldSyntax;
            fieldDef.Name        = variable.Identifier.ValueText;
            fieldDef.Type        = type;
            fieldDef.AccessLevel = ParseAccessLevel(fieldSyntax.Modifiers) ?? AccessLevel.Private;
            fieldDef.IsStatic    = fieldSyntax.Modifiers.Any(x => x.ValueText == "static");

            // Summary
            var declaredSymbol = semanticModel.GetDeclaredSymbol(fieldSyntax);
            var xml            = declaredSymbol?.GetDocumentationCommentXml();

            fieldDef.Summary = SummaryComment.Parse(xml);

            return(fieldDef);
        }
コード例 #5
0
ファイル: Parser.cs プロジェクト: altseed/LanguageTranslator
        private EnumMemberDef ParseEnumMember(EnumMemberDeclarationSyntax syntax, SemanticModel semanticModel)
        {
            EnumMemberDef dst = new EnumMemberDef();

            // 名称
            dst.Name     = syntax.Identifier.ValueText;
            dst.Internal = syntax;

            // Summary
            var declaredSymbol = semanticModel.GetDeclaredSymbol(syntax);
            var xml            = declaredSymbol?.GetDocumentationCommentXml();

            dst.Summary = SummaryComment.Parse(xml);

            return(dst);
        }
コード例 #6
0
ファイル: Parser.cs プロジェクト: altseed/LanguageTranslator
        private void ParseClass(string namespace_, ClassDeclarationSyntax classSyntax, SemanticModel semanticModel)
        {
            var classDef = new ClassDef();

            // swig
            classDef.IsDefinedBySWIG = namespace_.Contains(swig_namespace_keyword);

            classDef.Namespace = namespace_;
            classDef.Name      = classSyntax.Identifier.ValueText;

            var fullName = namespace_ + "." + classDef.Name;

            if (TypesNotParsed.Contains(fullName))
            {
                return;
            }

            if (TypesNotExported.Contains(fullName))
            {
                classDef.IsExported = false;
            }

            var partial = definitions.Classes.FirstOrDefault(x => x.Namespace + "." + x.Name == fullName);

            if (partial != null)
            {
                classDef = partial;
            }

            if (classSyntax.Modifiers.Any(x => x.ValueText == "abstract"))
            {
                classDef.IsAbstract = true;
            }

            // Summary
            var declaredSymbol = semanticModel.GetDeclaredSymbol(classSyntax);
            var xml            = declaredSymbol?.GetDocumentationCommentXml();

            classDef.Summary = SummaryComment.Parse(xml);

            ParseTypeDeclaration(classDef, classSyntax, semanticModel);

            definitions.Classes.Add(classDef);
        }
コード例 #7
0
ファイル: Parser.cs プロジェクト: altseed/LanguageTranslator
        private void ParseInterface(string namespace_, InterfaceDeclarationSyntax interfaceSyntax, SemanticModel semanticModel)
        {
            var interfaceDef = new InterfaceDef();

            interfaceDef.Namespace = namespace_;
            interfaceDef.Name      = interfaceSyntax.Identifier.ValueText;

            var fullName = interfaceDef.Namespace + "." + interfaceDef.Name;

            if (TypesNotParsed.Contains(fullName))
            {
                return;
            }

            // Summary
            var declaredSymbol = semanticModel.GetDeclaredSymbol(interfaceSyntax);
            var xml            = declaredSymbol?.GetDocumentationCommentXml();

            interfaceDef.Summary = SummaryComment.Parse(xml);

            ParseTypeDeclaration(interfaceDef, interfaceSyntax, semanticModel);

            definitions.Interfaces.Add(interfaceDef);
        }
コード例 #8
0
        void ParseClass(Definition.ClassDef def)
        {
            if (def.IsDefinedBySWIG)
            {
                return;
            }
            if (def.IsDefinedDefault)
            {
                return;
            }

            foreach (var field in def.Fields)
            {
                var semanticModel = compilation.GetSemanticModel(field.Internal.SyntaxTree);

                var v = field.Internal.Declaration.Variables[0];
                if (v.Initializer != null && v.Initializer.Value != null)
                {
                    field.Initializer = ParseExpression(v.Initializer.Value, semanticModel);
                }
            }

            foreach (var prop in def.Properties)
            {
                var semanticModel = compilation.GetSemanticModel(prop.Internal.SyntaxTree);

                if (prop.Getter != null && prop.Getter.Internal.Body != null)
                {
                    prop.Getter.Body = ParseStatement(prop.Getter.Internal.Body, semanticModel);
                }

                if (prop.Setter != null)
                {
                    prop.Setter.Body = ParseStatement(prop.Setter.Internal.Body, semanticModel);
                }
            }

            foreach (var method in def.Methods)
            {
                var semanticModel = compilation.GetSemanticModel(method.Internal.SyntaxTree);

                if (method.Internal.Body == null)
                {
                    continue;
                }

                var statement = ParseStatement(method.Internal.Body, semanticModel) as BlockStatement;
                method.Body = statement.Statements.ToList();

                var declaredSymbol = semanticModel.GetDeclaredSymbol(method.Internal);
                var xml            = declaredSymbol?.GetDocumentationCommentXml();
                method.Summary = SummaryComment.Parse(xml);
            }

            foreach (var cst in def.Constructors)
            {
                if (cst.Internal == null)
                {
                    continue;
                }

                var semanticModel = compilation.GetSemanticModel(cst.Internal.SyntaxTree);

                if (cst.Internal.Body == null)
                {
                    continue;
                }

                if (cst.Initializer != null)
                {
                    foreach (var arg in cst.Initializer.Internal.ArgumentList.Arguments)
                    {
                        cst.Initializer.Arguments.Add(ParseExpression(arg.Expression, semanticModel));
                    }
                }

                var statement = ParseStatement(cst.Internal.Body, semanticModel) as BlockStatement;
                cst.Body = statement.Statements.ToList();
            }

            foreach (var dst in def.Destructors)
            {
                if (dst.Internal == null)
                {
                    continue;
                }

                var semanticModel = compilation.GetSemanticModel(dst.Internal.SyntaxTree);

                if (dst.Internal.Body == null)
                {
                    continue;
                }

                var statement = ParseStatement(dst.Internal.Body, semanticModel) as BlockStatement;
                dst.Body = statement.Statements.ToList();
            }
        }