Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort includes when generating multiple files #2363

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/synthesiser/GenDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,16 @@ std::string GenDb::emitMultipleFilesInDir(fs::path dir, std::vector<fs::path>& t
auto genHeader = [&](std::ofstream& hpp, std::ofstream& cpp, GenFile& gen) {
hpp << "#pragma once\n";
globalHeader(hpp);
for (const std::string& inc : gen.getDeclIncludes()) {
for (const std::string& inc : gen.getSortedDeclIncludes()) {
hpp << "#include " << inc << "\n";
}
for (GenFile* dep : gen.getDeclDependencies()) {
for (GenFile* dep : gen.getSortedDeclDependencies()) {
hpp << "#include " << dep->getHeader() << "\n";
}
for (const std::string& inc : gen.getIncludes()) {
for (const std::string& inc : gen.getSortedIncludes()) {
cpp << "#include " << inc << "\n";
}
for (GenFile* dep : gen.getDependencies()) {
for (GenFile* dep : gen.getSortedDependencies()) {
cpp << "#include " << dep->getHeader() << "\n";
}
cpp << "#include " << gen.getHeader() << "\n";
Expand Down
28 changes: 27 additions & 1 deletion src/synthesiser/GenDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include "souffle/utility/Types.h"
#include <algorithm>
#include <cassert>
#include <filesystem>
#include <iostream>
Expand Down Expand Up @@ -47,7 +48,7 @@ class GenFile {
return basename;
};

fs::path getHeader() {
fs::path getHeader() const {
fs::path header = basename;
return header.concat(".hpp");
}
Expand All @@ -70,15 +71,40 @@ class GenFile {
std::set<std::string>& getDeclIncludes() {
return decl_includes;
}
std::vector<std::string> getSortedDeclIncludes() {
std::vector<std::string> v{decl_includes.begin(), decl_includes.end()};
std::sort(v.begin(), v.end());
return v;
}

std::set<std::string>& getIncludes() {
return includes;
}
std::vector<std::string> getSortedIncludes() {
std::vector<std::string> v{includes.begin(), includes.end()};
std::sort(v.begin(), v.end());
return v;
}

std::set<GenFile*>& getDeclDependencies() {
return decl_dependencies;
}
std::vector<GenFile*> getSortedDeclDependencies() {
std::vector<GenFile*> v{decl_dependencies.begin(), decl_dependencies.end()};
std::sort(v.begin(), v.end(),
[](const GenFile* a, const GenFile* b) { return a->getHeader() < b->getHeader(); });
return v;
}

std::set<GenFile*>& getDependencies() {
return dependencies;
}
std::vector<GenFile*> getSortedDependencies() {
std::vector<GenFile*> v{dependencies.begin(), dependencies.end()};
std::sort(v.begin(), v.end(),
[](const GenFile* a, const GenFile* b) { return a->getHeader() < b->getHeader(); });
return v;
}

private:
fs::path basename;
Expand Down