Explorar el Código

*** empty log message ***

David Rose hace 25 años
padre
commit
3e5939ead1

+ 2 - 2
direct/src/dcparse/Makefile.gnu

@@ -1,12 +1,12 @@
 OFILES = \
   dcParser.o dcLexer.o \
-  dcAtomicField.o dcClass.o dcFile.o dcMolecularField.o \
+  dcAtomicField.o dcClass.o dcField.o dcFile.o dcMolecularField.o \
   dcSubatomicType.o indent.o \
   dcparse.o
 
 # Cheesy dependencies.
 HFILES = \
-  dcAtomicField.h dcClass.h dcClassDescription.h dcFile.h	\
+  dcAtomicField.h dcClass.h dcClassDescription.h dcField.h dcFile.h \
   dcLexerDefs.h dcMolecularField.h dcParser.h dcParserDefs.h	\
   dcSubatomicType.h dcbase.h indent.h
 

+ 1 - 1
direct/src/dcparse/Sources.pp

@@ -6,7 +6,7 @@
 
   #define SOURCES \
     dcAtomicField.cxx dcAtomicField.h dcClass.cxx dcClass.h \
-    dcFile.cxx dcFile.h dcLexer.lxx dcLexerDefs.h \
+    dcField.cxx dcField.h dcFile.cxx dcFile.h dcLexer.lxx dcLexerDefs.h \
     dcMolecularField.cxx dcMolecularField.h dcParser.yxx \
     dcParserDefs.h dcSubatomicType.cxx dcSubatomicType.h dcbase.h \
     indent.cxx indent.h

+ 8 - 0
direct/src/dcparse/dc.dsp

@@ -93,6 +93,10 @@ SOURCE=.\dcClass.cxx
 # End Source File
 # Begin Source File
 
+SOURCE=.\dcField.cxx
+# End Source File
+# Begin Source File
+
 SOURCE=.\dcFile.cxx
 # End Source File
 # Begin Source File
@@ -141,6 +145,10 @@ SOURCE=.\dcClassDescription.h
 # End Source File
 # Begin Source File
 
+SOURCE=.\dcField.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\dcFile.h
 # End Source File
 # Begin Source File

+ 10 - 20
direct/src/dcparse/dcAtomicField.cxx

