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;
10 import java.util.HashMap;
12 import edu.uci.eecs.specCompiler.grammerParser.ParseException;
13 import edu.uci.eecs.specCompiler.grammerParser.SpecParser;
14 import edu.uci.eecs.specCompiler.grammerParser.TokenMgrError;
18 * This class represents the specification extractor of the specification. The
19 * main function of this class is to read C/C++11 source files and extract the
20 * corresponding specification out, and remember its location, including the
21 * file name and the line number, to help the code generation process.
27 public class SpecExtractor {
28 public final ArrayList<Construct> constructs;
30 public final HashMap<File, ArrayList<String>> contents;
33 public SpecExtractor() {
34 constructs = new ArrayList<Construct>();
35 contents = new HashMap<File, ArrayList<String>>();
40 * Given a list of files, it scans each file and add found SpecConstrcut to
41 * the _constructs list.
45 * @throws SpecNotMatchException
47 public void extract(File[] files) {
48 for (int i = 0; i < files.length; i++)
52 public void extract(File file) {
53 if (contents.containsKey(file))
55 ArrayList<String> content = new ArrayList<String>();
56 ArrayList<Construct> localConstructs = new ArrayList<Construct>();
58 SpecParser.ParseFile(file, content, localConstructs);
59 contents.put(file, content);
60 constructs.addAll(localConstructs);
61 } catch (ParseException e) {
63 } catch (TokenMgrError e) {