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

dtool/src/cppparser/cppSimpleType.cxx

Go to the documentation of this file.
00001 // Filename: cppSimpleType.cxx
00002 // Created by:  drose (19Oct99)
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 #include "cppSimpleType.h"
00020 #include "cppGlobals.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //     Function: CPPSimpleType::Constructor
00024 //       Access: Public
00025 //  Description:
00026 ////////////////////////////////////////////////////////////////////
00027 CPPSimpleType::
00028 CPPSimpleType(CPPSimpleType::Type type, int flags) :
00029   CPPType(CPPFile()),
00030   _type(type), _flags(flags)
00031 {
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: CPPSimpleType::is_tbd
00036 //       Access: Public, Virtual
00037 //  Description: Returns true if the type, or any nested type within
00038 //               the type, is a CPPTBDType and thus isn't fully
00039 //               determined right now.  In this case, calling
00040 //               resolve_type() may or may not resolve the type.
00041 ////////////////////////////////////////////////////////////////////
00042 bool CPPSimpleType::
00043 is_tbd() const {
00044   return (_type == T_unknown);
00045 }
00046 
00047 ////////////////////////////////////////////////////////////////////
00048 //     Function: CPPSimpleType::get_preferred_name
00049 //       Access: Public, Virtual
00050 //  Description:
00051 ////////////////////////////////////////////////////////////////////
00052 string CPPSimpleType::
00053 get_preferred_name() const {
00054   // Simple types always prefer to use their native types.
00055   return get_local_name();
00056 }
00057 
00058 ////////////////////////////////////////////////////////////////////
00059 //     Function: CPPSimpleType::output
00060 //       Access: Public, Virtual
00061 //  Description:
00062 ////////////////////////////////////////////////////////////////////
00063 void CPPSimpleType::
00064 output(ostream &out, int, CPPScope *, bool) const {
00065   if (_flags & F_unsigned) {
00066     out << "unsigned ";
00067   }
00068 
00069   if (_flags & F_signed) {
00070     out << "signed ";
00071   }
00072 
00073   if ((_type == T_int && (_flags & F_longlong) != 0) &&
00074       !cpp_longlong_keyword.empty()) {
00075     // It's a long long, and we have a specific long long type name.
00076     // This is to output code for compilers that don't recognize "long
00077     // long int".
00078     out << cpp_longlong_keyword;
00079     return;
00080   }
00081 
00082   if (_flags & F_longlong) {
00083     out << "long long ";
00084   } else if (_flags & F_long) {
00085     out << "long ";
00086   } else if (_flags & F_short) {
00087     out << "short ";
00088   }
00089 
00090   switch (_type) {
00091   case T_bool:
00092     out << "bool";
00093     break;
00094 
00095   case T_char:
00096     out << "char";
00097     break;
00098 
00099   case T_int:
00100     out << "int";
00101     break;
00102 
00103   case T_float:
00104     out << "float";
00105     break;
00106 
00107   case T_double:
00108     out << "double";
00109     break;
00110 
00111   case T_void:
00112     out << "void";
00113     break;
00114 
00115   case T_unknown:
00116     out << "unknown";
00117     break;
00118 
00119   default:
00120     out << "***invalid type***";
00121   }
00122 }
00123 
00124 ////////////////////////////////////////////////////////////////////
00125 //     Function: CPPSimpleType::get_subtype
00126 //       Access: Public, Virtual
00127 //  Description:
00128 ////////////////////////////////////////////////////////////////////
00129 CPPDeclaration::SubType CPPSimpleType::
00130 get_subtype() const {
00131   return ST_simple;
00132 }
00133 
00134 ////////////////////////////////////////////////////////////////////
00135 //     Function: CPPSimpleType::as_simple_type
00136 //       Access: Public, Virtual
00137 //  Description:
00138 ////////////////////////////////////////////////////////////////////
00139 CPPSimpleType *CPPSimpleType::
00140 as_simple_type() {
00141   return this;
00142 }
00143 
00144 
00145 ////////////////////////////////////////////////////////////////////
00146 //     Function: CPPSimpleType::is_equal
00147 //       Access: Protected, Virtual
00148 //  Description: Called by CPPDeclaration() to determine whether this type is
00149 //               equivalent to another type of the same type.
00150 ////////////////////////////////////////////////////////////////////
00151 bool CPPSimpleType::
00152 is_equal(const CPPDeclaration *other) const {
00153   const CPPSimpleType *ot = ((CPPDeclaration *)other)->as_simple_type();
00154   assert(ot != NULL);
00155 
00156   return _type == ot->_type && _flags == ot->_flags;
00157 }
00158 
00159 
00160 ////////////////////////////////////////////////////////////////////
00161 //     Function: CPPSimpleType::is_less
00162 //       Access: Protected, Virtual
00163 //  Description: Called by CPPDeclaration() to determine whether this type
00164 //               should be ordered before another type of the same
00165 //               type, in an arbitrary but fixed ordering.
00166 ////////////////////////////////////////////////////////////////////
00167 bool CPPSimpleType::
00168 is_less(const CPPDeclaration *other) const {
00169   const CPPSimpleType *ot = ((CPPDeclaration *)other)->as_simple_type();
00170   assert(ot != NULL);
00171 
00172   if (_type != ot->_type) {
00173     return _type < ot->_type;
00174   }
00175   return _flags < ot->_flags;
00176 }

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