1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

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

View file

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

View file

@ -27,33 +27,33 @@ public:
private:
struct worker {
public:
// 入力
// in
sprout::array<value_type, In + 1> xi1;
sprout::array<value_type, Hid + 1> xi2;
sprout::array<value_type, Out> xi3;
// 出力
// out
sprout::array<value_type, In + 1> o1;
sprout::array<value_type, Hid + 1> o2;
sprout::array<value_type, Out> o3;
};
private:
// 誤差
// error
sprout::array<value_type, Hid + 1> d2;
sprout::array<value_type, Out> d3;
// 重み
// weight
sprout::array<value_type, (In + 1) * Hid> w1;
sprout::array<value_type, (Hid + 1) * Out> w2;
private:
// 順伝播
// forward propagation
template<typename ForwardIterator>
SPROUT_CXX14_CONSTEXPR void
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));
work.xi1[In] = 1;
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) {
work.xi2[i] = 0;
for (std::size_t j = 0; j != In + 1; ++j) {
@ -63,7 +63,7 @@ private:
}
work.o2[Hid] = 1;
// 出力層の順伝播
// forward propagation with output layer
for (std::size_t i = 0; i != Hid; ++i) {
work.xi3[i] = 0;
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>()))
{}
// ニューラルネットの訓練
// [in_first, in_last) : 訓練データ (N*In 個)
// [t_first, t_last) : 教師データ (N 個)
// training of neural network
// [in_first, in_last) : training data (N*In elements)
// [t_first, t_last) : training data (N elements)
template<typename ForwardIterator1, typename ForwardIterator2>
SPROUT_CXX14_CONSTEXPR void
train(
@ -99,24 +99,24 @@ public:
ForwardIterator1 in_it = in_first;
ForwardIterator2 t_it = t_first;
for (; in_it != in_last; sprout::advance(in_it, In), ++t_it) {
// 順伝播
// forward propagation
forward_propagation(in_it, sprout::next(in_it, In), work);
// 出力層の誤差計算
// error calculation of output layer
for (std::size_t i = 0; i != Out; ++i) {
d3[i] = *t_it == i ? work.o3[i] - 1
: work.o3[i]
;
}
// 出力層の重み更新
// weight update of output layer
for (std::size_t i = 0; i != Hid + 1; ++i) {
for (std::size_t j = 0; j != Out; ++j) {
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) {
d2[i] = 0;
for (std::size_t j = 0; j != Out; ++j) {
@ -125,7 +125,7 @@ public:
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 j = 0; j != Hid; ++j) {
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>
SPROUT_CXX14_CONSTEXPR std::size_t
predict(ForwardIterator in_first, ForwardIterator in_last) const {
@ -143,10 +143,10 @@ public:
worker work{};
// 順伝播による予測
// prediction by forward propagation
forward_propagation(in_first, in_last, work);
// 出力が最大になるクラスを判定
// determining a class which output is maximum
return sprout::distance(
sprout::begin(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/static_assert.hpp>
// 訓練データ
// training data
SPROUT_CONSTEXPR auto train_data = sprout::make_array<double>(
# include "g3_train.csv"
);
// 教師データ
// teaching data
SPROUT_CONSTEXPR auto teach_data = sprout::make_array<std::size_t>(
# 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 == teach_data.size());
// 訓練済みパーセプトロンを生成
// generate a trained perceptron
template<typename FloatType, std::size_t In, std::size_t Hid, std::size_t Out>
SPROUT_CXX14_CONSTEXPR ::perceptron<FloatType, In, Hid, Out>
make_trained_perceptron() {
// 乱数生成器
// random number generator
sprout::random::default_random_engine rng(SPROUT_UNIQUE_SEED);
// パーセプトロン
// perceptron
::perceptron<FloatType, In, Hid, Out> per(rng);
// 訓練
// training
per.train(
train_data.begin(), train_data.end(),
teach_data.begin(), teach_data.end(),
@ -194,10 +194,10 @@ make_trained_perceptron() {
}
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>();
// 結果の表示
// print results
for (auto it = train_data.begin(), last = train_data.end(); it != last; it += 2) {
std::cout << per.predict(it, it + 2) << std::endl;
}

View file

@ -16,31 +16,31 @@
#include <testspr/tools.hpp>
namespace testspr {
static void endian_test() {
using namespace sprout;
static void endian_test() {
using namespace sprout;
{ // 16
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint16_t(0x0A1B)) == std::uint16_t(0x1B0A));
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint16_t(0x1B0A)) == std::uint16_t(0x0A1B));
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint16_t(0x0A1B)) == std::uint16_t(0x1B0A));
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint16_t(0x1B0A)) == std::uint16_t(0x0A1B));
}
{ // 16
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint16_t(0x0A1B)) == std::uint16_t(0x1B0A));
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint16_t(0x1B0A)) == std::uint16_t(0x0A1B));
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint16_t(0x0A1B)) == std::uint16_t(0x1B0A));
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint16_t(0x1B0A)) == std::uint16_t(0x0A1B));
}
{ // 32
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint32_t(0x0A1B2C3D)) == std::uint32_t(0x3D2C1B0A));
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint32_t(0x3D2C1B0A)) == std::uint32_t(0x0A1B2C3D));
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint32_t(0x0A1B2C3D)) == std::uint32_t(0x1B0A3D2C));
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint32_t(0x1B0A3D2C)) == std::uint32_t(0x0A1B2C3D));
}
{ // 32
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint32_t(0x0A1B2C3D)) == std::uint32_t(0x3D2C1B0A));
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint32_t(0x3D2C1B0A)) == std::uint32_t(0x0A1B2C3D));
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint32_t(0x0A1B2C3D)) == std::uint32_t(0x1B0A3D2C));
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint32_t(0x1B0A3D2C)) == std::uint32_t(0x0A1B2C3D));
}
{ // 64
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint64_t(0x0A1B2C3D4E5F6A7B)) == std::uint64_t(0x7B6A5F4E3D2C1B0A));
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint64_t(0x7B6A5F4E3D2C1B0A)) == std::uint64_t(0x0A1B2C3D4E5F6A7B));
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint64_t(0x0A1B2C3D4E5F6A7B)) == std::uint64_t(0x1B0A3D2C5F4E7B6A));
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint64_t(0x1B0A3D2C5F4E7B6A)) == std::uint64_t(0x0A1B2C3D4E5F6A7B));
}
}
} // namespace testspr
{ // 64
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint64_t(0x0A1B2C3D4E5F6A7B)) == std::uint64_t(0x7B6A5F4E3D2C1B0A));
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint64_t(0x7B6A5F4E3D2C1B0A)) == std::uint64_t(0x0A1B2C3D4E5F6A7B));
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint64_t(0x0A1B2C3D4E5F6A7B)) == std::uint64_t(0x1B0A3D2C5F4E7B6A));
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint64_t(0x1B0A3D2C5F4E7B6A)) == std::uint64_t(0x0A1B2C3D4E5F6A7B));
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::endian_test

