コード例 #1
0
 public TypeDeclaration(TypeTypeLiteral type, IdToken name, IEnumerable <Ust> typeMembers,
                        TextSpan textSpan) : base(name, textSpan)
 {
     Type        = type;
     BaseTypes   = new List <TypeToken>();
     TypeMembers = typeMembers as List <Ust> ?? typeMembers.ToList();
 }
コード例 #2
0
        public Ust VisitClassDeclaration(JavaParser.ClassDeclarationContext context)
        {
            var typeTypeToken = new TypeTypeLiteral(TypeType.Class,
                                                    context.GetChild <ITerminalNode>(0).Symbol.GetTextSpan());

            var id = (IdToken)Visit(context.IDENTIFIER());

            EntityDeclaration[] typeMembers = context.classBody().classBodyDeclaration()
                                              .Select(dec => Visit(dec) as EntityDeclaration)
                                              .Where(dec => dec != null).ToArray();

            var baseTypes = new List <TypeToken>();

            if (context.typeType() != null)
            {
                baseTypes.Add((TypeToken)Visit(context.typeType()));
            }
            if (context.typeList() != null)
            {
                baseTypes.AddRange(context.typeList().typeType().Select(t => (TypeToken)Visit(t)));
            }

            var result = new TypeDeclaration(typeTypeToken, id, baseTypes, typeMembers, context.GetTextSpan());

            return(result);
        }
コード例 #3
0
 public TypeDeclaration(TypeTypeLiteral type, IdToken name, IEnumerable <EntityDeclaration> typeMembers, TextSpan textSpan, FileNode fileNode)
     : base(name, textSpan, fileNode)
 {
     Type        = type;
     BaseTypes   = new List <StringLiteral>();
     TypeMembers = typeMembers as List <EntityDeclaration> ?? typeMembers.ToList();
 }
コード例 #4
0
        protected Ust ConvertBaseTypeDeclaration(
            BaseTypeDeclarationSyntax node,
            TypeTypeLiteral typeTypeToken,
            IEnumerable <EntityDeclaration> typeMembers)
        {
            var nameLiteral = ConvertId(node.Identifier);
            var modifiers   = node.Modifiers.Select(ConvertModifier).ToList();
            var baseTypes   = node.BaseList?.Types.Select(t =>
            {
                var name = t.Type is IdentifierNameSyntax id ? id.Identifier.ValueText : t.ToString();
                return(new TypeToken(name, t.GetTextSpan()));
            }).ToList() ?? new List <TypeToken>();

            var result = new TypeDeclaration(
                typeTypeToken,
                nameLiteral,
                baseTypes,
                typeMembers,
                node.GetTextSpan())
            {
                Modifiers = modifiers,
            };

            return(result);
        }
コード例 #5
0
ファイル: TypeDeclaration.cs プロジェクト: smartfish/PT.PM
 public TypeDeclaration(TypeTypeLiteral type, IdToken name, List <TypeToken> baseTypes,
                        IEnumerable <EntityDeclaration> typeMembers, TextSpan textSpan)
     : base(name, textSpan)
 {
     Type        = type;
     BaseTypes   = baseTypes;
     TypeMembers = typeMembers as List <EntityDeclaration> ?? typeMembers.ToList();
 }
コード例 #6
0
        public override UstNode VisitDelegateDeclaration(DelegateDeclarationSyntax node)
        {
            var typeType      = ConvertTypeType(TypeType.Delegate);
            var typeTypeToken = new TypeTypeLiteral(typeType, node.DelegateKeyword.GetTextSpan(), FileNode);
            var result        = new TypeDeclaration(typeTypeToken, ConvertId(node.Identifier), new EntityDeclaration[0],
                                                    node.GetTextSpan(), FileNode);

            return(result);
        }
コード例 #7
0
        public override UstNode VisitEnumDeclaration(EnumDeclarationSyntax node)
        {
            var type          = ConvertTypeType(TypeType.Enum);
            var typeTypeToken = new TypeTypeLiteral(type, node.EnumKeyword.GetTextSpan(), FileNode);
            var members       = node.Members.Select(m => (FieldDeclaration)VisitAndReturnNullIfError(m))
                                .ToArray();

            var result = ConvertBaseTypeDeclaration(node, typeTypeToken, members);

            return(result);
        }
