Skip to content

Commit

Permalink
tools/combine: merge equivalent 'typedef struct' declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Jun 12, 2019
1 parent 06dd355 commit 74fb255
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tools/combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ function include_sys(line, filename) {
sys_included[key] = true;
}

const declarations = {};
function declare(line) {
const key = line.replace(/\s+/g, ' ').trim();
if (declarations[key]) {
return ''; // Declared earlier.
}
declarations[key] = true;
}

let source = [];

source = source
Expand All @@ -124,7 +133,8 @@ for (let i = 0; i < files.length; i++) {

const patterns = [
{ re: /^\s*#include\s*"([^"]*)".*$/, fn: include },
{ re: /^\s*#include\s*<([^"]*)>.*$/, fn: include_sys }
{ re: /^\s*#include\s*<([^"]*)>.*$/, fn: include_sys },
{ re: /^\s*typedef\s+struct\s+\w+\s+\w+\s*;$/, fn: declare }
];

restart: for (let lno = 0; lno < source.length; ) {
Expand Down

0 comments on commit 74fb255

Please sign in to comment.