diff --git a/atcoder/all b/atcoder/all index 112458e..666568e 100644 --- a/atcoder/all +++ b/atcoder/all @@ -1,12 +1,12 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "atcoder/convolution" +#include "atcoder/dsu" +#include "atcoder/fenwicktree" +#include "atcoder/lazysegtree" +#include "atcoder/math" +#include "atcoder/maxflow" +#include "atcoder/mincostflow" +#include "atcoder/modint" +#include "atcoder/scc" +#include "atcoder/segtree" +#include "atcoder/string" +#include "atcoder/twosat" diff --git a/atcoder/convolution b/atcoder/convolution index 4668477..a768486 100644 --- a/atcoder/convolution +++ b/atcoder/convolution @@ -1 +1 @@ -#include +#include "atcoder/convolution.hpp" diff --git a/atcoder/convolution.hpp b/atcoder/convolution.hpp index 04cc20f..166e356 100644 --- a/atcoder/convolution.hpp +++ b/atcoder/convolution.hpp @@ -3,12 +3,13 @@ #include #include -#include -#include #include #include #include +#include "atcoder/internal_bit" +#include "atcoder/modint" + namespace atcoder { namespace internal { diff --git a/atcoder/dsu b/atcoder/dsu index 846e8cb..8052180 100644 --- a/atcoder/dsu +++ b/atcoder/dsu @@ -1 +1 @@ -#include +#include "atcoder/dsu.hpp" diff --git a/atcoder/fenwicktree b/atcoder/fenwicktree index f2febd1..c7371dc 100644 --- a/atcoder/fenwicktree +++ b/atcoder/fenwicktree @@ -1 +1 @@ -#include +#include "atcoder/fenwicktree.hpp" diff --git a/atcoder/fenwicktree.hpp b/atcoder/fenwicktree.hpp index 3e49e90..ab7c63b 100644 --- a/atcoder/fenwicktree.hpp +++ b/atcoder/fenwicktree.hpp @@ -1,10 +1,11 @@ #ifndef ATCODER_FENWICKTREE_HPP #define ATCODER_FENWICKTREE_HPP 1 -#include #include #include +#include "atcoder/internal_type_traits" + namespace atcoder { // Reference: https://en.wikipedia.org/wiki/Fenwick_tree diff --git a/atcoder/internal_bit b/atcoder/internal_bit index c7443cc..a24ec48 100644 --- a/atcoder/internal_bit +++ b/atcoder/internal_bit @@ -1 +1 @@ -#include +#include "atcoder/internal_bit.hpp" diff --git a/atcoder/internal_math b/atcoder/internal_math index b228a70..84042f5 100644 --- a/atcoder/internal_math +++ b/atcoder/internal_math @@ -1 +1 @@ -#include +#include "atcoder/internal_math.hpp" diff --git a/atcoder/internal_queue b/atcoder/internal_queue index 9cb49b3..36cca9d 100644 --- a/atcoder/internal_queue +++ b/atcoder/internal_queue @@ -1 +1 @@ -#include +#include "atcoder/internal_queue.hpp" diff --git a/atcoder/internal_scc b/atcoder/internal_scc index 21d8865..fd49944 100644 --- a/atcoder/internal_scc +++ b/atcoder/internal_scc @@ -1 +1 @@ -#include +#include "atcoder/internal_scc.hpp" diff --git a/atcoder/internal_type_traits b/atcoder/internal_type_traits index 87fd106..31b2695 100644 --- a/atcoder/internal_type_traits +++ b/atcoder/internal_type_traits @@ -1 +1 @@ -#include +#include "atcoder/internal_type_traits.hpp" diff --git a/atcoder/lazysegtree b/atcoder/lazysegtree index 7323e25..0f3875f 100644 --- a/atcoder/lazysegtree +++ b/atcoder/lazysegtree @@ -1 +1 @@ -#include +#include "atcoder/lazysegtree.hpp" diff --git a/atcoder/lazysegtree.hpp b/atcoder/lazysegtree.hpp index 8d23989..e9c0c63 100644 --- a/atcoder/lazysegtree.hpp +++ b/atcoder/lazysegtree.hpp @@ -2,10 +2,12 @@ #define ATCODER_LAZYSEGTREE_HPP 1 #include -#include #include #include #include + +#include "atcoder/internal_bit" + namespace atcoder { template +#include "atcoder/math.hpp" diff --git a/atcoder/math.hpp b/atcoder/math.hpp index dd68ca9..ec5bca5 100644 --- a/atcoder/math.hpp +++ b/atcoder/math.hpp @@ -5,7 +5,8 @@ #include #include #include -#include + +#include "atcoder/internal_math" namespace atcoder { diff --git a/atcoder/maxflow b/atcoder/maxflow index 64d215c..66df972 100644 --- a/atcoder/maxflow +++ b/atcoder/maxflow @@ -1 +1 @@ -#include +#include "atcoder/maxflow.hpp" diff --git a/atcoder/maxflow.hpp b/atcoder/maxflow.hpp index 6f535b9..d74cfad 100644 --- a/atcoder/maxflow.hpp +++ b/atcoder/maxflow.hpp @@ -2,12 +2,13 @@ #define ATCODER_MAXFLOW_HPP 1 #include -#include #include #include #include #include +#include "atcoder/internal_queue" + namespace atcoder { template struct mf_graph { diff --git a/atcoder/mincostflow b/atcoder/mincostflow index f6c451e..ed3ad2a 100644 --- a/atcoder/mincostflow +++ b/atcoder/mincostflow @@ -1 +1 @@ -#include +#include "atcoder/mincostflow.hpp" diff --git a/atcoder/modint b/atcoder/modint index a0dfdc3..1aeaacb 100644 --- a/atcoder/modint +++ b/atcoder/modint @@ -1 +1 @@ -#include +#include "atcoder/modint.hpp" diff --git a/atcoder/modint.hpp b/atcoder/modint.hpp index 78df9ef..a00a650 100644 --- a/atcoder/modint.hpp +++ b/atcoder/modint.hpp @@ -1,8 +1,6 @@ #ifndef ATCODER_MODINT_HPP #define ATCODER_MODINT_HPP 1 -#include -#include #include #include #include @@ -11,6 +9,9 @@ #include #endif +#include "atcoder/internal_math" +#include "atcoder/internal_type_traits" + namespace atcoder { namespace internal { diff --git a/atcoder/scc b/atcoder/scc index 6fda4bf..cdf451a 100644 --- a/atcoder/scc +++ b/atcoder/scc @@ -1 +1 @@ -#include +#include "atcoder/scc.hpp" diff --git a/atcoder/scc.hpp b/atcoder/scc.hpp index 6623b76..29e120f 100644 --- a/atcoder/scc.hpp +++ b/atcoder/scc.hpp @@ -2,10 +2,11 @@ #define ATCODER_SCC_HPP 1 #include -#include #include #include +#include "atcoder/internal_scc" + namespace atcoder { struct scc_graph { diff --git a/atcoder/segtree b/atcoder/segtree index 60a0d88..150f785 100644 --- a/atcoder/segtree +++ b/atcoder/segtree @@ -1 +1 @@ -#include +#include "atcoder/segtree.hpp" diff --git a/atcoder/segtree.hpp b/atcoder/segtree.hpp index 31e1662..789fa33 100644 --- a/atcoder/segtree.hpp +++ b/atcoder/segtree.hpp @@ -2,10 +2,11 @@ #define ATCODER_SEGTREE_HPP 1 #include -#include #include #include +#include "atcoder/internal_bit" + namespace atcoder { template struct segtree { diff --git a/atcoder/string b/atcoder/string index f4b40a1..7df6f26 100644 --- a/atcoder/string +++ b/atcoder/string @@ -1 +1 @@ -#include +#include "atcoder/string.hpp" diff --git a/atcoder/twosat b/atcoder/twosat index 324a4c8..7e83c51 100644 --- a/atcoder/twosat +++ b/atcoder/twosat @@ -1 +1 @@ -#include +#include "atcoder/twosat.hpp" diff --git a/atcoder/twosat.hpp b/atcoder/twosat.hpp index e16c443..25b9706 100644 --- a/atcoder/twosat.hpp +++ b/atcoder/twosat.hpp @@ -1,10 +1,11 @@ #ifndef ATCODER_TWOSAT_HPP #define ATCODER_TWOSAT_HPP 1 -#include #include #include +#include "atcoder/internal_scc" + namespace atcoder { // Reference: diff --git a/expander.py b/expander.py index ff41810..2f98f88 100755 --- a/expander.py +++ b/expander.py @@ -13,10 +13,12 @@ class Expander: + local_include = re.compile( + r'#include\s*"([a-z_]*(|.hpp))"\s*') atcoder_include = re.compile( - '#include\s*["<](atcoder/[a-z_]*(|.hpp))[">]\s*') + r'#include\s*["<](atcoder/[a-z_]*(|.hpp))[">]\s*') - include_guard = re.compile('#.*ATCODER_[A-Z_]*_HPP') + include_guard = re.compile(r'#.*ATCODER_[A-Z_]*_HPP') def is_ignored_line(self, line) -> bool: if self.include_guard.match(line): @@ -30,27 +32,24 @@ def is_ignored_line(self, line) -> bool: def __init__(self, lib_paths: List[Path]): self.lib_paths = lib_paths - included = set() # type: Set[str] + included = set() # type: Set[Path] - def find_acl(self, acl_name: str) -> Optional[Path]: + def find_acl(self, acl_name: str) -> Path: for lib_path in self.lib_paths: path = lib_path / acl_name if path.exists(): return path - return None + logger.error('cannot find: {}'.format(acl_name)) + raise FileNotFoundError() - def expand_acl(self, acl_name: str) -> List[str]: - if acl_name in self.included: - logger.info('already included: {}'.format(acl_name)) + def expand_acl(self, acl_file_path: Path) -> List[str]: + if acl_file_path in self.included: + logger.info('already included: {}'.format(acl_file_path.name)) return [] - self.included.add(acl_name) - logger.info('include: {}'.format(acl_name)) - acl_path = self.find_acl(acl_name) - if not acl_path: - logger.warning('cannot find: {}'.format(acl_name)) - raise FileNotFoundError() + self.included.add(acl_file_path) + logger.info('include: {}'.format(acl_file_path.name)) - acl_source = open(str(acl_path)).read() + acl_source = open(str(acl_file_path)).read() result = [] # type: List[str] for line in acl_source.splitlines(): @@ -59,7 +58,14 @@ def expand_acl(self, acl_name: str) -> List[str]: m = self.atcoder_include.match(line) if m: - result.extend(self.expand_acl(m.group(1))) + name = m.group(1) + result.extend(self.expand_acl(self.find_acl(name))) + continue + + m = self.local_include.match(line) + if m: + name = m.group(1) + result.extend(self.expand_acl(acl_file_path.parent / name)) continue result.append(line) @@ -71,10 +77,11 @@ def expand(self, source: str) -> str: result = [] # type: List[str] for line in source.splitlines(): m = self.atcoder_include.match(line) - if m: - result.extend(self.expand_acl(m.group(1))) + acl_path = self.find_acl(m.group(1)) + result.extend(self.expand_acl(acl_path)) continue + result.append(line) return '\n'.join(result) diff --git a/test/unittest/basic_test.cpp b/test/unittest/basic_test.cpp index 28a298b..777aacf 100644 --- a/test/unittest/basic_test.cpp +++ b/test/unittest/basic_test.cpp @@ -1,4 +1,5 @@ -#include +#include "atcoder/all" + #include #include diff --git a/test/unittest/bit_test.cpp b/test/unittest/bit_test.cpp index 802e013..18e38f4 100644 --- a/test/unittest/bit_test.cpp +++ b/test/unittest/bit_test.cpp @@ -1,4 +1,5 @@ -#include +#include "atcoder/internal_bit" + #include #include diff --git a/test/unittest/convolution_test.cpp b/test/unittest/convolution_test.cpp index 90cc480..cf8f55a 100644 --- a/test/unittest/convolution_test.cpp +++ b/test/unittest/convolution_test.cpp @@ -1,5 +1,6 @@ -#include -#include +#include "atcoder/convolution" +#include "atcoder/modint" + #include #include "../utils/random.hpp" diff --git a/test/unittest/dsu_test.cpp b/test/unittest/dsu_test.cpp index 1797b2d..cca95e3 100644 --- a/test/unittest/dsu_test.cpp +++ b/test/unittest/dsu_test.cpp @@ -1,4 +1,5 @@ -#include +#include "atcoder/dsu" + #include #include diff --git a/test/unittest/fenwicktree_test.cpp b/test/unittest/fenwicktree_test.cpp index e00a331..17ffc78 100644 --- a/test/unittest/fenwicktree_test.cpp +++ b/test/unittest/fenwicktree_test.cpp @@ -1,5 +1,6 @@ -#include -#include +#include "atcoder/fenwicktree" +#include "atcoder/modint" + #include #include diff --git a/test/unittest/internal_math_test.cpp b/test/unittest/internal_math_test.cpp index 014847b..7e26406 100644 --- a/test/unittest/internal_math_test.cpp +++ b/test/unittest/internal_math_test.cpp @@ -1,8 +1,9 @@ -#include -#include +#include "atcoder/internal_math" + #include "../utils/math.hpp" -#include +#include +#include using namespace atcoder; using uint = unsigned int; diff --git a/test/unittest/lazysegtree_stress_test.cpp b/test/unittest/lazysegtree_stress_test.cpp index 8da3a52..f45ffec 100644 --- a/test/unittest/lazysegtree_stress_test.cpp +++ b/test/unittest/lazysegtree_stress_test.cpp @@ -1,6 +1,8 @@ -#include -#include +#include "atcoder/lazysegtree" + #include "../utils/random.hpp" + +#include #include #include diff --git a/test/unittest/lazysegtree_test.cpp b/test/unittest/lazysegtree_test.cpp index ff2d7e0..d408a6b 100644 --- a/test/unittest/lazysegtree_test.cpp +++ b/test/unittest/lazysegtree_test.cpp @@ -1,5 +1,6 @@ +#include "atcoder/lazysegtree" + #include -#include #include #include diff --git a/test/unittest/math_test.cpp b/test/unittest/math_test.cpp index e211c79..c2d80a9 100644 --- a/test/unittest/math_test.cpp +++ b/test/unittest/math_test.cpp @@ -1,4 +1,5 @@ -#include +#include "atcoder/math" + #include #include diff --git a/test/unittest/maxflow_test.cpp b/test/unittest/maxflow_test.cpp index 44c1574..dbdf5b6 100644 --- a/test/unittest/maxflow_test.cpp +++ b/test/unittest/maxflow_test.cpp @@ -1,8 +1,9 @@ -#include +#include "atcoder/maxflow" +#include "../utils/random.hpp" + #include #include #include -#include "../utils/random.hpp" #include diff --git a/test/unittest/mincostflow_test.cpp b/test/unittest/mincostflow_test.cpp index 293b4ec..6db41cb 100644 --- a/test/unittest/mincostflow_test.cpp +++ b/test/unittest/mincostflow_test.cpp @@ -1,10 +1,11 @@ -#include -#include +#include "atcoder/maxflow" +#include "atcoder/mincostflow" + +#include "../utils/random.hpp" #include #include #include -#include "../utils/random.hpp" #include diff --git a/test/unittest/modint_test.cpp b/test/unittest/modint_test.cpp index 9229eeb..81f33cc 100644 --- a/test/unittest/modint_test.cpp +++ b/test/unittest/modint_test.cpp @@ -1,4 +1,5 @@ -#include +#include "atcoder/modint" + #include #include diff --git a/test/unittest/scc_test.cpp b/test/unittest/scc_test.cpp index 4124a73..50b7cc8 100644 --- a/test/unittest/scc_test.cpp +++ b/test/unittest/scc_test.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "atcoder/scc" +#include "atcoder/modint" #include #include diff --git a/test/unittest/segtree_test.cpp b/test/unittest/segtree_test.cpp index e95ae6a..0f49e1c 100644 --- a/test/unittest/segtree_test.cpp +++ b/test/unittest/segtree_test.cpp @@ -1,4 +1,5 @@ -#include +#include "atcoder/segtree" + #include #include diff --git a/test/unittest/string_test.cpp b/test/unittest/string_test.cpp index c7ead7c..037f817 100644 --- a/test/unittest/string_test.cpp +++ b/test/unittest/string_test.cpp @@ -1,5 +1,6 @@ +#include "atcoder/string" + #include -#include #include #include diff --git a/test/unittest/twosat_test.cpp b/test/unittest/twosat_test.cpp index cbf5b68..0122554 100644 --- a/test/unittest/twosat_test.cpp +++ b/test/unittest/twosat_test.cpp @@ -1,4 +1,5 @@ -#include +#include "atcoder/twosat" + #include #include "../utils/random.hpp" diff --git a/test/unittest/type_traits_test.cpp b/test/unittest/type_traits_test.cpp index 15ce726..aa4ca67 100644 --- a/test/unittest/type_traits_test.cpp +++ b/test/unittest/type_traits_test.cpp @@ -1,4 +1,5 @@ -#include +#include "atcoder/internal_type_traits" + #include #include