コード例 #8
0
        public UstNode VisitClassDeclaration(JavaParser.ClassDeclarationContext context)
        {
            var typeTypeToken = new TypeTypeLiteral(TypeType.Class,
                                                    context.GetChild <ITerminalNode>(0).Symbol.GetTextSpan(), FileNode);

            var id = (IdToken)Visit(context.IDENTIFIER());

            EntityDeclaration[] typeMembers = context.classBody().classBodyDeclaration()
                                              .Select(dec => Visit(dec) as EntityDeclaration)
                                              .Where(dec => dec != null).ToArray();

            var result = new TypeDeclaration(typeTypeToken, id, typeMembers, context.GetTextSpan(), FileNode);

            return(result);
        }
コード例 #9
0
        protected UstNode ConvertBaseTypeDeclaration(
            BaseTypeDeclarationSyntax node,
            TypeTypeLiteral typeTypeToken,
            IEnumerable <EntityDeclaration> typeMembers)
        {
            var nameLiteral = ConvertId(node.Identifier);
            var modifiers   = node.Modifiers.Select(ConvertModifier).ToList();

            var result = new TypeDeclaration(
                typeTypeToken,
                nameLiteral,
                typeMembers,
                node.GetTextSpan(),
                FileNode)
            {
                Modifiers = modifiers
            };

            return(result);
        }
コード例 #10
0
ファイル: UstVisitor.cs プロジェクト: smartfish/PT.PM
 public virtual T Visit(TypeTypeLiteral typeTypeLiteral)
 {
     return(VisitChildren(typeTypeLiteral));
 }
