Skip to content

Commit

Permalink
adding decl_func sig_param
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisosaurus committed Jun 5, 2017
1 parent 865d0ec commit 2f9c6ff
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
111 changes: 111 additions & 0 deletions src/parse/data/decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ unsigned int ic_decl_func_init(struct ic_decl_func *fdecl, char *name, unsigned
/* initialise return type to 0 (void) */
fdecl->ret_type = 0;
fdecl->builtin = 0;
fdecl->sig_param = 0;

/* make sure to init tbody */
fdecl->tbody = 0;
Expand Down Expand Up @@ -248,6 +249,13 @@ unsigned int ic_decl_func_destroy(struct ic_decl_func *fdecl, unsigned int free_
}
}

if (fdecl->sig_param) {
if (!ic_string_destroy(fdecl->sig_param, 1)) {
puts("ic_decl_func_destroy: for tbody call to ic_string_destroy failed");
return 0;
}
}

/* only free if caller asked */
if (free_fdecl) {
free(fdecl);
Expand Down Expand Up @@ -979,6 +987,109 @@ char *ic_decl_func_sig_mangled(struct ic_decl_func *fdecl) {
return ic_string_contents(fstr);
}

/* return a masked representation of this function's call signature
*
* string representation of function decl with param and arg masking
* e.g. Foo[A,B](a::A, b::B, i::Sint) becomes Foo[_,_](_,_,_)
*
* can be generated without arg analyis, generated by
* ic_decl_func_sig_param
*
* returns char* on success
* returns 0 on failure
*/

char *ic_decl_func_sig_param(struct ic_decl_func *fdecl) {
struct ic_string *str = 0;
char *ch = 0;
unsigned int len = 0;
unsigned int i = 0;

if (!fdecl) {
puts("ic_decl_func_sig_param: fdecl was null");
return 0;
}

if (fdecl->sig_param) {
ch = ic_string_contents(fdecl->sig_param);
if (!ch) {
puts("ic_decl_func_sig_param: call to ic_string_contents failed");
return 0;
}
return ch;
}

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

if (!ic_string_append_symbol(str, &(fdecl->name))) {
puts("ic_decl_func_sig_param: call to ic_string_append_symbol failed");
return 0;
}

len = ic_decl_func_type_params_length(fdecl);
if (len) {
if (!ic_string_append_char(str, "[", 1)) {
puts("ic_decl_func_sig_param: call to ic_string_append_char failed");
return 0;
}

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

if (!ic_string_append_char(str, "[", 1)) {
puts("ic_decl_func_sig_param: call to ic_string_append_char failed");
return 0;
}
}

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

fdecl->sig_param = str;
ch = ic_string_contents(fdecl->sig_param);
if (!ch) {
puts("ic_decl_func_sig_param: call to ic_string_contents failed");
return 0;
}

return ch;
}

/* check if this function returns void
*
* returns boolean on success
Expand Down
22 changes: 22 additions & 0 deletions src/parse/data/decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ struct ic_decl_func {
*/
struct ic_string sig_mangled;

/* string representation of function decl with param and arg masking
* e.g. Foo[A,B](a::A, b::B, i::Sint) becomes Foo[_,_](_,_,_)
*
* can be generated without arg analyis, generated by
* ic_decl_func_sig_param
*/
struct ic_string *sig_param;

/* 1 for builtin, 0 for not */
unsigned int builtin;
};
Expand Down Expand Up @@ -224,6 +232,20 @@ char *ic_decl_func_sig_full(struct ic_decl_func *fdecl);
*/
char *ic_decl_func_sig_mangled(struct ic_decl_func *fdecl);

/* return a masked representation of this function's call signature
*
* string representation of function decl with param and arg masking
* e.g. Foo[A,B](a::A, b::B, i::Sint) becomes Foo[_,_](_,_,_)
*
* can be generated without arg analyis, generated by
* ic_decl_func_sig_param
*
* returns char* on success
* returns 0 on failure
*/

char *ic_decl_func_sig_param(struct ic_decl_func *fdecl);

/* check if this function returns void
*
* returns boolean on success
Expand Down

0 comments on commit 2f9c6ff

Please sign in to comment.