mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Allow internal macros without prefix
Internal macros are not present as symbols, visible or usable outside the compilation unit and it is safe to allow them to have a name without namespace prefix. We also allow them to start with lower case letters as some of our internal macros already have names like that. Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
@ -58,8 +58,9 @@ import logging
|
|||||||
|
|
||||||
# Naming patterns to check against. These are defined outside the NameCheck
|
# Naming patterns to check against. These are defined outside the NameCheck
|
||||||
# class for ease of modification.
|
# class for ease of modification.
|
||||||
MACRO_PATTERN = r"^(MBEDTLS|PSA)_[0-9A-Z_]*[0-9A-Z]$"
|
PUBLIC_MACRO_PATTERN = r"^(MBEDTLS|PSA)_[0-9A-Z_]*[0-9A-Z]$"
|
||||||
CONSTANTS_PATTERN = MACRO_PATTERN
|
INTERNAL_MACRO_PATTERN = r"^[0-9A-Za-z_]*[0-9A-Z]$"
|
||||||
|
CONSTANTS_PATTERN = PUBLIC_MACRO_PATTERN
|
||||||
IDENTIFIER_PATTERN = r"^(mbedtls|psa)_[0-9a-z_]*[0-9a-z]$"
|
IDENTIFIER_PATTERN = r"^(mbedtls|psa)_[0-9a-z_]*[0-9a-z]$"
|
||||||
|
|
||||||
class Match(): # pylint: disable=too-few-public-methods
|
class Match(): # pylint: disable=too-few-public-methods
|
||||||
@ -249,14 +250,17 @@ class CodeParser():
|
|||||||
.format(str(self.excluded_files))
|
.format(str(self.excluded_files))
|
||||||
)
|
)
|
||||||
|
|
||||||
all_macros = self.parse_macros([
|
all_macros = {"public": [], "internal": []}
|
||||||
|
all_macros["public"] = self.parse_macros([
|
||||||
"include/mbedtls/*.h",
|
"include/mbedtls/*.h",
|
||||||
"include/psa/*.h",
|
"include/psa/*.h",
|
||||||
"library/*.h",
|
|
||||||
"tests/include/test/drivers/*.h",
|
|
||||||
"3rdparty/everest/include/everest/everest.h",
|
"3rdparty/everest/include/everest/everest.h",
|
||||||
"3rdparty/everest/include/everest/x25519.h"
|
"3rdparty/everest/include/everest/x25519.h"
|
||||||
])
|
])
|
||||||
|
all_macros["internal"] = self.parse_macros([
|
||||||
|
"library/*.h",
|
||||||
|
"tests/include/test/drivers/*.h",
|
||||||
|
])
|
||||||
enum_consts = self.parse_enum_consts([
|
enum_consts = self.parse_enum_consts([
|
||||||
"include/mbedtls/*.h",
|
"include/mbedtls/*.h",
|
||||||
"library/*.h",
|
"library/*.h",
|
||||||
@ -284,20 +288,25 @@ class CodeParser():
|
|||||||
|
|
||||||
# Remove identifier macros like mbedtls_printf or mbedtls_calloc
|
# Remove identifier macros like mbedtls_printf or mbedtls_calloc
|
||||||
identifiers_justname = [x.name for x in identifiers]
|
identifiers_justname = [x.name for x in identifiers]
|
||||||
actual_macros = []
|
actual_macros = {"public": [], "internal": []}
|
||||||
for macro in all_macros:
|
for scope in actual_macros:
|
||||||
|
for macro in all_macros[scope]:
|
||||||
if macro.name not in identifiers_justname:
|
if macro.name not in identifiers_justname:
|
||||||
actual_macros.append(macro)
|
actual_macros[scope].append(macro)
|
||||||
|
|
||||||
self.log.debug("Found:")
|
self.log.debug("Found:")
|
||||||
# Aligns the counts on the assumption that none exceeds 4 digits
|
# Aligns the counts on the assumption that none exceeds 4 digits
|
||||||
self.log.debug(" {:4} Total Macros".format(len(all_macros)))
|
for scope in actual_macros:
|
||||||
self.log.debug(" {:4} Non-identifier Macros".format(len(actual_macros)))
|
self.log.debug(" {:4} Total {} Macros"
|
||||||
|
.format(len(all_macros[scope]), scope))
|
||||||
|
self.log.debug(" {:4} {} Non-identifier Macros"
|
||||||
|
.format(len(actual_macros[scope]), scope))
|
||||||
self.log.debug(" {:4} Enum Constants".format(len(enum_consts)))
|
self.log.debug(" {:4} Enum Constants".format(len(enum_consts)))
|
||||||
self.log.debug(" {:4} Identifiers".format(len(identifiers)))
|
self.log.debug(" {:4} Identifiers".format(len(identifiers)))
|
||||||
self.log.debug(" {:4} Exported Symbols".format(len(symbols)))
|
self.log.debug(" {:4} Exported Symbols".format(len(symbols)))
|
||||||
return {
|
return {
|
||||||
"macros": actual_macros,
|
"public_macros": actual_macros["public"],
|
||||||
|
"internal_macros": actual_macros["internal"],
|
||||||
"enum_consts": enum_consts,
|
"enum_consts": enum_consts,
|
||||||
"identifiers": identifiers,
|
"identifiers": identifiers,
|
||||||
"symbols": symbols,
|
"symbols": symbols,
|
||||||
@ -741,7 +750,8 @@ class NameChecker():
|
|||||||
problems += self.check_symbols_declared_in_header()
|
problems += self.check_symbols_declared_in_header()
|
||||||
|
|
||||||
pattern_checks = [
|
pattern_checks = [
|
||||||
("macros", MACRO_PATTERN),
|
("public_macros", PUBLIC_MACRO_PATTERN),
|
||||||
|
("internal_macros", INTERNAL_MACRO_PATTERN),
|
||||||
("enum_consts", CONSTANTS_PATTERN),
|
("enum_consts", CONSTANTS_PATTERN),
|
||||||
("identifiers", IDENTIFIER_PATTERN)
|
("identifiers", IDENTIFIER_PATTERN)
|
||||||
]
|
]
|
||||||
@ -825,7 +835,10 @@ class NameChecker():
|
|||||||
all_caps_names = {
|
all_caps_names = {
|
||||||
match.name
|
match.name
|
||||||
for match
|
for match
|
||||||
in self.parse_result["macros"] + self.parse_result["enum_consts"]}
|
in self.parse_result["public_macros"] +
|
||||||
|
self.parse_result["internal_macros"] +
|
||||||
|
self.parse_result["enum_consts"]
|
||||||
|
}
|
||||||
typo_exclusion = re.compile(r"XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$|"
|
typo_exclusion = re.compile(r"XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$|"
|
||||||
r"MBEDTLS_TEST_LIBTESTDRIVER*")
|
r"MBEDTLS_TEST_LIBTESTDRIVER*")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user