@@ -18,25 +18,15 @@ operator << (ostream &out, const DCAtomicField::ElementType &et) {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: DCAtomicField::get_number
-//       Access: Public
-//  Description: Returns a unique index number associated with this
-//               field.  This is defined implicitly when the .dc
-//               file(s) are read.
-////////////////////////////////////////////////////////////////////
-int DCAtomicField::
-get_number() const {
-  return _number;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DCAtomicField::get_name
-//       Access: Public
-//  Description: Returns the name of this field.
+//     Function: DCAtomicField::as_atomic_field
+//       Access: Public, Virtual
+//  Description: Returns the same field pointer converted to an atomic
+//               field pointer, if this is in fact an atomic field;
+//               otherwise, returns NULL.
 ////////////////////////////////////////////////////////////////////
-string DCAtomicField::
-get_name() const {
-  return _name;
+DCAtomicField *DCAtomicField::
+as_atomic_field() {
+  return this;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -188,7 +178,7 @@ DCAtomicField() {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: DCAtomicField::write
-//       Access: Public
+//       Access: Public, Virtual
 //  Description: Generates a parseable description of the object to
 //               the indicated output stream.
 ////////////////////////////////////////////////////////////////////
@@ -236,5 +226,5 @@ write(ostream &out, int indent_level) const {
     out << " airecv";
   }
 
-  out << ";  // atomic " << _number << "\n";
+  out << ";  // field " << _number << "\n";
 }

+ 4 - 7
direct/src/dcparse/dcAtomicField.h

@@ -7,6 +7,7 @@
 #define DCATOMICFIELD_H
 
 #include "dcbase.h"
+#include "dcField.h"
 #include "dcSubatomicType.h"
 
 #include <vector>
@@ -18,10 +19,9 @@
 //               Distributed Class, and is always implemented as a
 //               remote procedure method.
 ////////////////////////////////////////////////////////////////////
-class DCAtomicField {
+class DCAtomicField : public DCField {
 PUBLISHED:
-  int get_number() const;
-  string get_name() const;
+  virtual DCAtomicField *as_atomic_field();
 
   int get_num_elements() const;
   DCSubatomicType get_element_type(int n) const;
@@ -39,14 +39,11 @@ PUBLISHED:
 
 public:
   DCAtomicField();
-  void write(ostream &out, int indent_level = 0) const;
+  virtual void write(ostream &out, int indent_level = 0) const;
 
 public:
   // These members define the primary interface to the atomic field
   // definition as read from the file.
-  int _number;
-  string _name;
-
   class ElementType {
   public:
     DCSubatomicType _type;

+ 47 - 168
direct/src/dcparse/dcClass.cxx

@@ -55,181 +55,92 @@ get_parent() const {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: DCClass::get_num_atomics
+//     Function: DCClass::get_num_fields
 //       Access: Public
-//  Description: Returns the number of atomic fields defined directly
-//               in this class, ignoring inheritance.
+//  Description: Returns the number of fields defined directly in this
+//               class, ignoring inheritance.
 ////////////////////////////////////////////////////////////////////
 int DCClass::
-get_num_atomics() {
-  return _atomic_fields.size();
+get_num_fields() {
+  return _fields.size();
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: DCClass::get_atomic
+//     Function: DCClass::get_field
 //       Access: Public
-//  Description: Returns the nth atomic field in the class.  This is
-//               not necessarily the field with index n; this is the
-//               nth field defined in the class directly, ignoring
+//  Description: Returns the nth field in the class.  This is not
+//               necessarily the field with index n; this is the nth
+//               field defined in the class directly, ignoring
 //               inheritance.
 ////////////////////////////////////////////////////////////////////
-DCAtomicField *DCClass::
-get_atomic(int n) {
-  assert(n >= 0 && n < (int)_atomic_fields.size());
-  return _atomic_fields[n];
+DCField *DCClass::
+get_field(int n) {
+  assert(n >= 0 && n < (int)_fields.size());
+  return _fields[n];
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: DCClass::get_atomic_by_name
+//     Function: DCClass::get_field_by_name
 //       Access: Public
-//  Description: Returns a pointer to the DCAtomicField that shares
-//               the indicated name.  If the named field is not found
-//               in the current class, the parent classes will be
+//  Description: Returns a pointer to the DCField that shares the
+//               indicated name.  If the named field is not found in
+//               the current class, the parent classes will be
 //               searched, so the value returned may not actually be a
 //               field within this class.  Returns NULL if there is no
 //               such field defined.
 ////////////////////////////////////////////////////////////////////
-DCAtomicField *DCClass::
-get_atomic_by_name(const string &name) {
-  AtomicsByName::const_iterator ni;
-  ni = _atomics_by_name.find(name);
-  if (ni != _atomics_by_name.end()) {
+DCField *DCClass::
+get_field_by_name(const string &name) {
+  FieldsByName::const_iterator ni;
+  ni = _fields_by_name.find(name);
+  if (ni != _fields_by_name.end()) {
     return (*ni).second;
   }
 
   // We didn't have such a field, so check our parents.
   Parents::iterator pi;
   for (pi = _parents.begin(); pi != _parents.end(); ++pi) {
-    DCAtomicField *result = (*pi)->get_atomic_by_name(name);
-    if (result != (DCAtomicField *)NULL) {
+    DCField *result = (*pi)->get_field_by_name(name);
+    if (result != (DCField *)NULL) {
       return result;
     }
   }
 
   // Nobody knew what this field is.
-  return (DCAtomicField *)NULL;
+  return (DCField *)NULL;
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: DCClass::get_num_inherited_atomics
+//     Function: DCClass::get_num_inherited_fields
 //       Access: Public
-//  Description: Returns the total number of atomic fields defined in
+//  Description: Returns the total number of field fields defined in
 //               this class and all ancestor classes.
 ////////////////////////////////////////////////////////////////////
 int DCClass::
-get_num_inherited_atomics() {
+get_num_inherited_fields() {
   if (!_parents.empty()) {
     // This won't work for multiple dclass inheritance.
-    return _parents.front()->get_num_atomics() + get_num_atomics();
+    return _parents.front()->get_num_fields() + get_num_fields();
   }
-  return get_num_atomics();
+  return get_num_fields();
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: DCClass::get_inherited_atomic
+//     Function: DCClass::get_inherited_field
 //       Access: Public
-//  Description: Returns the nth atomic field in the class and all of
+//  Description: Returns the nth field field in the class and all of
 //               its ancestors.  This *is* the field corresponding to
 //               the given index number, since the fields are ordered
 //               consecutively beginning at the earliest inherited
 //               fields.
 ////////////////////////////////////////////////////////////////////
-DCAtomicField *DCClass::
-get_inherited_atomic(int n) {
+DCField *DCClass::
+get_inherited_field(int n) {
   if (!_parents.empty()) {
     // This won't work for multiple dclass inheritance.
-    n -= _parents.front()->get_num_inherited_atomics();
+    n -= _parents.front()->get_num_inherited_fields();
   }
-  return get_atomic(n);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DCClass::get_num_moleculars
-//       Access: Public
-//  Description: Returns the number of molecular fields defined directly
-//               in this class, ignoring inheritance.
-////////////////////////////////////////////////////////////////////
-int DCClass::
-get_num_moleculars() {
-  return _molecular_fields.size();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DCClass::get_molecular
-//       Access: Public
-//  Description: Returns the nth molecular field in the class.  This is
-//               not necessarily the field with index n; this is the
-//               nth field defined in the class directly, ignoring
-//               inheritance.
-////////////////////////////////////////////////////////////////////
-DCMolecularField *DCClass::
-get_molecular(int n) {
-  assert(n >= 0 && n < (int)_molecular_fields.size());
-  return _molecular_fields[n];
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DCClass::get_molecular_by_name
-//       Access: Public
-//  Description: Returns a pointer to the DCMolecularField that shares
-//               the indicated name.  If the named field is not found
-//               in the current class, the parent classes will be
-//               searched, so the value returned may not actually be a
-//               field within this class.  Returns NULL if there is no
-//               such field defined.
-////////////////////////////////////////////////////////////////////
-DCMolecularField *DCClass::
-get_molecular_by_name(const string &name) {
-  MolecularsByName::const_iterator ni;
-  ni = _moleculars_by_name.find(name);
-  if (ni != _moleculars_by_name.end()) {
-    return (*ni).second;
-  }
-
-  // We didn't have such a field, so check our parents.
-  Parents::iterator pi;
-  for (pi = _parents.begin(); pi != _parents.end(); ++pi) {
-    DCMolecularField *result = (*pi)->get_molecular_by_name(name);
-    if (result != (DCMolecularField *)NULL) {
-      return result;
-    }
-  }
-
-  // Nobody knew what this field is.
-  return (DCMolecularField *)NULL;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DCClass::get_num_inherited_moleculars
-//       Access: Public
-//  Description: Returns the total number of molecular fields defined in
-//               this class and all ancestor classes.
-////////////////////////////////////////////////////////////////////
-int DCClass::
-get_num_inherited_moleculars() {
-  if (!_parents.empty()) {
-    // This won't work for multiple dclass inheritance.
-    return _parents.front()->get_num_moleculars() + get_num_moleculars();
-  }
-  return get_num_moleculars();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DCClass::get_inherited_molecular
-//       Access: Public
-//  Description: Returns the nth molecular field in the class and all of
-//               its ancestors.  This *is* the field corresponding to
-//               the given index number, since the fields are ordered
-//               consecutively beginning at the earliest inherited
-//               fields.
-////////////////////////////////////////////////////////////////////
-DCMolecularField *DCClass::
-get_inherited_molecular(int n) {
-  if (!_parents.empty()) {
-    // This won't work for multiple dclass inheritance.
-    n -= _parents.front()->get_num_inherited_moleculars();
-  }
-  return get_molecular(n);
+  return get_field(n);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -248,14 +159,10 @@ DCClass() {
 ////////////////////////////////////////////////////////////////////
 DCClass::
 ~DCClass() {
-  AtomicFields::iterator ai;
-  for (ai = _atomic_fields.begin(); ai != _atomic_fields.end(); ++ai) {
+  Fields::iterator ai;
+  for (ai = _fields.begin(); ai != _fields.end(); ++ai) {
     delete (*ai);
   }
-  MolecularFields::iterator mi;
-  for (mi = _molecular_fields.begin(); mi != _molecular_fields.end(); ++mi) {
-    delete (*mi);
-  }
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -280,61 +187,33 @@ write(ostream &out, int indent_level) const {
   }
   out << " {  // index " << _number << "\n";
 
-  AtomicFields::const_iterator ai;
-  for (ai = _atomic_fields.begin(); ai != _atomic_fields.end(); ++ai) {
+  Fields::const_iterator ai;
+  for (ai = _fields.begin(); ai != _fields.end(); ++ai) {
     (*ai)->write(out, indent_level + 2);
   }
 
-  MolecularFields::const_iterator mi;
-  for (mi = _molecular_fields.begin(); mi != _molecular_fields.end(); ++mi) {
-    (*mi)->write(out, indent_level + 2);
-  }
-
   indent(out, indent_level) << "};\n";
 }
 
 ////////////////////////////////////////////////////////////////////
 //     Function: DCClass::add_field
 //       Access: Public
-//  Description: Adds the newly-allocated atomic field to the class.
-//               The class becomes the owner of the pointer and will
-//               delete it when it destructs.  Returns true if the
-//               field is successfully added, or false if there was a
-//               name conflict.
-////////////////////////////////////////////////////////////////////
-bool DCClass::
-add_field(DCAtomicField *field) {
-  bool inserted = _atomics_by_name.insert
-    (AtomicsByName::value_type(field->_name, field)).second;
-
-  if (!inserted) {
-    return false;
-  }
-
-  field->_number = get_num_inherited_atomics();
-  _atomic_fields.push_back(field);
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DCClass::add_field
-//       Access: Public
-//  Description: Adds the newly-allocated molecular field to the class.
-//               The class becomes the owner of the pointer and will
+//  Description: Adds the newly-allocated field to the class.  The
+//               class becomes the owner of the pointer and will
 //               delete it when it destructs.  Returns true if the
 //               field is successfully added, or false if there was a
 //               name conflict.
 ////////////////////////////////////////////////////////////////////
 bool DCClass::
-add_field(DCMolecularField *field) {
-  bool inserted = _moleculars_by_name.insert
-    (MolecularsByName::value_type(field->_name, field)).second;
+add_field(DCField *field) {
+  bool inserted = _fields_by_name.insert
+    (FieldsByName::value_type(field->_name, field)).second;
 
   if (!inserted) {
     return false;
   }
 
-  field->_number = get_num_inherited_moleculars();
-  _molecular_fields.push_back(field);
+  field->_number = get_num_inherited_fields();
+  _fields.push_back(field);
   return true;
 }

+ 11 - 26
direct/src/dcparse/dcClass.h

@@ -7,8 +7,7 @@
 #define DCCLASS_H
 
 #include "dcbase.h"
-#include "dcAtomicField.h"
-#include "dcMolecularField.h"
+#include "dcField.h"
 
 #include <vector>
 #include <map>
@@ -26,27 +25,19 @@ PUBLISHED:
   bool has_parent() const;
   DCClass *get_parent() const;
 
-  int get_num_atomics();
-  DCAtomicField *get_atomic(int n);
-  DCAtomicField *get_atomic_by_name(const string &name);
+  int get_num_fields();
+  DCField *get_field(int n);
+  DCField *get_field_by_name(const string &name);
 
-  int get_num_inherited_atomics();
-  DCAtomicField *get_inherited_atomic(int n);
-
-  int get_num_moleculars();
-  DCMolecularField *get_molecular(int n);
-  DCMolecularField *get_molecular_by_name(const string &name);
-
-  int get_num_inherited_moleculars();
-  DCMolecularField *get_inherited_molecular(int n);
+  int get_num_inherited_fields();
+  DCField *get_inherited_field(int n);
 
 public:
   DCClass();
   ~DCClass();
 
   void write(ostream &out, int indent_level = 0) const;
-  bool add_field(DCAtomicField *field);
-  bool add_field(DCMolecularField *field);
+  bool add_field(DCField *field);
 
 public:
   // These members define the primary interface to the distributed
@@ -57,20 +48,14 @@ public:
   typedef vector<DCClass *> Parents;
   Parents _parents;
 
-  typedef vector<DCAtomicField *> AtomicFields;
-  AtomicFields _atomic_fields;
-
-  typedef vector<DCMolecularField *> MolecularFields;
-  MolecularFields _molecular_fields;
+  typedef vector<DCField *> Fields;
+  Fields _fields;
 
 public:
   // These members are built up during parsing for the convenience of
   // the parser.
-  typedef map<string, DCAtomicField *> AtomicsByName;
-  AtomicsByName _atomics_by_name;
-
-  typedef map<string, DCMolecularField *> MolecularsByName;
-  MolecularsByName _moleculars_by_name;
+  typedef map<string, DCField *> FieldsByName;
+  FieldsByName _fields_by_name;
 };
 
 #endif

+ 10 - 20
direct/src/dcparse/dcMolecularField.cxx

@@ -11,25 +11,15 @@
 
 
 ////////////////////////////////////////////////////////////////////
-//     Function: DCMolecularField::get_number
-//       Access: Public
-//  Description: Returns a unique index number associated with this
-//               field.  This is defined implicitly when the .dc
-//               file(s) are read.
-////////////////////////////////////////////////////////////////////
-int DCMolecularField::
-get_number() const {
-  return _number;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DCMolecularField::get_name
-//       Access: Public
-//  Description: Returns the name of this field.
+//     Function: DCMolecularField::as_molecular_field
+//       Access: Public, Virtual
+//  Description: Returns the same field pointer converted to a
+//               molecular field pointer, if this is in fact a
+//               molecular field; otherwise, returns NULL.
 ////////////////////////////////////////////////////////////////////
-string DCMolecularField::
-get_name() const {
-  return _name;
+DCMolecularField *DCMolecularField::
+as_molecular_field() {
+  return this;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -69,7 +59,7 @@ DCMolecularField() {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: DCMolecularField::write
-//       Access: Public
+//       Access: Public, Virtual
 //  Description: Generates a parseable description of the object to
 //               the indicated output stream.
 ////////////////////////////////////////////////////////////////////
@@ -87,6 +77,6 @@ write(ostream &out, int indent_level) const {
     }
   }
 
-  out << ";  // molecular " << _number << "\n";
+  out << ";  // field " << _number << "\n";
 }
 

+ 4 - 7
direct/src/dcparse/dcMolecularField.h

@@ -7,6 +7,7 @@
 #define DCMOLECULARFIELD_H
 
 #include "dcbase.h"
+#include "dcField.h"
 
 #include <vector>
 
@@ -19,24 +20,20 @@ class DCAtomicField;
 //               of two or more related atomic fields, that will often
 //               be treated as a unit.
 ////////////////////////////////////////////////////////////////////
-class DCMolecularField {
+class DCMolecularField : public DCField {
 PUBLISHED:
-  int get_number() const;
-  string get_name() const;
+  virtual DCMolecularField *as_molecular_field();
 
   int get_num_atomics() const;
   DCAtomicField *get_atomic(int n) const;
 
 public:
   DCMolecularField();
-  void write(ostream &out, int indent_level = 0) const;
+  virtual void write(ostream &out, int indent_level = 0) const;
 
 public:
   // These members define the primary interface to the molecular field
   // definition as read from the file.
-  int _number;
-  string _name;
-
   typedef vector<DCAtomicField *> Fields;
   Fields _fields;
 };

+ 17 - 5
direct/src/dcparse/dcParser.yxx

@@ -9,6 +9,7 @@
 #include "dcFile.h"
 #include "dcClass.h"
 #include "dcAtomicField.h"
+#include "dcMolecularField.h"
 
 // Because our token type contains objects of type string, which
 // require correct copy construction (and not simply memcpying), we
@@ -139,7 +140,7 @@ atomic_field:
   current_atomic = new DCAtomicField;
   current_atomic->_name = $1;
   if (!current_class->add_field(current_atomic)) {
-    yyerror("Duplicate atomic field name: " + current_atomic->_name);
+    yyerror("Duplicate field name: " + current_atomic->_name);
   }
 }
 	parameter_list ')' atomic_flags
@@ -148,9 +149,15 @@ atomic_field:
 atomic_name:
 	IDENTIFIER
 {
-  $$ = current_class->get_atomic_by_name($1);
-  if ($$ == (DCAtomicField *)NULL) {
-    yyerror("Unknown atomic field: " + $1);
+  DCField *field = current_class->get_field_by_name($1);
+  $$ = (DCAtomicField *)NULL;
+  if (field == (DCField *)NULL) {
+    yyerror("Unknown field: " + $1);
+  } else {
+    $$ = field->as_atomic_field();
+    if ($$ == (DCAtomicField *)NULL) {
+      yyerror("Not an atomic field: " + $1);
+    }
   }
 }
 
@@ -270,7 +277,7 @@ molecular_field:
   current_molecular = new DCMolecularField;
   current_molecular->_name = $1;
   if (!current_class->add_field(current_molecular)) {
-    yyerror("Duplicate molecular field name: " + current_molecular->_name);
+    yyerror("Duplicate field name: " + current_molecular->_name);
   }
 }
 	molecular_atom_list
@@ -287,6 +294,11 @@ molecular_atom_list:
 {
   if ($3 != (DCAtomicField *)NULL) {
     current_molecular->_fields.push_back($3);
+    if (current_molecular->_fields[0]->_flags != $3->_flags) {
+      yyerror("Mismatched flags in molecule between " + 
+	      current_molecular->_fields[0]->_name + " and " +
+	      $3->_name);
+    }
   }
 }
 	;

+ 1 - 1
direct/src/dcparse/test.dc

@@ -14,7 +14,7 @@ dclass Movable {
 dclass Attitude : Movable {
   // methods are inherited from parent class.
 
-  set_attitude(int8);
+  set_attitude(int8) required broadcast ram;
 
   // This molecular field uses some inherited atomic fields.
   set_xyzhprattitude : set_xyz, set_hpr, set_attitude;