Meta-Programming and Model-Driven Meta-Program Development www.it-ebooks.info Advanced Information and Knowledge Processing Series Editors Professor Lakhmi C. Jain lakhmi.jain@unisa.edu.au Professor Xindong Wu xwu@cs.uvm.edu For further volumes: http://www.springer.com/series/4738 www.it-ebooks.info Vytautas ˇ Stuikys • Robertas Dama ˇ sevi ˇ cius Meta-Programming and Model-Driven Meta-Program Development Principles, Processes and Techniques 123 www.it-ebooks.info Prof. Vytautas ˇ Stuikys Software Engineering Department Kaunas University of Technology Kaunas Lithuania Robertas Dama ˇ sevi ˇ cius Software Engineering Department Kaunas University of Technology Kaunas Lithuania ISSN 1610-3947 ISBN 978-1-4471-4125-9 ISBN 978-1-4471-4126-6 (eBook) DOI 10.1007/978-1-4471-4126-6 Springer London Heidelberg New York Dordrecht Library of Congress Control Number: 2012943398 © Springer-Verlag London 2013 This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Printed on acid-free paper Springer is part of Springer Science+Business Media (www.springer.com) www.it-ebooks.info Preface Information communication technologiesare further advancing at an uninterruptible rate. The technology advances resulted in creating the computing infrastructure which, even at the current maturity level, can be called by a general term ‘digital world’, where humans are working with computer-based systems everywhere: in the office, at home, during travel, at entertainment spots, etc. What is most important in this case is that they can do that at any time. As computational-communicational capacities within the digital infrastructure are constantly increasing, we need more and more software. The software content in modern systems within the digital infrastructure is growing perhaps at the similar rate as technology advances. The aim of the book is to look at the field from different perspectives: (1) histor- ical evolution of the meta-programming concept; (2) overall analysis of the meta- programming principles and techniques as they are treated in software engineering disciplines; (3) focus on the insights of the meta-program development processes in the context of model-driven, feature-based and transformative approaches; (4) taking a background and framework for the further generalization of the paradigm in two dimensions, that is, multi-linguistic and multi-stage programming;and (5) focus on the domain-specific view in programming and meta-programming (domain- specific languages, a diverse of application domains such as hardware design, embedded software, e-learning, etc.). In general, the meta-programming paradigm can be conceived of as a generative technology enabling to generalize the program development process and to build domain program generators. Though there are many solutions discussed in the literature (especially language-based for both kinds of meta-programming, i.e. homogeneous and heterogeneous, e.g. within software product families, etc.), but how the technology is to be bound with the application domain models in a systematic way is yet little known. The distinguishing features of the book are as follows: (1) taxonomy of meta- programming concepts based on the retrieval, analysis and evaluation of the scientific data and knowledge on the subject; (2) the concept of structural hetero- geneous meta-programming based on the original meta-language Open PROMOL; (3) the model-driven concept to the meta-program development process, including v www.it-ebooks.info vi Preface the concept of forward and reverse transformations within the evolution-based framework to develop and maintain heterogeneous meta-programs and staged meta-programs (i.e. heterogeneous meta-meta-programs); (4) metrics to evaluate the complexity of feature-based models and meta-programs; (5) the high-level specification of meta-programs using feature-based models that are described by feature diagrams (including their extensions); and (6) a variety of academic research case studies within the different application domains to experimentally verify the soundness of the investigated approaches. One feature of the book as an important research result should be highlighted separately. Though the dedicated meta-language Open PROMOL has been devel- oped to support and better understand the principles of structural heterogeneous meta-programming, this programming paradigm is independent upon the use of the meta-language type. We have shown (using Java and PHP languages as case studies) that a general-purpose programming language can also be used in the role of a meta-language, when this meta-programming paradigm is applied. In this case, however, the only part of the language that need be used is a subset relevant to textual manipulations. How has the book been written? For more than the last decade, we were involved (and we are till now involved) in the intensive academic research on the topic. As a result, we have published about 70 scientific papers in journals and conference proceedings worldwide. Thus, a large amount of the book content was extracted from our published papers, but this content was revised and extended taking into account a broad context of the large research communities that are considering the same or related topics. To create, outline the context and combine it with our original ideas, we needed to read and analyse more than 390 references. It was possible because our teaching courses are closely related with our research activities. Thus, the book is a monograph, in which we present the results of our research activities. What is the content of the book? We have divided the content of the book into three parts, where we consider the following topics: basics of meta-programming, model-driven view to meta-programming and transformations, some generalization aspects of heterogeneous meta-programming and variability modelling and applica- tions of meta-programming relevant to our research. Part I includes (1) Introduction (Chap. 1), (2) Taxonomy of Fundamental Con- cepts of Meta-Programming (Chap. 2), (3) A Background of Meta-Programming Techniques (Chap. 3), (4) Homogeneous Meta-Programming Techniques with Case Study (Chap. 4), (5) Structural Heterogeneous Meta-Programming (Chap. 5)and (6) Open PROMOL: An Experimental Meta-language for Heterogeneous Meta- Programming (Chap. 6). Part II includes (1) A Framework to Deal with Heterogeneous Meta- Programming in Large: Meta-Program Lifecycle (Chap. 7), (2) A Model-Driven View to Meta-Program Development Process (Chap. 8), (3) Cognitive Insights into Feature Diagram Notation and Beyond (Chap. 9), (4) Meta-Programming Task Specification Using Feature Diagram Patterns (Chap. 10), (5) Meta-Program Development as a Model Transformation Process (Chap. 11) and (6) Complexity Evaluation of Feature-Based Specifications and Meta-Programs (Chap. 12). www.it-ebooks.info Preface vii Part III includes (1) A Framework: How Can Heterogeneous Meta-Programs Be Further Generalized? (Chap. 13), (2) Meta-Meta-Programming and Equivalent Transformations of Heterogeneous Meta-Programs (with Examples Using PHP as a Meta-language) (Chap. 14), (3) Multi-linguistic Aspects of Heterogeneous Meta-Programming in Web Applications (Chap. 15), (4) Applications of Meta- Programming (Chap. 16) and (5) What Is on the Horizon? Who might be interested in reading the book? The book’s content covers (of course, to some extent) the topics that are to be or might be studied as research issues at the postgraduate level in the Computer Science and Software Engineering specialities. Thus, master-level and PhD students can benefit from reading the book in the first place. We hope that their supervisors and lecturers can also find pertinent and useful information here. As we were seeking for throughout the book to identify the links of our concepts with the modern software design methodologies, we believe that software experts will obtain useful ideas to support their solutions too. Though the notion of meta-programming was introduced almost from the emergence of computer science, it still has to live up to its promises: software reuse and automated program development. A major stumbling block to achieving the promised benefits is the understanding and learning of the meta-programming approach. One reason may be that we do not yet thoroughly understand the fundamental concepts that define meta-programming. The difficulties with the meta-programming approach are related to the following stages: (1) understand- ing, (2) adoption and (3) application of the meta-programming methods. Meta- programming does not allow for its promises to be achieved straight away. Rather, it demands a thorough domain analysis, investment into the creation of meta- programming tools such as meta-language processors, development of generic component libraries and code generators, etc. The payoff will come only after some time, and designers will have to accept that. Adoption of meta-programming also requires some shift in the attitudes and mind-sets of software developers. Currently, a majority of programmers and designers are accustomed to producing specific solutions and applications for a particular domain problem. They like to reuse the existing software artefacts, but not much is done and invested into designing for reuse. How should the book be read or studied? This depends on the reader’s previous knowledge and his or her intention. For novices, we suggest first to read Part I only. For concreteness, we suggest they also look at the relevant illustrative examples in the other parts (usually given in another context) and to solve the exercise questions given at the end of each chapter. At the next level – for example, for learning – one might choose or create some environment to test the ideas described in a particular chapter. Experts and knowledgeable researchers first could read the introductory and concluding parts of each chapter, or some selected chapters depending on the reader’s preference. If they find the ideas discussed interesting, then they may wish to explore the more involved and intensive studies within a particular chapter, or even to explore the referenced sources. www.it-ebooks.info Acknowledgements Authors would like to thank Dr. Gintautas Grigas and anonymous reviewers for their valuable suggestions and comments that largely contributed to make the book’s content improvements. Our sincere thanks are also to Helen Desmond, the Associate Editor, for her excellent management during the book preparation for publishing. We would like also to express our gratitude to the Series Editors Professor Lakhmi C. Jain and Professor Xindong Wu for their contribution and editing suggestions during the final stages of the book publishing. The technical quality of the book could not have been improved without the endeavours and contributions of Ben Bishop, Editorial Assistant at Springer London, and V. Sabarirajan, Senior Project Manager at SPi Content Solutions. With thanks also to our family members for their patience, encouragement and understanding. R. Dama ˇ sevi ˇ cius especially would like to thank his wife Vaida and sons Paulius and Matas for their patience and sensibility shown during the writing of this book. ix www.it-ebooks.info Contents Part I 1 Introduction 3 1.1 What Is Meta-Programming? 3 1.2 Origins of Meta-Programming and Its Evolution 5 1.3 Other Definitions of Meta-Programming 7 1.4 Why Is Meta-Programming Needed? 8 1.5 Meta-Programming as a Higher-Level Thinking Paradigm to Develop Systems 11 1.6 The Topics This Book Addresses 11 1.7 Summary and Concluding Remarks 12 1.8 Exercise Questions 13 References 13 2 Taxonomy of Fundamental Concepts of Meta-Programming 17 2.1 What Is Taxonomy? 17 2.2 Fundamental Concepts of Meta-Programming 17 2.2.1 Transformation 18 2.2.2 Generation 19 2.2.3 Meta-Program 19 2.2.4 Levels of Abstraction 20 2.2.5 Generalization 21 2.2.6 Separation of Concerns 21 2.2.7 Reflection 22 2.2.8 Metadata 22 2.3 Taxonomy of Meta-Programming Concepts 22 2.4 Analysis of Meta-Programming Sources 25 2.5 What Can One Learn from Meta-Programming Taxonomy? 25 2.6 Summary 28 2.7 Exercise Questions 28 References 28 xi www.it-ebooks.info xii Contents 3 A Background of Meta-Programming Techniques 31 3.1 Introduction 31 3.2 Preliminary Principles 32 3.3 Fundamental Principles of Meta-Programming 33 3.3.1 Separation of Concepts 33 3.3.2 Taxonomy Axes to Describe Relationships Between Concepts 35 3.3.3 Levels of Abstractions and Meta-Programming 37 3.3.4 Integration of Concepts 38 3.4 Process-Based Relationships of Meta-Programming Concepts 39 3.5 Multidimensional Separation of Concepts and Meta-Programming 41 3.6 Representation of Meta-Programming Concepts Using Feature Diagrams: MDSoC View 43 3.7 Summary and Evaluation 45 3.8 Exercise Questions 46 References 46 4 Homogeneous Meta-Programming Techniques with Case Study 49 4.1 Introduction 49 4.2 Language-Independent Aspects of Homogeneous Meta-Programming 50 4.3 Terminology, Taxonomy and Formal Description of Homogeneous Meta-Programming Domain 52 4.3.1 Functional Homogeneous Meta-Programming 52 4.3.2 Structural Homogeneous Meta-Programming 55 4.3.3 Mixed Homogeneous Meta-Programming 57 4.4 Homogeneous Meta-Programming in Java 58 4.4.1 Basic Built-In Abstractions 58 4.4.2 Taxonomy of Homogeneous Meta- Programming Techniques in Java 59 4.4.3 Functional Homogeneous Meta- Programming Techniques 60 4.4.4 Structural Homogeneous Meta- Programming Techniques 62 4.5 Homogeneous Meta-Programming in VHDL 66 4.5.1 Similarities and Differences Between VHDL and General-Purpose Programming Languages (GPLs) 66 4.5.2 Component Generalization Framework in VHDL 67 4.6 Case Study: Development of Generic GATE Component in VHDL 68 4.6.1 Formulation of Requirements 68 4.6.2 Development of Generic Interface 69 www.it-ebooks.info [...]... basics of meta- programming, model- driven view to metaprogramming and transformations, generalization aspects of heterogeneous www.it-ebooks.info 12 1 Introduction meta- programming, variability modelling and applications of meta- programming relevant to our research Part I includes (1) Introduction (Chap 1), (2) Taxonomy of Fundamental Concepts of Meta- Programming (Chap 2), (3) A Background of Meta- Programming. .. heterogeneous meta- programming per se in Parts II and III of the book 1.4 Why Is Meta- Programming Needed? As a meta- program produces another program, it is often said that the meta- program is a program generator Thus, meta- programming is about creating programs automatically The automatic program creation is a value per se Such a statement, at some extent, motivates the need of meta- programming as... boundaries of programming in constructing programs automatically The reader should not be confused with the prefix meta , which means here ‘higher level’ Two important observations follow from the definition: 1 Meta- programming and programming are subjects of the same field; thus, meta- programming cannot be conceived without knowing the fundamentals of programming 2 Meta- programming deals with automatic programming. .. Examples of meta- programs are application generators such as parser generators Meta- programming then can be defined as ‘creating application programs by writing programs that produce programs’ [Lev86] Sheard [She01] emphasizes the role of meta- programming in program generation explicitly He says that in a meta- programming system, meta- programs manipulate object-programs’ A meta- program is a program, which... thinking and reasoning in analysis and modelling As a result, the researchers have recently introduced new design paradigms expressed and described through such terms as meta- model and meta- analysis, meta- meta -model, meta- design or even meta- engineering [Den84] Here, we generalize all these terms using one word – meta- thinking In terms of meta- programming, by meta- thinking we mean the social aspects of meta- programming. .. the same concepts as meta- programming Furthermore, meta- programming techniques closely relate to novel software development technologies such as aspect-oriented programming [KLMC97] Thus, meta- programming is widely used in the software development cycle where it plays an essential role in program interpreters and compilers Metaprogramming as a conceptual approach continues to evolve and its principles... Meta- Programming Techniques with Case Study (Chap 4), (5) Structural Heterogeneous Meta- Programming (Chap 5) and (6) Open PROMOL: An Experimental Meta- Language for Heterogeneous MetaProgramming (with comparative studies against other languages) (Chap 6) Part II includes (1) A Framework to Deal with Heterogeneous MetaProgramming in Large: Meta- Program Lifecycle (Chap 7), (2) A Model- Driven View to Meta- Program. .. understand meta- programming at the definition level as a specific field of programming There is a great deal of definitions of the term meta- programming This phenomenon is important per se providing slightly different aspects and views for better understanding of the topic This understanding may vary, depending on the context and aims We summarize three different views on meta- programming: 1 Meta- programming. .. meta- thinking we mean the social aspects of meta- programming in the first place [FGYC04] We explain these aspects in more details later By introducing this term here, we aim to send a message to the reader that meta- programming is also about meta- analysis, meta- models, meta- program and meta- meta -program development and other related tasks as it is stated by the term model- driven view’ in the title of the book... Heterogeneous Meta- Programs Be Further Generalized? (Chap 13), (2) Meta- Meta -Programming and Equivalent Transformations of Heterogeneous Meta- Programs (with examples using PHP as a Meta- Language) (Chap 14), (3) Multi-linguistic Aspects of Heterogeneous Meta- Programming in WEB Applications (Chap 15), (4) Applications of MetaProgramming Methodology (Chap 16) and (5) What Is on the Horizon? 1.7 Summary and Concluding . of meta- programming, model- driven view to meta- programming and transformations, some generalization aspects of heterogeneous meta- programming and variability modelling and applica- tions of meta- programming. 3 1.1 What Is Meta- Programming? 3 1.2 Origins of Meta- Programming and Its Evolution 5 1.3 Other Definitions of Meta- Programming 7 1.4 Why Is Meta- Programming Needed? 8 1.5 Meta- Programming as. Variability Modelling and Meta- Programming 123 7.7 Design-for-Change, Context Modelling and Meta- Programming 124 7.8 Summary 125 7.9 Exercise Questions 125 References 126 8 A Model- Driven View to Meta- Program