Commit d8981796 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Fix resolution of asn1 constants

parent 2e493d06
......@@ -135,6 +135,10 @@ The background pattern was downloaded from www.subtlepatterns.com
Changelog
=========
2.0.12 (06/2018)
- Fix resolution of ASN.1 constants - values were not use propertly when
a constant was referencing another constant (numerical operations only)
2.0.11 (06/2018)
- Ada backend: fix choice determinant issue leading to CHOICE_NOT_FOUND bug
......
......@@ -1349,6 +1349,26 @@ def arithmetic_expression(root, context):
# accordingly with the kind of operation used between operands:
left = find_basic_type(expr.left.exprType)
right = find_basic_type(expr.right.exprType)
def get_constant_value(const_val):
# value may be a reference to another constant. In that case we
# must find the actual value by following the path until we find it
# however, stop after 20 trials to avoid looping forever in case
# there is some circular dependency or other weird asn1 construct
first_str = const_val
while retry < 20:
try:
return float(const_val)
except ValueError:
possible_constant = is_asn1constant(const_val)
if possible_constant is not None:
const_val = possible_constant.value
else:
# Exceptional case - should be caught by asn1scc
raise ValueError(str(first_str) + " could not be resolved")
retry += 1
raise ValueError(str(first_str) + " actual value not found" )
try:
minL = float(left.Min)
maxL = float(left.Max)
......@@ -1358,7 +1378,27 @@ def arithmetic_expression(root, context):
if isinstance(expr.left, ogAST.PrimConstant):
minL = maxL = float (expr.left.constant_value)
if isinstance(expr.right, ogAST.PrimConstant):
minR = maxR = float (expr.right.constant_value)
# value may be a reference to another constant. In that case we
# must find the actual value by following the path until we find it
# however, stop after 10 trials to avoid looping forever in case
# there is some circular dependency or other weird asn1 construct
const_val = expr.right.constant_value
retry = 0
while True:
try:
minR = maxR = float (const_val)
except ValueError:
possible_constant = is_asn1constant(const_val)
if possible_constant is not None:
const_val = possible_constant.value
else:
raise
retry += 1
if retry > 10:
# Avoid infinite loop
raise
else:
break
# Type of the resulting expression depends on whether there are raw
# numbers on one side of the expression (PrInt). By default when they
# are parsed, they are set to 64 bits integers ; but if they are in an
......@@ -1396,6 +1436,7 @@ def arithmetic_expression(root, context):
except (ValueError, AttributeError):
msg = 'Check that all your numerical data types '\
'have a range constraint'
#print (traceback.format_exc())
errors.append(error(root, msg))
if root.type in (lexer.REM, lexer.MOD):
......
......@@ -141,7 +141,7 @@ except ImportError:
__all__ = ['opengeode', 'SDL_Scene', 'SDL_View', 'parse']
__version__ = '2.0.11'
__version__ = '2.0.12'
if hasattr(sys, 'frozen'):
# Detect if we are running on Windows (py2exe-generated)
......
......@@ -32,6 +32,8 @@ myBool MyBoolean ::= TRUE
myInt TASTE-Peek-id ::= 5
myInt2 TASTE-Peek-id ::= myInt
myString VariableString ::= 'DEADBEEF'H
mySeqBool SeqBool ::= { TRUE, FALSE }
......
/* CIF PROCESS (295, 56), (150, 75) */
PROCESS orchestrator
/* CIF COMMENT (405, 192), (71, 35) */
COMMENT 'Hello';
/* CIF TEXT (649, 323), (294, 140) */
process orchestrator
/* CIF comment (405, 192), (71, 35) */
comment 'Hello';
/* CIF TEXT (649, 323), (294, 143) */
-- Text area for declarations and comments
dcl toto NamedInt := one;
dcl tutu Enum_with_dash := first_one;
dcl titi NamedInt_with_dash := second_value;
dcl toto NamedInt := one;
dcl tutu Enum_with_dash := first_one;
dcl titi NamedInt_with_dash := second_value;
dcl recursive TASTE_Peek_id := myInt2;
/* CIF ENDTEXT */
/* CIF START (530, 150), (80, 36) */
START;
/* CIF NEXTSTATE (512, 201), (116, 33) */
NEXTSTATE Wait_for_GUI;
/* CIF STATE (1063, 119), (116, 33) */
STATE Wait_for_GUI;
ENDSTATE;
/* CIF STATE (512, 201), (116, 33) */
STATE Wait_for_GUI;
/* CIF INPUT (529, 254), (82, 35) */
INPUT pulse(titi);
/* CIF state (1063, 119), (116, 33) */
state Wait_for_GUI;
endstate;
/* CIF state (512, 201), (116, 33) */
state Wait_for_GUI;
/* CIF input (529, 254), (82, 35) */
input pulse(titi);
/* CIF PROCEDURECALL (522, 309), (96, 35) */
CALL writeln(titi);
/* CIF OUTPUT (508, 359), (123, 35) */
OUTPUT telemetry(tutu);
/* CIF TASK (501, 414), (138, 35) */
TASK tutu := second_one;
/* CIF NEXTSTATE (535, 464), (70, 35) */
call writeln(titi);
/* CIF output (508, 359), (123, 35) */
output telemetry(tutu);
/* CIF task (501, 414), (138, 35) */
task tutu := second_one;
/* CIF task (492, 469), (156, 35) */
task recursive := 1 + myInt2;
/* CIF NEXTSTATE (535, 519), (70, 35) */
NEXTSTATE -;
ENDSTATE;
ENDPROCESS orchestrator;
\ No newline at end of file
endstate;
endprocess orchestrator;
\ No newline at end of file
Supports Markdown
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