Commit 90746690 authored by Maxime Perrotin's avatar Maxime Perrotin

Complete advanced support of "in" operator

parent 6aac21a9
......@@ -135,6 +135,10 @@ The background pattern was downloaded from www.subtlepatterns.com
Changelog
=========
2.0.38 (04/2019)
- Support advanced "in" expressions (e.g. "someVar in {enum1, enum2}",
or "someVar in {{a 4, b false}, {a 1, b true}}"
2.0.37 (04/2019)
- Support substrings on the left part of an expression (a(1,2) := ...)
......
......@@ -2306,7 +2306,7 @@ def _expr_in(expr, **kwargs):
local_decl.extend([u'tmp{} : constant array (1 .. {}) of {} := ({});'
.format(expr.tmpVar, size, sort, left_str)])
ada_string = u'for some var of tmp{} => var = {}'.format(expr.tmpVar,
ada_string = u'(for some var of tmp{} => var = {})'.format(expr.tmpVar,
right_str)
else:
local_decl.extend([u'tmp{} : Boolean := False;'.format(expr.tmpVar)])
......
......@@ -183,7 +183,6 @@ class Primary(Expression):
self.charPositionInLine = primary.charPositionInLine
self.value = primary.value
self.exprType = primary.exprType
self.debugLine = primary.debugLine
else:
self.inputString = inputString
self.line = line
......
......@@ -1289,6 +1289,8 @@ def fix_expression_types(expr, context): # type: -> [warnings]
# (due to similarities, the following should be refactored FIXME)
if isinstance(expr.right, ogAST.PrimSequence):
#print "Left:", type_name(expr.left.exprType), "Right:", expr.right.inputString
#print traceback.print_stack()
# left side must have a known type
asn_type = find_basic_type(expr.left.exprType)
if asn_type.kind != 'SequenceType':
......@@ -1828,13 +1830,13 @@ def in_expression(root, context):
# in "foo in {enum1, enum2}" we must check that enum1 and enum2 are both
# of the same type as foo
if expr.left.is_raw and not expr.right.is_raw:
# we must check that all entries are compatible with ref_type
# we must check that all entries are compatible with the other side
# and if they were variables, but are in fact raw enumerants, they
# must be changed from ogAST.PrimVariable to ogAST.PrimEnumeratedValue
for idx, value in enumerate(expr.left.value):
check_expr = ogAST.ExprAssign()
check_expr.left = ogAST.PrimVariable(debugLine=lineno())
check_expr.left.exprType = ref_type
check_expr.left.exprType = expr.right.exprType
check_expr.right = value
try:
warnings.extend(fix_expression_types(check_expr, context))
......
......@@ -141,7 +141,7 @@ except ImportError:
__all__ = ['opengeode', 'SDL_Scene', 'SDL_View', 'parse']
__version__ = '2.0.37'
__version__ = '2.0.38'
if hasattr(sys, 'frozen'):
# Detect if we are running on Windows (py2exe-generated)
......
......@@ -29,11 +29,9 @@ system og;
dcl someEnum Enum_T := enum2;
dcl somSeq Toto := {elem_1 1, elem_2 false};
dcl someSeq Toto := {elem_1 1, elem_2 false};
dcl testincase ForTheSakeOfIt := {enum1, enum2};
/* CIF ENDTEXT */
/* CIF START (556, 221), (70, 35) */
START;
......@@ -73,7 +71,7 @@ system og;
call writeln('ERROR 3');
enddecision;
/* CIF decision (388, 815), (406, 50) */
decision 'someSeq in {{elem_1 1, elem_2 false}, {elem_1 0, elem_2 true}}'
decision someSeq in {{elem_1 1, elem_2 false}, {elem_1 0, elem_2 true}}
/* CIF comment (814, 822), (226, 35) */
comment 'cause bug in Ada backend: FIXME';
/* CIF ANSWER (475, 885), (70, 23) */
......
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