Exemplo n.º 1
0
        //============================================================
        // <T>解析*.h文件,查找相应的类的信息。</T>
        //
        // @param fileH 要解析的*.h文件
        // @param classStr 需要匹配的类的类名信息
        // @return 返回匹配到的类的结果。若是没有则返回null
        //============================================================
        public FCppClass ParserFileH(string fileH, string classStr)
        {
            FLineFile lineFileH = new FLineFile(fileH);
            FStrings  lines     = lineFileH;

            for (int n = 0; n < lines.Count; n++)
            {
                if (FCppClass.IsClass(lines, n))
                {
                    string strTemp = lines[n].Trim();
                    int    end     = strTemp.Length;
                    if (strTemp.Contains(':'))
                    {
                        end = strTemp.IndexOf(':');
                    }
                    strTemp = strTemp.Substring(0, end);
                    if (strTemp.Contains(classStr))
                    {
                        int       endIndex = GetPairNum(lines, n);
                        FCppClass cppclass = new FCppClass(lines, n, endIndex);
                        for (int i = n; i < endIndex; i++)
                        {
                            if (FCppField.IsField(lines, i))
                            {
                                FCppField field = new FCppField(lines, i);
                                cppclass.Field.Add(field);
                            }
                        }
                        return(cppclass);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        //============================================================
        // <T>解析H文件中的模板类。</T>
        //============================================================
        public void ParserTemplate(string filePath)
        {
            FStrings strLines = FCppParser.GetLines(filePath);

            for (int n = 0; n < strLines.Count; n++)
            {
                if (FCppClass.IsTemplateClass(strLines, n))
                {
                }
            }
        }
Exemplo n.º 3
0
 //============================================================
 // <T> 取得在FArray<FCppClass>中class的索引号。</T>
 //
 // @param cppClasses 被查找的Array
 // @param cppClass 需要查找的Node
 // @return 若是存在则返回索引号,否则返回-1;
 //============================================================
 public int ExistNo(FArray <FCppClass> cppClasses, FCppClass cppClass)
 {
     for (int n = 0; n < cppClasses.Length; n++)
     {
         if (cppClasses[n].ClassName == cppClass.ClassName)
         {
             return(n);
         }
     }
     return(-1);
 }
Exemplo n.º 4
0
        //============================================================
        // <T>将被选择的文件解析为类对象数组,并解析出代码在编译器外的警告或者错误。</T>
        //
        // @param indextable 从.h文件中解析出来的类与头文件对应的MAP表
        // @param putPath XML文档的输出路径
        // @param swPrint StringWriter对象用来输出警告或者错误。
        // @param fileCpp 当前解析的文件
        // @param relativePath 被选择解析的文件夹路径
        //============================================================
        public void ParserFileCpp(FileInfo fileCpp, FCppClassesIndexTable indextable, string outPath, string relativePath, StreamWriter swPrint)
        {
            FStrings           strLines = FCppParser.GetLines(fileCpp.FullName);
            string             strClass = string.Empty;
            FArray <FCppClass> classArr = new FArray <FCppClass>();
            int start, end = CheckParaAnnotate(strLines, 0, out start);

            for (int n = 0; n < strLines.Count; n++)
            {
                if (IsInInterregional(n, start, end))
                {
                    continue;
                }
                if (FCppMethod.IsMethodInCpp(strLines, n))
                {
                    FCppMethod method   = new FCppMethod(strLines, n, GetPairNum(strLines, n));
                    string     classStr = GetClassInCpp(strLines, n);
                    strClass = classStr;
                    FFileNode node      = MakeNode(strLines, GetClassInCpp(strLines, n));
                    string    fileHpath = indextable.LookInMap(node);
                    if (fileHpath == "")
                    {
                        continue;
                    }
                    FCppClass cppClass = ParserFileH(fileHpath, classStr);
                    int       index    = ExistNo(classArr, cppClass);
                    if (index != -1)
                    {
                        classArr.Get(index).Method.Add(method);
                    }
                    else
                    {
                        cppClass.Method.Add(method);
                        classArr.Add(cppClass);
                    }
                }
            }
            ProduceXMLFile(classArr, outPath, swPrint, fileCpp, relativePath);
            if (strLines[strLines.Count - 1].Trim() != "")
            {
                string errID = "CPP07CL06E" + strLines.Count.ToString() + "L";
                string path  = fileCpp.FullName.Substring(relativePath.Length);
                string error = "[错误][" + errID.PadRight(16) + "][" + path + "(" + strLines.Count.ToString().PadRight(5) + ")]";
                swPrint.WriteLine(error);
            }
        }
Exemplo n.º 5
0
        //============================================================
        // <T>解析单个文件</T>
        //
        // @param 需要解析的单个文件
        //============================================================
        public void ParserSingleFile(FileInfo file)
        {
            FStrings strLines = FCppParser.GetLines(file.FullName);
            int      start, end = CheckParaAnnotate(strLines, 0, out start);

            for (int n = 0; n < strLines.Count; n++)
            {
                if (IsInInterregional(n, start, end))
                {
                    continue;
                }
                if (FCppClass.IsClass(strLines, n))
                {
                    string   classStr = GetClassString(strLines[n]);
                    FMapNode node     = new FMapNode(classStr, file.Name);
                    AddNode(node, file.FullName);
                    n = GetPairNum(strLines, n);
                }
            }
        }
Exemplo n.º 6
0
        //============================================================
        // <T>获取类对象的代码段。</T>
        //
        // @param cppClass 类对象
        // @return 返回类对象的字符串
        //============================================================
        public string GetClassCode(FCppClass cppClass)
        {
            string code = string.Empty;

            if (cppClass == null)
            {
                return(code);
            }
            for (int n = cppClass._beginIndex; n <= cppClass._endInde; n++)
            {
                code += cppClass._strLines[n].TrimEnd() + "\r\n";
            }
            if (cppClass.Method == null || cppClass.Method.Length == 0)
            {
                return(code);
            }
            code += cppClass.ClassName + ".CPP\r\n";
            for (int n = 0; n < cppClass.Method.Length; n++)
            {
                code += cppClass.Method[n].MethodCode + "\r\n";
            }
            return(code);
        }