예제 #1
0
        private void ParseClassDeclaration(Class_definitionContext node)
        {
            var members = node.class_body().class_member_declarations().class_member_declaration();

            foreach (var member in members)
            {
                Common_member_declarationContext child = member.GetRuleContext <Common_member_declarationContext>(0);

                if (child is Common_member_declarationContext)
                {
                    Common_member_declarationContext commonMemberContext = child as Common_member_declarationContext;

                    Event_declarationContext        eventContext      = commonMemberContext.event_declaration();
                    Typed_member_declarationContext typeMemberContext = commonMemberContext.typed_member_declaration();
                    Method_declarationContext       methodContext     = commonMemberContext.method_declaration();

                    string type = "";
                    string name = "";

                    if (eventContext != null)
                    {
                        type = "Event";
                        name = eventContext.variable_declarators().GetText();
                    }

                    if (typeMemberContext != null)
                    {
                        Field_declarationContext    field    = typeMemberContext.field_declaration();
                        Property_declarationContext property = typeMemberContext.property_declaration();

                        if (field != null)
                        {
                            type = "Field";
                            name = field.variable_declarators().GetText();
                        }
                        else if (property != null)
                        {
                            type = "Property";
                            name = property.member_name().GetText();
                        }
                    }
                    else if (methodContext != null)
                    {
                        type = "Method";
                        name = methodContext.method_member_name().GetText();
                    }

                    if (!string.IsNullOrEmpty(name))
                    {
                        this.WriteKeyValue(type, name);
                    }
                }
            }
        }
        public override void EnterField_declaration([NotNull] Field_declarationContext context)
        {
            var variableDeclaraContextList = context.variable_declarators().variable_declarator();

            //same as : int a, b = 10
            foreach (var variableDec in variableDeclaraContextList)
            {
                var         identityContext = variableDec.identifier();
                FieldSymbol fieldSymbol     = new FieldSymbol(identityContext.GetText())
                {
                    DefNode = identityContext
                };

                identityContext.Symbol = fieldSymbol;
                identityContext.Scope  = currentScope;

                Define(fieldSymbol);
            }
        }