Posets now integrated into the CGenerator, so the CGenerator now chooses a valid order for the object definitions based on their dependence on each other. Another test now passing

This commit is contained in:
Nathan Braswell
2014-05-21 13:14:16 -04:00
parent d37a07201a
commit 0f6b6c0c67
4 changed files with 40 additions and 8 deletions

View File

@@ -10,6 +10,7 @@
#include "Type.h"
#include "util.h"
#include "Poset.h"
class CGenerator {

View File

@@ -17,6 +17,7 @@ class Poset {
Poset();
~Poset();
void addRelationship(T first, T second);
void addVertex(T vertex);
bool zeroDependencies(T vertex);
std::set<T> getDependsOn(T dependency);
std::vector<T> getTopoSort();
@@ -45,6 +46,11 @@ void Poset<T>::addRelationship(T first, T second) {
adjMatrix[first][second] = true;
}
template <class T>
void Poset<T>::addVertex(T vertex) {
verticies.insert(vertex);
}
template <class T>
bool Poset<T>::zeroDependencies(T vertex) {
auto depMapItr = adjMatrix.find(vertex);
@@ -87,19 +93,21 @@ std::vector<T> Poset<T>::getTopoSort() {
}
//int specilization just for testing
template<>
void Poset<int>::test() {
//would make it just an int specilization, but then we get multiple definition complaints....
template<class T>
void Poset<T>::test() {
std::string result;
{
Poset<int> poset;
poset.addVertex(1000);
for (int i = 0; i < 20; i++)
poset.addRelationship(i,i+1);
result = "";
for (int i : poset.getTopoSort())
result += intToString(i) + " ";
//std::cout << result << std::endl;
assert(result == "20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ");
assert(result == "20 1000 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 "); //Note that sets do not have a set order, so this could change
//This is why the 1000 is in an odd, yet valid, position
}
{
Poset<int> poset;