diff --git a/Makefile b/Makefile index 6a51509a..a0f64be7 100644 --- a/Makefile +++ b/Makefile @@ -9,18 +9,18 @@ DBGFLAGS = -fsanitize=address -fno-omit-frame-pointer -g GEND = hoatools/hoalexer.hpp hoatools/hoalexer.cpp\ hoatools/hoaparser.hpp hoatools/hoaparser.cpp -$(GEND): - cd hoatools && $(MAKE) +$(GEND): hoatools/hoa.l hoatools/hoa.y + cd hoatools && $(MAKE) all .PHONY: all clean acacia: $(SRCS) $(HDRS) - $(CXX) $(CFLAGS) -o acacia $(SRCS) acacia.c + $(CXX) $(CFLAGS) -o acacia $(SRCS) acacia.cpp acacia-dbg: $(SRCS) $(HDRS) - $(CXX) $(DBGFLAGS) -o acacia $(SRCS) acacia.c + $(CXX) $(DBGFLAGS) -o acacia $(SRCS) acacia.cpp all: acacia acacia-dbg clean: - rm tests + rm acacia acacia-dbg diff --git a/acacia.cpp b/acacia.cpp index eef854c8..3dc26f67 100644 --- a/acacia.cpp +++ b/acacia.cpp @@ -1,120 +1,59 @@ -/* Copyright 2019, Guillermo A. Perez @ University of Antwerp - * +/************************************************************************** + * Copyright (c) 2020- Guillermo A. Perez + * Copyright (c) 2020- Michael Cadilhac + * * This file is part of Acacia bonsai. - * + * * Acacia bonsai is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * * Acacia bonsai is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License - * along with Acacia bonsai. If not, see . - */ + * along with Acacia bonsai. If not, see . + * + * Guillermo A. Perez + * University of Antwerp + * guillermoalberto.perez@uantwerpen.be + *************************************************************************/ -#include -#include -#include #include +#include +#include +#include -#include "veclist.h" -#include "kdtree.h" +using namespace std; -static void testsVecList() { - int a[] = {3, 5, 1}; - VLNode* list = newVLNode(a); - VLNode* last = list; - int b[] = {4, 8, 9}; - last = appendVLNode(last, b); - int c[] = {2, 6, 10}; - last = appendVLNode(last, c); - - // test correct insertion - assert(list != NULL); - assert(list->data == a); - VLNode* i = list->next; - assert(i != NULL); - assert(i->data == b); - VLNode* j = i->next; - assert(j != NULL); - assert(j->data == c); - assert(j->next == NULL); - - // test the print - printf("Test the printing of DL lists\n"); - printVList(list, 3); - - // test the copy - VLNode* list2 = copyVList(list); - assert(list2 != NULL); - assert(list2->data == a); - i = list2->next; - assert(i != NULL); - assert(i->data == b); - j = i->next; - assert(j != NULL); - assert(j->data == c); - assert(j->next == NULL); - - // test the sort - sortVList(list2, 1); - assert(list2 != NULL); - assert(list2->data == a); - i = list2->next; - assert(i != NULL); - assert(i->data == c); - j = i->next; - assert(j != NULL); - assert(j->data == b); - assert(j->next == NULL); - - // test the deletion of a list - deleteVList(list); - deleteVList(list2); -} - -void testsKDTree() { - int a[] = {3, 5, 1}; - VLNode* list = newVLNode(a); - VLNode* last = list; - int b[] = {4, 8, 9}; - last = appendVLNode(last, b); - int c[] = {2, 6, 10}; - last = appendVLNode(last, c); - int d[] = {3, 3, 4}; - last = appendVLNode(last, d); - int e[] = {1, 2, 3}; - last = appendVLNode(last, e); - - // test KDTree creation - KDTNode* tree = createKDTree(list, 3); - - // test print - printf("Test printing of KDTrees\n"); - printKDTree(tree, 3); - - // test domination - assert(isDominatedKDTree(tree, 3, a)); - int f[] = {2, 5, 9}; - assert(isDominatedKDTree(tree, 3, f)); - int x[] = {8, 1, 1}; - assert(!isDominatedKDTree(tree, 3, x)); - int y[] = {1, 1, 100}; - assert(!isDominatedKDTree(tree, 3, y)); - int z[] = {0, 0, 0}; - assert(isDominatedKDTree(tree, 3, z)); - - // test deletion - deleteKDTree(tree); - deleteVList(list); +void usage(char* progName) { + cout << progName << " [OPTIONS] [FILENAME]" << endl + << endl; } -int main() { - testsVecList(); - testsKDTree(); - return 0; +int main(int argc, char* argv[]) { + int c; + while ((c = getopt(argc, argv, "h")) != -1) { + switch (c) { + case 'h': + usage(argv[0]); + break; + case '?': // getopt found an invalid option + return EXIT_FAILURE; + default: + assert(false); // this should not be reachable + } + } + + // making sure we have at most 1 (positional) non-option + if (argc - optind > 1) { + fprintf(stderr, "Expected at most 1 positional arguments!\n"); + return EXIT_FAILURE; + } else { + // pass + } + return EXIT_SUCCESS; } diff --git a/hoatools/Makefile b/hoatools/Makefile index 05cbb80e..553db838 100644 --- a/hoatools/Makefile +++ b/hoatools/Makefile @@ -1,9 +1,9 @@ # The parser is flex + bison based, everything is generated from # hoa.l and hoa.y, the tokenizer and parser specifications -hoalexer.cpp: hoa.l hoaparser.cpp hoaparser.hpp +hoalexer.cpp: hoa.l hoaparser.cpp hoaparser.hpp simplehoa.cpp simplehoa.hpp flex --outfile=hoalexer.cpp --header-file=hoalexer.hpp hoa.l -hoaparser.cpp: hoa.y +hoaparser.cpp: hoa.y simplehoa.cpp simplehoa.hpp bison --defines --output=hoaparser.cpp hoa.y .PHONY: clean all diff --git a/hoatools/hoa.l b/hoatools/hoa.l index 447cd548..5dac06d4 100644 --- a/hoatools/hoa.l +++ b/hoatools/hoa.l @@ -32,14 +32,14 @@ char* getString(char* s) { int newLen = strlen(s) - 1; - char* str = malloc(sizeof(char) * newLen); + char* str = (char*) malloc(sizeof(char) * newLen); strncpy(str, s + 1, newLen - 1); str[newLen - 1] = '\0'; return str; } char* getAlias(char* s) { - char* str = malloc(sizeof(char) * strlen(s)); + char* str = (char*) malloc(sizeof(char) * strlen(s)); strcpy(str, s + 1); return str; } diff --git a/hoatools/simplehoa.cpp b/hoatools/simplehoa.cpp index 6e0aec1a..2fd6ec8a 100644 --- a/hoatools/simplehoa.cpp +++ b/hoatools/simplehoa.cpp @@ -28,10 +28,10 @@ #include #include -#include "simplehoa.h" +#include "simplehoa.hpp" StateList* newStateNode(int id, char* name, BTree* label, IntList* accSig) { - StateList* list = malloc(sizeof(StateList)); + StateList* list = (StateList*) malloc(sizeof(StateList)); list->id = id; list->name = name; list->label = label; @@ -49,7 +49,7 @@ StateList* prependStateNode(StateList* node, StateList* newNode, TransList* prependTransNode(TransList* node , BTree* label, IntList* successors, IntList* accSig) { - TransList* newHead = malloc(sizeof(TransList)); + TransList* newHead = (TransList*) malloc(sizeof(TransList)); newHead->label = label; newHead->successors = successors; newHead->accSig = accSig; @@ -58,28 +58,28 @@ TransList* prependTransNode(TransList* node , BTree* label, } IntList* newIntNode(int val) { - IntList* list = malloc(sizeof(IntList)); + IntList* list = (IntList*) malloc(sizeof(IntList)); list->i = val; list->next = NULL; return list; } IntList* prependIntNode(IntList* node, int val) { - IntList* newHead = malloc(sizeof(IntList)); + IntList* newHead = (IntList*) malloc(sizeof(IntList)); newHead->i = val; newHead->next = node; return newHead; } StringList* prependStrNode(StringList* node, char* str) { - StringList* newHead = malloc(sizeof(StringList)); + StringList* newHead = (StringList*) malloc(sizeof(StringList)); newHead->str = str; newHead->next = node; return newHead; } AliasList* prependAliasNode(AliasList* node, char* alias, BTree* labelExpr) { - AliasList* newHead = malloc(sizeof(AliasList)); + AliasList* newHead = (AliasList*) malloc(sizeof(AliasList)); newHead->alias = alias; newHead->next = node; newHead->labelExpr = labelExpr; @@ -114,7 +114,7 @@ IntList* concatIntLists(IntList* list1, IntList* list2) { } BTree* boolBTree(bool b) { - BTree* created = malloc(sizeof(BTree)); + BTree* created = (BTree*) malloc(sizeof(BTree)); created->left = NULL; created->right = NULL; created->alias = NULL; @@ -124,7 +124,7 @@ BTree* boolBTree(bool b) { } BTree* andBTree(BTree* u, BTree* v) { - BTree* created = malloc(sizeof(BTree)); + BTree* created = (BTree*) malloc(sizeof(BTree)); created->left = u; created->right = v; created->alias = NULL; @@ -134,7 +134,7 @@ BTree* andBTree(BTree* u, BTree* v) { } BTree* orBTree(BTree* u, BTree* v) { - BTree* created = malloc(sizeof(BTree)); + BTree* created = (BTree*) malloc(sizeof(BTree)); created->left = u; created->right = v; created->alias = NULL; @@ -144,7 +144,7 @@ BTree* orBTree(BTree* u, BTree* v) { } BTree* notBTree(BTree* u) { - BTree* created = malloc(sizeof(BTree)); + BTree* created = (BTree*) malloc(sizeof(BTree)); created->left = u; created->right = NULL; created->alias = NULL; @@ -154,7 +154,7 @@ BTree* notBTree(BTree* u) { } BTree* aliasBTree(char* alias) { - BTree* created = malloc(sizeof(BTree)); + BTree* created = (BTree*) malloc(sizeof(BTree)); created->left = NULL; created->right = NULL; created->alias = alias; @@ -164,7 +164,7 @@ BTree* aliasBTree(char* alias) { } BTree* apBTree(int id) { - BTree* created = malloc(sizeof(BTree)); + BTree* created = (BTree*) malloc(sizeof(BTree)); created->left = NULL; created->right = NULL; created->alias = NULL; @@ -174,7 +174,7 @@ BTree* apBTree(int id) { } BTree* accidBTree(NodeType type, int id, bool negated) { - BTree* tree = malloc(sizeof(BTree)); + BTree* tree = (BTree*) malloc(sizeof(BTree)); tree->left = NULL; tree->right = NULL; tree->alias = NULL; @@ -183,7 +183,7 @@ BTree* accidBTree(NodeType type, int id, bool negated) { if (negated) { BTree* original = tree; - tree = malloc(sizeof(BTree)); + tree = (BTree*) malloc(sizeof(BTree)); tree->left = original; tree->right = NULL; tree->alias = NULL; @@ -191,7 +191,7 @@ BTree* accidBTree(NodeType type, int id, bool negated) { tree->id = -1; } - BTree* created = malloc(sizeof(BTree)); + BTree* created = (BTree*) malloc(sizeof(BTree)); created->left = tree; created->right = NULL; created->alias = NULL;