Commit 2bb129d6 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Ease the work of case-sensitive backends

parent 1f0bbb05
......@@ -1181,10 +1181,13 @@ def _prim_call(prim):
ret_decls.extend(param_decls)
math_include = True
else:
ret_string = function_name + '('
ret_string = f"{UNICODE_SEP}{prim.value[0]} ("
list_of_params = []
for param in params:
list_of_params.append(expression(param))
param_stmt, param_str, local_var = expression(param)
list_of_params.append(param_str)
ret_stmts.extend(param_stmt)
ret_decls.extend(local_var)
ret_string += ', '.join(list_of_params)
ret_string += ')'
return ret_stmts, ret_string, ret_decls
......
......@@ -369,11 +369,11 @@ def valid_output(scope):
(does not mean it IS valid - caller still has to check it)
'''
for out_sig in scope.output_signals:
yield out_sig['name'].lower()
yield out_sig['name']
for proc in scope.procedures:
yield proc.inputString.lower()
yield proc.inputString
for special_op in SPECIAL_OPERATORS:
yield special_op.lower()
yield special_op
def get_interfaces(ast, process_name):
......@@ -2140,10 +2140,9 @@ def call_expression(root, context, pos="right"):
if primary.children[0].type == lexer.VARIABLE:
variable = primary.children[0]
ident = variable.children[0].text.lower()
proc_list = [proc.inputString.lower()
for proc in context.procedures]
if ident in (list(SPECIAL_OPERATORS.keys()) + proc_list):
return primary_call(root, context)
for each in valid_output (context):
if ident == each.lower():
return primary_call(root, context)
# not a call to a special operator or procedure
# => it is either an index or a substring
......@@ -2173,7 +2172,13 @@ def primary_call(root, context):
node.inputString = get_input_string(root)
node.tmpVar = tmp()
name = root.children[0].children[0].children[0].text.lower()
nameLower = root.children[0].children[0].children[0].text.lower()
# Retrieve the right casing from the declaration
for name in valid_output (context):
if nameLower == name.lower():
break
else:
name = nameLower
params, params_errors, param_warnings = \
expression_list(root.children[1], context)
......@@ -2183,7 +2188,7 @@ def primary_call(root, context):
node.value = [name, {'procParams': params}]
try:
node.exprType = check_call(name, params, context)
node.exprType = check_call(nameLower, params, context)
except (TypeError, ValueError) as err:
errors.append(error(root, str(err)))
except OverflowError:
......@@ -4151,6 +4156,9 @@ def procedure_call(root: antlr3.tree.CommonTree,
for each in context.procedures:
if each.inputString.lower() == call_name:
out_ast.exprType = each.return_type
# Take the right casing from prcedure declaration - always useful
# for case-sensitive backends like C code generators
out_ast.output[0]['outputName'] = each.inputString
break
return out_ast, err, warn
......@@ -4162,10 +4170,13 @@ def outputbody(root, context):
body = {'outputName': '', 'params': []}
for child in root.getChildren():
if child.type == lexer.ID:
body['outputName'] = child.text
if child.text.lower() not in valid_output(context):
errors.append('"' + child.text +
'" is not defined in the current scope')
for each in valid_output(context):
if each.lower() == child.text.lower():
# Take the right casing from the declaration
body['outputName'] = each
break
else:
errors.append(f'"{child.text}" is not defined or not visible')
elif child.type == lexer.PARAMS:
body['params'], err, warn = expression_list(child, context)
errors.extend(err)
......
......@@ -30,7 +30,7 @@ test-ada:
test-c:
$(OPENGEODE) og.pr --toC
mono $(ASN1SCC) -c -typePrefix asn1Scc -equal dataview-uniq.asn
mono $(ASN1SCC) -c -typePrefix asn1Scc -equal dataview.asn
$(CC) -O$(O) -c *.c
......
......@@ -21,34 +21,34 @@ system titi;
dcl u SomeInt;
/* CIF ENDTEXT */
/* CIF procedure (347, 552), (117, 35) */
procedure procWithReturn;
/* CIF TEXT (142, 194), (267, 140) */
-- Text area for declarations and comments
fpar in t Temperature;
/* CIF procedure (342, 620), (171, 35) */
procedure procNoParamsButReturn;
/* CIF TEXT (103, 121), (267, 137) */
returns Temperature;
/* CIF ENDTEXT */
/* CIF START (854, 137), (70, 35) */
/* CIF START (639, 218), (70, 35) */
START;
/* CIF return (871, 192), (35, 35) */
/* CIF return (656, 273), (35, 35) */
return 5.0;
endprocedure;
/* CIF procedure (353, 505), (107, 35) */
/* CIF procedure (352, 505), (107, 35) */
procedure procNoReturn;
/* CIF START (117, 52), (70, 35) */
START;
/* CIF return (134, 107), (35, 35) */
return ;
endprocedure;
/* CIF procedure (343, 620), (171, 35) */
procedure procNoParamsButReturn;
/* CIF TEXT (103, 121), (267, 137) */
/* CIF procedure (346, 552), (117, 35) */
procedure procWithReturn;
/* CIF TEXT (142, 194), (267, 140) */
-- Text area for declarations and comments
fpar in t Temperature;
returns Temperature;
/* CIF ENDTEXT */
/* CIF START (639, 218), (70, 35) */
/* CIF START (854, 137), (70, 35) */
START;
/* CIF return (656, 273), (35, 35) */
/* CIF return (871, 192), (35, 35) */
return 5.0;
endprocedure;
/* CIF START (669, 229), (70, 35) */
......@@ -60,7 +60,7 @@ system titi;
/* CIF task (613, 394), (181, 40) */
task one := procwithreturn(1.1);
/* CIF task (579, 454), (250, 35) */
task one := call procNoParamsButReturn;
task one := call procnoparamsButReturn;
/* CIF decision (669, 509), (70, 50) */
decision u;
/* CIF ANSWER (579, 579), (70, 24) */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment