diff --git a/dtool/src/cppparser/cppManifest.cxx b/dtool/src/cppparser/cppManifest.cxx index 451416f93d..eeb2859c0d 100644 --- a/dtool/src/cppparser/cppManifest.cxx +++ b/dtool/src/cppparser/cppManifest.cxx @@ -43,22 +43,19 @@ ExpansionNode(const string &str, bool paste) : //////////////////////////////////////////////////////////////////// // Function: CPPManifest::Constructor // Access: Public -// Description: +// Description: Creates a manifest from a preprocessor definition. //////////////////////////////////////////////////////////////////// CPPManifest:: CPPManifest(const string &args, const cppyyltype &loc) : _variadic_param(-1), _loc(loc), - _expr((CPPExpression *)NULL) + _expr((CPPExpression *)NULL), + _vis(V_public) { assert(!args.empty()); assert(!isspace(args[0])); - _expr = (CPPExpression *)NULL; - _vis = V_public; - // First, identify the manifest name. - size_t p = 0; while (p < args.size() && !isspace(args[p]) && args[p] != '(') { p++; @@ -88,6 +85,51 @@ CPPManifest(const string &args, const cppyyltype &loc) : save_expansion(args.substr(p), parameter_names); } +//////////////////////////////////////////////////////////////////// +// Function: CPPManifest::Constructor +// Access: Public +// Description: Creates a custom manifest definition, for example +// as specified from a command-line -D option. +//////////////////////////////////////////////////////////////////// +CPPManifest:: +CPPManifest(const string ¯o, const string &definition) : + _variadic_param(-1), + _expr((CPPExpression *)NULL), + _vis(V_public) +{ + _loc.first_line = 0; + _loc.first_column = 0; + _loc.last_line = 0; + _loc.last_column = 0; + + assert(!macro.empty()); + assert(!isspace(macro[0])); + + // First, identify the manifest name. + size_t p = 0; + while (p < macro.size() && !isspace(macro[p]) && macro[p] != '(') { + p++; + } + + _name = macro.substr(0, p); + + vector_string parameter_names; + + if (macro[p] == '(') { + // Hmm, parameters. + _has_parameters = true; + parse_parameters(macro, p, parameter_names); + _num_parameters = parameter_names.size(); + + p++; + } else { + _has_parameters = false; + _num_parameters = 0; + } + + save_expansion(definition, parameter_names); +} + //////////////////////////////////////////////////////////////////// // Function: CPPManifest::Destructor // Access: Public diff --git a/dtool/src/cppparser/cppManifest.h b/dtool/src/cppparser/cppManifest.h index 549c50494f..3510fa14fe 100644 --- a/dtool/src/cppparser/cppManifest.h +++ b/dtool/src/cppparser/cppManifest.h @@ -32,7 +32,8 @@ class CPPType; //////////////////////////////////////////////////////////////////// class CPPManifest { public: - CPPManifest(const string &args, const cppyyltype &loc = {0}); + CPPManifest(const string &args, const cppyyltype &loc); + CPPManifest(const string ¯o, const string &definition); ~CPPManifest(); static string stringify(const string &source); diff --git a/dtool/src/interrogate/interrogate.cxx b/dtool/src/interrogate/interrogate.cxx index 7e7e6e8280..232f293a9b 100644 --- a/dtool/src/interrogate/interrogate.cxx +++ b/dtool/src/interrogate/interrogate.cxx @@ -300,7 +300,7 @@ predefine_macro(CPPParser& parser, const string& inoption) { macro_name = inoption; } - CPPManifest *macro = new CPPManifest(macro_name + " " + macro_def); + CPPManifest *macro = new CPPManifest(macro_name, macro_def); parser._manifests[macro->_name] = macro; } diff --git a/dtool/src/interrogate/parse_file.cxx b/dtool/src/interrogate/parse_file.cxx index 33d99917c6..938ca95731 100644 --- a/dtool/src/interrogate/parse_file.cxx +++ b/dtool/src/interrogate/parse_file.cxx @@ -41,7 +41,7 @@ predefine_macro(CPPParser &parser, const string &option) { cerr << "Predefining " << macro_name << " as " << macro_def << "\n"; - CPPManifest *macro = new CPPManifest(macro_name + " " + macro_def); + CPPManifest *macro = new CPPManifest(macro_name, macro_def); parser._manifests[macro->_name] = macro; }