Skip to content

Commit

Permalink
CREATE_PROJECT: Get rid of variadic macro usage.
Browse files Browse the repository at this point in the history
Variadic macros are C99 and ugly in C++. If we would want to do it differently
we should rather rely on C++0x's initializer lists. But since we cannot assume
all compilers we want create_project to build support that we cannot do that.
  • Loading branch information
Johannes Schickel committed Apr 28, 2011
1 parent a0fc266 commit 7f889c6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 50 deletions.
68 changes: 46 additions & 22 deletions devtools/create_project/create_project.cpp
Expand Up @@ -295,19 +295,6 @@ int main(int argc, char *argv[]) {
setup.libraries.push_back(ADDITIONAL_LIBRARY);
#endif

// Initialize global & project-specific warnings
#define SET_GLOBAL_WARNINGS(...) \
{ \
std::string global[PP_NARG(__VA_ARGS__)] = { __VA_ARGS__ }; \
globalWarnings.assign(global, global + (sizeof(global) / sizeof(global[0]))); \
}

#define SET_WARNINGS(name, ...) \
{ \
std::string project[PP_NARG(__VA_ARGS__)] = { __VA_ARGS__ }; \
projectWarnings[name].assign(project, project + (sizeof(project) / sizeof(project[0]))); \
}

// List of global warnings and map of project-specific warnings
StringList globalWarnings;
std::map<std::string, StringList> projectWarnings;
Expand Down Expand Up @@ -342,9 +329,23 @@ int main(int argc, char *argv[]) {
//
////////////////////////////////////////////////////////////////////////////

SET_GLOBAL_WARNINGS("-Wall", "-Wno-long-long", "-Wno-multichar", "-Wno-unknown-pragmas", "-Wno-reorder",
"-Wpointer-arith", "-Wcast-qual", "-Wcast-align", "-Wshadow", "-Wimplicit",
"-Wnon-virtual-dtor", "-Wwrite-strings", "-fno-rtti", "-fno-exceptions", "-fcheck-new");
globalWarnings.push_back("-Wall");
globalWarnings.push_back("-Wno-long-long");
globalWarnings.push_back("-Wno-multichar");
globalWarnings.push_back("-Wno-unknown-pragmas");
globalWarnings.push_back("-Wno-reorder");
globalWarnings.push_back("-Wpointer-arith");
globalWarnings.push_back("-Wcast-qual");
globalWarnings.push_back("-Wcast-align");
globalWarnings.push_back("-Wshadow");
globalWarnings.push_back("-Wimplicit");
globalWarnings.push_back("-Wnon-virtual-dtor");
globalWarnings.push_back("-Wwrite-strings");
// The following are not warnings at all... We should consider adding them to
// a different list of parameters.
globalWarnings.push_back("-fno-rtti");
globalWarnings.push_back("-fno-exceptions");
globalWarnings.push_back("-fcheck-new");

provider = new CreateProjectTool::CodeBlocksProvider(globalWarnings, projectWarnings);

Expand Down Expand Up @@ -421,12 +422,35 @@ int main(int argc, char *argv[]) {
//
////////////////////////////////////////////////////////////////////////////

SET_GLOBAL_WARNINGS("4068", "4100", "4103", "4127", "4244", "4250", "4310", "4351", "4512", "4702", "4706", "4800", "4996", "6204", "6211", "6385", "6386");
SET_WARNINGS("agi", "4510", "4610");
SET_WARNINGS("agos", "4511");
SET_WARNINGS("lure", "4189", "4355");
SET_WARNINGS("kyra", "4355");
SET_WARNINGS("m4", "4355");
globalWarnings.push_back("4068");
globalWarnings.push_back("4100");
globalWarnings.push_back("4103");
globalWarnings.push_back("4127");
globalWarnings.push_back("4244");
globalWarnings.push_back("4250");
globalWarnings.push_back("4310");
globalWarnings.push_back("4351");
globalWarnings.push_back("4512");
globalWarnings.push_back("4702");
globalWarnings.push_back("4706");
globalWarnings.push_back("4800");
globalWarnings.push_back("4996");
globalWarnings.push_back("6204");
globalWarnings.push_back("6211");
globalWarnings.push_back("6385");
globalWarnings.push_back("6386");

projectWarnings["agi"].push_back("4510");
projectWarnings["agi"].push_back("4610");

projectWarnings["agos"].push_back("4511");

projectWarnings["lure"].push_back("4189");
projectWarnings["lure"].push_back("4355");

projectWarnings["kyra"].push_back("4355");

projectWarnings["m4"].push_back("4355");

if (msvcVersion == 8 || msvcVersion == 9)
provider = new CreateProjectTool::VisualStudioProvider(globalWarnings, projectWarnings, msvcVersion);
Expand Down
28 changes: 0 additions & 28 deletions devtools/create_project/create_project.h
Expand Up @@ -32,34 +32,6 @@

#include <cassert>

// The PP_NARG macro returns the number of arguments that have been passed to it.
#define PP_NARG(...) \
PP_NARG_(__VA_ARGS__,PP_RSEQ_N())
#define PP_NARG_(...) \
PP_ARG_N(__VA_ARGS__)
#define PP_ARG_N( \
_1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
_31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
_41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
_51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
_61,_62,_63,N,...) N
#define PP_RSEQ_N() \
63,62,61,60, \
59,58,57,56,55,54,53,52,51,50, \
49,48,47,46,45,44,43,42,41,40, \
39,38,37,36,35,34,33,32,31,30, \
29,28,27,26,25,24,23,22,21,20, \
19,18,17,16,15,14,13,12,11,10, \
9,8,7,6,5,4,3,2,1,0

#define SET_VALUES(list, ...) \
{ \
std::string values[PP_NARG(__VA_ARGS__)] = { __VA_ARGS__ }; \
list.assign(values, values + (sizeof(values) / sizeof(values[0]))); \
}

typedef std::list<std::string> StringList;

/**
Expand Down

0 comments on commit 7f889c6

Please sign in to comment.