00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00031
00032
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
00046
00047
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
00059
00060
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
00071
00072
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
00083
00084
00085
00086 CPPInstanceIdentifier::
00087 CPPInstanceIdentifier(CPPIdentifier *ident) : _ident(ident) {
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
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
00108
00109
00110
00111 void CPPInstanceIdentifier::
00112 add_modifier(CPPInstanceIdentifierType type) {
00113 _modifiers.push_back(Modifier(type));
00114 }
00115
00116
00117
00118
00119
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
00133
00134
00135
00136 void CPPInstanceIdentifier::
00137 add_array_modifier(CPPExpression *expr) {
00138 _modifiers.push_back(Modifier::array_type(expr));
00139 }
00140
00141
00142
00143
00144
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
00158
00159
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 }