public override void EnterMethod([NotNull] XSharpParser.MethodContext context)
        {
            Kind kind = Kind.Method;

            if (context.Name.Contains(":Access"))
            {
                kind = Kind.Access;
            }
            else if (context.Name.Contains(":Assign"))
            {
                kind = Kind.Assign;
            }
            //
            var         tokens    = context.Modifiers?._Tokens;
            XTypeMember newMethod = new XTypeMember(context.Id.GetText(),
                                                    kind,
                                                    decodeModifiers(tokens),
                                                    decodeVisibility(tokens),
                                                    new TextRange(context), new TextInterval(context),
                                                    (context.Type == null) ? "Void" : context.Type.GetText(),
                                                    isStatic(tokens));

            //
            addParameters(context.Params, newMethod);
            addMember(newMethod);
        }
Example #2
0
            public override void EnterMethod([NotNull] XSharpParser.MethodContext context)
            {
                if (context?.Sig == null)
                {
                    return;
                }

                AddMethodInfo(GetMethodName(context.Sig), GetClassName(context), MethodInfoType.Method, context.statementBlock());
            }
Example #3
0
 public override void ExitMethod([NotNull] XSharpParser.MethodContext context)
 {
     // Reset
     initComponent = null;
     _locals.Clear();
 }
Example #4
0
        public override void EnterMethod([NotNull] XSharpParser.MethodContext context)
        {
            _locals.Clear();
            var newMethod = new XCodeMemberMethod();

            writeTrivia(newMethod, context);
            newMethod.Name       = context.Sig.Id.GetCleanText();
            newMethod.Attributes = MemberAttributes.Public;
            newMethod.Parameters.AddRange(GetParametersList(context.Sig.ParamList));
            FillCodeDomDesignerData(newMethod, context.Start.Line, context.Start.Column);
            var returnType = BuildDataType(context.Sig.Type);

            newMethod.ReturnType = returnType;
            //
            if (context.Modifiers != null)
            {
                // Get standard Visibilities
                newMethod.Attributes = ContextToMethodModifiers(context.Modifiers);
                // Is it a NEW method ?
                if (context.Modifiers.NEW().Length > 0)
                {
                    newMethod.Attributes |= MemberAttributes.New;
                }
                if (context.Modifiers.STATIC().Length > 0)
                {
                    newMethod.Attributes |= MemberAttributes.Static;
                }
                if (context.Modifiers.VIRTUAL().Length > 0)
                {
                    // According to MSDN, The absence of the Final flag makes a member virtual in C#, same for us
                    newMethod.Attributes &= ~MemberAttributes.Final;
                }
                else
                {
                    // Other cases = FINAL
                    newMethod.Attributes |= MemberAttributes.Final;
                }
            }
            // !!! WARNING !!!
            // If the method is InitializeComponent, we will have to find all CodeObjects, as the designer is using them
            // Else, we can just copy the whole code in USERDATA, that will be fine
            if (newMethod.Name == "InitializeComponent")
            {
                initComponent = newMethod;
                if (context.Attributes != null)
                {
                    newMethod.CustomAttributes = GenerateAttributes(context.Attributes);
                }
            }
            else
            {
                if (context.StmtBlk != null)
                {
                    // Copy all source code to User_Data
                    // --> See XSharpCodeGenerator.GenerateMethod for writing
                    FillCodeSource(newMethod, context, _tokens);

                    // The designer will need to locate the code in the file, so we must add the location
                    if (context.StmtBlk.ChildCount > 0)
                    {
                        FillCodeDomDesignerData(newMethod, context.StmtBlk.Start.Line, context.StmtBlk.Start.Column);
                    }
                    else
                    {
                        FillCodeDomDesignerData(newMethod, context.Start.Line + 1, context.Start.Column);
                    }
                }
            }
            //
            this.CurrentClass.Members.Add(newMethod);
            this.addClassMember(new XMemberType(newMethod.Name, MemberTypes.Method, false, returnType.BaseType));
        }
        public override void ExitMethod([NotNull] XSharpParser.MethodContext context)
        {
            var t = context.T.Token as XSharpToken;

            var isInInterface = context.isInInterface();
            var isExtern      = context.Modifiers?.EXTERN().Length > 0;
            var isAbstract    = context.Modifiers?.ABSTRACT().Length > 0;
            var hasbody       = context.StmtBlk != null && context.StmtBlk._Stmts.Count > 0;

            if (context.T2 != null)
            {
                var endToken = context.T2.Token as XSharpToken;
                if (endToken != null && endToken.Type != t.Type)
                {
                    _parseErrors.Add(new ParseErrorData(endToken, ErrorCode.ERR_SyntaxError, t.Text));
                }
            }
            if (isInInterface && hasbody)
            {
                _parseErrors.Add(new ParseErrorData(context.Sig.Id, ErrorCode.ERR_InterfaceMemberHasBody));
            }
            if (isInInterface && context.ClassId != null)
            {
                _parseErrors.Add(new ParseErrorData(context.ClassId, ErrorCode.ERR_InterfacesCannotContainTypes));
            }
            if (isInInterface && _options.VoInitAxitMethods)
            {
                var name = context.Sig.Id.GetText().ToLower();
                if (name == "init" || name == "axit")
                {
                    _parseErrors.Add(new ParseErrorData(context.Start, ErrorCode.ERR_InterfacesCantContainConstructors));
                }
            }

            if (isAbstract)
            {
                if (isExtern)
                {
                    _parseErrors.Add(new ParseErrorData(context.Modifiers, ErrorCode.ERR_AbstractAndExtern, "Method"));
                }
                if (hasbody)
                {
                    _parseErrors.Add(new ParseErrorData(context.StmtBlk, ErrorCode.ERR_AbstractHasBody, "Method"));
                }
            }
            else if (isExtern)
            {
                if (hasbody)
                {
                    _parseErrors.Add(new ParseErrorData(context.StmtBlk, ErrorCode.ERR_ExternHasBody, "Method"));
                }
            }
            if (context.T.Token.Type == XSharpParser.ASSIGN || context.T.Token.Type == XSharpParser.ACCESS)
            {
                // no type parameters on access and assign
                if (context.Sig != null && (context.Sig.TypeParameters != null || context.Sig._ConstraintsClauses?.Count > 0))
                {
                    context.AddError(new ParseErrorData(context, ErrorCode.Err_TypeParametersAccessAssign));
                }
            }
        }
 public override void ExitMethod([NotNull] XSharpParser.MethodContext context)
 {
     endMember(context);
 }