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 specification out, and remember its location, including the
22 * file name and the line number, to help the code generation process.
28 public class SpecExtractor {
29 public final HashMap<File, SourceFileInfo> srcFilesInfo;
31 public SpecExtractor() {
32 srcFilesInfo = new HashMap<File, SourceFileInfo>();
35 public ArrayList<Construct> getConstructs() {
36 ArrayList<Construct> constructs = new ArrayList<Construct>();
37 for (File f : srcFilesInfo.keySet()) {
38 constructs.addAll(srcFilesInfo.get(f).constructs);
45 * Given a list of files, it scans each file and add found SpecConstrcut to
46 * the _constructs list.
50 * @throws SpecNotMatchException
52 public void extract(File[] files) {
53 for (int i = 0; i < files.length; i++)
57 public void extract(File file) {
58 if (srcFilesInfo.containsKey(file))
60 SourceFileInfo srcFileInfo;
62 srcFileInfo = SpecParser.ParseFile(file);
63 for (int i = 0; i < srcFileInfo.content.size(); i++) {
64 System.out.println(srcFileInfo.content.get(i));
66 ParserUtils.write2File(srcFileInfo.file, srcFileInfo.content);
67 srcFilesInfo.put(file, srcFileInfo);
68 } catch (ParseException e) {
70 } catch (TokenMgrError e) {