Skip to content

Commit

Permalink
adding fcall string_param for genreating "masked" fcall
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisosaurus committed Jun 5, 2017
1 parent 0d1dbb5 commit 865d0ec
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
104 changes: 104 additions & 0 deletions src/parse/data/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ unsigned int ic_expr_func_call_init(struct ic_expr_func_call *fcall, struct ic_e

/* fstr is set later by ic_analyse_fcall_str */
fcall->string = 0;
/* set by expr_func_call_string_param */
fcall->string_param = 0;
/* fdecl is used in the analyse phase */
fcall->fdecl = 0;
/* set our func_name */
Expand Down Expand Up @@ -136,6 +138,14 @@ unsigned int ic_expr_func_call_destroy(struct ic_expr_func_call *fcall, unsigned
fcall->string = 0;
}

if (fcall->string_param) {
if (!ic_string_destroy(fcall->string_param, 1)) {
puts("ic_expr_func_call_destroy: call to ic_string_destroy failed");
return 0;
}
fcall->string_param = 0;
}

fcall->fdecl = 0;

/* if asked */
Expand Down Expand Up @@ -316,6 +326,100 @@ unsigned int ic_expr_func_call_type_refs_length(struct ic_expr_func_call *fcall)
return ic_pvector_length(&(fcall->type_refs));
}

/* get internal string_param
*
* will generate is not already generated
*
* returns * on success
* returns 0 on failure
*/
struct ic_string *ic_expr_func_call_string_param(struct ic_expr_func_call *fcall) {
struct ic_string *str = 0;
struct ic_symbol *sym = 0;
unsigned int i = 0;
unsigned int len = 0;

if (!fcall) {
puts("ic_expr_func_call_string_param: fcall was null");
return 0;
}

if (fcall->string_param) {
return fcall->string_param;
}

str = ic_string_new_empty();
if (!str) {
puts("ic_expr_func_call_string_param: call to ic_string_new_empty failed");
return 0;
}

sym = ic_expr_func_call_get_symbol(fcall);
if (!sym) {
puts("ic_expr_func_call_string_param: call to ic_expr_func_call_get_symbol failed");
return 0;
}

if (!ic_string_append_symbol(str, sym)) {
puts("ic_expr_func_call_string_param: call to ic_string_append_symbol failed");
return 0;
}

len = ic_expr_func_call_type_refs_length(fcall);
if (len) {
if (!ic_string_append_char(str, "[", 1)) {
puts("ic_expr_func_call_string_param: call to ic_string_append_symbol failed");
return 0;
}

for (i = 0; i < len; ++i) {
if (i == 0) {
if (!ic_string_append_char(str, "_", 1)) {
puts("ic_expr_func_call_string_param: call to ic_string_append_symbol failed");
return 0;
}
} else {
if (!ic_string_append_char(str, ",_", 2)) {
puts("ic_expr_func_call_string_param: call to ic_string_append_symbol failed");
return 0;
}
}
}

if (!ic_string_append_char(str, "]", 1)) {
puts("ic_expr_func_call_string_param: call to ic_string_append_symbol failed");
return 0;
}
}

if (!ic_string_append_char(str, "(", 1)) {
puts("ic_expr_func_call_string_param: call to ic_string_append_symbol failed");
return 0;
}
len = ic_expr_func_call_length(fcall);
for (i = 0; i < len; ++i) {
if (i == 0) {
if (!ic_string_append_char(str, "_", 1)) {
puts("ic_expr_func_call_string_param: call to ic_string_append_symbol failed");
return 0;
}
} else {
if (!ic_string_append_char(str, ",_", 2)) {
puts("ic_expr_func_call_string_param: call to ic_string_append_symbol failed");
return 0;
}
}
}
if (!ic_string_append_char(str, ")", 1)) {
puts("ic_expr_func_call_string_param: call to ic_string_append_symbol failed");
return 0;
}

fcall->string_param = str;

return fcall->string_param;
}

/* get internal symbol for function name
*
* returns * on success
Expand Down
19 changes: 19 additions & 0 deletions src/parse/data/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,19 @@ struct ic_expr_func_call {
/* string representation of function call
* generated by ic_analyse_fcall_str
* e.g. Foo(Int Int)
*
* requires information about args so can only be generated during analysis
*/
struct ic_string *string;

/* string representation of function call with param and arg masking
* e.g. Foo[A,B](A,B,Int) becomes Foo[_,_](_,_,_)
*
* can be generated without arg analyis, generated by
* ic_expr_func_call_string_param
*/
struct ic_string *string_param;

/* the function we are calling
* this is set at the analyse phase
*
Expand Down Expand Up @@ -119,6 +129,15 @@ struct ic_type_ref *ic_expr_func_call_get_type_ref(struct ic_expr_func_call *fca
*/
unsigned int ic_expr_func_call_type_refs_length(struct ic_expr_func_call *fcall);

/* get internal string_param
*
* will generate is not already generated
*
* returns * on success
* returns 0 on failure
*/
struct ic_string *ic_expr_func_call_string_param(struct ic_expr_func_call *fcall);

/* get internal symbol for function name
*
* returns * on success
Expand Down

0 comments on commit 865d0ec

Please sign in to comment.