1 package edu.uci.eecs.specCompiler.specExtraction;
3 import java.io.BufferedReader;
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;
11 import edu.uci.eecs.specCompiler.grammerParser.ParseException;
12 import edu.uci.eecs.specCompiler.grammerParser.SpecParser;
13 import edu.uci.eecs.specCompiler.grammerParser.TokenMgrError;
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.
26 public class SpecExtractor {
27 private ArrayList<Construct> _constructs;
28 private int _beginLineNum, _endLineNum;
29 private String _beginLine;
31 public SpecExtractor() {
32 _constructs = new ArrayList<Construct>();
35 ArrayList<Construct> getConstructs() {
36 return this._constructs;
41 * Given a list of files, it scans each file and add found SpecConstrcut to
42 * the _constructs list.
46 * @throws SpecNotMatchException
48 public void extract(File[] files) {
49 for (int i = 0; i < files.length; i++)
53 public void extract(File file) {
54 StringBuilder specText = new StringBuilder();
58 public static String trimSpace(String line) {
61 for (i = 0; i < line.length(); i++) {
63 if (ch != ' ' && ch != '\t')
66 for (j = line.length() - 1; j >= 0; j--) {
68 if (ch != ' ' && ch != '\t')
74 return line.substring(i, j + 1);