Commit 736f7150 authored by Maxime Perrotin's avatar Maxime Perrotin

Major refactoring to move the context to ASN.1

Now all the context, including the state and all DCL variables are
generated as an ASN.1 type
This allows a better interface with external tools in C or Python since
there is a single ASN.1 SEQUENCE variable. There is no need to have a
getter and a setter for each internal variable.
parent 2c9f5c60
......@@ -142,6 +142,9 @@ The background pattern was downloaded from www.subtlepatterns.com
Changelog
=========
**3.3.3 (10/2020)**
- Refactoring : Generate all data types in ASN.1
**3.3.2 (10/2020)**
- Fix reporting of semantic errors in procedures
......
This diff is collapsed.
......@@ -201,13 +201,15 @@ def create_choice_determinant_types(ast):
"Line": each.Line,
"CharPositionInLine": each.CharPositionInLine,
"EnumID": each.type.Children[key].EnumID,
"IsStandardEnum" : False
#"IsStandardEnum" : False
}) for key in each.type.Children.keys()
}
new_sorts[new_sort] = \
type(new_sort, (object,), {
"Line": each.Line,
"CharPositionInLine": each.CharPositionInLine,
"AddedType" : "False",
"ChoiceTypeName" : each.__name__,
"type": type(new_sort + "_type", (object,), {
"Line" : each.Line,
"CharPositionInLine": each.CharPositionInLine,
......@@ -220,7 +222,7 @@ def create_choice_determinant_types(ast):
return new_sorts
def asn2dataModel(*files):
''' Call asn1DataModel, including the Makefile.python and return
''' Call asn2DataModel, including the Makefile.python and return
the imported module "name_of_dataview_asn.py"
From this module it is possible to create native Asn1scc instances of
ASN.1 data types, and to access to DV.py, which contains constants
......
......@@ -179,6 +179,7 @@ lineno = lambda : currentframe().f_back.f_lineno
# they are stored in a dedicated dictionary with the same structure
# as the ASN1SCC generated python AST
USER_DEFINED_TYPES = dict()
CHOICE_SELECTORS = dict()
def types():
......@@ -186,13 +187,13 @@ def types():
ret = getattr(DV, 'types', {}).copy()
ret.update(USER_DEFINED_TYPES)
return ret
#types = lambda: getattr(DV, 'types', {}) or USER_DEFINED_TYPES
def set_global_DV(asn1_filenames):
# type: (List[str]) -> None
''' Call ASN.1 parser and set the global dataview AST entry (DV) '''
global DV
global USER_DEFINED_TYPES
if '--toC' in sys.argv:
rename_policy = ASN1.RenameOnlyConflicting
else:
......@@ -205,7 +206,11 @@ def set_global_DV(asn1_filenames):
pretty_print=True)
# Create new types corresponding to CHOICE determinants as enum
choice_selectors = create_choice_determinant_types (DV)
DV.types.update(choice_selectors)
# Add to user defined types, so that they wil be generated
# as explicit ASN.1 types
CHOICE_SELECTORS.update(choice_selectors)
USER_DEFINED_TYPES=CHOICE_SELECTORS.copy()
#DV.types.update(choice_selectors)
except (ImportError, NameError) as err:
# Can happen if DataView.py is not there
LOG.error('Error loading ASN.1 model')
......@@ -3151,6 +3156,7 @@ def get_array_type(newtypename, root):
newtype = type(str(newtypename), (object,), {
"Line": typeSortLine,
"CharPositionInLine": typeSortChar,
"AddedType": "False",
"type": type ("SeqOf_type", (object,), {
"Line": typeSortLine,
"CharPositionInLine": typeSortChar,
......@@ -3588,7 +3594,8 @@ def process_definition(root, parent=None, context=None):
inner_proc = []
# first look for all text areas to find NEWTYPE declarations
USER_DEFINED_TYPES.clear()
USER_DEFINED_TYPES = CHOICE_SELECTORS.copy()
process.user_defined_types = USER_DEFINED_TYPES
tas = (x for x in root.getChildren() if x.type == lexer.TEXTAREA)
for child in tas:
content = (x for x in child.getChildren()
......@@ -5310,7 +5317,7 @@ def pr_file(root):
# This to allow SDL types injection in ASN1 ASTs
DV = type("ASNParseTree", (object, ),
{"types": {}, "exportedVariables": {}, "asn1Modules": [],
"variables": {}})
"exportedTypes": {}, "variables": {}})
# Re-order the children of the AST to make sure system and use clauses
# are parsed before process definition - to get signal definitions
......
......@@ -140,7 +140,7 @@ except ImportError:
__all__ = ['opengeode', 'SDL_Scene', 'SDL_View', 'parse']
__version__ = '3.3.2'
__version__ = '3.3.3'
if hasattr(sys, 'frozen'):
# Detect if we are running on Windows (py2exe-generated)
......
num(det) = 0 (should be 0)
FOO_PRESENT (should be FOO)
ASN1SCCFOO_PRESENT (should be FOO)
ASN1SCCFOO (should be FOO)
BAR_PRESENT (should be BAR)
ASN1SCCBAR_PRESENT (should be BAR)
ASN1SCCBAR (should be BAR)
ASN1SCCFOO (should be FOO)
......@@ -10,7 +10,7 @@ extern char *orchestrator_state();
void orchestrator_RI_peek_list(void *_) {}
void orchestrator_RI_peek_fixed(void *_) {}
void orchestrator_RI_telemetry(void *_){}
extern char *fixed_value();
//extern char *fixed_value();
//extern int fixed_size();
int main()
{
......@@ -20,7 +20,7 @@ int main()
printf("[C Code] Running test\n");
adainit();
orchestrator_startup();
toto = fixed_value();
// toto = fixed_value();
printf("%s\n", orchestrator_state());
orchestrator_PI_other();
printf("%s\n", orchestrator_state());
......
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