aboutsummaryrefslogtreecommitdiffstats
path: root/asn1
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2022-11-11 17:09:51 +0100
committerOliver Smith <osmith@sysmocom.de>2022-11-15 11:16:38 +0100
commit1d19c8e21ecd79a1e8250aa481cf66b25641008d (patch)
tree3ee8019061201e1dea3da132ca5cfa8cce0366a7 /asn1
parent8d3f18888bf75a0ab4ed8aa2215610bde7cbc56a (diff)
asn1tostruct: fix defines getting redefined
Do not write the same define twice for two files in a struct, e.g.: #define ENHANCEDRELOCATIONCOMPLETEREQUESTIES_RANAP_EXTENDEDRNC_ID_PRESENT (1 << 0) #define ENHANCEDRELOCATIONCOMPLETEREQUESTIES_RANAP_EXTENDEDRNC_ID_PRESENT (1 << 1) #define ENHANCEDRELOCATIONCOMPLETEREQUESTIES_RANAP_RAB_SETUPLIST_ENHANCEDRELOCCOMPLETEREQ_PRESENT (1 << 2) typedef struct RANAP_EnhancedRelocationCompleteRequestIEs_s { uint16_t presenceMask; RANAP_IuSignallingConnectionIdentifier_t oldIuSigConId; RANAP_IuSignallingConnectionIdentifier_t iuSigConId; RANAP_GlobalRNC_ID_t relocation_SourceRNC_ID; RANAP_ExtendedRNC_ID_t relocation_SourceExtendedRNC_ID; ///< Optional field RANAP_GlobalRNC_ID_t relocation_TargetRNC_ID; RANAP_ExtendedRNC_ID_t relocation_TargetExtendedRNC_ID; ///< Optional field RANAP_RAB_SetupList_EnhancedRelocCompleteReq_t raB_SetupList_EnhancedRelocCompleteReq; ///< Optional field } RANAP_EnhancedRelocationCompleteRequestIEs_t; The problem is that the type is used and it may not be unique inside a struct. Change the code to use the name of the field if the type is not unique. Keep using the type otherwise so existing code doesn't need to be modified a lot to fix this. Fix for: ../include/osmocom/ranap/ranap_ies_defs.h:514: warning: "RANAP_ENHANCEDRELOCATIONINFORMATIONREQUESTIES_RANAP_IUSIGNALLINGCONNECTIONIDENTIFIER_PRESENT" redefined Change-Id: I2ecae6789899952d1dc5691ab76907abeaa71c12
Diffstat (limited to 'asn1')
-rwxr-xr-xasn1/utils/asn1tostruct.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/asn1/utils/asn1tostruct.py b/asn1/utils/asn1tostruct.py
index 220517d..d71d87d 100755
--- a/asn1/utils/asn1tostruct.py
+++ b/asn1/utils/asn1tostruct.py
@@ -79,6 +79,29 @@ def usage():
print("-p [pfx] Prefix all types with given prefix")
print("-h Print this help and return")
+def getUniqueIENameForDefine(ies, ie):
+ """ Usually the type of the IE is used for defines. However a struct may
+ use the same type multiple times, in that case we use the actual name
+ of the field. """
+ unique = True
+
+ for ie_other in ies:
+ if ie_other == ie:
+ continue
+ if ie_other[2] == ie[2]:
+ unique = False
+ assert ie[0] != ie_other[0], "failed to find a unique name for" \
+ f" IE {ie}. Found another entry in ies {ie_other}" \
+ " that has the same ie[0] value."
+
+ if unique:
+ ret = ie[2]
+ else:
+ ret = ie[0]
+
+ ret = re.sub('-', '_', ret.upper())
+ return ret
+
try:
opts, args = getopt.getopt(sys.argv[1:], "df:ho:p:", ["debug", "file", "help", "outdir", "prefix"])
except getopt.GetoptError as err:
@@ -167,7 +190,7 @@ for key in iesDefs:
# Presence mask
for ie in iesDefs[key]["ies"]:
- ieupperunderscore = re.sub('-', '_', ie[2].upper())
+ ieupperunderscore = getUniqueIENameForDefine(iesDefs[key]["ies"], ie)
if ie[3] == "optional" or ie[3] == "conditional":
f.write("#define {0:<{pad}} {1}\n".format("%s_%s%s_PRESENT" % (keyupperunderscore, prefix, ieupperunderscore), "(1 << %d)" % shift,
pad=iesDefs[key]["length"] + len(keyupperunderscore) + 9))
@@ -328,7 +351,7 @@ for key in iesDefs:
ienameunderscorefirstlower = lowerFirstCamelWord(ienameunderscore)
ietypesubst = prefix + re.sub('-', '', ie[2])
ietypeunderscore = prefix + re.sub('-', '_', ie[2])
- ieupperunderscore = prefix + re.sub('-', '_', ie[2]).upper()
+ ieupperunderscore = prefix + getUniqueIENameForDefine(iesDefs[key]["ies"], ie)
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
@@ -377,7 +400,7 @@ for key in iesDefs:
for ie in iesDefs[key]["ies"]:
ietypeunderscore = prefix + re.sub('-', '_', ie[2])
- ieupperunderscore = prefix + re.sub('-', '_', ie[2]).upper()
+ ieupperunderscore = prefix + getUniqueIENameForDefine(iesDefs[key]["ies"], ie)
if ie[3] != "mandatory":
if ie[3] == "optional":
f.write(" /* Optional field */\n")
@@ -471,7 +494,7 @@ for key in iesDefs:
iename = re.sub('-', '_', re.sub('id-', '', ie[0]))
ienameunderscore = prefix + re.sub('-', '_', iename)
ienamefirstwordlower = lowerFirstCamelWord(iename)
- ieupperunderscore = prefix + re.sub('-', '_', ie[2]).upper()
+ ieupperunderscore = prefix + getUniqueIENameForDefine(iesDefs[key]["ies"], ie)
ietypeunderscore = prefix + re.sub('-', '_', ie[2])
if ie[3] != "mandatory":
if ie[3] == "optional":