X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FMigrationTools%2Forg%2Ftianocore%2Fmigration%2FCritic.java;h=97129b561b80570ea985197802b2e7f096c0d53b;hp=9c81282038593f12c0c51ab632e7942c8d853350;hb=3637381becd36149ea7cedff910ce65916e662a8;hpb=2d16dcec6f602d218ae95a823fca6ae542e03a8f diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/Critic.java b/Tools/Source/MigrationTools/org/tianocore/migration/Critic.java index 9c81282038..97129b561b 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/Critic.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/Critic.java @@ -13,23 +13,75 @@ package org.tianocore.migration; import java.util.regex.*; +import java.io.*; public class Critic implements Common.ForDoAll { private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL); private static Pattern ptnfunccomment = Pattern.compile("([\\w\\d]*\\s*[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)(\\/\\*\\+\\+.*?)(\\-\\-\\*\\/\\s*)(.*?)([\\{;])",Pattern.DOTALL); private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL); - private static Pattern ptninfequation = Pattern.compile("#%%\\s*([^\\s]*\\s*-\\s*.*\\s*)*",Pattern.MULTILINE); + private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*-\\s*(.*)\\s*"); private static Matcher mtrinfequation; + private static Matcher mtrfunccomment; public void toDo(String filepath) throws Exception { if (filepath.contains(".c") || filepath.contains(".h")) { + BufferedReader rd = null; + String line = null; + StringBuffer templine = new StringBuffer(); + boolean description = false; + boolean arguments = false; + boolean returns = false; + System.out.println("Criticing " + filepath); String wholeline = Common.file2string(filepath); wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/"); - wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$2$3$4$1$5"); - wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/"); - + //wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$2$3$4$1$5"); + //wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/"); + /* + rd = new BufferedReader(new StringReader(wholeline)); + while ((line = rd.readLine()) != null) { + if (line.contains("\\-\\-\\*\\/")) { + description = false; + arguments = false; + returns = false; + templine.append(line + "\n"); + } else if (line.contains("Routine Description:")) { + description = true; + arguments = false; + returns = false; + } else if (line.contains("Arguments:")) { + description = false; + arguments = true; + returns = false; + } else if (line.contains("Returns:")) { + description = false; + arguments = false; + returns = true; + } else if (description) { + templine.append(line + "\n"); + //System.out.println("Description:" + line); + } else if (arguments) { + mtrinfequation = ptninfequation.matcher(line); + if (mtrinfequation.find()) { + templine.append(" @param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n"); + } else { + templine.append(line + "\n"); + } + //System.out.println("Arguments:" + line); + } else if (returns) { + mtrinfequation = ptninfequation.matcher(line); + if (mtrinfequation.find()) { + templine.append(" @retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n"); + } else { + templine.append(line + "\n"); + } + //System.out.println("Returns:" + line); + } else { + templine.append(line + "\n"); + } + } + wholeline = templine.toString();*/ /* -----slow edition of replacefirst with stringbuffer----- line.append(wholeline); mtrfunccomment = ptnfunccomment.matcher(line); @@ -37,13 +89,13 @@ public class Critic implements Common.ForDoAll { line.replace(0, line.length()-1, mtrfunccomment.replaceFirst("$2$4$3$1$5")); } */ - /* -----slow edition of replacefirst with string----- + // -----slow edition of replacefirst with string----- while ((mtrfunccomment = ptnfunccomment.matcher(wholeline)).find()) { //funccomment = mtrfunccomment.group(2); //mtrcommentstructure = ptncommentstructure.matcher(funccomment); wholeline = mtrfunccomment.replaceFirst("$2$4$3$1$5"); } - */ + /* // edit func comment mtrtempcomment = ptntempcomment.matcher(wholeline);