Detect required arg after optional. For now, Clownfish allows required arguments to appear after optional arguments in a parameter list. Python does not, so we need to detect that error case.
Eventually, we'll either fix Clownfish to take on Python's restriction, or else force the user to create manual glue for problematic methods. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/74878d3c Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/74878d3c Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/74878d3c Branch: refs/heads/py_exp13 Commit: 74878d3ce0be405b575552dfb25caa6a00e46ba9 Parents: 15602e6 Author: Marvin Humphrey <[email protected]> Authored: Tue Feb 2 11:09:57 2016 -0800 Committer: Marvin Humphrey <[email protected]> Committed: Wed Feb 24 15:24:52 2016 -0800 ---------------------------------------------------------------------- compiler/src/CFCPyMethod.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/74878d3c/compiler/src/CFCPyMethod.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPyMethod.c b/compiler/src/CFCPyMethod.c index c89d12c..fcbeee1 100644 --- a/compiler/src/CFCPyMethod.c +++ b/compiler/src/CFCPyMethod.c @@ -71,7 +71,7 @@ S_build_py_args(CFCParamList *param_list) { * them to Clownfish-flavored C values. */ static char* -S_gen_arg_parsing(CFCParamList *param_list) { +S_gen_arg_parsing(CFCParamList *param_list, int first_tick, char **error) { char *content = NULL; CFCVariable **vars = CFCParamList_get_variables(param_list); @@ -84,6 +84,21 @@ S_gen_arg_parsing(CFCParamList *param_list) { char *targets = CFCUtil_strdup(""); int optional_started = 0; + for (int i = first_tick; i < num_vars; i++) { + const char *val = vals[i]; + if (val == NULL) { + if (optional_started) { // problem! + *error = "Required after optional param"; + goto CLEAN_UP_AND_RETURN; + } + } + else { + if (!optional_started) { + optional_started = 1; + } + } + } + char parse_pattern[] = "%s" " char *keywords[] = {%sNULL};\n" @@ -95,6 +110,7 @@ S_gen_arg_parsing(CFCParamList *param_list) { content = CFCUtil_sprintf(parse_pattern, declarations, keywords, format_str, targets); +CLEAN_UP_AND_RETURN: FREEMEM(declarations); FREEMEM(keywords); FREEMEM(format_str); @@ -262,7 +278,14 @@ S_meth_top(CFCMethod *method) { return CFCUtil_sprintf(pattern); } else { - char *arg_parsing = S_gen_arg_parsing(param_list); + char *error = NULL; + char *arg_parsing = S_gen_arg_parsing(param_list, 1, &error); + if (error) { + CFCUtil_die("%s in %s", error, CFCMethod_get_name(method)); + } + if (!arg_parsing) { + return NULL; + } char pattern[] = "(PyObject *self, PyObject *args, PyObject *kwargs) {\n" "%s"
