Commit c7d0bc6b authored by Laura Alexandra Sequeira Gouveia's avatar Laura Alexandra Sequeira Gouveia

Merge branch 'master' into CoRA-ZynQ

parents 5d0ec830 34f98001
version: 2
jobs:
build:
machine: true
steps:
- checkout
- restore_cache:
key: docker-{{ checksum "Dockerfile" }}
- run:
command: if [[ -e ~/docker/image.tar ]]; then docker load --input ~/docker/image.tar; else docker build -t dmt . && { mkdir -p ~/docker; docker save dmt > ~/docker/image.tar ; } ; fi
- save_cache:
key: docker-{{ checksum "Dockerfile" }}
paths:
- ~/docker
- run:
command: docker run -it -v $(pwd):/root/tests dmt bash -c 'cd /root/tests ; pip3 uninstall dmt ; pip3 install --upgrade . ; LANG=C LC_ALL=C PATH=$PATH:/asn1scc make'
......@@ -14,3 +14,10 @@ tests-sqlalchemy/test.db
tests-sqlalchemy/verifier/LotsOfDataTypes.asn
tests-sqlalchemy/verifier/asn2dataModel/
.mypy_cache
env
aclocal.m4
autom4te.cache/
config.log
config.status
setup.py
dmt/commonPy/__init__.py
FROM debian:stretch
RUN bash -c echo -e 'Acquire::http::Pipeline-Depth 0;\nAcquire::http::No-Cache true;\nAcquire::BrokenProxy true;\n' > /etc/apt/apt.conf.d/99badproxies
RUN cat /etc/apt/apt.conf.d/99badproxies
RUN apt-get update
RUN apt-get install -y libxslt-dev libxml2-dev python-psycopg2 mono-runtime libmono-system-data4.0-cil libmono-system-web4.0-cil libfsharp-core4.3-cil
RUN apt-get install -y wget python3-pip
RUN wget -O - -q https://github.com/ttsiodras/asn1scc/releases/download/4.2.0.1.f/asn1scc-bin-4.2.0.1f.tar.bz2 | tar jxvf -
RUN apt-get install -y python-pip
RUN wget -O - -q https://github.com/ttsiodras/DataModellingTools/files/335591/antlr-2.7.7.tar.gz | tar zxvf - ; cd antlr-2.7.7/lib/python ; pip2 install .
RUN pip2 install SQLAlchemy psycopg2
COPY requirements.txt /tmp/
RUN pip3 install -r /tmp/requirements.txt
RUN apt-get install less
RUN apt-get install -y postgresql
COPY setup_testdb.sh /tmp/
RUN /tmp/setup_testdb.sh
......@@ -5,11 +5,19 @@ PY_SRC:=$(filter-out dmt/B_mappers/antlr.main.py dmt/A_mappers/Stubs.py, ${PY_SR
# the one installed in $HOME/.local via setup.py.
#
# To address this, we find where our pip-installed typing lives:
TYPING_FOLDER:=$(shell pip3 show typing | grep ^Location | sed 's,^.*: ,,')
TYPING_FOLDER:=$(shell pip3 show typing 2>/dev/null | grep ^Location | sed 's,^.*: ,,')
export PYTHONPATH=${TYPING_FOLDER}
# all: flake8 pylint mypy coverage testDB
all: flake8 mypy coverage testDB
all: tests
tests: flake8 pylint mypy coverage testDB
configure:
./configure
install: configure
pip3 uninstall -y dmt || exit 0 # Uninstall if there, but don't abort if not installed
pip3 install --user .
flake8:
@echo Performing syntax checks via flake8...
......@@ -33,4 +41,4 @@ testDB:
@echo Performing database tests...
@$(MAKE) -C tests-sqlalchemy || exit 1
.PHONY: flake8 pylint mypy coverage
.PHONY: flake8 pylint mypy coverage install configure
# Automake macro to set the revision utils
# Usage: AM_REVISION_UTILS([directory_name]).
# Directory name must be a litteral string and not the result of a
# command.
AC_DEFUN([AM_REVISION_UTILS],
[
# Take the current SVN revision
AC_MSG_CHECKING(whether this is a SCM working copy)
temp_scm_output=`(cd $srcdir; git rev-parse --short HEAD)`
if test x"${temp_scm_output}" = x""; then
# This means we are NOT working on a repository copy, the value of
# SCM_REVISION will not be taken into account.
SCM_REVISION=""
AC_MSG_RESULT(no.)
else
SCM_REVISION="r${temp_scm_output}"
AC_MSG_RESULT(yes: ${SCM_REVISION}.)
fi
AC_SUBST(SCM_REVISION)
# Take the configure full date
AC_MSG_CHECKING(the configuration full date)
temp_config_date=`LANG=C date +"%A %d %B %Y, %H:%M:%S"`
if test x"${temp_config_date}" = x""; then
LAST_CONFIG_DATE=""
AC_MSG_RESULT(empty date.)
else
LAST_CONFIG_DATE="${temp_config_date}"
AC_MSG_RESULT(${LAST_CONFIG_DATE}.)
fi
AC_SUBST(LAST_CONFIG_DATE)
# Take the configure year
AC_MSG_CHECKING(the configuration year)
temp_config_year=`LANG=C date +"%Y"`
if test x"${temp_config_year}" = x""; then
LAST_CONFIG_YEAR="2007"
AC_MSG_RESULT(no year found, fall into default: ${LAST_CONFIG_YEAR}.)
else
LAST_CONFIG_YEAR="${temp_config_year}"
AC_MSG_RESULT(${LAST_CONFIG_YEAR})
fi
AC_SUBST(LAST_CONFIG_YEAR)
])
m4_include([ac-macros/revision_utils.m4])
machine:
post:
- pyenv global 3.4.4 system
dependencies:
cache_directories:
- "~/.apt-cache"
pre:
- sudo rm -rf /var/cache/apt/archives && sudo ln -s ~/.apt-cache /var/cache/apt/archives && mkdir -p ~/.apt-cache/partial
# - sudo apt-get update
- sudo apt-get install libxslt-dev libxml2-dev python-psycopg2
- wget -O - -q https://github.com/ttsiodras/asn1scc/releases/download/4.1b/asn1scc-bin-4.1b.tar.bz2 | tar jxvf -
- wget -O - -q https://github.com/ttsiodras/DataModellingTools/files/335591/antlr-2.7.7.tar.gz | tar zxvf - ; cd antlr-2.7.7/lib/python ; sudo pip2 install .
- sudo apt-get install mono-runtime libmono-system-data4.0-cil libmono-system-web4.0-cil libfsharp-core4.3-cil
override:
- pip3 install -r requirements.txt
test:
override:
- sudo pip2 install SQLAlchemy psycopg2
- PATH=$PATH:$(pwd)/asn1scc make
This diff is collapsed.
AC_INIT([DMT], [2.2], [Thanassis.Tsiodras@esa.int])
AC_CONFIG_MACRO_DIR([ac-macros])
AM_REVISION_UTILS
# Finally create all the generated files
AC_CONFIG_FILES([setup.py dmt/commonPy/__init__.py])
AC_OUTPUT
......@@ -23,12 +23,16 @@ from __future__ import absolute_import
import os
import re
import copy
import sys
import DV_Types # pylint: disable=import-error
from ctypes import (
cdll, c_void_p, c_ubyte, c_double, c_uint,
c_longlong, c_bool, c_int, c_long, c_char
)
if sys.version_info > (3,):
long = int
# load the *getset.so in this folder
script_path = os.path.dirname(os.path.realpath(__file__))
soFileNames = [
......@@ -102,12 +106,20 @@ class DataStream(object):
def GetPyString(self):
# print "Reading",
msg = ""
pData = c_void_p(GetBitstreamBuffer(self._bs))
for i in range(0, GetStreamCurrentLength(self._bs)):
b = GetBufferByte(pData, i)
msg += chr(b)
# print b, ",",
if sys.version_info > (3,):
msg = b""
pData = c_void_p(GetBitstreamBuffer(self._bs))
for i in range(0, GetStreamCurrentLength(self._bs)):
b = GetBufferByte(pData, i)
msg += bytes([b])
# print b, ",",
else:
msg = ""
pData = c_void_p(GetBitstreamBuffer(self._bs))
for i in range(0, GetStreamCurrentLength(self._bs)):
b = GetBufferByte(pData, i)
msg += chr(b)
# print b, ",",
# print "EOF"
return msg
......@@ -117,10 +129,16 @@ class DataStream(object):
self._bs.count = strLength
pData = c_void_p(GetBitstreamBuffer(self._bs))
# print "Writing",
for i in range(0, strLength):
b = ord(data[i])
# print b, ",",
SetBufferByte(pData, i, b)
if sys.version_info > (3,):
for i in range(0, strLength):
b = data[i]
# print b, ",",
SetBufferByte(pData, i, b)
else:
for i in range(0, strLength):
b = ord(data[i])
# print b, ",",
SetBufferByte(pData, i, b)
# print "EOF"
......@@ -354,22 +372,42 @@ grep for the errorcode value inside ASN1SCC generated headers."""
self.SetLength(strLength, False)
self._Caccessor += "_iDx"
accessPath = self._accessPath
for idx in range(0, strLength):
self._params.append(idx)
self._accessPath = accessPath + "[" + str(idx) + "]"
self.Set(ord(src[idx]), reset=False)
self._params.pop()
if sys.version_info > (3,):
for idx in range(0, strLength):
self._params.append(idx)
self._accessPath = accessPath + "[" + str(idx) + "]"
self.Set(ord(src[idx]), reset=False)
self._params.pop()
else:
for idx in range(0, strLength):
self._params.append(idx)
self._accessPath = accessPath + "[" + str(idx) + "]"
self.Set(ord(src[idx]), reset=False)
self._params.pop()
self.Reset()
def GetPyString(self):
retval = ""
strLength = self.GetLength(False)
self._Caccessor += "_iDx"
accessPath = self._accessPath
for idx in range(0, strLength):
self._params.append(idx)
self._accessPath = accessPath + "[" + str(idx) + "]"
retval += chr(self.Get(reset=False))
self._params.pop()
self.Reset()
return retval
if sys.version_info > (3,):
retval = b""
strLength = self.GetLength(False)
self._Caccessor += "_iDx"
accessPath = self._accessPath
for idx in range(0, strLength):
self._params.append(idx)
self._accessPath = accessPath + "[" + str(idx) + "]"
retval += bytes([self.Get(reset=False)])
self._params.pop()
self.Reset()
return retval.decode("utf-8")
else:
retval = ""
strLength = self.GetLength(False)
self._Caccessor += "_iDx"
accessPath = self._accessPath
for idx in range(0, strLength):
self._params.append(idx)
self._accessPath = accessPath + "[" + str(idx) + "]"
retval += chr(self.Get(reset=False))
self._params.pop()
self.Reset()
return retval
......@@ -24,7 +24,7 @@ code generator A.'''
import os
import sys
import distutils.spawn as spawn
from distutils import spawn
from typing import List
from ..commonPy.utility import panic
......@@ -47,12 +47,12 @@ def OnStartup(unused_modelingLanguage: str, asnFiles: List[str], outputDir: str,
if not asn1SccPath:
panic("ASN1SCC seems to be missing from your system (asn1.exe not found in PATH).\n") # pragma: no cover
# allow externally-defined flags when calling the asn1 compiler (e.g. to set word size based on target)
extraFlags = os.getenv ("ASN1SCC_FLAGS") or ""
extraFlags = os.getenv("ASN1SCC_FLAGS") or ""
os.system(
("mono " if sys.platform.startswith('linux') else "") +
"\"{}\" -typePrefix asn1Scc -Ada {} -uPER -o \"".format(asn1SccPath, extraFlags) +
"\"{}\" -typePrefix asn1Scc -equal -Ada {} -o \"".format(asn1SccPath, extraFlags) +
outputDir + "\" \"" + "\" \"".join(asnFiles) + "\"")
os.system("rm -f \"" + outputDir + "\"/*.adb")
# os.system("rm -f \"" + outputDir + "\"/*.adb")
def OnBasic(unused_nodeTypename: str, unused_node: AsnBasicNode, unused_leafTypeDict: AST_Leaftypes) -> None:
......
......@@ -24,7 +24,7 @@ code generator A.'''
import os
import sys
import distutils.spawn as spawn
from distutils import spawn
from typing import List
from ..commonPy.utility import panic
......@@ -49,12 +49,12 @@ def OnStartup(unused_modelingLanguage: str, asnFiles: List[str], outputDir: str,
("mono " if sys.platform.startswith('linux') else "") +
"\"{}\" -typePrefix asn1Scc -c -uPER -o \"".format(asn1SccPath) +
outputDir + "\" \"" + "\" \"".join(asnFiles) + "\"")
cmd = 'rm -f '
for i in ['real.c', 'asn1crt.c', 'acn.c']:
cmd += ' "' + outputDir + '"/' + i
os.system(cmd)
for tmp in asnFiles:
os.system("rm -f \"" + outputDir + os.sep + os.path.basename(os.path.splitext(tmp)[0]) + ".c\"")
# cmd = 'rm -f '
# for i in ['real.c', 'asn1crt.c', 'acn.c']:
# cmd += ' "' + outputDir + '"/' + i
# os.system(cmd)
# for tmp in asnFiles:
# os.system("rm -f \"" + outputDir + os.sep + os.path.basename(os.path.splitext(tmp)[0]) + ".c\"")
def OnBasic(unused_nodeTypename: str, unused_node: AsnBasicNode, unused_leafTypeDict: AST_Leaftypes) -> None:
......
......@@ -31,7 +31,7 @@ enums_dump = "\n ".join(
)
enums_dump += "\n ".join(
'printf("%s = %d\\n");' % (name.strip(), int(val))
'printf("{} = {}\\n");'.format(name.strip(), val.replace('LL', ''))
for name, val in enums
)
uniq = os.getpid()
......
......@@ -102,7 +102,7 @@ def OnStartup(unused_modelingLanguage: str, asnFile: str, outputDir: str, badTyp
g_outputGetSetC.write('}\n\n')
g_outputGetSetC.write('void ResetStream(BitStream *pStrm) {\n')
g_outputGetSetC.write(' assert(pStrm);\n')
g_outputGetSetC.write(' assert(pStrm->count > 0);\n')
g_outputGetSetC.write(' assert(pStrm->count >= 0);\n')
g_outputGetSetC.write(' pStrm->currentByte = 0;\n')
g_outputGetSetC.write(' pStrm->currentBit = 0;\n')
g_outputGetSetC.write('}\n\n')
......@@ -131,12 +131,14 @@ def OnStartup(unused_modelingLanguage: str, asnFile: str, outputDir: str, badTyp
# mono_exe = "mono " if sys.platform.startswith('linux') else ""
mono_exe = "mono"
makefile_text = '''\
export MAKEFLAGS="-j $(grep -c ^processor /proc/cpuinfo)"
ASN1SCC:=$(shell which asn1.exe)
ASN2DATAMODEL:=asn2dataModel
GRAMMAR := %(origGrammarBase)s
BASEGRAMMAR := %(base)s
BDIR:= .
OBJ := $(BDIR)/$(GRAMMAR).o $(BDIR)/asn1crt.o $(BDIR)/real.o $(BDIR)/acn.o $(BDIR)/$(BASEGRAMMAR)_getset.o
OBJ := $(BDIR)/$(GRAMMAR).o $(BDIR)/asn1crt.o $(BDIR)/asn1crt_encoding.o $(BDIR)/asn1crt_encoding_uper.o $(BDIR)/asn1crt_encoding_acn.o $(BDIR)/$(BASEGRAMMAR)_getset.o
all: $(BDIR)/$(BASEGRAMMAR)_getset.so $(BDIR)/DV.py
......@@ -144,22 +146,39 @@ $(BDIR)/$(GRAMMAR)_getset.c: $(GRAMMAR).asn
%(tab)smkdir -p $(BDIR)
%(tab)s$(ASN2DATAMODEL) -toPython -o $(BDIR) $<
$(BDIR)/asn1crt.c $(BDIR)/$(GRAMMAR).c $(BDIR)/real.c $(BDIR)/acn.c $(BDIR)/$(GRAMMAR).h $(BDIR)/asn1crt.h: $(GRAMMAR).asn
%(tab)sif [ ! -f "$(GRAMMAR).acn" ] ; then %(mono)s $(ASN1SCC) -ACND -o $(BDIR) $< ; fi
# Create the ACN file if it is missing
$(BDIR)/$(GRAMMAR).acn:
%(tab)smono $(ASN1SCC) -ACND -o $(BDIR) $(GRAMMAR).asn
# The hell of multiple outputs (see https://www.gnu.org/software/automake/manual/html_node/Multiple-Outputs.html )
$(BDIR)/asn1crt.c: $(GRAMMAR).asn $(GRAMMAR).acn
%(tab)s%(mono)s $(ASN1SCC) -ACN -c -uPER -equal -o $(BDIR) $< $(GRAMMAR).acn
$(BDIR)/DV.py: $(GRAMMAR).asn
# The hell of multiple outputs (see https://www.gnu.org/software/automake/manual/html_node/Multiple-Outputs.html )
$(BDIR)/$(GRAMMAR).c $(BDIR)/asn1crt_encoding.c $(BDIR)/asn1crt_encoding_uper.c $(BDIR)/asn1crt_encoding_acn.c $(BDIR)/$(GRAMMAR).h $(BDIR)/asn1crt.h: $(BDIR)/asn1crt.c
## Recover from the removal of any of these
%(tab)s@for i in $@; do \
%(tab)s if test -f "$$i" ; then :; \
%(tab)s else \
%(tab)s%(tab)srm -f $< ; \
%(tab)s%(tab)s$(MAKE) $< ; \
%(tab)s fi ; \
%(tab)sdone
$(BDIR)/$(GRAMMAR).c $(BDIR)/asn1crt_encoding.c $(BDIR)/asn1crt_encoding_uper.c $(BDIR)/asn1crt_encoding_acn.c $(BDIR)/$(GRAMMAR).h $(BDIR)/asn1crt.h:
$(BDIR)/DV.py: $(GRAMMAR).asn $(BDIR)/$(GRAMMAR).h
%(tab)sgrep 'REQUIRED_BYTES_FOR_.*ENCODING' $(BDIR)/$(GRAMMAR).h | awk '{print $$2 " = " $$3}' > $@
%(tab)spython learn_CHOICE_enums.py %(base)s >> $@
%(tab)spython learn_CHOICE_enums.py %(base)s >> $@ || rm $@
$(BDIR)/%%.o: $(BDIR)/%%.c
$(BDIR)/%%.o: $(BDIR)/%%.c $(BDIR)/$(GRAMMAR).h
%(tab)sgcc -g -fPIC -c `python-config --includes` -o $@ $<
$(BDIR)/$(BASEGRAMMAR)_getset.so: ${OBJ}
%(tab)sgcc -g -fPIC -shared `python-config --ldflags` -o $@ $^
clean:
%(tab)srm -f $(BDIR)/asn1crt.? $(BDIR)/real.? $(BDIR)/$(GRAMMAR).? $(BDIR)/acn.?
%(tab)srm -f $(BDIR)/asn1crt* $(BDIR)/$(GRAMMAR).?
%(tab)srm -f $(BDIR)/DV.py $(BDIR)/*.pyc $(BDIR)/$(BASEGRAMMAR)_getset.? $(BDIR)/$(BASEGRAMMAR)_getset.so
%(tab)srm -f $(BDIR)/$(GRAMMAR)_asn.py
'''
......
......@@ -29,7 +29,7 @@ import os
import sys
import re
import distutils.spawn as spawn
from distutils import spawn
from typing import List, Union, Set # NOQA
from ..commonPy import asnParser
......
......@@ -88,7 +88,7 @@ def FixupNestedStringsAndEnumerated() -> None:
node = names[nodeTypename]
if isinstance(node, (AsnSequence, AsnChoice, AsnSet)):
for child in node._members:
if isinstance(child[1], AsnString) or isinstance(child[1], AsnEnumerated):
if isinstance(child[1], (AsnString, AsnEnumerated)):
newName = nodeTypename + "_" + child[0] # pragma: no cover
while newName in names: # pragma: no cover
newName += "_t" # pragma: no cover
......@@ -158,7 +158,7 @@ def RenderElements(controlString: str) -> None:
else:
# This is a bug in pylint - scheduled to be fixed in next release, by:
# https://github.com/PyCQA/pylint/commit/6d31776454b5e308e4b869a1893b39083dca3146
newElement = g_doc.createElement(finalElementName) # pylint: disable=redefined-variable-type
newElement = g_doc.createElement(finalElementName)
if attributes:
for atr in attributes:
# This is a bug in pylint - scheduled to be fixed in next release, by:
......@@ -168,7 +168,7 @@ def RenderElements(controlString: str) -> None:
parent = createdElements[under]
parent.appendChild(newElement)
createdElements[finalElementName] = newElement
parent = newElement # pylint: disable=redefined-variable-type
parent = newElement
def GetOID(nodeTypename: str) -> str:
......@@ -259,7 +259,7 @@ def OnBasic(nodeTypename: str, node: AsnBasicNode, unused_leafTypeDict: AST_Leaf
def CommonSeqSetChoice(nodeTypename: str,
node: Union[AsnSequence, AsnSet, AsnChoice],
unused_leafTypeDict: AST_Leaftypes,
isChoice: bool=False) -> None:
isChoice: bool = False) -> None:
if nodeTypename in g_declaredTypes:
return
g_declaredTypes.add(nodeTypename)
......
......@@ -209,7 +209,7 @@ def CreateDeclarationForType(nodeTypename: str, names: AST_Lookup, leafTypeDict:
CreateAlias(nodeTypename, "int32", "values of ENUMERATED %s" % nodeTypename)
g_outputFile.write("\n")
elif isinstance(node, (AsnSequence, AsnSet, AsnChoice)):
if len(node._members) == 0:
if not node._members:
panic("Simulink_A_mapper: Simulink can't support empty Seq/Set/Choice! (%s)" % node.Location()) # pragma: no cover
elemNo = 0
if isinstance(node, AsnChoice):
......
......@@ -46,7 +46,7 @@ def Version() -> None:
# noinspection PyDefaultArgument
def getUID(strIdentifier: str, idStore: Dict[str, str]={}) -> str: # pylint: disable=dangerous-default-value
def getUID(strIdentifier: str, idStore: Dict[str, str] = {}) -> str: # pylint: disable=dangerous-default-value
def h(digits: int) -> str:
ret = ""
for _ in range(0, digits):
......
......@@ -211,7 +211,7 @@ CREATE TABLE {cleanTypename} (
def CommonSeqSetChoice(nodeTypename: str,
node: Union[AsnChoice, AsnSet, AsnSequence],
unused_leafTypeDict: AST_Leaftypes,
isChoice: bool=False) -> None:
isChoice: bool = False) -> None:
cleanTypename = CleanName(nodeTypename)
g_sqlOutput.write(
'\nCREATE TABLE {cleanTypename} (\n id int NOT NULL,\n'.format(
......
......@@ -252,7 +252,7 @@ class {cleanTypename}_SQL(Base):
def CommonSeqSetChoice(nodeTypename: str,
node: Union[AsnSet, AsnSequence, AsnChoice],
unused_leafTypeDict: AST_Leaftypes,
isChoice: bool=False) -> None:
isChoice: bool = False) -> None:
cleanTypename = CleanName(nodeTypename)
choiceField = ''
if isChoice:
......@@ -265,7 +265,7 @@ def CommonSeqSetChoice(nodeTypename: str,
for c in node._members:
cleanFieldname = CleanName(c[0])
memberAssignments.append(
'if self.kind == DV.' + c[-1] + ':')
'if self.kind == DV.' + c[2] + ':')
memberAssignments.append(' pyObj.Reset(state)')
assert isinstance(c[1], AsnMetaMember)
containedTypename = CleanName(c[1]._containedType)
......@@ -346,7 +346,7 @@ class {cleanTypename}_SQL(Base):
if isChoice:
g_sqlalchemyOutput.write(
' '
'if self.kind == DV.' + c[-1] + ':\n')
'if self.kind == DV.' + c[2] + ':\n')
g_sqlalchemyOutput.write(
' '
'self.{cleanFieldname} = '
......
......@@ -9,7 +9,7 @@ file created by Maxime Perrotin.
import os
import sys
import distutils.spawn as spawn
from distutils import spawn
from typing import List, Union
from ..commonPy.utility import panic
......
......@@ -519,7 +519,7 @@ def WriteCodeForGUIControls(
varPrefix = prefix.replace("::", "_")
txtPrefix = re.sub(r'^.*::', '', prefix)
# Depending on the type of the node, create the appropriate controls
if isinstance(node, AsnInt) or isinstance(node, AsnReal) or isinstance(node, AsnOctetString):
if isinstance(node, (AsnInt, AsnReal, AsnOctetString)):
# Write a static label before the child
g_MyCreation.write("wxStaticText* itemStaticText_%s = new wxStaticText( %s, wxID_STATIC, _(\"%s\"), wxDefaultPosition, wxDefaultSize, 0 );\n" %
(varPrefix, ScrollWnd, txtPrefix))
......@@ -655,7 +655,7 @@ def maybeElseZero(childNo: int) -> str:
def CopyDataFromDlgToASN1(f: IO[Any], srcVar: str, destVar: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
if isinstance(node, AsnInt) or isinstance(node, AsnReal):
if isinstance(node, (AsnInt, AsnReal)):
targetType = {"INTEGER": "asn1SccSint", "REAL": "double"}[node._leafType]
f.write("if (false == StringToAny<%s>(\"%s\", _itemTextCtrl_%s->GetValue().ToAscii().release(), %s, msgError)) {\n" % (targetType, srcVar, srcVar, destVar))
f.write(" wxMessageBox(wxConvLocal.cMB2WC(msgError.c_str()), _T(\"Data input error\"), wxICON_ERROR);\n")
......@@ -727,7 +727,7 @@ def CopyDataFromASN1ToDlg(fDesc: IO[Any],
node: AsnNode,
leafTypeDict: AST_Leaftypes,
names: AST_Lookup,
bClear: bool=False) -> None:
bClear: bool = False) -> None:
if isinstance(node, AsnInt):
fDesc.write("{\n")
fDesc.write(" ostringstream s;\n")
......@@ -896,7 +896,7 @@ def WriteCodeForGnuPlot(prefix: str, node: AsnNode, subProgram: ApLevelContainer
CleanParam = CleanName(param._id)
if prefix in ("TCDATA: ", "TMDATA: "):
prefix += CleanSP + "::" + CleanParam
if isinstance(node, AsnInt) or isinstance(node, AsnReal) or isinstance(node, AsnOctetString):
if isinstance(node, (AsnInt, AsnReal, AsnOctetString)):
g_GnuplotFile.write(prefix + '\n')
elif isinstance(node, AsnBool):
pass
......@@ -988,7 +988,7 @@ def Common(nodeTypename: str,
control = "itemBoxSizer_%s" % CleanName(subProgram._id)
WriteCodeForGUIControls('', control, node, subProgram, subProgramImplementation, param, leafTypeDict, names)
global g_bBraceOpen
if len(g_SPs) == 0 or subProgram._id != g_SPs[-1]:
if not g_SPs or subProgram._id != g_SPs[-1]:
if g_bBraceOpen:
g_MyAction.write("} // %s\n" % g_SPs[-1])
g_MySave.write("} // %s\n" % g_SPs[-1])
......
......@@ -165,6 +165,9 @@ mp_float_t mp_obj_get_float(mp_obj_t self_in);
"""
# pylint: disable=unused-argument
# pylint: disable=no-self-use
class MapUPyObjData(RecursiveMapperGeneric[str, str]):
def __init__(self) -> None:
......@@ -263,7 +266,7 @@ class MapUPyObjEncode(RecursiveMapperGeneric[str, Tuple[str, str]]):
def MapInteger(self, srcVar: str, destVar: Tuple[str, str], _: AsnInt, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:
# TODO check range of integer
dest, data = destVar
dest, unused = destVar
return ['%s = mp_obj_new_int(%s);' % (dest, srcVar)]
def MapReal(self, srcVar: str, destVar: Tuple[str, str], _: AsnReal, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:
......@@ -277,7 +280,7 @@ class MapUPyObjEncode(RecursiveMapperGeneric[str, Tuple[str, str]]):
]
def MapBoolean(self, srcVar: str, destVar: Tuple[str, str], _: AsnBool, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:
dest, data = destVar
dest, unused = destVar
return ['%s = mp_obj_new_bool(%s);' % (dest, srcVar)]
def MapOctetString(self, srcVar: str, destVar: Tuple[str, str], node: AsnOctetString, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:
......@@ -297,7 +300,7 @@ class MapUPyObjEncode(RecursiveMapperGeneric[str, Tuple[str, str]]):
def MapEnumerated(self, srcVar: str, destVar: Tuple[str, str], _: AsnEnumerated, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:
# TODO check the enum value fits in a small int and use MP_OBJ_NEW_SMALL_INT
dest, data = destVar
dest, unused = destVar
return ['%s = mp_obj_new_int(%s);' % (dest, srcVar)]
def MapSequence(self, srcVar: str, destVar: Tuple[str, str], node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:
......@@ -490,9 +493,9 @@ class MicroPython_GlueGenerator(ASynchronousToolGlueGenerator):
try:
return self.neededQstrFields[fields][0]
except KeyError:
id = 'upython_qstr_fields%u' % len(self.neededQstrFields)
self.neededQstrFields[fields] = (id, fields)
return id
ide = 'upython_qstr_fields%u' % len(self.neededQstrFields)
self.neededQstrFields[fields] = (ide, fields)
return ide
def AddChoiceFields(self, choiceNode: AsnChoice, fields: List[str]) -> None:
self.choiceNodes[choiceNode] = fields
......@@ -614,8 +617,8 @@ class MicroPython_GlueGenerator(ASynchronousToolGlueGenerator):
# Generate the init function
lines = []
for id, fields in self.neededQstrFields.values():
lines.append('qstr %s[%u];' % (id, len(fields)))
for ide, fields in self.neededQstrFields.values():
lines.append('qstr %s[%u];' % (ide, len(fields)))
lines.append('')
lines.append('void mp_taste_types_init(void) {')
lines.append(' static int inited = 0;')
......@@ -623,9 +626,9 @@ class MicroPython_GlueGenerator(ASynchronousToolGlueGenerator):
lines.append(' return;')
lines.append(' }')
lines.append(' inited = 1;')
for id, fields in self.neededQstrFields.values():
for ide, fields in self.neededQstrFields.values():
for i, f in enumerate(fields):
lines.append(' %s[%u] = qstr_from_str("%s");' % (id, i, f))
lines.append(' %s[%u] = qstr_from_str("%s");' % (ide, i, f))
lines.append('}')
self.C_SourceFile.write('\n'.join(lines) + '\n\n')
......
......@@ -687,7 +687,7 @@ class OG_GlueGenerator(ASynchronousToolGlueGenerator):
fileOutHeader.write("}\n\n"