From 7a3fb30df64bd5a914f7ae150ad4d582df26c9a9 Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Sat, 16 Sep 2023 10:20:02 +0200 Subject: [PATCH] ContikiMoteType: inline regexp at use site The section parser is OS-specific, so put the OS data where it is used. --- .../cooja/contikimote/ContikiMoteType.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/java/org/contikios/cooja/contikimote/ContikiMoteType.java b/java/org/contikios/cooja/contikimote/ContikiMoteType.java index e023482e0..113b14860 100644 --- a/java/org/contikios/cooja/contikimote/ContikiMoteType.java +++ b/java/org/contikios/cooja/contikimote/ContikiMoteType.java @@ -262,9 +262,9 @@ public boolean loadMoteFirmware(boolean vis) throws MoteTypeCreationException { if (useCommand) { String[] output = loadCommandData(command, firmwareFile, vis); - dataSecParser = new CommandSectionParser(output, "(__DATA,__data)"); - bssSecParser = new CommandSectionParser(output, "(__DATA,__bss)"); - commonSecParser = new CommandSectionParser(output, "(__DATA,__common)"); + dataSecParser = new CommandSectionParser(output); + bssSecParser = new CommandSectionParser(output); + commonSecParser = new CommandSectionParser(output); } else { var symbols = String.join("\n", loadCommandData(command, firmwareFile, vis)); dataSecParser = new MapSectionParser(symbols); @@ -398,18 +398,14 @@ public Map parseSymbols(Map inVars) { */ private static class CommandSectionParser implements SectionParser { private final String[] mapFileData; - private final String sectionRegExp; /** * Creates SectionParser based on output of configurable command. * * @param mapFileData Map file lines as array of String - * @param sectionRegExp Regular expression describing symbol table section identifier (e.g. '[Rr]' for readonly) - * Will be used to replaced '
'in 'COMMAND_VAR_NAME_ADDRESS_SIZE' */ - CommandSectionParser(String[] mapFileData, String sectionRegExp) { + CommandSectionParser(String[] mapFileData) { this.mapFileData = mapFileData; - this.sectionRegExp = sectionRegExp; } @Override @@ -421,7 +417,7 @@ public Map parseSymbols(Map inVars) { /* Replace "
" in regex by section specific regex */ Pattern pattern = Pattern.compile( Cooja.getExternalToolsSetting("COMMAND_VAR_NAME_ADDRESS_SIZE") - .replace("
", Pattern.quote(sectionRegExp))); + .replace("
", "\\(__DATA,__(data|bss|common)\\)")); for (String line : mapFileData) { Matcher matcher = pattern.matcher(line);