home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!demon!cix.compulink.co.uk!vadim
- Newsgroups: comp.lang.c++
- From: vadim@cix.compulink.co.uk (Vadim Lebedev)
- Subject: Language extension
- Reply-To: vadim@cix.compulink.co.uk
- Date: Thu, 13 Aug 1992 23:17:33 +0000
- Message-ID: <memo.575428@cix.compulink.co.uk>
- Sender: usenet@gate.demon.co.uk
- Lines: 115
-
-
- While thinking about various RTTI, XRTTI and GC proposals
- for C++ i've stumbled on following idea:
- Many of the modern computer programs such as communication programs,
- word processors, CAD systems, e-mail systems provides a means to tailor
- them to match user needs by offering some kind of script language.
- It just occured that the same mechanism could be provided in the
- compiler. A scripting language which could access and manipulate
- compiler data structures. Such a thing will give almost unlimited
- language extension possibilites and that WITHOUT need to change the
- language itself.
-
- With souch a feauture RTTI, EXCEPTION HANDLING, GC, PRE- and POST-
- method conditions, class invariants, all become
- possible without modifying the language. The stadards commetee will
- simply have to agree on library interface to all these features.
-
- With such a feauture one could write following to add persistemcy
- to his classes:
-
- class Something
- {
-
- public:
-
- doSomeThing();
-
- Something( int a, b, c);
- Something(float x);
- protected:
- int x, y;
- };
-
-
-
- template <class T>
- class Persistent: public T, public PersitentObj
- {
- public:
- // Generates the same constructors as class T
- #for f in #methods(T)
- #if f == T::T
- Persistent(#arglist(f)) : T(#params()) { }
- #endif
- #endfor
-
- private:
- // Generate the store method
- virtual storeOn(PStream &s)
- {
- #for a in #attributes(T)
- s.store(T::a);
- #endfor
- }
-
- };
-
-
- Or to add a class invariants:
-
-
- template <class T, class Expr>
- class Constrained : public T
- {
- private:
- // generate invariant checking method
- void check() { assert(Expr); }
- public:
- // add invariant checking for all public methods
- #for f in #methods(T)
- #if #visibility(T::f) == public
- #typeof(f) f(#arglist(T::f)) {
- check();
- #if #typeof(T::f) != #typeof(void)
- #typeof(T::f) ret =
- #endif
- T::f(#params());
- check();
- #if #typeof(T::f) != #typeof(void)
- return ret;
- #endif
- #endif
- #endfor
-
- public:
- // Generates the same PUBLIC constructors as class T
- #for f in #methods(T)
- #if f == T::T && #visibility(f) == public
- Constrained(#arglist(f)) : T(#params()) { check(); }
- #endif
- #endfor
-
- };
-
-
-
- Actually the TI C++ Preprocessor has somewhat similar capabilities,
- but it is limited by fact that it is a PREPROCESSOR, and does not
- have full access to all compiler data structures.
-
-
- What do you think?
- -----------------------------------------------------------------------
- Vadim Lebedev | Kortex International
- vadim@cix.compulink.co.uk | 139-147 av. Paul-Vaillant Couturier
- | 93126 La Courneuve - CEDEX, France
-
-
-
-
-
-
-
-
-
-