#include <algorithm>
#include <memory>
+#include <unordered_set>
#include <sys/types.h>
#include "gromacs/utility/arrayref.h"
{
std::shared_ptr < std::vector < t_define>> defines;
std::shared_ptr < std::vector < std::string>> includes;
-
- FILE *fp = nullptr;
- std::string path;
- std::string cwd;
- std::string fn;
- std::string line;
- int line_nr;
- std::vector<int> ifdefs;
- struct gmx_cpp *child = nullptr;
- struct gmx_cpp *parent = nullptr;
+ std::unordered_set<std::string> unmatched_defines;
+ FILE *fp = nullptr;
+ std::string path;
+ std::string cwd;
+ std::string fn;
+ std::string line;
+ int line_nr;
+ std::vector<int> ifdefs;
+ struct gmx_cpp *child = nullptr;
+ struct gmx_cpp *parent = nullptr;
};
static bool is_word_end(char c)
{
std::string buf = cppopts[i] + 2;
buf.resize(ptr - cppopts[i] - 2);
-
add_define(cpp->defines.get(), buf, ptr + 1);
+ cpp->unmatched_defines.insert(buf);
+
}
else
{
add_define(cpp->defines.get(), cppopts[i] + 2, "");
+ cpp->unmatched_defines.insert(cppopts[i] + 2);
}
}
i++;
{
if (define.name == dval)
{
+ // erase from unmatched_defines in original handle
+ gmx_cpp_t root = handle;
+ while (root->parent != nullptr)
+ {
+ root = root->parent;
+ }
+ root->unmatched_defines.erase(dval);
+
found = true;
break;
}
}
if (nn > 0)
{
+ // Need to erase unmatched define in original handle
+ gmx_cpp_t root = handle;
+ while (root->parent != nullptr)
+ {
+ root = root->parent;
+ }
+ root->unmatched_defines.erase(define.name);
+
std::string name;
const char *ptr = buf;
const char *ptr2;
return gmx_strdup(buf);
}
+
+std::string checkAndWarnForUnusedDefines(const gmx_cpp &handle)
+{
+ std::string warning;
+ if (!handle.unmatched_defines.empty())
+ {
+ warning = "The following macros were defined in the 'define' mdp field with the -D prefix, but "
+ "were not used in the topology:\n";
+ for (auto &str : handle.unmatched_defines)
+ {
+ warning += (" " + str + "\n");
+ }
+ warning += "If you haven't made a spelling error, either use the macro you defined, "
+ "or don't define the macro";
+ }
+ return warning;
+}