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

dtool/src/cppparser/cppInstanceIdentifier.cxx

Go to the documentation of this file.
00001 // Filename: cppInstanceIdentifier.cxx
00002 // Created by:  drose (21Oct99)
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 "cppInstanceIdentifier.h"
00021 #include "cppPointerType.h"
00022 #include "cppReferenceType.h"
00023 #include "cppArrayType.h"
00024 #include "cppConstType.h"
00025 #include "cppFunctionType.h"
00026 #include "cppParameterList.h"
00027 #include "cppIdentifier.h"
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: CPPInstanceIdentifier::Modifier::Constructor
00031 //       Access: Public
00032 //  Description:
00033 ////////////////////////////////////////////////////////////////////
00034 CPPInstanceIdentifier::Modifier::
00035 Modifier(CPPInstanceIdentifierType type) :
00036   _type(type)
00037 {
00038   _func_params = NULL;
00039   _func_flags = 0;
00040   _scoping = NULL;
00041   _expr = NULL;
00042 }
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //     Function: CPPInstanceIdentifier::Modifier::named func_type constructor
00046 //       Access: Public, Static
00047 //  Description:
00048 ////////////////////////////////////////////////////////////////////
00049 CPPInstanceIdentifier::Modifier CPPInstanceIdentifier::Modifier::
00050 func_type(CPPParameterList *params, int flags) {
00051   Modifier mod(IIT_func);
00052   mod._func_params = params;
00053   mod._func_flags = flags;
00054   return mod;
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: CPPInstanceIdentifier::Modifier::named array_type constructor
00059 //       Access: Public, Static
00060 //  Description:
00061 ////////////////////////////////////////////////////////////////////
00062 CPPInstanceIdentifier::Modifier CPPInstanceIdentifier::Modifier::
00063 array_type(CPPExpression *expr) {
00064   Modifier mod(IIT_array);
00065   mod._expr = expr;
00066   return mod;
00067 }
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: CPPInstanceIdentifier::Modifier::named scoped_pointer_type
00071 //       Access: Public, Static
00072 //  Description:
00073 ////////////////////////////////////////////////////////////////////
00074 CPPInstanceIdentifier::Modifier CPPInstanceIdentifier::Modifier::
00075 scoped_pointer_type(CPPIdentifier *scoping) {
00076   Modifier mod(IIT_scoped_pointer);
00077   mod._scoping = scoping;
00078   return mod;
00079 }
00080 
00081 ////////////////////////////////////////////////////////////////////
00082 //     Function: CPPInstanceIdentifier::Constructor
00083 //       Access: Public
00084 //  Description:
00085 ////////////////////////////////////////////////////////////////////
00086 CPPInstanceIdentifier::
00087 CPPInstanceIdentifier(CPPIdentifier *ident) : _ident(ident) {
00088 }
00089 
00090 ////////////////////////////////////////////////////////////////////
00091 //     Function: CPPInstanceIdentifier::unroll_type
00092 //       Access: Public
00093 //  Description: Unrolls the list of type punctuation on either side
00094 //               of the identifier to determine the actual type
00095 //               represented by the identifier, given the indicated
00096 //               starting type (that is, the type name written to the
00097 //               left of the identifier).
00098 ////////////////////////////////////////////////////////////////////
00099 CPPType *CPPInstanceIdentifier::
00100 unroll_type(CPPType *start_type) {
00101   CPPType *result = r_unroll_type(start_type, _modifiers.begin());
00102   return result;
00103 }
00104 
00105 
00106 ////////////////////////////////////////////////////////////////////
00107 //     Function: CPPInstanceIdentifier::add_modifier
00108 //       Access: Public
00109 //  Description:
00110 ////////////////////////////////////////////////////////////////////
00111 void CPPInstanceIdentifier::
00112 add_modifier(CPPInstanceIdentifierType type) {
00113   _modifiers.push_back(Modifier(type));
00114 }
00115 
00116 ////////////////////////////////////////////////////////////////////
00117 //     Function: CPPInstanceIdentifier::add_modifier
00118 //       Access: Public
00119 //  Description:
00120 ////////////////////////////////////////////////////////////////////
00121 void CPPInstanceIdentifier::
00122 add_func_modifier(CPPParameterList *params, int flags) {
00123   _modifiers.push_back(Modifier::func_type(params, flags));
00124 }
00125 
00126 void CPPInstanceIdentifier::
00127 add_scoped_pointer_modifier(CPPIdentifier *scoping) {
00128   _modifiers.push_back(Modifier::scoped_pointer_type(scoping));
00129 }
00130 
00131 ////////////////////////////////////////////////////////////////////
00132 //     Function: CPPInstanceIdentifier::add_modifier
00133 //       Access: Public
00134 //  Description:
00135 ////////////////////////////////////////////////////////////////////
00136 void CPPInstanceIdentifier::
00137 add_array_modifier(CPPExpression *expr) {
00138   _modifiers.push_back(Modifier::array_type(expr));
00139 }
00140 
00141 ////////////////////////////////////////////////////////////////////
00142 //     Function: CPPInstanceIdentifier::get_scope
00143 //       Access: Public
00144 //  Description:
00145 ////////////////////////////////////////////////////////////////////
00146 CPPScope *CPPInstanceIdentifier::
00147 get_scope(CPPScope *current_scope, CPPScope *global_scope,
00148           CPPPreprocessor *error_sink) const {
00149   if (_ident == NULL) {
00150     return current_scope;
00151   } else {
00152     return _ident->get_scope(current_scope, global_scope, error_sink);
00153   }
00154 }
00155 
00156 ////////////////////////////////////////////////////////////////////
00157 //     Function: CPPInstanceIdentifier::r_unroll_type
00158 //       Access: Private
00159 //  Description: The recursive implementation of unroll_type().
00160 ////////////////////////////////////////////////////////////////////
00161 CPPType *CPPInstanceIdentifier::
00162 r_unroll_type(CPPType *start_type,
00163               CPPInstanceIdentifier::Modifiers::const_iterator mi) {
00164   start_type = CPPType::new_type(start_type);
00165 
00166   if (mi == _modifiers.end()) {
00167     return start_type;
00168   }
00169 
00170   const Modifier &mod = (*mi);
00171   ++mi;
00172 
00173   CPPType *result = NULL;
00174 
00175   switch (mod._type) {
00176   case IIT_pointer:
00177     result = new CPPPointerType(r_unroll_type(start_type, mi));
00178     break;
00179 
00180   case IIT_reference:
00181     result = new CPPReferenceType(r_unroll_type(start_type, mi));
00182     break;
00183 
00184   case IIT_scoped_pointer:
00185     {
00186       CPPType *type = r_unroll_type(start_type, mi);
00187       CPPFunctionType *ftype = type->as_function_type();
00188       if (ftype != NULL) {
00189         ftype = new CPPFunctionType(*ftype);
00190         ftype->_class_owner = mod._scoping;
00191         ftype->_flags |= CPPFunctionType::F_method_pointer;
00192         type = ftype;
00193       }
00194       result = new CPPPointerType(type);
00195     }
00196     break;
00197 
00198   case IIT_array:
00199     result = new CPPArrayType(r_unroll_type(start_type, mi),
00200                               mod._expr);
00201     break;
00202 
00203   case IIT_const:
00204     result = new CPPConstType(r_unroll_type(start_type, mi));
00205     break;
00206 
00207   case IIT_paren:
00208     result = r_unroll_type(start_type, mi);
00209     break;
00210 
00211   case IIT_func:
00212     {
00213       CPPType *return_type = r_unroll_type(start_type, mi);
00214       result = new CPPFunctionType(return_type, mod._func_params,
00215                                    mod._func_flags);
00216     }
00217     break;
00218 
00219   default:
00220     cerr << "Internal error--invalid CPPInstanceIdentifier\n";
00221     abort();
00222   }
00223 
00224   return CPPType::new_type(result);
00225 }

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