/**
* Class properties
*/
- private String origInt;
private ParseTreeHandler ptHandler;
private InterfaceDecl intDecl;
private CapabilityDecl capDecl;
*/
public IoTCompiler() {
- origInt = null;
ptHandler = new ParseTreeHandler();
intDecl = null;
capDecl = null;
}
- public IoTCompiler(String _origInt, ParseNode _pnPol, ParseNode _pnReq) {
+ public IoTCompiler(String _intface, ParseNode _pnPol, ParseNode _pnReq) {
- origInt = _origInt;
- ptHandler = new ParseTreeHandler(_origInt, _pnPol, _pnReq);
+ ptHandler = new ParseTreeHandler(_intface, _pnPol, _pnReq);
intDecl = null;
capDecl = null;
reqDecl = null;
* The local interface has to be the input parameter for the stub and the stub
* interface has to be the input parameter for the local class.
*/
- public void generateJavaLocalInterface() throws IOException {
+ public void generateJavaLocalInterface(String _intface) throws IOException {
// Create a new directory
createDirectory(dir);
// Open a new file to write into
- String intface = origInt;
+ String intface = _intface;
FileWriter fw = new FileWriter(dir + "/" + intface + ".java");
pw = new PrintWriter(new BufferedWriter(fw));
// Pass in set of methods and get import classes
* The local interface has to be the input parameter for the stub and the stub
* interface has to be the input parameter for the local class.
*/
- public void generateCplusLocalInterface() throws IOException {
+ public void generateCplusLocalInterface(String _intface) throws IOException {
// Create a new directory
createDirectory(dir);
// Open a new file to write into
- String intface = origInt;
+ String intface = _intface;
FileWriter fw = new FileWriter(dir + "/" + intface + ".hpp");
pw = new PrintWriter(new BufferedWriter(fw));
// Write file headers
}
+ /**
+ * parseFile() prepares Lexer and Parser objects, then parses the file
+ */
+ public static ParseNode parseFile(String file) {
+
+ ParseNode pn = null;
+ try {
+ ComplexSymbolFactory csf = new ComplexSymbolFactory();
+ ScannerBuffer lexer =
+ new ScannerBuffer(new Lexer(new BufferedReader(new FileReader(file)),csf));
+ Parser parse = new Parser(lexer,csf);
+ pn = (ParseNode) parse.parse().value;
+ } catch (Exception e) {
+ System.out.println("IoTCompiler: ERROR parsing policy file!");
+ e.printStackTrace();
+ }
+
+ return pn;
+ }
+
+
/**================================================
* Helper functions to write stub codes into files
**================================================
public static void main(String[] args) throws Exception {
// Runtime options
- if (args.length != 0) {
+ if (args.length > 1) {
// Display help
if ((args[0].equals("--help") ||
(args[0].equals("-h")))) {
IoTCompiler.printUsage();
} else {
// Parse main policy file
- ComplexSymbolFactory csfPol = new ComplexSymbolFactory();
- ScannerBuffer lexerPol =
- new ScannerBuffer(new Lexer(new BufferedReader(new FileReader(args[0])),csfPol));
- Parser parsePol = new Parser(lexerPol,csfPol);
- ParseNode pnPol = (ParseNode) parsePol.parse().value;
+ ParseNode pnPol = IoTCompiler.parseFile(args[0]);
// Parse "requires" policy file
- ComplexSymbolFactory csfReq = new ComplexSymbolFactory();
- ScannerBuffer lexerReq =
- new ScannerBuffer(new Lexer(new BufferedReader(new FileReader(args[1])),csfReq));
- Parser parseReq = new Parser(lexerReq,csfReq);
- ParseNode pnReq = (ParseNode) parseReq.parse().value;
+ ParseNode pnReq = IoTCompiler.parseFile(args[1]);
// Get interface name
- String intFace = ParseTreeHandler.getOrigIntface(pnPol);
- //System.out.println("IoTCompiler: Original interface: " + intFace);
- IoTCompiler comp = new IoTCompiler(intFace, pnPol, pnReq);
+ String intface = ParseTreeHandler.getOrigIntface(pnPol);
+ IoTCompiler comp = new IoTCompiler(intface, pnPol, pnReq);
// Generate all policy files if just policy file is provided
comp.parsePolicyFile();
comp.getMethodsForIntface();
if (args.length == 2) {
- comp.generateJavaLocalInterface();
+ comp.generateJavaLocalInterface(intface);
comp.generateJavaInterfaces();
comp.generateJavaStubClasses();
- comp.generateCplusLocalInterface();
+ comp.generateCplusLocalInterface(intface);
comp.generateCPlusInterfaces();
comp.generateCPlusStubClasses();
} else {
} else
throw new Error("IoTCompiler: ERROR - please provide <directory> after option: " + args[i]);
if (args[i].equals("-java")) {
- comp.generateJavaLocalInterface();
+ comp.generateJavaLocalInterface(intface);
comp.generateJavaInterfaces();
comp.generateJavaStubClasses();
} else if (args[i].equals("-cplus")) {
- comp.generateCplusLocalInterface();
+ comp.generateCplusLocalInterface(intface);
comp.generateCPlusInterfaces();
comp.generateCPlusStubClasses();
} else