示例#1
0
        public void Parse(ref string aText, SrcMethod aMethod)
        {
            /*
             * TPtrC16::TPtrC16(const unsigned short*)
             * TPtrC16::TPtrC16(const TDesC16&)
             * UserHal::MemoryInfo(TDes8&)
             * RHandleBase::Close()
             * TBufCBase16::Copy(const TDesC16&, int)
             * CBufFlat::NewL(int)
             * TBufCBase16::TBufCBase16()
             * CServer2::RunL()
             * CServer2::StartL(const TDesC16&)
             * CServer2::DoCancel()
             * CServer2::RunError(int)
             * CServer2::DoConnect(const RMessage2&)
             * CServer2::CServer2__sub_object(int, CServer2::TServerType)
             */
            string paramType = string.Empty;

            while (aText.Length > 0)
            {
                int commaPos = aText.IndexOf(",");
                //
                paramType = aText;
                if (commaPos > 0)
                {
                    paramType = aText.Substring(0, commaPos).Trim();
                    if (commaPos < aText.Length)
                    {
                        aText = aText.Substring(commaPos + 1).Trim();
                    }
                    else
                    {
                        aText = string.Empty;
                    }
                }
                else
                {
                    // Everything was consumed
                    aText = string.Empty;
                }

                // Should have the parameter same now. Make a new parameter
                SrcMethodParameter parameter = new SrcMethodParameter();
                parameter.Name = paramType;
                aMethod.AddParameter(parameter);
            }
        }
示例#2
0
        public SrcMethod Parse(string aText)
        {
            ParserSrcMethod methodParser = new ParserSrcMethod();
            SrcMethod       method       = methodParser.Parse(ref aText);

            // And then parse what's left as the class
            if (method != null)
            {
                ParserSrcClass classParser = new ParserSrcClass();
                SrcClass       classObject = classParser.Parse(ref aText);
                //
                classObject.AddMethod(method);
            }

            return(method);
        }
示例#3
0
        ////////////////////////////////////////////////////////////////
        // Methods
        ////////////////////////////////////////////////////////////////

        /// <summary>
        /// Create the source code that is to be compiled.
        /// </summary>
        /// <param name="targetNameSpaceName"></param>
        /// <param name="targetClassName"></param>
        /// <returns></returns>
        public SourceCodeData CreateSourceContent(string filePath, object scriptObject, string targetNameSpaceName, string targetClassName)
        {
            SourceCodeData sourceCodeData = new SourceCodeData();

            sourceCodeData.Append("using System;");
            sourceCodeData.Append("using System.Text.RegularExpressions;");
            sourceCodeData.Append("using System.IO;");
            sourceCodeData.Append("using System.Collections.Generic;");
            sourceCodeData.Append("using System.Linq;");
            sourceCodeData.Append("using System.Text;");
            sourceCodeData.Append("namespace " + targetNameSpaceName + " {");
            sourceCodeData.Append("public class " + targetClassName + " {");
            sourceCodeData.Append("public " + targetClassName + "() {}");

            SourceFile sourceFile = (SourceFile)scriptObject;
            SrcMethod  method     = new SrcMethod("string", "Test", new SrcVariable("int", "something"), sourceFile.Text);

            method.WriteTo(sourceCodeData, "bla", -1);

            sourceCodeData.Append("}");
            sourceCodeData.Append("}");
            return(sourceCodeData);
        }
示例#4
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);
        }