Changeset 051bc69a in mainline for uspace/app/sbi/src/stype_expr.c


Ignore:
Timestamp:
2010-05-08T08:10:44Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
640ffe6, c5cb943d
Parents:
25a76ab8
Message:

Update SBI to rev. 244.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/src/stype_expr.c

    r25a76ab8 r051bc69a  
    4646#include <stdlib.h>
    4747#include <assert.h>
     48#include "cspan.h"
    4849#include "debug.h"
    4950#include "list.h"
     
    8586static void stype_binop_tobject(stype_t *stype, stree_binop_t *binop,
    8687    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem);
     88static void stype_binop_tenum(stype_t *stype, stree_binop_t *binop,
     89    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem);
     90static void stype_binop_tvref(stype_t *stype, stree_binop_t *binop,
     91    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem);
    8792
    8893static void stype_unop(stype_t *stype, stree_unop_t *unop,
     
    9297static void stype_new(stype_t *stype, stree_new_t *new,
    9398    tdata_item_t **rtitem);
     99static void stype_new_object_args(stype_t *stype, stree_new_t *new_op,
     100    tdata_item_t *obj_ti);
    94101
    95102static void stype_access(stype_t *stype, stree_access_t *access,
     
    101108static void stype_access_tarray(stype_t *stype, stree_access_t *access,
    102109    tdata_item_t *arg_ti, tdata_item_t **rtitem);
     110static void stype_access_tebase(stype_t *stype, stree_access_t *access,
     111    tdata_item_t *arg_ti, tdata_item_t **rtitem);
    103112
    104113static void stype_call(stype_t *stype, stree_call_t *call,
    105114    tdata_item_t **rtitem);
     115static void stype_call_args(stype_t *stype, cspan_t *cspan, list_t *farg_tis,
     116    tdata_item_t *fvarg_ti, list_t *args);
    106117
    107118static void stype_index(stype_t *stype, stree_index_t *index,
     
    133144
    134145#ifdef DEBUG_TYPE_TRACE
    135         printf("Type expression.\n");
     146        cspan_print(expr->cspan);
     147        printf(" Type expression.\n");
    136148#endif
    137149        /* Silence warning. */
     
    156168
    157169#ifdef DEBUG_TYPE_TRACE
    158         printf("Expression type is '");
     170        cspan_print(expr->cspan);
     171        printf(" Expression type is '");
    159172        tdata_item_print(et);
    160173        printf("'.\n");
     
    178191        stree_csi_t *csi;
    179192        stree_deleg_t *deleg;
     193        stree_enum_t *enum_d;
     194        tdata_ebase_t *tebase;
    180195        stree_fun_t *fun;
    181196
    182197#ifdef DEBUG_TYPE_TRACE
    183         printf("Evaluate type of name reference '%s'.\n",
     198        cspan_print(nameref->expr->cspan);
     199        printf(" Evaluate type of name reference '%s'.\n",
    184200            strtab_get_str(nameref->name->sid));
    185201#endif
     
    226242                /* Not found. */
    227243                if (stype->current_csi != NULL) {
    228                         printf("Error: Symbol '%s' not found in '",
     244                        cspan_print(nameref->expr->cspan);
     245                        printf(" Error: Symbol '%s' not found in '",
    229246                            strtab_get_str(nameref->name->sid));
    230247                        symbol_print_fqn(csi_to_symbol(stype->current_csi));
    231248                        printf("'.\n");
    232249                } else {
    233                         printf("Error: Symbol '%s' not found.\n",
     250                        cspan_print(nameref->expr->cspan);
     251                        printf(" Error: Symbol '%s' not found.\n",
    234252                            strtab_get_str(nameref->name->sid));
    235253                }
     
    260278                tobject->csi = csi;
    261279                break;
     280        case sc_ctor:
     281                /* It is not possible to reference a constructor explicitly. */
     282                assert(b_false);
    262283        case sc_deleg:
    263                 printf("referenced name is deleg\n");
    264284                deleg = symbol_to_deleg(sym);
    265285                assert(deleg != NULL);
     
    267287                stype_deleg(stype, deleg);
    268288                titem = deleg->titem;
     289                break;
     290        case sc_enum:
     291                enum_d = symbol_to_enum(sym);
     292                assert(enum_d != NULL);
     293
     294                titem = tdata_item_new(tic_tebase);
     295                tebase = tdata_ebase_new();
     296                titem->u.tebase = tebase;
     297
     298                /* This is an enum base reference. */
     299                tebase->enum_d = enum_d;
    269300                break;
    270301        case sc_fun:
     
    294325
    295326#ifdef DEBUG_TYPE_TRACE
    296         printf("Evaluate type of literal.\n");
     327        cspan_print(literal->expr->cspan);
     328        printf(" Evaluate type of literal.\n");
    297329#endif
    298330        (void) stype;
     
    322354    tdata_item_t **rtitem)
    323355{
     356        stree_csi_t *cur_csi;
     357        tdata_item_t *titem;
     358        tdata_object_t *tobject;
     359
    324360#ifdef DEBUG_TYPE_TRACE
    325         printf("Evaluate type of self reference.\n");
     361        cspan_print(self_ref->expr->cspan);
     362        printf(" Evaluate type of self reference.\n");
    326363#endif
    327364        (void) stype;
    328365        (void) self_ref;
    329366
    330         *rtitem = NULL;
     367        cur_csi = stype->proc_vr->proc->outer_symbol->outer_csi;
     368
     369        /* No global symbols should have procedures. */
     370        assert(cur_csi != NULL);
     371
     372        /* Construct type item. */
     373        titem = tdata_item_new(tic_tobject);
     374        tobject = tdata_object_new();
     375        titem->u.tobject = tobject;
     376
     377        tobject->static_ref = b_false;
     378        tobject->csi = cur_csi;
     379        list_init(&tobject->targs);
     380
     381        *rtitem = titem;
    331382}
    332383
     
    344395
    345396#ifdef DEBUG_TYPE_TRACE
    346         printf("Evaluate type of binary operation.\n");
     397        cspan_print(binop->expr->cspan);
     398        printf(" Evaluate type of binary operation.\n");
    347399#endif
    348400        stype_expr(stype, binop->arg1);
     
    352404        titem2 = binop->arg2->titem;
    353405
    354         if (titem1 == NULL || titem2 == NULL) {
    355                 printf("Error: Binary operand has no value.\n");
     406        if (titem1 == NULL) {
     407                cspan_print(binop->arg1->cspan);
     408                printf(" Error: Binary operand has no value.\n");
     409                stype_note_error(stype);
     410                *rtitem = stype_recovery_titem(stype);
     411                return;
     412        }
     413
     414        if (titem2 == NULL) {
     415                cspan_print(binop->arg2->cspan);
     416                printf(" Error: Binary operand has no value.\n");
    356417                stype_note_error(stype);
    357418                *rtitem = stype_recovery_titem(stype);
     
    366427        equal = tdata_item_equal(titem1, titem2);
    367428        if (equal != b_true) {
    368                 printf("Error: Binary operation arguments "
     429                cspan_print(binop->expr->cspan);
     430                printf(" Error: Binary operation arguments "
    369431                    "have different types ('");
    370432                tdata_item_print(titem1);
     
    384446                stype_binop_tobject(stype, binop, titem1, titem2, rtitem);
    385447                break;
     448        case tic_tenum:
     449                stype_binop_tenum(stype, binop, titem1, titem2, rtitem);
     450                break;
     451        case tic_tvref:
     452                stype_binop_tvref(stype, binop, titem1, titem2, rtitem);
     453                break;
    386454        default:
    387                 printf("Error: Binary operation on value which is not of a "
     455                cspan_print(binop->expr->cspan);
     456                printf(" Error: Binary operation on value which is not of a "
    388457                    "supported type (found '");
    389458                tdata_item_print(titem1);
     
    458527        case bo_mult:
    459528                /* Arithmetic -> error */
    460                 printf("Error: Binary operation (%d) on booleans.\n",
     529                cspan_print(binop->expr->cspan);
     530                printf(" Error: Binary operation (%d) on booleans.\n",
    461531                    binop->bc);
    462532                stype_note_error(stype);
    463533                *rtitem = stype_recovery_titem(stype);
    464534                return;
     535        case bo_and:
     536        case bo_or:
     537                /* Boolean -> boolean type */
     538                rtpc = tpc_bool;
     539                break;
    465540        }
    466541
     
    498573        case bo_minus:
    499574        case bo_mult:
    500                 /* Arithmetic -> error */
    501                 printf("Error: Binary operation (%d) on characters.\n",
     575        case bo_and:
     576        case bo_or:
     577                /* Arithmetic, boolean -> error */
     578                cspan_print(binop->expr->cspan);
     579                printf(" Error: Binary operation (%d) on characters.\n",
    502580                    binop->bc);
    503581                stype_note_error(stype);
     
    542620                rtpc = tpc_int;
    543621                break;
     622        case bo_and:
     623        case bo_or:
     624                /* Boolean -> error */
     625                cspan_print(binop->expr->cspan);
     626                printf(" Error: Binary operation (%d) on integers.\n",
     627                    binop->bc);
     628                stype_note_error(stype);
     629                rtpc = tpc_char;
     630                break;
    544631        }
    545632
     
    561648        (void) binop;
    562649
    563         printf("Unimplemented; Binary operation on nil.\n");
     650        cspan_print(binop->expr->cspan);
     651        printf(" Unimplemented: Binary operation on nil.\n");
    564652        stype_note_error(stype);
    565653        *rtitem = stype_recovery_titem(stype);
     
    578666        tdata_item_t *res_ti;
    579667
    580         if (binop->bc != bo_plus) {
    581                 printf("Unimplemented: Binary operation(%d) "
    582                     "on strings.\n", binop->bc);
    583                 stype_note_error(stype);
    584                 *rtitem = stype_recovery_titem(stype);
    585                 return;
    586         }
    587 
    588         rtpc = tpc_string;
     668        switch (binop->bc) {
     669        case bo_equal:
     670        case bo_notequal:
     671                /* Comparison -> boolean type */
     672                rtpc = tpc_bool;
     673                break;
     674        case bo_plus:
     675                /* Concatenation -> string type */
     676                rtpc = tpc_string;
     677                break;
     678
     679        case bo_lt:
     680        case bo_gt:
     681        case bo_lt_equal:
     682        case bo_gt_equal:
     683
     684        case bo_minus:
     685        case bo_mult:
     686        case bo_and:
     687        case bo_or:
     688                /* Ordering, arithmetic, boolean -> error */
     689                cspan_print(binop->expr->cspan);
     690                printf(" Error: Binary operation (%d) on strings.\n",
     691                    binop->bc);
     692                stype_note_error(stype);
     693                rtpc = tpc_char;
     694                break;
     695        }
    589696
    590697        res_ti = tdata_item_new(tic_tprimitive);
     
    608715        (void) binop;
    609716
    610         printf("Error: Cannot apply operator to resource type.\n");
     717        cspan_print(binop->expr->cspan);
     718        printf(" Error: Cannot apply operator to resource type.\n");
    611719        stype_note_error(stype);
    612720        rtpc = tpc_resource;
     
    645753                break;
    646754        default:
    647                 printf("Error: Binary operation (%d) on objects.\n",
     755                cspan_print(binop->expr->cspan);
     756                printf(" Error: Binary operation (%d) on objects.\n",
    648757                    binop->bc);
    649758                stype_note_error(stype);
     
    655764}
    656765
     766/** Type a binary operation with arguments of an enum type.
     767 *
     768 * @param stype         Static typing object
     769 * @param binop         Binary operation
     770 * @param ta            Type of first argument
     771 * @param tb            Type of second argument
     772 * @param rtitem        Place to store result type
     773 */
     774static void stype_binop_tenum(stype_t *stype, stree_binop_t *binop,
     775    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem)
     776{
     777        tdata_item_t *res_ti;
     778
     779        assert(ta->tic == tic_tenum);
     780        assert(tb->tic == tic_tenum);
     781
     782        switch (binop->bc) {
     783        case bo_equal:
     784        case bo_notequal:
     785                /* Comparison -> boolean type */
     786                res_ti = stype_boolean_titem(stype);
     787                break;
     788        default:
     789                cspan_print(binop->expr->cspan);
     790                printf(" Error: Binary operation (%d) on values of enum "
     791                    "type.\n", binop->bc);
     792                stype_note_error(stype);
     793                *rtitem = stype_recovery_titem(stype);
     794                return;
     795        }
     796
     797        *rtitem = res_ti;
     798}
     799
     800/** Type a binary operation with arguments of a variable type.
     801 *
     802 * @param stype         Static typing object
     803 * @param binop         Binary operation
     804 * @param ta            Type of first argument
     805 * @param tb            Type of second argument
     806 * @param rtitem        Place to store result type
     807 */
     808static void stype_binop_tvref(stype_t *stype, stree_binop_t *binop,
     809    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem)
     810{
     811        tdata_item_t *res_ti;
     812
     813        assert(ta->tic == tic_tvref || (ta->tic == tic_tprimitive &&
     814            ta->u.tprimitive->tpc == tpc_nil));
     815        assert(tb->tic == tic_tvref || (tb->tic == tic_tprimitive &&
     816            tb->u.tprimitive->tpc == tpc_nil));
     817
     818        switch (binop->bc) {
     819        case bo_equal:
     820        case bo_notequal:
     821                /* Comparison -> boolean type */
     822                res_ti = stype_boolean_titem(stype);
     823                break;
     824        default:
     825                cspan_print(binop->expr->cspan);
     826                printf(" Error: Binary operation (%d) on variable types.\n",
     827                    binop->bc);
     828                stype_note_error(stype);
     829                *rtitem = stype_recovery_titem(stype);
     830                return;
     831        }
     832
     833        *rtitem = res_ti;
     834}
    657835
    658836/** Type a unary operation.
     
    668846
    669847#ifdef DEBUG_TYPE_TRACE
    670         printf("Evaluate type of unary operation.\n");
     848        cspan_print(unop->expr->cspan);
     849        printf(" Evaluate type of unary operation.\n");
    671850#endif
    672851        stype_expr(stype, unop->arg);
     
    684863                break;
    685864        default:
    686                 printf("Error: Unary operation on value which is not of a "
     865                cspan_print(unop->arg->cspan);
     866                printf(" Error: Unary operation on value which is not of a "
    687867                    "supported type (found '");
    688868                tdata_item_print(titem);
     
    720900                break;
    721901        default:
    722                 printf("Error: Unary operator applied on unsupported "
     902                cspan_print(unop->arg->cspan);
     903                printf(" Error: Unary operator applied on unsupported "
    723904                    "primitive type %d.\n", ta->u.tprimitive->tpc);
    724905                stype_note_error(stype);
     
    743924{
    744925#ifdef DEBUG_TYPE_TRACE
     926        cspan_print(new_op->expr->cspan);
    745927        printf("Evaluate type of 'new' operation.\n");
    746928#endif
     
    754936                /* An error occured when evaluating the type expression. */
    755937                stype_note_error(stype);
    756         }
     938                *rtitem = stype_recovery_titem(stype);
     939                return;
     940        }
     941
     942        if ((*rtitem)->tic == tic_tobject)
     943                stype_new_object_args(stype, new_op, *rtitem);
     944}
     945
     946/** Type a new object operation arguments.
     947 *
     948 * @param stype         Static typing object
     949 * @param new_op        @c new operation
     950 */
     951static void stype_new_object_args(stype_t *stype, stree_new_t *new_op,
     952    tdata_item_t *obj_ti)
     953{
     954        stree_csi_t *csi;
     955        stree_ctor_t *ctor;
     956        stree_symbol_t *ctor_sym;
     957        stree_ident_t *ctor_ident;
     958        tdata_fun_sig_t *tsig;
     959
     960        assert(obj_ti->tic == tic_tobject);
     961        csi = obj_ti->u.tobject->csi;
     962        ctor_ident = stree_ident_new();
     963        ctor_ident->sid = strtab_get_sid(CTOR_IDENT);
     964
     965        /* Find constructor. */
     966        ctor_sym = symbol_search_csi_no_base(stype->program, csi,
     967            ctor_ident);
     968
     969        if (ctor_sym == NULL && !list_is_empty(&new_op->ctor_args)) {
     970                cspan_print(new_op->expr->cspan);
     971                printf(" Error: Passing arguments to 'new' but no "
     972                    "constructor found.\n");
     973                stype_note_error(stype);
     974                return;
     975        }
     976
     977        if (ctor_sym == NULL)
     978                return;
     979
     980        ctor = symbol_to_ctor(ctor_sym);
     981        assert(ctor != NULL);
     982
     983        /* Type constructor header if it has not been typed yet. */
     984        stype_ctor_header(stype, ctor);
     985        if (ctor->titem->tic == tic_ignore)
     986                return;
     987
     988        assert(ctor->titem->tic == tic_tfun);
     989        tsig = ctor->titem->u.tfun->tsig;
     990
     991        stype_call_args(stype, new_op->expr->cspan, &tsig->arg_ti,
     992            tsig->varg_ti, &new_op->ctor_args);
    757993}
    758994
     
    7691005
    7701006#ifdef DEBUG_TYPE_TRACE
    771         printf("Evaluate type of access operation.\n");
     1007        cspan_print(access->expr->cspan);
     1008        printf(" Evaluate type of access operation.\n");
    7721009#endif
    7731010        stype_expr(stype, access->arg);
     
    7751012
    7761013        if (arg_ti == NULL) {
    777                 printf("Error: Argument of access has no value.\n");
     1014                cspan_print(access->arg->cspan);
     1015                printf(" Error: Argument of access operation has no value.\n");
    7781016                stype_note_error(stype);
    7791017                *rtitem = stype_recovery_titem(stype);
     
    7921030                break;
    7931031        case tic_tdeleg:
    794                 printf("Error: Using '.' operator on a function.\n");
     1032                cspan_print(access->arg->cspan);
     1033                printf(" Error: Using '.' operator on a delegate.\n");
     1034                stype_note_error(stype);
     1035                *rtitem = stype_recovery_titem(stype);
     1036                break;
     1037        case tic_tebase:
     1038                stype_access_tebase(stype, access, arg_ti, rtitem);
     1039                break;
     1040        case tic_tenum:
     1041                cspan_print(access->arg->cspan);
     1042                printf(" Error: Using '.' operator on expression of enum "
     1043                    "type.\n");
    7951044                stype_note_error(stype);
    7961045                *rtitem = stype_recovery_titem(stype);
    7971046                break;
    7981047        case tic_tfun:
    799                 printf("Error: Using '.' operator on a delegate.\n");
     1048                cspan_print(access->arg->cspan);
     1049                printf(" Error: Using '.' operator on a function.\n");
    8001050                stype_note_error(stype);
    8011051                *rtitem = stype_recovery_titem(stype);
     
    8031053        case tic_tvref:
    8041054                /* Cannot allow this without some constraint. */
    805                 printf("Error: Using '.' operator on generic data.\n");
     1055                cspan_print(access->arg->cspan);
     1056                printf(" Error: Using '.' operator on generic data.\n");
    8061057                *rtitem = stype_recovery_titem(stype);
    8071058                break;
     
    8221073    tdata_item_t *arg_ti, tdata_item_t **rtitem)
    8231074{
    824         (void) stype;
    825         (void) access;
    826         (void) rtitem;
    827 
    828         printf("Error: Unimplemented: Accessing primitive type '");
    829         tdata_item_print(arg_ti);
    830         printf("'.\n");
    831         stype_note_error(stype);
    832         *rtitem = stype_recovery_titem(stype);
     1075        (void) arg_ti;
     1076
     1077        /* Box the value. */
     1078        access->arg = stype_box_expr(stype, access->arg);
     1079        if (access->arg->titem->tic == tic_ignore) {
     1080                *rtitem = stype_recovery_titem(stype);
     1081                return;
     1082        }
     1083
     1084        /* Access the boxed object. */
     1085        stype_access_tobject(stype, access, access->arg->titem, rtitem);
    8331086}
    8341087
     
    8451098        stree_symbol_t *member_sym;
    8461099        stree_var_t *var;
     1100        stree_enum_t *enum_d;
    8471101        stree_fun_t *fun;
    8481102        stree_prop_t *prop;
     
    8631117        if (member_sym == NULL) {
    8641118                /* No such member found. */
    865                 printf("Error: CSI '");
     1119                cspan_print(access->member_name->cspan);
     1120                printf(" Error: CSI '");
    8661121                symbol_print_fqn(csi_to_symbol(tobject->csi));
    8671122                printf("' has no member named '%s'.\n",
     
    8791134        switch (member_sym->sc) {
    8801135        case sc_csi:
    881                 printf("Error: Accessing object member which is nested "
     1136                cspan_print(access->member_name->cspan);
     1137                printf(" Error: Accessing object member which is nested "
    8821138                    "CSI.\n");
    8831139                stype_note_error(stype);
    8841140                *rtitem = stype_recovery_titem(stype);
    8851141                return;
     1142        case sc_ctor:
     1143                /* It is not possible to reference a constructor explicitly. */
     1144                assert(b_false);
    8861145        case sc_deleg:
    887                 printf("Error: Accessing object member which is a "
     1146                cspan_print(access->member_name->cspan);
     1147                printf(" Error: Accessing object member which is a "
    8881148                    "delegate.\n");
    8891149                stype_note_error(stype);
    8901150                *rtitem = stype_recovery_titem(stype);
    8911151                return;
     1152        case sc_enum:
     1153                enum_d = symbol_to_enum(member_sym);
     1154                assert(enum_d != NULL);
     1155                /* Type enum if it has not been typed yet. */
     1156                stype_enum(stype, enum_d);
     1157                mtitem = enum_d->titem;
     1158                break;
    8921159        case sc_fun:
    8931160                fun = symbol_to_fun(member_sym);
     
    9371204        (void) rtitem;
    9381205
    939         printf("Error: Unimplemented: Accessing array type '");
     1206        cspan_print(access->arg->cspan);
     1207        printf(" Error: Unimplemented: Accessing array type '");
    9401208        tdata_item_print(arg_ti);
    9411209        printf("'.\n");
     
    9441212}
    9451213
     1214/** Type an enum access operation.
     1215 *
     1216 * @param stype         Static typing object
     1217 * @param access        Member access operation
     1218 * @param arg_ti        Base type
     1219 * @param rtitem        Place to store result type
     1220*/
     1221static void stype_access_tebase(stype_t *stype, stree_access_t *access,
     1222    tdata_item_t *arg_ti, tdata_item_t **rtitem)
     1223{
     1224        tdata_ebase_t *tebase;
     1225        tdata_enum_t *tenum;
     1226        tdata_item_t *mtitem;
     1227        stree_embr_t *embr;
     1228
     1229#ifdef DEBUG_TYPE_TRACE
     1230        printf("Type an ebase access operation.\n");
     1231#endif
     1232        assert(arg_ti->tic == tic_tebase);
     1233        tebase = arg_ti->u.tebase;
     1234
     1235        /* Look for a member with the specified name. */
     1236        embr = stree_enum_find_mbr(tebase->enum_d, access->member_name);
     1237
     1238        if (embr == NULL) {
     1239                /* No such member found. */
     1240                cspan_print(access->member_name->cspan);
     1241                printf(" Error: Enum type '");
     1242                symbol_print_fqn(enum_to_symbol(tebase->enum_d));
     1243                printf("' has no member named '%s'.\n",
     1244                    strtab_get_str(access->member_name->sid));
     1245                stype_note_error(stype);
     1246                *rtitem = stype_recovery_titem(stype);
     1247                return;
     1248        }
     1249
     1250#ifdef DEBUG_RUN_TRACE
     1251        printf("Found member '%s'.\n",
     1252            strtab_get_str(access->member_name->sid));
     1253#endif
     1254
     1255        mtitem = tdata_item_new(tic_tenum);
     1256        tenum = tdata_enum_new();
     1257        mtitem->u.tenum = tenum;
     1258        tenum->enum_d = tebase->enum_d;
     1259
     1260        *rtitem = mtitem;
     1261}
     1262
     1263
    9461264/** Type a call operation.
    9471265 *
     
    9531271    tdata_item_t **rtitem)
    9541272{
    955         list_node_t *fargt_n;
    956         tdata_item_t *farg_ti;
    957         tdata_item_t *varg_ti;
    958 
    959         list_node_t *arg_n;
    960         stree_expr_t *arg;
    961         stree_expr_t *carg;
    962 
    9631273        tdata_item_t *fun_ti;
    9641274        tdata_fun_sig_t *tsig;
    9651275
    966         int cnt;
    967 
    9681276#ifdef DEBUG_TYPE_TRACE
    969         printf("Evaluate type of call operation.\n");
     1277        cspan_print(call->expr->cspan);
     1278        printf(" Evaluate type of call operation.\n");
    9701279#endif
    9711280        /* Type the function */
     
    9861295                return;
    9871296        default:
    988                 printf("Error: Calling something which is not a function ");
     1297                cspan_print(call->fun->cspan);
     1298                printf(" Error: Calling something which is not a function ");
    9891299                printf("(found '");
    9901300                tdata_item_print(fun_ti);
     
    9951305        }
    9961306
    997         /* Type and check the arguments. */
    998         fargt_n = list_first(&tsig->arg_ti);
    999         arg_n = list_first(&call->args);
     1307        /* Type call arguments. */
     1308        stype_call_args(stype, call->expr->cspan, &tsig->arg_ti, tsig->varg_ti,
     1309            &call->args);
     1310
     1311        if (tsig->rtype != NULL) {
     1312                /* XXX Might be better to clone here. */
     1313                *rtitem = tsig->rtype;
     1314        } else {
     1315                *rtitem = NULL;
     1316        }
     1317}
     1318
     1319/** Type call arguments.
     1320 *
     1321 * Type arguments in call to a function or constructor.
     1322 *
     1323 * @param stype         Static typing object
     1324 * @param cpsan         Cspan to print in case of error.
     1325 * @param farg_tis      Formal argument types (list of tdata_item_t)
     1326 * @param args          Real arguments (list of stree_expr_t)
     1327 */
     1328static void stype_call_args(stype_t *stype, cspan_t *cspan, list_t *farg_tis,
     1329    tdata_item_t *fvarg_ti, list_t *args)
     1330{
     1331        list_node_t *fargt_n;
     1332        tdata_item_t *farg_ti;
     1333        tdata_item_t *varg_ti;
     1334
     1335        list_node_t *arg_n;
     1336        stree_expr_t *arg;
     1337        stree_expr_t *carg;
     1338
     1339        int cnt;
     1340
     1341        /* Type and check regular arguments. */
     1342        fargt_n = list_first(farg_tis);
     1343        arg_n = list_first(args);
    10001344
    10011345        cnt = 0;
     
    10081352                if (farg_ti == NULL) {
    10091353                        /* Skip the check */
    1010                         fargt_n = list_next(&tsig->arg_ti, fargt_n);
    1011                         arg_n = list_next(&call->args, arg_n);
     1354                        fargt_n = list_next(farg_tis, fargt_n);
     1355                        arg_n = list_next(args, arg_n);
    10121356                        continue;
    10131357                }
     
    10191363                list_node_setdata(arg_n, carg);
    10201364
    1021                 fargt_n = list_next(&tsig->arg_ti, fargt_n);
    1022                 arg_n = list_next(&call->args, arg_n);
     1365                fargt_n = list_next(farg_tis, fargt_n);
     1366                arg_n = list_next(args, arg_n);
    10231367        }
    10241368
    10251369        /* Type and check variadic arguments. */
    1026         if (tsig->varg_ti != NULL) {
     1370        if (fvarg_ti != NULL) {
    10271371                /* Obtain type of packed argument. */
    1028                 farg_ti = tsig->varg_ti;
     1372                farg_ti = fvarg_ti;
    10291373
    10301374                /* Get array element type */
     
    10421386                        list_node_setdata(arg_n, carg);
    10431387
    1044                         arg_n = list_next(&call->args, arg_n);
     1388                        arg_n = list_next(args, arg_n);
    10451389                }
    10461390        }
    10471391
    10481392        if (fargt_n != NULL) {
    1049                 printf("Error: Too few arguments to function.\n");
     1393                cspan_print(cspan);
     1394                printf(" Error: Too few arguments.\n");
    10501395                stype_note_error(stype);
    10511396        }
    10521397
    10531398        if (arg_n != NULL) {
    1054                 printf("Error: Too many arguments to function.\n");
    1055                 stype_note_error(stype);
    1056         }
    1057 
    1058         if (tsig->rtype != NULL) {
    1059                 /* XXX Might be better to clone here. */
    1060                 *rtitem = tsig->rtype;
    1061         } else {
    1062                 *rtitem = NULL;
     1399                cspan_print(cspan);
     1400                printf(" Error: Too many arguments.\n");
     1401                stype_note_error(stype);
    10631402        }
    10641403}
     
    10781417
    10791418#ifdef DEBUG_TYPE_TRACE
    1080         printf("Evaluate type of index operation.\n");
     1419        cspan_print(index->expr->cspan);
     1420        printf(" Evaluate type of index operation.\n");
    10811421#endif
    10821422        stype_expr(stype, index->base);
     
    11031443                break;
    11041444        case tic_tdeleg:
    1105                 printf("Error: Indexing a delegate.\n");
     1445                cspan_print(index->base->cspan);
     1446                printf(" Error: Indexing a delegate.\n");
     1447                stype_note_error(stype);
     1448                *rtitem = stype_recovery_titem(stype);
     1449                break;
     1450        case tic_tebase:
     1451                cspan_print(index->base->cspan);
     1452                printf(" Error: Indexing an enum declaration.\n");
     1453                stype_note_error(stype);
     1454                *rtitem = stype_recovery_titem(stype);
     1455                break;
     1456        case tic_tenum:
     1457                cspan_print(index->base->cspan);
     1458                printf(" Error: Indexing an enum value.\n");
    11061459                stype_note_error(stype);
    11071460                *rtitem = stype_recovery_titem(stype);
    11081461                break;
    11091462        case tic_tfun:
    1110                 printf("Error: Indexing a function.\n");
     1463                cspan_print(index->base->cspan);
     1464                printf(" Error: Indexing a function.\n");
    11111465                stype_note_error(stype);
    11121466                *rtitem = stype_recovery_titem(stype);
     
    11141468        case tic_tvref:
    11151469                /* Cannot allow this without some constraint. */
    1116                 printf("Error: Indexing generic data.\n");
     1470                cspan_print(index->base->cspan);
     1471                printf(" Error: Indexing generic data.\n");
    11171472                *rtitem = stype_recovery_titem(stype);
    11181473                break;
     
    11491504        }
    11501505
    1151         printf("Error: Indexing primitive type '");
     1506        cspan_print(index->base->cspan);
     1507        printf(" Error: Indexing primitive type '");
    11521508        tdata_item_print(base_ti);
    11531509        printf("'.\n");
     
    11761532
    11771533#ifdef DEBUG_TYPE_TRACE
    1178         printf("Indexing object type '");
     1534        cspan_print(index->expr->cspan);
     1535        printf(" Indexing object type '");
    11791536        tdata_item_print(base_ti);
    11801537        printf("'.\n");
     
    11901547
    11911548        if (idx_sym == NULL) {
    1192                 printf("Error: Indexing object of type '");
     1549                cspan_print(index->base->cspan);
     1550                printf(" Error: Indexing object of type '");
    11931551                tdata_item_print(base_ti);
    11941552                printf("' which does not have an indexer.\n");
     
    12461604                    arg->titem->u.tprimitive->tpc != tpc_int) {
    12471605
    1248                         printf("Error: Array index is not an integer.\n");
     1606                        cspan_print(arg->cspan);
     1607                        printf(" Error: Array index is not an integer.\n");
    12491608                        stype_note_error(stype);
    12501609                }
     
    12541613
    12551614        if (arg_count != base_ti->u.tarray->rank) {
    1256                 printf("Error: Using %d indices with array of rank %d.\n",
     1615                cspan_print(index->expr->cspan);
     1616                printf(" Error: Using %d indices with array of rank %d.\n",
    12571617                    arg_count, base_ti->u.tarray->rank);
    12581618                stype_note_error(stype);
     
    12741634
    12751635#ifdef DEBUG_TYPE_TRACE
    1276         printf("Evaluate type of assignment.\n");
     1636        cspan_print(assign->expr->cspan);
     1637        printf(" Evaluate type of assignment.\n");
    12771638#endif
    12781639        stype_expr(stype, assign->dest);
     
    12971658
    12981659#ifdef DEBUG_TYPE_TRACE
    1299         printf("Evaluate type of @c as conversion.\n");
     1660        cspan_print(as_op->expr->cspan);
     1661        printf(" Evaluate type of @c as conversion.\n");
    13001662#endif
    13011663        stype_expr(stype, as_op->arg);
     
    13041666        /* Check that target type is derived from argument type. */
    13051667        if (tdata_is_ti_derived_from_ti(titem, as_op->arg->titem) != b_true) {
    1306                 printf("Error: Target of 'as' operator '");
     1668                cspan_print(as_op->dtype->cspan);
     1669                printf(" Error: Target of 'as' operator '");
    13071670                tdata_item_print(titem);
    13081671                printf("' is not derived from '");
     
    13321695
    13331696#ifdef DEBUG_TYPE_TRACE
    1334         printf("Evaluate type of boxing operation.\n");
     1697        cspan_print(box->expr->cspan);
     1698        printf(" Evaluate type of boxing operation.\n");
    13351699#endif
    13361700        bi = stype->program->builtin;
Note: See TracChangeset for help on using the changeset viewer.