Changes in uspace/app/sbi/src/run_texpr.c [38aaacc2:074444f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run_texpr.c
r38aaacc2 r074444f 27 27 */ 28 28 29 /** @file Evaluate type expressions. */29 /** @file Evaluates type expressions. */ 30 30 31 31 #include <assert.h> 32 32 #include <stdlib.h> 33 #include "debug.h"34 33 #include "list.h" 35 34 #include "mytypes.h" 36 #include "stree.h"37 35 #include "strtab.h" 38 36 #include "symbol.h" … … 52 50 stree_tapply_t *tapply, tdata_item_t **res); 53 51 54 /** Evaluate type expression.55 *56 * Evaluate type expression (this produces a type item). If a type error57 * occurs, the resulting type item is of class @c tic_ignore.58 *59 * @param prog Program60 * @param ctx Current CSI (context)61 * @param texpr Type expression to evaluate62 * @param res Place to store type result63 */64 52 void run_texpr(stree_program_t *prog, stree_csi_t *ctx, stree_texpr_t *texpr, 65 53 tdata_item_t **res) … … 84 72 } 85 73 86 /** Evaluate type access expression.87 *88 * Evaluate operation per the type access ('.') operator.89 *90 * @param prog Program91 * @param ctx Current CSI (context)92 * @param taccess Type access expression to evaluate93 * @param res Place to store type result94 */95 74 static void run_taccess(stree_program_t *prog, stree_csi_t *ctx, 96 75 stree_taccess_t *taccess, tdata_item_t **res) … … 100 79 tdata_item_t *titem; 101 80 tdata_object_t *tobject; 102 tdata_deleg_t *tdeleg;103 81 stree_csi_t *base_csi; 104 82 … … 133 111 } 134 112 135 switch (sym->sc) { 136 case sc_csi: 137 /* Construct type item. */ 138 titem = tdata_item_new(tic_tobject); 139 tobject = tdata_object_new(); 140 titem->u.tobject = tobject; 141 142 tobject->static_ref = b_false; 143 tobject->csi = sym->u.csi; 144 list_init(&tobject->targs); /* XXX */ 145 break; 146 case sc_deleg: 147 /* Construct type item. */ 148 titem = tdata_item_new(tic_tdeleg); 149 tdeleg = tdata_deleg_new(); 150 titem->u.tdeleg = tdeleg; 151 152 tdeleg->deleg = sym->u.deleg; 153 break; 154 case sc_fun: 155 case sc_var: 156 case sc_prop: 113 if (sym->sc != sc_csi) { 157 114 printf("Error: Symbol '"); 158 115 symbol_print_fqn(sym); 159 printf("' is not a type.\n"); 160 titem = tdata_item_new(tic_ignore); 161 break; 162 } 163 164 *res = titem; 165 } 166 167 /** Evaluate type indexing expression. 168 * 169 * Evaluate operation per the type indexing ('[', ']') operator. 170 * A type indexing operation may have extents specified or only rank 171 * specified. 172 * 173 * @param prog Program 174 * @param ctx Current CSI (context) 175 * @param tindex Type indexing expression to evaluate 176 * @param res Place to store type result 177 */ 116 printf("' is not a CSI.\n"); 117 *res = tdata_item_new(tic_ignore); 118 return; 119 } 120 121 /* Construct type item. */ 122 titem = tdata_item_new(tic_tobject); 123 tobject = tdata_object_new(); 124 titem->u.tobject = tobject; 125 126 tobject->static_ref = b_false; 127 tobject->csi = sym->u.csi; 128 129 *res = titem; 130 } 131 178 132 static void run_tindex(stree_program_t *prog, stree_csi_t *ctx, 179 133 stree_tindex_t *tindex, tdata_item_t **res) … … 217 171 } 218 172 219 /** Evaluate type literal expression.220 *221 * @param prog Program222 * @param ctx Current CSI (context)223 * @param tliteral Type literal224 * @param res Place to store type result225 */226 173 static void run_tliteral(stree_program_t *prog, stree_csi_t *ctx, 227 174 stree_tliteral_t *tliteral, tdata_item_t **res) … … 260 207 tdata_item_t *titem; 261 208 tdata_object_t *tobject; 262 stree_targ_t *targ;263 tdata_vref_t *tvref;264 stree_deleg_t *deleg;265 tdata_deleg_t *tdeleg;266 209 267 210 #ifdef DEBUG_RUN_TRACE 268 211 printf("Evaluating type name reference.\n"); 269 printf("'%s'\n", strtab_get_str(tnameref->name->sid)); 270 #endif 271 /* In interactive mode we are not in a class */ 272 if (ctx != NULL) { 273 /* Look for type argument */ 274 targ = stree_csi_find_targ(ctx, tnameref->name); 275 276 if (targ != NULL) { 277 /* Found type argument */ 278 #ifdef DEBUG_RUN_TRACE 279 printf("Found type argument '%s'.\n", 280 strtab_get_str(tnameref->name->sid)); 281 #endif 282 titem = tdata_item_new(tic_tvref); 283 tvref = tdata_vref_new(); 284 titem->u.tvref = tvref; 285 tvref->targ = targ; 286 287 *res = titem; 288 return; 289 } 290 } 291 292 /* Look for symbol */ 212 #endif 293 213 sym = symbol_lookup_in_csi(prog, ctx, tnameref->name); 294 214 if (sym == NULL) { … … 299 219 } 300 220 301 switch (sym->sc) { 302 case sc_csi: 303 /* Construct type item. */ 304 titem = tdata_item_new(tic_tobject); 305 tobject = tdata_object_new(); 306 titem->u.tobject = tobject; 307 308 tobject->static_ref = b_false; 309 tobject->csi = sym->u.csi; 310 list_init(&tobject->targs); /* XXX */ 311 break; 312 case sc_deleg: 313 /* Fetch stored delegate type. */ 314 deleg = symbol_to_deleg(sym); 315 assert(deleg != NULL); 316 if (deleg->titem == NULL) { 317 /* 318 * Prepare a partial delegate which will be completed 319 * later. 320 */ 321 titem = tdata_item_new(tic_tdeleg); 322 tdeleg = tdata_deleg_new(); 323 titem->u.tdeleg = tdeleg; 324 tdeleg->deleg = deleg; 325 tdeleg->tsig = NULL; 326 327 deleg->titem = titem; 328 } else { 329 titem = deleg->titem; 330 } 331 break; 332 case sc_fun: 333 case sc_var: 334 case sc_prop: 221 if (sym->sc != sc_csi) { 335 222 printf("Error: Symbol '"); 336 223 symbol_print_fqn(sym); 337 printf("' is not a type.\n"); 338 titem = tdata_item_new(tic_ignore); 339 break; 340 } 341 342 *res = titem; 343 } 344 345 /** Evaluate type application expression. 346 * 347 * In a type application expression type arguments are applied to a generic 348 * CSI. 349 * 350 * @param prog Program 351 * @param ctx Current CSI (context) 352 * @param tapply Type application expression 353 * @param res Place to store type result 354 */ 355 static void run_tapply(stree_program_t *prog, stree_csi_t *ctx, 356 stree_tapply_t *tapply, tdata_item_t **res) 357 { 358 tdata_item_t *base_ti; 359 tdata_item_t *arg_ti; 360 tdata_item_t *titem; 361 tdata_object_t *tobject; 362 363 list_node_t *arg_n; 364 stree_texpr_t *arg; 365 366 list_node_t *farg_n; 367 stree_targ_t *farg; 368 369 #ifdef DEBUG_RUN_TRACE 370 printf("Evaluating type apply operation.\n"); 371 #endif 224 printf("' is not a CSI.\n"); 225 *res = tdata_item_new(tic_ignore); 226 return; 227 } 228 372 229 /* Construct type item. */ 373 230 titem = tdata_item_new(tic_tobject); … … 375 232 titem->u.tobject = tobject; 376 233 234 tobject->static_ref = b_false; 235 tobject->csi = sym->u.csi; 236 237 *res = titem; 238 } 239 240 static void run_tapply(stree_program_t *prog, stree_csi_t *ctx, 241 stree_tapply_t *tapply, tdata_item_t **res) 242 { 243 tdata_item_t *base_ti; 244 tdata_item_t *arg_ti; 245 tdata_item_t *titem; 246 tdata_object_t *tobject; 247 248 list_node_t *arg_n; 249 stree_texpr_t *arg; 250 251 #ifdef DEBUG_RUN_TRACE 252 printf("Evaluating type apply operation.\n"); 253 #endif 254 /* Construct type item. */ 255 titem = tdata_item_new(tic_tobject); 256 tobject = tdata_object_new(); 257 titem->u.tobject = tobject; 258 377 259 /* Evaluate base (generic) type. */ 378 260 run_texpr(prog, ctx, tapply->gtype, &base_ti); … … 390 272 391 273 /* Evaluate type arguments. */ 392 farg_n = list_first(&tobject->csi->targ);393 274 arg_n = list_first(&tapply->targs); 394 while (farg_n != NULL && arg_n != NULL) { 395 farg = list_node_data(farg_n, stree_targ_t *); 275 while (arg_n != NULL) { 396 276 arg = list_node_data(arg_n, stree_texpr_t *); 397 398 277 run_texpr(prog, ctx, arg, &arg_ti); 399 278 … … 405 284 list_append(&tobject->targs, arg_ti); 406 285 407 farg_n = list_next(&tobject->csi->targ, farg_n);408 286 arg_n = list_next(&tapply->targs, arg_n); 409 287 } 410 288 411 if (farg_n != NULL || arg_n != NULL) { 412 printf("Error: Incorrect number of type arguments.\n"); 413 *res = tdata_item_new(tic_ignore); 414 return; 415 } 416 417 *res = titem; 418 } 289 *res = titem; 290 }
Note:
See TracChangeset
for help on using the changeset viewer.