minor fix
[cdsspec-compiler.git] / src / edu / uci / eecs / specExtraction / SpecExtractor.java
index a7b4fe591926defe578dd785351bc95aaf7b9a0b..d3a2521223e3a3c5a9f918de46de5161fbaf8544 100644 (file)
@@ -30,6 +30,7 @@ import edu.uci.eecs.utilParser.ParseException;
  * 
  */
 public class SpecExtractor {
+       public final HashMap<File, ArrayList<DefineConstruct>> defineListMap;
        public final HashMap<File, ArrayList<InterfaceConstruct>> interfaceListMap;
        public final HashMap<File, ArrayList<OPConstruct>> OPListMap;
        public final HashSet<String> OPLabelSet;
@@ -44,6 +45,7 @@ public class SpecExtractor {
        private GlobalConstruct globalConstruct;
 
        public SpecExtractor() {
+               defineListMap = new HashMap<File, ArrayList<DefineConstruct>>();
                interfaceListMap = new HashMap<File, ArrayList<InterfaceConstruct>>();
                OPListMap = new HashMap<File, ArrayList<OPConstruct>>();
                OPLabelSet = new HashSet<String>();
@@ -52,6 +54,16 @@ public class SpecExtractor {
                forwardClass = new HashSet<String>();
                globalConstruct = null;
        }
+       
+       private void addDefineConstruct(DefineConstruct construct) {
+               ArrayList<DefineConstruct> list = defineListMap
+                               .get(construct.file);
+               if (list == null) {
+                       list = new ArrayList<DefineConstruct>();
+                       defineListMap.put(construct.file, list);
+               }
+               list.add(construct);
+       }
 
        private void addInterfaceConstruct(InterfaceConstruct construct) {
                ArrayList<InterfaceConstruct> list = interfaceListMap
@@ -256,11 +268,12 @@ public class SpecExtractor {
                annotations.add(curLine);
                // System.out.println(curLine);
                // Initial settings for matching lines
-               // "\*/( |\t)*$"
-               Pattern regexpEnd = Pattern.compile("\\*/( |\\t)*$");
+               // "\*/\s*$"
+               Pattern regexpEnd = Pattern.compile("\\*/\\s*$");
                Matcher matcher = regexpEnd.matcher(curLine);
-               if (matcher.find()) { // The beginning line is also the end line
-                       annotations.add(curLine);
+               if (matcher.find()) {
+                       // The beginning line is also the end line
+                       // In this case, we have already add the curLine
                        return annotations;
                } else {
                        try {
@@ -372,6 +385,40 @@ public class SpecExtractor {
                // -1 means the curl symbols in the interface do not match
                return -1;
        }
+       
+       /**
+        * <p>
+        * A sub-routine to extract the define construct. When called, we have
+        * already match the beginning of the construct, and we also need to find
+        * the ending line number of the anntotation.
+        * </p>
+        * 
+        * @param file
+        *            The file that we are processing
+        * @param lineReader
+        *            The LineNumberReader that we are using when processing the
+        *            current file.
+        * @param curLine
+        *            The current line that we are processing. It should be the
+        *            beginning line of the annotation construct.
+        * @param beginLineNum
+        *            The beginning line number of the interface construct
+        *            annotation
+        * @throws WrongAnnotationException
+        * @throws IOException
+        * @throws ParseException
+        */
+       private void extractDefineConstruct(File file,
+                       LineNumberReader lineReader, String curLine, int beginLineNum)
+                       throws WrongAnnotationException, IOException, ParseException {
+               ArrayList<String> annotations = extractTillConstructEnd(file,
+                               lineReader, curLine, beginLineNum);
+               int endLineNum = lineReader.getLineNumber();
+               DefineConstruct construct = new DefineConstruct(file,
+                               beginLineNum, endLineNum, annotations);
+               addDefineConstruct(construct);
+       }
+       
 
        /**
         * <p>
@@ -577,7 +624,7 @@ public class SpecExtractor {
                        lineReader = new LineNumberReader(br);
                        // "/\*\*\s*@(DeclareState|Interface)"
                        Pattern regexpBegin = Pattern
-                                       .compile("/\\*\\*\\s*@(DeclareState|Interface)");
+                                       .compile("/\\*\\*\\s*@(DeclareState|Interface|Define)");
                        Matcher matcher = regexpBegin.matcher("");
 
                        String line;
@@ -608,6 +655,9 @@ public class SpecExtractor {
                                        } else if (constructName.equals(SpecNaming.Interface)) {
                                                extractInterfaceConstruct(file, lineReader, line,
                                                                beginLineNum);
+                                       } else if (constructName.equals(SpecNaming.Define)) {
+                                               extractDefineConstruct(file, lineReader, line,
+                                                               beginLineNum);
                                        } else {
                                                WrongAnnotationException.err(file, beginLineNum,
                                                                constructName