home *** CD-ROM | disk | FTP | other *** search
/ ftp.umcs.maine.edu / 2015-02-07.ftp.umcs.maine.edu.tar / ftp.umcs.maine.edu / pub / WISR / wisr6 / proceedings / ascii / kojima.ascii < prev    next >
Text File  |  1993-10-19  |  14KB  |  313 lines

  1.  
  2.  
  3.  
  4.  
  5. Customizing  C++  to  Improve  the  Reusability  of  Class  Libraries
  6.  
  7.  
  8.  
  9.                                                    Taizo Ko jima
  10.  
  11.  
  12.  
  13.                  Mitsubishi Electric Corporation, Central Research Laboratory
  14.  
  15.                 1-1, Tsukaguchi-honmachi 8-chome, Amagasaki, Hyogo, JAPAN
  16.  
  17.                                                Tel: (06)  497-7144
  18.  
  19.                                      Email: kojima@sys.crl.melco.co.jp
  20.  
  21.  
  22.  
  23.                                                  Akira Sugimoto
  24.  
  25.  
  26.  
  27.                  Mitsubishi Electric Corporation, Central Research Laboratory
  28.  
  29.                 1-1, Tsukaguchi-honmachi 8-chome, Amagasaki, Hyogo, JAPAN
  30.  
  31.                                                Tel: (06)  497-7144
  32.  
  33.                                    Email: sugimoto@sys.crl.melco.co.jp
  34.  
  35.  
  36.  
  37.                                                       Abstract
  38.  
  39.  
  40.         OPTEC is a language extension tool for customizing C++ language to improve theusability
  41.     of specific class libraries. Using OPTEC, a system specific language for non-expert programmers
  42.     can be built easily by extending C++.  The system sp ecific language supports selection of the
  43.     appropriate  class  from  the  class  libraries,  simplifies  the  use  of  the  class,  and  makes  it  easy
  44.     to define a subclass from an abstract class.  The system-specific language uses libraries as its
  45.     run-time libraries, however, this language can hide the detailed structure of the libraries from
  46.     programmers.  This article describes how extension and customization of the C++ language
  47.     is effective for increasing the reusability of a library. It also describes an outline of OPTEC
  48.     system.
  49.  
  50.  
  51.     Keywords: class library, reuse, language extension, translator generator, C++
  52.  
  53.  
  54.     Workshop Goals: Learning; exchange views on practical experiences.
  55.  
  56.  
  57.     Working Groups: Reuse and OO methods, Tools and environments.
  58.  
  59.  
  60.  
  61.                                                       Kojima- 1
  62.  
  63.  
  64. 1      Background
  65.  
  66.  
  67.  
  68. Recently,software architectures of large-scale systems have become complicated,and the productiv-
  69. ity of the application programmers is decreasing. Customers want systems which are as integrated,
  70. user-friendly, reliable and scalable asthey can be.  As a result, large, complicated software libraries
  71. are required to develop large-scale systems. Also, the librariesof large-scale systems are not optimal
  72. tools for reducing programming work. Each programmer should be able to understand the frame-
  73. work  of  the  libraries  and  use  them  appropriately,  so  that  many  programmers  can  cooperatively
  74. implement the high-level facilities of the system.
  75.  
  76.  
  77. General purpose object-oriented programming languages are very effectivefor developing a system
  78. library.  Using the advanced features of the existing object-oriented languages, such as encapsu-
  79. lation,  inheritance,  and  polymorphism,  we  can  create  a  well  organized  library  based  on  classes.
  80. However, providing only a class library is not enough to improve software productivity. To use a
  81. class library effectively, such as making a subclass from an abstract class, the programmer must
  82. have a detailed knowledge of the library source code.  To develop a large-scale system requires many
  83. programmers, and unfortunately, all programmers may not have adequate knowledge of the library.
  84.  
  85.  
  86.  
  87. 2      Position
  88.  
  89.  
  90.  
  91. Although object-oriented languages provide an abstraction mechanism, enhancing the languages is
  92. an effective means of simplifying application programs for asp ecific system.  An example is Argus[1].
  93. Argus language was developed by enhancing CLU[2] to design a fault-tolerant distributed system.
  94. C++[3] has also been extended by many researchers to solve specific problem domains or create
  95. new paradigms.  For example, Concurrent C++[4] was developed for concurrent processing, and
  96. RTC++[5] for real time systems.
  97.  
  98.  
  99.  
  100. 2.1     System-Specific Extension of Object-Oriented Language
  101.  
  102.  
  103.  
  104. System-specific extension of language is effective for increasing the reusability of a library. Because
  105. system-specific language uses libraries as its run-time libraries, however, this language can hide the
  106. detailed structure of the libraries from programmers.  Followings are examples of system-specific
  107. extensions of language, which improve the usablity of a library.
  108.  
  109.  
  110.  
  111. ffl Simplifying the use of class
  112.       To simplify the use ofa class library, it is important to minimize the necessity of knowing the
  113. usage of the classes. This can be done by introducing new syntax for the use of specific classes.
  114.  
  115. ffl Selection of appropriate class
  116.       Selecting  an  appropriate  class  from  libraries  is another  difficulty  when  a  lot  of  classes  are
  117. provided. Therefore, it would be effective if a language system could support the selection.
  118.  
  119. ffl Context sensitive transformation
  120.       Context sensitive transformationis useful for simplifying the programs.
  121.  
  122. ffl Overloading the control statement
  123.       In C++, overloading is allowed only for functionsand operators.  However, overloading the
  124. control statement is useful for simplifying a program[6 , 7].
  125.  
  126.  
  127.  
  128.                                                          Kojima- 2
  129.  
  130.  
  131. ffl Optimization using knowledge of the library
  132.       In C++, operator overloading is resolved by looking only at the arguments of one operator. As
  133. a result, sometimes the execution efficiency may be lost. The execution efficiency will be improved
  134. by using appropriate functions in regard to the pattern.
  135.  
  136. ffl Customization of class definition
  137.       In an object-oriented language such as C++, sometimes an abstract class is defined, to be used
  138. for  the  inheritance.  When  defining  a  class  using  inheritance, programmers  must  have  sufficient
  139. knowledge  of  an  inherited  class.  To  simplify class  definition,  introducing  a  new  construct  is  an
  140. effective way of defining the subclasses of a specific class.
  141.  
  142.  
  143.  
  144. 2.2     A Language Translator Generator for Extending C++
  145.  
  146.  
  147.  
  148. Frequently, conventional extensions for a strongly typed, object-oriented language have b eendone
  149. by directly modifying the base language system. One drawback of this method, however, is that at
  150. the start of a system-specific language design, the specifications of language are not usually clear,
  151. and  therefore, must  be  decided  experimentally.  Furthermore, in  a  practical  language  extension,
  152. it  is  necessary  to  handle  several  libraries  provided  for  supporting  various  aspects  of  a  system.
  153. Consequently, it is necessary to design a simple method of extending a language.
  154.  
  155.  
  156. OPTEC  is  a  language  translator  generator  for  extending  C++.  The  purpose  of  OPTEC  is  to
  157. facilitate the construction of a system-specific language for each system architecture and associated
  158. class libraries.  OPTEC automatically generates a language translator from a specification of the
  159. extension. To simplify specification of the translation, a tree rewriting method is adopted, in which
  160. a syntax tree for the source code is converted by transformation rules.  The language translator
  161. converts  a  source  code,  using  extended  C++,  into  a  non-extended  C++  code.   The  reason  for
  162. choosing C++ as a base language is that many programmers arefamiliar with C language;  from
  163. which C++ was derived.
  164.  
  165.  
  166. Figure 1 illustrates the software organization ofthe OPTEC system. Language extension definitions
  167. are described separately with 2 source files. One is for syntax extension definition, and the other is
  168. for transformation rules. A translator is constructed as follows: First, the parser generator creates
  169. a YACCsource with a syntax extension definition and a YACC template file, in which C++ syntax
  170. is defined.  The parser generator also creates a parser for rule descriptions.  Then, transformation
  171. rules are processed with default rules, and the C++ program for the tree transformer is generated.
  172. During this process, the template pattern and the semantic predicates of the rules are preprocessed
  173. by the pattern compiler for making later rule selection efficient.
  174.  
  175.  
  176.  
  177. 3      Comparison
  178.  
  179.  
  180.  
  181. The C++ language provides a semantic extension mechanism called overloading,  however,  over-
  182. loading of C++ is restricted to operators and functions.  Therefore, an effective way for extending a
  183. programming language would be to generalize the overloading.  In order to generalize overloading,
  184. a feature for handling attributes of the tree, such as adding new attributes to a tree and controlling
  185. a scope, should be included in the extension mechanism.  Although there have been many macro
  186. expansion systems developed[8], most macro expansion methods which use syntactical pattern only,
  187. have difficulty in handling semantics in the extensions.
  188.  
  189.  
  190. In the language extension prototype system TXL by Cordy[9], variable and type declaration are
  191.  
  192.  
  193.                                                          Kojima- 3
  194.  
  195.  
  196.  
  197.  
  198.  
  199.                                     Figure 1: Organization of OPTEC system
  200.  
  201.  
  202.  
  203. handled by the dynamic rule creation, that is, rules that corresp ond each variable name are created.
  204. Although  this  method  is  very  effective, a  complicated  rule  description  is  needed  and  there  are
  205. problems in the execution efficiency.
  206.  
  207.  
  208. Cheatham et al[10 ] introduced data type to tree rewriting,which is derived from semantic analysis,
  209. and used data type as one of the elements that compose the tree pattern. They used this method
  210. to refine an abstract program into a concrete program[6].  Cheathamshowed that the modularity
  211. of  rules  are  improved  by  specifying  the  transformation  with  data  types  in  the  examples  for  the
  212. optimization of code and overloading of control statements.  However, they did not consider the
  213. extension of variable and type declarations. Their system used a semantic analizer for their base
  214. language, and once the replacement of the tree occurs, the semantic analysis is performed for that
  215. tree  again.  Therefore,  when  the  variable  or  the  type  declaration  is  inserted,  it  is  necessary  to
  216. perform the semantic analysis over the entire scope in which the declaration has effect.
  217.  
  218.  
  219. On the other hand, the tree rewriting methods havealso b een studied for building a compiler code
  220. generator[11 , 12 ].  Aho et al[11 ] introduced synthesized attributes to the tree rewriting metho d.
  221. The attributes represent the target machine instruction set, such as the kind of register.
  222.  
  223.  
  224. The rewriting method used in OPTEC is basically an extension of Aho's method. In the compiler
  225. code  generation, variable  and  type  declarations  are  processed  before  the  code  generation  phase.
  226. However, in the language extension, since the declaration will be inserted by the tree rewriting, it
  227. is necessary to do a semantic analysis for variables and types at the rewriting phase.  Therefore,
  228. in OPTEC, features to handle synthesized and inherited attributes in the attribute grammar[13 ]
  229. are  introduced  to  the  transformation  rules  to  permit  flexible  transformation.   In  the  attribute
  230. grammar, variable declaration is propagated as an inherited attribute through the tree in the scope.
  231. In OPTEC, to perform transformation efficiently, attributes of variables, such as data types, are
  232. stored in a symbol table, and functions for manipulating a symbol table are provided. Furthermore,
  233. programming using inherited attributes enables complicated transformation,  which is difficultin
  234. conventional tree rewriting methods.
  235.  
  236.  
  237.  
  238.                                                          Kojima- 4
  239.  
  240.  
  241. References
  242.  
  243.  
  244.  
  245.   [1] B. Liskov, "The Argus Language and System," in Distributed Systems, Lecture Notes No.190,
  246.       Springer Verlag, 1984.
  247.  
  248.  
  249.   [2] B.  Liskov, A.  Snyder,  R.  Atkinson, and  C.  Schaffert, "Abstraction  Mechanisms  in  CLU,"
  250.       Comunications of ACM, vol. 20, no. 8, pp. 564-576, 1977.
  251.  
  252.  
  253.   [3] M. Elis and B. Stroustrup, The Annotated C++ Reference Manual. Addison Wesley, 1990.
  254.  
  255.  
  256.   [4] N. Gehani and W. Roome, The Concurrent C Programming Language. Silicon Press, 1989.
  257.  
  258.  
  259.   [5] Y. Ishikawa, H. Tokuda, and C. Mercer, "Real-Time Object-Oriented Language Design: Con-
  260.       structors for Timing Constraints," Tech. Rep. CMU-CS-90-111, CMU, 1990.
  261.  
  262.  
  263.   [6] T. Cheatham, "Reusability Through Program Transformations," IEEE Trans. Software Engi-
  264.       neering, vol. SE-10, no. 5, pp. 589-594, 1984.
  265.  
  266.  
  267.   [7] J.  Katzenelson,  "Intro duction  to  Enhanced  C(EC),"  Softw.  Pract.  Exper.,  vol.  13,  no.  7,
  268.       pp. 551-576, 1983.
  269.  
  270.  
  271.   [8] P. Layzell,"The history of macro processors in programming language extensibility,"Computer
  272.       Jornal, vol. 28, no. 1, pp. 29-33, 1985.
  273.  
  274.  
  275.   [9] J. Cordy and E. Promislow, "Specification and Automatic Prototype Implementation of Poly-
  276.       morphic Objects in TURING Using the TXL Dialect Processor," in Proceedings of IEEE 1990
  277.       ICCL, pp. 280-285, 1990.
  278.  
  279.  
  280. [10]  T.  Cheatham,  G.  Holloway,  and  J.  Townley,  "Program  Refinement  By  Transformation,"  in
  281.       Proceedings of 5th IEEE International Conference on SoftwareEngineering, pp. 430-437, 1981.
  282.  
  283.  
  284. [11]  A. Aho and M. Ganapathi, "Efficient Tree Pattern Matching an Aid to Code Generation," in
  285.       Proceedings of 12th ACM POPL, pp. 334-340, 1984.
  286.  
  287.  
  288. [12]  A.  Aho,  R.  Sethi,  and  J.  Ullman,  Compilers,  Principles,  Techniques,  and Tools.  Addison
  289.       Wesley, 1986.
  290.  
  291.  
  292. [13]  T. Reps, Generating Language-Based Environments. The MIT Press, 1984.
  293.  
  294.  
  295.  
  296. Biography
  297.  
  298.  
  299. TaizoKo jima has been a researcher at Mitsubishi Electric Corporation's Central Research Labora-
  300. tory since 1982. His current intrests include object-oriented systems, distributed systems, database
  301. systems, and application-oriented programming environment He developed several application sys-
  302. tems for practical use. Kojima received a BME from University of Tokyo in 1982.
  303.  
  304.  
  305. Akira Sugimoto has been a researcher Mitsubishi Electric Corporation's Central Research Labo-
  306. ratory since 1979. He leads research on object-oriented software engineering, visual programming,
  307. and user interface systems. He received a BS and a MS degrees from Kyoto university in 1977 and
  308. 1979, and Dr degree from University of Tokyo in 1989.
  309.  
  310.  
  311.  
  312.                                                          Kojima- 5
  313.