lots of changes
[cdsspec-compiler.git] / src / edu / uci / eecs / specCompiler / specExtraction / SpecExtractor.java
1 package edu.uci.eecs.specCompiler.specExtraction;
2
3 import java.io.BufferedReader;
4 import java.io.File;
5 import java.io.FileNotFoundException;
6 import java.io.FileReader;
7 import java.io.IOException;
8 import java.io.LineNumberReader;
9 import java.util.ArrayList;
10
11 import edu.uci.eecs.specCompiler.grammerParser.ParseException;
12 import edu.uci.eecs.specCompiler.grammerParser.SpecParser;
13 import edu.uci.eecs.specCompiler.grammerParser.TokenMgrError;
14
15 /**
16  * <p>
17  * This class represents the specification extractor of the specification. The
18  * main function of this class is to read C/C++11 source files and extract the
19  * corresponding specification out, and remember its location, including the
20  * file name and the line number, to help the code generation process.
21  * </p>
22  * 
23  * @author peizhaoo
24  * 
25  */
26 public class SpecExtractor {
27         private ArrayList<Construct> _constructs;
28         private int _beginLineNum, _endLineNum;
29         private String _beginLine;
30
31         public SpecExtractor() {
32                 _constructs = new ArrayList<Construct>();
33         }
34         
35         ArrayList<Construct> getConstructs() {
36                 return this._constructs;
37         }
38
39         /**
40          * <p>
41          * Given a list of files, it scans each file and add found SpecConstrcut to
42          * the _constructs list.
43          * </p>
44          * 
45          * @param files
46          * @throws SpecNotMatchException
47          */
48         public void extract(File[] files) {
49                 for (int i = 0; i < files.length; i++)
50                         extract(files[i]);
51         }
52
53         public void extract(File file) {
54                 StringBuilder specText = new StringBuilder();
55                 
56         }
57
58         public static String trimSpace(String line) {
59                 int i, j;
60                 char ch;
61                 for (i = 0; i < line.length(); i++) {
62                         ch = line.charAt(i);
63                         if (ch != ' ' && ch != '\t')
64                                 break;
65                 }
66                 for (j = line.length() - 1; j >= 0; j--) {
67                         ch = line.charAt(j);
68                         if (ch != ' ' && ch != '\t')
69                                 break;
70                 }
71                 if (i > j)
72                         return "";
73                 else
74                         return line.substring(i, j + 1);
75         }
76 }