Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
OpenGEODE
Commits
12e33e31
Commit
12e33e31
authored
Nov 07, 2014
by
Maxime Perrotin
Browse files
Fix string handling in Conditional expressions
parent
59bb515c
Changes
8
Hide whitespace changes
Inline
Side-by-side
AdaGenerator.py
View file @
12e33e31
...
...
@@ -1186,6 +1186,7 @@ def _append(expr):
ogAST
.
PrimConstant
))
else
''
)
right
=
'{}{}'
.
format
(
right_str
,
string_payload
(
expr
.
right
,
right_str
)
if
isinstance
(
expr
.
right
,
(
ogAST
.
PrimVariable
,
ogAST
.
PrimConditional
,
ogAST
.
PrimConstant
))
else
''
)
ada_string
=
'(({}) & ({}))'
.
format
(
left
,
right
)
...
...
@@ -1375,15 +1376,27 @@ def _sequence_of(seqof):
stmts
,
local_decl
=
[],
[]
seqof_ty
=
seqof
.
exprType
try
:
asn_type
=
TYPES
[
seqof_ty
.
ReferencedTypeName
].
type
asn_type
=
find_basic_type
(
TYPES
[
seqof_ty
.
ReferencedTypeName
].
type
)
min_size
=
asn_type
.
Min
max_size
=
asn_type
.
Max
except
AttributeError
:
asn_type
=
None
min_size
,
max_size
=
seqof_ty
.
Min
,
seqof_ty
.
Max
if
hasattr
(
seqof
,
'expected_type'
):
asn_type
=
find_basic_type
(
TYPES
[
seqof
.
expected_type
.
ReferencedTypeName
].
type
.
type
)
try
:
min_size
,
max_size
=
asn_type
.
Min
,
asn_type
.
Max
except
AttributeError
:
pass
tab
=
[]
for
i
in
xrange
(
len
(
seqof
.
value
)):
item_stmts
,
item_str
,
local_var
=
expression
(
seqof
.
value
[
i
])
if
isinstance
(
seqof
.
value
[
i
],
(
ogAST
.
PrimSequenceOf
,
ogAST
.
PrimStringLiteral
)):
item_str
=
array_content
(
seqof
.
value
[
i
],
item_str
,
asn_type
or
find_basic_type
(
seqof
.
value
[
i
].
exprType
))
stmts
.
extend
(
item_stmts
)
local_decl
.
extend
(
local_var
)
tab
.
append
(
u
'{i} => {value}'
.
format
(
i
=
i
+
1
,
value
=
item_str
))
...
...
@@ -1710,8 +1723,12 @@ def array_content(prim, values, asnty):
else
:
# Find a default value for the "others" field in case of SEQOF
_
,
df
,
_
=
expression
(
prim
.
value
[
0
])
return
u
"(Data => ({}, others => {}){})"
.
format
(
values
,
df
,
rlen
)
if
isinstance
(
prim
.
value
[
0
],
(
ogAST
.
PrimSequenceOf
,
ogAST
.
PrimStringLiteral
)):
df
=
array_content
(
prim
.
value
[
0
],
df
,
asnty
)
return
u
"(Data => ({}{}others => {}){})"
.
format
(
values
,
', '
if
values
else
''
,
df
,
rlen
)
def
append_size
(
append
):
...
...
ogParser.py
View file @
12e33e31
...
...
@@ -1760,6 +1760,7 @@ def variables(root, ta_ast, context):
else
:
if
def_value
.
exprType
==
UNKNOWN_TYPE
:
def_value
.
exprType
=
asn1_sort
def_value
.
expected_type
=
asn1_sort
if
not
def_value
.
is_raw
and
\
not
isinstance
(
def_value
,
ogAST
.
PrimConstant
):
...
...
@@ -3694,6 +3695,11 @@ def assign(root, context):
# this could cause a bug (and regression is OK)
if
isinstance
(
expr
.
right
,
ogAST
.
ExprAppend
):
expr
.
right
.
exprType
=
expr
.
left
.
exprType
if
isinstance
(
expr
.
right
,
(
ogAST
.
PrimSequenceOf
,
ogAST
.
PrimStringLiteral
)):
# Set the expected type on the right, this is needed to know
# if the expected size is variable or fixed in backends
expr
.
right
.
expected_type
=
expr
.
left
.
exprType
return
expr
,
errors
,
warnings
...
...
tests/regression/test-strings/.Makefile.swp
0 → 100644
View file @
12e33e31
File added
tests/regression/test-strings/Makefile
0 → 100644
View file @
12e33e31
include
../shared.mk
all
:
test-ada test-llvm
edit
:
$(OPENGEODE)
og.pr
test-parse
:
$(OPENGEODE)
og.pr
--check
test-ada
:
dataview-uniq.o | test_ada.o
$(OPENGEODE)
og.pr
--toAda
$(ASN1SCC)
-Ada
dataview-uniq.asn
-typePrefix
asn1Scc
-equal
$(GNATMAKE)
-O
$(O)
-c
*
.adb
$(GNATBIND)
-n
og.ali
$(GNATLINK)
-o
test_ada test_ada.o og.ali
-lgnat
./test_ada
test-llvm
:
test.o dataview-uniq.o | test_llvm.o
$(OPENGEODE)
og.pr
--llvm
-O
$(O)
$(LLC)
*
.ll
$(CC)
-O
$(O)
-c
*
.s
$(CC)
test.o dataview-uniq.o test_llvm.o
-o
test_llvm
-lm
coverage
:
coverage run
-p
$(OPENGEODE)
og.pr
--toAda
.PHONY
:
all edit test-parse test-ada test-llvm coverage
tests/regression/test-strings/dataview-uniq.asn
0 → 100644
View file @
12e33e31
TASTE-Dataview DEFINITIONS ::=
BEGIN
List ::= SEQUENCE(SIZE(5)) OF OCTET STRING(SIZE(1..5))
OutStr ::= OCTET STRING (SIZE(0..255))
END
tests/regression/test-strings/og.pr
0 → 100644
View file @
12e33e31
SYSTEM og;
/* CIF TEXT (279, 258), (356, 140) */
-- Text area for declarations and comments
use dv comment 'dataview-uniq.asn';
signal run;
/* CIF ENDTEXT */
CHANNEL c
FROM ENV TO og WITH run;
ENDCHANNEL;
BLOCK og;
SIGNALROUTE r
FROM ENV TO og WITH run;
CONNECT c AND r;
/* CIF PROCESS (253, 105), (150, 75) */
PROCESS og;
/* CIF TEXT (0, 33), (356, 143) */
-- Text area for declarations and comments
dcl a List := {'a', 'b', 'foo', 'bar
', ' baz'};
dcl result OutStr := '';
dcl sep OutStr := ', ';
dcl nosep OutStr := '';
/* CIF ENDTEXT */
/* CIF START (597, 63), (70, 35) */
START;
/* CIF TASK (539, 113), (185, 35) */
TASK result := result // 'Hello!';
/* CIF TASK (584, 163), (96, 35) */
TASK result := '';
/* CIF TASK (403, 213), (457, 78) */
TASK for each in a(2, length(a) - 1):
result := result // (if length(result) > 0 then sep else nosep fi) // each
endfor;
/* CIF PROCEDURECALL (567, 306), (129, 35) */
CALL writeln(result);
/* CIF NEXTSTATE (597, 356), (70, 35) */
NEXTSTATE wait;
/* CIF STATE (286, 217), (70, 35) */
STATE wait;
ENDSTATE;
ENDPROCESS og;
ENDBLOCK;
ENDSYSTEM;
\ No newline at end of file
tests/regression/test-strings/test_ada.c
0 → 100644
View file @
12e33e31
#include
<stdio.h>
#include
"dataview-uniq.h"
extern
void
adainit
();
int
main
()
{
adainit
();
return
0
;
}
tests/regression/test-strings/test_llvm.c
0 → 100644
View file @
12e33e31
#include
<stdio.h>
#include
"dataview-uniq.h"
extern
void
test_startup
();
int
main
()
{
test_startup
();
return
0
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment