Changes in uspace/app/sbi/src/run_texpr.c [074444f:38aaacc2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run_texpr.c
r074444f r38aaacc2 27 27 */ 28 28 29 /** @file Evaluate stype expressions. */29 /** @file Evaluate type expressions. */ 30 30 31 31 #include <assert.h> 32 32 #include <stdlib.h> 33 #include "debug.h" 33 34 #include "list.h" 34 35 #include "mytypes.h" 36 #include "stree.h" 35 37 #include "strtab.h" 36 38 #include "symbol.h" … … 50 52 stree_tapply_t *tapply, tdata_item_t **res); 51 53 54 /** Evaluate type expression. 55 * 56 * Evaluate type expression (this produces a type item). If a type error 57 * occurs, the resulting type item is of class @c tic_ignore. 58 * 59 * @param prog Program 60 * @param ctx Current CSI (context) 61 * @param texpr Type expression to evaluate 62 * @param res Place to store type result 63 */ 52 64 void run_texpr(stree_program_t *prog, stree_csi_t *ctx, stree_texpr_t *texpr, 53 65 tdata_item_t **res) … … 72 84 } 73 85 86 /** Evaluate type access expression. 87 * 88 * Evaluate operation per the type access ('.') operator. 89 * 90 * @param prog Program 91 * @param ctx Current CSI (context) 92 * @param taccess Type access expression to evaluate 93 * @param res Place to store type result 94 */ 74 95 static void run_taccess(stree_program_t *prog, stree_csi_t *ctx, 75 96 stree_taccess_t *taccess, tdata_item_t **res) … … 79 100 tdata_item_t *titem; 80 101 tdata_object_t *tobject; 102 tdata_deleg_t *tdeleg; 81 103 stree_csi_t *base_csi; 82 104 … … 111 133 } 112 134 113 if (sym->sc != sc_csi) { 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: 114 157 printf("Error: Symbol '"); 115 158 symbol_print_fqn(sym); 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; 159 printf("' is not a type.\n"); 160 titem = tdata_item_new(tic_ignore); 161 break; 162 } 128 163 129 164 *res = titem; 130 165 } 131 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 */ 132 178 static void run_tindex(stree_program_t *prog, stree_csi_t *ctx, 133 179 stree_tindex_t *tindex, tdata_item_t **res) … … 171 217 } 172 218 219 /** Evaluate type literal expression. 220 * 221 * @param prog Program 222 * @param ctx Current CSI (context) 223 * @param tliteral Type literal 224 * @param res Place to store type result 225 */ 173 226 static void run_tliteral(stree_program_t *prog, stree_csi_t *ctx, 174 227 stree_tliteral_t *tliteral, tdata_item_t **res) … … 207 260 tdata_item_t *titem; 208 261 tdata_object_t *tobject; 262 stree_targ_t *targ; 263 tdata_vref_t *tvref; 264 stree_deleg_t *deleg; 265 tdata_deleg_t *tdeleg; 209 266 210 267 #ifdef DEBUG_RUN_TRACE 211 268 printf("Evaluating type name reference.\n"); 212 #endif 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 */ 213 293 sym = symbol_lookup_in_csi(prog, ctx, tnameref->name); 214 294 if (sym == NULL) { … … 219 299 } 220 300 221 if (sym->sc != sc_csi) { 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: 222 335 printf("Error: Symbol '"); 223 336 symbol_print_fqn(sym); 224 printf("' is not a CSI.\n"); 225 *res = tdata_item_new(tic_ignore); 226 return; 227 } 228 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 229 372 /* Construct type item. */ 230 373 titem = tdata_item_new(tic_tobject); … … 232 375 titem->u.tobject = tobject; 233 376 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_TRACE252 printf("Evaluating type apply operation.\n");253 #endif254 /* Construct type item. */255 titem = tdata_item_new(tic_tobject);256 tobject = tdata_object_new();257 titem->u.tobject = tobject;258 259 377 /* Evaluate base (generic) type. */ 260 378 run_texpr(prog, ctx, tapply->gtype, &base_ti); … … 272 390 273 391 /* Evaluate type arguments. */ 392 farg_n = list_first(&tobject->csi->targ); 274 393 arg_n = list_first(&tapply->targs); 275 while (arg_n != NULL) { 394 while (farg_n != NULL && arg_n != NULL) { 395 farg = list_node_data(farg_n, stree_targ_t *); 276 396 arg = list_node_data(arg_n, stree_texpr_t *); 397 277 398 run_texpr(prog, ctx, arg, &arg_ti); 278 399 … … 284 405 list_append(&tobject->targs, arg_ti); 285 406 407 farg_n = list_next(&tobject->csi->targ, farg_n); 286 408 arg_n = list_next(&tapply->targs, arg_n); 287 409 } 288 410 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 289 417 *res = titem; 290 418 }
Note:
See TracChangeset
for help on using the changeset viewer.