diff --git a/direct/src/dcparser/Sources.pp b/direct/src/dcparser/Sources.pp index 96f9a25cd6..5cf286ec16 100644 --- a/direct/src/dcparser/Sources.pp +++ b/direct/src/dcparser/Sources.pp @@ -15,24 +15,29 @@ #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define SOURCES \ - dcAtomicField.h dcClass.h dcField.h dcFile.h dcLexer.lxx \ + dcAtomicField.h dcClass.h \ + dcDeclaration.h \ + dcField.h dcFile.h dcLexer.lxx \ dcLexerDefs.h dcMolecularField.h dcParser.yxx dcParserDefs.h \ dcSubatomicType.h \ dcPackData.h dcPackData.I \ dcPacker.h dcPacker.I \ dcPackerInterface.h dcPackerInterface.I \ - dcParameter.h dcArrayParameter.h dcSimpleParameter.h \ + dcParameter.h dcClassParameter.h dcArrayParameter.h dcSimpleParameter.h \ dcTypedef.h \ dcbase.h dcindent.h hashGenerator.h \ primeNumberGenerator.h #define INCLUDED_SOURCES \ - dcAtomicField.cxx dcClass.cxx dcField.cxx dcFile.cxx \ + dcAtomicField.cxx dcClass.cxx \ + dcDeclaration.cxx \ + dcField.cxx dcFile.cxx \ dcMolecularField.cxx dcSubatomicType.cxx \ dcPackData.cxx \ dcPacker.cxx \ dcPackerInterface.cxx \ - dcParameter.cxx dcArrayParameter.cxx dcSimpleParameter.cxx \ + dcParameter.cxx dcClassParameter.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 index 8ecaee59fc..9cdac824b3 100644 --- a/direct/src/dcparser/dcArrayParameter.cxx +++ b/direct/src/dcparser/dcArrayParameter.cxx @@ -29,7 +29,8 @@ DCArrayParameter(DCParameter *element_type, int array_size) : _element_type(element_type), _array_size(array_size) { - set_name(element_type->get_name()); + set_name(_element_type->get_name()); + _element_type->set_name(string()); if (_array_size >= 0 && _element_type->has_fixed_byte_size()) { _has_fixed_byte_size = true; @@ -57,7 +58,7 @@ DCArrayParameter(const DCArrayParameter ©) : //////////////////////////////////////////////////////////////////// // Function: DCArrayParameter::Destructor -// Access: Public +// Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// DCArrayParameter:: diff --git a/direct/src/dcparser/dcArrayParameter.h b/direct/src/dcparser/dcArrayParameter.h index 9c4a21ffa0..5b6e93804b 100644 --- a/direct/src/dcparser/dcArrayParameter.h +++ b/direct/src/dcparser/dcArrayParameter.h @@ -33,7 +33,7 @@ class EXPCL_DIRECT DCArrayParameter : public DCParameter { public: DCArrayParameter(DCParameter *element_type, int array_size = -1); DCArrayParameter(const DCArrayParameter ©); - ~DCArrayParameter(); + virtual ~DCArrayParameter(); PUBLISHED: virtual DCArrayParameter *as_array_parameter(); diff --git a/direct/src/dcparser/dcClass.cxx b/direct/src/dcparser/dcClass.cxx index 1a4352a51a..75ff704bfd 100644 --- a/direct/src/dcparser/dcClass.cxx +++ b/direct/src/dcparser/dcClass.cxx @@ -17,6 +17,7 @@ //////////////////////////////////////////////////////////////////// #include "dcClass.h" +#include "dcParameter.h" #include "hashGenerator.h" #include "dcindent.h" #include "dcmsgtypes.h" @@ -151,6 +152,109 @@ get_inherited_field(int n) const { return get_field(n); } +//////////////////////////////////////////////////////////////////// +// Function: DCClass::get_num_parameters +// Access: Published +// Description: Returns the number of parameters defined directly in +// this class, ignoring inheritance. +//////////////////////////////////////////////////////////////////// +int DCClass:: +get_num_parameters() const { + return _parameters.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClass::get_parameter +// Access: Published +// Description: Returns the nth parameter in the class. This is not +// necessarily the parameter with index n; this is the +// nth parameter defined in the class directly, ignoring +// inheritance. +//////////////////////////////////////////////////////////////////// +DCParameter *DCClass:: +get_parameter(int n) const { + nassertr_always(n >= 0 && n < (int)_parameters.size(), NULL); + return _parameters[n]; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClass::get_parameter_by_name +// Access: Published +// Description: Returns a pointer to the DCParameter that shares the +// indicated name. If the named parameter is not found +// in the current class, the parent classes will be +// searched, so the value returned may not actually be a +// parameter within this class. Returns NULL if there +// is no such parameter defined. +//////////////////////////////////////////////////////////////////// +DCParameter *DCClass:: +get_parameter_by_name(const string &name) const { + ParametersByName::const_iterator ni; + ni = _parameters_by_name.find(name); + if (ni != _parameters_by_name.end()) { + return (*ni).second; + } + + // We didn't have such a parameter, so check our parents. + Parents::const_iterator pi; + for (pi = _parents.begin(); pi != _parents.end(); ++pi) { + DCParameter *result = (*pi)->get_parameter_by_name(name); + if (result != (DCParameter *)NULL) { + return result; + } + } + + // Nobody knew what this parameter is. + return (DCParameter *)NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClass::get_num_inherited_parameters +// Access: Published +// Description: Returns the total number of parameters defined in +// this class and all ancestor classes. +//////////////////////////////////////////////////////////////////// +int DCClass:: +get_num_inherited_parameters() const { + if (!_parents.empty()) { + // This won't work for multiple dclass inheritance. + return _parents.front()->get_num_inherited_parameters() + get_num_parameters(); + } + return get_num_parameters(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClass::get_inherited_parameter +// Access: Published +// Description: Returns the nth parameter parameter in the class and +// all of its ancestors. +//////////////////////////////////////////////////////////////////// +DCParameter *DCClass:: +get_inherited_parameter(int n) const { + if (!_parents.empty()) { + // This won't work for multiple dclass inheritance. + int psize = _parents.front()->get_num_inherited_parameters(); + if (n < psize) { + return _parents.front()->get_inherited_parameter(n); + } + + n -= psize; + } + return get_parameter(n); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClass::is_struct +// Access: Public +// Description: Returns true if the class has been identified with +// the "struct" keyword in the dc file, false if it was +// declared with "dclass". +//////////////////////////////////////////////////////////////////// +bool DCClass:: +is_struct() const { + return _is_struct; +} + //////////////////////////////////////////////////////////////////// // Function: DCClass::is_bogus_class // Access: Public @@ -523,8 +627,9 @@ ai_format_generate(PyObject *distobj, int do_id, // Description: //////////////////////////////////////////////////////////////////// DCClass:: -DCClass(const string &name, bool bogus_class) : +DCClass(const string &name, bool is_struct, bool bogus_class) : DCPackerInterface(name), + _is_struct(is_struct), _bogus_class(bogus_class) { #ifdef HAVE_PYTHON @@ -551,14 +656,18 @@ DCClass:: //////////////////////////////////////////////////////////////////// // Function: DCClass::write -// Access: Public +// Access: Public, Virtual // Description: Generates a parseable description of the object to // the indicated output stream. //////////////////////////////////////////////////////////////////// void DCClass:: write(ostream &out, bool brief, int indent_level) const { - indent(out, indent_level) - << "dclass " << _name; + indent(out, indent_level); + if (_is_struct) { + out << "struct " << _name; + } else { + out << "dclass " << _name; + } if (!_parents.empty()) { Parents::const_iterator pi = _parents.begin(); @@ -581,6 +690,15 @@ write(ostream &out, bool brief, int indent_level) const { (*fi)->write(out, brief, indent_level + 2); } + if (!_fields.empty() && !_parameters.empty()) { + out << "\n"; + } + + Parameters::const_iterator pi; + for (pi = _parameters.begin(); pi != _parameters.end(); ++pi) { + (*pi)->write(out, brief, indent_level + 2); + } + indent(out, indent_level) << "};\n"; } @@ -605,6 +723,14 @@ generate_hash(HashGenerator &hashgen) const { for (fi = _fields.begin(); fi != _fields.end(); ++fi) { (*fi)->generate_hash(hashgen); } + + if (!_parameters.empty()) { + hashgen.add_int(_parameters.size()); + Parameters::const_iterator pi; + for (pi = _parameters.begin(); pi != _parameters.end(); ++pi) { + (*pi)->generate_hash(hashgen); + } + } } //////////////////////////////////////////////////////////////////// @@ -619,17 +745,43 @@ generate_hash(HashGenerator &hashgen) const { bool DCClass:: add_field(DCField *field) { bool inserted = _fields_by_name.insert - (FieldsByName::value_type(field->_name, field)).second; + (FieldsByName::value_type(field->get_name(), field)).second; if (!inserted) { return false; } - field->_number = get_num_inherited_fields(); + field->set_number(get_num_inherited_fields()); _fields.push_back(field); return true; } +//////////////////////////////////////////////////////////////////// +// Function: DCClass::add_parameter +// Access: Public +// Description: Adds the newly-allocated parameter to the class. The +// class becomes the owner of the pointer and will +// delete it when it destructs. +// +// The parameters are only useful for classes that will +// themselves be used as parameters; DistributedObjects +// in their own right cannot use free parameters. +//////////////////////////////////////////////////////////////////// +bool DCClass:: +add_parameter(DCParameter *parameter) { + if (!parameter->get_name().empty()) { + bool inserted = _parameters_by_name.insert + (ParametersByName::value_type(parameter->get_name(), parameter)).second; + + if (!inserted) { + return false; + } + } + + _parameters.push_back(parameter); + return true; +} + //////////////////////////////////////////////////////////////////// // Function: DCClass::add_parent // Access: Public diff --git a/direct/src/dcparser/dcClass.h b/direct/src/dcparser/dcClass.h index a55bbf5b42..f66258eb6d 100644 --- a/direct/src/dcparser/dcClass.h +++ b/direct/src/dcparser/dcClass.h @@ -22,15 +22,17 @@ #include "dcbase.h" #include "dcField.h" #include "dcPackerInterface.h" +#include "dcDeclaration.h" class HashGenerator; +class DCParameter; //////////////////////////////////////////////////////////////////// // Class : DCClass // Description : Defines a particular DistributedClass as read from an // input .dc file. //////////////////////////////////////////////////////////////////// -class EXPCL_DIRECT DCClass : public DCPackerInterface { +class EXPCL_DIRECT DCClass : public DCPackerInterface, public DCDeclaration { PUBLISHED: int get_number() const; @@ -44,6 +46,14 @@ PUBLISHED: int get_num_inherited_fields() const; DCField *get_inherited_field(int n) const; + int get_num_parameters() const; + DCParameter *get_parameter(int n) const; + DCParameter *get_parameter_by_name(const string &name) const; + + int get_num_inherited_parameters() const; + DCParameter *get_inherited_parameter(int n) const; + + bool is_struct() const; bool is_bogus_class() const; #ifdef HAVE_PYTHON @@ -72,17 +82,19 @@ PUBLISHED: #endif public: - DCClass(const string &name, bool bogus_class = false); + DCClass(const string &name, bool is_struct, bool bogus_class); ~DCClass(); - void write(ostream &out, bool brief, int indent_level) const; + virtual void write(ostream &out, bool brief, int indent_level) const; void generate_hash(HashGenerator &hash) const; bool add_field(DCField *field); + bool add_parameter(DCParameter *parameter); void add_parent(DCClass *parent); void set_number(int number); private: + bool _is_struct; bool _bogus_class; int _number; @@ -95,6 +107,12 @@ private: typedef pmap FieldsByName; FieldsByName _fields_by_name; + typedef pvector Parameters; + Parameters _parameters; + + typedef pmap ParametersByName; + ParametersByName _parameters_by_name; + #ifdef HAVE_PYTHON PyObject *_class_def; #endif diff --git a/direct/src/dcparser/dcClassParameter.cxx b/direct/src/dcparser/dcClassParameter.cxx new file mode 100644 index 0000000000..1840c46caa --- /dev/null +++ b/direct/src/dcparser/dcClassParameter.cxx @@ -0,0 +1,142 @@ +// Filename: dcClassParameter.cxx +// Created by: drose (18Jun04) +// +//////////////////////////////////////////////////////////////////// +// +// 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 "dcClassParameter.h" +#include "dcClass.h" +#include "hashGenerator.h" + +//////////////////////////////////////////////////////////////////// +// Function: DCClassParameter::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +DCClassParameter:: +DCClassParameter(DCClass *dclass) : + _dclass(dclass) +{ + set_name(dclass->get_name()); + + _has_nested_fields = true; + _num_fields = _dclass->get_num_inherited_fields(); + _num_nested_fields = _num_fields + _dclass->get_num_inherited_parameters(); + _pack_type = PT_class; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClassParameter::Copy Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +DCClassParameter:: +DCClassParameter(const DCClassParameter ©) : + DCParameter(copy), + _dclass(copy._dclass), + _num_fields(copy._num_fields) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClassParameter::as_class_parameter +// Access: Published, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +DCClassParameter *DCClassParameter:: +as_class_parameter() { + return this; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClassParameter::make_copy +// Access: Published, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +DCParameter *DCClassParameter:: +make_copy() const { + return new DCClassParameter(*this); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClassParameter::is_valid +// Access: Published, Virtual +// Description: Returns false if the type is an invalid type +// (e.g. declared from an undefined typedef), true if +// it is valid. +//////////////////////////////////////////////////////////////////// +bool DCClassParameter:: +is_valid() const { + return !_dclass->is_bogus_class(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClassParameter::get_class +// Access: Published +// Description: Returns the class object this parameter represents. +//////////////////////////////////////////////////////////////////// +DCClass *DCClassParameter:: +get_class() const { + return _dclass; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClassParameter::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 *DCClassParameter:: +get_nested_field(int n) const { + if (n < _num_fields) { + return _dclass->get_inherited_field(n); + } else { + return _dclass->get_inherited_parameter(n - _num_fields); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClassParameter::output_instance +// Access: Public, Virtual +// Description: Formats the parameter in the C++-like dc syntax as a +// typename and identifier. +//////////////////////////////////////////////////////////////////// +void DCClassParameter:: +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 { + out << get_name(); + if (!prename.empty() || !name.empty() || !postname.empty()) { + out << " " << prename << name << postname; + } + } +} + +//////////////////////////////////////////////////////////////////// +// Function: DCClassParameter::generate_hash +// Access: Public, Virtual +// Description: Accumulates the properties of this type into the +// hash. +//////////////////////////////////////////////////////////////////// +void DCClassParameter:: +generate_hash(HashGenerator &hashgen) const { + DCParameter::generate_hash(hashgen); + _dclass->generate_hash(hashgen); +} diff --git a/direct/src/dcparser/dcClassParameter.h b/direct/src/dcparser/dcClassParameter.h new file mode 100644 index 0000000000..48e0f26c9f --- /dev/null +++ b/direct/src/dcparser/dcClassParameter.h @@ -0,0 +1,57 @@ +// Filename: dcClassParameter.h +// Created by: drose (18Jun04) +// +//////////////////////////////////////////////////////////////////// +// +// 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 DCCLASSPARAMETER_H +#define DCCLASSPARAMETER_H + +#include "dcbase.h" +#include "dcParameter.h" + +class DCClass; + +//////////////////////////////////////////////////////////////////// +// Class : DCClassParameter +// Description : This represents a class (or struct) object used as a +// parameter itself. This means that all the fields of +// the class get packed into the message. +//////////////////////////////////////////////////////////////////// +class EXPCL_DIRECT DCClassParameter : public DCParameter { +public: + DCClassParameter(DCClass *dclass); + DCClassParameter(const DCClassParameter ©); + +PUBLISHED: + virtual DCClassParameter *as_class_parameter(); + virtual DCParameter *make_copy() const; + virtual bool is_valid() const; + + DCClass *get_class() const; + +public: + 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: + DCClass *_dclass; + int _num_fields; +}; + +#endif diff --git a/direct/src/dcparser/dcDeclaration.cxx b/direct/src/dcparser/dcDeclaration.cxx new file mode 100644 index 0000000000..f625a3a6f1 --- /dev/null +++ b/direct/src/dcparser/dcDeclaration.cxx @@ -0,0 +1,29 @@ +// Filename: dcDeclaration.cxx +// Created by: drose (18Jun04) +// +//////////////////////////////////////////////////////////////////// +// +// 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 "dcDeclaration.h" + + +//////////////////////////////////////////////////////////////////// +// Function: DCDeclaration::Destructor +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +DCDeclaration:: +~DCDeclaration() { +} diff --git a/direct/src/dcparser/dcDeclaration.h b/direct/src/dcparser/dcDeclaration.h new file mode 100644 index 0000000000..600fad07f9 --- /dev/null +++ b/direct/src/dcparser/dcDeclaration.h @@ -0,0 +1,41 @@ +// Filename: dcDeclaration.h +// Created by: drose (18Jun04) +// +//////////////////////////////////////////////////////////////////// +// +// 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 DCDECLARATION_H +#define DCDECLARATION_H + +#include "dcbase.h" + +//////////////////////////////////////////////////////////////////// +// Class : DCDeclaration +// Description : This is a common interface for a declaration in a DC +// file. Currently, this is either a class or a typedef +// declaration (import declarations are still collected +// together at the top, and don't inherit from this +// object). Its only purpose is so that classes and +// typedefs can be stored in one list together so they +// can be ordered correctly on output. +//////////////////////////////////////////////////////////////////// +class EXPCL_DIRECT DCDeclaration { +public: + virtual ~DCDeclaration(); + virtual void write(ostream &out, bool brief, int indent_level) const=0; +}; + +#endif + diff --git a/direct/src/dcparser/dcField.cxx b/direct/src/dcparser/dcField.cxx index 188c9434d0..dba12f1454 100644 --- a/direct/src/dcparser/dcField.cxx +++ b/direct/src/dcparser/dcField.cxx @@ -282,3 +282,16 @@ generate_hash(HashGenerator &hashgen) const { // redundant. However, the field name is significant. hashgen.add_string(_name); } + +//////////////////////////////////////////////////////////////////// +// Function: DCField::set_number +// Access: Public +// Description: Assigns the unique number to this field. This is +// normally called only by the DCClass interface as the +// field is added. +//////////////////////////////////////////////////////////////////// +void DCField:: +set_number(int number) { + _number = number; +} + diff --git a/direct/src/dcparser/dcField.h b/direct/src/dcparser/dcField.h index 61a54661e2..367bd5c068 100644 --- a/direct/src/dcparser/dcField.h +++ b/direct/src/dcparser/dcField.h @@ -68,10 +68,10 @@ public: virtual void write(ostream &out, bool brief, int indent_level) const=0; virtual void generate_hash(HashGenerator &hash) const; + void set_number(int number); + protected: int _number; - - friend class DCClass; }; #endif diff --git a/direct/src/dcparser/dcFile.cxx b/direct/src/dcparser/dcFile.cxx index 2cc4f0a2fe..a2c98002ea 100644 --- a/direct/src/dcparser/dcFile.cxx +++ b/direct/src/dcparser/dcFile.cxx @@ -234,21 +234,9 @@ write(ostream &out, bool brief) const { out << "\n"; } - if (!_typedefs.empty()) { - Typedefs::const_iterator ti; - for (ti = _typedefs.begin(); ti != _typedefs.end(); ++ti) { - if (!(*ti)->is_bogus_typedef()) { - (*ti)->write(out, brief, 0); - } - } - out << "\n"; - } - - Classes::const_iterator ci; - for (ci = _classes.begin(); ci != _classes.end(); ++ci) { - if (!(*ci)->is_bogus_class()) { - (*ci)->write(out, brief, 0); - } + Declarations::const_iterator di; + for (di = _declarations.begin(); di != _declarations.end(); ++di) { + (*di)->write(out, brief, 0); out << "\n"; } @@ -452,6 +440,10 @@ add_class(DCClass *dclass) { _all_objects_valid = false; } + if (!dclass->is_bogus_class()) { + _declarations.push_back(dclass); + } + return true; } @@ -510,5 +502,9 @@ add_typedef(DCTypedef *dtypedef) { _all_objects_valid = false; } + if (!dtypedef->is_bogus_typedef() && !dtypedef->is_implicit_typedef()) { + _declarations.push_back(dtypedef); + } + return true; } diff --git a/direct/src/dcparser/dcFile.h b/direct/src/dcparser/dcFile.h index 95b6860854..598c76f2f2 100644 --- a/direct/src/dcparser/dcFile.h +++ b/direct/src/dcparser/dcFile.h @@ -24,6 +24,7 @@ class HashGenerator; class DCTypedef; +class DCDeclaration; //////////////////////////////////////////////////////////////////// // Class : DCFile @@ -94,6 +95,9 @@ private: typedef pmap TypedefsByName; TypedefsByName _typedefs_by_name; + typedef pvector Declarations; + Declarations _declarations; + bool _all_objects_valid; }; diff --git a/direct/src/dcparser/dcLexer.cxx.prebuilt b/direct/src/dcparser/dcLexer.cxx.prebuilt index 1d59024c5a..feac1e1901 100644 --- a/direct/src/dcparser/dcLexer.cxx.prebuilt +++ b/direct/src/dcparser/dcLexer.cxx.prebuilt @@ -302,27 +302,27 @@ static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); #define YY_NUM_RULES 45 #define YY_END_OF_BUFFER 46 -static yyconst short int yy_accept[180] = +static yyconst short int yy_accept[179] = { 0, 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, + 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, 0, 3, 39, 43, 43, 43, 43, 43, + 43, 43, 43, 43, 43, 43, 31, 32, 43, 43, + 43, 43, 0, 40, 43, 20, 43, 43, 43, 43, + 43, 7, 43, 43, 43, 43, 10, 43, 43, 43, + 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, - 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 + 43, 11, 12, 13, 43, 43, 43, 43, 43, 43, + 43, 43, 43, 14, 37, 21, 43, 35, 34, 5, + 43, 8, 43, 43, 43, 43, 43, 19, 6, 43, + 15, 16, 17, 43, 43, 18, 43, 43, 43, 36, + 43, 9, 43, 43, 43, 43, 43, 43, 43, 43, + 29, 43, 43, 43, 43, 30, 43, 43, 22, 43, + 43, 43, 43, 23, 24, 43, 43, 43, 25, 26, + 27, 43, 43, 43, 43, 43, 28, 0 } ; static yyconst int yy_ec[256] = @@ -366,118 +366,116 @@ static yyconst int yy_meta[43] = 7, 7 } ; -static yyconst short int yy_base[187] = +static yyconst short int yy_base[186] = { 0, - 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, + 0, 0, 214, 215, 215, 0, 215, 206, 0, 38, + 37, 205, 215, 0, 183, 16, 181, 25, 20, 22, + 169, 197, 29, 170, 164, 177, 0, 0, 197, 37, + 215, 0, 0, 0, 0, 168, 170, 169, 22, 0, + 171, 167, 166, 164, 159, 164, 161, 163, 158, 156, + 157, 158, 182, 0, 0, 162, 164, 164, 159, 158, + 161, 160, 150, 147, 49, 142, 0, 0, 139, 32, + 151, 138, 168, 167, 149, 159, 146, 146, 137, 131, + 129, 0, 130, 149, 152, 149, 140, 135, 131, 127, + 134, 132, 56, 116, 143, 130, 113, 127, 114, 134, - 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 + 111, 126, 125, 0, 110, 113, 108, 115, 104, 115, + 124, 127, 124, 115, 0, 0, 114, 0, 0, 0, + 121, 0, 98, 97, 96, 106, 104, 0, 0, 102, + 106, 42, 0, 91, 89, 0, 89, 88, 101, 0, + 97, 0, 85, 84, 90, 82, 79, 94, 93, 71, + 0, 77, 76, 79, 88, 0, 66, 65, 0, 85, + 84, 66, 52, 0, 0, 40, 37, 61, 0, 0, + 0, 55, 40, 39, 52, 27, 0, 215, 80, 84, + 62, 85, 92, 95, 99 } ; -static yyconst short int yy_def[187] = +static yyconst short int yy_def[186] = { 0, - 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, + 178, 1, 178, 178, 178, 179, 178, 180, 181, 178, + 180, 180, 178, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 179, 181, 180, 181, + 178, 183, 30, 184, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 185, 183, 184, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 185, 185, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, - 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 + 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 0, 178, 178, + 178, 178, 178, 178, 178 } ; -static yyconst short int yy_nxt[265] = +static yyconst short int yy_nxt[258] = { 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, 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, + 15, 16, 17, 18, 14, 19, 14, 20, 14, 14, + 14, 21, 22, 14, 23, 24, 25, 26, 14, 14, + 14, 14, 31, 33, 37, 32, 40, 41, 42, 48, + 38, 44, 45, 49, 43, 53, 59, 60, 84, 90, + 85, 53, 144, 86, 87, 111, 30, 112, 177, 91, + 113, 114, 176, 175, 174, 173, 172, 34, 171, 145, + 27, 170, 27, 27, 27, 27, 27, 29, 29, 35, + 35, 35, 54, 169, 54, 54, 54, 54, 54, 55, - 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, + 55, 74, 168, 74, 167, 166, 165, 164, 163, 162, + 161, 160, 159, 158, 157, 156, 155, 154, 153, 152, + 151, 150, 149, 148, 147, 146, 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, 116, 115, 110, 109, 108, 107, 106, + 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, + 95, 94, 178, 178, 93, 92, 89, 88, 83, 82, + 81, 80, 79, 78, 77, 76, 75, 73, 72, 71, + 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, - 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 + 58, 57, 56, 33, 52, 51, 50, 47, 46, 39, + 36, 33, 28, 178, 3, 178, 178, 178, 178, 178, + 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, + 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, + 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, + 178, 178, 178, 178, 178, 178, 178 } ; -static yyconst short int yy_chk[265] = +static yyconst short int yy_chk[258] = { 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, 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, + 1, 1, 10, 11, 16, 10, 18, 18, 19, 23, + 16, 20, 20, 23, 19, 30, 39, 39, 65, 70, + 65, 30, 132, 65, 65, 93, 181, 93, 176, 70, + 93, 93, 175, 174, 173, 172, 168, 11, 167, 132, + 179, 166, 179, 179, 179, 179, 179, 180, 180, 182, + 182, 182, 183, 163, 183, 183, 183, 183, 183, 184, - 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, + 184, 185, 162, 185, 161, 160, 158, 157, 155, 154, + 153, 152, 150, 149, 148, 147, 146, 145, 144, 143, + 141, 139, 138, 137, 135, 134, 131, 130, 127, 126, + 125, 124, 123, 121, 117, 114, 113, 112, 111, 110, + 109, 108, 107, 106, 105, 103, 102, 101, 100, 99, + 98, 97, 96, 95, 94, 92, 91, 90, 89, 88, + 87, 86, 85, 84, 83, 81, 80, 79, 78, 77, + 76, 75, 74, 73, 72, 71, 69, 66, 64, 63, + 62, 61, 60, 59, 58, 57, 56, 53, 52, 51, + 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, - 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 + 38, 37, 36, 29, 26, 25, 24, 22, 21, 17, + 15, 12, 8, 3, 178, 178, 178, 178, 178, 178, + 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, + 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, + 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, + 178, 178, 178, 178, 178, 178, 178 } ; static yy_state_type yy_last_accepting_state; @@ -624,7 +622,7 @@ input_chars(char *buffer, int &result, int max_size) { // from the stream, copy it into the current_line array. This // is because the \n.* rule below, which fills current_line // normally, doesn't catch the first line. - strncpy(current_line, yytext, max_error_width); + strncpy(current_line, dcyytext, max_error_width); current_line[max_error_width] = '\0'; line_number++; col_number = 0; @@ -792,7 +790,7 @@ inline void accept() { col_number += yyleng; } -#line 797 "lex.yy.c" +#line 795 "lex.yy.c" /* Macros after this point can all be overridden by user definitions in * section 1. @@ -954,7 +952,7 @@ YY_DECL } -#line 959 "lex.yy.c" +#line 957 "lex.yy.c" if ( yy_init ) { @@ -1005,13 +1003,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 >= 180 ) + if ( yy_current_state >= 179 ) 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] != 222 ); + while ( yy_base[yy_current_state] != 215 ); yy_find_action: yy_act = yy_accept[yy_current_state]; @@ -1044,7 +1042,7 @@ YY_RULE_SETUP // 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. - strncpy(current_line, yytext+1, max_error_width); + strncpy(current_line, dcyytext+1, max_error_width); current_line[max_error_width] = '\0'; line_number++; col_number=0; @@ -1092,7 +1090,7 @@ YY_RULE_SETUP #line 353 "dcLexer.lxx" { accept(); - return KW_FROM; + return KW_STRUCT; } YY_BREAK case 7: @@ -1100,7 +1098,7 @@ YY_RULE_SETUP #line 358 "dcLexer.lxx" { accept(); - return KW_IMPORT; + return KW_FROM; } YY_BREAK case 8: @@ -1108,7 +1106,7 @@ YY_RULE_SETUP #line 363 "dcLexer.lxx" { accept(); - return KW_TYPEDEF; + return KW_IMPORT; } YY_BREAK case 9: @@ -1116,7 +1114,7 @@ YY_RULE_SETUP #line 368 "dcLexer.lxx" { accept(); - return KW_INT8; + return KW_TYPEDEF; } YY_BREAK case 10: @@ -1124,7 +1122,7 @@ YY_RULE_SETUP #line 373 "dcLexer.lxx" { accept(); - return KW_INT16; + return KW_INT8; } YY_BREAK case 11: @@ -1132,7 +1130,7 @@ YY_RULE_SETUP #line 378 "dcLexer.lxx" { accept(); - return KW_INT32; + return KW_INT16; } YY_BREAK case 12: @@ -1140,7 +1138,7 @@ YY_RULE_SETUP #line 383 "dcLexer.lxx" { accept(); - return KW_INT64; + return KW_INT32; } YY_BREAK case 13: @@ -1148,7 +1146,7 @@ YY_RULE_SETUP #line 388 "dcLexer.lxx" { accept(); - return KW_UINT8; + return KW_INT64; } YY_BREAK case 14: @@ -1156,7 +1154,7 @@ YY_RULE_SETUP #line 393 "dcLexer.lxx" { accept(); - return KW_UINT16; + return KW_UINT8; } YY_BREAK case 15: @@ -1164,7 +1162,7 @@ YY_RULE_SETUP #line 398 "dcLexer.lxx" { accept(); - return KW_UINT32; + return KW_UINT16; } YY_BREAK case 16: @@ -1172,7 +1170,7 @@ YY_RULE_SETUP #line 403 "dcLexer.lxx" { accept(); - return KW_UINT64; + return KW_UINT32; } YY_BREAK case 17: @@ -1180,7 +1178,7 @@ YY_RULE_SETUP #line 408 "dcLexer.lxx" { accept(); - return KW_FLOAT64; + return KW_UINT64; } YY_BREAK case 18: @@ -1188,7 +1186,7 @@ YY_RULE_SETUP #line 413 "dcLexer.lxx" { accept(); - return KW_STRING; + return KW_FLOAT64; } YY_BREAK case 19: @@ -1196,7 +1194,7 @@ YY_RULE_SETUP #line 418 "dcLexer.lxx" { accept(); - return KW_BLOB; + return KW_STRING; } YY_BREAK case 20: @@ -1204,7 +1202,7 @@ YY_RULE_SETUP #line 423 "dcLexer.lxx" { accept(); - return KW_BLOB32; + return KW_BLOB; } YY_BREAK case 21: @@ -1212,7 +1210,7 @@ YY_RULE_SETUP #line 428 "dcLexer.lxx" { accept(); - return KW_INT8ARRAY; + return KW_BLOB32; } YY_BREAK case 22: @@ -1220,7 +1218,7 @@ YY_RULE_SETUP #line 433 "dcLexer.lxx" { accept(); - return KW_INT16ARRAY; + return KW_INT8ARRAY; } YY_BREAK case 23: @@ -1228,7 +1226,7 @@ YY_RULE_SETUP #line 438 "dcLexer.lxx" { accept(); - return KW_INT32ARRAY; + return KW_INT16ARRAY; } YY_BREAK case 24: @@ -1236,7 +1234,7 @@ YY_RULE_SETUP #line 443 "dcLexer.lxx" { accept(); - return KW_UINT8ARRAY; + return KW_INT32ARRAY; } YY_BREAK case 25: @@ -1244,7 +1242,7 @@ YY_RULE_SETUP #line 448 "dcLexer.lxx" { accept(); - return KW_UINT16ARRAY; + return KW_UINT8ARRAY; } YY_BREAK case 26: @@ -1252,7 +1250,7 @@ YY_RULE_SETUP #line 453 "dcLexer.lxx" { accept(); - return KW_UINT32ARRAY; + return KW_UINT16ARRAY; } YY_BREAK case 27: @@ -1260,23 +1258,20 @@ YY_RULE_SETUP #line 458 "dcLexer.lxx" { accept(); - return KW_UINT32UINT8ARRAY; + return KW_UINT32ARRAY; } YY_BREAK case 28: YY_RULE_SETUP #line 463 "dcLexer.lxx" { - // A molecular keyword. accept(); - dcyylval.u.integer = atoi(dcyytext + 3); - dcyylval.str = yytext; - return KW_MOL; + return KW_UINT32UINT8ARRAY; } YY_BREAK case 29: YY_RULE_SETUP -#line 471 "dcLexer.lxx" +#line 468 "dcLexer.lxx" { accept(); return KW_REQUIRED; @@ -1284,7 +1279,7 @@ YY_RULE_SETUP YY_BREAK case 30: YY_RULE_SETUP -#line 476 "dcLexer.lxx" +#line 473 "dcLexer.lxx" { accept(); return KW_BROADCAST; @@ -1292,7 +1287,7 @@ YY_RULE_SETUP YY_BREAK case 31: YY_RULE_SETUP -#line 481 "dcLexer.lxx" +#line 478 "dcLexer.lxx" { accept(); return KW_P2P; @@ -1300,7 +1295,7 @@ YY_RULE_SETUP YY_BREAK case 32: YY_RULE_SETUP -#line 486 "dcLexer.lxx" +#line 483 "dcLexer.lxx" { accept(); return KW_RAM; @@ -1308,7 +1303,7 @@ YY_RULE_SETUP YY_BREAK case 33: YY_RULE_SETUP -#line 491 "dcLexer.lxx" +#line 488 "dcLexer.lxx" { accept(); return KW_DB; @@ -1316,7 +1311,7 @@ YY_RULE_SETUP YY_BREAK case 34: YY_RULE_SETUP -#line 496 "dcLexer.lxx" +#line 493 "dcLexer.lxx" { accept(); return KW_CLSEND; @@ -1324,7 +1319,7 @@ YY_RULE_SETUP YY_BREAK case 35: YY_RULE_SETUP -#line 501 "dcLexer.lxx" +#line 498 "dcLexer.lxx" { accept(); return KW_CLRECV; @@ -1332,7 +1327,7 @@ YY_RULE_SETUP YY_BREAK case 36: YY_RULE_SETUP -#line 506 "dcLexer.lxx" +#line 503 "dcLexer.lxx" { accept(); return KW_OWNSEND; @@ -1340,7 +1335,7 @@ YY_RULE_SETUP YY_BREAK case 37: YY_RULE_SETUP -#line 511 "dcLexer.lxx" +#line 508 "dcLexer.lxx" { accept(); return KW_AIRECV; @@ -1348,40 +1343,70 @@ YY_RULE_SETUP YY_BREAK case 38: YY_RULE_SETUP -#line 516 "dcLexer.lxx" +#line 513 "dcLexer.lxx" { // An integer number. - accept(); - dcyylval.u.integer = atoi(dcyytext); - dcyylval.str = yytext; + accept(); + + // atoll isn't fully portable, so we'll decode the integer by hand. + dcyylval.u.integer = 0; + bool neg = false; + const char *p = dcyytext; + if (*p == '-') { + neg = true; + ++p; + } else if (*p == '+') { + ++p; + } + while (*p != '\0') { + dcyylval.u.integer = dcyylval.u.integer * 10 + (*p - '0'); + ++p; + } + if (neg) { + dcyylval.u.integer = -dcyylval.u.integer; + } + + dcyylval.str = dcyytext; return INTEGER; } YY_BREAK case 39: YY_RULE_SETUP -#line 524 "dcLexer.lxx" +#line 539 "dcLexer.lxx" { // A hexadecimal integer number. accept(); - dcyylval.u.integer = strtoul(yytext+2, NULL, 16); - dcyylval.str = yytext; + + // As above, we'll decode the hex string by hand. + dcyylval.u.integer = 0; + const char *p = dcyytext + 2; + while (*p != '\0') { + if (isalpha(*p)) { + dcyylval.u.integer = dcyylval.u.integer * 16 + (tolower(*p) - 'a' + 10); + } else { + dcyylval.u.integer = dcyylval.u.integer * 16 + (*p - '0'); + } + ++p; + } + + dcyylval.str = dcyytext; return INTEGER; } YY_BREAK case 40: YY_RULE_SETUP -#line 532 "dcLexer.lxx" +#line 559 "dcLexer.lxx" { // A floating-point number. accept(); dcyylval.u.real = atof(dcyytext); - dcyylval.str = yytext; + dcyylval.str = dcyytext; return REAL; } YY_BREAK case 41: YY_RULE_SETUP -#line 540 "dcLexer.lxx" +#line 567 "dcLexer.lxx" { // Quoted string. accept(); @@ -1391,7 +1416,7 @@ YY_RULE_SETUP YY_BREAK case 42: YY_RULE_SETUP -#line 547 "dcLexer.lxx" +#line 574 "dcLexer.lxx" { // Long hex string. accept(); @@ -1401,17 +1426,17 @@ YY_RULE_SETUP YY_BREAK case 43: YY_RULE_SETUP -#line 554 "dcLexer.lxx" +#line 581 "dcLexer.lxx" { // Identifier. accept(); - dcyylval.str = yytext; + dcyylval.str = dcyytext; return IDENTIFIER; } YY_BREAK case 44: YY_RULE_SETUP -#line 562 "dcLexer.lxx" +#line 589 "dcLexer.lxx" { // Send any other printable character as itself. accept(); @@ -1420,10 +1445,10 @@ YY_RULE_SETUP YY_BREAK case 45: YY_RULE_SETUP -#line 568 "dcLexer.lxx" +#line 595 "dcLexer.lxx" ECHO; YY_BREAK -#line 1428 "lex.yy.c" +#line 1453 "lex.yy.c" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -1715,7 +1740,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 >= 180 ) + if ( yy_current_state >= 179 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; @@ -1750,11 +1775,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 >= 180 ) + if ( yy_current_state >= 179 ) 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 == 179); + yy_is_jam = (yy_current_state == 178); return yy_is_jam ? 0 : yy_current_state; } @@ -2304,4 +2329,4 @@ int main() return 0; } #endif -#line 568 "dcLexer.lxx" +#line 595 "dcLexer.lxx" diff --git a/direct/src/dcparser/dcLexer.lxx b/direct/src/dcparser/dcLexer.lxx index 70b292c116..8eba29594d 100644 --- a/direct/src/dcparser/dcLexer.lxx +++ b/direct/src/dcparser/dcLexer.lxx @@ -350,6 +350,11 @@ REALNUM ([+-]?(([0-9]+[.])|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?) return KW_DCLASS; } +"struct" { + accept(); + return KW_STRUCT; +} + "from" { accept(); return KW_FROM; @@ -460,14 +465,6 @@ REALNUM ([+-]?(([0-9]+[.])|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?) return KW_UINT32UINT8ARRAY; } -mol[0-9]+ { - // A molecular keyword. - accept(); - dcyylval.u.integer = atoi(dcyytext + 3); - dcyylval.str = dcyytext; - return KW_MOL; -} - "required" { accept(); return KW_REQUIRED; diff --git a/direct/src/dcparser/dcPacker.cxx b/direct/src/dcparser/dcPacker.cxx index 880c389f59..bc54f8111e 100755 --- a/direct/src/dcparser/dcPacker.cxx +++ b/direct/src/dcparser/dcPacker.cxx @@ -532,10 +532,9 @@ unpack_and_format(ostream &out) { out << '('; break; - case PT_struct: + case PT_class: default: out << '{'; - abort(); break; } @@ -558,7 +557,7 @@ unpack_and_format(ostream &out) { out << ')'; break; - case PT_struct: + case PT_class: default: out << '}'; break; diff --git a/direct/src/dcparser/dcPackerInterface.h b/direct/src/dcparser/dcPackerInterface.h index e7db794478..572ec99e15 100755 --- a/direct/src/dcparser/dcPackerInterface.h +++ b/direct/src/dcparser/dcPackerInterface.h @@ -46,7 +46,7 @@ enum DCPackType { // but the PackType provides a bit of a semantic context. PT_array, PT_field, - PT_struct, + PT_class, }; END_PUBLISH diff --git a/direct/src/dcparser/dcParameter.cxx b/direct/src/dcparser/dcParameter.cxx index 9ec3a5663a..db98590338 100644 --- a/direct/src/dcparser/dcParameter.cxx +++ b/direct/src/dcparser/dcParameter.cxx @@ -121,6 +121,18 @@ output(ostream &out, bool brief) const { output_instance(out, "", name, ""); } +//////////////////////////////////////////////////////////////////// +// Function: DCParameter::write +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void DCParameter:: +write(ostream &out, bool brief, int indent_level) const { + indent(out, indent_level); + output(out, brief); + out << ";\n"; +} + //////////////////////////////////////////////////////////////////// // Function: DCParameter::output_typedef_name // Access: Public diff --git a/direct/src/dcparser/dcParameter.h b/direct/src/dcparser/dcParameter.h index 247def1995..b46b86aebf 100644 --- a/direct/src/dcparser/dcParameter.h +++ b/direct/src/dcparser/dcParameter.h @@ -60,6 +60,7 @@ public: void set_typedef(const DCTypedef *dtypedef); void output(ostream &out, bool brief) const; + void write(ostream &out, bool brief, int indent_level) 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, diff --git a/direct/src/dcparser/dcParser.cxx.prebuilt b/direct/src/dcparser/dcParser.cxx.prebuilt index 68b146e283..a8e1e33ac3 100644 --- a/direct/src/dcparser/dcParser.cxx.prebuilt +++ b/direct/src/dcparser/dcParser.cxx.prebuilt @@ -16,29 +16,29 @@ # define HEX_STRING 260 # define IDENTIFIER 261 # define KW_DCLASS 262 -# define KW_FROM 263 -# define KW_IMPORT 264 -# 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_STRUCT 263 +# define KW_FROM 264 +# define KW_IMPORT 265 +# define KW_TYPEDEF 266 +# define KW_INT8 267 +# define KW_INT16 268 +# define KW_INT32 269 +# define KW_INT64 270 +# define KW_UINT8 271 +# define KW_UINT16 272 +# define KW_UINT32 273 +# define KW_UINT64 274 +# define KW_FLOAT64 275 +# define KW_STRING 276 +# define KW_BLOB 277 +# define KW_BLOB32 278 +# define KW_INT8ARRAY 279 +# define KW_INT16ARRAY 280 +# define KW_INT32ARRAY 281 +# define KW_UINT8ARRAY 282 +# define KW_UINT16ARRAY 283 +# define KW_UINT32ARRAY 284 +# define KW_UINT32UINT8ARRAY 285 # define KW_REQUIRED 286 # define KW_BROADCAST 287 # define KW_P2P 288 @@ -59,6 +59,7 @@ #include "dcClass.h" #include "dcAtomicField.h" #include "dcMolecularField.h" +#include "dcClassParameter.h" #include "dcArrayParameter.h" #include "dcSimpleParameter.h" #include "dcTypedef.h" @@ -111,12 +112,12 @@ dc_cleanup_parser() { -#define YYFINAL 150 +#define YYFINAL 157 #define YYFLAG -32768 #define YYNTBASE 56 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */ -#define YYTRANSLATE(x) ((unsigned)(x) <= 296 ? yytranslate[x] : 96) +#define YYTRANSLATE(x) ((unsigned)(x) <= 296 ? yytranslate[x] : 99) /* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */ static const char yytranslate[] = @@ -157,48 +158,51 @@ static const char yytranslate[] = static const short yyprhs[] = { 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 + 29, 31, 33, 35, 37, 41, 43, 47, 50, 51, + 57, 59, 61, 63, 67, 70, 72, 75, 77, 81, + 83, 86, 89, 92, 96, 99, 100, 107, 109, 111, + 113, 115, 119, 121, 122, 127, 128, 132, 134, 136, + 138, 140, 144, 146, 148, 152, 157, 159, 163, 167, + 172, 174, 176, 178, 180, 181, 186, 187, 192, 193, + 198, 202, 206, 210, 212, 215, 217, 219, 221, 225, + 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, + 247, 249, 251, 253, 255, 257, 259, 261, 263, 265, + 268, 271, 274, 277, 280, 283, 286, 289, 292, 293, + 298, 300, 304 }; static const short yyrhs[] = { - 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 + 41, 57, 0, 42, 86, 0, 98, 0, 57, 43, + 0, 57, 58, 0, 57, 64, 0, 57, 68, 0, + 0, 60, 7, 59, 69, 44, 71, 45, 0, 9, + 0, 8, 0, 7, 0, 7, 0, 62, 46, 7, + 0, 62, 0, 63, 47, 62, 0, 11, 63, 0, + 0, 10, 63, 11, 65, 66, 0, 67, 0, 48, + 0, 62, 0, 67, 49, 62, 0, 12, 82, 0, + 98, 0, 50, 70, 0, 61, 0, 70, 49, 61, + 0, 98, 0, 71, 43, 0, 71, 72, 0, 71, + 95, 0, 71, 81, 43, 0, 71, 79, 0, 0, + 7, 51, 73, 75, 52, 94, 0, 7, 0, 98, + 0, 76, 0, 77, 0, 76, 49, 77, 0, 82, + 0, 0, 82, 53, 78, 86, 0, 0, 84, 80, + 85, 0, 84, 0, 79, 0, 81, 0, 93, 0, + 93, 46, 3, 0, 7, 0, 83, 0, 84, 54, + 55, 0, 84, 54, 3, 55, 0, 7, 0, 85, + 46, 3, 0, 85, 54, 55, 0, 85, 54, 3, + 55, 0, 3, 0, 4, 0, 5, 0, 6, 0, + 0, 44, 87, 90, 45, 0, 0, 54, 88, 90, + 55, 0, 0, 51, 89, 90, 52, 0, 3, 48, + 3, 0, 4, 48, 3, 0, 6, 48, 3, 0, + 91, 0, 92, 91, 0, 98, 0, 49, 0, 86, + 0, 92, 49, 86, 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, 31, 0, 98, 0, 94, 32, 0, 94, 33, + 0, 94, 34, 0, 94, 35, 0, 94, 36, 0, + 94, 37, 0, 94, 38, 0, 94, 39, 0, 94, + 40, 0, 0, 7, 50, 96, 97, 0, 74, 0, + 97, 49, 74, 0, 0 }; #endif @@ -207,17 +211,18 @@ static const short yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const short yyrline[] = { - 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 + 0, 123, 125, 128, 130, 131, 132, 133, 136, 136, + 152, 157, 163, 176, 178, 184, 186, 192, 197, 197, + 204, 206, 212, 217, 223, 239, 241, 244, 251, 259, + 261, 262, 263, 264, 268, 276, 276, 287, 303, 305, + 308, 310, 313, 319, 319, 343, 343, 354, 358, 360, + 363, 368, 379, 400, 402, 406, 412, 418, 432, 436, + 442, 447, 451, 455, 459, 459, 467, 467, 475, 475, + 483, 489, 495, 503, 505, 508, 510, 513, 515, 518, + 523, 527, 531, 535, 539, 543, 547, 551, 555, 559, + 563, 567, 571, 575, 579, 583, 587, 591, 597, 599, + 603, 607, 611, 615, 619, 623, 627, 631, 637, 637, + 648, 655, 668 }; #endif @@ -228,21 +233,22 @@ static const short yyrline[] = static const char *const yytname[] = { "$", "error", "$undefined.", "INTEGER", "REAL", "STRING", "HEX_STRING", - "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", - "KW_UINT32UINT8ARRAY", "KW_MOL", "KW_REQUIRED", "KW_BROADCAST", - "KW_P2P", "KW_RAM", "KW_DB", "KW_CLSEND", "KW_CLRECV", "KW_OWNSEND", - "KW_AIRECV", "START_DC", "START_PARAMETER_VALUE", "';'", "'{'", "'}'", - "'/'", "'.'", "'*'", "','", "':'", "'('", "')'", "'='", "'['", "']'", - "grammar", "dc", "dclass", "@1", "dclass_name", "slash_identifier", - "import_identifier", "import", "@2", "import_symbol_list_or_star", - "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", - "type_name", "type_definition", "parameter_definition", + "IDENTIFIER", "KW_DCLASS", "KW_STRUCT", "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", + "KW_UINT32UINT8ARRAY", "KW_REQUIRED", "KW_BROADCAST", "KW_P2P", + "KW_RAM", "KW_DB", "KW_CLSEND", "KW_CLRECV", "KW_OWNSEND", "KW_AIRECV", + "START_DC", "START_PARAMETER_VALUE", "';'", "'{'", "'}'", "'/'", "'.'", + "'*'", "','", "':'", "'('", "')'", "'='", "'['", "']'", "grammar", "dc", + "dclass", "@1", "kw_struct_or_kw_dclass", "dclass_name", + "slash_identifier", "import_identifier", "import", "@2", + "import_symbol_list_or_star", "import_symbol_list", "typedef_decl", + "dclass_derivation", "base_list", "dclass_fields", "atomic_field", "@3", + "atomic_name", "parameter_list", "nonempty_parameter_list", + "atomic_element", "@4", "named_parameter", "@5", "unnamed_parameter", + "parameter", "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 @@ -253,32 +259,34 @@ static const char *const yytname[] = static const short yyr1[] = { 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 + 60, 60, 61, 62, 62, 63, 63, 64, 65, 64, + 66, 66, 67, 67, 68, 69, 69, 70, 70, 71, + 71, 71, 71, 71, 71, 73, 72, 74, 75, 75, + 76, 76, 77, 78, 77, 80, 79, 81, 82, 82, + 83, 83, 83, 84, 84, 84, 85, 85, 85, 85, + 86, 86, 86, 86, 87, 86, 88, 86, 89, 86, + 86, 86, 86, 90, 90, 91, 91, 92, 92, 93, + 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, + 93, 93, 93, 93, 93, 93, 93, 93, 94, 94, + 94, 94, 94, 94, 94, 94, 94, 94, 96, 95, + 97, 97, 98 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const short yyr2[] = { 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, 3, 1, 3, 2, 0, 5, + 1, 1, 1, 3, 2, 1, 2, 1, 3, 1, + 2, 2, 2, 3, 2, 0, 6, 1, 1, 1, + 1, 3, 1, 0, 4, 0, 3, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 0, 4, 1, 3, 0 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 0, 4, + 1, 3, 0 }; /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE @@ -286,98 +294,106 @@ static const short yyr2[] = error. */ static const short yydefact[] = { - 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 + 0, 112, 0, 1, 3, 60, 61, 62, 63, 64, + 68, 66, 2, 11, 10, 0, 0, 0, 4, 5, + 0, 6, 7, 0, 0, 0, 112, 112, 112, 13, + 15, 0, 17, 52, 79, 80, 81, 82, 83, 84, + 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, + 95, 96, 97, 48, 49, 24, 53, 47, 50, 8, + 70, 71, 72, 76, 77, 0, 73, 112, 75, 0, + 0, 0, 18, 0, 0, 0, 0, 112, 65, 76, + 74, 69, 67, 14, 0, 16, 0, 54, 56, 46, + 51, 0, 0, 25, 78, 21, 22, 19, 20, 55, + 0, 0, 12, 27, 26, 112, 0, 57, 0, 58, + 0, 0, 29, 23, 59, 28, 52, 30, 9, 31, + 34, 0, 32, 108, 35, 33, 0, 112, 37, 110, + 109, 0, 39, 40, 42, 38, 0, 112, 0, 43, + 111, 36, 98, 41, 0, 99, 100, 101, 102, 103, + 104, 105, 106, 107, 44, 0, 0, 0 }; static const short yydefgoto[] = { - 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 + 155, 3, 19, 77, 20, 103, 30, 31, 21, 84, + 97, 98, 22, 92, 104, 111, 119, 127, 129, 131, + 132, 133, 144, 53, 75, 54, 134, 56, 57, 89, + 64, 26, 28, 27, 65, 66, 67, 58, 141, 122, + 126, 130, 68 }; static const short yypact[] = { - -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, + -19,-32768, 9, 8,-32768, -41, -20,-32768, -16,-32768, + -32768,-32768,-32768,-32768,-32768, 17, 17, 130,-32768,-32768, + 26,-32768,-32768, 31, 34, 35, 5, 5, 5,-32768, + -11, -5, -8,-32768,-32768,-32768,-32768,-32768,-32768,-32768, -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-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 + -32768,-32768,-32768,-32768,-32768,-32768,-32768, -6, 4,-32768, + -32768,-32768,-32768,-32768,-32768, -4,-32768, -9,-32768, 10, + -12, 37,-32768, 17, 0, 39, 44, 11,-32768, 9, + -32768,-32768,-32768,-32768, -3, -11, 19,-32768,-32768, -25, + -32768, 45, 54,-32768,-32768,-32768, -11,-32768, 27,-32768, + 72, 2,-32768,-32768, 50,-32768, 17,-32768, 46,-32768, + 45, 66,-32768, -11,-32768,-32768, -24,-32768,-32768,-32768, + -32768, 57,-32768,-32768,-32768,-32768, 95, 130,-32768,-32768, + 55, 51, 56,-32768, 59,-32768, 95,-32768, 130,-32768, + -32768, 32,-32768,-32768, 9,-32768,-32768,-32768,-32768,-32768, + -32768,-32768,-32768,-32768,-32768, 107, 108,-32768 }; static const short yypgoto[] = { - -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 + -32768,-32768,-32768,-32768,-32768, 6, -48, 94,-32768,-32768, + -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, -23,-32768, + -32768, -21,-32768, 7,-32768, 12, 97,-32768,-32768,-32768, + -2,-32768,-32768,-32768, 3, 48,-32768,-32768,-32768,-32768, + -32768,-32768, 1 }; -#define YYLAST 135 +#define YYLAST 161 static const short yytable[] = { - 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 + 12, -45, 4, 86, 29, 108, 72, 23, 5, 6, + 7, 8, 5, 6, 7, 8, 13, 14, 15, 16, + 17, 100, 1, 2, 29, 85, 123, 124, 24, 101, + 69, 70, 25, 59, 60, 71, 96, 61, 62, 73, + 79, 78, 73, 82, 83, 95, 88, 90, 74, 9, + 76, 18, 102, 9, 63, 87, 10, 109, 113, 11, + 10, 91, 81, 11, 145, 146, 147, 148, 149, 150, + 151, 152, 153, 116, 99, 107, 106, 94, 93, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 105, 110, + 125, 114, 128, 137, 136, 138, 112, 156, 157, 117, + 32, 118, 139, 140, 55, 80, 115, 143, 120, 0, + 0, 0, 0, 121, 0, 0, 0, 0, 135, 0, + 0, 0, 0, 0, 0, 0, 0, 33, 142, 0, + 0, 0, 154, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52 }; static const short yycheck[] = { - 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 + 2, 7, 1, 3, 7, 3, 11, 48, 3, 4, + 5, 6, 3, 4, 5, 6, 8, 9, 10, 11, + 12, 46, 41, 42, 7, 73, 50, 51, 48, 54, + 27, 28, 48, 7, 3, 46, 84, 3, 3, 47, + 49, 45, 47, 55, 7, 48, 7, 3, 54, 44, + 46, 43, 7, 44, 49, 55, 51, 55, 106, 54, + 51, 50, 52, 54, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 7, 55, 3, 49, 79, 77, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 44, 49, + 43, 55, 7, 52, 49, 49, 105, 0, 0, 43, + 16, 45, 53, 136, 17, 67, 110, 138, 111, -1, + -1, -1, -1, 111, -1, -1, -1, -1, 127, -1, + -1, -1, -1, -1, -1, -1, -1, 7, 137, -1, + -1, -1, 144, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31 }; /* -*-C-*- Note some compilers choke on comments on `#line' lines. */ #line 3 "/usr/share/bison/bison.simple" @@ -1087,9 +1103,9 @@ yyreduce: switch (yyn) { case 8: -#line 135 "dcParser.yxx" +#line 138 "dcParser.yxx" { - current_class = new DCClass(yyvsp[0].str); + current_class = new DCClass(yyvsp[0].str, yyvsp[-1].u.flag, false); if (!dc_file->add_class(current_class)) { DCClass *old_class = dc_file->get_class_by_name(current_class->get_name()); if (old_class->is_bogus_class()) { @@ -1101,83 +1117,118 @@ case 8: } break; case 10: -#line 151 "dcParser.yxx" +#line 154 "dcParser.yxx" +{ + yyval.u.flag = true; +} + break; +case 11: +#line 158 "dcParser.yxx" +{ + yyval.u.flag = false; +} + break; +case 12: +#line 165 "dcParser.yxx" { DCClass *dclass = dc_file->get_class_by_name(yyvsp[0].str); if (dclass == (DCClass *)NULL) { - dclass = new DCClass(yyvsp[0].str, true); + dclass = new DCClass(yyvsp[0].str, false, true); dc_file->add_class(dclass); } yyval.u.dclass = dclass; } break; -case 12: -#line 165 "dcParser.yxx" +case 14: +#line 179 "dcParser.yxx" { yyval.str = yyvsp[-2].str + string("/") + yyvsp[0].str; } break; -case 14: -#line 173 "dcParser.yxx" +case 16: +#line 187 "dcParser.yxx" { yyval.str = yyvsp[-2].str + string(".") + yyvsp[0].str; } break; -case 15: -#line 180 "dcParser.yxx" +case 17: +#line 194 "dcParser.yxx" { dc_file->add_import_module(yyvsp[0].str); } break; -case 16: -#line 184 "dcParser.yxx" +case 18: +#line 198 "dcParser.yxx" { dc_file->add_import_module(yyvsp[-1].str); } break; -case 19: -#line 193 "dcParser.yxx" +case 21: +#line 207 "dcParser.yxx" { dc_file->add_import_symbol("*"); } break; -case 20: -#line 200 "dcParser.yxx" -{ - dc_file->add_import_symbol(yyvsp[0].str); -} - break; -case 21: -#line 204 "dcParser.yxx" -{ - dc_file->add_import_symbol(yyvsp[0].str); -} - break; case 22: -#line 211 "dcParser.yxx" +#line 214 "dcParser.yxx" { - dc_file->add_typedef(new DCTypedef(yyvsp[0].u.parameter)); + dc_file->add_import_symbol(yyvsp[0].str); } break; -case 25: -#line 223 "dcParser.yxx" +case 23: +#line 218 "dcParser.yxx" +{ + dc_file->add_import_symbol(yyvsp[0].str); +} + break; +case 24: +#line 225 "dcParser.yxx" +{ + DCTypedef *dtypedef = new DCTypedef(yyvsp[0].u.parameter); + + if (!dc_file->add_typedef(dtypedef)) { + DCTypedef *old_typedef = dc_file->get_typedef_by_name(dtypedef->get_name()); + if (old_typedef->is_bogus_typedef()) { + yyerror("typedef defined after its first reference: " + dtypedef->get_name()); + } else { + yyerror("Duplicate typedef name: " + dtypedef->get_name()); + } + } +} + break; +case 27: +#line 246 "dcParser.yxx" { if (yyvsp[0].u.dclass != (DCClass *)NULL) { current_class->add_parent(yyvsp[0].u.dclass); } } break; -case 26: -#line 229 "dcParser.yxx" +case 28: +#line 252 "dcParser.yxx" { if (yyvsp[0].u.dclass != (DCClass *)NULL) { current_class->add_parent(yyvsp[0].u.dclass); } } break; -case 31: -#line 245 "dcParser.yxx" +case 33: +#line 265 "dcParser.yxx" +{ + current_class->add_parameter(yyvsp[-1].u.parameter); +} + break; +case 34: +#line 269 "dcParser.yxx" +{ + if (!current_class->add_parameter(yyvsp[0].u.parameter)) { + yyerror("Duplicate parameter name: " + yyvsp[0].u.parameter->get_name()); + } +} + break; +case 35: +#line 278 "dcParser.yxx" { current_atomic = new DCAtomicField(yyvsp[-1].str); if (!current_class->add_field(current_atomic)) { @@ -1185,8 +1236,8 @@ case 31: } } break; -case 33: -#line 256 "dcParser.yxx" +case 37: +#line 289 "dcParser.yxx" { DCField *field = current_class->get_field_by_name(yyvsp[0].str); yyval.u.atomic = (DCAtomicField *)NULL; @@ -1200,53 +1251,59 @@ case 33: } } break; -case 38: -#line 282 "dcParser.yxx" +case 42: +#line 315 "dcParser.yxx" { atomic_element = DCAtomicField::ElementType(yyvsp[0].u.parameter); current_atomic->add_element(atomic_element); } break; -case 39: -#line 287 "dcParser.yxx" +case 43: +#line 320 "dcParser.yxx" { current_packer = &default_packer; current_packer->begin_pack(yyvsp[-1].u.parameter); } break; -case 40: -#line 292 "dcParser.yxx" +case 44: +#line 325 "dcParser.yxx" { - if (!current_packer->end_pack()) { - yyerror("Invalid default value for type"); + bool is_valid = yyvsp[-3].u.parameter->is_valid(); + atomic_element = DCAtomicField::ElementType(yyvsp[-3].u.parameter); + if (current_packer->end_pack()) { + atomic_element.set_default_value(current_packer->get_string()); } else { - atomic_element = DCAtomicField::ElementType(yyvsp[-3].u.parameter); - atomic_element.set_default_value(current_packer->get_string()); - current_atomic->add_element(atomic_element); + if (is_valid) { + yyerror("Invalid default value for type"); + } + // If the current parameter isn't valid, we don't mind a pack + // error (there's no way for us to validate the syntax). So we'll + // just ignore the default value in this case. } + current_atomic->add_element(atomic_element); } break; -case 41: -#line 306 "dcParser.yxx" +case 45: +#line 345 "dcParser.yxx" { current_parameter = yyvsp[0].u.parameter; } break; -case 42: -#line 310 "dcParser.yxx" +case 46: +#line 349 "dcParser.yxx" { yyval.u.parameter = yyvsp[0].u.parameter; } break; -case 44: -#line 318 "dcParser.yxx" +case 50: +#line 365 "dcParser.yxx" { yyval.u.parameter = new DCSimpleParameter(yyvsp[0].u.subatomic); } break; -case 45: -#line 322 "dcParser.yxx" +case 51: +#line 369 "dcParser.yxx" { DCSimpleParameter *simple_param = new DCSimpleParameter(yyvsp[-2].u.subatomic); if (yyvsp[0].u.integer == 0) { @@ -1258,39 +1315,48 @@ case 45: yyval.u.parameter = simple_param; } break; -case 46: -#line 333 "dcParser.yxx" +case 52: +#line 380 "dcParser.yxx" { DCTypedef *dtypedef = dc_file->get_typedef_by_name(yyvsp[0].str); if (dtypedef == (DCTypedef *)NULL) { - yyerror("Invalid type name"); + // Maybe it's a class name. + DCClass *dclass = dc_file->get_class_by_name(yyvsp[0].str); + if (dclass != (DCClass *)NULL) { + // Create an implicit typedef for this. + dtypedef = new DCTypedef(new DCClassParameter(dclass), true); + } else { + // It's an undefined typedef. Create a bogus forward reference. + dtypedef = new DCTypedef(yyvsp[0].str); + } - } else { - yyval.u.parameter = dtypedef->make_new_parameter(); + dc_file->add_typedef(dtypedef); } + + yyval.u.parameter = dtypedef->make_new_parameter(); } break; -case 48: -#line 347 "dcParser.yxx" +case 54: +#line 403 "dcParser.yxx" { yyval.u.parameter = new DCArrayParameter(yyvsp[-2].u.parameter); } break; -case 49: -#line 351 "dcParser.yxx" +case 55: +#line 407 "dcParser.yxx" { yyval.u.parameter = new DCArrayParameter(yyvsp[-3].u.parameter, yyvsp[-1].u.integer); } break; -case 50: -#line 358 "dcParser.yxx" +case 56: +#line 414 "dcParser.yxx" { current_parameter->set_name(yyvsp[0].str); yyval.u.parameter = current_parameter; } break; -case 51: -#line 363 "dcParser.yxx" +case 57: +#line 419 "dcParser.yxx" { if (yyvsp[0].u.integer == 0) { yyerror("Invalid divisor."); @@ -1305,272 +1371,272 @@ case 51: } } break; -case 52: -#line 377 "dcParser.yxx" +case 58: +#line 433 "dcParser.yxx" { yyval.u.parameter = new DCArrayParameter(yyvsp[-2].u.parameter); } break; -case 53: -#line 381 "dcParser.yxx" +case 59: +#line 437 "dcParser.yxx" { yyval.u.parameter = new DCArrayParameter(yyvsp[-3].u.parameter, yyvsp[-1].u.integer); } break; -case 54: -#line 388 "dcParser.yxx" +case 60: +#line 444 "dcParser.yxx" { - current_packer->pack_int(yyvsp[0].u.integer); + current_packer->pack_int64(yyvsp[0].u.integer); } break; -case 55: -#line 392 "dcParser.yxx" +case 61: +#line 448 "dcParser.yxx" { current_packer->pack_double(yyvsp[0].u.real); } break; -case 56: -#line 396 "dcParser.yxx" +case 62: +#line 452 "dcParser.yxx" { current_packer->pack_string(yyvsp[0].str); } break; -case 57: -#line 400 "dcParser.yxx" +case 63: +#line 456 "dcParser.yxx" { current_packer->pack_literal_value(yyvsp[0].str); } break; -case 58: -#line 404 "dcParser.yxx" -{ - current_packer->push(); -} - break; -case 59: -#line 408 "dcParser.yxx" -{ - current_packer->pop(); -} - break; -case 60: -#line 412 "dcParser.yxx" -{ - current_packer->push(); -} - break; -case 61: -#line 416 "dcParser.yxx" -{ - current_packer->pop(); -} - break; -case 62: -#line 420 "dcParser.yxx" -{ - current_packer->push(); -} - break; -case 63: -#line 424 "dcParser.yxx" -{ - current_packer->pop(); -} - break; case 64: -#line 428 "dcParser.yxx" +#line 460 "dcParser.yxx" { - for (int i = 0; i < yyvsp[0].u.integer; i++) { - current_packer->pack_int(yyvsp[-2].u.integer); - } + current_packer->push(); } break; case 65: -#line 434 "dcParser.yxx" +#line 464 "dcParser.yxx" +{ + current_packer->pop(); +} + break; +case 66: +#line 468 "dcParser.yxx" +{ + current_packer->push(); +} + break; +case 67: +#line 472 "dcParser.yxx" +{ + current_packer->pop(); +} + break; +case 68: +#line 476 "dcParser.yxx" +{ + current_packer->push(); +} + break; +case 69: +#line 480 "dcParser.yxx" +{ + current_packer->pop(); +} + break; +case 70: +#line 484 "dcParser.yxx" +{ + for (int i = 0; i < yyvsp[0].u.integer; i++) { + current_packer->pack_int64(yyvsp[-2].u.integer); + } +} + break; +case 71: +#line 490 "dcParser.yxx" { for (int i = 0; i < yyvsp[0].u.integer; i++) { current_packer->pack_double(yyvsp[-2].u.real); } } break; -case 66: -#line 440 "dcParser.yxx" +case 72: +#line 496 "dcParser.yxx" { for (int i = 0; i < yyvsp[0].u.integer; i++) { current_packer->pack_literal_value(yyvsp[-2].str); } } break; -case 73: -#line 464 "dcParser.yxx" +case 79: +#line 520 "dcParser.yxx" { yyval.u.subatomic = ST_int8; } break; -case 74: -#line 468 "dcParser.yxx" +case 80: +#line 524 "dcParser.yxx" { yyval.u.subatomic = ST_int16; } break; -case 75: -#line 472 "dcParser.yxx" +case 81: +#line 528 "dcParser.yxx" { yyval.u.subatomic = ST_int32; } break; -case 76: -#line 476 "dcParser.yxx" +case 82: +#line 532 "dcParser.yxx" { yyval.u.subatomic = ST_int64; } break; -case 77: -#line 480 "dcParser.yxx" +case 83: +#line 536 "dcParser.yxx" { yyval.u.subatomic = ST_uint8; } break; -case 78: -#line 484 "dcParser.yxx" +case 84: +#line 540 "dcParser.yxx" { yyval.u.subatomic = ST_uint16; } break; -case 79: -#line 488 "dcParser.yxx" +case 85: +#line 544 "dcParser.yxx" { yyval.u.subatomic = ST_uint32; } break; -case 80: -#line 492 "dcParser.yxx" +case 86: +#line 548 "dcParser.yxx" { yyval.u.subatomic = ST_uint64; } break; -case 81: -#line 496 "dcParser.yxx" +case 87: +#line 552 "dcParser.yxx" { yyval.u.subatomic = ST_float64; } break; -case 82: -#line 500 "dcParser.yxx" +case 88: +#line 556 "dcParser.yxx" { yyval.u.subatomic = ST_string; } break; -case 83: -#line 504 "dcParser.yxx" +case 89: +#line 560 "dcParser.yxx" { yyval.u.subatomic = ST_blob; } break; -case 84: -#line 508 "dcParser.yxx" +case 90: +#line 564 "dcParser.yxx" { yyval.u.subatomic = ST_blob32; } break; -case 85: -#line 512 "dcParser.yxx" +case 91: +#line 568 "dcParser.yxx" { yyval.u.subatomic = ST_int8array; } break; -case 86: -#line 516 "dcParser.yxx" +case 92: +#line 572 "dcParser.yxx" { yyval.u.subatomic = ST_int16array; } break; -case 87: -#line 520 "dcParser.yxx" +case 93: +#line 576 "dcParser.yxx" { yyval.u.subatomic = ST_int32array; } break; -case 88: -#line 524 "dcParser.yxx" +case 94: +#line 580 "dcParser.yxx" { yyval.u.subatomic = ST_uint8array; } break; -case 89: -#line 528 "dcParser.yxx" +case 95: +#line 584 "dcParser.yxx" { yyval.u.subatomic = ST_uint16array; } break; -case 90: -#line 532 "dcParser.yxx" +case 96: +#line 588 "dcParser.yxx" { yyval.u.subatomic = ST_uint32array; } break; -case 91: -#line 536 "dcParser.yxx" +case 97: +#line 592 "dcParser.yxx" { yyval.u.subatomic = ST_uint32uint8array; } break; -case 93: -#line 544 "dcParser.yxx" +case 99: +#line 600 "dcParser.yxx" { current_atomic->add_flag(DCAtomicField::F_required); } break; -case 94: -#line 548 "dcParser.yxx" +case 100: +#line 604 "dcParser.yxx" { current_atomic->add_flag(DCAtomicField::F_broadcast); } break; -case 95: -#line 552 "dcParser.yxx" +case 101: +#line 608 "dcParser.yxx" { current_atomic->add_flag(DCAtomicField::F_p2p); } break; -case 96: -#line 556 "dcParser.yxx" +case 102: +#line 612 "dcParser.yxx" { current_atomic->add_flag(DCAtomicField::F_ram); } break; -case 97: -#line 560 "dcParser.yxx" +case 103: +#line 616 "dcParser.yxx" { current_atomic->add_flag(DCAtomicField::F_db); } break; -case 98: -#line 564 "dcParser.yxx" +case 104: +#line 620 "dcParser.yxx" { current_atomic->add_flag(DCAtomicField::F_clsend); } break; -case 99: -#line 568 "dcParser.yxx" +case 105: +#line 624 "dcParser.yxx" { current_atomic->add_flag(DCAtomicField::F_clrecv); } break; -case 100: -#line 572 "dcParser.yxx" +case 106: +#line 628 "dcParser.yxx" { current_atomic->add_flag(DCAtomicField::F_ownsend); } break; -case 101: -#line 576 "dcParser.yxx" +case 107: +#line 632 "dcParser.yxx" { current_atomic->add_flag(DCAtomicField::F_airecv); } break; -case 102: -#line 583 "dcParser.yxx" +case 108: +#line 639 "dcParser.yxx" { current_molecular = new DCMolecularField(yyvsp[-1].str); if (!current_class->add_field(current_molecular)) { @@ -1578,16 +1644,16 @@ case 102: } } break; -case 104: -#line 594 "dcParser.yxx" +case 110: +#line 650 "dcParser.yxx" { if (yyvsp[0].u.atomic != (DCAtomicField *)NULL) { current_molecular->add_atomic(yyvsp[0].u.atomic); } } break; -case 105: -#line 600 "dcParser.yxx" +case 111: +#line 656 "dcParser.yxx" { if (yyvsp[0].u.atomic != (DCAtomicField *)NULL) { current_molecular->add_atomic(yyvsp[0].u.atomic); @@ -1832,4 +1898,4 @@ yyreturn: #endif return yyresult; } -#line 615 "dcParser.yxx" +#line 671 "dcParser.yxx" diff --git a/direct/src/dcparser/dcParser.h.prebuilt b/direct/src/dcparser/dcParser.h.prebuilt index bbf08f4f66..bdaac625ea 100644 --- a/direct/src/dcparser/dcParser.h.prebuilt +++ b/direct/src/dcparser/dcParser.h.prebuilt @@ -7,29 +7,29 @@ # define HEX_STRING 260 # define IDENTIFIER 261 # define KW_DCLASS 262 -# define KW_FROM 263 -# define KW_IMPORT 264 -# 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_STRUCT 263 +# define KW_FROM 264 +# define KW_IMPORT 265 +# define KW_TYPEDEF 266 +# define KW_INT8 267 +# define KW_INT16 268 +# define KW_INT32 269 +# define KW_INT64 270 +# define KW_UINT8 271 +# define KW_UINT16 272 +# define KW_UINT32 273 +# define KW_UINT64 274 +# define KW_FLOAT64 275 +# define KW_STRING 276 +# define KW_BLOB 277 +# define KW_BLOB32 278 +# define KW_INT8ARRAY 279 +# define KW_INT16ARRAY 280 +# define KW_INT32ARRAY 281 +# define KW_UINT8ARRAY 282 +# define KW_UINT16ARRAY 283 +# define KW_UINT32ARRAY 284 +# define KW_UINT32UINT8ARRAY 285 # define KW_REQUIRED 286 # define KW_BROADCAST 287 # define KW_P2P 288 diff --git a/direct/src/dcparser/dcParser.yxx b/direct/src/dcparser/dcParser.yxx index da180098c8..e2006c4605 100644 --- a/direct/src/dcparser/dcParser.yxx +++ b/direct/src/dcparser/dcParser.yxx @@ -10,6 +10,7 @@ #include "dcClass.h" #include "dcAtomicField.h" #include "dcMolecularField.h" +#include "dcClassParameter.h" #include "dcArrayParameter.h" #include "dcSimpleParameter.h" #include "dcTypedef.h" @@ -63,6 +64,7 @@ dc_cleanup_parser() { %token STRING HEX_STRING IDENTIFIER %token KW_DCLASS +%token KW_STRUCT %token KW_FROM %token KW_IMPORT %token KW_TYPEDEF @@ -87,8 +89,6 @@ dc_cleanup_parser() { %token KW_UINT32ARRAY %token KW_UINT32UINT8ARRAY -%token KW_MOL - %token KW_REQUIRED %token KW_BROADCAST %token KW_P2P @@ -105,11 +105,14 @@ dc_cleanup_parser() { %token START_DC %token START_PARAMETER_VALUE +%type kw_struct_or_kw_dclass %type dclass_name %type atomic_name %type type_token %type type_name %type type_definition +%type named_parameter +%type unnamed_parameter %type parameter %type parameter_definition %type import_identifier @@ -131,9 +134,9 @@ dc: ; dclass: - KW_DCLASS IDENTIFIER + kw_struct_or_kw_dclass IDENTIFIER { - current_class = new DCClass($2); + current_class = new DCClass($2, $1, false); if (!dc_file->add_class(current_class)) { DCClass *old_class = dc_file->get_class_by_name(current_class->get_name()); if (old_class->is_bogus_class()) { @@ -146,12 +149,23 @@ dclass: dclass_derivation '{' dclass_fields '}' ; +kw_struct_or_kw_dclass: + KW_STRUCT +{ + $$ = true; +} + | KW_DCLASS +{ + $$ = false; +} + ; + dclass_name: IDENTIFIER { DCClass *dclass = dc_file->get_class_by_name($1); if (dclass == (DCClass *)NULL) { - dclass = new DCClass($1, true); + dclass = new DCClass($1, false, true); dc_file->add_class(dclass); } @@ -247,6 +261,16 @@ dclass_fields: | dclass_fields ';' | dclass_fields atomic_field | dclass_fields molecular_field + | dclass_fields unnamed_parameter ';' +{ + current_class->add_parameter($2); +} + | dclass_fields named_parameter +{ + if (!current_class->add_parameter($2)) { + yyerror("Duplicate parameter name: " + $2->get_name()); + } +} ; atomic_field: @@ -316,7 +340,7 @@ atomic_element: } ; -parameter: +named_parameter: type_definition { current_parameter = $1; @@ -325,7 +349,15 @@ parameter: { $$ = $3; } - | type_definition + ; + +unnamed_parameter: + type_definition + ; + +parameter: + named_parameter + | unnamed_parameter ; type_name: @@ -348,7 +380,16 @@ type_name: { DCTypedef *dtypedef = dc_file->get_typedef_by_name($1); if (dtypedef == (DCTypedef *)NULL) { - dtypedef = new DCTypedef($1); + // Maybe it's a class name. + DCClass *dclass = dc_file->get_class_by_name($1); + if (dclass != (DCClass *)NULL) { + // Create an implicit typedef for this. + dtypedef = new DCTypedef(new DCClassParameter(dclass), true); + } else { + // It's an undefined typedef. Create a bogus forward reference. + dtypedef = new DCTypedef($1); + } + dc_file->add_typedef(dtypedef); } diff --git a/direct/src/dcparser/dcParserDefs.h b/direct/src/dcparser/dcParserDefs.h index 2c357b376b..cb984c4c4f 100644 --- a/direct/src/dcparser/dcParserDefs.h +++ b/direct/src/dcparser/dcParserDefs.h @@ -46,6 +46,7 @@ public: union U { PN_int64 integer; double real; + bool flag; DCClass *dclass; DCAtomicField *atomic; DCSubatomicType subatomic; diff --git a/direct/src/dcparser/dcSimpleParameter.cxx b/direct/src/dcparser/dcSimpleParameter.cxx index 99e6a4399b..1ba1bfed7c 100644 --- a/direct/src/dcparser/dcSimpleParameter.cxx +++ b/direct/src/dcparser/dcSimpleParameter.cxx @@ -1202,7 +1202,7 @@ Uint32Uint8Type() { _uint8_type = new DCSimpleParameter(ST_uint8); _has_nested_fields = true; _num_nested_fields = 2; - _pack_type = PT_struct; + _pack_type = PT_class; } //////////////////////////////////////////////////////////////////// diff --git a/direct/src/dcparser/dcTypedef.cxx b/direct/src/dcparser/dcTypedef.cxx index 035cea28fc..0562940ae7 100644 --- a/direct/src/dcparser/dcTypedef.cxx +++ b/direct/src/dcparser/dcTypedef.cxx @@ -27,9 +27,10 @@ // Description: //////////////////////////////////////////////////////////////////// DCTypedef:: -DCTypedef(DCParameter *parameter) : +DCTypedef(DCParameter *parameter, bool implicit) : _parameter(parameter), _bogus_typedef(false), + _implicit_typedef(implicit), _number(-1) { } @@ -43,6 +44,7 @@ DCTypedef:: DCTypedef(const string &name) : _parameter(new DCSimpleParameter(ST_invalid)), _bogus_typedef(true), + _implicit_typedef(false), _number(-1) { _parameter->set_name(name); @@ -107,6 +109,18 @@ is_bogus_typedef() const { return _bogus_typedef; } +//////////////////////////////////////////////////////////////////// +// Function: DCTypedef::is_implicit_typedef +// Access: Public +// Description: Returns true if the typedef has been flagged as an +// implicit typedef, meaning it was created for a +// DCClass that was referenced inline as a type. +//////////////////////////////////////////////////////////////////// +bool DCTypedef:: +is_implicit_typedef() const { + return _implicit_typedef; +} + //////////////////////////////////////////////////////////////////// // Function: DCTypedef::make_new_parameter // Access: Public @@ -135,7 +149,7 @@ set_number(int number) { //////////////////////////////////////////////////////////////////// // Function: DCTypedef::write -// Access: Public +// Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// void DCTypedef:: @@ -153,4 +167,3 @@ write(ostream &out, bool brief, int indent_level) const { } out << "\n"; } - diff --git a/direct/src/dcparser/dcTypedef.h b/direct/src/dcparser/dcTypedef.h index e1c63e3e49..418611f14c 100644 --- a/direct/src/dcparser/dcTypedef.h +++ b/direct/src/dcparser/dcTypedef.h @@ -20,6 +20,7 @@ #define DCTYPEDEF_H #include "dcbase.h" +#include "dcDeclaration.h" class DCParameter; @@ -29,11 +30,11 @@ class DCParameter; // dc file. It assigns a particular type to a new name, // just like a C typedef. //////////////////////////////////////////////////////////////////// -class EXPCL_DIRECT DCTypedef { +class EXPCL_DIRECT DCTypedef : public DCDeclaration { public: - DCTypedef(DCParameter *parameter); + DCTypedef(DCParameter *parameter, bool implicit = false); DCTypedef(const string &name); - ~DCTypedef(); + virtual ~DCTypedef(); PUBLISHED: int get_number() const; @@ -41,16 +42,18 @@ PUBLISHED: string get_description() const; bool is_bogus_typedef() const; + bool is_implicit_typedef() const; public: DCParameter *make_new_parameter() const; void set_number(int number); - void write(ostream &out, bool brief, int indent_level) const; + virtual void write(ostream &out, bool brief, int indent_level) const; private: DCParameter *_parameter; bool _bogus_typedef; + bool _implicit_typedef; int _number; }; diff --git a/direct/src/dcparser/dcparser_composite1.cxx b/direct/src/dcparser/dcparser_composite1.cxx index da2e12063e..2b992aadfd 100644 --- a/direct/src/dcparser/dcparser_composite1.cxx +++ b/direct/src/dcparser/dcparser_composite1.cxx @@ -3,6 +3,7 @@ #include "hashGenerator.cxx" #include "dcAtomicField.cxx" #include "dcClass.cxx" +#include "dcDeclaration.cxx" #include "dcPackData.cxx" #include "dcPacker.cxx" #include "dcPackerInterface.cxx" diff --git a/direct/src/dcparser/dcparser_composite2.cxx b/direct/src/dcparser/dcparser_composite2.cxx index f3c56f186b..4b1e960e2c 100644 --- a/direct/src/dcparser/dcparser_composite2.cxx +++ b/direct/src/dcparser/dcparser_composite2.cxx @@ -1,5 +1,6 @@ #include "dcParameter.cxx" +#include "dcClassParameter.cxx" #include "dcArrayParameter.cxx" #include "dcSimpleParameter.cxx" #include "dcField.cxx"