コード例 #1
0
        public SrcMethodModifier Parse(ref string aText)
        {
            SrcMethodModifier ret = null;

            // Should not be the first or second character as
            // we should always have an opening bracket before
            // the closing bracket, and the shortest possible
            // valid sequence is "(<char>)" where <char> is a
            // single character (type).
            //
            // Needs to also handle tricky things like...:
            //
            // RDbHandle::operator ->() const

            int closingBracketPos = aText.LastIndexOf(")");

            System.Diagnostics.Debug.Assert(closingBracketPos >= 1);

            // Get the modifier text. We currently only support
            // one modifier and that's the const keyword
            string modifierText = aText.Substring(closingBracketPos + 1).Trim();

            if (modifierText.Length > 0)
            {
                ret = new SrcMethodModifier();

                if (modifierText.ToLower() == "const")
                {
                    ret.Type = SrcMethodModifier.TModifier.EConst;
                }
            }

            // Clean up the text object we were passed...
            aText = aText.Substring(0, closingBracketPos + 1);

            return(ret);
        }
コード例 #2
0
        public SrcMethod Parse(ref string aText)
        {
            SrcMethod ret = null;

            //
            if (aText.Length > 0)
            {
                string parameters = string.Empty;
                //
                if (ContainsParameters(aText))
                {
                    // This leaves modifiers intact
                    parameters = ExtractParameters(ref aText);
                }

                // Look for the class separator. If we find that, then everything after
                // it is the method name.
                //
                // If no class separator exists, then we treat the whole thing as the method
                // name.
                int pos = aText.IndexOf(SrcClass.KClassSeparator);

                // By default, treat the whole text as the class name
                string methodText = aText;
                if (pos >= 0)
                {
                    methodText = aText.Substring(pos + SrcClass.KClassSeparator.Length);
                    aText      = aText.Substring(0, pos + SrcClass.KClassSeparator.Length);
                }
                else
                {
                    // Everything was consumed...
                    aText = string.Empty;
                }

                // Make a new method. Work out if the method text
                // actually has any parameters
                ret = new SrcMethod();

                // Try to parse the modifiers. We extract that first
                // to leave us with just the method name and the parameters.
                bool hasModifier = ContainsModifier(methodText);
                if (hasModifier)
                {
                    ParserSrcMethodModifier parser   = new ParserSrcMethodModifier();
                    SrcMethodModifier       modifier = parser.Parse(ref methodText);
                    if (modifier != null)
                    {
                        ret.Modifier = modifier;
                    }
                }

                // Try to parse the parameters. We can also use this
                // to calculate the exact method name.
                if (parameters.Length > 0)
                {
                    ParserSrcMethodParameter parser = new ParserSrcMethodParameter();
                    parser.Parse(ref parameters, ret);
                }

                // What's left should be the method name followed by "()" if the
                // 'method' wasn't a label.
                if (ContainsParameters(methodText))
                {
                    // Discard "()";
                    pos        = methodText.LastIndexOf("(");
                    methodText = methodText.Substring(0, pos);
                }

                ret.Name = methodText;
            }
            //
            return(ret);
        }