2007/06/11
GCC 勉強途中経過
ある改造のためにかれこれ数週間 gcc の変態コードと格闘しているのですが、思ったより時間がかかりそうなので途中経過(今 20% ぐらい)。
その改造というのが、 C++ 大好き子なら一度はやりたいと思うはずの文字列テンプレート引数の対応。一応以下のようなことはできるようになっている。
full specialization:
typedef const char * const cstring;
template <cstring V>
struct S {
static cstring value;
};
template <cstring V> cstring S<V>::value = V;
template <> cstring S<"World">::value = "World :)";
int main() {
std::cout << S<"Hello ">::value << S<"World">::value << std::endl; // Hello World :)
return 0;
}
in-class initialization:
typedef const char * const cstring;
/* in-class initialization of string constant is not yet available in template. */
struct S {
static cstring value = "Hello";
};
int main() {
std::cout << S::value << std::endl; // Hello
return 0;
}
concatenation:
int main() {
/* D like contatenation */
std::cout << "Hello " ~ "World" << std::endl; // Hello World
return 0;
}
まだ未実装だけど以下のような記法も導入したい。
substring:
typedef const char * const cstring;
int main() {
static cstring value = "FooHoge";
std::cout << value[0..3] << " " << value[3..7] << std::endl; // Foo Hoge
}
property:
int main() {
std::cout << "What length of this string?".length << std::endl;
return 0;
}
大体これだけあれば不自由しないはず。
ていうか、 integral で決め打ちになっているので改造がかなり大変、 g++ frontend 。まあそういう仕様だから仕方ないけど。
以下適当なメモ。
- template 内での in-class initialization は、 DECL_EXTERNAL のコントロールが必要
- array_type_node と const_string_type_node を上手く統合する必要がある * 統合というか統合的な比較機構
- ちゃんと mangle したいが as が対応してないのでどうしようもない * とりあえずランダムな数字埋めこんでる
- build_binary_op ではなく fold で演算する必要がある * 後ろに手をいれないといけないかも
- Bjarne Stroustrup が発狂しかねない言語仕様だということは重々承知している
- 正直実装しきる自信がない
- The URL to Trackback this entry is:
- http://dev.ariel-networks.com/Members/matsuyama/gcc1/tbping