View file

@ -17,7 +17,7 @@
int
main(){
//
// String literal to Sprout.String
//
@ -30,7 +30,7 @@ main(){
static_assert(str2 == L"ほむほむ", "");
static_assert(std::is_same<decltype(str2), sprout::wstring<4> const>{}, "");
}
//
// Integer literal to Sprout.String
//
@ -38,7 +38,7 @@ main(){
static constexpr auto str = sprout::to_string(42);
static_assert(str == "42", "");
}
//
// Float literal to Sprout.String
//

View file

@ -28,7 +28,7 @@ main(){
// __TIME__ to Sprout.String
//
static constexpr auto time = sprout::to_string(__TIME__);
// static constexpr auto time = sprout::to_string("23:22:45");
// static constexpr auto time = sprout::to_string("23:22:45");
//
@ -43,13 +43,13 @@ main(){
// get result
//
static constexpr sprout::array<long long int, 3> result_attr = result.attr();
static constexpr auto hour = result_attr[0];
static constexpr auto hour = result_attr[0];
static constexpr auto minute = result_attr[1];
static constexpr auto second = result_attr[2];
static constexpr auto second = result_attr[2];
// static_assert(hour == 23, "");
// static_assert(minute == 22, "");
// static_assert(second == 45, "");
// static_assert(hour == 23, "");
// static_assert(minute == 22, "");
// static_assert(second == 45, "");
std::cout << hour << std::endl;
std::cout << minute << std::endl;

View file

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

View file

@ -16,7 +16,9 @@ namespace sprout {
namespace compost {
//
// 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>
inline SPROUT_CONSTEXPR typename sprout::float_promote<T>::type

View file

@ -18,7 +18,7 @@
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
abs(int j) {
return j < 0 ? -j : j;

View file

@ -88,7 +88,7 @@ namespace sprout {
}
} // 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
div(int numer, int denom) {
return sprout::detail::div_impl(numer, denom);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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