Browse Source

Fix issue building with pre-C++11 compiler

rdb 10 years ago
parent
commit
a43d6a45c1

+ 48 - 6
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 &macro, 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

+ 2 - 1
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 &macro, const string &definition);
   ~CPPManifest();
 
   static string stringify(const string &source);

+ 1 - 1
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;
 }
 

+ 1 - 1
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;
 }