Commit ebf11fb3 authored by Maxime Perrotin's avatar Maxime Perrotin

Generate iterators for SEQUENCE

parent f1cfa191
......@@ -5,11 +5,10 @@ all:
@echo A testcase can be build from source with "make test"
install: uninstall
mkdir -p obj && rm -f obj/taste-asn1-iterators && \
sed 's,$$PREFIX,$(PREFIX),g' src/taste-asn1-iterators > obj/taste-asn1-iterators && \
chmod +x obj/taste-asn1-iterators
mkdir -p obj && cp src/taste-asn1-iterators.py obj/taste-asn1-iterators
gprbuild -p asn1_iterators.gpr
gprinstall -p -XLIBRARY_TYPE=dynamic --build-name=shared --prefix=$(PREFIX) asn1_iterators.gpr
rm -rf obj
@echo Do not forget to export ADA_PROJECT_PATH=$(PREFIX)/share/gpr
test_build: clean install
......
PREFIX?=$(HOME)/.local
all:
@echo You can install with "make install"
@echo A testcase can be build from source with "make test"
install: uninstall
mkdir -p obj && rm -f obj/taste-asn1-iterators && \
sed 's,$$PREFIX,$(PREFIX),g' src/taste-asn1-iterators > obj/taste-asn1-iterators && \
chmod +x obj/taste-asn1-iterators
gprbuild -p asn1_iterators.gpr
gprinstall -p -XLIBRARY_TYPE=dynamic --build-name=shared --prefix=$(PREFIX) asn1_iterators.gpr
@echo Do not forget to export ADA_PROJECT_PATH=$(PREFIX)/share/gpr
test_build: clean install
mkdir -p build_test
cp test/DataView.asn build_test
cd build_test && taste-asn1-iterators DataView.asn
gprbuild -p -P test_generic.gpr
test: test_build
build_test/test_generic
uninstall:
gprinstall --uninstall --prefix=$(PREFIX) asn1_iterators || :
clean:
gprclean test_generic.gpr || :
gprclean asn1_iterators.gpr || :
.PHONY: all clean install test test_build
asn1-iterators
==============
(c) 2016-2017 European Space Agency
(c) 2016-2019 European Space Agency
Author/Contact: Maxime.Perrotin@esa.int
Generic iterator functions in Ada for generating all combinations of values of ASN.1 data types
v0.1 support for INTEGER with a range and SEQUENCE OF INTEGER (fixed and variable size arrays)
test:
cd src
make
Support integer, enumerated, sequence, sequence of (fixed and variable sizes)
Work in progress... Part of the TASTE project.
......@@ -13,6 +13,7 @@
"""
__version__ = "3.0.0"
import os
import signal
import argparse
import traceback
......@@ -265,6 +266,21 @@ def sequence_adb_template (sort: str, fields: dict) -> str:
end {sort}_Pkg;'''
def top_ads_template(modules: List[str]) -> str:
''' Template for asn1_ada_iterators.ads '''
withs = (f'''with {module}; use {module}; pragma Unreferenced ({module});'''
for module in modules)
withs_str = '\n'.join(withs)
return f'''-- This file was generated by TASTE: DO NOT EDIT
{withs_str}
package ASN1_Ada_Iterators is
end;'''
def ads_template(packages: List[str]) -> str:
''' Top-level template to generate the .ads file '''
return f'''-- This file was generated by TASTE: DO NOT EDIT
......@@ -434,6 +450,13 @@ def parse_args():
action='store_true',
default=False,
help='Display debug information')
parser.add_argument(
'-o',
'--output',
type=str,
metavar='folder',
default='iterators',
help='Set the output folder')
parser.add_argument(
'files',
metavar='file.asn',
......@@ -465,7 +488,7 @@ def run(options):
# Parse the ASN.1 AST to know the types and generate the corresponding code
sorts = {}
for module, types in ast.exportedTypes.items():
modules.append(module)
modules.append(module.replace('-', '_'))
for sort in types:
sort_def = ast.types[sort]
basic = parser.find_basic_type (sort_def.type)
......@@ -518,14 +541,20 @@ def run(options):
ads = ads_template(packages_ads)
adb = adb_template(packages_adb)
top_ads = top_ads_template(modules)
out_folder = options.output if options.output else '.'
os.makedirs(out_folder, exist_ok=True)
# Write the .ads
with open ("asn1_ada_iterators-iterators.ads", "wb") as source:
with open (f"{out_folder}/asn1_ada_iterators-iterators.ads", "wb") as source:
source.write(ads.encode('latin1'))
with open ("asn1_ada_iterators-iterators.adb", "wb") as source:
with open (f"{out_folder}/asn1_ada_iterators-iterators.adb", "wb") as source:
source.write(adb.encode('latin1'))
with open (f"{out_folder}/asn1_ada_iterators.ads", "wb") as source:
source.write(top_ads.encode('latin1'))
def main():
''' Tool entry point '''
# Catch Ctrl-C to stop the app from the console
......
this folder is DEPRECATED, the code is now generated from python
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