*
*/
public class SpecExtractor {
+ public final HashMap<File, ArrayList<DefineConstruct>> defineListMap;
public final HashMap<File, ArrayList<InterfaceConstruct>> interfaceListMap;
public final HashMap<File, ArrayList<OPConstruct>> OPListMap;
public final HashSet<String> OPLabelSet;
public final HashMap<File, EntryConstruct> entryMap;
public final HashSet<String> headerFiles;
+
+ // In the generated header file, we need to forward the user-defined
+ public final HashSet<String> forwardClass;
private GlobalConstruct globalConstruct;
public SpecExtractor() {
+ defineListMap = new HashMap<File, ArrayList<DefineConstruct>>();
interfaceListMap = new HashMap<File, ArrayList<InterfaceConstruct>>();
OPListMap = new HashMap<File, ArrayList<OPConstruct>>();
OPLabelSet = new HashSet<String>();
entryMap = new HashMap<File, EntryConstruct>();
headerFiles = new HashSet<String>();
+ forwardClass = new HashSet<String>();
globalConstruct = null;
}
+
+ private void addDefineConstruct(DefineConstruct construct) {
+ ArrayList<DefineConstruct> list = defineListMap
+ .get(construct.file);
+ if (list == null) {
+ list = new ArrayList<DefineConstruct>();
+ defineListMap.put(construct.file, list);
+ }
+ list.add(construct);
+ }
private void addInterfaceConstruct(InterfaceConstruct construct) {
ArrayList<InterfaceConstruct> list = interfaceListMap
// -1 means the curl symbols in the interface do not match
return -1;
}
+
+ /**
+ * <p>
+ * A sub-routine to extract the define construct. When called, we have
+ * already match the beginning of the construct, and we also need to find
+ * the ending line number of the anntotation.
+ * </p>
+ *
+ * @param file
+ * The file that we are processing
+ * @param lineReader
+ * The LineNumberReader that we are using when processing the
+ * current file.
+ * @param curLine
+ * The current line that we are processing. It should be the
+ * beginning line of the annotation construct.
+ * @param beginLineNum
+ * The beginning line number of the interface construct
+ * annotation
+ * @throws WrongAnnotationException
+ * @throws IOException
+ * @throws ParseException
+ */
+ private void extractDefineConstruct(File file,
+ LineNumberReader lineReader, String curLine, int beginLineNum)
+ throws WrongAnnotationException, IOException, ParseException {
+ ArrayList<String> annotations = extractTillConstructEnd(file,
+ lineReader, curLine, beginLineNum);
+ int endLineNum = lineReader.getLineNumber();
+ DefineConstruct construct = new DefineConstruct(file,
+ beginLineNum, endLineNum, annotations);
+ addDefineConstruct(construct);
+ }
+
/**
* <p>
line = lineReader.readLine();
lineNum = lineReader.getLineNumber();
construct.processFunctionDeclaration(line);
+
+ // Record those user-defined struct
+ // RET
+ String returnType = construct.getFunctionHeader().returnType;
+ if (SpecUtils.isUserDefinedStruct(returnType))
+ forwardClass.add(SpecUtils.getPlainType(returnType));
+ // Arguments
+ for (VariableDeclaration decl : construct.getFunctionHeader().args) {
+ if (SpecUtils.isUserDefinedStruct(decl.type))
+ forwardClass.add(SpecUtils.getPlainType(decl.type));
+ }
+
} catch (IOException e) {
errMsg = "Spec error in file \""
+ file.getName()
lineReader = new LineNumberReader(br);
// "/\*\*\s*@(DeclareState|Interface)"
Pattern regexpBegin = Pattern
- .compile("/\\*\\*\\s*@(DeclareState|Interface)");
+ .compile("/\\*\\*\\s*@(DeclareState|Interface|Define)");
Matcher matcher = regexpBegin.matcher("");
String line;
} else if (constructName.equals(SpecNaming.Interface)) {
extractInterfaceConstruct(file, lineReader, line,
beginLineNum);
+ } else if (constructName.equals(SpecNaming.Define)) {
+ extractDefineConstruct(file, lineReader, line,
+ beginLineNum);
} else {
WrongAnnotationException.err(file, beginLineNum,
constructName