]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/MigrationTools/org/tianocore/migration/Critic.java
According r1311 can't support linux. So rollback the change, but still remove the...
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Critic.java
CommitLineData
8c4eeeb6 1/** @file\r
2 \r
3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8 \r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 \r
12 **/\r
fed802b1 13package org.tianocore.migration;\r
14\r
15import java.util.regex.*;\r
3637381b 16import java.io.*;\r
fed802b1 17\r
18public class Critic implements Common.ForDoAll {\r
fed802b1 19 private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r
63406ead 20 private static Pattern ptnfunccomment = Pattern.compile("([\\};\\/]\\s*)([\\w\\s]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/(\\s*.*?)([\\{;])",Pattern.DOTALL);\r
7934aee7 21 //private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);\r
3637381b 22 private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*-\\s*(.*)\\s*");\r
8c4eeeb6 23 private static Matcher mtrinfequation;\r
fed802b1 24 \r
25 public void toDo(String filepath) throws Exception {\r
26 if (filepath.contains(".c") || filepath.contains(".h")) {\r
3637381b 27 BufferedReader rd = null;\r
28 String line = null;\r
29 StringBuffer templine = new StringBuffer();\r
1af2e90c 30 boolean incomment = false;\r
3637381b 31 boolean description = false;\r
32 boolean arguments = false;\r
33 boolean returns = false;\r
7934aee7 34 boolean inequation = false;\r
63406ead 35\r
8c4eeeb6 36 System.out.println("Criticing " + filepath);\r
fed802b1 37 String wholeline = Common.file2string(filepath);\r
63406ead 38\r
39 wholeline = wholeline.replaceAll("\t", " ");\r
a756211f 40 wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");\r
63406ead 41 wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$1/**$3**/$4$2$5");\r
3637381b 42 //wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");\r
1af2e90c 43 \r
3637381b 44 rd = new BufferedReader(new StringReader(wholeline));\r
45 while ((line = rd.readLine()) != null) {\r
1af2e90c 46 if (line.matches("\\/\\*\\*")) {\r
47 incomment = true;\r
3637381b 48 templine.append(line + "\n");\r
1af2e90c 49 } else if (line.matches("\\*\\*\\/")) {\r
50 incomment = false;\r
51 templine.append(line + "\n");\r
52 } else if (incomment && line.contains("Routine Description:")) {\r
3637381b 53 description = true;\r
54 arguments = false;\r
55 returns = false;\r
1af2e90c 56 } else if (incomment && line.contains("Arguments:")) {\r
3637381b 57 description = false;\r
58 arguments = true;\r
59 returns = false;\r
1af2e90c 60 } else if (incomment && line.contains("Returns:")) {\r
3637381b 61 description = false;\r
62 arguments = false;\r
63 returns = true;\r
1af2e90c 64 } else if (incomment && description) {\r
3637381b 65 templine.append(line + "\n");\r
1af2e90c 66 } else if (incomment && arguments) {\r
3637381b 67 mtrinfequation = ptninfequation.matcher(line);\r
68 if (mtrinfequation.find()) {\r
7934aee7 69 inequation = true;\r
63406ead 70 templine.append(" @param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");\r
7934aee7 71 } else if (inequation && line.trim().length() == 0) {\r
72 inequation = false;\r
73 templine.append(line + "\n");\r
74 } else if (inequation && line.trim().length() != 0) {\r
75 templine.append("#%#%" + line + "\n");\r
3637381b 76 } else {\r
77 templine.append(line + "\n");\r
78 }\r
1af2e90c 79 } else if (incomment && returns) {\r
3637381b 80 mtrinfequation = ptninfequation.matcher(line);\r
81 if (mtrinfequation.find()) {\r
7934aee7 82 inequation = true;\r
63406ead 83 templine.append(" @retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");\r
7934aee7 84 } else if (inequation && line.trim().length() == 0) {\r
85 inequation = false;\r
86 templine.append(line + "\n");\r
87 } else if (inequation && line.trim().length() != 0) {\r
88 templine.append("#%#%" + line + "\n");\r
3637381b 89 } else {\r
90 templine.append(line + "\n");\r
91 }\r
3637381b 92 } else {\r
93 templine.append(line + "\n");\r
94 }\r
95 }\r
1af2e90c 96 wholeline = templine.toString();\r
7934aee7 97 wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");\r
1af2e90c 98 \r
a756211f 99 /* -----slow edition of replacefirst with stringbuffer-----\r
100 line.append(wholeline);\r
101 mtrfunccomment = ptnfunccomment.matcher(line);\r
8c4eeeb6 102 while (mtrfunccomment.find()) {\r
a756211f 103 line.replace(0, line.length()-1, mtrfunccomment.replaceFirst("$2$4$3$1$5"));\r
8c4eeeb6 104 }\r
a756211f 105 */\r
1af2e90c 106 /* -----slow edition of replacefirst with string-----\r
a756211f 107 while ((mtrfunccomment = ptnfunccomment.matcher(wholeline)).find()) {\r
108 //funccomment = mtrfunccomment.group(2);\r
109 //mtrcommentstructure = ptncommentstructure.matcher(funccomment);\r
110 wholeline = mtrfunccomment.replaceFirst("$2$4$3$1$5");\r
111 }\r
1af2e90c 112 */\r
a756211f 113 /*\r
8c4eeeb6 114 // edit func comment\r
115 mtrtempcomment = ptntempcomment.matcher(wholeline);\r
116 while (mtrtempcomment.find()) {\r
117 System.out.println("-----------------------------");\r
118 System.out.println(mtrtempcomment.group());\r
119 System.out.println("-----------------------------");\r
120 }\r
a756211f 121 */\r
8c4eeeb6 122 Common.string2file(wholeline, filepath);\r
fed802b1 123 }\r
124 }\r
125 \r
126 public static void fireAt(String path) throws Exception {\r
8c4eeeb6 127 Critic critic = new Critic();\r
128 Common.toDoAll(Common.dirCopy_(path), critic);\r
fed802b1 129 System.out.println("Critic Done");\r
130 }\r
131}\r
8c4eeeb6 132//analyze func comment\r
133/*if (mtrcommentstructure.find()) {\r
134 newcomment.append("/*++\n\n" + mtrcommentstructure.group(1) + "\n\n");\r
135 \r
136 //System.out.println("-------1-------");\r
137 //System.out.println(mtrcommentstructure.group(1));\r
138 \r
139 // arg\r
140 //System.out.println("-------2-------");\r
141 //System.out.println(mtrcommentstructure.group(2));\r
142 mtrinfequation = ptninfequation.matcher(mtrcommentstructure.group(2));\r
143 while (mtrinfequation.find()) {\r
144 newcomment.append("@param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");\r
145 //System.out.println("@param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2));\r
146 }\r
147 newcomment.append("\n");\r
148 // return\r
149 //System.out.println("-------3-------");\r
150 //System.out.println(mtrcommentstructure.group(3));\r
151 mtrinfequation = ptninfequation.matcher(mtrcommentstructure.group(3));\r
152 while (mtrinfequation.find()) {\r
153 newcomment.append("@retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");\r
154 //System.out.println("@retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2));\r
155 }\r
156 System.out.println(newcomment);\r
157} else {\r
158 System.out.println("Error: Comment Style Incorrect");\r
159}*/