public override object VisitMethod_declaration([NotNull] Method_declarationContext context)
        {
            var identifiers = context.method_member_name().identifier();

            base.VisitMethod_declaration(context);
            return(new List <IdentifierContext>(new IdentifierContext[] { identifiers[identifiers.Length - 1] }));
        }
示例#2
0
        public void Enter_MethodDeclaration(Method_declarationContext context)
        {
            _currentMethodName = context.method_member_name().GetText();

            var ruleAttr = ValidationRuleProvider <MethodNameValidationAttribute>(nameof(Enter_MethodDeclaration)) as MethodNameValidationAttribute;

            if (ruleAttr != null)
            {
                var nameRuleError = ruleAttr.Validate(_currentNamespace, _currentClassName, _currentMethodName, string.Empty, string.Empty);
                if (nameRuleError != null)
                {
                    _nameRuleErrorsList.Add(nameRuleError);
                }
            }


            var maxLenAttr = ValidationRuleProvider <MaxLengthValidationAttribute>(nameof(Enter_MethodDeclaration)) as MaxLengthValidationAttribute;

            if (maxLenAttr != null)
            {
                var nameRuleError = maxLenAttr.Validate(_currentNamespace, _currentClassName, _currentMethodName, string.Empty, string.Empty);
                if (nameRuleError != null)
                {
                    _nameRuleErrorsList.Add(nameRuleError);
                }
            }

            var    paramses   = context.formal_parameter_list();
            string parameters = HandleMethodParameters(paramses);

            ExtractInterfaceMethodSignature(context, parameters);
        }
        private List <IdentifierContext> SetTypeForFunction(Method_declarationContext context, IType type)
        {
            var identifierContext = (IdentifierContext)Visit(context.method_member_name());
            var symbol            = identifierContext.Symbol as FunctionSymbol;

            symbol.SetType(type);
            return(new List <IdentifierContext>(new IdentifierContext[] { identifierContext }));
        }
        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);
                    }
                }
            }
        }
        /// <summary>
        /// Define function symbol and scope
        /// </summary>
        /// <param name="context"></param>
        public override void EnterMethod_declaration([NotNull] Method_declarationContext context)
        {
            var identityContextList    = context.method_member_name().identifier();
            var lastestIdentityContext = identityContextList[identityContextList.Length - 1]; //is name of method

            MethodSymbol methodSymbol = new MethodSymbol(lastestIdentityContext.GetText())
            {
                DefNode = lastestIdentityContext
            };

            methodSymbol.SetEnclosingScope(currentScope);

            lastestIdentityContext.Symbol = methodSymbol;
            lastestIdentityContext.Scope  = methodSymbol;

            Define(methodSymbol);
            currentScope = methodSymbol;
        }
        public void CheckLoop(ParserRuleContext context, out ErrorInformation error)
        {
            error = null;
            List <Unary_expressionContext> unaryExpressionContext = ((Method_declarationContext)context).GetDeepChildContext <Unary_expressionContext>();
            Method_declarationContext      methodContext          = ((Method_declarationContext)context);
            string methodName = methodContext.method_member_name().identifier()[0].GetText();

            foreach (Unary_expressionContext contxt in unaryExpressionContext)
            {
                if (IsMethod(contxt) && !HasCheckMethod(methodContext))
                {
                    if (IsSameName(contxt, methodName))
                    {
                        error = new ErrorInformation()
                        {
                            ErrorCode    = "WA0005",
                            ErrorMessage = "UIT: Recursive function should have conditional statement to stop recursive",
                            StartIndex   = contxt.Start.StartIndex,
                            Length       = contxt.Stop.StopIndex - contxt.Start.StartIndex + 1
                        };
                    }
                }
            }
        }