mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-04 03:02:05 +01:00
put audit --fix includes in the fragment, not the purview
The inserter aimed at the spot before the first import, which in a module unit is past the module declaration - so the includes landed in the purview, attaching those declarations to the module, and re-running piled up duplicates. It now targets the global module fragment for module units and keeps the before-first-import rule only for ordinary units.
This commit is contained in:
@@ -1,4 +1,16 @@
|
|||||||
module;
|
module;
|
||||||
|
#include <array>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <deque>
|
||||||
|
#include <limits>
|
||||||
|
#include <mutex>
|
||||||
|
#include <ostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
#include "winheaders.h" // HINSTANCE
|
#include "winheaders.h" // HINSTANCE
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,19 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
module;
|
module;
|
||||||
|
#include <array>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <deque>
|
||||||
|
#include <limits>
|
||||||
|
#include <mutex>
|
||||||
|
#include <ostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
export module eu07.console.lpt;
|
export module eu07.console.lpt;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,16 @@
|
|||||||
module;
|
module;
|
||||||
|
#include <array>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <deque>
|
||||||
|
#include <limits>
|
||||||
|
#include <mutex>
|
||||||
|
#include <ostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
#include "winheaders.h" // HANDLE; setupapi.h happens to pull it in, but say so
|
#include "winheaders.h" // HANDLE; setupapi.h happens to pull it in, but say so
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
@@ -9,6 +9,18 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
module;
|
module;
|
||||||
|
#include <array>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <deque>
|
||||||
|
#include <limits>
|
||||||
|
#include <mutex>
|
||||||
|
#include <ostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
export module eu07.console.pokeys55;
|
export module eu07.console.pokeys55;
|
||||||
|
|||||||
@@ -151,7 +151,26 @@ def template_bodies(purview):
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
def insert_point(src):
|
def insert_includes(src):
|
||||||
|
"""Where a new #include belongs.
|
||||||
|
|
||||||
|
In a module unit that is the global module fragment - after `module;` and
|
||||||
|
before the module declaration. Putting it after the declaration would place
|
||||||
|
the include in the purview, attaching those declarations to the module.
|
||||||
|
In an ordinary translation unit it is the top level of the preprocessor,
|
||||||
|
before the first import, never inside a #define's continuation.
|
||||||
|
"""
|
||||||
|
decl = MODULE_DECL.search(src)
|
||||||
|
if decl:
|
||||||
|
g = re.search(r'^module;[ \t]*\n', src, re.M)
|
||||||
|
if g:
|
||||||
|
return src[:g.end()], src[g.end():]
|
||||||
|
return src[:decl.start()] + 'module;\n', '\n' + src[decl.start():]
|
||||||
|
lines, at = _plain_insert_point(src)
|
||||||
|
return '\n'.join(lines[:at]) + ('\n' if at else ''), '\n'.join(lines[at:])
|
||||||
|
|
||||||
|
|
||||||
|
def _plain_insert_point(src):
|
||||||
"""Top level of the preprocessor, before the first import, never inside a
|
"""Top level of the preprocessor, before the first import, never inside a
|
||||||
#define's continuation."""
|
#define's continuation."""
|
||||||
depth, last_include, first_import, i = 0, None, None, 0
|
depth, last_include, first_import, i = 0, None, None, 0
|
||||||
@@ -325,17 +344,19 @@ def main():
|
|||||||
print(' ... i %d wiecej' % (len(v) - 12))
|
print(' ... i %d wiecej' % (len(v) - 12))
|
||||||
|
|
||||||
if fix and edits:
|
if fix and edits:
|
||||||
|
touched = 0
|
||||||
for p, (need, bom) in edits.items():
|
for p, (need, bom) in edits.items():
|
||||||
src, _ = read(p)
|
src, _ = read(p)
|
||||||
lines, at = insert_point(src)
|
|
||||||
gmf = split_unit(src)[0]
|
gmf = split_unit(src)[0]
|
||||||
add = ['#include <%s>' % h for h in need if '<%s>' % h not in gmf]
|
add = ''.join('#include <%s>\n' % h for h in need
|
||||||
|
if '<%s>' % h not in gmf)
|
||||||
if not add:
|
if not add:
|
||||||
continue
|
continue
|
||||||
lines[at:at] = add
|
head, tail = insert_includes(src)
|
||||||
open(p, 'w', encoding='utf-8').write(
|
open(p, 'w', encoding='utf-8').write(
|
||||||
('' if bom else '') + '\n'.join(lines))
|
('' if bom else '') + head + add + tail)
|
||||||
print('\nnaprawiono %d plikow' % len(edits))
|
touched += 1
|
||||||
|
print('\nnaprawiono %d plikow' % touched)
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user