| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @file Evaluate type expressions. */
|
|---|
| 30 |
|
|---|
| 31 | #include <assert.h>
|
|---|
| 32 | #include <stdlib.h>
|
|---|
| 33 | #include "cspan.h"
|
|---|
| 34 | #include "debug.h"
|
|---|
| 35 | #include "list.h"
|
|---|
| 36 | #include "mytypes.h"
|
|---|
| 37 | #include "stree.h"
|
|---|
| 38 | #include "strtab.h"
|
|---|
| 39 | #include "symbol.h"
|
|---|
| 40 | #include "tdata.h"
|
|---|
| 41 |
|
|---|
| 42 | #include "run_texpr.h"
|
|---|
| 43 |
|
|---|
| 44 | static void run_taccess(stree_program_t *prog, stree_csi_t *ctx,
|
|---|
| 45 | stree_taccess_t *taccess, tdata_item_t **res);
|
|---|
| 46 | static void run_tindex(stree_program_t *prog, stree_csi_t *ctx,
|
|---|
| 47 | stree_tindex_t *tindex, tdata_item_t **res);
|
|---|
| 48 | static void run_tliteral(stree_program_t *prog, stree_csi_t *ctx,
|
|---|
| 49 | stree_tliteral_t *tliteral, tdata_item_t **res);
|
|---|
| 50 | static void run_tnameref(stree_program_t *prog, stree_csi_t *ctx,
|
|---|
| 51 | stree_tnameref_t *tnameref, tdata_item_t **res);
|
|---|
| 52 | static void run_tapply(stree_program_t *prog, stree_csi_t *ctx,
|
|---|
| 53 | stree_tapply_t *tapply, tdata_item_t **res);
|
|---|
| 54 |
|
|---|
| 55 | /** Evaluate type expression.
|
|---|
| 56 | *
|
|---|
| 57 | * Evaluate type expression (this produces a type item). If a type error
|
|---|
| 58 | * occurs, the resulting type item is of class @c tic_ignore.
|
|---|
| 59 | *
|
|---|
| 60 | * @param prog Program
|
|---|
| 61 | * @param ctx Current CSI (context)
|
|---|
| 62 | * @param texpr Type expression to evaluate
|
|---|
| 63 | * @param res Place to store type result
|
|---|
| 64 | */
|
|---|
| 65 | void run_texpr(stree_program_t *prog, stree_csi_t *ctx, stree_texpr_t *texpr,
|
|---|
| 66 | tdata_item_t **res)
|
|---|
| 67 | {
|
|---|
| 68 | switch (texpr->tc) {
|
|---|
| 69 | case tc_taccess:
|
|---|
| 70 | run_taccess(prog, ctx, texpr->u.taccess, res);
|
|---|
| 71 | break;
|
|---|
| 72 | case tc_tindex:
|
|---|
| 73 | run_tindex(prog, ctx, texpr->u.tindex, res);
|
|---|
| 74 | break;
|
|---|
| 75 | case tc_tliteral:
|
|---|
| 76 | run_tliteral(prog, ctx, texpr->u.tliteral, res);
|
|---|
| 77 | break;
|
|---|
| 78 | case tc_tnameref:
|
|---|
| 79 | run_tnameref(prog, ctx, texpr->u.tnameref, res);
|
|---|
| 80 | break;
|
|---|
| 81 | case tc_tapply:
|
|---|
| 82 | run_tapply(prog, ctx, texpr->u.tapply, res);
|
|---|
| 83 | break;
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | /** Evaluate type access expression.
|
|---|
| 88 | *
|
|---|
| 89 | * Evaluate operation per the type access ('.') operator.
|
|---|
| 90 | *
|
|---|
| 91 | * @param prog Program
|
|---|
| 92 | * @param ctx Current CSI (context)
|
|---|
| 93 | * @param taccess Type access expression to evaluate
|
|---|
| 94 | * @param res Place to store type result
|
|---|
| 95 | */
|
|---|
| 96 | static void run_taccess(stree_program_t *prog, stree_csi_t *ctx,
|
|---|
| 97 | stree_taccess_t *taccess, tdata_item_t **res)
|
|---|
| 98 | {
|
|---|
| 99 | stree_symbol_t *sym;
|
|---|
| 100 | tdata_item_t *targ_i;
|
|---|
| 101 | tdata_item_t *titem;
|
|---|
| 102 | tdata_object_t *tobject;
|
|---|
| 103 | tdata_deleg_t *tdeleg;
|
|---|
| 104 | stree_csi_t *base_csi;
|
|---|
| 105 | stree_deleg_t *deleg;
|
|---|
| 106 | stree_enum_t *enum_d;
|
|---|
| 107 | tdata_enum_t *tenum;
|
|---|
| 108 |
|
|---|
| 109 | #ifdef DEBUG_RUN_TRACE
|
|---|
| 110 | printf("Evaluating type access operation.\n");
|
|---|
| 111 | #endif
|
|---|
| 112 | /* Evaluate base type. */
|
|---|
| 113 | run_texpr(prog, ctx, taccess->arg, &targ_i);
|
|---|
| 114 |
|
|---|
| 115 | if (targ_i->tic == tic_ignore) {
|
|---|
| 116 | *res = tdata_item_new(tic_ignore);
|
|---|
| 117 | return;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | if (targ_i->tic != tic_tobject) {
|
|---|
| 121 | cspan_print(taccess->texpr->cspan);
|
|---|
| 122 | printf(" Error: Using '.' with type which is not an "
|
|---|
| 123 | "object.\n");
|
|---|
| 124 | *res = tdata_item_new(tic_ignore);
|
|---|
| 125 | return;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | /* Get base CSI. */
|
|---|
| 129 | base_csi = targ_i->u.tobject->csi;
|
|---|
| 130 |
|
|---|
| 131 | sym = symbol_lookup_in_csi(prog, base_csi, taccess->member_name);
|
|---|
| 132 | if (sym == NULL) {
|
|---|
| 133 | cspan_print(taccess->member_name->cspan);
|
|---|
| 134 | printf(" Error: CSI '");
|
|---|
| 135 | symbol_print_fqn(csi_to_symbol(base_csi));
|
|---|
| 136 | printf("' has no member named '%s'.\n",
|
|---|
| 137 | strtab_get_str(taccess->member_name->sid));
|
|---|
| 138 | *res = tdata_item_new(tic_ignore);
|
|---|
| 139 | return;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | /* Make compiler happy. */
|
|---|
| 143 | titem = NULL;
|
|---|
| 144 |
|
|---|
| 145 | switch (sym->sc) {
|
|---|
| 146 | case sc_csi:
|
|---|
| 147 | /* Construct type item. */
|
|---|
| 148 | titem = tdata_item_new(tic_tobject);
|
|---|
| 149 | tobject = tdata_object_new();
|
|---|
| 150 | titem->u.tobject = tobject;
|
|---|
| 151 |
|
|---|
| 152 | tobject->static_ref = sn_nonstatic;
|
|---|
| 153 | tobject->csi = sym->u.csi;
|
|---|
| 154 | list_init(&tobject->targs);
|
|---|
| 155 | break;
|
|---|
| 156 | case sc_ctor:
|
|---|
| 157 | /* It is not possible to reference a constructor explicitly. */
|
|---|
| 158 | assert(b_false);
|
|---|
| 159 | case sc_deleg:
|
|---|
| 160 | /* Fetch stored delegate type. */
|
|---|
| 161 | deleg = symbol_to_deleg(sym);
|
|---|
| 162 | assert(deleg != NULL);
|
|---|
| 163 | if (deleg->titem == NULL) {
|
|---|
| 164 | /*
|
|---|
| 165 | * Prepare a partial delegate which will be completed
|
|---|
| 166 | * later.
|
|---|
| 167 | */
|
|---|
| 168 | titem = tdata_item_new(tic_tdeleg);
|
|---|
| 169 | tdeleg = tdata_deleg_new();
|
|---|
| 170 | titem->u.tdeleg = tdeleg;
|
|---|
| 171 | tdeleg->deleg = deleg;
|
|---|
| 172 | tdeleg->tsig = NULL;
|
|---|
| 173 |
|
|---|
| 174 | deleg->titem = titem;
|
|---|
| 175 | } else {
|
|---|
| 176 | titem = deleg->titem;
|
|---|
| 177 | }
|
|---|
| 178 | break;
|
|---|
| 179 | case sc_enum:
|
|---|
| 180 | /* Fetch stored enum type. */
|
|---|
| 181 | enum_d = symbol_to_enum(sym);
|
|---|
| 182 | assert(enum_d != NULL);
|
|---|
| 183 | if (enum_d->titem == NULL) {
|
|---|
| 184 | /*
|
|---|
| 185 | * Prepare a partial enum whic will be completed
|
|---|
| 186 | * later.
|
|---|
| 187 | */
|
|---|
| 188 | titem = tdata_item_new(tic_tenum);
|
|---|
| 189 | tenum = tdata_enum_new();
|
|---|
| 190 | titem->u.tenum = tenum;
|
|---|
| 191 | tenum->enum_d = enum_d;
|
|---|
| 192 | } else {
|
|---|
| 193 | titem = enum_d->titem;
|
|---|
| 194 | }
|
|---|
| 195 | break;
|
|---|
| 196 | case sc_fun:
|
|---|
| 197 | case sc_var:
|
|---|
| 198 | case sc_prop:
|
|---|
| 199 | cspan_print(taccess->member_name->cspan);
|
|---|
| 200 | printf(" Error: Symbol '");
|
|---|
| 201 | symbol_print_fqn(sym);
|
|---|
| 202 | printf("' is not a type.\n");
|
|---|
| 203 | titem = tdata_item_new(tic_ignore);
|
|---|
| 204 | break;
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | *res = titem;
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | /** Evaluate type indexing expression.
|
|---|
| 211 | *
|
|---|
| 212 | * Evaluate operation per the type indexing ('[', ']') operator.
|
|---|
| 213 | * A type indexing operation may have extents specified or only rank
|
|---|
| 214 | * specified.
|
|---|
| 215 | *
|
|---|
| 216 | * @param prog Program
|
|---|
| 217 | * @param ctx Current CSI (context)
|
|---|
| 218 | * @param tindex Type indexing expression to evaluate
|
|---|
| 219 | * @param res Place to store type result
|
|---|
| 220 | */
|
|---|
| 221 | static void run_tindex(stree_program_t *prog, stree_csi_t *ctx,
|
|---|
| 222 | stree_tindex_t *tindex, tdata_item_t **res)
|
|---|
| 223 | {
|
|---|
| 224 | tdata_item_t *base_ti;
|
|---|
| 225 | tdata_item_t *titem;
|
|---|
| 226 | tdata_array_t *tarray;
|
|---|
| 227 | stree_expr_t *arg_expr;
|
|---|
| 228 | list_node_t *arg_node;
|
|---|
| 229 |
|
|---|
| 230 | #ifdef DEBUG_RUN_TRACE
|
|---|
| 231 | printf("Evaluating type index operation.\n");
|
|---|
| 232 | #endif
|
|---|
| 233 | /* Evaluate base type. */
|
|---|
| 234 | run_texpr(prog, ctx, tindex->base_type, &base_ti);
|
|---|
| 235 |
|
|---|
| 236 | if (base_ti->tic == tic_ignore) {
|
|---|
| 237 | *res = tdata_item_new(tic_ignore);
|
|---|
| 238 | return;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | /* Construct type item. */
|
|---|
| 242 | titem = tdata_item_new(tic_tarray);
|
|---|
| 243 | tarray = tdata_array_new();
|
|---|
| 244 | titem->u.tarray = tarray;
|
|---|
| 245 |
|
|---|
| 246 | tarray->base_ti = base_ti;
|
|---|
| 247 | tarray->rank = tindex->n_args;
|
|---|
| 248 |
|
|---|
| 249 | /* Copy extents. */
|
|---|
| 250 | list_init(&tarray->extents);
|
|---|
| 251 | arg_node = list_first(&tindex->args);
|
|---|
| 252 |
|
|---|
| 253 | while (arg_node != NULL) {
|
|---|
| 254 | arg_expr = list_node_data(arg_node, stree_expr_t *);
|
|---|
| 255 | list_append(&tarray->extents, arg_expr);
|
|---|
| 256 | arg_node = list_next(&tindex->args, arg_node);
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | *res = titem;
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | /** Evaluate type literal expression.
|
|---|
| 263 | *
|
|---|
| 264 | * @param prog Program
|
|---|
| 265 | * @param ctx Current CSI (context)
|
|---|
| 266 | * @param tliteral Type literal
|
|---|
| 267 | * @param res Place to store type result
|
|---|
| 268 | */
|
|---|
| 269 | static void run_tliteral(stree_program_t *prog, stree_csi_t *ctx,
|
|---|
| 270 | stree_tliteral_t *tliteral, tdata_item_t **res)
|
|---|
| 271 | {
|
|---|
| 272 | tdata_item_t *titem;
|
|---|
| 273 | tdata_primitive_t *tprimitive;
|
|---|
| 274 | tprimitive_class_t tpc;
|
|---|
| 275 |
|
|---|
| 276 | #ifdef DEBUG_RUN_TRACE
|
|---|
| 277 | printf("Evaluating type literal.\n");
|
|---|
| 278 | #endif
|
|---|
| 279 | (void) prog;
|
|---|
| 280 | (void) ctx;
|
|---|
| 281 | (void) tliteral;
|
|---|
| 282 |
|
|---|
| 283 | /* Make compiler happy. */
|
|---|
| 284 | tpc = 0;
|
|---|
| 285 |
|
|---|
| 286 | switch (tliteral->tlc) {
|
|---|
| 287 | case tlc_bool: tpc = tpc_bool; break;
|
|---|
| 288 | case tlc_char: tpc = tpc_char; break;
|
|---|
| 289 | case tlc_int: tpc = tpc_int; break;
|
|---|
| 290 | case tlc_string: tpc = tpc_string; break;
|
|---|
| 291 | case tlc_resource: tpc = tpc_resource; break;
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | /* Construct type item. */
|
|---|
| 295 | titem = tdata_item_new(tic_tprimitive);
|
|---|
| 296 | tprimitive = tdata_primitive_new(tpc);
|
|---|
| 297 | titem->u.tprimitive = tprimitive;
|
|---|
| 298 |
|
|---|
| 299 | *res = titem;
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | static void run_tnameref(stree_program_t *prog, stree_csi_t *ctx,
|
|---|
| 303 | stree_tnameref_t *tnameref, tdata_item_t **res)
|
|---|
| 304 | {
|
|---|
| 305 | stree_symbol_t *sym;
|
|---|
| 306 | tdata_item_t *titem;
|
|---|
| 307 | tdata_object_t *tobject;
|
|---|
| 308 | stree_targ_t *targ;
|
|---|
| 309 | tdata_vref_t *tvref;
|
|---|
| 310 | stree_deleg_t *deleg;
|
|---|
| 311 | tdata_deleg_t *tdeleg;
|
|---|
| 312 | stree_enum_t *enum_d;
|
|---|
| 313 | tdata_enum_t *tenum;
|
|---|
| 314 |
|
|---|
| 315 | #ifdef DEBUG_RUN_TRACE
|
|---|
| 316 | printf("Evaluating type name reference.\n");
|
|---|
| 317 | printf("'%s'\n", strtab_get_str(tnameref->name->sid));
|
|---|
| 318 | #endif
|
|---|
| 319 | /* In interactive mode we are not in a class */
|
|---|
| 320 | if (ctx != NULL) {
|
|---|
| 321 | /* Look for type argument */
|
|---|
| 322 | targ = stree_csi_find_targ(ctx, tnameref->name);
|
|---|
| 323 |
|
|---|
| 324 | if (targ != NULL) {
|
|---|
| 325 | /* Found type argument */
|
|---|
| 326 | #ifdef DEBUG_RUN_TRACE
|
|---|
| 327 | printf("Found type argument '%s'.\n",
|
|---|
| 328 | strtab_get_str(tnameref->name->sid));
|
|---|
| 329 | #endif
|
|---|
| 330 | titem = tdata_item_new(tic_tvref);
|
|---|
| 331 | tvref = tdata_vref_new();
|
|---|
| 332 | titem->u.tvref = tvref;
|
|---|
| 333 | tvref->targ = targ;
|
|---|
| 334 |
|
|---|
| 335 | *res = titem;
|
|---|
| 336 | return;
|
|---|
| 337 | }
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | /* Look for symbol */
|
|---|
| 341 | sym = symbol_lookup_in_csi(prog, ctx, tnameref->name);
|
|---|
| 342 | if (sym == NULL) {
|
|---|
| 343 | cspan_print(tnameref->texpr->cspan);
|
|---|
| 344 | printf(" Error: Symbol '%s' not found.\n",
|
|---|
| 345 | strtab_get_str(tnameref->name->sid));
|
|---|
| 346 | *res = tdata_item_new(tic_ignore);
|
|---|
| 347 | return;
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | /* Make compiler happy. */
|
|---|
| 351 | titem = NULL;
|
|---|
| 352 |
|
|---|
| 353 | switch (sym->sc) {
|
|---|
| 354 | case sc_csi:
|
|---|
| 355 | /* Construct type item. */
|
|---|
| 356 | titem = tdata_item_new(tic_tobject);
|
|---|
| 357 | tobject = tdata_object_new();
|
|---|
| 358 | titem->u.tobject = tobject;
|
|---|
| 359 |
|
|---|
| 360 | tobject->static_ref = sn_nonstatic;
|
|---|
| 361 | tobject->csi = sym->u.csi;
|
|---|
| 362 | list_init(&tobject->targs);
|
|---|
| 363 | break;
|
|---|
| 364 | case sc_ctor:
|
|---|
| 365 | /* It is not possible to reference a constructor explicitly. */
|
|---|
| 366 | assert(b_false);
|
|---|
| 367 | case sc_deleg:
|
|---|
| 368 | /* Fetch stored delegate type. */
|
|---|
| 369 | deleg = symbol_to_deleg(sym);
|
|---|
| 370 | assert(deleg != NULL);
|
|---|
| 371 | if (deleg->titem == NULL) {
|
|---|
| 372 | /*
|
|---|
| 373 | * Prepare a partial delegate which will be completed
|
|---|
| 374 | * later.
|
|---|
| 375 | */
|
|---|
| 376 | titem = tdata_item_new(tic_tdeleg);
|
|---|
| 377 | tdeleg = tdata_deleg_new();
|
|---|
| 378 | titem->u.tdeleg = tdeleg;
|
|---|
| 379 | tdeleg->deleg = deleg;
|
|---|
| 380 | tdeleg->tsig = NULL;
|
|---|
| 381 |
|
|---|
| 382 | deleg->titem = titem;
|
|---|
| 383 | } else {
|
|---|
| 384 | titem = deleg->titem;
|
|---|
| 385 | }
|
|---|
| 386 | break;
|
|---|
| 387 | case sc_enum:
|
|---|
| 388 | /* Fetch stored enum type. */
|
|---|
| 389 | enum_d = symbol_to_enum(sym);
|
|---|
| 390 | assert(enum_d != NULL);
|
|---|
| 391 | if (enum_d->titem == NULL) {
|
|---|
| 392 | /*
|
|---|
| 393 | * Prepare a partial enum whic will be completed
|
|---|
| 394 | * later.
|
|---|
| 395 | */
|
|---|
| 396 | titem = tdata_item_new(tic_tenum);
|
|---|
| 397 | tenum = tdata_enum_new();
|
|---|
| 398 | titem->u.tenum = tenum;
|
|---|
| 399 | tenum->enum_d = enum_d;
|
|---|
| 400 | } else {
|
|---|
| 401 | titem = enum_d->titem;
|
|---|
| 402 | }
|
|---|
| 403 | break;
|
|---|
| 404 | case sc_fun:
|
|---|
| 405 | case sc_var:
|
|---|
| 406 | case sc_prop:
|
|---|
| 407 | cspan_print(tnameref->texpr->cspan);
|
|---|
| 408 | printf(" Error: Symbol '");
|
|---|
| 409 | symbol_print_fqn(sym);
|
|---|
| 410 | printf("' is not a type.\n");
|
|---|
| 411 | titem = tdata_item_new(tic_ignore);
|
|---|
| 412 | break;
|
|---|
| 413 | }
|
|---|
| 414 |
|
|---|
| 415 | *res = titem;
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | /** Evaluate type application expression.
|
|---|
| 419 | *
|
|---|
| 420 | * In a type application expression type arguments are applied to a generic
|
|---|
| 421 | * CSI.
|
|---|
| 422 | *
|
|---|
| 423 | * @param prog Program
|
|---|
| 424 | * @param ctx Current CSI (context)
|
|---|
| 425 | * @param tapply Type application expression
|
|---|
| 426 | * @param res Place to store type result
|
|---|
| 427 | */
|
|---|
| 428 | static void run_tapply(stree_program_t *prog, stree_csi_t *ctx,
|
|---|
| 429 | stree_tapply_t *tapply, tdata_item_t **res)
|
|---|
| 430 | {
|
|---|
| 431 | tdata_item_t *base_ti;
|
|---|
| 432 | tdata_item_t *arg_ti;
|
|---|
| 433 | tdata_item_t *titem;
|
|---|
| 434 | tdata_object_t *tobject;
|
|---|
| 435 |
|
|---|
| 436 | list_node_t *arg_n;
|
|---|
| 437 | stree_texpr_t *arg;
|
|---|
| 438 |
|
|---|
| 439 | list_node_t *farg_n;
|
|---|
| 440 |
|
|---|
| 441 | #ifdef DEBUG_RUN_TRACE
|
|---|
| 442 | printf("Evaluating type apply operation.\n");
|
|---|
| 443 | #endif
|
|---|
| 444 | /* Construct type item. */
|
|---|
| 445 | titem = tdata_item_new(tic_tobject);
|
|---|
| 446 | tobject = tdata_object_new();
|
|---|
| 447 | titem->u.tobject = tobject;
|
|---|
| 448 |
|
|---|
| 449 | /* Evaluate base (generic) type. */
|
|---|
| 450 | run_texpr(prog, ctx, tapply->gtype, &base_ti);
|
|---|
| 451 |
|
|---|
| 452 | if (base_ti->tic != tic_tobject) {
|
|---|
| 453 | cspan_print(tapply->gtype->cspan);
|
|---|
| 454 | printf(" Error: Base type of generic application is not "
|
|---|
| 455 | "a CSI.\n");
|
|---|
| 456 | *res = tdata_item_new(tic_ignore);
|
|---|
| 457 | return;
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 | tobject->static_ref = sn_nonstatic;
|
|---|
| 461 | tobject->csi = base_ti->u.tobject->csi;
|
|---|
| 462 | list_init(&tobject->targs);
|
|---|
| 463 |
|
|---|
| 464 | /* Evaluate type arguments. */
|
|---|
| 465 | farg_n = list_first(&tobject->csi->targ);
|
|---|
| 466 | arg_n = list_first(&tapply->targs);
|
|---|
| 467 | while (farg_n != NULL && arg_n != NULL) {
|
|---|
| 468 | arg = list_node_data(arg_n, stree_texpr_t *);
|
|---|
| 469 |
|
|---|
| 470 | run_texpr(prog, ctx, arg, &arg_ti);
|
|---|
| 471 |
|
|---|
| 472 | if (arg_ti->tic == tic_ignore) {
|
|---|
| 473 | *res = tdata_item_new(tic_ignore);
|
|---|
| 474 | return;
|
|---|
| 475 | }
|
|---|
| 476 |
|
|---|
| 477 | list_append(&tobject->targs, arg_ti);
|
|---|
| 478 |
|
|---|
| 479 | farg_n = list_next(&tobject->csi->targ, farg_n);
|
|---|
| 480 | arg_n = list_next(&tapply->targs, arg_n);
|
|---|
| 481 | }
|
|---|
| 482 |
|
|---|
| 483 | if (farg_n != NULL || arg_n != NULL) {
|
|---|
| 484 | cspan_print(tapply->texpr->cspan);
|
|---|
| 485 | printf(" Error: Incorrect number of type arguments.\n");
|
|---|
| 486 | *res = tdata_item_new(tic_ignore);
|
|---|
| 487 | return;
|
|---|
| 488 | }
|
|---|
| 489 |
|
|---|
| 490 | *res = titem;
|
|---|
| 491 | }
|
|---|