home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12326 < prev    next >
Encoding:
Text File  |  1992-08-13  |  2.9 KB  |  126 lines

  1. Path: sparky!uunet!pipex!demon!cix.compulink.co.uk!vadim
  2. Newsgroups: comp.lang.c++
  3. From: vadim@cix.compulink.co.uk (Vadim Lebedev)
  4. Subject: Language extension
  5. Reply-To: vadim@cix.compulink.co.uk
  6. Date: Thu, 13 Aug 1992 23:17:33 +0000
  7. Message-ID: <memo.575428@cix.compulink.co.uk>
  8. Sender: usenet@gate.demon.co.uk
  9. Lines: 115
  10.  
  11.  
  12. While thinking about various RTTI, XRTTI and GC proposals
  13. for C++ i've stumbled on following idea:
  14. Many of the modern computer programs such as communication programs,
  15. word processors, CAD systems, e-mail systems provides a means to tailor
  16. them to match user needs by offering some kind of script language.
  17. It just occured that the same mechanism could be provided in the
  18. compiler.  A scripting language which could access and manipulate
  19. compiler data structures. Such a thing will give almost unlimited
  20. language extension possibilites and that WITHOUT need to change the
  21. language itself.
  22.  
  23. With souch a feauture RTTI, EXCEPTION HANDLING, GC, PRE- and POST- 
  24. method conditions, class invariants, all become
  25. possible without modifying the language. The stadards commetee will
  26. simply have to agree on library interface to all these features.
  27.  
  28. With such a feauture one could write following to add persistemcy
  29. to his classes:
  30.  
  31. class Something
  32. {
  33.  
  34. public:
  35.  
  36.     doSomeThing();
  37.  
  38.  Something( int a, b, c);
  39.  Something(float x);
  40. protected:
  41.  int x, y;
  42. };
  43.  
  44.  
  45.  
  46. template <class T>
  47. class Persistent: public T, public PersitentObj
  48. {
  49. public:
  50.  // Generates the same constructors as class T
  51.  #for f in  #methods(T) 
  52.   #if f == T::T
  53.    Persistent(#arglist(f)) : T(#params()) { }
  54.   #endif
  55.  #endfor
  56.  
  57. private:
  58.  // Generate the store method
  59.  virtual storeOn(PStream &s)
  60.  {
  61.   #for a in #attributes(T)
  62.     s.store(T::a);
  63.      #endfor
  64.  }
  65.  
  66. };
  67.   
  68.  
  69. Or to add a class invariants: 
  70.  
  71.  
  72. template <class T, class Expr>
  73. class Constrained : public T
  74. {
  75. private:
  76.     // generate invariant checking method
  77.  void check() { assert(Expr); }
  78. public:
  79.  // add invariant checking for all public methods
  80.  #for f in  #methods(T) 
  81.   #if #visibility(T::f) == public
  82.    #typeof(f) f(#arglist(T::f)) {
  83.       check();
  84.       #if #typeof(T::f) != #typeof(void)
  85.        #typeof(T::f) ret = 
  86.       #endif
  87.         T::f(#params());
  88.       check();
  89.       #if #typeof(T::f) != #typeof(void)
  90.          return ret;
  91.       #endif
  92.   #endif
  93.  #endfor
  94.  
  95. public:
  96.  // Generates the same PUBLIC constructors as class T
  97.  #for f in  #methods(T) 
  98.   #if f == T::T  && #visibility(f) == public
  99.    Constrained(#arglist(f)) : T(#params()) { check(); }
  100.   #endif
  101.  #endfor
  102.  
  103. };
  104.  
  105.  
  106.  
  107. Actually the TI  C++ Preprocessor has somewhat similar capabilities,
  108. but it is limited by fact that it is a PREPROCESSOR, and does not
  109. have full access to all compiler data structures.
  110.  
  111.  
  112. What do you think?
  113. -----------------------------------------------------------------------
  114. Vadim Lebedev                      |   Kortex International
  115. vadim@cix.compulink.co.uk          |   139-147 av. Paul-Vaillant Couturier
  116.                                    |   93126 La Courneuve - CEDEX, France
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.