From ac1f745525d5fec47deb32c1c1daee04c48796f5 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 17 Jun 2004 23:38:59 +0000 Subject: [PATCH] typedefs and arrays --- direct/src/dcparser/Sources.pp | 6 +- direct/src/dcparser/dcArrayParameter.cxx | 178 +++++ direct/src/dcparser/dcArrayParameter.h | 58 ++ direct/src/dcparser/dcAtomicField.cxx | 81 ++- direct/src/dcparser/dcAtomicField.h | 15 +- direct/src/dcparser/dcClass.cxx | 13 + direct/src/dcparser/dcClass.h | 15 +- direct/src/dcparser/dcField.cxx | 27 +- direct/src/dcparser/dcField.h | 3 - direct/src/dcparser/dcFile.cxx | 112 ++- direct/src/dcparser/dcFile.h | 30 +- direct/src/dcparser/dcLexer.cxx.prebuilt | 419 ++++++----- direct/src/dcparser/dcLexer.lxx | 5 + direct/src/dcparser/dcMolecularField.cxx | 19 +- direct/src/dcparser/dcMolecularField.h | 1 - direct/src/dcparser/dcPacker.cxx | 31 +- direct/src/dcparser/dcPackerInterface.cxx | 95 ++- direct/src/dcparser/dcPackerInterface.h | 23 +- direct/src/dcparser/dcParameter.cxx | 68 +- direct/src/dcparser/dcParameter.h | 28 +- direct/src/dcparser/dcParser.cxx.prebuilt | 749 +++++++++++--------- direct/src/dcparser/dcParser.h.prebuilt | 63 +- direct/src/dcparser/dcParser.yxx | 127 +++- direct/src/dcparser/dcSimpleParameter.cxx | 242 +++---- direct/src/dcparser/dcSimpleParameter.h | 20 +- direct/src/dcparser/dcTypedef.cxx | 127 ++++ direct/src/dcparser/dcTypedef.h | 53 ++ direct/src/dcparser/dcparser_composite1.cxx | 1 + direct/src/dcparser/dcparser_composite2.cxx | 3 +- 29 files changed, 1678 insertions(+), 934 deletions(-) create mode 100644 direct/src/dcparser/dcArrayParameter.cxx create mode 100644 direct/src/dcparser/dcArrayParameter.h create mode 100644 direct/src/dcparser/dcTypedef.cxx create mode 100644 direct/src/dcparser/dcTypedef.h diff --git a/direct/src/dcparser/Sources.pp b/direct/src/dcparser/Sources.pp index 8b207cc405..fac1cf4405 100644 --- a/direct/src/dcparser/Sources.pp +++ b/direct/src/dcparser/Sources.pp @@ -21,7 +21,8 @@ dcPackData.h dcPackData.I \ dcPacker.h dcPacker.I \ dcPackerInterface.h \ - dcParameter.h dcSimpleParameter.h \ + dcParameter.h dcArrayParameter.h dcSimpleParameter.h \ + dcTypedef.h \ dcbase.h dcindent.h hashGenerator.h \ primeNumberGenerator.h @@ -31,7 +32,8 @@ dcPackData.cxx \ dcPacker.cxx \ dcPackerInterface.cxx \ - dcParameter.cxx dcSimpleParameter.cxx \ + dcParameter.cxx dcArrayParameter.cxx dcSimpleParameter.cxx \ + dcTypedef.cxx \ dcindent.cxx \ hashGenerator.cxx primeNumberGenerator.cxx diff --git a/direct/src/dcparser/dcArrayParameter.cxx b/direct/src/dcparser/dcArrayParameter.cxx new file mode 100644 index 0000000000..3b992e05e3 --- /dev/null +++ b/direct/src/dcparser/dcArrayParameter.cxx @@ -0,0 +1,178 @@ +// Filename: dcArrayParameter.cxx +// Created by: drose (17Jun04) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#include "dcArrayParameter.h" +#include "hashGenerator.h" + +//////////////////////////////////////////////////////////////////// +// Function: DCArrayParameter::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +DCArrayParameter:: +DCArrayParameter(DCParameter *element_type, int array_size) : + _element_type(element_type), + _array_size(array_size) +{ + set_name(element_type->get_name()); + + if (_array_size >= 0 && _element_type->has_fixed_byte_size()) { + _has_fixed_byte_size = true; + _fixed_byte_size = _array_size * _element_type->get_fixed_byte_size(); + } + + _num_length_bytes = 2; + _has_nested_fields = true; + _num_nested_fields = _array_size; + _pack_type = PT_array; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCArrayParameter::Copy Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +DCArrayParameter:: +DCArrayParameter(const DCArrayParameter ©) : + DCParameter(copy), + _element_type(copy._element_type->make_copy()), + _array_size(copy._array_size) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: DCArrayParameter::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +DCArrayParameter:: +~DCArrayParameter() { + delete _element_type; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCArrayParameter::as_array_parameter +// Access: Published, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +DCArrayParameter *DCArrayParameter:: +as_array_parameter() { + return this; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCArrayParameter::make_copy +// Access: Published, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +DCParameter *DCArrayParameter:: +make_copy() const { + return new DCArrayParameter(*this); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCArrayParameter::get_element_type +// Access: Published +// Description: Returns the type of the individual elements of this +// array. +//////////////////////////////////////////////////////////////////// +DCParameter *DCArrayParameter:: +get_element_type() const { + return _element_type; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCArrayParameter::get_array_size +// Access: Published +// Description: Returns the fixed number of elements in this array, +// or -1 if the array may contain any number of +// elements. +//////////////////////////////////////////////////////////////////// +int DCArrayParameter:: +get_array_size() const { + return _array_size; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCArrayParameter::calc_num_nested_fields +// Access: Public, Virtual +// Description: This flavor of get_num_nested_fields is used during +// unpacking. It returns the number of nested fields to +// expect, given a certain length in bytes (as read from +// the get_num_length_bytes() stored in the stream on the +// pack). This will only be called if +// get_num_length_bytes() returns nonzero. +//////////////////////////////////////////////////////////////////// +int DCArrayParameter:: +calc_num_nested_fields(size_t length_bytes) const { + if (_element_type->has_fixed_byte_size()) { + return length_bytes / _element_type->get_fixed_byte_size(); + } + return -1; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCArrayParameter::get_nested_field +// Access: Public, Virtual +// Description: Returns the DCPackerInterface object that represents +// the nth nested field. This may return NULL if there +// is no such field (but it shouldn't do this if n is in +// the range 0 <= n < get_num_nested_fields()). +//////////////////////////////////////////////////////////////////// +DCPackerInterface *DCArrayParameter:: +get_nested_field(int) const { + return _element_type; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCArrayParameter::output_instance +// Access: Public, Virtual +// Description: Formats the parameter in the C++-like dc syntax as a +// typename and identifier. +//////////////////////////////////////////////////////////////////// +void DCArrayParameter:: +output_instance(ostream &out, const string &prename, const string &name, + const string &postname) const { + if (get_typedef() != (DCTypedef *)NULL) { + output_typedef_name(out, prename, name, postname); + + } else { + ostringstream strm; + + if (_array_size >= 0) { + strm << "[" << _array_size << "]"; + } else { + strm << "[]"; + } + + _element_type->output_instance(out, prename, name, strm.str() + postname); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: DCArrayParameter::generate_hash +// Access: Public, Virtual +// Description: Accumulates the properties of this type into the +// hash. +//////////////////////////////////////////////////////////////////// +void DCArrayParameter:: +generate_hash(HashGenerator &hashgen) const { + DCParameter::generate_hash(hashgen); + _element_type->generate_hash(hashgen); + hashgen.add_int(_array_size); +} diff --git a/direct/src/dcparser/dcArrayParameter.h b/direct/src/dcparser/dcArrayParameter.h new file mode 100644 index 0000000000..66dcf749e9 --- /dev/null +++ b/direct/src/dcparser/dcArrayParameter.h @@ -0,0 +1,58 @@ +// Filename: dcArrayParameter.h +// Created by: drose (17Jun04) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#ifndef DCARRAYPARAMETER_H +#define DCARRAYPARAMETER_H + +#include "dcbase.h" +#include "dcParameter.h" + +//////////////////////////////////////////////////////////////////// +// Class : DCArrayParameter +// Description : This represents an array of some other kind of +// object, meaning this parameter type accepts an +// arbitrary (or possibly fixed) number of nested +// fields, all of which are of the same type. +//////////////////////////////////////////////////////////////////// +class EXPCL_DIRECT DCArrayParameter : public DCParameter { +public: + DCArrayParameter(DCParameter *element_type, int array_size = -1); + DCArrayParameter(const DCArrayParameter ©); + ~DCArrayParameter(); + +PUBLISHED: + virtual DCArrayParameter *as_array_parameter(); + virtual DCParameter *make_copy() const; + + DCParameter *get_element_type() const; + int get_array_size() const; + +public: + virtual int calc_num_nested_fields(size_t length_bytes) const; + virtual DCPackerInterface *get_nested_field(int n) const; + + virtual void output_instance(ostream &out, const string &prename, + const string &name, const string &postname) const; + virtual void generate_hash(HashGenerator &hash) const; + +private: + DCParameter *_element_type; + int _array_size; +}; + +#endif diff --git a/direct/src/dcparser/dcAtomicField.cxx b/direct/src/dcparser/dcAtomicField.cxx index 0403ffe0e3..b1385c4399 100644 --- a/direct/src/dcparser/dcAtomicField.cxx +++ b/direct/src/dcparser/dcAtomicField.cxx @@ -104,7 +104,7 @@ output(ostream &out, bool brief) const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::as_atomic_field -// Access: Public, Virtual +// Access: Published, Virtual // Description: Returns the same field pointer converted to an atomic // field pointer, if this is in fact an atomic field; // otherwise, returns NULL. @@ -116,7 +116,7 @@ as_atomic_field() { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::get_num_elements -// Access: Public +// Access: Published // Description: Returns the number of elements (parameters) of the // atomic field. //////////////////////////////////////////////////////////////////// @@ -127,7 +127,7 @@ get_num_elements() const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::get_element -// Access: Public +// Access: Published // Description: Returns the parameter object describing the // nth element. //////////////////////////////////////////////////////////////////// @@ -139,7 +139,7 @@ get_element(int n) const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::get_element_default -// Access: Public +// Access: Published // Description: Returns the pre-formatted default value associated // with the nth element of the field. This is only // valid if has_element_default() returns true, in which @@ -160,7 +160,7 @@ get_element_default(int n) const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::has_element_default -// Access: Public +// Access: Published // Description: Returns true if the nth element of the field has a // default value specified, false otherwise. //////////////////////////////////////////////////////////////////// @@ -172,7 +172,7 @@ has_element_default(int n) const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::get_element_name -// Access: Public +// Access: Published // Description: Returns the name of the nth element of the field. // This name is strictly for documentary purposes; it // does not generally affect operation. If a name is @@ -189,7 +189,7 @@ get_element_name(int n) const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::get_element_type -// Access: Public +// Access: Published // Description: Returns the numeric type of the nth element of the // field. This method is deprecated; use // get_element() instead. @@ -204,7 +204,7 @@ get_element_type(int n) const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::get_element_divisor -// Access: Public +// Access: Published // Description: Returns the divisor associated with the nth element // of the field. This implements an implicit // fixed-point system; floating-point values are to be @@ -224,7 +224,7 @@ get_element_divisor(int n) const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::is_required -// Access: Public +// Access: Published // Description: Returns true if the "required" flag is set for this // field, false otherwise. //////////////////////////////////////////////////////////////////// @@ -235,7 +235,7 @@ is_required() const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::is_broadcast -// Access: Public +// Access: Published // Description: Returns true if the "broadcast" flag is set for this // field, false otherwise. //////////////////////////////////////////////////////////////////// @@ -246,7 +246,7 @@ is_broadcast() const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::is_p2p -// Access: Public +// Access: Published // Description: Returns true if the "p2p" flag is set for this // field, false otherwise. //////////////////////////////////////////////////////////////////// @@ -257,7 +257,7 @@ is_p2p() const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::is_ram -// Access: Public +// Access: Published // Description: Returns true if the "ram" flag is set for this // field, false otherwise. //////////////////////////////////////////////////////////////////// @@ -268,7 +268,7 @@ is_ram() const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::is_db -// Access: Public +// Access: Published // Description: Returns true if the "db" flag is set for this // field, false otherwise. //////////////////////////////////////////////////////////////////// @@ -279,7 +279,7 @@ is_db() const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::is_clsend -// Access: Public +// Access: Published // Description: Returns true if the "clsend" flag is set for this // field, false otherwise. //////////////////////////////////////////////////////////////////// @@ -290,7 +290,7 @@ is_clsend() const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::is_clrecv -// Access: Public +// Access: Published // Description: Returns true if the "clrecv" flag is set for this // field, false otherwise. //////////////////////////////////////////////////////////////////// @@ -301,7 +301,7 @@ is_clrecv() const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::is_ownsend -// Access: Public +// Access: Published // Description: Returns true if the "ownsend" flag is set for this // field, false otherwise. //////////////////////////////////////////////////////////////////// @@ -312,7 +312,7 @@ is_ownsend() const { //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::is_airecv -// Access: Public +// Access: Published // Description: Returns true if the "airecv" flag is set for this // field, false otherwise. //////////////////////////////////////////////////////////////////// @@ -321,6 +321,18 @@ is_airecv() const { return (_flags & F_airecv) != 0; } +//////////////////////////////////////////////////////////////////// +// Function: DCAtomicField::compare_flags +// Access: Published +// Description: Returns true if this field has the same flags +// settings as the other field, false if some flags +// differ. +//////////////////////////////////////////////////////////////////// +bool DCAtomicField:: +compare_flags(const DCAtomicField &other) const { + return _flags == other._flags; +} + //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::Constructor // Access: Public @@ -408,19 +420,6 @@ generate_hash(HashGenerator &hashgen) const { hashgen.add_int(_flags); } -//////////////////////////////////////////////////////////////////// -// Function: DCAtomicField::get_num_nested_fields -// Access: Public, Virtual -// Description: Returns the number of nested fields required by this -// field type. These may be array elements or structure -// elements. The return value may be -1 to indicate the -// number of nested fields is variable. -//////////////////////////////////////////////////////////////////// -int DCAtomicField:: -get_num_nested_fields() const { - return _elements.size(); -} - //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::get_nested_field // Access: Public, Virtual @@ -434,3 +433,25 @@ get_nested_field(int n) const { nassertr(n >= 0 && n < (int)_elements.size(), NULL); return _elements[n]._param; } + +//////////////////////////////////////////////////////////////////// +// Function: DCAtomicField::add_element +// Access: Public +// Description: Adds a new element (parameter) to the field. +// Normally this is called only during parsing. +//////////////////////////////////////////////////////////////////// +void DCAtomicField:: +add_element(const DCAtomicField::ElementType &element) { + _elements.push_back(element); + _num_nested_fields = (int)_elements.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCAtomicField::add_flag +// Access: Public +// Description: Adds a new flag to the field. +//////////////////////////////////////////////////////////////////// +void DCAtomicField:: +add_flag(enum Flags flag) { + _flags |= flag; +} diff --git a/direct/src/dcparser/dcAtomicField.h b/direct/src/dcparser/dcAtomicField.h index 17d6c99819..dd1f6879fa 100644 --- a/direct/src/dcparser/dcAtomicField.h +++ b/direct/src/dcparser/dcAtomicField.h @@ -59,17 +59,16 @@ PUBLISHED: bool is_ownsend() const; bool is_airecv() const; + bool compare_flags(const DCAtomicField &other) const; + public: DCAtomicField(const string &name); virtual void write(ostream &out, bool brief, int indent_level) const; virtual void generate_hash(HashGenerator &hash) const; - virtual int get_num_nested_fields() const; virtual DCPackerInterface *get_nested_field(int n) const; public: - // These members define the primary interface to the atomic field - // definition as read from the file. class ElementType { public: ElementType(DCParameter *param); @@ -86,9 +85,6 @@ public: bool _has_default_value; }; - typedef pvector Elements; - Elements _elements; - enum Flags { F_required = 0x0001, F_broadcast = 0x0002, @@ -101,6 +97,13 @@ public: F_airecv = 0x0100, }; + void add_element(const ElementType &element); + void add_flag(enum Flags flag); + +private: + typedef pvector Elements; + Elements _elements; + int _flags; // A bitmask union of any of the above values. }; diff --git a/direct/src/dcparser/dcClass.cxx b/direct/src/dcparser/dcClass.cxx index 4ecb9ef696..1a4352a51a 100644 --- a/direct/src/dcparser/dcClass.cxx +++ b/direct/src/dcparser/dcClass.cxx @@ -640,3 +640,16 @@ void DCClass:: add_parent(DCClass *parent) { _parents.push_back(parent); } + +//////////////////////////////////////////////////////////////////// +// Function: DCClass::set_number +// Access: Public +// Description: Assigns the unique number to this class. This is +// normally called only by the DCFile interface as the +// class is added. +//////////////////////////////////////////////////////////////////// +void DCClass:: +set_number(int number) { + _number = number; +} + diff --git a/direct/src/dcparser/dcClass.h b/direct/src/dcparser/dcClass.h index 6b49cd3112..a55bbf5b42 100644 --- a/direct/src/dcparser/dcClass.h +++ b/direct/src/dcparser/dcClass.h @@ -80,11 +80,9 @@ public: bool add_field(DCField *field); void add_parent(DCClass *parent); + void set_number(int number); private: - - // These members define the primary interface to the distributed - // class as read from the file. bool _bogus_class; int _number; @@ -94,17 +92,12 @@ private: typedef pvector Fields; Fields _fields; -#ifdef HAVE_PYTHON - PyObject *_class_def; -#endif - -public: - // These members are built up during parsing for the convenience of - // the parser. typedef pmap FieldsByName; FieldsByName _fields_by_name; - friend class DCFile; +#ifdef HAVE_PYTHON + PyObject *_class_def; +#endif }; #endif diff --git a/direct/src/dcparser/dcField.cxx b/direct/src/dcparser/dcField.cxx index 6c7cc3442b..188c9434d0 100644 --- a/direct/src/dcparser/dcField.cxx +++ b/direct/src/dcparser/dcField.cxx @@ -254,6 +254,9 @@ ai_format_update(int do_id, int to_id, int from_id, PyObject *args) const { DCField:: DCField(const string &name) : DCPackerInterface(name) { _number = 0; + _has_nested_fields = true; + _num_nested_fields = 0; + _pack_type = PT_field; } //////////////////////////////////////////////////////////////////// @@ -279,27 +282,3 @@ generate_hash(HashGenerator &hashgen) const { // redundant. However, the field name is significant. hashgen.add_string(_name); } - -//////////////////////////////////////////////////////////////////// -// Function: DCField::has_nested_fields -// Access: Public, Virtual -// Description: Returns true if this field type has any nested fields -// (and thus expects a push() .. pop() interface to the -// DCPacker), or false otherwise. If this returns true, -// get_num_nested_fields() may be called to determine -// how many nested fields are expected. -//////////////////////////////////////////////////////////////////// -bool DCField:: -has_nested_fields() const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: DCField::get_pack_type -// Access: Public, Virtual -// Description: Returns the type of value expected by this field. -//////////////////////////////////////////////////////////////////// -DCPackType DCField:: -get_pack_type() const { - return PT_field; -} diff --git a/direct/src/dcparser/dcField.h b/direct/src/dcparser/dcField.h index c451afc84d..61a54661e2 100644 --- a/direct/src/dcparser/dcField.h +++ b/direct/src/dcparser/dcField.h @@ -68,9 +68,6 @@ public: virtual void write(ostream &out, bool brief, int indent_level) const=0; virtual void generate_hash(HashGenerator &hash) const; - virtual bool has_nested_fields() const; - virtual DCPackType get_pack_type() const; - protected: int _number; diff --git a/direct/src/dcparser/dcFile.cxx b/direct/src/dcparser/dcFile.cxx index 1f138ada41..8006c06a5a 100644 --- a/direct/src/dcparser/dcFile.cxx +++ b/direct/src/dcparser/dcFile.cxx @@ -19,6 +19,7 @@ #include "dcFile.h" #include "dcParserDefs.h" #include "dcLexerDefs.h" +#include "dcTypedef.h" #include "hashGenerator.h" #ifdef WITHIN_PANDA @@ -212,24 +213,34 @@ write(Filename filename, bool brief) const { //////////////////////////////////////////////////////////////////// bool DCFile:: write(ostream &out, bool brief) const { - Imports::const_iterator ii; - for (ii = _imports.begin(); ii != _imports.end(); ++ii) { - const Import &import = (*ii); - if (import._symbols.empty()) { - out << "import " << import._module << "\n"; - } else { - out << "from " << import._module << " import "; - ImportSymbols::const_iterator si = import._symbols.begin(); - out << *si; - ++si; - while (si != import._symbols.end()) { - out << ", " << *si; + if (!_imports.empty()) { + Imports::const_iterator ii; + for (ii = _imports.begin(); ii != _imports.end(); ++ii) { + const Import &import = (*ii); + if (import._symbols.empty()) { + out << "import " << import._module << "\n"; + } else { + out << "from " << import._module << " import "; + ImportSymbols::const_iterator si = import._symbols.begin(); + out << *si; ++si; + while (si != import._symbols.end()) { + out << ", " << *si; + ++si; + } + out << "\n"; } - out << "\n"; } + out << "\n"; + } + + if (!_typedefs.empty()) { + Typedefs::const_iterator ti; + for (ti = _typedefs.begin(); ti != _typedefs.end(); ++ti) { + (*ti)->write(out, brief, 0); + } + out << "\n"; } - out << "\n"; Classes::const_iterator ci; for (ci = _classes.begin(); ci != _classes.end(); ++ci) { @@ -249,7 +260,7 @@ write(ostream &out, bool brief) const { // file(s). //////////////////////////////////////////////////////////////////// int DCFile:: -get_num_classes() { +get_num_classes() const { return _classes.size(); } @@ -259,7 +270,7 @@ get_num_classes() { // Description: Returns the nth class read from the .dc file(s). //////////////////////////////////////////////////////////////////// DCClass *DCFile:: -get_class(int n) { +get_class(int n) const { nassertr(n >= 0 && n < (int)_classes.size(), NULL); return _classes[n]; } @@ -271,7 +282,7 @@ get_class(int n) { // NULL if there is no such class. //////////////////////////////////////////////////////////////////// DCClass *DCFile:: -get_class_by_name(const string &name) { +get_class_by_name(const string &name) const { ClassesByName::const_iterator ni; ni = _classes_by_name.find(name); if (ni != _classes_by_name.end()) { @@ -344,6 +355,45 @@ get_import_symbol(int n, int i) const { return _imports[n]._symbols[i]; } +//////////////////////////////////////////////////////////////////// +// Function: DCFile::get_num_typedefs +// Access: Published +// Description: Returns the number of typedefs read from the .dc +// file(s). +//////////////////////////////////////////////////////////////////// +int DCFile:: +get_num_typedefs() const { + return _typedefs.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCFile::get_typedef +// Access: Published +// Description: Returns the nth typedef read from the .dc file(s). +//////////////////////////////////////////////////////////////////// +DCTypedef *DCFile:: +get_typedef(int n) const { + nassertr(n >= 0 && n < (int)_typedefs.size(), NULL); + return _typedefs[n]; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCFile::get_typedef_by_name +// Access: Published +// Description: Returns the typedef that has the indicated name, or +// NULL if there is no such typedef name. +//////////////////////////////////////////////////////////////////// +DCTypedef *DCFile:: +get_typedef_by_name(const string &name) const { + TypedefsByName::const_iterator ni; + ni = _typedefs_by_name.find(name); + if (ni != _typedefs_by_name.end()) { + return (*ni).second; + } + + return NULL; +} + //////////////////////////////////////////////////////////////////// // Function: DCFile::get_hash // Access: Published @@ -387,13 +437,13 @@ generate_hash(HashGenerator &hashgen) const { bool DCFile:: add_class(DCClass *dclass) { bool inserted = _classes_by_name.insert - (ClassesByName::value_type(dclass->_name, dclass)).second; + (ClassesByName::value_type(dclass->get_name(), dclass)).second; if (!inserted) { return false; } - dclass->_number = get_num_classes(); + dclass->set_number(get_num_classes()); _classes.push_back(dclass); if (dclass->is_bogus_class()) { @@ -432,3 +482,27 @@ add_import_symbol(const string &import_symbol) { nassertv(!_imports.empty()); _imports.back()._symbols.push_back(import_symbol); } + +//////////////////////////////////////////////////////////////////// +// Function: DCFile::add_typedef +// Access: Public +// Description: Adds the newly-allocated distributed typedef definition +// to the file. The DCFile becomes the owner of the +// pointer and will delete it when it destructs. +// Returns true if the typedef is successfully added, or +// false if there was a name conflict. +//////////////////////////////////////////////////////////////////// +bool DCFile:: +add_typedef(DCTypedef *dtypedef) { + bool inserted = _typedefs_by_name.insert + (TypedefsByName::value_type(dtypedef->get_name(), dtypedef)).second; + + if (!inserted) { + return false; + } + + dtypedef->set_number(get_num_typedefs()); + _typedefs.push_back(dtypedef); + + return true; +} diff --git a/direct/src/dcparser/dcFile.h b/direct/src/dcparser/dcFile.h index c27c5aa719..93900704dd 100644 --- a/direct/src/dcparser/dcFile.h +++ b/direct/src/dcparser/dcFile.h @@ -23,6 +23,7 @@ #include "dcClass.h" class HashGenerator; +class DCTypedef; //////////////////////////////////////////////////////////////////// // Class : DCFile @@ -46,9 +47,9 @@ PUBLISHED: bool write(Filename filename, bool brief) const; bool write(ostream &out, bool brief) const; - int get_num_classes(); - DCClass *get_class(int n); - DCClass *get_class_by_name(const string &name); + int get_num_classes() const; + DCClass *get_class(int n) const; + DCClass *get_class_by_name(const string &name) const; bool all_classes_valid() const; @@ -57,6 +58,10 @@ PUBLISHED: int get_num_import_symbols(int n) const; string get_import_symbol(int n, int i) const; + int get_num_typedefs() const; + DCTypedef *get_typedef(int n) const; + DCTypedef *get_typedef_by_name(const string &name) const; + unsigned long get_hash() const; public: @@ -64,13 +69,15 @@ public: bool add_class(DCClass *dclass); void add_import_module(const string &import_module); void add_import_symbol(const string &import_symbol); + bool add_typedef(DCTypedef *dtypedef); -public: - // This vector is the primary interface to the distributed classes - // read from the file. +private: typedef pvector Classes; Classes _classes; + typedef pmap ClassesByName; + ClassesByName _classes_by_name; + typedef pvector ImportSymbols; class Import { public: @@ -81,12 +88,13 @@ public: typedef pvector Imports; Imports _imports; - bool _all_classes_valid; + typedef pvector Typedefs; + Typedefs _typedefs; -public: - // This map is built up during parsing for the convenience of the parser. - typedef pmap ClassesByName; - ClassesByName _classes_by_name; + typedef pmap TypedefsByName; + TypedefsByName _typedefs_by_name; + + bool _all_classes_valid; }; #endif diff --git a/direct/src/dcparser/dcLexer.cxx.prebuilt b/direct/src/dcparser/dcLexer.cxx.prebuilt index a180c75a2f..1d59024c5a 100644 --- a/direct/src/dcparser/dcLexer.cxx.prebuilt +++ b/direct/src/dcparser/dcLexer.cxx.prebuilt @@ -300,29 +300,29 @@ static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); *yy_cp = '\0'; \ yy_c_buf_p = yy_cp; -#define YY_NUM_RULES 44 -#define YY_END_OF_BUFFER 45 -static yyconst short int yy_accept[173] = +#define YY_NUM_RULES 45 +#define YY_END_OF_BUFFER 46 +static yyconst short int yy_accept[180] = { 0, - 0, 0, 45, 43, 2, 1, 40, 43, 43, 43, - 37, 37, 41, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 1, 0, 37, 39, - 4, 3, 39, 38, 42, 42, 42, 42, 42, 32, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 0, 3, 38, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 30, 31, 42, - 42, 42, 0, 39, 42, 18, 42, 42, 42, 42, - 42, 6, 42, 42, 42, 42, 8, 27, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 0, 0, 46, 44, 2, 1, 41, 44, 44, 44, + 38, 38, 42, 43, 43, 43, 43, 43, 43, 43, + 43, 43, 43, 43, 43, 43, 43, 1, 0, 38, + 40, 4, 3, 40, 39, 43, 43, 43, 43, 43, + 33, 43, 43, 43, 43, 43, 43, 43, 43, 43, + 43, 43, 43, 43, 0, 3, 39, 43, 43, 43, + 43, 43, 43, 43, 43, 43, 43, 43, 43, 31, + 32, 43, 43, 43, 43, 0, 40, 43, 19, 43, + 43, 43, 43, 43, 6, 43, 43, 43, 43, 9, + 28, 43, 43, 43, 43, 43, 43, 43, 43, 43, - 9, 10, 11, 42, 42, 42, 42, 42, 42, 42, - 12, 36, 19, 42, 34, 33, 5, 42, 7, 42, - 42, 42, 42, 42, 17, 13, 14, 15, 42, 42, - 16, 42, 42, 42, 35, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 28, 42, 42, 42, 42, 29, - 42, 42, 20, 42, 42, 42, 42, 21, 22, 42, - 42, 42, 23, 24, 25, 42, 42, 42, 42, 42, - 26, 0 + 43, 43, 43, 43, 10, 11, 12, 43, 43, 43, + 43, 43, 43, 43, 43, 13, 37, 20, 43, 35, + 34, 5, 43, 7, 43, 43, 43, 43, 43, 18, + 43, 14, 15, 16, 43, 43, 17, 43, 43, 43, + 36, 43, 8, 43, 43, 43, 43, 43, 43, 43, + 43, 29, 43, 43, 43, 43, 30, 43, 43, 21, + 43, 43, 43, 43, 22, 23, 43, 43, 43, 24, + 25, 26, 43, 43, 43, 43, 43, 27, 0 } ; static yyconst int yy_ec[256] = @@ -366,114 +366,118 @@ static yyconst int yy_meta[43] = 7, 7 } ; -static yyconst short int yy_base[180] = +static yyconst short int yy_base[187] = { 0, - 0, 0, 215, 216, 216, 0, 216, 207, 0, 38, - 37, 206, 216, 0, 184, 16, 182, 25, 20, 22, - 178, 169, 197, 29, 170, 178, 0, 0, 198, 37, - 216, 0, 0, 0, 0, 169, 171, 170, 22, 0, - 172, 168, 167, 165, 160, 167, 164, 161, 163, 158, - 156, 159, 183, 0, 0, 163, 165, 165, 160, 159, - 162, 161, 151, 148, 49, 70, 143, 0, 0, 140, - 149, 139, 169, 168, 150, 160, 147, 147, 138, 132, - 130, 0, 131, 150, 153, 150, 141, 0, 136, 132, - 128, 56, 119, 146, 133, 116, 130, 117, 137, 114, + 0, 0, 221, 222, 222, 0, 222, 213, 0, 38, + 37, 212, 222, 0, 190, 16, 188, 25, 20, 22, + 184, 175, 203, 29, 176, 170, 183, 0, 0, 203, + 37, 222, 0, 0, 0, 0, 174, 176, 175, 22, + 0, 177, 173, 172, 170, 165, 172, 169, 166, 168, + 163, 161, 162, 163, 187, 0, 0, 167, 169, 169, + 164, 163, 166, 165, 155, 152, 49, 70, 147, 0, + 0, 144, 153, 155, 142, 172, 171, 153, 163, 150, + 150, 141, 135, 133, 0, 134, 153, 156, 153, 144, + 0, 139, 135, 131, 137, 56, 121, 148, 135, 118, - 129, 128, 0, 113, 116, 111, 118, 129, 132, 129, - 120, 0, 0, 119, 0, 0, 0, 126, 0, 103, - 102, 101, 111, 109, 0, 112, 39, 0, 97, 95, - 0, 95, 94, 107, 0, 103, 91, 90, 96, 88, - 85, 100, 99, 77, 0, 83, 82, 85, 94, 0, - 72, 71, 0, 91, 90, 72, 58, 0, 0, 46, - 34, 59, 0, 0, 0, 53, 38, 35, 48, 25, - 0, 216, 86, 90, 58, 91, 98, 101, 105 + 132, 119, 139, 116, 131, 130, 0, 115, 118, 113, + 120, 121, 130, 133, 130, 121, 0, 0, 120, 0, + 0, 0, 127, 0, 104, 103, 102, 112, 110, 0, + 108, 112, 39, 0, 97, 95, 0, 95, 94, 107, + 0, 103, 0, 91, 90, 96, 88, 85, 100, 99, + 77, 0, 83, 82, 85, 94, 0, 72, 71, 0, + 91, 90, 72, 58, 0, 0, 46, 34, 59, 0, + 0, 0, 53, 38, 35, 48, 25, 0, 222, 86, + 90, 58, 91, 98, 101, 105 } ; -static yyconst short int yy_def[180] = +static yyconst short int yy_def[187] = { 0, - 172, 1, 172, 172, 172, 173, 172, 174, 175, 172, - 174, 174, 172, 176, 176, 176, 176, 176, 176, 176, - 176, 176, 176, 176, 176, 176, 173, 175, 174, 175, - 172, 177, 30, 178, 176, 176, 176, 176, 176, 176, - 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, - 176, 176, 179, 177, 178, 176, 176, 176, 176, 176, - 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, - 176, 176, 179, 179, 176, 176, 176, 176, 176, 176, - 176, 176, 176, 176, 176, 176, 176, 66, 176, 176, - 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, + 179, 1, 179, 179, 179, 180, 179, 181, 182, 179, + 181, 181, 179, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 180, 182, 181, + 182, 179, 184, 31, 185, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 186, 184, 185, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 186, 186, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 68, 183, 183, 183, 183, 183, 183, 183, 183, 183, - 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, - 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, - 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, - 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, - 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, - 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, - 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, - 176, 0, 172, 172, 172, 172, 172, 172, 172 + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 0, 179, + 179, 179, 179, 179, 179, 179 } ; -static yyconst short int yy_nxt[259] = +static yyconst short int yy_nxt[265] = { 0, 4, 5, 6, 7, 4, 8, 9, 10, 11, 12, 12, 12, 12, 12, 12, 12, 13, 14, 14, 14, 15, 16, 17, 18, 14, 19, 14, 20, 14, 21, - 14, 22, 23, 14, 24, 25, 14, 26, 14, 14, - 14, 14, 31, 33, 37, 32, 40, 41, 42, 49, - 38, 44, 45, 50, 43, 53, 59, 60, 84, 138, - 85, 53, 30, 86, 87, 108, 171, 109, 170, 169, - 110, 111, 168, 167, 166, 165, 139, 34, 88, 88, - 88, 88, 88, 88, 88, 88, 27, 164, 27, 27, - 27, 27, 27, 29, 29, 35, 35, 35, 54, 163, + 14, 22, 23, 14, 24, 25, 26, 27, 14, 14, + 14, 14, 32, 34, 38, 33, 41, 42, 43, 50, + 39, 45, 46, 51, 44, 55, 61, 62, 87, 145, + 88, 55, 31, 89, 90, 113, 178, 114, 177, 176, + 115, 116, 175, 174, 173, 172, 146, 35, 91, 91, + 91, 91, 91, 91, 91, 91, 28, 171, 28, 28, + 28, 28, 28, 30, 30, 36, 36, 36, 56, 170, - 54, 54, 54, 54, 54, 55, 55, 74, 162, 74, - 161, 160, 159, 158, 157, 156, 155, 154, 153, 152, - 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, - 141, 140, 137, 136, 135, 134, 133, 132, 131, 130, - 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, - 119, 118, 117, 116, 115, 114, 113, 112, 107, 106, - 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, - 95, 94, 93, 172, 172, 92, 91, 90, 89, 83, - 82, 81, 80, 79, 78, 77, 76, 75, 73, 72, - 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, + 56, 56, 56, 56, 56, 57, 57, 77, 169, 77, + 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, + 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, + 148, 147, 144, 143, 142, 141, 140, 139, 138, 137, + 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, + 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, + 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, + 102, 101, 100, 99, 98, 97, 179, 179, 96, 95, + 94, 93, 92, 86, 85, 84, 83, 82, 81, 80, + 79, 78, 76, 75, 74, 73, 72, 71, 70, 69, - 61, 58, 57, 56, 33, 52, 51, 48, 47, 46, - 39, 36, 33, 28, 172, 3, 172, 172, 172, 172, - 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, - 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, - 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, - 172, 172, 172, 172, 172, 172, 172, 172 + 68, 67, 66, 65, 64, 63, 60, 59, 58, 34, + 54, 53, 52, 49, 48, 47, 40, 37, 34, 29, + 179, 3, 179, 179, 179, 179, 179, 179, 179, 179, + 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, + 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, + 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, + 179, 179, 179, 179 } ; -static yyconst short int yy_chk[259] = +static yyconst short int yy_chk[265] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 11, 16, 10, 18, 18, 19, 24, - 16, 20, 20, 24, 19, 30, 39, 39, 65, 127, - 65, 30, 175, 65, 65, 92, 170, 92, 169, 168, - 92, 92, 167, 166, 162, 161, 127, 11, 66, 66, - 66, 66, 66, 66, 66, 66, 173, 160, 173, 173, - 173, 173, 173, 174, 174, 176, 176, 176, 177, 157, + 16, 20, 20, 24, 19, 31, 40, 40, 67, 133, + 67, 31, 182, 67, 67, 96, 177, 96, 176, 175, + 96, 96, 174, 173, 169, 168, 133, 11, 68, 68, + 68, 68, 68, 68, 68, 68, 180, 167, 180, 180, + 180, 180, 180, 181, 181, 183, 183, 183, 184, 164, - 177, 177, 177, 177, 177, 178, 178, 179, 156, 179, - 155, 154, 152, 151, 149, 148, 147, 146, 144, 143, - 142, 141, 140, 139, 138, 137, 136, 134, 133, 132, - 130, 129, 126, 124, 123, 122, 121, 120, 118, 114, - 111, 110, 109, 108, 107, 106, 105, 104, 102, 101, - 100, 99, 98, 97, 96, 95, 94, 93, 91, 90, - 89, 87, 86, 85, 84, 83, 81, 80, 79, 78, - 77, 76, 75, 74, 73, 72, 71, 70, 67, 64, - 63, 62, 61, 60, 59, 58, 57, 56, 53, 52, - 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, + 184, 184, 184, 184, 184, 185, 185, 186, 163, 186, + 162, 161, 159, 158, 156, 155, 154, 153, 151, 150, + 149, 148, 147, 146, 145, 144, 142, 140, 139, 138, + 136, 135, 132, 131, 129, 128, 127, 126, 125, 123, + 119, 116, 115, 114, 113, 112, 111, 110, 109, 108, + 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, + 95, 94, 93, 92, 90, 89, 88, 87, 86, 84, + 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, + 73, 72, 69, 66, 65, 64, 63, 62, 61, 60, + 59, 58, 55, 54, 53, 52, 51, 50, 49, 48, - 41, 38, 37, 36, 29, 26, 25, 23, 22, 21, - 17, 15, 12, 8, 3, 172, 172, 172, 172, 172, - 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, - 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, - 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, - 172, 172, 172, 172, 172, 172, 172, 172 + 47, 46, 45, 44, 43, 42, 39, 38, 37, 30, + 27, 26, 25, 23, 22, 21, 17, 15, 12, 8, + 3, 179, 179, 179, 179, 179, 179, 179, 179, 179, + 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, + 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, + 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, + 179, 179, 179, 179 } ; static yy_state_type yy_last_accepting_state; @@ -529,6 +533,10 @@ static istream *inp = NULL; // can print it out for error messages. static string dc_filename; +// This is the initial token state returned by the lexer. It allows +// the yacc grammar to start from initial points. +static int initial_token; + //////////////////////////////////////////////////////////////////// // Defining the interface to the lexer. @@ -542,6 +550,14 @@ dc_init_lexer(istream &in, const string &filename) { col_number = 0; error_count = 0; warning_count = 0; + initial_token = START_DC; +} + +void +dc_start_parameter_value() { + /* Set the initial state to begin parsing a parameter value, instead + of at the beginning of the dc file. */ + initial_token = START_PARAMETER_VALUE; } int @@ -776,7 +792,7 @@ inline void accept() { col_number += yyleng; } -#line 781 "lex.yy.c" +#line 797 "lex.yy.c" /* Macros after this point can all be overridden by user definitions in * section 1. @@ -927,13 +943,18 @@ YY_DECL register char *yy_cp = NULL, *yy_bp = NULL; register int yy_act; -#line 295 "dcLexer.lxx" +#line 307 "dcLexer.lxx" + if (initial_token != 0) { + int t = initial_token; + initial_token = 0; + return t; + } -#line 938 "lex.yy.c" +#line 959 "lex.yy.c" if ( yy_init ) { @@ -984,13 +1005,13 @@ yy_match: while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 173 ) + if ( yy_current_state >= 180 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } - while ( yy_base[yy_current_state] != 216 ); + while ( yy_base[yy_current_state] != 222 ); yy_find_action: yy_act = yy_accept[yy_current_state]; @@ -1018,7 +1039,7 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 300 "dcLexer.lxx" +#line 317 "dcLexer.lxx" { // New line. Save a copy of the line so we can print it out for the // benefit of the user in case we get an error. @@ -1035,7 +1056,7 @@ YY_RULE_SETUP YY_BREAK case 2: YY_RULE_SETUP -#line 314 "dcLexer.lxx" +#line 331 "dcLexer.lxx" { // Eat whitespace. accept(); @@ -1043,7 +1064,7 @@ YY_RULE_SETUP YY_BREAK case 3: YY_RULE_SETUP -#line 319 "dcLexer.lxx" +#line 336 "dcLexer.lxx" { // Eat C++-style comments. accept(); @@ -1051,7 +1072,7 @@ YY_RULE_SETUP YY_BREAK case 4: YY_RULE_SETUP -#line 324 "dcLexer.lxx" +#line 341 "dcLexer.lxx" { // Eat C-style comments. accept(); @@ -1060,7 +1081,7 @@ YY_RULE_SETUP YY_BREAK case 5: YY_RULE_SETUP -#line 331 "dcLexer.lxx" +#line 348 "dcLexer.lxx" { accept(); return KW_DCLASS; @@ -1068,7 +1089,7 @@ YY_RULE_SETUP YY_BREAK case 6: YY_RULE_SETUP -#line 336 "dcLexer.lxx" +#line 353 "dcLexer.lxx" { accept(); return KW_FROM; @@ -1076,7 +1097,7 @@ YY_RULE_SETUP YY_BREAK case 7: YY_RULE_SETUP -#line 341 "dcLexer.lxx" +#line 358 "dcLexer.lxx" { accept(); return KW_IMPORT; @@ -1084,159 +1105,167 @@ YY_RULE_SETUP YY_BREAK case 8: YY_RULE_SETUP -#line 346 "dcLexer.lxx" +#line 363 "dcLexer.lxx" +{ + accept(); + return KW_TYPEDEF; +} + YY_BREAK +case 9: +YY_RULE_SETUP +#line 368 "dcLexer.lxx" { accept(); return KW_INT8; } YY_BREAK -case 9: +case 10: YY_RULE_SETUP -#line 351 "dcLexer.lxx" +#line 373 "dcLexer.lxx" { accept(); return KW_INT16; } YY_BREAK -case 10: +case 11: YY_RULE_SETUP -#line 356 "dcLexer.lxx" +#line 378 "dcLexer.lxx" { accept(); return KW_INT32; } YY_BREAK -case 11: +case 12: YY_RULE_SETUP -#line 361 "dcLexer.lxx" +#line 383 "dcLexer.lxx" { accept(); return KW_INT64; } YY_BREAK -case 12: +case 13: YY_RULE_SETUP -#line 366 "dcLexer.lxx" +#line 388 "dcLexer.lxx" { accept(); return KW_UINT8; } YY_BREAK -case 13: +case 14: YY_RULE_SETUP -#line 371 "dcLexer.lxx" +#line 393 "dcLexer.lxx" { accept(); return KW_UINT16; } YY_BREAK -case 14: +case 15: YY_RULE_SETUP -#line 376 "dcLexer.lxx" +#line 398 "dcLexer.lxx" { accept(); return KW_UINT32; } YY_BREAK -case 15: +case 16: YY_RULE_SETUP -#line 381 "dcLexer.lxx" +#line 403 "dcLexer.lxx" { accept(); return KW_UINT64; } YY_BREAK -case 16: +case 17: YY_RULE_SETUP -#line 386 "dcLexer.lxx" +#line 408 "dcLexer.lxx" { accept(); return KW_FLOAT64; } YY_BREAK -case 17: +case 18: YY_RULE_SETUP -#line 391 "dcLexer.lxx" +#line 413 "dcLexer.lxx" { accept(); return KW_STRING; } YY_BREAK -case 18: +case 19: YY_RULE_SETUP -#line 396 "dcLexer.lxx" +#line 418 "dcLexer.lxx" { accept(); return KW_BLOB; } YY_BREAK -case 19: +case 20: YY_RULE_SETUP -#line 401 "dcLexer.lxx" +#line 423 "dcLexer.lxx" { accept(); return KW_BLOB32; } YY_BREAK -case 20: +case 21: YY_RULE_SETUP -#line 406 "dcLexer.lxx" +#line 428 "dcLexer.lxx" { accept(); return KW_INT8ARRAY; } YY_BREAK -case 21: +case 22: YY_RULE_SETUP -#line 411 "dcLexer.lxx" +#line 433 "dcLexer.lxx" { accept(); return KW_INT16ARRAY; } YY_BREAK -case 22: +case 23: YY_RULE_SETUP -#line 416 "dcLexer.lxx" +#line 438 "dcLexer.lxx" { accept(); return KW_INT32ARRAY; } YY_BREAK -case 23: +case 24: YY_RULE_SETUP -#line 421 "dcLexer.lxx" +#line 443 "dcLexer.lxx" { accept(); return KW_UINT8ARRAY; } YY_BREAK -case 24: +case 25: YY_RULE_SETUP -#line 426 "dcLexer.lxx" +#line 448 "dcLexer.lxx" { accept(); return KW_UINT16ARRAY; } YY_BREAK -case 25: +case 26: YY_RULE_SETUP -#line 431 "dcLexer.lxx" +#line 453 "dcLexer.lxx" { accept(); return KW_UINT32ARRAY; } YY_BREAK -case 26: +case 27: YY_RULE_SETUP -#line 436 "dcLexer.lxx" +#line 458 "dcLexer.lxx" { accept(); return KW_UINT32UINT8ARRAY; } YY_BREAK -case 27: +case 28: YY_RULE_SETUP -#line 441 "dcLexer.lxx" +#line 463 "dcLexer.lxx" { // A molecular keyword. accept(); @@ -1245,81 +1274,81 @@ YY_RULE_SETUP return KW_MOL; } YY_BREAK -case 28: +case 29: YY_RULE_SETUP -#line 449 "dcLexer.lxx" +#line 471 "dcLexer.lxx" { accept(); return KW_REQUIRED; } YY_BREAK -case 29: +case 30: YY_RULE_SETUP -#line 454 "dcLexer.lxx" +#line 476 "dcLexer.lxx" { accept(); return KW_BROADCAST; } YY_BREAK -case 30: +case 31: YY_RULE_SETUP -#line 459 "dcLexer.lxx" +#line 481 "dcLexer.lxx" { accept(); return KW_P2P; } YY_BREAK -case 31: +case 32: YY_RULE_SETUP -#line 464 "dcLexer.lxx" +#line 486 "dcLexer.lxx" { accept(); return KW_RAM; } YY_BREAK -case 32: +case 33: YY_RULE_SETUP -#line 469 "dcLexer.lxx" +#line 491 "dcLexer.lxx" { accept(); return KW_DB; } YY_BREAK -case 33: +case 34: YY_RULE_SETUP -#line 474 "dcLexer.lxx" +#line 496 "dcLexer.lxx" { accept(); return KW_CLSEND; } YY_BREAK -case 34: +case 35: YY_RULE_SETUP -#line 479 "dcLexer.lxx" +#line 501 "dcLexer.lxx" { accept(); return KW_CLRECV; } YY_BREAK -case 35: +case 36: YY_RULE_SETUP -#line 484 "dcLexer.lxx" +#line 506 "dcLexer.lxx" { accept(); return KW_OWNSEND; } YY_BREAK -case 36: +case 37: YY_RULE_SETUP -#line 489 "dcLexer.lxx" +#line 511 "dcLexer.lxx" { accept(); return KW_AIRECV; } YY_BREAK -case 37: +case 38: YY_RULE_SETUP -#line 494 "dcLexer.lxx" +#line 516 "dcLexer.lxx" { // An integer number. accept(); @@ -1328,9 +1357,9 @@ YY_RULE_SETUP return INTEGER; } YY_BREAK -case 38: +case 39: YY_RULE_SETUP -#line 502 "dcLexer.lxx" +#line 524 "dcLexer.lxx" { // A hexadecimal integer number. accept(); @@ -1339,9 +1368,9 @@ YY_RULE_SETUP return INTEGER; } YY_BREAK -case 39: +case 40: YY_RULE_SETUP -#line 510 "dcLexer.lxx" +#line 532 "dcLexer.lxx" { // A floating-point number. accept(); @@ -1350,9 +1379,9 @@ YY_RULE_SETUP return REAL; } YY_BREAK -case 40: +case 41: YY_RULE_SETUP -#line 518 "dcLexer.lxx" +#line 540 "dcLexer.lxx" { // Quoted string. accept(); @@ -1360,9 +1389,9 @@ YY_RULE_SETUP return STRING; } YY_BREAK -case 41: +case 42: YY_RULE_SETUP -#line 525 "dcLexer.lxx" +#line 547 "dcLexer.lxx" { // Long hex string. accept(); @@ -1370,9 +1399,9 @@ YY_RULE_SETUP return HEX_STRING; } YY_BREAK -case 42: +case 43: YY_RULE_SETUP -#line 532 "dcLexer.lxx" +#line 554 "dcLexer.lxx" { // Identifier. accept(); @@ -1380,21 +1409,21 @@ YY_RULE_SETUP return IDENTIFIER; } YY_BREAK -case 43: +case 44: YY_RULE_SETUP -#line 540 "dcLexer.lxx" +#line 562 "dcLexer.lxx" { // Send any other printable character as itself. accept(); return dcyytext[0]; } YY_BREAK -case 44: +case 45: YY_RULE_SETUP -#line 546 "dcLexer.lxx" +#line 568 "dcLexer.lxx" ECHO; YY_BREAK -#line 1399 "lex.yy.c" +#line 1428 "lex.yy.c" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -1686,7 +1715,7 @@ static yy_state_type yy_get_previous_state() while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 173 ) + if ( yy_current_state >= 180 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; @@ -1721,11 +1750,11 @@ yy_state_type yy_current_state; while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 173 ) + if ( yy_current_state >= 180 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 172); + yy_is_jam = (yy_current_state == 179); return yy_is_jam ? 0 : yy_current_state; } @@ -2275,4 +2304,4 @@ int main() return 0; } #endif -#line 546 "dcLexer.lxx" +#line 568 "dcLexer.lxx" diff --git a/direct/src/dcparser/dcLexer.lxx b/direct/src/dcparser/dcLexer.lxx index a3bc507750..9fd59645e2 100644 --- a/direct/src/dcparser/dcLexer.lxx +++ b/direct/src/dcparser/dcLexer.lxx @@ -360,6 +360,11 @@ REALNUM ([+-]?(([0-9]+[.])|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?) return KW_IMPORT; } +"typedef" { + accept(); + return KW_TYPEDEF; +} + "int8" { accept(); return KW_INT8; diff --git a/direct/src/dcparser/dcMolecularField.cxx b/direct/src/dcparser/dcMolecularField.cxx index 1e648d05b0..1812030c5a 100644 --- a/direct/src/dcparser/dcMolecularField.cxx +++ b/direct/src/dcparser/dcMolecularField.cxx @@ -81,10 +81,12 @@ void DCMolecularField:: add_atomic(DCAtomicField *atomic) { _fields.push_back(atomic); - int num_nested_fields = atomic->get_num_nested_fields(); - for (int i = 0; i < num_nested_fields; i++) { + int num_atomic_fields = atomic->get_num_nested_fields(); + for (int i = 0; i < num_atomic_fields; i++) { _nested_fields.push_back(atomic->get_nested_field(i)); } + + _num_nested_fields = _nested_fields.size(); } //////////////////////////////////////////////////////////////////// @@ -132,19 +134,6 @@ generate_hash(HashGenerator &hashgen) const { } } -//////////////////////////////////////////////////////////////////// -// Function: DCMolecularField::get_num_nested_fields -// Access: Public, Virtual -// Description: Returns the number of nested fields required by this -// field type. These may be array elements or structure -// elements. The return value may be -1 to indicate the -// number of nested fields is variable. -//////////////////////////////////////////////////////////////////// -int DCMolecularField:: -get_num_nested_fields() const { - return _nested_fields.size(); -} - //////////////////////////////////////////////////////////////////// // Function: DCMolecularField::get_nested_field // Access: Public, Virtual diff --git a/direct/src/dcparser/dcMolecularField.h b/direct/src/dcparser/dcMolecularField.h index 517bc11652..f1411209a1 100644 --- a/direct/src/dcparser/dcMolecularField.h +++ b/direct/src/dcparser/dcMolecularField.h @@ -46,7 +46,6 @@ public: virtual void write(ostream &out, bool brief, int indent_level) const; virtual void generate_hash(HashGenerator &hash) const; - virtual int get_num_nested_fields() const; virtual DCPackerInterface *get_nested_field(int n) const; private: diff --git a/direct/src/dcparser/dcPacker.cxx b/direct/src/dcparser/dcPacker.cxx index aaf8711436..1e3e55a030 100755 --- a/direct/src/dcparser/dcPacker.cxx +++ b/direct/src/dcparser/dcPacker.cxx @@ -189,7 +189,7 @@ push() { // Now deal with the length prefix that might or might not be // before a sequence of nested fields. int num_nested_fields = _current_parent->get_num_nested_fields(); - size_t length_bytes = _current_parent->get_length_bytes(); + size_t length_bytes = _current_parent->get_num_length_bytes(); if (_mode == M_pack) { // Reserve length_bytes for when we figure out what the length @@ -224,7 +224,11 @@ push() { // The explicit length trumps the number of nested fields // reported by get_num_nested_fields(). - num_nested_fields = _current_parent->get_num_nested_fields(length); + if (length == 0) { + num_nested_fields = 0; + } else { + num_nested_fields = _current_parent->calc_num_nested_fields(length); + } } } } @@ -273,7 +277,7 @@ pop() { } else { if (_mode == M_pack) { - size_t length_bytes = _current_parent->get_length_bytes(); + size_t length_bytes = _current_parent->get_num_length_bytes(); if (length_bytes != 0) { // Now go back and fill in the length of the array. char buffer[4]; @@ -478,28 +482,24 @@ unpack_and_format(ostream &out) { DCPackType pack_type = get_pack_type(); switch (pack_type) { + case PT_invalid: + out << ""; + break; + case PT_double: - { - out << unpack_double(); - } + out << unpack_double(); break; case PT_int: - { - out << unpack_int(); - } + out << unpack_int(); break; case PT_int64: - { - out << unpack_int64(); - } + out << unpack_int64(); break; case PT_string: - { - out << '"' << unpack_string() << '"'; - } + out << '"' << unpack_string() << '"'; break; default: @@ -516,6 +516,7 @@ unpack_and_format(ostream &out) { case PT_struct: default: out << '{'; + abort(); break; } diff --git a/direct/src/dcparser/dcPackerInterface.cxx b/direct/src/dcparser/dcPackerInterface.cxx index 3845702477..687257dbc9 100755 --- a/direct/src/dcparser/dcPackerInterface.cxx +++ b/direct/src/dcparser/dcPackerInterface.cxx @@ -26,6 +26,29 @@ DCPackerInterface:: DCPackerInterface(const string &name) : _name(name) +{ + _has_fixed_byte_size = false; + _fixed_byte_size = 0; + _num_length_bytes = 0; + _has_nested_fields = false; + _num_nested_fields = -1; + _pack_type = PT_invalid; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCPackerInterface::Copy Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +DCPackerInterface:: +DCPackerInterface(const DCPackerInterface ©) : + _name(copy._name), + _has_fixed_byte_size(copy._has_fixed_byte_size), + _fixed_byte_size(copy._fixed_byte_size), + _num_length_bytes(copy._num_length_bytes), + _has_nested_fields(copy._has_nested_fields), + _num_nested_fields(copy._num_nested_fields), + _pack_type(copy._pack_type) { } @@ -59,9 +82,45 @@ set_name(const string &name) { _name = name; } +//////////////////////////////////////////////////////////////////// +// Function: DCPackerInterface::has_fixed_byte_size +// Access: Public +// Description: Returns true if this field type always packs to the +// same number of bytes, false if it is variable. +//////////////////////////////////////////////////////////////////// +bool DCPackerInterface:: +has_fixed_byte_size() const { + return _has_fixed_byte_size; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCPackerInterface::get_fixed_byte_size +// Access: Public +// Description: If has_fixed_byte_size() returns true, this returns +// the number of bytes this field type will use. +//////////////////////////////////////////////////////////////////// +size_t DCPackerInterface:: +get_fixed_byte_size() const { + return _fixed_byte_size; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCPackerInterface::get_num_length_bytes +// Access: Public +// Description: Returns the number of bytes that should be written +// into the stream on a push() to record the number of +// bytes in the record up until the next pop(). This is +// only meaningful if _has_nested_fields is true. +//////////////////////////////////////////////////////////////////// +size_t DCPackerInterface:: +get_num_length_bytes() const { + return _num_length_bytes; +} + + //////////////////////////////////////////////////////////////////// // Function: DCPackerInterface::has_nested_fields -// Access: Public, Virtual +// Access: Public // Description: Returns true if this field type has any nested fields // (and thus expects a push() .. pop() interface to the // DCPacker), or false otherwise. If this returns true, @@ -70,12 +129,12 @@ set_name(const string &name) { //////////////////////////////////////////////////////////////////// bool DCPackerInterface:: has_nested_fields() const { - return false; + return _has_nested_fields; } //////////////////////////////////////////////////////////////////// // Function: DCPackerInterface::get_num_nested_fields -// Access: Public, Virtual +// Access: Public // Description: Returns the number of nested fields required by this // field type. These may be array elements or structure // elements. The return value may be -1 to indicate the @@ -83,21 +142,21 @@ has_nested_fields() const { //////////////////////////////////////////////////////////////////// int DCPackerInterface:: get_num_nested_fields() const { - return 0; + return _num_nested_fields; } //////////////////////////////////////////////////////////////////// -// Function: DCPackerInterface::get_num_nested_fields +// Function: DCPackerInterface::calc_num_nested_fields // Access: Public, Virtual // Description: This flavor of get_num_nested_fields is used during // unpacking. It returns the number of nested fields to // expect, given a certain length in bytes (as read from -// the get_length_bytes() stored in the stream on the -// pack). This will only be called if -// get_length_bytes() returns nonzero. +// the _num_length_bytes stored in the stream on the +// push). This will only be called if _num_length_bytes +// is nonzero. //////////////////////////////////////////////////////////////////// int DCPackerInterface:: -get_num_nested_fields(size_t length_bytes) const { +calc_num_nested_fields(size_t length_bytes) const { return 0; } @@ -114,28 +173,14 @@ get_nested_field(int n) const { return NULL; } -//////////////////////////////////////////////////////////////////// -// Function: DCPackerInterface::get_length_bytes -// Access: Public, Virtual -// Description: If has_nested_fields() returns true, this should -// return either 0, 2, or 4, indicating the number of -// bytes this field's data should be prefixed with to -// record its length. This is respected by push() and -// pop(). -//////////////////////////////////////////////////////////////////// -size_t DCPackerInterface:: -get_length_bytes() const { - return 0; -} - //////////////////////////////////////////////////////////////////// // Function: DCPackerInterface::get_pack_type -// Access: Public, Virtual +// Access: Public // Description: Returns the type of value expected by this field. //////////////////////////////////////////////////////////////////// DCPackType DCPackerInterface:: get_pack_type() const { - return PT_invalid; + return _pack_type; } //////////////////////////////////////////////////////////////////// diff --git a/direct/src/dcparser/dcPackerInterface.h b/direct/src/dcparser/dcPackerInterface.h index 17377513d2..1f1073a519 100755 --- a/direct/src/dcparser/dcPackerInterface.h +++ b/direct/src/dcparser/dcPackerInterface.h @@ -61,6 +61,7 @@ END_PUBLISH class EXPCL_DIRECT DCPackerInterface { public: DCPackerInterface(const string &name = string()); + DCPackerInterface(const DCPackerInterface ©); virtual ~DCPackerInterface(); PUBLISHED: @@ -68,13 +69,17 @@ PUBLISHED: void set_name(const string &name); public: - virtual bool has_nested_fields() const; - virtual int get_num_nested_fields() const; - virtual int get_num_nested_fields(size_t length_bytes) const; - virtual DCPackerInterface *get_nested_field(int n) const; - virtual size_t get_length_bytes() const; + bool has_fixed_byte_size() const; + size_t get_fixed_byte_size() const; + size_t get_num_length_bytes() const; + + bool has_nested_fields() const; + int get_num_nested_fields() const; + virtual int calc_num_nested_fields(size_t length_bytes) const; + virtual DCPackerInterface *get_nested_field(int n) const; + + DCPackType get_pack_type() const; - virtual DCPackType get_pack_type() const; virtual bool pack_double(DCPackData &pack_data, double value) const; virtual bool pack_int(DCPackData &pack_data, int value) const; virtual bool pack_int64(DCPackData &pack_data, PN_int64 value) const; @@ -87,6 +92,12 @@ public: protected: string _name; + bool _has_fixed_byte_size; + size_t _fixed_byte_size; + size_t _num_length_bytes; + bool _has_nested_fields; + int _num_nested_fields; + DCPackType _pack_type; }; #endif diff --git a/direct/src/dcparser/dcParameter.cxx b/direct/src/dcparser/dcParameter.cxx index 1fd03726e8..9ec3a5663a 100644 --- a/direct/src/dcparser/dcParameter.cxx +++ b/direct/src/dcparser/dcParameter.cxx @@ -18,6 +18,8 @@ #include "dcParameter.h" #include "hashGenerator.h" +#include "dcindent.h" +#include "dcTypedef.h" //////////////////////////////////////////////////////////////////// @@ -27,6 +29,19 @@ //////////////////////////////////////////////////////////////////// DCParameter:: DCParameter() { + _typedef = NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCParameter::Copy Constructor +// Access: Protected +// Description: +//////////////////////////////////////////////////////////////////// +DCParameter:: +DCParameter(const DCParameter ©) : + DCPackerInterface(copy), + _typedef(copy._typedef) +{ } //////////////////////////////////////////////////////////////////// @@ -69,13 +84,56 @@ as_array_parameter() { } //////////////////////////////////////////////////////////////////// -// Function: DCParameter::as_typedef_parameter -// Access: Published, Virtual +// Function: DCParameter::get_typedef +// Access: Published +// Description: If this type has been referenced from a typedef, +// returns the DCTypedef instance, or NULL if the +// type was declared on-the-fly. +//////////////////////////////////////////////////////////////////// +const DCTypedef *DCParameter:: +get_typedef() const { + return _typedef; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCParameter::set_typedef +// Access: Published +// Description: Records the DCTypedef object that generated this +// parameter. This is normally called only from +// DCTypedef::make_new_parameter(). +//////////////////////////////////////////////////////////////////// +void DCParameter:: +set_typedef(const DCTypedef *dtypedef) { + _typedef = dtypedef; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCParameter::output +// Access: Public // Description: //////////////////////////////////////////////////////////////////// -DCTypedefParameter *DCParameter:: -as_typedef_parameter() { - return NULL; +void DCParameter:: +output(ostream &out, bool brief) const { + string name; + if (!brief) { + name = get_name(); + } + output_instance(out, "", name, ""); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCParameter::output_typedef_name +// Access: Public +// Description: Formats the instance like output_instance, but uses +// the typedef name instead. +//////////////////////////////////////////////////////////////////// +void DCParameter:: +output_typedef_name(ostream &out, const string &prename, const string &name, + const string &postname) const { + out << get_typedef()->get_name(); + if (!prename.empty() || !name.empty() || !postname.empty()) { + out << " " << prename << name << postname; + } } //////////////////////////////////////////////////////////////////// diff --git a/direct/src/dcparser/dcParameter.h b/direct/src/dcparser/dcParameter.h index 822d66434f..6be367677b 100644 --- a/direct/src/dcparser/dcParameter.h +++ b/direct/src/dcparser/dcParameter.h @@ -22,21 +22,10 @@ #include "dcbase.h" #include "dcPackerInterface.h" -#ifdef HAVE_PYTHON - -#undef HAVE_LONG_LONG // NSPR and Python both define this. -#include - -// We only need these headers if we are also building a Python interface. -#include "datagram.h" -#include "datagramIterator.h" - -#endif // HAVE_PYTHON - class DCSimpleParameter; class DCClassParameter; class DCArrayParameter; -class DCTypedefParameter; +class DCTypedef; class HashGenerator; //////////////////////////////////////////////////////////////////// @@ -53,6 +42,7 @@ class HashGenerator; class EXPCL_DIRECT DCParameter : public DCPackerInterface { protected: DCParameter(); + DCParameter(const DCParameter ©); public: virtual ~DCParameter(); @@ -60,13 +50,23 @@ PUBLISHED: virtual DCSimpleParameter *as_simple_parameter(); virtual DCClassParameter *as_class_parameter(); virtual DCArrayParameter *as_array_parameter(); - virtual DCTypedefParameter *as_typedef_parameter(); virtual DCParameter *make_copy() const=0; + const DCTypedef *get_typedef() const; + public: - virtual void output(ostream &out, bool brief) const=0; + void set_typedef(const DCTypedef *dtypedef); + + void output(ostream &out, bool brief) const; + virtual void output_instance(ostream &out, const string &prename, + const string &name, const string &postname) const=0; + void output_typedef_name(ostream &out, const string &prename, + const string &name, const string &postname) const; virtual void generate_hash(HashGenerator &hash) const; + +private: + const DCTypedef *_typedef; }; #endif diff --git a/direct/src/dcparser/dcParser.cxx.prebuilt b/direct/src/dcparser/dcParser.cxx.prebuilt index 1ede9eed78..68b146e283 100644 --- a/direct/src/dcparser/dcParser.cxx.prebuilt +++ b/direct/src/dcparser/dcParser.cxx.prebuilt @@ -18,37 +18,38 @@ # define KW_DCLASS 262 # define KW_FROM 263 # define KW_IMPORT 264 -# define KW_INT8 265 -# define KW_INT16 266 -# define KW_INT32 267 -# define KW_INT64 268 -# define KW_UINT8 269 -# define KW_UINT16 270 -# define KW_UINT32 271 -# define KW_UINT64 272 -# define KW_FLOAT64 273 -# define KW_STRING 274 -# define KW_BLOB 275 -# define KW_BLOB32 276 -# define KW_INT8ARRAY 277 -# define KW_INT16ARRAY 278 -# define KW_INT32ARRAY 279 -# define KW_UINT8ARRAY 280 -# define KW_UINT16ARRAY 281 -# define KW_UINT32ARRAY 282 -# define KW_UINT32UINT8ARRAY 283 -# define KW_MOL 284 -# define KW_REQUIRED 285 -# define KW_BROADCAST 286 -# define KW_P2P 287 -# define KW_RAM 288 -# define KW_DB 289 -# define KW_CLSEND 290 -# define KW_CLRECV 291 -# define KW_OWNSEND 292 -# define KW_AIRECV 293 -# define START_DC 294 -# define START_PARAMETER_VALUE 295 +# define KW_TYPEDEF 265 +# define KW_INT8 266 +# define KW_INT16 267 +# define KW_INT32 268 +# define KW_INT64 269 +# define KW_UINT8 270 +# define KW_UINT16 271 +# define KW_UINT32 272 +# define KW_UINT64 273 +# define KW_FLOAT64 274 +# define KW_STRING 275 +# define KW_BLOB 276 +# define KW_BLOB32 277 +# define KW_INT8ARRAY 278 +# define KW_INT16ARRAY 279 +# define KW_INT32ARRAY 280 +# define KW_UINT8ARRAY 281 +# define KW_UINT16ARRAY 282 +# define KW_UINT32ARRAY 283 +# define KW_UINT32UINT8ARRAY 284 +# define KW_MOL 285 +# define KW_REQUIRED 286 +# define KW_BROADCAST 287 +# define KW_P2P 288 +# define KW_RAM 289 +# define KW_DB 290 +# define KW_CLSEND 291 +# define KW_CLRECV 292 +# define KW_OWNSEND 293 +# define KW_AIRECV 294 +# define START_DC 295 +# define START_PARAMETER_VALUE 296 #line 6 "dcParser.yxx" @@ -58,7 +59,9 @@ #include "dcClass.h" #include "dcAtomicField.h" #include "dcMolecularField.h" +#include "dcArrayParameter.h" #include "dcSimpleParameter.h" +#include "dcTypedef.h" #include "dcPacker.h" // Because our token type contains objects of type string, which @@ -108,12 +111,12 @@ dc_cleanup_parser() { -#define YYFINAL 135 +#define YYFINAL 150 #define YYFLAG -32768 -#define YYNTBASE 55 +#define YYNTBASE 56 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */ -#define YYTRANSLATE(x) ((unsigned)(x) <= 295 ? yytranslate[x] : 92) +#define YYTRANSLATE(x) ((unsigned)(x) <= 296 ? yytranslate[x] : 96) /* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */ static const char yytranslate[] = @@ -122,15 +125,15 @@ static const char yytranslate[] = 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 50, 51, 47, 2, 48, 2, 46, 45, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 49, 42, - 2, 52, 2, 2, 2, 2, 2, 2, 2, 2, + 51, 52, 48, 2, 49, 2, 47, 46, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 50, 43, + 2, 53, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 53, 2, 54, 2, 2, 2, 2, 2, 2, + 2, 54, 2, 55, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 43, 2, 44, 2, 2, 2, 2, + 2, 2, 2, 44, 2, 45, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -147,51 +150,55 @@ static const char yytranslate[] = 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 + 36, 37, 38, 39, 40, 41, 42 }; #if YYDEBUG static const short yyprhs[] = { - 0, 0, 3, 6, 8, 11, 14, 17, 18, 26, - 28, 30, 34, 36, 40, 43, 44, 50, 52, 54, - 56, 60, 62, 65, 67, 71, 73, 76, 79, 82, - 83, 90, 92, 94, 96, 98, 102, 104, 105, 110, - 111, 115, 117, 121, 124, 126, 128, 130, 132, 133, - 138, 139, 144, 145, 150, 154, 158, 162, 164, 167, - 169, 171, 173, 177, 179, 181, 183, 185, 187, 189, - 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, - 211, 213, 215, 217, 220, 223, 226, 229, 232, 235, - 238, 241, 244, 245, 250, 252, 256 + 0, 0, 3, 6, 8, 11, 14, 17, 20, 21, + 29, 31, 33, 37, 39, 43, 46, 47, 53, 55, + 57, 59, 63, 66, 68, 71, 73, 77, 79, 82, + 85, 88, 89, 96, 98, 100, 102, 104, 108, 110, + 111, 116, 117, 121, 123, 125, 129, 131, 133, 137, + 142, 144, 148, 152, 157, 159, 161, 163, 165, 166, + 171, 172, 177, 178, 183, 187, 191, 195, 197, 200, + 202, 204, 206, 210, 212, 214, 216, 218, 220, 222, + 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, + 244, 246, 248, 250, 253, 256, 259, 262, 265, 268, + 271, 274, 277, 278, 283, 285, 289 }; static const short yyrhs[] = { - 40, 56, 0, 41, 79, 0, 91, 0, 56, 42, - 0, 56, 57, 0, 56, 62, 0, 0, 8, 7, - 58, 66, 43, 68, 44, 0, 7, 0, 7, 0, - 60, 45, 7, 0, 60, 0, 61, 46, 60, 0, - 10, 61, 0, 0, 9, 61, 10, 63, 64, 0, - 65, 0, 47, 0, 60, 0, 65, 48, 60, 0, - 91, 0, 49, 67, 0, 59, 0, 67, 48, 59, - 0, 91, 0, 68, 42, 0, 68, 69, 0, 68, - 88, 0, 0, 7, 50, 70, 72, 51, 87, 0, - 7, 0, 91, 0, 73, 0, 74, 0, 73, 48, - 74, 0, 76, 0, 0, 76, 52, 75, 79, 0, - 0, 86, 77, 78, 0, 91, 0, 78, 45, 3, - 0, 78, 7, 0, 3, 0, 4, 0, 5, 0, - 6, 0, 0, 43, 80, 83, 44, 0, 0, 53, - 81, 83, 54, 0, 0, 50, 82, 83, 51, 0, - 3, 47, 3, 0, 4, 47, 3, 0, 6, 47, - 3, 0, 84, 0, 85, 84, 0, 91, 0, 48, - 0, 79, 0, 85, 48, 79, 0, 11, 0, 12, - 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, - 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, - 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, - 0, 28, 0, 29, 0, 91, 0, 87, 31, 0, - 87, 32, 0, 87, 33, 0, 87, 34, 0, 87, - 35, 0, 87, 36, 0, 87, 37, 0, 87, 38, - 0, 87, 39, 0, 0, 7, 49, 89, 90, 0, - 71, 0, 90, 48, 71, 0, 0 + 41, 57, 0, 42, 83, 0, 95, 0, 57, 43, + 0, 57, 58, 0, 57, 63, 0, 57, 67, 0, + 0, 8, 7, 59, 68, 44, 70, 45, 0, 7, + 0, 7, 0, 61, 46, 7, 0, 61, 0, 62, + 47, 61, 0, 10, 62, 0, 0, 9, 62, 10, + 64, 65, 0, 66, 0, 48, 0, 61, 0, 66, + 49, 61, 0, 11, 78, 0, 95, 0, 50, 69, + 0, 60, 0, 69, 49, 60, 0, 95, 0, 70, + 43, 0, 70, 71, 0, 70, 92, 0, 0, 7, + 51, 72, 74, 52, 91, 0, 7, 0, 95, 0, + 75, 0, 76, 0, 75, 49, 76, 0, 78, 0, + 0, 78, 53, 77, 83, 0, 0, 81, 79, 82, + 0, 81, 0, 90, 0, 90, 46, 3, 0, 7, + 0, 80, 0, 81, 54, 55, 0, 81, 54, 3, + 55, 0, 7, 0, 82, 46, 3, 0, 82, 54, + 55, 0, 82, 54, 3, 55, 0, 3, 0, 4, + 0, 5, 0, 6, 0, 0, 44, 84, 87, 45, + 0, 0, 54, 85, 87, 55, 0, 0, 51, 86, + 87, 52, 0, 3, 48, 3, 0, 4, 48, 3, + 0, 6, 48, 3, 0, 88, 0, 89, 88, 0, + 95, 0, 49, 0, 83, 0, 89, 49, 83, 0, + 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, + 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, + 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, + 27, 0, 28, 0, 29, 0, 30, 0, 95, 0, + 91, 32, 0, 91, 33, 0, 91, 34, 0, 91, + 35, 0, 91, 36, 0, 91, 37, 0, 91, 38, + 0, 91, 39, 0, 91, 40, 0, 0, 7, 50, + 93, 94, 0, 73, 0, 94, 49, 73, 0, 0 }; #endif @@ -200,16 +207,17 @@ static const short yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const short yyrline[] = { - 0, 114, 116, 119, 121, 122, 123, 126, 126, 142, - 156, 158, 164, 166, 172, 177, 177, 184, 186, 192, - 197, 203, 205, 208, 215, 223, 225, 226, 227, 230, - 230, 241, 257, 259, 262, 264, 267, 273, 273, 291, - 291, 302, 304, 313, 319, 324, 328, 332, 336, 336, - 344, 344, 352, 352, 360, 366, 372, 380, 382, 385, - 387, 390, 392, 395, 400, 404, 408, 412, 416, 420, - 424, 428, 432, 436, 440, 444, 448, 452, 456, 460, - 464, 468, 474, 476, 480, 484, 488, 492, 496, 500, - 504, 508, 514, 514, 525, 532, 545 + 0, 120, 122, 125, 127, 128, 129, 130, 133, 133, + 149, 162, 164, 170, 172, 178, 183, 183, 190, 192, + 198, 203, 209, 216, 218, 221, 228, 236, 238, 239, + 240, 243, 243, 254, 270, 272, 275, 277, 280, 286, + 286, 304, 304, 313, 316, 321, 332, 344, 346, 350, + 356, 362, 376, 380, 386, 391, 395, 399, 403, 403, + 411, 411, 419, 419, 427, 433, 439, 447, 449, 452, + 454, 457, 459, 462, 467, 471, 475, 479, 483, 487, + 491, 495, 499, 503, 507, 511, 515, 519, 523, 527, + 531, 535, 541, 543, 547, 551, 555, 559, 563, 567, + 571, 575, 581, 581, 592, 599, 612 }; #endif @@ -220,8 +228,8 @@ static const short yyrline[] = static const char *const yytname[] = { "$", "error", "$undefined.", "INTEGER", "REAL", "STRING", "HEX_STRING", - "IDENTIFIER", "KW_DCLASS", "KW_FROM", "KW_IMPORT", "KW_INT8", - "KW_INT16", "KW_INT32", "KW_INT64", "KW_UINT8", "KW_UINT16", + "IDENTIFIER", "KW_DCLASS", "KW_FROM", "KW_IMPORT", "KW_TYPEDEF", + "KW_INT8", "KW_INT16", "KW_INT32", "KW_INT64", "KW_UINT8", "KW_UINT16", "KW_UINT32", "KW_UINT64", "KW_FLOAT64", "KW_STRING", "KW_BLOB", "KW_BLOB32", "KW_INT8ARRAY", "KW_INT16ARRAY", "KW_INT32ARRAY", "KW_UINT8ARRAY", "KW_UINT16ARRAY", "KW_UINT32ARRAY", @@ -231,38 +239,41 @@ static const char *const yytname[] = "'/'", "'.'", "'*'", "','", "':'", "'('", "')'", "'='", "'['", "']'", "grammar", "dc", "dclass", "@1", "dclass_name", "slash_identifier", "import_identifier", "import", "@2", "import_symbol_list_or_star", - "import_symbol_list", "dclass_derivation", "base_list", "dclass_fields", - "atomic_field", "@3", "atomic_name", "parameter_list", + "import_symbol_list", "typedef_decl", "dclass_derivation", "base_list", + "dclass_fields", "atomic_field", "@3", "atomic_name", "parameter_list", "nonempty_parameter_list", "atomic_element", "@4", "parameter", "@5", - "parameter_definition", "parameter_value", "@6", "@7", "@8", "array", - "maybe_comma", "array_def", "type_token", "atomic_flags", - "molecular_field", "@9", "molecular_atom_list", "empty", 0 + "type_name", "type_definition", "parameter_definition", + "parameter_value", "@6", "@7", "@8", "array", "maybe_comma", + "array_def", "type_token", "atomic_flags", "molecular_field", "@9", + "molecular_atom_list", "empty", 0 }; #endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const short yyr1[] = { - 0, 55, 55, 56, 56, 56, 56, 58, 57, 59, - 60, 60, 61, 61, 62, 63, 62, 64, 64, 65, - 65, 66, 66, 67, 67, 68, 68, 68, 68, 70, - 69, 71, 72, 72, 73, 73, 74, 75, 74, 77, - 76, 78, 78, 78, 79, 79, 79, 79, 80, 79, - 81, 79, 82, 79, 79, 79, 79, 83, 83, 84, - 84, 85, 85, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, - 87, 87, 89, 88, 90, 90, 91 + 0, 56, 56, 57, 57, 57, 57, 57, 59, 58, + 60, 61, 61, 62, 62, 63, 64, 63, 65, 65, + 66, 66, 67, 68, 68, 69, 69, 70, 70, 70, + 70, 72, 71, 73, 74, 74, 75, 75, 76, 77, + 76, 79, 78, 78, 80, 80, 80, 81, 81, 81, + 82, 82, 82, 82, 83, 83, 83, 83, 84, 83, + 85, 83, 86, 83, 83, 83, 83, 87, 87, 88, + 88, 89, 89, 90, 90, 90, 90, 90, 90, 90, + 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, + 90, 90, 91, 91, 91, 91, 91, 91, 91, 91, + 91, 91, 93, 92, 94, 94, 95 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const short yyr2[] = { - 0, 2, 2, 1, 2, 2, 2, 0, 7, 1, - 1, 3, 1, 3, 2, 0, 5, 1, 1, 1, - 3, 1, 2, 1, 3, 1, 2, 2, 2, 0, - 6, 1, 1, 1, 1, 3, 1, 0, 4, 0, - 3, 1, 3, 2, 1, 1, 1, 1, 0, 4, + 0, 2, 2, 1, 2, 2, 2, 2, 0, 7, + 1, 1, 3, 1, 3, 2, 0, 5, 1, 1, + 1, 3, 2, 1, 2, 1, 3, 1, 2, 2, + 2, 0, 6, 1, 1, 1, 1, 3, 1, 0, + 4, 0, 3, 1, 1, 3, 1, 1, 3, 4, + 1, 3, 3, 4, 1, 1, 1, 1, 0, 4, 0, 4, 0, 4, 3, 3, 3, 1, 2, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -275,90 +286,98 @@ static const short yyr2[] = error. */ static const short yydefact[] = { - 0, 96, 0, 1, 3, 44, 45, 46, 47, 48, - 52, 50, 2, 0, 0, 0, 4, 5, 6, 0, - 0, 0, 96, 96, 96, 7, 10, 12, 0, 14, - 54, 55, 56, 60, 61, 0, 57, 96, 59, 0, - 0, 96, 0, 15, 0, 49, 60, 58, 53, 51, - 0, 0, 21, 11, 0, 13, 62, 9, 23, 22, - 96, 18, 19, 16, 17, 0, 0, 25, 0, 24, - 0, 26, 8, 27, 28, 20, 92, 29, 0, 96, - 31, 94, 93, 63, 64, 65, 66, 67, 68, 69, - 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 0, 33, 34, 36, 39, 32, 0, 96, - 0, 37, 96, 95, 30, 82, 35, 0, 40, 41, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 38, - 43, 0, 42, 0, 0, 0 + 0, 106, 0, 1, 3, 54, 55, 56, 57, 58, + 62, 60, 2, 0, 0, 0, 0, 4, 5, 6, + 7, 0, 0, 0, 106, 106, 106, 8, 11, 13, + 0, 15, 46, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, + 90, 91, 22, 47, 43, 44, 64, 65, 66, 70, + 71, 0, 67, 106, 69, 0, 0, 106, 0, 16, + 0, 0, 0, 0, 59, 70, 68, 63, 61, 0, + 0, 23, 12, 0, 14, 0, 48, 50, 42, 45, + 72, 10, 25, 24, 106, 19, 20, 17, 18, 49, + 0, 0, 0, 0, 27, 0, 51, 0, 52, 26, + 0, 28, 9, 29, 30, 21, 53, 102, 31, 0, + 106, 33, 104, 103, 0, 35, 36, 38, 34, 0, + 106, 0, 39, 105, 32, 92, 37, 0, 93, 94, + 95, 96, 97, 98, 99, 100, 101, 40, 0, 0, + 0 }; static const short yydefgoto[] = { - 133, 3, 17, 41, 58, 27, 28, 18, 54, 63, - 64, 51, 59, 66, 73, 79, 81, 102, 103, 104, - 117, 105, 112, 118, 34, 22, 24, 23, 35, 36, - 37, 106, 114, 74, 78, 82, 38 + 148, 3, 18, 67, 92, 29, 30, 19, 83, 97, + 98, 20, 80, 93, 103, 113, 120, 122, 124, 125, + 126, 137, 127, 72, 53, 54, 88, 60, 24, 26, + 25, 61, 62, 63, 55, 134, 114, 119, 123, 64 }; static const short yypact[] = { - -19,-32768, 3, 6,-32768, -37, -30,-32768, -28,-32768, - -32768,-32768,-32768, 31, 32, 32,-32768,-32768,-32768, 37, - 40, 42, -1, -1, -1,-32768,-32768, 14, 8, 15, - -32768,-32768,-32768,-32768,-32768, 18,-32768, 10,-32768, 16, - 9, 17, 57,-32768, 32,-32768, 3,-32768,-32768,-32768, - 58, 25,-32768,-32768, 4, 14,-32768,-32768,-32768, 21, - -32768,-32768, 14,-32768, 22, 58, 13,-32768, 32,-32768, - -16,-32768,-32768,-32768,-32768, 14,-32768,-32768, 64, 69, - -32768,-32768, 24,-32768,-32768,-32768,-32768,-32768,-32768,-32768, + -24,-32768, 8, 21,-32768, -26, -22,-32768, -15,-32768, + -32768,-32768,-32768, 17, 27, 27, 62,-32768,-32768,-32768, + -32768, 32, 33, 34, 4, 4, 4,-32768,-32768, -8, + -5, -7,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, - -32768,-32768, 23, 27,-32768, 26,-32768,-32768, 64,-32768, - 69,-32768,-32768,-32768, -7,-32768,-32768, 3, 5,-32768, - -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, - -32768, 70,-32768, 76, 77,-32768 + -32768,-32768,-32768,-32768, -4, -3,-32768,-32768,-32768,-32768, + -32768, -6,-32768, 11,-32768, 13, -11, 16, 38,-32768, + 27, -1, 39, 44,-32768, 8,-32768,-32768,-32768, 42, + 7,-32768,-32768, 9, -8, 15,-32768,-32768, -31,-32768, + -32768,-32768,-32768, 19,-32768,-32768, -8,-32768, 22,-32768, + 69, 1, 42, 18,-32768, 27,-32768, 49,-32768,-32768, + -30,-32768,-32768,-32768,-32768, -8,-32768,-32768,-32768, 86, + 62,-32768,-32768, 56, 54, 58,-32768, 55,-32768, 86, + -32768, 62,-32768,-32768, 63,-32768,-32768, 8,-32768,-32768, + -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 109, 110, + -32768 }; static const short yypgoto[] = { - -32768,-32768,-32768,-32768, 34, -31, 85,-32768,-32768,-32768, - -32768,-32768,-32768,-32768,-32768,-32768, -6,-32768,-32768, -9, - -32768,-32768,-32768,-32768, -2,-32768,-32768,-32768, 12, 66, - -32768,-32768,-32768,-32768,-32768,-32768, 0 + -32768,-32768,-32768,-32768, 10, -64, 96,-32768,-32768,-32768, + -32768,-32768,-32768,-32768,-32768,-32768,-32768, -16,-32768,-32768, + -17,-32768, 99,-32768,-32768,-32768,-32768, -2,-32768,-32768, + -32768, 2, 53,-32768,-32768,-32768,-32768,-32768,-32768, 0 }; -#define YYLAST 115 +#define YYLAST 135 static const short yytable[] = { - 12, 4, 5, 6, 7, 8, 5, 6, 7, 8, - 19, 26, 130, 55, 13, 14, 15, 20, 43, 21, - 70, 1, 2, 62, 120, 121, 122, 123, 124, 125, - 126, 127, 128, 76, 77, 39, 40, 75, 25, 26, - 30, 52, 9, 31, 56, 32, 9, 33, 16, 10, - 131, 61, 11, 10, 44, 71, 11, 72, 46, 42, - 67, 44, 45, 49, 53, 57, 50, 48, 60, 65, - 68, 80, 108, 132, 109, 110, 134, 135, 111, 107, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - 93, 94, 95, 96, 97, 98, 99, 100, 101, 69, - 29, 116, 113, 47, 0, 0, 0, 0, 0, 115, - 0, 0, 119, 0, 0, 129 + 12, 4, 85, -41, 107, 69, 84, 5, 6, 7, + 8, 5, 6, 7, 8, 100, 28, 1, 2, 96, + 117, 118, 21, 101, 27, 110, 22, 65, 66, 13, + 14, 15, 16, 23, 28, 56, 57, 58, 68, 74, + 70, 115, 70, 73, 78, 82, 87, 89, 9, 91, + 71, 94, 9, 59, 86, 10, 108, 95, 11, 10, + 75, 111, 11, 112, 17, 77, 79, 81, 102, 32, + 99, 105, 106, 90, 33, 34, 35, 36, 37, 38, + 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 121, 104, 138, 139, 140, 141, 142, + 143, 144, 145, 146, 116, 129, 130, 131, 132, 149, + 150, 31, 109, 133, 136, 52, 76, 0, 0, 0, + 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 135, 0, 0, 0, 0, 147 }; static const short yycheck[] = { - 2, 1, 3, 4, 5, 6, 3, 4, 5, 6, - 47, 7, 7, 44, 8, 9, 10, 47, 10, 47, - 7, 40, 41, 54, 31, 32, 33, 34, 35, 36, - 37, 38, 39, 49, 50, 23, 24, 68, 7, 7, - 3, 41, 43, 3, 46, 3, 43, 48, 42, 50, - 45, 47, 53, 50, 46, 42, 53, 44, 48, 45, - 60, 46, 44, 54, 7, 7, 49, 51, 43, 48, - 48, 7, 48, 3, 51, 48, 0, 0, 52, 79, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 65, - 15, 110, 108, 37, -1, -1, -1, -1, -1, 109, - -1, -1, 112, -1, -1, 117 + 2, 1, 3, 7, 3, 10, 70, 3, 4, 5, + 6, 3, 4, 5, 6, 46, 7, 41, 42, 83, + 50, 51, 48, 54, 7, 7, 48, 25, 26, 8, + 9, 10, 11, 48, 7, 3, 3, 3, 46, 45, + 47, 105, 47, 46, 55, 7, 7, 3, 44, 7, + 54, 44, 44, 49, 55, 51, 55, 48, 54, 51, + 49, 43, 54, 45, 43, 52, 50, 67, 49, 7, + 55, 49, 3, 75, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 7, 94, 32, 33, 34, 35, 36, + 37, 38, 39, 40, 55, 49, 52, 49, 53, 0, + 0, 15, 102, 129, 131, 16, 63, -1, -1, -1, + 120, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 130, -1, -1, -1, -1, 137 }; /* -*-C-*- Note some compilers choke on comments on `#line' lines. */ #line 3 "/usr/share/bison/bison.simple" @@ -1067,8 +1086,8 @@ yyreduce: switch (yyn) { -case 7: -#line 128 "dcParser.yxx" +case 8: +#line 135 "dcParser.yxx" { current_class = new DCClass(yyvsp[0].str); if (!dc_file->add_class(current_class)) { @@ -1081,79 +1100,84 @@ case 7: } } break; -case 9: -#line 144 "dcParser.yxx" +case 10: +#line 151 "dcParser.yxx" { - DCFile::ClassesByName::const_iterator ni; - ni = dc_file->_classes_by_name.find(yyvsp[0].str); - if (ni == dc_file->_classes_by_name.end()) { - yyval.u.dclass = new DCClass(yyvsp[0].str, true); - dc_file->add_class(yyval.u.dclass); - } else { - yyval.u.dclass = (*ni).second; + DCClass *dclass = dc_file->get_class_by_name(yyvsp[0].str); + if (dclass == (DCClass *)NULL) { + dclass = new DCClass(yyvsp[0].str, true); + dc_file->add_class(dclass); } + + yyval.u.dclass = dclass; } break; -case 11: -#line 159 "dcParser.yxx" +case 12: +#line 165 "dcParser.yxx" { yyval.str = yyvsp[-2].str + string("/") + yyvsp[0].str; } break; -case 13: -#line 167 "dcParser.yxx" +case 14: +#line 173 "dcParser.yxx" { yyval.str = yyvsp[-2].str + string(".") + yyvsp[0].str; } break; -case 14: -#line 174 "dcParser.yxx" +case 15: +#line 180 "dcParser.yxx" { dc_file->add_import_module(yyvsp[0].str); } break; -case 15: -#line 178 "dcParser.yxx" +case 16: +#line 184 "dcParser.yxx" { dc_file->add_import_module(yyvsp[-1].str); } break; -case 18: -#line 187 "dcParser.yxx" +case 19: +#line 193 "dcParser.yxx" { dc_file->add_import_symbol("*"); } break; -case 19: -#line 194 "dcParser.yxx" -{ - dc_file->add_import_symbol(yyvsp[0].str); -} - break; case 20: -#line 198 "dcParser.yxx" +#line 200 "dcParser.yxx" { dc_file->add_import_symbol(yyvsp[0].str); } break; -case 23: -#line 210 "dcParser.yxx" +case 21: +#line 204 "dcParser.yxx" +{ + dc_file->add_import_symbol(yyvsp[0].str); +} + break; +case 22: +#line 211 "dcParser.yxx" +{ + dc_file->add_typedef(new DCTypedef(yyvsp[0].u.parameter)); +} + break; +case 25: +#line 223 "dcParser.yxx" { if (yyvsp[0].u.dclass != (DCClass *)NULL) { current_class->add_parent(yyvsp[0].u.dclass); } } break; -case 24: -#line 216 "dcParser.yxx" +case 26: +#line 229 "dcParser.yxx" { if (yyvsp[0].u.dclass != (DCClass *)NULL) { current_class->add_parent(yyvsp[0].u.dclass); } } break; -case 29: -#line 232 "dcParser.yxx" +case 31: +#line 245 "dcParser.yxx" { current_atomic = new DCAtomicField(yyvsp[-1].str); if (!current_class->add_field(current_atomic)) { @@ -1161,8 +1185,8 @@ case 29: } } break; -case 31: -#line 243 "dcParser.yxx" +case 33: +#line 256 "dcParser.yxx" { DCField *field = current_class->get_field_by_name(yyvsp[0].str); yyval.u.atomic = (DCAtomicField *)NULL; @@ -1176,22 +1200,22 @@ case 31: } } break; -case 36: -#line 269 "dcParser.yxx" +case 38: +#line 282 "dcParser.yxx" { atomic_element = DCAtomicField::ElementType(yyvsp[0].u.parameter); - current_atomic->_elements.push_back(atomic_element); + current_atomic->add_element(atomic_element); } break; -case 37: -#line 274 "dcParser.yxx" +case 39: +#line 287 "dcParser.yxx" { current_packer = &default_packer; current_packer->begin_pack(yyvsp[-1].u.parameter); } break; -case 38: -#line 279 "dcParser.yxx" +case 40: +#line 292 "dcParser.yxx" { if (!current_packer->end_pack()) { yyerror("Invalid default value for type"); @@ -1199,293 +1223,354 @@ case 38: } else { atomic_element = DCAtomicField::ElementType(yyvsp[-3].u.parameter); atomic_element.set_default_value(current_packer->get_string()); - current_atomic->_elements.push_back(atomic_element); + current_atomic->add_element(atomic_element); } } break; -case 39: -#line 293 "dcParser.yxx" +case 41: +#line 306 "dcParser.yxx" { - current_parameter = new DCSimpleParameter(yyvsp[0].u.subatomic); -} - break; -case 40: -#line 297 "dcParser.yxx" -{ - yyval.u.parameter = current_parameter; + current_parameter = yyvsp[0].u.parameter; } break; case 42: -#line 305 "dcParser.yxx" +#line 310 "dcParser.yxx" { - if (current_parameter->as_simple_parameter() == NULL) { - yyerror("Invalid divisor on complex type"); - - } else { - current_parameter->as_simple_parameter()->set_divisor(yyvsp[0].u.integer); - } -} - break; -case 43: -#line 314 "dcParser.yxx" -{ - current_parameter->set_name(yyvsp[0].str); + yyval.u.parameter = yyvsp[0].u.parameter; } break; case 44: -#line 321 "dcParser.yxx" +#line 318 "dcParser.yxx" +{ + yyval.u.parameter = new DCSimpleParameter(yyvsp[0].u.subatomic); +} + break; +case 45: +#line 322 "dcParser.yxx" +{ + DCSimpleParameter *simple_param = new DCSimpleParameter(yyvsp[-2].u.subatomic); + if (yyvsp[0].u.integer == 0) { + yyerror("Invalid divisor."); + + } else if (!simple_param->set_divisor(yyvsp[0].u.integer)) { + yyerror("A divisor is only valid on a numeric type."); + } + yyval.u.parameter = simple_param; +} + break; +case 46: +#line 333 "dcParser.yxx" +{ + DCTypedef *dtypedef = dc_file->get_typedef_by_name(yyvsp[0].str); + if (dtypedef == (DCTypedef *)NULL) { + yyerror("Invalid type name"); + + } else { + yyval.u.parameter = dtypedef->make_new_parameter(); + } +} + break; +case 48: +#line 347 "dcParser.yxx" +{ + yyval.u.parameter = new DCArrayParameter(yyvsp[-2].u.parameter); +} + break; +case 49: +#line 351 "dcParser.yxx" +{ + yyval.u.parameter = new DCArrayParameter(yyvsp[-3].u.parameter, yyvsp[-1].u.integer); +} + break; +case 50: +#line 358 "dcParser.yxx" +{ + current_parameter->set_name(yyvsp[0].str); + yyval.u.parameter = current_parameter; +} + break; +case 51: +#line 363 "dcParser.yxx" +{ + if (yyvsp[0].u.integer == 0) { + yyerror("Invalid divisor."); + + } else if (yyvsp[-2].u.parameter->as_simple_parameter() == NULL || yyvsp[-2].u.parameter->get_typedef() != (DCTypedef *)NULL) { + yyerror("A divisor is only allowed on a primitive type."); + + } else { + if (!yyvsp[-2].u.parameter->as_simple_parameter()->set_divisor(yyvsp[0].u.integer)) { + yyerror("A divisor is only valid on a numeric type."); + } + } +} + break; +case 52: +#line 377 "dcParser.yxx" +{ + yyval.u.parameter = new DCArrayParameter(yyvsp[-2].u.parameter); +} + break; +case 53: +#line 381 "dcParser.yxx" +{ + yyval.u.parameter = new DCArrayParameter(yyvsp[-3].u.parameter, yyvsp[-1].u.integer); +} + break; +case 54: +#line 388 "dcParser.yxx" { current_packer->pack_int(yyvsp[0].u.integer); } break; -case 45: -#line 325 "dcParser.yxx" +case 55: +#line 392 "dcParser.yxx" { current_packer->pack_double(yyvsp[0].u.real); } break; -case 46: -#line 329 "dcParser.yxx" +case 56: +#line 396 "dcParser.yxx" { current_packer->pack_string(yyvsp[0].str); } break; -case 47: -#line 333 "dcParser.yxx" +case 57: +#line 400 "dcParser.yxx" { current_packer->pack_literal_value(yyvsp[0].str); } break; -case 48: -#line 337 "dcParser.yxx" +case 58: +#line 404 "dcParser.yxx" { current_packer->push(); } break; -case 49: -#line 341 "dcParser.yxx" +case 59: +#line 408 "dcParser.yxx" { current_packer->pop(); } break; -case 50: -#line 345 "dcParser.yxx" +case 60: +#line 412 "dcParser.yxx" { current_packer->push(); } break; -case 51: -#line 349 "dcParser.yxx" +case 61: +#line 416 "dcParser.yxx" { current_packer->pop(); } break; -case 52: -#line 353 "dcParser.yxx" +case 62: +#line 420 "dcParser.yxx" { current_packer->push(); } break; -case 53: -#line 357 "dcParser.yxx" +case 63: +#line 424 "dcParser.yxx" { current_packer->pop(); } break; -case 54: -#line 361 "dcParser.yxx" +case 64: +#line 428 "dcParser.yxx" { for (int i = 0; i < yyvsp[0].u.integer; i++) { current_packer->pack_int(yyvsp[-2].u.integer); } } break; -case 55: -#line 367 "dcParser.yxx" +case 65: +#line 434 "dcParser.yxx" { for (int i = 0; i < yyvsp[0].u.integer; i++) { current_packer->pack_double(yyvsp[-2].u.real); } } break; -case 56: -#line 373 "dcParser.yxx" +case 66: +#line 440 "dcParser.yxx" { for (int i = 0; i < yyvsp[0].u.integer; i++) { current_packer->pack_literal_value(yyvsp[-2].str); } } break; -case 63: -#line 397 "dcParser.yxx" +case 73: +#line 464 "dcParser.yxx" { yyval.u.subatomic = ST_int8; } break; -case 64: -#line 401 "dcParser.yxx" +case 74: +#line 468 "dcParser.yxx" { yyval.u.subatomic = ST_int16; } break; -case 65: -#line 405 "dcParser.yxx" +case 75: +#line 472 "dcParser.yxx" { yyval.u.subatomic = ST_int32; } break; -case 66: -#line 409 "dcParser.yxx" +case 76: +#line 476 "dcParser.yxx" { yyval.u.subatomic = ST_int64; } break; -case 67: -#line 413 "dcParser.yxx" +case 77: +#line 480 "dcParser.yxx" { yyval.u.subatomic = ST_uint8; } break; -case 68: -#line 417 "dcParser.yxx" +case 78: +#line 484 "dcParser.yxx" { yyval.u.subatomic = ST_uint16; } break; -case 69: -#line 421 "dcParser.yxx" +case 79: +#line 488 "dcParser.yxx" { yyval.u.subatomic = ST_uint32; } break; -case 70: -#line 425 "dcParser.yxx" +case 80: +#line 492 "dcParser.yxx" { yyval.u.subatomic = ST_uint64; } break; -case 71: -#line 429 "dcParser.yxx" +case 81: +#line 496 "dcParser.yxx" { yyval.u.subatomic = ST_float64; } break; -case 72: -#line 433 "dcParser.yxx" +case 82: +#line 500 "dcParser.yxx" { yyval.u.subatomic = ST_string; } break; -case 73: -#line 437 "dcParser.yxx" +case 83: +#line 504 "dcParser.yxx" { yyval.u.subatomic = ST_blob; } break; -case 74: -#line 441 "dcParser.yxx" +case 84: +#line 508 "dcParser.yxx" { yyval.u.subatomic = ST_blob32; } break; -case 75: -#line 445 "dcParser.yxx" +case 85: +#line 512 "dcParser.yxx" { yyval.u.subatomic = ST_int8array; } break; -case 76: -#line 449 "dcParser.yxx" +case 86: +#line 516 "dcParser.yxx" { yyval.u.subatomic = ST_int16array; } break; -case 77: -#line 453 "dcParser.yxx" +case 87: +#line 520 "dcParser.yxx" { yyval.u.subatomic = ST_int32array; } break; -case 78: -#line 457 "dcParser.yxx" +case 88: +#line 524 "dcParser.yxx" { yyval.u.subatomic = ST_uint8array; } break; -case 79: -#line 461 "dcParser.yxx" +case 89: +#line 528 "dcParser.yxx" { yyval.u.subatomic = ST_uint16array; } break; -case 80: -#line 465 "dcParser.yxx" +case 90: +#line 532 "dcParser.yxx" { yyval.u.subatomic = ST_uint32array; } break; -case 81: -#line 469 "dcParser.yxx" +case 91: +#line 536 "dcParser.yxx" { yyval.u.subatomic = ST_uint32uint8array; } break; -case 83: -#line 477 "dcParser.yxx" +case 93: +#line 544 "dcParser.yxx" { - current_atomic->_flags |= DCAtomicField::F_required; + current_atomic->add_flag(DCAtomicField::F_required); } break; -case 84: -#line 481 "dcParser.yxx" +case 94: +#line 548 "dcParser.yxx" { - current_atomic->_flags |= DCAtomicField::F_broadcast; + current_atomic->add_flag(DCAtomicField::F_broadcast); } break; -case 85: -#line 485 "dcParser.yxx" +case 95: +#line 552 "dcParser.yxx" { - current_atomic->_flags |= DCAtomicField::F_p2p; + current_atomic->add_flag(DCAtomicField::F_p2p); } break; -case 86: -#line 489 "dcParser.yxx" +case 96: +#line 556 "dcParser.yxx" { - current_atomic->_flags |= DCAtomicField::F_ram; + current_atomic->add_flag(DCAtomicField::F_ram); } break; -case 87: -#line 493 "dcParser.yxx" +case 97: +#line 560 "dcParser.yxx" { - current_atomic->_flags |= DCAtomicField::F_db; + current_atomic->add_flag(DCAtomicField::F_db); } break; -case 88: -#line 497 "dcParser.yxx" +case 98: +#line 564 "dcParser.yxx" { - current_atomic->_flags |= DCAtomicField::F_clsend; + current_atomic->add_flag(DCAtomicField::F_clsend); } break; -case 89: -#line 501 "dcParser.yxx" +case 99: +#line 568 "dcParser.yxx" { - current_atomic->_flags |= DCAtomicField::F_clrecv; + current_atomic->add_flag(DCAtomicField::F_clrecv); } break; -case 90: -#line 505 "dcParser.yxx" +case 100: +#line 572 "dcParser.yxx" { - current_atomic->_flags |= DCAtomicField::F_ownsend; + current_atomic->add_flag(DCAtomicField::F_ownsend); } break; -case 91: -#line 509 "dcParser.yxx" +case 101: +#line 576 "dcParser.yxx" { - current_atomic->_flags |= DCAtomicField::F_airecv; + current_atomic->add_flag(DCAtomicField::F_airecv); } break; -case 92: -#line 516 "dcParser.yxx" +case 102: +#line 583 "dcParser.yxx" { current_molecular = new DCMolecularField(yyvsp[-1].str); if (!current_class->add_field(current_molecular)) { @@ -1493,20 +1578,20 @@ case 92: } } break; -case 94: -#line 527 "dcParser.yxx" +case 104: +#line 594 "dcParser.yxx" { if (yyvsp[0].u.atomic != (DCAtomicField *)NULL) { current_molecular->add_atomic(yyvsp[0].u.atomic); } } break; -case 95: -#line 533 "dcParser.yxx" +case 105: +#line 600 "dcParser.yxx" { if (yyvsp[0].u.atomic != (DCAtomicField *)NULL) { current_molecular->add_atomic(yyvsp[0].u.atomic); - if (current_molecular->get_atomic(0)->_flags != yyvsp[0].u.atomic->_flags) { + if (!current_molecular->get_atomic(0)->compare_flags(*yyvsp[0].u.atomic)) { yyerror("Mismatched flags in molecule between " + current_molecular->get_atomic(0)->get_name() + " and " + yyvsp[0].u.atomic->get_name()); @@ -1747,4 +1832,4 @@ yyreturn: #endif return yyresult; } -#line 548 "dcParser.yxx" +#line 615 "dcParser.yxx" diff --git a/direct/src/dcparser/dcParser.h.prebuilt b/direct/src/dcparser/dcParser.h.prebuilt index 5401afc333..bbf08f4f66 100644 --- a/direct/src/dcparser/dcParser.h.prebuilt +++ b/direct/src/dcparser/dcParser.h.prebuilt @@ -9,37 +9,38 @@ # define KW_DCLASS 262 # define KW_FROM 263 # define KW_IMPORT 264 -# define KW_INT8 265 -# define KW_INT16 266 -# define KW_INT32 267 -# define KW_INT64 268 -# define KW_UINT8 269 -# define KW_UINT16 270 -# define KW_UINT32 271 -# define KW_UINT64 272 -# define KW_FLOAT64 273 -# define KW_STRING 274 -# define KW_BLOB 275 -# define KW_BLOB32 276 -# define KW_INT8ARRAY 277 -# define KW_INT16ARRAY 278 -# define KW_INT32ARRAY 279 -# define KW_UINT8ARRAY 280 -# define KW_UINT16ARRAY 281 -# define KW_UINT32ARRAY 282 -# define KW_UINT32UINT8ARRAY 283 -# define KW_MOL 284 -# define KW_REQUIRED 285 -# define KW_BROADCAST 286 -# define KW_P2P 287 -# define KW_RAM 288 -# define KW_DB 289 -# define KW_CLSEND 290 -# define KW_CLRECV 291 -# define KW_OWNSEND 292 -# define KW_AIRECV 293 -# define START_DC 294 -# define START_PARAMETER_VALUE 295 +# define KW_TYPEDEF 265 +# define KW_INT8 266 +# define KW_INT16 267 +# define KW_INT32 268 +# define KW_INT64 269 +# define KW_UINT8 270 +# define KW_UINT16 271 +# define KW_UINT32 272 +# define KW_UINT64 273 +# define KW_FLOAT64 274 +# define KW_STRING 275 +# define KW_BLOB 276 +# define KW_BLOB32 277 +# define KW_INT8ARRAY 278 +# define KW_INT16ARRAY 279 +# define KW_INT32ARRAY 280 +# define KW_UINT8ARRAY 281 +# define KW_UINT16ARRAY 282 +# define KW_UINT32ARRAY 283 +# define KW_UINT32UINT8ARRAY 284 +# define KW_MOL 285 +# define KW_REQUIRED 286 +# define KW_BROADCAST 287 +# define KW_P2P 288 +# define KW_RAM 289 +# define KW_DB 290 +# define KW_CLSEND 291 +# define KW_CLRECV 292 +# define KW_OWNSEND 293 +# define KW_AIRECV 294 +# define START_DC 295 +# define START_PARAMETER_VALUE 296 extern YYSTYPE dcyylval; diff --git a/direct/src/dcparser/dcParser.yxx b/direct/src/dcparser/dcParser.yxx index 1b455dfc74..0cf74d63b1 100644 --- a/direct/src/dcparser/dcParser.yxx +++ b/direct/src/dcparser/dcParser.yxx @@ -10,7 +10,9 @@ #include "dcClass.h" #include "dcAtomicField.h" #include "dcMolecularField.h" +#include "dcArrayParameter.h" #include "dcSimpleParameter.h" +#include "dcTypedef.h" #include "dcPacker.h" // Because our token type contains objects of type string, which @@ -63,6 +65,7 @@ dc_cleanup_parser() { %token KW_DCLASS %token KW_FROM %token KW_IMPORT +%token KW_TYPEDEF %token KW_INT8 %token KW_INT16 @@ -105,7 +108,10 @@ dc_cleanup_parser() { %type dclass_name %type atomic_name %type type_token +%type type_name +%type type_definition %type parameter +%type parameter_definition %type import_identifier %type slash_identifier @@ -121,6 +127,7 @@ dc: | dc ';' | dc dclass | dc import + | dc typedef_decl ; dclass: @@ -142,14 +149,13 @@ dclass: dclass_name: IDENTIFIER { - DCFile::ClassesByName::const_iterator ni; - ni = dc_file->_classes_by_name.find($1); - if (ni == dc_file->_classes_by_name.end()) { - $$ = new DCClass($1, true); - dc_file->add_class($$); - } else { - $$ = (*ni).second; + DCClass *dclass = dc_file->get_class_by_name($1); + if (dclass == (DCClass *)NULL) { + dclass = new DCClass($1, true); + dc_file->add_class(dclass); } + + $$ = dclass; } ; @@ -200,6 +206,13 @@ import_symbol_list: } ; +typedef_decl: + KW_TYPEDEF parameter +{ + dc_file->add_typedef(new DCTypedef($2)); +} + ; + dclass_derivation: empty | ':' base_list @@ -268,7 +281,7 @@ atomic_element: parameter { atomic_element = DCAtomicField::ElementType($1); - current_atomic->_elements.push_back(atomic_element); + current_atomic->add_element(atomic_element); } | parameter '=' { @@ -283,36 +296,90 @@ atomic_element: } else { atomic_element = DCAtomicField::ElementType($1); atomic_element.set_default_value(current_packer->get_string()); - current_atomic->_elements.push_back(atomic_element); + current_atomic->add_element(atomic_element); } } ; parameter: - type_token + type_definition { - current_parameter = new DCSimpleParameter($1); + current_parameter = $1; } parameter_definition { - $$ = current_parameter; + $$ = $3; } + | type_definition ; -parameter_definition: - empty - | parameter_definition '/' INTEGER +type_name: + type_token { - if (current_parameter->as_simple_parameter() == NULL) { - yyerror("Invalid divisor on complex type"); + $$ = new DCSimpleParameter($1); +} + | type_token '/' INTEGER +{ + DCSimpleParameter *simple_param = new DCSimpleParameter($1); + if ($3 == 0) { + yyerror("Invalid divisor."); + + } else if (!simple_param->set_divisor($3)) { + yyerror("A divisor is only valid on a numeric type."); + } + $$ = simple_param; +} + | IDENTIFIER +{ + DCTypedef *dtypedef = dc_file->get_typedef_by_name($1); + if (dtypedef == (DCTypedef *)NULL) { + yyerror("Invalid type name"); } else { - current_parameter->as_simple_parameter()->set_divisor($3); + $$ = dtypedef->make_new_parameter(); } } - | parameter_definition IDENTIFIER + ; + +type_definition: + type_name + | type_definition '[' ']' { - current_parameter->set_name($2); + $$ = new DCArrayParameter($1); +} + | type_definition '[' INTEGER ']' +{ + $$ = new DCArrayParameter($1, $3); +} + ; + +parameter_definition: + IDENTIFIER +{ + current_parameter->set_name($1); + $$ = current_parameter; +} + | parameter_definition '/' INTEGER +{ + if ($3 == 0) { + yyerror("Invalid divisor."); + + } else if ($1->as_simple_parameter() == NULL || $1->get_typedef() != (DCTypedef *)NULL) { + yyerror("A divisor is only allowed on a primitive type."); + + } else { + if (!$1->as_simple_parameter()->set_divisor($3)) { + yyerror("A divisor is only valid on a numeric type."); + } + } +} + | parameter_definition '[' ']' +{ + $$ = new DCArrayParameter($1); +} + | parameter_definition '[' INTEGER ']' +{ + $$ = new DCArrayParameter($1, $3); } ; @@ -475,39 +542,39 @@ atomic_flags: empty | atomic_flags KW_REQUIRED { - current_atomic->_flags |= DCAtomicField::F_required; + current_atomic->add_flag(DCAtomicField::F_required); } | atomic_flags KW_BROADCAST { - current_atomic->_flags |= DCAtomicField::F_broadcast; + current_atomic->add_flag(DCAtomicField::F_broadcast); } | atomic_flags KW_P2P { - current_atomic->_flags |= DCAtomicField::F_p2p; + current_atomic->add_flag(DCAtomicField::F_p2p); } | atomic_flags KW_RAM { - current_atomic->_flags |= DCAtomicField::F_ram; + current_atomic->add_flag(DCAtomicField::F_ram); } | atomic_flags KW_DB { - current_atomic->_flags |= DCAtomicField::F_db; + current_atomic->add_flag(DCAtomicField::F_db); } | atomic_flags KW_CLSEND { - current_atomic->_flags |= DCAtomicField::F_clsend; + current_atomic->add_flag(DCAtomicField::F_clsend); } | atomic_flags KW_CLRECV { - current_atomic->_flags |= DCAtomicField::F_clrecv; + current_atomic->add_flag(DCAtomicField::F_clrecv); } | atomic_flags KW_OWNSEND { - current_atomic->_flags |= DCAtomicField::F_ownsend; + current_atomic->add_flag(DCAtomicField::F_ownsend); } | atomic_flags KW_AIRECV { - current_atomic->_flags |= DCAtomicField::F_airecv; + current_atomic->add_flag(DCAtomicField::F_airecv); } ; @@ -533,7 +600,7 @@ molecular_atom_list: { if ($3 != (DCAtomicField *)NULL) { current_molecular->add_atomic($3); - if (current_molecular->get_atomic(0)->_flags != $3->_flags) { + if (!current_molecular->get_atomic(0)->compare_flags(*$3)) { yyerror("Mismatched flags in molecule between " + current_molecular->get_atomic(0)->get_name() + " and " + $3->get_name()); diff --git a/direct/src/dcparser/dcSimpleParameter.cxx b/direct/src/dcparser/dcSimpleParameter.cxx index b879656255..3a63c2cf84 100644 --- a/direct/src/dcparser/dcSimpleParameter.cxx +++ b/direct/src/dcparser/dcSimpleParameter.cxx @@ -18,6 +18,7 @@ #include "dcSimpleParameter.h" #include "dcPackData.h" +#include "dcTypedef.h" #include "hashGenerator.h" DCSimpleParameter::NestedFieldMap DCSimpleParameter::_nested_field_map; @@ -31,8 +32,14 @@ DCSimpleParameter::Uint32Uint8Type *DCSimpleParameter::_uint32uint8_type = NULL; DCSimpleParameter:: DCSimpleParameter(DCSubatomicType type, int divisor) : _type(type), - _divisor(divisor) + _divisor(1) { + _pack_type = PT_invalid; + _nested_type = ST_invalid; + _has_nested_fields = false; + _bytes_per_element = 0; + _num_length_bytes = 2; + // Check for one of the built-in array types. For these types, we // must present a packing interface that has a variable number of // nested fields of the appropriate type. @@ -40,135 +47,127 @@ DCSimpleParameter(DCSubatomicType type, int divisor) : case ST_int8array: _pack_type = PT_array; _nested_type = ST_int8; - _is_array = true; + _has_nested_fields = true; _bytes_per_element = 1; break; case ST_int16array: _pack_type = PT_array; _nested_type = ST_int16; - _is_array = true; + _has_nested_fields = true; _bytes_per_element = 2; break; case ST_int32array: _pack_type = PT_array; _nested_type = ST_int32; - _is_array = true; + _has_nested_fields = true; _bytes_per_element = 4; break; case ST_uint8array: _pack_type = PT_array; _nested_type = ST_uint8; - _is_array = true; + _has_nested_fields = true; _bytes_per_element = 1; break; case ST_uint16array: _pack_type = PT_array; _nested_type = ST_uint16; - _is_array = true; + _has_nested_fields = true; _bytes_per_element = 2; break; case ST_uint32array: _pack_type = PT_array; _nested_type = ST_uint32; - _is_array = true; + _has_nested_fields = true; _bytes_per_element = 4; break; case ST_uint32uint8array: _pack_type = PT_array; - _nested_type = ST_invalid; - _is_array = true; + _has_nested_fields = true; _bytes_per_element = 5; break; - case ST_blob: case ST_blob32: + _num_length_bytes = 4; + // fall through + + case ST_blob: case ST_string: // For these types, we will present an array interface as an array // of uint8, but we will also accept a set_value() with a string // parameter. _pack_type = PT_string; _nested_type = ST_uint8; - _is_array = true; + _has_nested_fields = true; _bytes_per_element = 1; break; // The simple types can be packed directly. case ST_int8: _pack_type = PT_int; - _nested_type = ST_invalid; - _is_array = false; - _bytes_per_element = 0; + _has_fixed_byte_size = true; + _fixed_byte_size = 1; break; case ST_int16: _pack_type = PT_int; - _nested_type = ST_invalid; - _is_array = false; - _bytes_per_element = 0; + _has_fixed_byte_size = true; + _fixed_byte_size = 2; break; case ST_int32: _pack_type = PT_int; - _nested_type = ST_invalid; - _is_array = false; - _bytes_per_element = 0; + _has_fixed_byte_size = true; + _fixed_byte_size = 4; break; case ST_int64: _pack_type = PT_int64; - _nested_type = ST_invalid; - _is_array = false; - _bytes_per_element = 0; + _has_fixed_byte_size = true; + _fixed_byte_size = 8; break; case ST_uint8: _pack_type = PT_int; - _nested_type = ST_invalid; - _is_array = false; - _bytes_per_element = 0; + _has_fixed_byte_size = true; + _fixed_byte_size = 1; break; case ST_uint16: _pack_type = PT_int; - _nested_type = ST_invalid; - _is_array = false; - _bytes_per_element = 0; + _has_fixed_byte_size = true; + _fixed_byte_size = 2; break; case ST_uint32: _pack_type = PT_int; - _nested_type = ST_invalid; - _is_array = false; - _bytes_per_element = 0; + _has_fixed_byte_size = true; + _fixed_byte_size = 4; break; case ST_uint64: _pack_type = PT_int64; - _nested_type = ST_invalid; - _is_array = false; - _bytes_per_element = 0; + _has_fixed_byte_size = true; + _fixed_byte_size = 8; break; case ST_float64: _pack_type = PT_double; - _nested_type = ST_invalid; - _is_array = false; - _bytes_per_element = 0; + _has_fixed_byte_size = true; + _fixed_byte_size = 8; break; case ST_invalid: - _pack_type = PT_invalid; - _nested_type = ST_invalid; - _is_array = false; - _bytes_per_element = 0; + break; } + set_divisor(divisor); + if (_nested_type != ST_invalid) { _nested_field = create_nested_field(_nested_type, _divisor); @@ -183,6 +182,21 @@ DCSimpleParameter(DCSubatomicType type, int divisor) : } } +//////////////////////////////////////////////////////////////////// +// Function: DCSimpleParameter::Copy Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +DCSimpleParameter:: +DCSimpleParameter(const DCSimpleParameter ©) : + DCParameter(copy), + _type(copy._type), + _divisor(copy._divisor), + _nested_field(copy._nested_field), + _bytes_per_element(copy._bytes_per_element) +{ +} + //////////////////////////////////////////////////////////////////// // Function: DCSimpleParameter::as_simple_parameter // Access: Published, Virtual @@ -231,57 +245,39 @@ get_divisor() const { //////////////////////////////////////////////////////////////////// // Function: DCSimpleParameter::set_divisor -// Access: Published -// Description: See get_divisor(). -//////////////////////////////////////////////////////////////////// -void DCSimpleParameter:: -set_divisor(int divisor) { - _divisor = divisor; - if (_pack_type == PT_int || _pack_type == PT_int64) { - _pack_type = PT_double; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DCSimpleParameter::has_nested_fields -// Access: Public, Virtual -// Description: Returns true if this field type has any nested fields -// (and thus expects a push() .. pop() interface to the -// DCPacker), or false otherwise. If this returns true, -// get_num_nested_fields() may be called to determine -// how many nested fields are expected. +// Access: Public +// Description: Assigns the indicated divisor to the simple type. +// Returns true if assigned, false if this type cannot +// accept a divisor. //////////////////////////////////////////////////////////////////// bool DCSimpleParameter:: -has_nested_fields() const { - return _is_array; +set_divisor(int divisor) { + if (_pack_type == PT_string || divisor == 0) { + return false; + } + + _divisor = divisor; + if ((_divisor != 1) && + (_pack_type == PT_int || _pack_type == PT_int64)) { + _pack_type = PT_double; + } + + return true; } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleParameter::get_num_nested_fields -// Access: Public, Virtual -// Description: Returns the number of nested fields required by this -// field type. These may be array elements or structure -// elements. The return value may be -1 to indicate the -// number of nested fields is variable. -//////////////////////////////////////////////////////////////////// -int DCSimpleParameter:: -get_num_nested_fields() const { - return _is_array ? -1 : 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: DCSimpleParameter::get_num_nested_fields +// Function: DCSimpleParameter::calc_num_nested_fields // Access: Public, Virtual // Description: This flavor of get_num_nested_fields is used during // unpacking. It returns the number of nested fields to // expect, given a certain length in bytes (as read from -// the get_length_bytes() stored in the stream on the -// pack). This will only be called if -// get_length_bytes() returns nonzero. +// the _num_length_bytes stored in the stream on the +// push). This will only be called if _num_length_bytes +// is nonzero. //////////////////////////////////////////////////////////////////// int DCSimpleParameter:: -get_num_nested_fields(size_t length_bytes) const { - if (_is_array) { +calc_num_nested_fields(size_t length_bytes) const { + if (_bytes_per_element != 0) { return length_bytes / _bytes_per_element; } return 0; @@ -296,34 +292,10 @@ get_num_nested_fields(size_t length_bytes) const { // the range 0 <= n < get_num_nested_fields()). //////////////////////////////////////////////////////////////////// DCPackerInterface *DCSimpleParameter:: -get_nested_field(int n) const { +get_nested_field(int) const { return _nested_field; } -//////////////////////////////////////////////////////////////////// -// Function: DCSimpleParameter::get_length_bytes -// Access: Public, Virtual -// Description: If has_nested_fields() returns true, this should -// return either 0, 2, or 4, indicating the number of -// bytes this field's data should be prefixed with to -// record its length. This is respected by push() and -// pop(). -//////////////////////////////////////////////////////////////////// -size_t DCSimpleParameter:: -get_length_bytes() const { - return _type == ST_blob32 ? 4 : 2; -} - -//////////////////////////////////////////////////////////////////// -// Function: DCSimpleParameter::get_pack_type -// Access: Public, Virtual -// Description: Returns the type of value expected by this field. -//////////////////////////////////////////////////////////////////// -DCPackType DCSimpleParameter:: -get_pack_type() const { - return _pack_type; -} - //////////////////////////////////////////////////////////////////// // Function: DCSimpleParameter::pack_double // Access: Published, Virtual @@ -1020,18 +992,25 @@ unpack_string(const char *data, size_t length, size_t &p, string &value) const { } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleParameter::output +// Function: DCSimpleParameter::output_instance // Access: Public, Virtual -// Description: +// Description: Formats the parameter in the C++-like dc syntax as a +// typename and identifier. //////////////////////////////////////////////////////////////////// void DCSimpleParameter:: -output(ostream &out, bool brief) const { - out << _type; - if (_divisor != 1) { - out << " / " << _divisor; +output_instance(ostream &out, const string &prename, const string &name, + const string &postname) const { + if (get_typedef() != (DCTypedef *)NULL) { + out << get_typedef()->get_name(); + } else { + out << _type; } - if (!brief && !_name.empty()) { - out << " " << _name; + if (_divisor != 1) { + out << "/" << _divisor; + } + + if (!prename.empty() || !name.empty() || !postname.empty()) { + out << " " << prename << name << postname; } } @@ -1096,26 +1075,9 @@ DCSimpleParameter::Uint32Uint8Type:: Uint32Uint8Type() { _uint32_type = new DCSimpleParameter(ST_uint32); _uint8_type = new DCSimpleParameter(ST_uint8); -} - -//////////////////////////////////////////////////////////////////// -// Function: DCSimpleParameter::Uint32Uint8Type::has_nested_fields -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool DCSimpleParameter::Uint32Uint8Type:: -has_nested_fields() const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: DCSimpleParameter::Uint32Uint8Type::get_num_nested_fields -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int DCSimpleParameter::Uint32Uint8Type:: -get_num_nested_fields() const { - return 2; + _has_nested_fields = true; + _num_nested_fields = 2; + _pack_type = PT_struct; } //////////////////////////////////////////////////////////////////// @@ -1136,13 +1098,3 @@ get_nested_field(int n) const { return NULL; } } - -//////////////////////////////////////////////////////////////////// -// Function: DCSimpleParameter::Uint32Uint8Type::get_pack_type -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -DCPackType DCSimpleParameter::Uint32Uint8Type:: -get_pack_type() const { - return PT_struct; -} diff --git a/direct/src/dcparser/dcSimpleParameter.h b/direct/src/dcparser/dcSimpleParameter.h index 3ff1320820..c3835c9be1 100644 --- a/direct/src/dcparser/dcSimpleParameter.h +++ b/direct/src/dcparser/dcSimpleParameter.h @@ -35,6 +35,7 @@ class EXPCL_DIRECT DCSimpleParameter : public DCParameter { public: DCSimpleParameter(DCSubatomicType type, int divisor = 1); + DCSimpleParameter(const DCSimpleParameter ©); PUBLISHED: virtual DCSimpleParameter *as_simple_parameter(); @@ -42,16 +43,13 @@ PUBLISHED: DCSubatomicType get_type() const; int get_divisor() const; - void set_divisor(int divisor); public: - virtual bool has_nested_fields() const; - virtual int get_num_nested_fields() const; - virtual int get_num_nested_fields(size_t length_bytes) const; - virtual DCPackerInterface *get_nested_field(int n) const; - virtual size_t get_length_bytes() const; + bool set_divisor(int divisor); + + virtual int calc_num_nested_fields(size_t length_bytes) const; + virtual DCPackerInterface *get_nested_field(int n) const; - virtual DCPackType get_pack_type() const; virtual bool pack_double(DCPackData &pack_data, double value) const; virtual bool pack_int(DCPackData &pack_data, int value) const; virtual bool pack_int64(DCPackData &pack_data, PN_int64 value) const; @@ -62,7 +60,8 @@ public: virtual bool unpack_int64(const char *data, size_t length, size_t &p, PN_int64 &value) const; virtual bool unpack_string(const char *data, size_t length, size_t &p, string &value) const; - virtual void output(ostream &out, bool brief) const; + virtual void output_instance(ostream &out, const string &prename, + const string &name, const string &postname) const; virtual void generate_hash(HashGenerator &hash) const; private: @@ -73,8 +72,6 @@ private: DCSubatomicType _type; int _divisor; - DCPackType _pack_type; - bool _is_array; DCSubatomicType _nested_type; DCPackerInterface *_nested_field; size_t _bytes_per_element; @@ -89,10 +86,7 @@ private: class Uint32Uint8Type : public DCPackerInterface { public: Uint32Uint8Type(); - virtual bool has_nested_fields() const; - virtual int get_num_nested_fields() const; virtual DCPackerInterface *get_nested_field(int n) const; - virtual DCPackType get_pack_type() const; DCSimpleParameter *_uint32_type; DCSimpleParameter *_uint8_type; diff --git a/direct/src/dcparser/dcTypedef.cxx b/direct/src/dcparser/dcTypedef.cxx new file mode 100644 index 0000000000..b9a61d30ff --- /dev/null +++ b/direct/src/dcparser/dcTypedef.cxx @@ -0,0 +1,127 @@ +// Filename: dcTypedef.cxx +// Created by: drose (17Jun04) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#include "dcParameter.h" +#include "hashGenerator.h" +#include "dcParameter.h" +#include "dcindent.h" + +//////////////////////////////////////////////////////////////////// +// Function: DCTypedef::Constructor +// Access: Protected +// Description: +//////////////////////////////////////////////////////////////////// +DCTypedef:: +DCTypedef(DCParameter *parameter) : + _parameter(parameter), + _number(-1) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: DCTypedef::Destructor +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +DCTypedef:: +~DCTypedef() { + delete _parameter; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCTypedef::get_number +// Access: Published +// Description: Returns a unique index number associated with this +// typedef definition. This is defined implicitly when +// the .dc file(s) are read. +//////////////////////////////////////////////////////////////////// +int DCTypedef:: +get_number() const { + return _number; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCTypedef::get_name +// Access: Published +// Description: Returns the name of this typedef. +//////////////////////////////////////////////////////////////////// +const string &DCTypedef:: +get_name() const { + return _parameter->get_name(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCTypedef::get_description +// Access: Published +// Description: Returns a brief decription of the typedef, useful for +// human consumption. +//////////////////////////////////////////////////////////////////// +string DCTypedef:: +get_description() const { + ostringstream strm; + _parameter->output(strm, true); + return strm.str(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCTypedef::make_new_parameter +// Access: Public +// Description: Returns a newly-allocated DCParameter object that +// uses the same type as that named by the typedef. +//////////////////////////////////////////////////////////////////// +DCParameter *DCTypedef:: +make_new_parameter() const { + DCParameter *new_parameter = _parameter->make_copy(); + new_parameter->set_name(string()); + new_parameter->set_typedef(this); + return new_parameter; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCTypedef::set_number +// Access: Public +// Description: Assigns the unique number to this typedef. This is +// normally called only by the DCFile interface as the +// typedef is added. +//////////////////////////////////////////////////////////////////// +void DCTypedef:: +set_number(int number) { + _number = number; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCTypedef::write +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void DCTypedef:: +write(ostream &out, bool brief, int indent_level) const { + indent(out, indent_level) + << "typedef "; + + // We need to preserve the parameter name in the typedef (this is + // the typedef name); hence, we pass brief = false to output(). + _parameter->output(out, false); + out << ";"; + + if (!brief) { + out << " // typedef " << _number; + } + out << "\n"; +} + diff --git a/direct/src/dcparser/dcTypedef.h b/direct/src/dcparser/dcTypedef.h new file mode 100644 index 0000000000..1101708893 --- /dev/null +++ b/direct/src/dcparser/dcTypedef.h @@ -0,0 +1,53 @@ +// Filename: dcTypedef.h +// Created by: drose (17Jun04) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#ifndef DCTYPEDEF_H +#define DCTYPEDEF_H + +#include "dcbase.h" + +class DCParameter; + +//////////////////////////////////////////////////////////////////// +// Class : DCTypedef +// Description : This represents a single typedef declaration in the +// dc file. It assigns a particular type to a new name, +// just like a C typedef. +//////////////////////////////////////////////////////////////////// +class EXPCL_DIRECT DCTypedef { +public: + DCTypedef(DCParameter *parameter); + ~DCTypedef(); + +PUBLISHED: + int get_number() const; + const string &get_name() const; + string get_description() const; + +public: + DCParameter *make_new_parameter() const; + + void set_number(int number); + void write(ostream &out, bool brief, int indent_level) const; + +private: + DCParameter *_parameter; + int _number; +}; + +#endif diff --git a/direct/src/dcparser/dcparser_composite1.cxx b/direct/src/dcparser/dcparser_composite1.cxx index fb8454590c..da2e12063e 100644 --- a/direct/src/dcparser/dcparser_composite1.cxx +++ b/direct/src/dcparser/dcparser_composite1.cxx @@ -6,4 +6,5 @@ #include "dcPackData.cxx" #include "dcPacker.cxx" #include "dcPackerInterface.cxx" +#include "dcindent.cxx" diff --git a/direct/src/dcparser/dcparser_composite2.cxx b/direct/src/dcparser/dcparser_composite2.cxx index 4c11994d3b..f3c56f186b 100644 --- a/direct/src/dcparser/dcparser_composite2.cxx +++ b/direct/src/dcparser/dcparser_composite2.cxx @@ -1,8 +1,9 @@ #include "dcParameter.cxx" +#include "dcArrayParameter.cxx" #include "dcSimpleParameter.cxx" #include "dcField.cxx" #include "dcFile.cxx" #include "dcMolecularField.cxx" #include "dcSubatomicType.cxx" -#include "dcindent.cxx" +#include "dcTypedef.cxx"