fix comments

This commit is contained in:
bolero-MURAKAMI 2016-04-05 18:21:13 +09:00
parent a0060119ab
commit 8dc640a6e2
23 changed files with 136 additions and 134 deletions

View file

@ -23,8 +23,8 @@
// //
// PE関連の構造体 // PE structs
// <windows.h> からコピペ // Copy an Paste from <windows.h>
// //
typedef unsigned long DWORD; typedef unsigned long DWORD;
typedef int BOOL; typedef int BOOL;
@ -133,21 +133,21 @@ typedef struct _IMAGE_SECTION_HEADER {
// //
// 出力バイナリサイズ // binary size for output
// //
#ifndef BRAINFUCK_BINARY_SIZE #ifndef BRAINFUCK_BINARY_SIZE
# define BRAINFUCK_BINARY_SIZE (16 * 1024) # define BRAINFUCK_BINARY_SIZE (16 * 1024)
#endif #endif
// //
// ループ制限 // loop limit
// //
#ifndef BRAINFUCK_LOOP_LIMIT #ifndef BRAINFUCK_LOOP_LIMIT
# define BRAINFUCK_LOOP_LIMIT 256 # define BRAINFUCK_LOOP_LIMIT 256
#endif #endif
// //
// 入力ファイル名 // source file name
// //
#ifndef BRAINFUCK_SOURCE_FILE #ifndef BRAINFUCK_SOURCE_FILE
# define BRAINFUCK_SOURCE_FILE a.bf # define BRAINFUCK_SOURCE_FILE a.bf
@ -155,7 +155,7 @@ typedef struct _IMAGE_SECTION_HEADER {
// //
// 定数 // constants
// //
SPROUT_STATIC_CONSTEXPR std::size_t bin_size = BRAINFUCK_BINARY_SIZE; SPROUT_STATIC_CONSTEXPR std::size_t bin_size = BRAINFUCK_BINARY_SIZE;
@ -171,7 +171,7 @@ SPROUT_STATIC_CONSTEXPR std::int32_t addr_buf = 0x00406000;
// //
// 出力用関数 // output functions
// //
template<typename OutputIterator, typename T> template<typename OutputIterator, typename T>
SPROUT_CXX14_CONSTEXPR std::size_t SPROUT_CXX14_CONSTEXPR std::size_t
@ -384,7 +384,7 @@ write_idata(OutputIterator& out, std::size_t n = 0) {
SPROUT_CONSTEXPR int idt[] = { SPROUT_CONSTEXPR int idt[] = {
// IDT 1 // IDT 1
0x5028, 0, 0, 0x5034, 0x5044, 0x5028, 0, 0, 0x5034, 0x5044,
// IDT (終端) // IDT (end)
0, 0, 0, 0, 0 0, 0, 0, 0, 0
}; };
n += ::write_bytes( n += ::write_bytes(
@ -429,12 +429,12 @@ write_idata(OutputIterator& out, std::size_t n = 0) {
} }
// //
// コンパイル // compile
// //
template<std::size_t LoopLimit = 256, typename InputIterator, typename RandomAccessIterator> template<std::size_t LoopLimit = 256, typename InputIterator, typename RandomAccessIterator>
SPROUT_CXX14_CONSTEXPR std::size_t SPROUT_CXX14_CONSTEXPR std::size_t
compile(InputIterator first, InputIterator last, RandomAccessIterator& out_first) { compile(InputIterator first, InputIterator last, RandomAccessIterator& out_first) {
sprout::array<int, LoopLimit> loops {{}}; // ループを保存するスタック sprout::array<int, LoopLimit> loops {{}}; // loop stack
auto loop_first = sprout::begin(loops); auto loop_first = sprout::begin(loops);
auto loop_last = sprout::end(loops); auto loop_last = sprout::end(loops);
auto loop = loop_first; auto loop = loop_first;
@ -499,12 +499,12 @@ compile(InputIterator first, InputIterator last, RandomAccessIterator& out_first
break; break;
case '[': case '[':
SPROUT_ASSERT_MSG(loop != loop_last, "loop overflow"); SPROUT_ASSERT_MSG(loop != loop_last, "loop overflow");
*loop++ = idx; // インデックスをスタックに積む *loop++ = idx; // push index to stack
idx += ::write_bytes( idx += ::write_bytes(
out, out,
(unsigned char)0x80, (unsigned char)0x3c, (unsigned char)0x0f, (unsigned char)0x00, // cmp byte [edi+ecx],0 (unsigned char)0x80, (unsigned char)0x3c, (unsigned char)0x0f, (unsigned char)0x00, // cmp byte [edi+ecx],0
(unsigned char)0x0f, (unsigned char)0x84, // jz 対応する]の直後 (unsigned char)0x0f, (unsigned char)0x84, // jz (immediately after corresponding ']')
(unsigned char)0xde, (unsigned char)0xad, (unsigned char)0xbe, (unsigned char)0xef // (アドレスは後で決定) (unsigned char)0xde, (unsigned char)0xad, (unsigned char)0xbe, (unsigned char)0xef // (set address later)
); );
break; break;
case ']': case ']':
@ -518,7 +518,7 @@ compile(InputIterator first, InputIterator last, RandomAccessIterator& out_first
auto out_loop = out_first + (idx_loop + 6); auto out_loop = out_first + (idx_loop + 6);
::write_bytes( ::write_bytes(
out_loop, out_loop,
(std::int32_t)(idx - (idx_loop + 10)) // (アドレス) (std::int32_t)(idx - (idx_loop + 10)) // (address)
); );
break; break;
} }
@ -528,7 +528,7 @@ compile(InputIterator first, InputIterator last, RandomAccessIterator& out_first
SPROUT_ASSERT_MSG(loop == loop_first, "missing ']'"); SPROUT_ASSERT_MSG(loop == loop_first, "missing ']'");
// 終了処理 // end
idx += ::write_bytes( idx += ::write_bytes(
out, out,
(unsigned char)0x5f, // pop edi (unsigned char)0x5f, // pop edi
@ -540,15 +540,15 @@ compile(InputIterator first, InputIterator last, RandomAccessIterator& out_first
} }
// //
// ビルド // build
// //
template<std::size_t LoopLimit = 256, typename InputIterator, typename RandomAccessIterator> template<std::size_t LoopLimit = 256, typename InputIterator, typename RandomAccessIterator>
SPROUT_CXX14_CONSTEXPR std::size_t SPROUT_CXX14_CONSTEXPR std::size_t
build(InputIterator first, InputIterator last, RandomAccessIterator& out) { build(InputIterator first, InputIterator last, RandomAccessIterator& out) {
std::size_t n = 0; std::size_t n = 0;
n += ::write_pe_header(out, n); // ヘッダ出力 n += ::write_pe_header(out, n); // header
n += ::write_idata(out, n); // .idataセクション出力 n += ::write_idata(out, n); // .idata section
n += ::compile<LoopLimit>(first, last, out); // コンパイル n += ::compile<LoopLimit>(first, last, out); // compile
return n; return n;
} }

View file

@ -186,7 +186,7 @@ void SPROUT_NON_CONSTEXPR print_board(Container const& board) {
int main() { int main() {
typedef sprout::array<sprout::array<int, BOARD_WIDTH>, BOARD_HEIGHT> board_type; typedef sprout::array<sprout::array<int, BOARD_WIDTH>, BOARD_HEIGHT> board_type;
// セルの初期配置 // cell initial placement
#define _ 0 #define _ 0
#define X 1 #define X 1
SPROUT_STATIC_CONSTEXPR board_type board0 SPROUT_STATIC_CONSTEXPR board_type board0
@ -211,10 +211,10 @@ int main() {
#undef _ #undef _
#undef X #undef X
// ライフゲームの実行 // execute life game
SPROUT_STATIC_CONSTEXPR auto boards = ::next_cells<BOARD_COUNT>(board0); SPROUT_STATIC_CONSTEXPR auto boards = ::next_cells<BOARD_COUNT>(board0);
// 表示 // print
for (auto&& board : boards) { for (auto&& board : boards) {
::print_board(board); ::print_board(board);
} }

View file

@ -27,33 +27,33 @@ public:
private: private:
struct worker { struct worker {
public: public:
// 入力 // in
sprout::array<value_type, In + 1> xi1; sprout::array<value_type, In + 1> xi1;
sprout::array<value_type, Hid + 1> xi2; sprout::array<value_type, Hid + 1> xi2;
sprout::array<value_type, Out> xi3; sprout::array<value_type, Out> xi3;
// 出力 // out
sprout::array<value_type, In + 1> o1; sprout::array<value_type, In + 1> o1;
sprout::array<value_type, Hid + 1> o2; sprout::array<value_type, Hid + 1> o2;
sprout::array<value_type, Out> o3; sprout::array<value_type, Out> o3;
}; };
private: private:
// 誤差 // error
sprout::array<value_type, Hid + 1> d2; sprout::array<value_type, Hid + 1> d2;
sprout::array<value_type, Out> d3; sprout::array<value_type, Out> d3;
// 重み // weight
sprout::array<value_type, (In + 1) * Hid> w1; sprout::array<value_type, (In + 1) * Hid> w1;
sprout::array<value_type, (Hid + 1) * Out> w2; sprout::array<value_type, (Hid + 1) * Out> w2;
private: private:
// 順伝播 // forward propagation
template<typename ForwardIterator> template<typename ForwardIterator>
SPROUT_CXX14_CONSTEXPR void SPROUT_CXX14_CONSTEXPR void
forward_propagation(ForwardIterator in_first, ForwardIterator in_last, worker& work) const { forward_propagation(ForwardIterator in_first, ForwardIterator in_last, worker& work) const {
// 入力層の順伝播 // forward propagation with input layer
sprout::copy(in_first, in_last, sprout::begin(work.xi1)); sprout::copy(in_first, in_last, sprout::begin(work.xi1));
work.xi1[In] = 1; work.xi1[In] = 1;
sprout::copy(sprout::begin(work.xi1), sprout::end(work.xi1), sprout::begin(work.o1)); sprout::copy(sprout::begin(work.xi1), sprout::end(work.xi1), sprout::begin(work.o1));
// 隠れ層の順伝播 // forward propagation with hidden layer
for (std::size_t i = 0; i != Hid; ++i) { for (std::size_t i = 0; i != Hid; ++i) {
work.xi2[i] = 0; work.xi2[i] = 0;
for (std::size_t j = 0; j != In + 1; ++j) { for (std::size_t j = 0; j != In + 1; ++j) {
@ -63,7 +63,7 @@ private:
} }
work.o2[Hid] = 1; work.o2[Hid] = 1;
// 出力層の順伝播 // forward propagation with output layer
for (std::size_t i = 0; i != Hid; ++i) { for (std::size_t i = 0; i != Hid; ++i) {
work.xi3[i] = 0; work.xi3[i] = 0;
for (std::size_t j = 0; j != In + 1; ++j) { for (std::size_t j = 0; j != In + 1; ++j) {
@ -80,9 +80,9 @@ public:
, w2(sprout::random::generate_array<(Hid + 1) * Out>(rng, sprout::random::uniform_01<value_type>())) , w2(sprout::random::generate_array<(Hid + 1) * Out>(rng, sprout::random::uniform_01<value_type>()))
{} {}
// ニューラルネットの訓練 // training of neural network
// [in_first, in_last) : 訓練データ (N*In 個) // [in_first, in_last) : training data (N*In elements)
// [t_first, t_last) : 教師データ (N 個) // [t_first, t_last) : training data (N elements)
template<typename ForwardIterator1, typename ForwardIterator2> template<typename ForwardIterator1, typename ForwardIterator2>
SPROUT_CXX14_CONSTEXPR void SPROUT_CXX14_CONSTEXPR void
train( train(
@ -99,24 +99,24 @@ public:
ForwardIterator1 in_it = in_first; ForwardIterator1 in_it = in_first;
ForwardIterator2 t_it = t_first; ForwardIterator2 t_it = t_first;
for (; in_it != in_last; sprout::advance(in_it, In), ++t_it) { for (; in_it != in_last; sprout::advance(in_it, In), ++t_it) {
// 順伝播 // forward propagation
forward_propagation(in_it, sprout::next(in_it, In), work); forward_propagation(in_it, sprout::next(in_it, In), work);
// 出力層の誤差計算 // error calculation of output layer
for (std::size_t i = 0; i != Out; ++i) { for (std::size_t i = 0; i != Out; ++i) {
d3[i] = *t_it == i ? work.o3[i] - 1 d3[i] = *t_it == i ? work.o3[i] - 1
: work.o3[i] : work.o3[i]
; ;
} }
// 出力層の重み更新 // weight update of output layer
for (std::size_t i = 0; i != Hid + 1; ++i) { for (std::size_t i = 0; i != Hid + 1; ++i) {
for (std::size_t j = 0; j != Out; ++j) { for (std::size_t j = 0; j != Out; ++j) {
w2[i * Out + j] -= eta * d3[j] * work.o2[i]; w2[i * Out + j] -= eta * d3[j] * work.o2[i];
} }
} }
// 隠れ層の誤差計算 // error calculation of hidden layer
for (std::size_t i = 0; i != Hid + 1; ++i) { for (std::size_t i = 0; i != Hid + 1; ++i) {
d2[i] = 0; d2[i] = 0;
for (std::size_t j = 0; j != Out; ++j) { for (std::size_t j = 0; j != Out; ++j) {
@ -125,7 +125,7 @@ public:
d2[i] *= sprout::math::d_sigmoid(work.xi2[i]); d2[i] *= sprout::math::d_sigmoid(work.xi2[i]);
} }
// 隠れ層の重み更新 // weight update of hidden layer
for (std::size_t i = 0; i != In + 1; ++i) { for (std::size_t i = 0; i != In + 1; ++i) {
for (std::size_t j = 0; j != Hid; ++j) { for (std::size_t j = 0; j != Hid; ++j) {
w1[i * Hid + j] -= eta * d2[j] * work.o1[i]; w1[i * Hid + j] -= eta * d2[j] * work.o1[i];
@ -135,7 +135,7 @@ public:
} }
} }
// 与えられたデータに対して最も可能性の高いクラスを返す // returns to predict the most likely class for a given data
template<typename ForwardIterator> template<typename ForwardIterator>
SPROUT_CXX14_CONSTEXPR std::size_t SPROUT_CXX14_CONSTEXPR std::size_t
predict(ForwardIterator in_first, ForwardIterator in_last) const { predict(ForwardIterator in_first, ForwardIterator in_last) const {
@ -143,10 +143,10 @@ public:
worker work{}; worker work{};
// 順伝播による予測 // prediction by forward propagation
forward_propagation(in_first, in_last, work); forward_propagation(in_first, in_last, work);
// 出力が最大になるクラスを判定 // determining a class which output is maximum
return sprout::distance( return sprout::distance(
sprout::begin(work.o3), sprout::begin(work.o3),
sprout::max_element(sprout::begin(work.o3), sprout::end(work.o3)) sprout::max_element(sprout::begin(work.o3), sprout::end(work.o3))
@ -161,11 +161,11 @@ public:
#include <sprout/random/unique_seed.hpp> #include <sprout/random/unique_seed.hpp>
#include <sprout/static_assert.hpp> #include <sprout/static_assert.hpp>
// 訓練データ // training data
SPROUT_CONSTEXPR auto train_data = sprout::make_array<double>( SPROUT_CONSTEXPR auto train_data = sprout::make_array<double>(
# include "g3_train.csv" # include "g3_train.csv"
); );
// 教師データ // teaching data
SPROUT_CONSTEXPR auto teach_data = sprout::make_array<std::size_t>( SPROUT_CONSTEXPR auto teach_data = sprout::make_array<std::size_t>(
# include "g3_teach.csv" # include "g3_teach.csv"
); );
@ -173,17 +173,17 @@ SPROUT_CONSTEXPR auto teach_data = sprout::make_array<std::size_t>(
SPROUT_STATIC_ASSERT(train_data.size() % 2 == 0); SPROUT_STATIC_ASSERT(train_data.size() % 2 == 0);
SPROUT_STATIC_ASSERT(train_data.size() / 2 == teach_data.size()); SPROUT_STATIC_ASSERT(train_data.size() / 2 == teach_data.size());
// 訓練済みパーセプトロンを生成 // generate a trained perceptron
template<typename FloatType, std::size_t In, std::size_t Hid, std::size_t Out> template<typename FloatType, std::size_t In, std::size_t Hid, std::size_t Out>
SPROUT_CXX14_CONSTEXPR ::perceptron<FloatType, In, Hid, Out> SPROUT_CXX14_CONSTEXPR ::perceptron<FloatType, In, Hid, Out>
make_trained_perceptron() { make_trained_perceptron() {
// 乱数生成器 // random number generator
sprout::random::default_random_engine rng(SPROUT_UNIQUE_SEED); sprout::random::default_random_engine rng(SPROUT_UNIQUE_SEED);
// パーセプトロン // perceptron
::perceptron<FloatType, In, Hid, Out> per(rng); ::perceptron<FloatType, In, Hid, Out> per(rng);
// 訓練 // training
per.train( per.train(
train_data.begin(), train_data.end(), train_data.begin(), train_data.end(),
teach_data.begin(), teach_data.end(), teach_data.begin(), teach_data.end(),
@ -194,10 +194,10 @@ make_trained_perceptron() {
} }
int main() { int main() {
// パーセプトロンを生成入力2 隠れ3 出力3 // generate a Perceptron (input 2, hidden 3, output 3)
SPROUT_CXX14_CONSTEXPR auto per = ::make_trained_perceptron<double, 2, 3, 3>(); SPROUT_CXX14_CONSTEXPR auto per = ::make_trained_perceptron<double, 2, 3, 3>();
// 結果の表示 // print results
for (auto it = train_data.begin(), last = train_data.end(); it != last; it += 2) { for (auto it = train_data.begin(), last = train_data.end(); it != last; it += 2) {
std::cout << per.predict(it, it + 2) << std::endl; std::cout << per.predict(it, it + 2) << std::endl;
} }

View file

@ -34,13 +34,13 @@ namespace sprout {
// //
struct info_type { struct info_type {
public: public:
std::uint16_t format_tag; // フォーマットID std::uint16_t format_tag; // format ID
std::uint16_t channels; // チャンネル数 std::uint16_t channels; // channels
std::uint32_t samples_per_sec; // サンプリングレート std::uint32_t samples_per_sec; // sampling rate
std::uint32_t bytes_per_sec; // データ速度 (Byte/sec) std::uint32_t bytes_per_sec; // data speed (Byte/sec)
std::uint16_t block_size; // ブロックサイズ (Byte/sample*チャンネル数) std::uint16_t block_size; // block size (Byte/sample*channels)
std::uint16_t bits_per_sample; // サンプルあたりのビット数 (bit/sample) std::uint16_t bits_per_sample; // bits per sample (bit/sample)
std::size_t size; // 要素数 std::size_t size; // elements
}; };
// //
// sound_type // sound_type

View file

@ -16,7 +16,9 @@ namespace sprout {
namespace compost { namespace compost {
// //
// rosenberg_value // rosenberg_value
// Rosenberg 波は声門開大期と閉小期が周期の40%16%となる非対称形の波形でありτ1 が開大期τ2が閉小期を示す // Rosenberg wave is asymmetric waveform,
// expansion period/reduction period of the glottis is 40%/16% of the cycle,
// tau1 is expansion period, tau2 is reduction period
// //
template<typename T> template<typename T>
inline SPROUT_CONSTEXPR typename sprout::float_promote<T>::type inline SPROUT_CONSTEXPR typename sprout::float_promote<T>::type

View file

@ -18,7 +18,7 @@
namespace sprout { namespace sprout {
// 7.20.6.1 abs<EFBFBD>Clabs<EFBFBD>C<EFBFBD>y<EFBFBD><EFBFBD> llabs <20>֐<EFBFBD> // 7.20.6.1 abs, labs, and llabs function
inline SPROUT_CONSTEXPR int inline SPROUT_CONSTEXPR int
abs(int j) { abs(int j) {
return j < 0 ? -j : j; return j < 0 ? -j : j;

View file

@ -88,7 +88,7 @@ namespace sprout {
} }
} // namespace detail } // namespace detail
// 7.20.6.2 div<EFBFBD>Cldiv<EFBFBD>CyÑ lldiv ŠÖ<C5A0> // 7.20.6.2 div, ldiv, and lldiv function
inline SPROUT_CONSTEXPR sprout::div_t inline SPROUT_CONSTEXPR sprout::div_t
div(int numer, int denom) { div(int numer, int denom) {
return sprout::detail::div_impl(numer, denom); return sprout::detail::div_impl(numer, denom);

View file

@ -50,7 +50,7 @@ namespace sprout {
} }
} // namespace detail } // namespace detail
// 7.21.5.1 memchr ŠÖ<EFBFBD> // 7.21.5.1 memchr function
// //
// recursion depth: // recursion depth:
// O(log N) // O(log N)

View file

@ -27,7 +27,7 @@ namespace sprout {
} }
} // namespace detail } // namespace detail
// 7.21.4.1 memcmp ŠÖ<EFBFBD> // 7.21.4.1 memcmp function
// //
// recursion depth: // recursion depth:
// O(log(N1+N2)) // O(log(N1+N2))

View file

@ -63,7 +63,7 @@ namespace sprout {
} // namespace detail } // namespace detail
// 7.21.5.2 strchr ŠÖ<EFBFBD> // 7.21.5.2 strchr function
// //
// recursion depth: // recursion depth:
// O(log N) // O(log N)

View file

@ -76,7 +76,7 @@ namespace sprout {
} }
} // namespace detail } // namespace detail
// 7.21.4.2 strcmp ŠÖ<EFBFBD> // 7.21.4.2 strcmp function
// //
// recursion depth: // recursion depth:
// O(log(N1+N2)) // O(log(N1+N2))

View file

@ -15,7 +15,7 @@
namespace sprout { namespace sprout {
// 7.21.4.3 strcoll ŠÖ<EFBFBD> // 7.21.4.3 strcoll function
// //
// recursion depth: // recursion depth:
// O(log(N1+N2)) // O(log(N1+N2))

View file

@ -66,7 +66,7 @@ namespace sprout {
} }
} // namespace detail } // namespace detail
// 7.21.5.3 strcspn ŠÖ<EFBFBD> // 7.21.5.3 strcspn function
// //
// recursion depth: // recursion depth:
// O(log(N1+N2)) // O(log(N1+N2))

View file

@ -64,7 +64,7 @@ namespace sprout {
} }
} // namespace detail } // namespace detail
// 7.21.6.3 strlen ŠÖ<EFBFBD> // 7.21.6.3 strlen function
// //
// recursion depth: // recursion depth:
// O(log N) // O(log N)

View file

@ -17,7 +17,7 @@
namespace sprout { namespace sprout {
// 7.21.4.4 strncmp ŠÖ<EFBFBD> // 7.21.4.4 strncmp function
// //
// recursion depth: // recursion depth:
// O(log(N1+N2)) // O(log(N1+N2))

View file

@ -67,7 +67,7 @@ namespace sprout {
} }
} // namespace detail } // namespace detail
// 7.21.5.4 strpbrk ŠÖ<EFBFBD> // 7.21.5.4 strpbrk function
// //
// recursion depth: // recursion depth:
// O(log(N1+N2)) // O(log(N1+N2))

View file

@ -74,7 +74,7 @@ namespace sprout {
} }
} // namespace detail } // namespace detail
// 7.21.5.5 strrchr ŠÖ<EFBFBD> // 7.21.5.5 strrchr function
// //
// recursion depth: // recursion depth:
// O(log N) // O(log N)

View file

@ -66,7 +66,7 @@ namespace sprout {
} }
} // namespace detail } // namespace detail
// 7.21.5.6 strspn ŠÖ<EFBFBD> // 7.21.5.6 strspn function
// //
// recursion depth: // recursion depth:
// O(log(N1+N2)) // O(log(N1+N2))

View file

@ -128,7 +128,7 @@ namespace sprout {
} }
} // namespace detail } // namespace detail
// 7.21.5.7 strstr ŠÖ<EFBFBD> // 7.21.5.7 strstr function
// //
// recursion depth: // recursion depth:
// O(log(N1+N2)) // O(log(N1+N2))

View file

@ -34,7 +34,7 @@ class include_graph_hooks
private: private:
typedef boost::wave::context_policies::default_preprocessing_hooks base_type; typedef boost::wave::context_policies::default_preprocessing_hooks base_type;
public: public:
// グラフのノード // node of graph
struct node_type { struct node_type {
boost::filesystem::path absolute; boost::filesystem::path absolute;
boost::filesystem::path filename; boost::filesystem::path filename;
@ -99,7 +99,7 @@ public:
edges() const { edges() const {
return edge_list_; return edge_list_;
} }
// グラフ生成 // make graph
template<typename Graph> template<typename Graph>
Graph make_graph() const { Graph make_graph() const {
return Graph(edge_list_.begin(), edge_list_.end(), node_list_.size()); return Graph(edge_list_.begin(), edge_list_.end(), node_list_.size());
@ -107,7 +107,7 @@ public:
graph_type make_graph() const { graph_type make_graph() const {
return make_graph<graph_type>(); return make_graph<graph_type>();
} }
// graphviz 出力 // output graphviz
void write_graphviz(std::ostream& out) const { void write_graphviz(std::ostream& out) const {
boost::write_graphviz( boost::write_graphviz(
out, out,
@ -115,7 +115,7 @@ public:
boost::make_label_writer(&node_list_[0]) boost::make_label_writer(&node_list_[0])
); );
} }
// 非インクルードガード検出 // collect no include guard files
template<typename OutputIterator> template<typename OutputIterator>
void collect_no_include_guard_files(OutputIterator result) const { void collect_no_include_guard_files(OutputIterator result) const {
std::copy_if( std::copy_if(
@ -123,7 +123,7 @@ public:
[](node_type const& e) { return !e.has_include_guard; } [](node_type const& e) { return !e.has_include_guard; }
); );
} }
// 循環インクルード検出 // collect circulated includes
template<typename OutputIterator> template<typename OutputIterator>
void collect_circulated_includes(OutputIterator result) const { void collect_circulated_includes(OutputIterator result) const {
boost::depth_first_search( boost::depth_first_search(
@ -131,7 +131,7 @@ public:
boost::visitor(sprig::make_back_edge_recorder(result)) boost::visitor(sprig::make_back_edge_recorder(result))
); );
} }
// 孤立ファイル検出 // collect isolated files
template<typename OutputIterator> template<typename OutputIterator>
void collect_isolated_files(OutputIterator result, boost::filesystem::path const& path) const { void collect_isolated_files(OutputIterator result, boost::filesystem::path const& path) const {
typedef boost::filesystem::recursive_directory_iterator iterator; typedef boost::filesystem::recursive_directory_iterator iterator;
@ -139,14 +139,14 @@ public:
if (!boost::filesystem::is_directory(*it)) { if (!boost::filesystem::is_directory(*it)) {
boost::filesystem::path abspath(boost::filesystem::absolute(*it)); boost::filesystem::path abspath(boost::filesystem::absolute(*it));
auto found = std::find(node_list_.begin(), node_list_.end(), abspath); auto found = std::find(node_list_.begin(), node_list_.end(), abspath);
if (found == node_list_.end()) { // インクルードされていないならば結果に追加 if (found == node_list_.end()) { // add result if not include
*result++ = abspath.generic_string(); *result++ = abspath.generic_string();
} }
} }
} }
} }
public: public:
// インクルードファイルパス設定処理をフック // hook the locate include file process
template<typename Context> template<typename Context>
bool locate_include_file( bool locate_include_file(
Context& ctx, Context& ctx,
@ -161,10 +161,10 @@ public:
if (!base_type::locate_include_file(ctx, file_path, is_system, current_name, dir_path, native_name)) { if (!base_type::locate_include_file(ctx, file_path, is_system, current_name, dir_path, native_name)) {
return false; return false;
} }
dir_path = filename; // インクルードディレクティブのテキストで上書き dir_path = filename; // overwrite the include directive text
return true; return true;
} }
// インクルードファイル解析開始をフック // hook the opened include file process
template<typename Context> template<typename Context>
void opened_include_file( void opened_include_file(
Context const& /*ctx*/, Context const& /*ctx*/,
@ -176,20 +176,20 @@ public:
boost::filesystem::path abspath(boost::filesystem::absolute(absname)); boost::filesystem::path abspath(boost::filesystem::absolute(absname));
auto found = std::find(node_list_.begin(), node_list_.end(), abspath); auto found = std::find(node_list_.begin(), node_list_.end(), abspath);
auto to = std::distance(node_list_.begin(), found); auto to = std::distance(node_list_.begin(), found);
if (found == node_list_.end()) { // 最初のインクルードならばノードに追加 if (found == node_list_.end()) { // add node if first include
node_list_.emplace_back(abspath, relname); node_list_.emplace_back(abspath, relname);
} }
edge_list_.emplace_back(current_list_.back(), to); edge_list_.emplace_back(current_list_.back(), to);
current_list_.push_back(to); // カレントを更新 current_list_.push_back(to); // update current
current_ = to; current_ = to;
} }
// インクルードファイル解析完了をフック // hook the returning from include file process
template<typename Context> template<typename Context>
void returning_from_include_file(Context const& /*ctx*/) { void returning_from_include_file(Context const& /*ctx*/) {
current_ = current_list_.back(); current_ = current_list_.back();
current_list_.pop_back(); // カレントを戻す current_list_.pop_back(); // revert current
} }
// インクルードガード検出をフック // hook the detected include guard process
template<typename Context> template<typename Context>
void detected_include_guard( void detected_include_guard(
Context const& /*ctx*/, Context const& /*ctx*/,
@ -210,7 +210,7 @@ public:
} }
}; };
// システムインクルードパスの取得 // collect sysinclude paths
template<typename OutputIterator> template<typename OutputIterator>
void collect_sysinclude_paths(OutputIterator result, std::string const& command = "g++") { void collect_sysinclude_paths(OutputIterator result, std::string const& command = "g++") {
{ {
@ -224,7 +224,7 @@ void collect_sysinclude_paths(OutputIterator result, std::string const& command
std::istreambuf_iterator<char>() std::istreambuf_iterator<char>()
); );
auto rng = boost::make_iterator_range(text); auto rng = boost::make_iterator_range(text);
rng = sprig::find_skip(rng, boost::algorithm::first_finder("#include <...>")); // インクルードパスの始点までスキップ rng = sprig::find_skip(rng, boost::algorithm::first_finder("#include <...>")); // skip to begin of the include path
rng = sprig::find_skip(rng, boost::algorithm::first_finder("\n")); rng = sprig::find_skip(rng, boost::algorithm::first_finder("\n"));
while (boost::algorithm::starts_with(rng, " ")) { while (boost::algorithm::starts_with(rng, " ")) {
auto found = sprig::find_between( auto found = sprig::find_between(
@ -247,7 +247,7 @@ int main(int argc, const char* argv[]) {
if (argc >= 2) { if (argc >= 2) {
src = argv[1]; src = argv[1];
// ファイルの内容を全部 text に読み込む // read text from file
std::ifstream ifs(argv[1]); std::ifstream ifs(argv[1]);
text = std::string( text = std::string(
std::istreambuf_iterator<char>(ifs.rdbuf()), std::istreambuf_iterator<char>(ifs.rdbuf()),
@ -259,7 +259,7 @@ int main(int argc, const char* argv[]) {
} }
try { try {
// プリプロセッサを用意 // prepare preprocessor
typedef boost::wave::context< typedef boost::wave::context<
std::string::iterator, std::string::iterator,
boost::wave::cpplexer::lex_iterator<boost::wave::cpplexer::lex_token<> >, boost::wave::cpplexer::lex_iterator<boost::wave::cpplexer::lex_token<> >,
@ -268,14 +268,14 @@ int main(int argc, const char* argv[]) {
> context_type; > context_type;
context_type ctx(text.begin(), text.end(), src.c_str(), ::include_graph_hooks(src)); context_type ctx(text.begin(), text.end(), src.c_str(), ::include_graph_hooks(src));
// ランゲージの設定 // set language
ctx.set_language( ctx.set_language(
boost::wave::language_support( boost::wave::language_support(
boost::wave::support_cpp11 boost::wave::support_cpp11
| boost::wave::support_option_include_guard_detection // インクルードガード検出 | boost::wave::support_option_include_guard_detection // include guard detection
) )
); );
// インクルードパスの設定 // set include paths
if (!command.empty()) { if (!command.empty()) {
std::cout std::cout
<< "collect command :\n" << "collect command :\n"
@ -304,7 +304,7 @@ int main(int argc, const char* argv[]) {
} }
if (!src.empty()) { if (!src.empty()) {
// プリプロセスを走らせる // run preprocessor
for (auto&& e : ctx) { for (auto&& e : ctx) {
//std::cout << e.get_value(); //std::cout << e.get_value();
} }
@ -323,7 +323,7 @@ int main(int argc, const char* argv[]) {
std::vector<std::string> tokens; std::vector<std::string> tokens;
boost::algorithm::split(tokens, line, boost::algorithm::is_space()); boost::algorithm::split(tokens, line, boost::algorithm::is_space());
if (tokens.at(0) == "find") { if (tokens.at(0) == "find") {
// インクルードファイルを検索 // find include paths
if (tokens.size() < 2) { if (tokens.size() < 2) {
std::cout std::cout
<< "missing parameter.\n" << "missing parameter.\n"
@ -348,7 +348,7 @@ int main(int argc, const char* argv[]) {
<< std::flush << std::flush
; ;
} else if (tokens.at(0) == "graph") { } else if (tokens.at(0) == "graph") {
// グラフ出力 // output graph
std::cout std::cout
<< "graph output > out.graph.dot\n" << "graph output > out.graph.dot\n"
; ;
@ -358,7 +358,7 @@ int main(int argc, const char* argv[]) {
<< std::flush << std::flush
; ;
} else if (tokens.at(0) == "noguard") { } else if (tokens.at(0) == "noguard") {
// 非インクルードガードを出力 // output no include guarde files
std::vector<::include_graph_hooks::node_type> list; std::vector<::include_graph_hooks::node_type> list;
ctx.get_hooks().collect_no_include_guard_files(std::back_inserter(list)); ctx.get_hooks().collect_no_include_guard_files(std::back_inserter(list));
std::cout std::cout
@ -373,7 +373,7 @@ int main(int argc, const char* argv[]) {
<< std::flush << std::flush
; ;
} else if (tokens.at(0) == "circulated") { } else if (tokens.at(0) == "circulated") {
// 循環インクルードを出力 // output circulated includes
std::vector<typename boost::graph_traits<::include_graph_hooks::graph_type>::edge_descriptor> list; std::vector<typename boost::graph_traits<::include_graph_hooks::graph_type>::edge_descriptor> list;
ctx.get_hooks().collect_circulated_includes(std::back_inserter(list)); ctx.get_hooks().collect_circulated_includes(std::back_inserter(list));
auto g = ctx.get_hooks().make_graph(); auto g = ctx.get_hooks().make_graph();
@ -390,12 +390,12 @@ int main(int argc, const char* argv[]) {
<< std::flush << std::flush
; ;
} else if (tokens.at(0) == "isolated") { } else if (tokens.at(0) == "isolated") {
// Sprout の孤立ファイルを出力 // output Sprout isolated files
std::cout std::cout
<< "isolated files output > out.isolated.txt\n" << "isolated files output > out.isolated.txt\n"
; ;
std::ofstream ofs("out.isolated.txt"); std::ofstream ofs("out.isolated.txt");
// Sprout のシステムインクル-ドパスを取得 // get Sprout system include path
std::string filepath("sprout/config.hpp"); std::string filepath("sprout/config.hpp");
std::string dirpath; std::string dirpath;
if (!ctx.find_include_file(filepath, dirpath, true, 0)) { if (!ctx.find_include_file(filepath, dirpath, true, 0)) {
@ -406,7 +406,7 @@ int main(int argc, const char* argv[]) {
continue; continue;
} }
dirpath = boost::filesystem::path(filepath).parent_path().generic_string(); dirpath = boost::filesystem::path(filepath).parent_path().generic_string();
// リスト出力 // output list
std::vector<std::string> list; std::vector<std::string> list;
ctx.get_hooks().collect_isolated_files(std::back_inserter(list), dirpath); ctx.get_hooks().collect_isolated_files(std::back_inserter(list), dirpath);
std::sort(list.begin(), list.end()); std::sort(list.begin(), list.end());
@ -422,7 +422,7 @@ int main(int argc, const char* argv[]) {
} }
} }
} catch (boost::wave::cpp_exception& e) { } catch (boost::wave::cpp_exception& e) {
// プリプロセスでエラー発生 // eorror handling
std::cerr std::cerr
<< "#error " << e.file_name() << "(" << e.line_no() << "):" << e.description() << "\n" << "#error " << e.file_name() << "(" << e.line_no() << "):" << e.description() << "\n"
<< std::flush << std::flush