Commit 1c9bd93f authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Parser reports proper error in choice selectors

Report error when user writes somechoice!a := value instead of
somechoice := a:value (reported warning before)
and report no error when accessing somechoice!a (on the right side of
expressions)
Add test case
parent 3963ff98
......@@ -1624,7 +1624,7 @@ def primary_substring(root, context):
return node, errors, warnings
def selector_expression(root, context):
def selector_expression(root, context, pos="right"):
''' Selector expression analysis '''
errors, warnings = [], []
......@@ -1641,8 +1641,9 @@ def selector_expression(root, context):
field_name = root.children[1].text.replace('_', '-').lower()
try:
if receiver_bty.kind == 'ChoiceType':
warnings.append(warning(root, 'Choice assignment: '
if receiver_bty.kind == 'ChoiceType' and pos == "left":
# Error if this is the left part of an assignment
errors.append(warning(root, 'Choice assignment: '
'use "var := {field}: value" instead of '
'"var!{field} := value"'
.format(field=field_name)))
......@@ -3962,7 +3963,8 @@ def assign(root, context):
if root.children[0].type == lexer.CALL:
expr.left, err, warn = call_expression(root.children[0], context)
elif root.children[0].type == lexer.SELECTOR:
expr.left, err, warn = selector_expression(root.children[0], context)
expr.left, err, warn = selector_expression(root.children[0], context,
pos="left")
else:
expr.left, err, warn = primary_variable(root.children[0], context)
warnings.extend(warn)
......
include ../shared.mk
all: test-ada test-llvm
edit:
$(OPENGEODE) og.pr
test-parse:
$(OPENGEODE) og.pr --check
test-ada:
$(OPENGEODE) og.pr --toAda
$(ASN1SCC) -Ada dataview.asn -typePrefix asn1Scc -equal
$(GNATMAKE) -O$(O) -c *.adb
$(GNATBIND) -n og.ali
test-c:
$(OPENGEODE) og.pr --toC
$(ASN1SCC) -c dataview.asn -typePrefix asn1Scc -equal
$(CC) -O$(O) -c *.c
test-llvm:
$(OPENGEODE) og.pr --llvm -O$(O)
$(LLC) *.ll
$(CC) -O$(O) -c *.s
coverage:
coverage run -p $(OPENGEODE) og.pr --toAda
.PHONY: all edit test-parse test-ada test-llvm coverage
TASTE-Dataview DEFINITIONS ::=
BEGIN
EmptySeq ::= SEQUENCE {}
AnotherEmptySeq ::= SEQUENCE {}
NullType ::= NULL
ChoiceWithEmptySeq ::= CHOICE {
a NULL,
b EmptySeq,
c NullType
}
c1 EmptySeq ::= {}
n1 NullType ::= NULL
c2 ChoiceWithEmptySeq ::= a: NULL
c3 ChoiceWithEmptySeq ::= b: {}
c4 ChoiceWithEmptySeq ::= c: NULL
c5 AnotherEmptySeq ::= {}
-- Type below is accepted by ASN.1 compiler but that's wrong
-- c6 ChoiceWithEmptySeq ::= b: c5
END
SYSTEM og;
/* CIF TEXT (159, 221), (289, 188) */
-- Text area for declarations and comments
use dv comment 'dataview.asn';
signal dd;
signal we;
/* CIF ENDTEXT */
CHANNEL c
FROM ENV TO og WITH dd;
FROM og TO ENV WITH we;
ENDCHANNEL;
BLOCK og;
SIGNALROUTE r
FROM ENV TO og WITH dd;
FROM og TO ENV WITH we;
CONNECT c AND r;
/* CIF PROCESS (225, 49), (150, 75) */
PROCESS og;
/* CIF TEXT (56, 58), (337, 130) */
-- Test choice assignments and access
dcl ch ChoiceWithEmptySeq := a: NULL;
dcl em EmptySeq := {};
/* CIF ENDTEXT */
/* CIF START (160, 226), (70, 35) */
START;
/* CIF TASK (148, 276), (93, 35) */
TASK ch := b: {};
/* CIF TASK (144, 326), (100, 35) */
TASK em := ch!b
/* CIF COMMENT (261, 324), (175, 40) */
COMMENT 'This is ok, there should
be no warning raised';
/* CIF NEXTSTATE (160, 376), (70, 35) */
NEXTSTATE wait;
/* CIF STATE (460, 231), (70, 35) */
STATE wait;
/* CIF INPUT (453, 286), (84, 35) */
INPUT dd;
/* CIF OUTPUT (450, 336), (89, 35) */
OUTPUT we;
/* CIF NEXTSTATE (460, 386), (70, 35) */
NEXTSTATE wait;
ENDSTATE;
ENDPROCESS og;
ENDBLOCK;
ENDSYSTEM;
\ No newline at end of file
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