+package edu.uci.eecs.specCompiler.specExtraction;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.util.ArrayList;
+
+/**
+ * <p>
+ * This class represents the specification extractor of the specification. The
+ * main function of this class is to read C/C++11 source files and extract the
+ * corresponding specification out, and remember its location, including the
+ * file name and the line number, to help the code generation process.
+ * </p>
+ * @author peizhaoo
+ *
+ */
+public class SpecExtractor {
+ private ArrayList<SpecConstruct> _constructs;
+ private StringBuilder _extractedSpecText;
+
+ private enum State {
+ Neutral, HeadParsed, BeginParsed, EndParsed
+ }
+
+ private State _curState;
+
+ private StringBuilder _potentialConstruct;
+ private int _startLine, _endLine;
+
+ SpecExtractor() {
+ _constructs = new ArrayList<SpecConstruct>();
+ _extractedSpecText = new StringBuilder();
+ _curState = State.Neutral;
+ _potentialConstruct = new StringBuilder();
+ }
+
+ /**
+ * <p>
+ * Given a list of files, it scans each file and add found SpecConstrcut
+ * to the _constructs list.
+ * </p>
+ * @param files
+ */
+ private void extract(File[] files) {
+ for (int i = 0; i < files.length; i++)
+ extract(files[i]);
+ }
+
+ private void extract(File file) {
+ try {
+ LineNumberReader reader = new LineNumberReader(new FileReader(file));
+ String prevLine = "", curLine;
+ ArrayList<String> text;
+ while ((curLine = reader.readLine()) != null) {
+
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void parseHead(String prevLine, String line) {
+ assert (_curState == State.Neutral);
+
+ // "\" is the C/C++ line break. If the previous line ends with "\",
+ // it may be part of a string literal.
+ if (prevLine.endsWith("\\"))
+ return;
+ String newLine = trimBeginningSpace(line);
+// if (newLine.startsWith("/**") &&
+// (newLine.length() == 3 ||
+ }
+
+ private void parseBegin(String line) {
+
+ }
+
+ private void parseEnd(String line) {
+
+ }
+
+ private void parseTail(String line) {
+
+ }
+
+ private String trimBeginningSpace(String line) {
+ int i;
+ for (i = 0; i < line.length(); i++) {
+ char ch = line.charAt(i);
+ if (ch == ' ' || ch == '\t')
+ i++;
+ else
+ break;
+ }
+ return line.substring(i);
+ }
+}