Changeset 39e8406 in mainline for uspace/app/sbi/src/run_texpr.c
- Timestamp:
- 2010-03-20T21:57:13Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b535aeb
- Parents:
- 6ba20a6b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run_texpr.c
r6ba20a6b r39e8406 29 29 /** @file Evaluates type expressions. */ 30 30 31 #include <assert.h> 31 32 #include <stdlib.h> 32 33 #include "list.h" 33 34 #include "mytypes.h" 34 #include "rdata.h"35 #include "run.h"36 35 #include "symbol.h" 36 #include "tdata.h" 37 37 38 38 #include "run_texpr.h" 39 39 40 static void run_taccess(run_t *run, stree_taccess_t *taccess, 41 rdata_titem_t **res); 42 static void run_tindex(run_t *run, stree_tindex_t *tindex, 43 rdata_titem_t **res); 44 static void run_tliteral(run_t *run, stree_tliteral_t *tliteral, 45 rdata_titem_t **res); 46 static void run_tnameref(run_t *run, stree_tnameref_t *tnameref, 47 rdata_titem_t **res); 48 49 void run_texpr(run_t *run, stree_texpr_t *texpr, rdata_titem_t **res) 40 static void run_taccess(stree_program_t *prog, stree_csi_t *ctx, 41 stree_taccess_t *taccess, tdata_item_t **res); 42 static void run_tindex(stree_program_t *prog, stree_csi_t *ctx, 43 stree_tindex_t *tindex, tdata_item_t **res); 44 static void run_tliteral(stree_program_t *prog, stree_csi_t *ctx, 45 stree_tliteral_t *tliteral, tdata_item_t **res); 46 static void run_tnameref(stree_program_t *prog, stree_csi_t *ctx, 47 stree_tnameref_t *tnameref, tdata_item_t **res); 48 49 void run_texpr(stree_program_t *prog, stree_csi_t *ctx, stree_texpr_t *texpr, 50 tdata_item_t **res) 50 51 { 51 52 switch (texpr->tc) { 52 53 case tc_taccess: 53 run_taccess( run, texpr->u.taccess, res);54 run_taccess(prog, ctx, texpr->u.taccess, res); 54 55 break; 55 56 case tc_tindex: 56 run_tindex( run, texpr->u.tindex, res);57 run_tindex(prog, ctx, texpr->u.tindex, res); 57 58 break; 58 59 case tc_tliteral: 59 run_tliteral( run, texpr->u.tliteral, res);60 run_tliteral(prog, ctx, texpr->u.tliteral, res); 60 61 break; 61 62 case tc_tnameref: 62 run_tnameref( run, texpr->u.tnameref, res);63 run_tnameref(prog, ctx, texpr->u.tnameref, res); 63 64 break; 64 65 case tc_tapply: … … 69 70 } 70 71 71 static void run_taccess( run_t *run, stree_taccess_t *taccess,72 rdata_titem_t **res)72 static void run_taccess(stree_program_t *prog, stree_csi_t *ctx, 73 stree_taccess_t *taccess, tdata_item_t **res) 73 74 { 74 75 stree_symbol_t *sym; 75 rdata_titem_t *targ_i;76 rdata_titem_t *titem;77 rdata_tcsi_t *tcsi;76 tdata_item_t *targ_i; 77 tdata_item_t *titem; 78 tdata_object_t *tobject; 78 79 stree_csi_t *base_csi; 79 80 … … 82 83 #endif 83 84 /* Evaluate base type. */ 84 run_texpr( run, taccess->arg, &targ_i);85 86 if (targ_i->tic != tic_t csi) {87 printf("Error: Using '.' with type which is not CSI.\n");85 run_texpr(prog, ctx, taccess->arg, &targ_i); 86 87 if (targ_i->tic != tic_tobject) { 88 printf("Error: Using '.' with type which is not an object.\n"); 88 89 exit(1); 89 90 } 90 91 91 92 /* Get base CSI. */ 92 base_csi = targ_i->u.tcsi->csi; 93 94 sym = symbol_lookup_in_csi(run->program, base_csi, 95 taccess->member_name); 93 base_csi = targ_i->u.tobject->csi; 94 95 sym = symbol_lookup_in_csi(prog, base_csi, taccess->member_name); 96 96 if (sym->sc != sc_csi) { 97 97 printf("Error: Symbol '"); 98 symbol_print_fqn( run->program,sym);98 symbol_print_fqn(sym); 99 99 printf("' is not a CSI.\n"); 100 100 exit(1); … … 102 102 103 103 /* Construct type item. */ 104 titem = rdata_titem_new(tic_tcsi); 105 tcsi = rdata_tcsi_new(); 106 titem->u.tcsi = tcsi; 107 108 tcsi->csi = sym->u.csi; 109 110 *res = titem; 111 } 112 113 static void run_tindex(run_t *run, stree_tindex_t *tindex, rdata_titem_t **res) 114 { 115 rdata_titem_t *base_ti; 116 rdata_titem_t *titem; 117 rdata_tarray_t *tarray; 104 titem = tdata_item_new(tic_tobject); 105 tobject = tdata_object_new(); 106 titem->u.tobject = tobject; 107 108 tobject->static_ref = b_false; 109 tobject->csi = sym->u.csi; 110 111 *res = titem; 112 } 113 114 static void run_tindex(stree_program_t *prog, stree_csi_t *ctx, 115 stree_tindex_t *tindex, tdata_item_t **res) 116 { 117 tdata_item_t *base_ti; 118 tdata_item_t *titem; 119 tdata_array_t *tarray; 118 120 stree_expr_t *arg_expr; 119 121 list_node_t *arg_node; … … 123 125 #endif 124 126 /* Evaluate base type. */ 125 run_texpr( run, tindex->base_type, &base_ti);126 127 /* Construct type item. */ 128 titem = rdata_titem_new(tic_tarray);129 tarray = rdata_tarray_new();127 run_texpr(prog, ctx, tindex->base_type, &base_ti); 128 129 /* Construct type item. */ 130 titem = tdata_item_new(tic_tarray); 131 tarray = tdata_array_new(); 130 132 titem->u.tarray = tarray; 131 133 … … 146 148 } 147 149 148 static void run_tliteral(run_t *run, stree_tliteral_t *tliteral, 149 rdata_titem_t **res) 150 { 151 rdata_titem_t *titem; 152 rdata_tprimitive_t *tprimitive; 150 static void run_tliteral(stree_program_t *prog, stree_csi_t *ctx, 151 stree_tliteral_t *tliteral, tdata_item_t **res) 152 { 153 tdata_item_t *titem; 154 tdata_primitive_t *tprimitive; 155 tprimitive_class_t tpc; 153 156 154 157 #ifdef DEBUG_RUN_TRACE 155 158 printf("Evaluating type literal.\n"); 156 159 #endif 157 158 (void) run;160 (void) prog; 161 (void) ctx; 159 162 (void) tliteral; 160 163 161 /* Construct type item. */ 162 titem = rdata_titem_new(tic_tprimitive); 163 tprimitive = rdata_tprimitive_new(); 164 switch (tliteral->tlc) { 165 case tlc_int: tpc = tpc_int; break; 166 case tlc_string: tpc = tpc_string; break; 167 } 168 169 /* Construct type item. */ 170 titem = tdata_item_new(tic_tprimitive); 171 tprimitive = tdata_primitive_new(tpc); 164 172 titem->u.tprimitive = tprimitive; 165 173 … … 167 175 } 168 176 169 static void run_tnameref(run_t *run, stree_tnameref_t *tnameref, 170 rdata_titem_t **res) 171 { 172 stree_csi_t *current_csi; 177 static void run_tnameref(stree_program_t *prog, stree_csi_t *ctx, 178 stree_tnameref_t *tnameref, tdata_item_t **res) 179 { 173 180 stree_symbol_t *sym; 174 rdata_titem_t *titem;175 rdata_tcsi_t *tcsi;181 tdata_item_t *titem; 182 tdata_object_t *tobject; 176 183 177 184 #ifdef DEBUG_RUN_TRACE 178 185 printf("Evaluating type name reference.\n"); 179 186 #endif 180 current_csi = run_get_current_csi(run); 181 sym = symbol_lookup_in_csi(run->program, current_csi, tnameref->name); 187 sym = symbol_lookup_in_csi(prog, ctx, tnameref->name); 182 188 183 189 if (sym->sc != sc_csi) { 184 190 printf("Error: Symbol '"); 185 symbol_print_fqn( run->program,sym);191 symbol_print_fqn(sym); 186 192 printf("' is not a CSI.\n"); 187 193 exit(1); … … 189 195 190 196 /* Construct type item. */ 191 titem = rdata_titem_new(tic_tcsi); 192 tcsi = rdata_tcsi_new(); 193 titem->u.tcsi = tcsi; 194 195 tcsi->csi = sym->u.csi; 196 197 *res = titem; 198 } 197 titem = tdata_item_new(tic_tobject); 198 tobject = tdata_object_new(); 199 titem->u.tobject = tobject; 200 201 tobject->static_ref = b_false; 202 tobject->csi = sym->u.csi; 203 204 *res = titem; 205 }
Note:
See TracChangeset
for help on using the changeset viewer.