From 0239a64c71af094908d3337042a7507e018d3eb3 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 4 Dec 2014 14:30:46 +0100 Subject: mds-kbdc: m + add argument count suffix to macro calls during simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-kbdc/compile-layout.c | 10 ---------- src/mds-kbdc/simplify-tree.c | 14 ++++++++++++-- .../simplify-tree/invalid/alternated_value_statement | 18 ------------------ .../invalid/macro_call_with_empty_alternation | 2 +- .../simplify-tree/valid/alternated_value_statement | 18 ++++++++++++++++++ test-files/mds-kbdc/simplify-tree/valid/macro_call | 4 ++-- .../simplify-tree/valid/macro_call_alternation | 16 ++++++++-------- .../valid/macro_call_alternation_with_nothing | 8 ++++---- .../simplify-tree/valid/macro_call_with_nothing | 4 ++-- .../valid/macro_call_with_singleton_alternation | 2 +- .../valid/multiple_nothing_alternation_in_macro_call | 10 +++++----- .../valid/nested_alternations_in_macro_call | 8 ++++---- .../validate-tree/invalid/assumption-macro_call | 15 +++++++++++++++ .../mds-kbdc/validate-tree/invalid/function-macro_call | 2 +- .../validate-tree/invalid/information-macro_call | 15 +++++++++++++++ .../mds-kbdc/validate-tree/valid/macro-macro_call | 2 +- test-files/mds-kbdc/validate-tree/valid/macro_call | 2 +- 17 files changed, 90 insertions(+), 60 deletions(-) delete mode 100644 test-files/mds-kbdc/simplify-tree/invalid/alternated_value_statement create mode 100644 test-files/mds-kbdc/simplify-tree/valid/alternated_value_statement create mode 100644 test-files/mds-kbdc/validate-tree/invalid/assumption-macro_call create mode 100644 test-files/mds-kbdc/validate-tree/invalid/information-macro_call diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c index 9ef5cf8..9242a76 100644 --- a/src/mds-kbdc/compile-layout.c +++ b/src/mds-kbdc/compile-layout.c @@ -644,10 +644,7 @@ static int compile_map(mds_kbdc_tree_map_t* restrict tree) static int compile_macro_call(mds_kbdc_tree_macro_call_t* restrict tree) { int bad; - size_t arg_count = 0; mds_kbdc_tree_t* arg = NULL; - mds_kbdc_tree_t* arg_; - char* full_macro_name = NULL; int saved_errno; fail_if ((arg = mds_kbdc_tree_dup(tree->arguments), arg = NULL)); @@ -655,19 +652,12 @@ static int compile_macro_call(mds_kbdc_tree_macro_call_t* restrict tree) if (bad) return 0; - for (arg_ = arg; arg_; arg_ = arg_->next) - arg_count++; - - fail_if (xasprintf(full_macro_name, "%s/%zu", tree->name, arg_count)); - /* TODO */ break_level = 0; - free(full_macro_name); mds_kbdc_tree_free(arg); return 0; FAIL_BEGIN; - free(full_macro_name); mds_kbdc_tree_free(arg); FAIL_END; } diff --git a/src/mds-kbdc/simplify-tree.c b/src/mds-kbdc/simplify-tree.c index 170c9ef..cc8ede7 100644 --- a/src/mds-kbdc/simplify-tree.c +++ b/src/mds-kbdc/simplify-tree.c @@ -218,6 +218,7 @@ static int simplify_macro_call(mds_kbdc_tree_macro_call_t* restrict tree) mds_kbdc_tree_t* argument; mds_kbdc_tree_t* dup_arguments = NULL; mds_kbdc_tree_t** here; + char* full_macro_name; size_t argument_index = 0; int saved_errno; @@ -230,16 +231,22 @@ static int simplify_macro_call(mds_kbdc_tree_macro_call_t* restrict tree) /* Copy arguments. */ if (tree->arguments == NULL) - return 0; + goto no_args; fail_if ((dup_arguments = mds_kbdc_tree_dup(tree->arguments), dup_arguments == NULL)); /* Eliminate alterations. */ for (argument = dup_arguments; argument; argument = argument->next, argument_index++) if (argument->type == C(ALTERNATION)) fail_if (eliminate_alternation((mds_kbdc_tree_t*)tree, argument, argument_index)); - mds_kbdc_tree_free(dup_arguments), dup_arguments = NULL; + /* Add argument count suffix. */ + no_args: + for (argument_index = 0, argument = tree->arguments; argument; argument = argument->next) + argument_index++; + fail_if (xasprintf(full_macro_name, "%s/%zu", tree->name, argument_index)); + free(tree->name), tree->name = full_macro_name; + /* Example of what will happend: * * my_macro([1 2] [1 2] [1 2]) ## call 1 @@ -308,6 +315,9 @@ static int simplify_macro_call(mds_kbdc_tree_macro_call_t* restrict tree) * no difference after simplify_macro_call on call 8 * * Nothings (‘.’) are removed before processing the alternations. + * + * It should also be noticed that all macro names are update to + * with the argument count suffix. */ return 0; diff --git a/test-files/mds-kbdc/simplify-tree/invalid/alternated_value_statement b/test-files/mds-kbdc/simplify-tree/invalid/alternated_value_statement deleted file mode 100644 index fae3bc1..0000000 --- a/test-files/mds-kbdc/simplify-tree/invalid/alternated_value_statement +++ /dev/null @@ -1,18 +0,0 @@ -[1 2] - -# (map (@ 1 0-0) -# (.sequence -# (string (@ 1 1-2) ‘1’) -# ) -# (.result nil) -# ) -# (map (@ 1 0-0) -# (.sequence -# (string (@ 1 3-4) ‘2’) -# ) -# (.result nil) -# ) -# :1:0–1: warning: alternated value statement is undefined unless the alternatives are identical -# [1 2] -# ^ - diff --git a/test-files/mds-kbdc/simplify-tree/invalid/macro_call_with_empty_alternation b/test-files/mds-kbdc/simplify-tree/invalid/macro_call_with_empty_alternation index 5532b22..86940a4 100644 --- a/test-files/mds-kbdc/simplify-tree/invalid/macro_call_with_empty_alternation +++ b/test-files/mds-kbdc/simplify-tree/invalid/macro_call_with_empty_alternation @@ -1,6 +1,6 @@ my_macro([]) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/0’ # (.arguments nil) # ) # :1:9–10: error: empty alternation diff --git a/test-files/mds-kbdc/simplify-tree/valid/alternated_value_statement b/test-files/mds-kbdc/simplify-tree/valid/alternated_value_statement new file mode 100644 index 0000000..fae3bc1 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/valid/alternated_value_statement @@ -0,0 +1,18 @@ +[1 2] + +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 1-2) ‘1’) +# ) +# (.result nil) +# ) +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 3-4) ‘2’) +# ) +# (.result nil) +# ) +# :1:0–1: warning: alternated value statement is undefined unless the alternatives are identical +# [1 2] +# ^ + diff --git a/test-files/mds-kbdc/simplify-tree/valid/macro_call b/test-files/mds-kbdc/simplify-tree/valid/macro_call index 9341a8b..24502cb 100644 --- a/test-files/mds-kbdc/simplify-tree/valid/macro_call +++ b/test-files/mds-kbdc/simplify-tree/valid/macro_call @@ -1,10 +1,10 @@ my_macro() my_macro(1) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/0’ # (.arguments nil) # ) -# (macro_call (@ 2 0-8) ‘my_macro’ +# (macro_call (@ 2 0-8) ‘my_macro/1’ # (.arguments # (string (@ 2 9-10) ‘1’) # ) diff --git a/test-files/mds-kbdc/simplify-tree/valid/macro_call_alternation b/test-files/mds-kbdc/simplify-tree/valid/macro_call_alternation index 0122c06..a2c306d 100644 --- a/test-files/mds-kbdc/simplify-tree/valid/macro_call_alternation +++ b/test-files/mds-kbdc/simplify-tree/valid/macro_call_alternation @@ -1,55 +1,55 @@ my_macro([1 2] [3 4] [5 6]) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/3’ # (.arguments # (string (@ 1 10-11) ‘1’) # (string (@ 1 16-17) ‘3’) # (string (@ 1 22-23) ‘5’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/3’ # (.arguments # (string (@ 1 10-11) ‘1’) # (string (@ 1 16-17) ‘3’) # (string (@ 1 24-25) ‘6’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/3’ # (.arguments # (string (@ 1 10-11) ‘1’) # (string (@ 1 18-19) ‘4’) # (string (@ 1 22-23) ‘5’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/3’ # (.arguments # (string (@ 1 10-11) ‘1’) # (string (@ 1 18-19) ‘4’) # (string (@ 1 24-25) ‘6’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/3’ # (.arguments # (string (@ 1 12-13) ‘2’) # (string (@ 1 16-17) ‘3’) # (string (@ 1 22-23) ‘5’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/3’ # (.arguments # (string (@ 1 12-13) ‘2’) # (string (@ 1 16-17) ‘3’) # (string (@ 1 24-25) ‘6’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/3’ # (.arguments # (string (@ 1 12-13) ‘2’) # (string (@ 1 18-19) ‘4’) # (string (@ 1 22-23) ‘5’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/3’ # (.arguments # (string (@ 1 12-13) ‘2’) # (string (@ 1 18-19) ‘4’) diff --git a/test-files/mds-kbdc/simplify-tree/valid/macro_call_alternation_with_nothing b/test-files/mds-kbdc/simplify-tree/valid/macro_call_alternation_with_nothing index 0c7096e..14e2ea2 100644 --- a/test-files/mds-kbdc/simplify-tree/valid/macro_call_alternation_with_nothing +++ b/test-files/mds-kbdc/simplify-tree/valid/macro_call_alternation_with_nothing @@ -1,23 +1,23 @@ my_macro([1 2] [3 .]) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/2’ # (.arguments # (string (@ 1 10-11) ‘1’) # (string (@ 1 16-17) ‘3’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/1’ # (.arguments # (string (@ 1 10-11) ‘1’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/2’ # (.arguments # (string (@ 1 12-13) ‘2’) # (string (@ 1 16-17) ‘3’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/1’ # (.arguments # (string (@ 1 12-13) ‘2’) # ) diff --git a/test-files/mds-kbdc/simplify-tree/valid/macro_call_with_nothing b/test-files/mds-kbdc/simplify-tree/valid/macro_call_with_nothing index f067b27..f386cbe 100644 --- a/test-files/mds-kbdc/simplify-tree/valid/macro_call_with_nothing +++ b/test-files/mds-kbdc/simplify-tree/valid/macro_call_with_nothing @@ -1,10 +1,10 @@ my_macro(.) my_macro(. .) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/0’ # (.arguments nil) # ) -# (macro_call (@ 2 0-8) ‘my_macro’ +# (macro_call (@ 2 0-8) ‘my_macro/0’ # (.arguments nil) # ) # :1:9–10: warning: ‘.’ outside alternation has no effect diff --git a/test-files/mds-kbdc/simplify-tree/valid/macro_call_with_singleton_alternation b/test-files/mds-kbdc/simplify-tree/valid/macro_call_with_singleton_alternation index c005dea..a6388cc 100644 --- a/test-files/mds-kbdc/simplify-tree/valid/macro_call_with_singleton_alternation +++ b/test-files/mds-kbdc/simplify-tree/valid/macro_call_with_singleton_alternation @@ -1,6 +1,6 @@ my_macro([1]) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/1’ # (.arguments # (string (@ 1 10-11) ‘1’) # ) diff --git a/test-files/mds-kbdc/simplify-tree/valid/multiple_nothing_alternation_in_macro_call b/test-files/mds-kbdc/simplify-tree/valid/multiple_nothing_alternation_in_macro_call index ef35cea..43ad4a1 100644 --- a/test-files/mds-kbdc/simplify-tree/valid/multiple_nothing_alternation_in_macro_call +++ b/test-files/mds-kbdc/simplify-tree/valid/multiple_nothing_alternation_in_macro_call @@ -1,20 +1,20 @@ my_macro([1 . . . 2]) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/1’ # (.arguments # (string (@ 1 10-11) ‘1’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/0’ # (.arguments nil) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/0’ # (.arguments nil) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/0’ # (.arguments nil) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/1’ # (.arguments # (string (@ 1 18-19) ‘2’) # ) diff --git a/test-files/mds-kbdc/simplify-tree/valid/nested_alternations_in_macro_call b/test-files/mds-kbdc/simplify-tree/valid/nested_alternations_in_macro_call index d40a68d..9289a4f 100644 --- a/test-files/mds-kbdc/simplify-tree/valid/nested_alternations_in_macro_call +++ b/test-files/mds-kbdc/simplify-tree/valid/nested_alternations_in_macro_call @@ -1,21 +1,21 @@ my_macro([[1 2] [3 4]]) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/1’ # (.arguments # (string (@ 1 11-12) ‘1’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/1’ # (.arguments # (string (@ 1 13-14) ‘2’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/1’ # (.arguments # (string (@ 1 17-18) ‘3’) # ) # ) -# (macro_call (@ 1 0-8) ‘my_macro’ +# (macro_call (@ 1 0-8) ‘my_macro/1’ # (.arguments # (string (@ 1 19-20) ‘4’) # ) diff --git a/test-files/mds-kbdc/validate-tree/invalid/assumption-macro_call b/test-files/mds-kbdc/validate-tree/invalid/assumption-macro_call new file mode 100644 index 0000000..8bcad6e --- /dev/null +++ b/test-files/mds-kbdc/validate-tree/invalid/assumption-macro_call @@ -0,0 +1,15 @@ +assumption + m() +end assumption + +# (assumption (@ 1 0-10) +# (.inner +# (macro_call (@ 2 2-3) ‘m/0’ +# (.arguments nil) +# ) +# ) +# ) +# :2:2–3: error: macro call inside assumption clause +# m() +# ^ + diff --git a/test-files/mds-kbdc/validate-tree/invalid/function-macro_call b/test-files/mds-kbdc/validate-tree/invalid/function-macro_call index c1ade46..b635844 100644 --- a/test-files/mds-kbdc/validate-tree/invalid/function-macro_call +++ b/test-files/mds-kbdc/validate-tree/invalid/function-macro_call @@ -4,7 +4,7 @@ end function # (function (@ 1 0-8) ‘f/0’ # (.inner -# (macro_call (@ 2 2-3) ‘m’ +# (macro_call (@ 2 2-3) ‘m/0’ # (.arguments nil) # ) # ) diff --git a/test-files/mds-kbdc/validate-tree/invalid/information-macro_call b/test-files/mds-kbdc/validate-tree/invalid/information-macro_call new file mode 100644 index 0000000..9887c9c --- /dev/null +++ b/test-files/mds-kbdc/validate-tree/invalid/information-macro_call @@ -0,0 +1,15 @@ +information + m() +end information + +# (information (@ 1 0-11) +# (.inner +# (macro_call (@ 2 2-3) ‘m/0’ +# (.arguments nil) +# ) +# ) +# ) +# :2:2–3: error: macro call inside information clause +# m() +# ^ + diff --git a/test-files/mds-kbdc/validate-tree/valid/macro-macro_call b/test-files/mds-kbdc/validate-tree/valid/macro-macro_call index dbd37de..9d8a771 100644 --- a/test-files/mds-kbdc/validate-tree/valid/macro-macro_call +++ b/test-files/mds-kbdc/validate-tree/valid/macro-macro_call @@ -4,7 +4,7 @@ end macro # (macro (@ 1 0-5) ‘m/0’ # (.inner -# (macro_call (@ 2 2-3) ‘n’ +# (macro_call (@ 2 2-3) ‘n/0’ # (.arguments nil) # ) # ) diff --git a/test-files/mds-kbdc/validate-tree/valid/macro_call b/test-files/mds-kbdc/validate-tree/valid/macro_call index 788ca76..d09428a 100644 --- a/test-files/mds-kbdc/validate-tree/valid/macro_call +++ b/test-files/mds-kbdc/validate-tree/valid/macro_call @@ -1,6 +1,6 @@ m() -# (macro_call (@ 1 0-1) ‘m’ +# (macro_call (@ 1 0-1) ‘m/0’ # (.arguments nil) # ) -- cgit v1.2.3-70-g09d2