Skip to content

Commit

Permalink
ContikiMoteType: inline regexp at use site
Browse files Browse the repository at this point in the history
The section parser is OS-specific, so put
the OS data where it is used.
  • Loading branch information
pjonsson committed Sep 16, 2023
1 parent 0b281a2 commit 7a3fb30
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions java/org/contikios/cooja/contikimote/ContikiMoteType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -398,18 +398,14 @@ public Map<String, Symbol> parseSymbols(Map<String, Symbol> 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 '<SECTION>'in 'COMMAND_VAR_NAME_ADDRESS_SIZE'
*/
CommandSectionParser(String[] mapFileData, String sectionRegExp) {
CommandSectionParser(String[] mapFileData) {
this.mapFileData = mapFileData;
this.sectionRegExp = sectionRegExp;
}

@Override
Expand All @@ -421,7 +417,7 @@ public Map<String, Symbol> parseSymbols(Map<String, Symbol> inVars) {
/* Replace "<SECTION>" in regex by section specific regex */
Pattern pattern = Pattern.compile(
Cooja.getExternalToolsSetting("COMMAND_VAR_NAME_ADDRESS_SIZE")
.replace("<SECTION>", Pattern.quote(sectionRegExp)));
.replace("<SECTION>", "\\(__DATA,__(data|bss|common)\\)"));
for (String line : mapFileData) {
Matcher matcher = pattern.matcher(line);

Expand Down

0 comments on commit 7a3fb30

Please sign in to comment.