コード例 #11
0
        /// <summary>
        /// TODO: Split method.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        protected UstNode ConvertTypeDeclaration(TypeDeclarationSyntax node)
        {
            TypeType type;

            Enum.TryParse(node.Keyword.ValueText, true, out type);
            type = ConvertTypeType(type);
            var typeTypeToken = new TypeTypeLiteral(type, node.Keyword.GetTextSpan(), FileNode);

            var typeMembers = new List <EntityDeclaration>();

            foreach (var member in node.Members)
            {
                PropertyDeclarationSyntax           propertySyntax;
                OperatorDeclarationSyntax           operatorSyntax;
                IndexerDeclarationSyntax            indexerSyntax;
                EventDeclarationSyntax              eventSyntax;
                ConversionOperatorDeclarationSyntax conversionOperatorSyntax;

                if ((indexerSyntax = member as IndexerDeclarationSyntax) != null)
                {
                    var name       = "Indexer";
                    var parameters =
                        indexerSyntax.ParameterList.Parameters.Select(p => (ParameterDeclaration)VisitAndReturnNullIfError(p))
                        .ToArray();

                    if (indexerSyntax.AccessorList == null)
                    {
                        typeMembers.Add(ConvertToExpressionBodyMethod(indexerSyntax.ExpressionBody,
                                                                      new IdToken(name, default(TextSpan), FileNode), indexerSyntax.GetTextSpan()));
                    }
                    else
                    {
                        foreach (var accessor in indexerSyntax.AccessorList.Accessors)
                        {
                            var method = ConvertAccessorToMethodDef(name, accessor, parameters);
                            typeMembers.Add(method);
                        }
                    }
                }
                else if ((eventSyntax = member as EventDeclarationSyntax) != null)
                {
                    if (eventSyntax.AccessorList == null)
                    {
                        typeMembers.Add(ConvertToExpressionBodyMethod(indexerSyntax.ExpressionBody,
                                                                      ConvertId(eventSyntax.Identifier), eventSyntax.GetTextSpan()));
                    }
                    else
                    {
                        var name = eventSyntax.Identifier.ValueText;
                        foreach (var accessor in eventSyntax.AccessorList.Accessors)
                        {
                            var method = ConvertAccessorToMethodDef(name, accessor);
                            typeMembers.Add(method);
                        }
                    }
                }
                else if ((operatorSyntax = member as OperatorDeclarationSyntax) != null)
                {
                    var id         = ConvertId(operatorSyntax.OperatorToken);
                    var parameters =
                        operatorSyntax.ParameterList.Parameters.Select(p => (ParameterDeclaration)VisitAndReturnNullIfError(p))
                    ;

                    BlockStatement body;
                    if (operatorSyntax.Body != null)
                    {
                        body = (BlockStatement)VisitBlock(operatorSyntax.Body);
                    }
                    else
                    {
                        var expressionBody = (Expression)VisitArrowExpressionClause(operatorSyntax.ExpressionBody);
                        body = new BlockStatement(new Statement[] {
                            new ExpressionStatement(expressionBody, expressionBody.TextSpan, FileNode)
                        },
                                                  expressionBody.TextSpan, FileNode);
                    }

                    var method = new MethodDeclaration(id, parameters, body, operatorSyntax.GetTextSpan(), FileNode)
                    {
                        Modifiers = operatorSyntax.Modifiers.Select(ConvertModifier).ToList()
                    };
                    typeMembers.Add(method);
                }
                else if ((conversionOperatorSyntax = member as ConversionOperatorDeclarationSyntax) != null)
                {
                    IdToken id;
                    if (conversionOperatorSyntax.Type is IdentifierNameSyntax)
                    {
                        id = (IdToken)VisitIdentifierName((IdentifierNameSyntax)conversionOperatorSyntax.Type);
                    }
                    else
                    {
                        var typeToken = (TypeToken)base.Visit(conversionOperatorSyntax.Type);
                        id = new IdToken("To" + typeToken.TypeText, typeToken.TextSpan, FileNode);
                    }

                    BlockStatement body;
                    if (conversionOperatorSyntax.Body != null)
                    {
                        body = (BlockStatement)VisitBlock(conversionOperatorSyntax.Body);
                    }
                    else
                    {
                        var expressionBody = (Expression)VisitArrowExpressionClause(conversionOperatorSyntax.ExpressionBody);
                        body = new BlockStatement(new Statement[] {
                            new ExpressionStatement(expressionBody, expressionBody.TextSpan, FileNode)
                        },
                                                  expressionBody.TextSpan, FileNode);
                    }

                    var parameters =
                        conversionOperatorSyntax.ParameterList.Parameters.Select(p => (ParameterDeclaration)VisitAndReturnNullIfError(p))
                        .ToArray();

                    var method = new MethodDeclaration(id, parameters, body, conversionOperatorSyntax.GetTextSpan(), FileNode)
                    {
                        Modifiers = conversionOperatorSyntax.Modifiers.Select(ConvertModifier).ToList()
                    };
                    typeMembers.Add(method);
                }
                else if ((propertySyntax = member as PropertyDeclarationSyntax) != null)
                {
                    if (propertySyntax.AccessorList == null)
                    {
                        IdToken id = ConvertId(propertySyntax.Identifier);
                        typeMembers.Add(ConvertToExpressionBodyMethod(propertySyntax.ExpressionBody, id, propertySyntax.GetTextSpan()));
                    }
                    else
                    {
                        var name = propertySyntax.Identifier.ValueText;
                        foreach (var accessor in propertySyntax.AccessorList.Accessors)
                        {
                            var method = ConvertAccessorToMethodDef(name, accessor);
                            typeMembers.Add(method);
                        }
                    }
                }
                else
                {
                    var entity = (EntityDeclaration)base.Visit(member);
                    typeMembers.Add(entity);
                }
            }

            var result = ConvertBaseTypeDeclaration(node, typeTypeToken, typeMembers);

            return(result);
        }
コード例 #12
0
 public virtual UstNode Visit(TypeTypeLiteral typeTypeToken)
 {
     return(VisitChildren(typeTypeToken));
 }
コード例 #13
0
ファイル: UstListener.cs プロジェクト: Yikez978/PT.PM
 public virtual void Exit(TypeTypeLiteral typeTypeToken)
 {
 }
コード例 #14
0
ファイル: UstListener.cs プロジェクト: Yikez978/PT.PM
 public virtual void Enter(TypeTypeLiteral typeTypeToken)
 {
 }