Browse Source

reverse order of nested array brackets to match C convention

David Rose 21 years ago
parent
commit
33517c9c8d

+ 17 - 1
direct/src/dcparser/dcArrayParameter.cxx

@@ -154,6 +154,22 @@ get_array_size() const {
   return _array_size;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: DCArrayParameter::append_array_specification
+//       Access: Public, Virtual
+//  Description: Returns the type represented by this_type[size].  
+//
+//               In the case of a DCArrayParameter, this means it
+//               modifies the current type to append the array
+//               specification on the innermost type, and returns this
+//               same pointer again.
+////////////////////////////////////////////////////////////////////
+DCParameter *DCArrayParameter::
+append_array_specification(const DCUnsignedIntRange &size) {
+  _element_type = _element_type->append_array_specification(size);
+  return this;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: DCArrayParameter::calc_num_nested_fields
 //       Access: Public, Virtual
@@ -223,7 +239,7 @@ output_instance(ostream &out, bool brief, const string &prename,
     strm << "]";
     
     _element_type->output_instance(out, brief, prename, name, 
-                                   strm.str() + postname);
+                                   postname + strm.str());
   }
 }
 

+ 2 - 0
direct/src/dcparser/dcArrayParameter.h

@@ -47,6 +47,8 @@ PUBLISHED:
   int get_array_size() const;
 
 public:
+  virtual DCParameter *append_array_specification(const DCUnsignedIntRange &size);
+
   virtual int calc_num_nested_fields(size_t length_bytes) const;
   virtual DCPackerInterface *get_nested_field(int n) const;
   virtual bool validate_num_nested_fields(int num_nested_fields) const;

+ 14 - 1
direct/src/dcparser/dcParameter.cxx

@@ -17,11 +17,11 @@
 ////////////////////////////////////////////////////////////////////
 
 #include "dcParameter.h"
+#include "dcArrayParameter.h"
 #include "hashGenerator.h"
 #include "dcindent.h"
 #include "dcTypedef.h"
 
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DCParameter::Constructor
 //       Access: Protected
@@ -180,6 +180,19 @@ set_typedef(const DCTypedef *dtypedef) {
   _typedef = dtypedef;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: DCParameter::append_array_specification
+//       Access: Public, Virtual
+//  Description: Returns the type represented by this_type[size].  
+//
+//               In the case of a generic DCParameter, this means it
+//               returns a DCArrayParameter wrapped around this type.
+////////////////////////////////////////////////////////////////////
+DCParameter *DCParameter::
+append_array_specification(const DCUnsignedIntRange &size) {
+  return new DCArrayParameter(this, size);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: DCParameter::output
 //       Access: Public, Virtual

+ 2 - 0
direct/src/dcparser/dcParameter.h

@@ -21,6 +21,7 @@
 
 #include "dcbase.h"
 #include "dcField.h"
+#include "dcNumericRange.h"
 
 class DCSimpleParameter;
 class DCClassParameter;
@@ -65,6 +66,7 @@ PUBLISHED:
 
 public:
   void set_typedef(const DCTypedef *dtypedef);
+  virtual DCParameter *append_array_specification(const DCUnsignedIntRange &size);
 
   virtual void output(ostream &out, bool brief) const;
   virtual void write(ostream &out, bool brief, int indent_level) const;

+ 2 - 2
direct/src/dcparser/dcParser.yxx

@@ -810,7 +810,7 @@ type_definition:
   if ($1 == (DCParameter *)NULL) {
     $$ = NULL;
   } else {
-    $$ = new DCArrayParameter($1, uint_range);
+    $$ = $1->append_array_specification(uint_range);
   }
 }
 	;
@@ -853,7 +853,7 @@ parameter_definition:
 }
 	| parameter_definition '[' uint_range ']'
 {
-  $$ = new DCArrayParameter($1, uint_range);
+  $$ = $1->append_array_specification(uint_range);
 }
 	;