]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Enhancing Critic
authoralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 16 Aug 2006 12:09:16 +0000 (12:09 +0000)
committeralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 16 Aug 2006 12:09:16 +0000 (12:09 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1296 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/MigrationTools/org/tianocore/migration/Common.java
Tools/Source/MigrationTools/org/tianocore/migration/Critic.java

index 83b4e869b6e54b1aeb9e684305575244ce36abcb..3468a43cebb3c26fffcd260ddbae8834f8ec99ed 100644 (file)
@@ -1,3 +1,15 @@
+/** @file\r
\r
+ Copyright (c) 2006, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
+ **/\r
 package org.tianocore.migration;\r
 \r
 import java.io.*;\r
@@ -5,6 +17,8 @@ import java.util.regex.*;
 import java.util.*;\r
 \r
 public class Common {\r
+       public static Pattern ptnseparate = Pattern.compile("(.*)\\\\([^\\\\]*)");\r
+       \r
        public static String file2string(String filename) throws Exception {\r
                BufferedReader rd = new BufferedReader(new FileReader(filename));\r
                StringBuffer wholefile = new StringBuffer();\r
@@ -16,11 +30,8 @@ public class Common {
        }\r
 \r
        public static void ensureDir(String objFileWhole) {\r
-               Pattern ptnseparate = Pattern.compile("(.*)\\\\[^\\\\]*");\r
-               Matcher mtrseparate;\r
                File tempdir;\r
-\r
-               mtrseparate = ptnseparate.matcher(objFileWhole);\r
+               Matcher mtrseparate = ptnseparate.matcher(objFileWhole);\r
                if (mtrseparate.find()) {\r
                        tempdir = new File(mtrseparate.group(1));\r
                        if (!tempdir.exists()) tempdir.mkdirs();\r
@@ -51,6 +62,29 @@ public class Common {
                \r
                return filelist;\r
        }\r
+\r
+       public static String dirCopy_(String src) throws Exception {\r
+               Matcher mtrseparate = Common.ptnseparate.matcher(src);\r
+               if (mtrseparate.find()) {\r
+                       dirCopy(src, mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2));\r
+               }\r
+               return mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2);\r
+       }\r
+       \r
+       public static void dirCopy(String src, String des) throws Exception {\r
+               String[] list = new File(src).list();\r
+               File test;\r
+\r
+               for (int i = 0 ; i < list.length ; i++) {\r
+                       test = new File(src + File.separator + list[i]);\r
+                       if (test.isDirectory()) {\r
+                               dirCopy(src + File.separator + list[i], des + File.separator + list[i]);\r
+                       } else {\r
+                               ensureDir(des + File.separator + list[i]);\r
+                               string2file(file2string(src + File.separator + list[i]), des + File.separator + list[i]);\r
+                       }\r
+               }\r
+       }\r
        \r
        public static void toDoAll(String path, ForDoAll fda) throws Exception { // filter of file type can be done in toDo\r
                String[] list = new File(path).list();\r
index a3dbc4b78e045225b567b39fcd17ae14651b5457..821305edf0035ae83508ea2ea31460459c375614 100644 (file)
@@ -1,3 +1,15 @@
+/** @file\r
\r
+ Copyright (c) 2006, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
+ **/\r
 package org.tianocore.migration;\r
 \r
 import java.util.regex.*;\r
@@ -14,20 +26,77 @@ public class Critic implements Common.ForDoAll {
        \r
        private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r
        private static Matcher mtrheadcomment;\r
+       private static Pattern ptnfunccomment = Pattern.compile("([\\w\\d]*\\s*[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)(\\/\\*\\+\\+.*?)(\\-\\-\\*\\/\\s*)(.*?)([\\{;])",Pattern.DOTALL);\r
+       private static Matcher mtrfunccomment;\r
+       private static Pattern ptncommentstructure = Pattern.compile("Routine Description:\\s*(\\w.*?\\w)\\s*Arguments:(\\s*\\w.*?\\w\\s*)Returns:(\\s*\\w.*?\\w\\s*)&%",Pattern.DOTALL);\r
+       private static Matcher mtrcommentstructure;\r
+       private static Pattern ptntempcomment = Pattern.compile("\\/\\*\\+\\+(.*?)\\-\\-\\*\\/\\s*[\\w\\d]*\\s*[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)",Pattern.DOTALL);\r
+       private static Matcher mtrtempcomment;\r
+       private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*-\\s*(\\w.*\\w)");\r
+       private static Matcher mtrinfequation;\r
        \r
        public void toDo(String filepath) throws Exception {\r
+               String funccomment = null;\r
                if (filepath.contains(".c") || filepath.contains(".h")) {\r
+                       System.out.println("Criticing   " + filepath);\r
                        String wholeline = Common.file2string(filepath);\r
+                       \r
+                       // find head comment\r
                        mtrheadcomment = ptnheadcomment.matcher(wholeline);\r
                        if (mtrheadcomment.find()) {                    //as we find only the head comment here, use 'if' not 'while'\r
                                wholeline = mtrheadcomment.replaceFirst("/** @file$1**/");\r
-                               Common.string2file(wholeline, filepath + "_");\r
                        }\r
+                       \r
+                       // find func comment\r
+                       mtrfunccomment = ptnfunccomment.matcher(wholeline);\r
+                       while (mtrfunccomment.find()) {\r
+                               funccomment = mtrfunccomment.group(2) + "&%";\r
+                               mtrcommentstructure = ptncommentstructure.matcher(funccomment);\r
+                               wholeline = mtrfunccomment.replaceAll("$2$4$3$1$5");\r
+                       }\r
+                       \r
+                       // edit func comment\r
+                       mtrtempcomment = ptntempcomment.matcher(wholeline);\r
+                       while (mtrtempcomment.find()) {\r
+                               System.out.println("-----------------------------");\r
+                               System.out.println(mtrtempcomment.group());\r
+                               System.out.println("-----------------------------");\r
+                       }\r
+                       Common.string2file(wholeline, filepath);\r
                }\r
        }\r
        \r
        public static void fireAt(String path) throws Exception {\r
-               Common.toDoAll(path, new Critic());\r
+               Critic critic = new Critic();\r
+               Common.toDoAll(Common.dirCopy_(path), critic);\r
                System.out.println("Critic Done");\r
        }\r
 }\r
+//analyze func comment\r
+/*if (mtrcommentstructure.find()) {\r
+       newcomment.append("/*++\n\n" + mtrcommentstructure.group(1) + "\n\n");\r
+       \r
+       //System.out.println("-------1-------");\r
+       //System.out.println(mtrcommentstructure.group(1));\r
+       \r
+       // arg\r
+       //System.out.println("-------2-------");\r
+       //System.out.println(mtrcommentstructure.group(2));\r
+       mtrinfequation = ptninfequation.matcher(mtrcommentstructure.group(2));\r
+       while (mtrinfequation.find()) {\r
+               newcomment.append("@param   " + mtrinfequation.group(1) + "            " + mtrinfequation.group(2) + "\n");\r
+               //System.out.println("@param   " + mtrinfequation.group(1) + "   " + mtrinfequation.group(2));\r
+       }\r
+       newcomment.append("\n");\r
+       // return\r
+       //System.out.println("-------3-------");\r
+       //System.out.println(mtrcommentstructure.group(3));\r
+       mtrinfequation = ptninfequation.matcher(mtrcommentstructure.group(3));\r
+       while (mtrinfequation.find()) {\r
+               newcomment.append("@retval   " + mtrinfequation.group(1) + "            " + mtrinfequation.group(2) + "\n");\r
+               //System.out.println("@retval   " + mtrinfequation.group(1) + "   " + mtrinfequation.group(2));\r
+       }\r
+       System.out.println(newcomment);\r
+} else {\r
+       System.out.println("Error: Comment Style Incorrect");\r
+}*/
\ No newline at end of file