Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

dtool/src/cppparser/cppEnumType.cxx

Go to the documentation of this file.
00001 // Filename: cppEnumType.cxx
00002 // Created by:  drose (25Oct99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 
00020 #include "cppEnumType.h"
00021 #include "cppTypedef.h"
00022 #include "cppExpression.h"
00023 #include "cppSimpleType.h"
00024 #include "cppScope.h"
00025 #include "cppParser.h"
00026 #include "indent.h"
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: CPPEnumType::Constructor
00030 //       Access: Public
00031 //  Description:
00032 ////////////////////////////////////////////////////////////////////
00033 CPPEnumType::
00034 CPPEnumType(CPPIdentifier *ident, CPPScope *current_scope,
00035             const CPPFile &file) :
00036   CPPExtensionType(T_enum, ident, current_scope, file)
00037 {
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: CPPEnumType::add_element
00042 //       Access: Public
00043 //  Description:
00044 ////////////////////////////////////////////////////////////////////
00045 void CPPEnumType::
00046 add_element(const string &name, CPPScope *scope, CPPExpression *value) {
00047   CPPType *type =
00048     CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_int,
00049                                         CPPSimpleType::F_unsigned));
00050   CPPIdentifier *ident = new CPPIdentifier(name);
00051   CPPInstance *inst = new CPPInstance(type, ident);
00052   inst->_initializer = value;
00053   _elements.push_back(inst);
00054   scope->add_enum_value(inst);
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: CPPEnumType::is_incomplete
00059 //       Access: Public, Virtual
00060 //  Description: Returns true if the type has not yet been fully
00061 //               specified, false if it has.
00062 ////////////////////////////////////////////////////////////////////
00063 bool CPPEnumType::
00064 is_incomplete() const {
00065   return false;
00066 }
00067 
00068 ////////////////////////////////////////////////////////////////////
00069 //     Function: CPPEnumType::substitute_decl
00070 //       Access: Public, Virtual
00071 //  Description:
00072 ////////////////////////////////////////////////////////////////////
00073 CPPDeclaration *CPPEnumType::
00074 substitute_decl(CPPDeclaration::SubstDecl &subst,
00075                 CPPScope *current_scope, CPPScope *global_scope) {
00076   SubstDecl::const_iterator si = subst.find(this);
00077   if (si != subst.end()) {
00078     return (*si).second;
00079   }
00080 
00081   CPPEnumType *rep = new CPPEnumType(*this);
00082   if (_ident != NULL) {
00083     rep->_ident =
00084       _ident->substitute_decl(subst, current_scope, global_scope);
00085   }
00086 
00087   if (rep->_ident == _ident) {
00088     delete rep;
00089     rep = this;
00090   }
00091   rep = CPPType::new_type(rep)->as_enum_type();
00092   subst.insert(SubstDecl::value_type(this, rep));
00093 
00094   return rep;
00095 }
00096 
00097 ////////////////////////////////////////////////////////////////////
00098 //     Function: CPPEnumType::output
00099 //       Access: Public, Virtual
00100 //  Description:
00101 ////////////////////////////////////////////////////////////////////
00102 void CPPEnumType::
00103 output(ostream &out, int indent_level, CPPScope *scope, bool complete) const {
00104   if (!complete && _ident != NULL) {
00105     // If we have a name, use it.
00106     if (cppparser_output_class_keyword) {
00107       out << _type << " ";
00108     }
00109     out << _ident->get_local_name(scope);
00110 
00111   } else if (!complete && !_typedefs.empty()) {
00112     // If we have a typedef name, use it.
00113     out << _typedefs.front()->get_local_name(scope);
00114 
00115   } else {
00116     out << _type;
00117     if (_ident != NULL) {
00118       out << " " << _ident->get_local_name(scope);
00119     }
00120 
00121     out << " {\n";
00122     Elements::const_iterator ei;
00123     for (ei = _elements.begin(); ei != _elements.end(); ++ei) {
00124       indent(out, indent_level + 2) << (*ei)->get_local_name();
00125       if ((*ei)->_initializer != NULL) {
00126         out << " = " << *(*ei)->_initializer;
00127       }
00128       out << ",\n";
00129     }
00130     indent(out, indent_level) << "}";
00131   }
00132 }
00133 
00134 ////////////////////////////////////////////////////////////////////
00135 //     Function: CPPEnumType::get_subtype
00136 //       Access: Public, Virtual
00137 //  Description:
00138 ////////////////////////////////////////////////////////////////////
00139 CPPDeclaration::SubType CPPEnumType::
00140 get_subtype() const {
00141   return ST_enum;
00142 }
00143 
00144 ////////////////////////////////////////////////////////////////////
00145 //     Function: CPPEnumType::as_enum_type
00146 //       Access: Public, Virtual
00147 //  Description:
00148 ////////////////////////////////////////////////////////////////////
00149 CPPEnumType *CPPEnumType::
00150 as_enum_type() {
00151   return this;
00152 }

Generated on Thu May 1 22:12:50 2003 for DTool by doxygen1.3