|
"\t"
|
- // Comment for the specification
+ // "#" comment for the specification
<"#" (~["\n", "\r"])* (["\n", "\r"])>
+|
+ // "//" comment for the specification
+ <"//" (~["\n", "\r"])* (["\n", "\r"])>
}
TOKEN :
|
<CONDITION: "@Condition:">
|
- <NUM_OR_EMPTY: ["1"-"9"](["0"-"9"])+ | "">
-|
- <ONE_HB_CONDITION: "@HB_condition:" <NUM_OR_EMPTY> (~["@", "#", "$"])+>
-|
- <ALL_HB_CONDITIONS: (<ONE_HB_CONDITION>)*>
+ <HB_CONDITIONS: "@HB_condition:">
|
<ID: "@ID:">
-| <CHECK: "@Check:">
+|
+ <CHECK: "@Check:">
|
<ACTION: "@Action:">
|
<LABEL: "@Label:">
|
<COMMIT_POINT_DEFINE_CHECK: "@Commit_point_define_check:">
-
|
<COMMIT_POINT_DEFINE: "@Commit_point_define:">
|
<POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
|
- <IDENTIFIER: (["a"-"z", "A"-"Z", "_"]) (["0"-"9", "a"-"z", "A"-"Z", "_"])*>
+ <#DIGIT: ["0"-"9"]>
+|
+ <#NONZERO_DIGIT: ["1"-"9"]>
+|
+ <#LETTER: ["a"-"z", "A"-"Z"]>
+|
+ <#NUM: <NONZERO_DIGIT> <DIGIT>>
+|
+ <IDENTIFIER: <LETTER> (<LETTER> | <DIGIT> | "_")>
}
void Start() :
{}
{
- <EOF>
+ Global_construct() <EOF>
}
void Global_construct() :
{}
{
- <HEAD>
+ <HEAD>
<BEGIN>
- <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")" "->" <IDENTIFIER>
+ Global_define() (Interface_cluster())? (Happens_before())?
<END>
<TAIL>
}
void C_CPP_CODE() :
{}
{
- <(~["@", "#", "$"])+>
+ <(~["@"])+>
}
void Global_define() :
void Happens_before() :
{}
{
- <HEAD>
- <BEGIN>
- <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")" "->" <IDENTIFIER>
- <END>
- <TAIL>
+ <HAPPENS_BEFORE> (Conditional_interface() "->" Conditional_interface())+
}
void Interface() :
--- /dev/null
+package edu.uci.eecs.specCompiler.specExtraction;
+
+import java.io.File;
+
+/**
+ * <p>
+ * This class represents the plain context for each specification construct.
+ * Besides, it also stores some useful information such as interfaceDeclBody,
+ * which is used in @Interface construct to wrap and rename interface calls.
+ * </p>
+ * @author peizhaoo
+ *
+ */
+public class SpecConstruct {
+ public enum ConstructType {
+ GLOBAL, INTERFACE, POTENTIAL_CP, CP_DEFINE, CP_DEFINE_CHECK
+ };
+ public ConstructType type;
+ public final String plainText;
+ public final File file;
+ public final int beginLineNum;
+ public final int endLineNum;
+ public final String interfaceDeclBody;
+
+ public SpecConstruct(ConstructType type, String plainText, File file,
+ int beginLineNum, int endLineNum) {
+ this.type = type;
+ this.plainText = plainText;
+ this.file = file;
+ this.beginLineNum = beginLineNum;
+ this.endLineNum = endLineNum;
+ this.interfaceDeclBody = "";
+ }
+
+ public SpecConstruct(ConstructType type, String plainText, File file,
+ int beginLineNum, int endLineNum, String interfaceDeclBody) {
+ this.type = type;
+ this.plainText = plainText;
+ this.file = file;
+ this.beginLineNum = beginLineNum;
+ this.endLineNum = endLineNum;
+ this.interfaceDeclBody = interfaceDeclBody;
+ }
+}
--- /dev/null
+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);
+ }
+}