array/map: use get() instead of _get() etc

pull/2272/head
Alexander Medvednikov 2019-10-10 01:07:00 +03:00
parent 52168d0781
commit cdfb7428c8
4 changed files with 11 additions and 11 deletions

View File

@ -131,10 +131,10 @@ typedef map map_string;
#endif #endif
//============================== HELPER C MACROS =============================*/ //============================== HELPER C MACROS =============================*/
#define _PUSH(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array__push(arr, &tmp);} #define _PUSH(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array_push(arr, &tmp);}
#define _PUSH_MANY(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array__push_many(arr, tmp.data, tmp.len);} #define _PUSH_MANY(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array_push_many(arr, tmp.data, tmp.len);}
#define _IN(typ, val, arr) array_##typ##_contains(arr, val) #define _IN(typ, val, arr) array_##typ##_contains(arr, val)
#define _IN_MAP(val, m) map__exists(m, val) #define _IN_MAP(val, m) map_exists(m, val)
#define DEFAULT_EQUAL(a, b) (a == b) #define DEFAULT_EQUAL(a, b) (a == b)
#define DEFAULT_NOT_EQUAL(a, b) (a != b) #define DEFAULT_NOT_EQUAL(a, b) (a != b)
#define DEFAULT_LT(a, b) (a < b) #define DEFAULT_LT(a, b) (a < b)

View File

@ -180,9 +180,9 @@ fn (p mut Parser) index_get(typ string, fn_ph int, cfg IndexCfg) {
} }
else { else {
if cfg.is_ptr { if cfg.is_ptr {
p.gen('( *($typ*) array__get(* $index_expr) )') p.gen('( *($typ*) array_get(* $index_expr) )')
} else { } else {
p.gen('( *($typ*) array__get($index_expr) )') p.gen('( *($typ*) array_get($index_expr) )')
} }
} }
} }
@ -358,7 +358,7 @@ fn (p mut Parser) gen_array_set(typ string, is_ptr, is_map bool,fn_ph, assign_po
mut cao_tmp := p.cgen.cur_line mut cao_tmp := p.cgen.cur_line
mut func := '' mut func := ''
if is_map { if is_map {
func = 'map__set(&' func = 'map_set(&'
// CAO on map is a bit more complicated as it loads // CAO on map is a bit more complicated as it loads
// the value inside a pointer instead of returning it. // the value inside a pointer instead of returning it.
} }
@ -366,13 +366,13 @@ fn (p mut Parser) gen_array_set(typ string, is_ptr, is_map bool,fn_ph, assign_po
if is_ptr { if is_ptr {
func = 'array_set(' func = 'array_set('
if is_cao { if is_cao {
cao_tmp = '*($p.expected_type *) array__get(*$cao_tmp)' cao_tmp = '*($p.expected_type *) array_get(*$cao_tmp)'
} }
} }
else { else {
func = 'array_set(&/*q*/' func = 'array_set(&/*q*/'
if is_cao { if is_cao {
cao_tmp = '*($p.expected_type *) array__get($cao_tmp)' cao_tmp = '*($p.expected_type *) array_get($cao_tmp)'
} }
} }
} }

View File

@ -147,7 +147,7 @@ const cJSON *jsval = NULL;
cJSON_ArrayForEach(jsval, root) cJSON_ArrayForEach(jsval, root)
{ {
$s $s
array__push(res, &val); array_push(res, &val);
} }
' '
} }

View File

@ -126,7 +126,7 @@ fn (p mut Parser) select_query(fn_ph int) string {
if field.typ == 'int' { if field.typ == 'int' {
cast = 'v_string_int' cast = 'v_string_int'
} }
obj_gen.writeln('${qprefix}$tmp . $field.name = $cast( *(string*)array__get(${qprefix}row.vals, $i) );') obj_gen.writeln('${qprefix}$tmp . $field.name = $cast( *(string*)array_get(${qprefix}row.vals, $i) );')
} }
// One object // One object
if query_one { if query_one {
@ -165,7 +165,7 @@ array_pg__Row ${qprefix}rows = pg__res_to_rows(${qprefix}res);
// TODO preallocate // TODO preallocate
array ${qprefix}arr_$tmp = new_array(0, 0, sizeof($table_name)); array ${qprefix}arr_$tmp = new_array(0, 0, sizeof($table_name));
for (int i = 0; i < ${qprefix}rows.len; i++) { for (int i = 0; i < ${qprefix}rows.len; i++) {
pg__Row ${qprefix}row = *(pg__Row*)array__get(${qprefix}rows, i); pg__Row ${qprefix}row = *(pg__Row*)array_get(${qprefix}rows, i);
$table_name ${qprefix}$tmp; $table_name ${qprefix}$tmp;
${obj_gen.str()} ${obj_gen.str()}
_PUSH(&${qprefix}arr_$tmp, ${qprefix}$tmp, ${tmp}2, $table_name); _PUSH(&${qprefix}arr_$tmp, ${qprefix}$tmp, ${tmp}2, $table_name);