How about some C++ template magic?
class Parser {
inline void OnNewNode(AstNode* t) {
/* do nothing */
}
inline void OnNewNode(WithStatement* t) {
/* do something special with WithStatement */
}
template<typename T, typename A1>
T* mk(A1 a1) {
T* t = new T(a1, a2, a3);
OnNewNode(t);
return t;
}
template<typename T, typename A1, typename A2>
T* mk(A1 a1, A2 a2, A3 a3) {
T* t = new T(a1, a2, a3);
OnNewNode(t);
return t;
}
template<typename T, typename A1, typename A2, typename A3>
T* mk(A1 a1, A2 a2, A3 a3) {
T* t = new T(a1, a2, a3);
OnNewNode(t);
return t;
}
/* add as much overloads of mk as you need */
WithStatement* ParseWithStatement() {
return mk<WithStatement>(x, y, z);
}
};
https://chromiumcodereview.appspot.com/9221011/
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev