import java.util.HashMap;
import java.util.Iterator;
-import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct.DefineVar;
import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct;
import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct;
import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface;
import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct;
import edu.uci.eecs.specCompiler.specExtraction.IDExtractor;
import edu.uci.eecs.specCompiler.specExtraction.InterfaceConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.InterfaceDefineConstruct;
import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct;
import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.SourceFileInfo;
import edu.uci.eecs.specCompiler.specExtraction.SpecExtractor;
/**
private File[] srcFiles;
- private HashMap<File, ArrayList<String>> contents;
+ private HashMap<File, SourceFileInfo> srcFilesInfo;
private HashMap<File, ArrayList<CodeAddition>> codeAdditions;
_extractor = new SpecExtractor();
_extractor.extract(srcFiles);
- this.contents = _extractor.contents;
+ this.srcFilesInfo = _extractor.srcFilesInfo;
this.globalContent = null;
this.codeAdditions = new HashMap<File, ArrayList<CodeAddition>>();
- _semantics = new SemanticsChecker(_extractor.constructs);
+ _semantics = new SemanticsChecker(_extractor.getConstructs());
try {
_semantics.check();
System.out.println(_semantics);
}
}
- private ArrayList<String> readSrcFile(File f) throws IOException {
- BufferedReader bf = new BufferedReader(new FileReader(f));
- ArrayList<String> content = new ArrayList<String>();
- String curLine;
- while ((curLine = bf.readLine()) != null) {
- content.add(curLine);
- }
- return content;
- }
-
/**
* <p>
* Generate all the global code, including the "@DefineVar" in each
// Mainly rename and wrap the interface
private void interface2Code(InterfaceConstruct construct)
throws InterfaceWrongFormatException {
- int lineNum = construct.begin + 1;
+ int lineNum = construct.beginLineNum;
+ String funcName = "";
// Rename the interface name
- File file = inst.file;
- String funcDecl = inst.interfaceDeclBody;
+
// Rename the function declaration
- String funcName = renameInterface(inst);
+
// Also rename the function definition if it's separated from the
// declaration
- SpecConstruct definition = _semantics.interfaceName2DefineConstruct
+ InterfaceDefineConstruct definition = (InterfaceDefineConstruct) _semantics.interfaceName2DefineConstruct
.get(construct.name);
if (definition != null) {
String funcDefintionName = renameInterface(definition);
// Generate new wrapper
ArrayList<String> newCode = CodeVariables.generateInterfaceWrapper(
- _semantics, inst);
+ _semantics, construct);
// Add it to the codeAdditions
CodeAddition addition = new CodeAddition(lineNum, newCode);
- if (!codeAdditions.containsKey(inst.file)) {
- codeAdditions.put(inst.file, new ArrayList<CodeAddition>());
+ if (!codeAdditions.containsKey(construct.file)) {
+ codeAdditions.put(construct.file, new ArrayList<CodeAddition>());
}
- codeAdditions.get(inst.file).add(addition);
+ codeAdditions.get(construct.file).add(addition);
}
// Returns the function name that has been renamed and replace the old line
- private String renameInterface(Construct inst)
+ private String renameInterface(Construct construct)
throws InterfaceWrongFormatException {
- String funcDecl = inst.interfaceDeclBody;
- ArrayList<String> content = contents.get(inst.file);
+ String funcDecl = "";
+ ArrayList<String> content = srcFilesInfo.get(construct.file).content;
// Depending on "(" to find the function name, so it doesn't matter if
// there's any template
int lineNumOfID = idExtractor.lineNumOfID();
// Be careful: lineNum - 1 -> index of content array
- content.set(inst.endLineNum + lineNumOfID, newLine);
+ content.set(construct.beginLineNum - 1, newLine);
return funcName;
}