Skip to content

Commit

Permalink
compiles, does nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
gaperez64 committed Aug 12, 2020
1 parent 6be3b26 commit 173a953
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 132 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
153 changes: 46 additions & 107 deletions acacia.cpp
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/
* along with Acacia bonsai. If not, see <http://www.gnu.org/licenses/>.
*
* Guillermo A. Perez
* University of Antwerp
* [email protected]
*************************************************************************/

#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <cstdlib>
#include <iostream>
#include <unistd.h>

#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;
}
4 changes: 2 additions & 2 deletions hoatools/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions hoatools/hoa.l
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
32 changes: 16 additions & 16 deletions hoatools/simplehoa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include <string.h>
#include <stdbool.h>

#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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -183,15 +183,15 @@ 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;
tree->type = NT_NOT;
tree->id = -1;
}

BTree* created = malloc(sizeof(BTree));
BTree* created = (BTree*) malloc(sizeof(BTree));
created->left = tree;
created->right = NULL;
created->alias = NULL;
Expand Down

0 comments on commit 173a953

Please sign in to comment.