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;
11 import java.util.HashSet;
13 import edu.uci.eecs.specCompiler.grammerParser.ParseException;
14 import edu.uci.eecs.specCompiler.grammerParser.SpecParser;
15 import edu.uci.eecs.specCompiler.grammerParser.TokenMgrError;
19 * This class represents the specification extractor of the specification. The
20 * main function of this class is to read C/C++11 source files and extract the
21 * corresponding specifications, and record corresponding information such as
22 * location, e.g., the file name and the line number, to help the code
29 public class SpecExtractor {
30 public final HashMap<File, SourceFileInfo> srcFilesInfo;
32 public SpecExtractor() {
33 srcFilesInfo = new HashMap<File, SourceFileInfo>();
36 public ArrayList<Construct> getConstructs() {
37 ArrayList<Construct> constructs = new ArrayList<Construct>();
38 for (File f : srcFilesInfo.keySet()) {
39 constructs.addAll(srcFilesInfo.get(f).constructs);
46 * Given a list of files, it scans each file and add found SpecConstrcut to
47 * the _constructs list.
51 * @throws SpecNotMatchException
53 public void extract(File[] files) {
54 for (int i = 0; i < files.length; i++)
58 public void extract(File file) {
59 if (srcFilesInfo.containsKey(file))
61 SourceFileInfo srcFileInfo;
63 srcFileInfo = SpecParser.ParseFile(file);
64 for (int i = 0; i < srcFileInfo.content.size(); i++) {
65 System.out.println(srcFileInfo.content.get(i));
67 ParserUtils.write2File(srcFileInfo.file, srcFileInfo.content);
68 srcFilesInfo.put(file, srcFileInfo);
69 } catch (ParseException e) {
71 } catch (TokenMgrError e) {