Tải bản đầy đủ (.pdf) (329 trang)

meta programming and model driven meta program development

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (7.73 MB, 329 trang )

Meta-Programming and Model-Driven
Meta-Program Development
www.it-ebooks.info
Advanced Information and Knowledge Processing
Series Editors
Professor Lakhmi C. Jain

Professor Xindong Wu

For further volumes:
/>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
Contents xiii
4.6.3 Development of Generic Architecture 71
4.6.4 How Generic Component Is Used
to Compose a Higher-Level Component/System 73
4.7 Summary 73
4.8 Exercise Questions 74
References 75
5 Structural Heterogeneous Meta-Programming 79
5.1 Introduction 79
5.2 Analysis of Structural Meta-Programming 79
5.3 Basics of Heterogeneous Meta-Programming 81

5.3.1 Explicit Separation of Concerns: A
Two-Dimensional Model 82
5.3.2 Integration of Separated Concerns 84
5.3.3 Component Instance Models 86
5.3.4 Generic Component Models 87
5.4 Pre-Requirements for Meta-Languages 88
5.5 Summary, Evaluation and Conclusions 91
5.6 Exercise Questions 91
References 92
6 Open PROMOL: A Meta-Language for Heterogeneous
Meta-Programming 93
6.1 Introduction and Motivation 93
6.2 What Concepts Does the Language Implement? 94
6.3 Basic Features of the Syntax and Semantics 97
6.4 Main Capabilities of the Language 97
6.5 Case Study: VHDL Code Modification via Widening,
Narrowing and Isolation 99
6.6 Comparative Studies 100
6.6.1 Open PROMOL vs. Java (CCC) as Meta-Languages . 100
6.6.2 PHP as Meta-Language for Web-Based Applications . 105
6.7 Evaluation of the Approach 107
6.8 Summary, Current State of the Language and Conclusions 108
6.9 Exercise Questions 109
References 110
Part II
7 A Framework to Deal with Heterogeneous Meta-
Programming in Large: Meta-Program Lifecycle 115
7.1 Introduction 115
7.2 Preliminary Assumptions and Motivation 116
7.3 General Description of the Framework 117

7.4 Roles of Actors Within the Framework 119
7.5 Meta-Design, Design Spaces and Meta-Programming 121
www.it-ebooks.info
xiv Contents
7.6 Domain 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 Development Process 127
8.1 Introduction 127
8.2 Related Works 128
8.3 Framework for Model-Driven Analysis of Meta-
Program Development 129
8.3.1 Basic Assumptions and Terminology 129
8.3.2 Description of the Framework 131
8.3.3 Meta-Model to Specify Problem Domain Abstractions 132
8.3.4 Instances of FD Meta-Model 134
8.3.5 Elements of the Instance of Meta-Program
Meta-Model 137
8.4 Interpretation of Transformations 137
8.5 Requirements for Tools to Support (Semi-) Automatic
Development of Meta-Programs 139
8.6 Summary and Evaluation 140
8.7 Exercise Questions 141
References 141
9 Cognitive Insights into Feature Diagram Notation and Beyond 143
9.1 Introduction 143
9.2 Overview of Feature Variability Management Research 144
9.3 Introduction into Feature Diagrams 145

9.3.1 Feature Definitions and Original Context of Use 145
9.3.2 Feature Model 145
9.3.3 Feature Types 146
9.3.4 Feature Diagram Definition and Variants of Notation . 147
9.3.5 Basic Set of Abstractions in Standard
Feature Diagram 150
9.4 Extensions of Feature Diagrams 150
9.4.1 Ontology-Based Extension 150
9.4.2 Extension for Quality-Oriented Modelling 152
9.4.3 Feature Diagram Extension for Variation
Sequence Modelling 156
9.4.4 Other Known Extensions of Feature
Diagram Notation 163
9.5 Summary 165
9.6 Exercise Questions 165
References 166
www.it-ebooks.info
Contents xv
10 Meta-Programming Task Specification Using Feature-
Based Patterns and Domain Program Scenarios 171
10.1 Introduction 171
10.2 Problem Statement 171
10.3 Binding the Task with Other Domains 173
10.3.1 Analysis of Feature-Based Modelling Research 173
10.3.2 Analysis of Program Understanding Research 174
10.4 Framework to Consider Meta-Program Specification Tasks 178
10.5 Concept of Feature-Based Patterns 180
10.5.1 Definitions 180
10.5.2 Elements of Feature Diagram Instance as Patterns 182
10.5.3 Some Properties of Patterns 184

10.6 Summary, Evaluation and Further Research 185
10.7 Exercise Questions 185
References 186
11 Meta-Program Development as a Model Transformation Process 189
11.1 Introduction 189
11.2 Meta-Program Development Strategies 189
11.3 Transformation Tasks 190
11.4 Meta-Program Understanding and Concept
of Multi-Stage Meta-Programming 191
11.4.1 Definition of Basic Terms 191
11.4.2 Understanding of One-Stage Meta-Programs 192
11.4.3 Understanding of Multi-Stage Meta-Programs 192
11.4.4 Static and Dynamic Analysis and Properties
of Models for Understanding 195
11.5 Representation of Source Models 198
11.6 Representation of Target Model and Overall Design Process 200
11.7 Transformation Rules and Methodology 202
11.7.1 Stages of the Methodology 202
11.7.2 Transformation Rules with Example 202
11.8 Summary, Evaluation and Conclusions 206
11.9 Exercise Questions 206
References 207
12 Complexity Evaluation of Feature Models and Meta-Programs 209
12.1 What Is Complexity? 209
12.2 Complexity Management 210
12.3 Complexity Metrics 211
12.4 Complexity Measures of Feature Models
as Meta-Programs Specifications 213
12.5 Evaluation of Abstraction Levels 216
12.6 Complexity of Meta-Programs and Meta-

Programming Techniques 221
www.it-ebooks.info
xvi Contents
12.7 Complexity Metrics of Heterogeneous Meta-Programs 222
12.7.1 Information Dimension: Relative
Kolmogorov Complexity 222
12.7.2 Meta-language Dimension: Meta-language Richness 223
12.7.3 Graph Dimension: Cyclomatic Complexity 223
12.7.4 Algorithmic Complexity: Normalized Difficulty 224
12.7.5 Cognitive Complexity: Cognitive Difficulty 225
12.8 Complexity of Homogeneous Meta-Programming 225
12.9 Theoretical Validation of Complexity Metrics 227
12.10 Examples of Meta-Program Complexity Calculation 229
12.10.1 Complexity of Heterogeneous Meta-Programs 229
12.10.2 Complexity of Homogeneous Meta-Programs 231
12.11 Summary, Evaluation and Future Work 232
12.12 Exercise Questions 234
References 235
Part III
13 A Framework: How Can Heterogeneous Meta-Programs
Be Further Generalized? 241
13.1 Introduction 241
13.2 A Framework to Analyse Generalization 242
13.2.1 Generalization Concept and Tasks 242
13.2.2 Why Structural Generalization Is Needed? 243
13.2.3 Why More Than Two Languages Are Needed? 245
13.2.4 More About the Language Aspects 245
13.2.5 Combining the Development and Evolution
Stages Through Prediction and Anticipation 248
13.3 Summary 249

13.4 Exercise Questions 249
References 250
14 Meta-Meta-Programming and Equivalent
Transformations of Heterogeneous Meta-Programs 253
14.1 Introduction 253
14.2 Related Works 253
14.3 Definitions of Basic Terms 256
14.4 Transformation Tasks 262
14.5 Transformation Method 263
14.6 Transformation Properties 265
14.7 Theoretical Background and Formal Description 267
14.8 Transformation-Based Processes to Develop
Multi-Stage Meta-Programs 270
www.it-ebooks.info
Contents xvii
14.9 Summary, Discussion and Evaluation 273
14.10 Conclusions 274
14.11 Exercise Questions 274
References 275
15 Multi-Linguistic Aspects of Heterogeneous Meta-
Programming in Web Applications 279
15.1 Introduction 279
15.2 A Survey of Technologies to Support Portal Development 279
15.3 Identification of Typical Web Components 281
15.4 Problem Statement 282
15.5 Properties of Web Component Instances 283
15.6 Web Component Generator Model 284
15.7 Analysis of Web Generators Designed Using
Multi-Linguistic Meta-Programming 286
15.8 Summary, Evaluation and Conclusions 286

15.9 Exercise Questions 289
References 289
16 Applications of Meta-Programming Methodology 291
16.1 Introduction 291
16.2 Meta-Programming in HW Design 292
16.3 Meta-Programming for Creating LOs for Teaching HW Design . 293
16.4 Context-Related Modelling and Meta-Programming
for Embedded SW Domain 297
16.5 Meta-Programming as Component Wrapping Technology 302
16.5.1 Communication-Based Design 303
16.5.2 Reliable System Design 308
16.6 Internet-Based Application of Meta-Programming 309
16.7 Summary and Evaluation 311
16.8 Exercise Questions 314
References 315
What Is on the Horizon? 317
Glossary 321
Index 323
www.it-ebooks.info
Part I
www.it-ebooks.info
Chapter 1
Introduction
1.1 What Is Meta-Programming?
At the very beginning, our aim is to describe a scheme for the initial understanding
of meta-programmingin order to introduce the knowledge required for the thorough
studies in the field later. We start from the statement which gives a very general
definition and formulates the primary objectives of the field as follows:
Meta-programming is a higher-level programming paradigm aiming to extend the bound-
aries 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 also known as program
generation.
We can look at the programming field from a very simplified perspective.
In the simplest case, programming is the activity (process) of writing programs
for a computer system. More specifically, this process can be described as a
transformation of a given task into the executable specification a computer can
interpret. Usually we call this executable specification a computer program, which
is the product of programming. How a human being translates a real-world task into
a computer program is a matter of programming – a very wide field of science and
engineering.
Currently, programming as a field of human activity is deeply integrated within
the countless appliances of information technology. Often, not only domain profes-
sionals, software engineers or computer scientists but also other actors having some
knowledge in computing are able to write programs and, in this way, are involved
in programming. This is happening because programming is not a homogeneous
V.
ˇ
Stuikys and R. Dama
ˇ
sevi
ˇ
cius, Meta-Programming and Model-Driven Meta-Program
Development, Advanced Information and Knowledge Processing,
DOI 10.1007/978-1-4471-4126-6
1, © Springer-Verlag London 2013

3
www.it-ebooks.info
4 1 Introduction
discipline and consists of many sub-fields (algorithms, programming languages,
operating systems, Internet and distributed programming environments, concurrent
programming, etc.).
It is not our intention to analyse programming in all aspects to which this
paradigm relates, but in this context, it is more important to focus on two aspects
only:
1. On the program structure
2. On the execution process of a program
What is the structure of a computer program? Wirth has raised that ques-
tion already in 1975 when he published the book ‘Algorithms C Data Struc-
tures D Programs’ [Wir76]. We interpret the title of the book as a concise definition
of the programming field, that is, programs using formula (1.1):
Program D data structure C algorithm (1.1)
Though formula (1.1) is very simple, its value was not lost over the decades of
programming evolution because this formula expresses and communicates to the
essence of programming. From the perspective of the execution process, formula
(1.1) can be reformulated in the following way: when executed, a program performs
data manipulations on the input data, that is, transforms the input data into the output
data. The transformation process is performed according to the rules specified by
operations of an algorithm. With respect to the second aspect, the symbol ‘C’in
formula (1.1) denotes manipulations. In that sense, programming is a process of
writing programs and then automatic solving of various computational and other
tasks resulting in creating the output data as a solution of the task.
Now we can look at the meta-programming field in a similar way that was used
to describe the essence of programming. Indeed, meta-programming is an extension
of programming as it was stated at the very beginning. The extension includes two
views to generalization:

1. Generalization of an algorithm
2. Generalization of data
With regard to generalization of data, one can ask: what are data, in what aspects
are they different from programs and in what aspects are they similar to them? Data
and programs are syntactically pre-specified sets of symbols from the same alphabet
arranged according to some predefined order of grammar. In that sense, programs
and data are not very different. Of course, in each context we may use different
syntactic rules enabling to form different structures of data and programs. Data and
programs differ in semantics, that is, in how they are interpreted and what result is
yielded after the interpretation.
As a result of the discussion, we conclude two important findings:
1. Program is some generalization of data.
2. In order to manipulate a program as a generalization of data, we need to
generalize an algorithm too and to use a meta-algorithm rather than an algorithm.
www.it-ebooks.info
1.2 Origins of Meta-Programming and Its Evolution 5
Now we can apply the stated findings to the introduced formula (1.1), aiming
to express the essence of meta-programming. We can rewrite formula (1.1)inthe
following way:
Meta-program D program ˚ meta-algorithm (1.2)
Here, the term ‘meta-algorithm’, meaning the higher-level algorithm, is used in
the sense of generalization of an algorithm. In other words, arguments for meta-
operations within a meta-algorithm are programs or their parts, but not data. The
term ‘program’ is used in the sense of the data generalization. The symbol ‘˚’has
the meaning ‘higher-level program manipulations’.
Now looking at formula (1.2), one can better understand the following definition
of meta-programming:
Meta-programming is a higher-level programming paradigm which deals with how manip-
ulating programs as data is performed. The result of the manipulation is the lower-level
program, not data.

After the insight into the meaning and definition of meta-programming, we
continue with a historical review of the field.
1.2 Origins of Meta-Programming and Its Evolution
The very beginning of meta-programming can be traced back to the EDVAC
computer in the 1940s [Tem95]. The new concept implemented in the EDVAC’s
design was to store data and programs in the same memory space. This allowed
manipulating programs in the same way as data at run time. Later the modification
of program code at run time initiated by an external program (such as a compiler or
a debugger) has become a standard practice.
In 1959, the Share 709 system (a suite of system software for the IBM 709
computer) introduced the idea of programmer macros as a sequence of computing
instructions available in a single program statement. The aim of macros was to save
time and avoid errors in writing a sequence of instructions that repeats often in a
program [GK59].
In 1966, the IBM/360 system with a high-level programming language PL/1
has been introduced. This language had the preprocessing capabilities to modify, at
some extent, the source code before translation. Preprocessing as the simplest form
of meta-programming has been implemented in many programming environments
and is still used. The IBM/360 and its derivatives also had powerful macro-
assembler facilities to generate complete programs or sections of programs.
Another idea that influenced the emergence of meta-programming was the
concept of frame languages proposed by Minsky for knowledge representation
[Min75]. In the frame language, the data is represented in units, called frames.
Frames contain not only information about the problem domain but also knowledge
www.it-ebooks.info
6 1 Introduction
about the stored data. Provision of access to this meta-information enables to write
programs that can deal not only with knowledge but also with knowledge about
knowledge (‘meta-knowledge’).
Manipulation of the program source code is one of the main aspects of any

software development process. As the size and complexity of software are growing
continuously, the manual manipulation becomes ever more infeasible. Therefore,
the programmer must be relieved from all repetitive and conceptually redundant
operations in order to focus on solving unresolved domain problems [Rid99]. This
means that the manipulation of a source code must be automated as much as possible
by allowing the tools to handle all the tasks that do not belong to the domain
problem. Such an automation of repetitive programming tasks can be seen as meta-
level programming or meta-programming.
Meta-programming was also known and used for a long time in formal logic
programming [Pas04]. However, now the scope of the application of the meta-
programming techniques is much wider. These include the domains such as
programming language implementation [BDGC95], including parser and compiler
generation [Ter97], application and software generators [Bat98], product lines
[Bat98], generic component design [Bec00], program transformations [LH01,
ˇ
Stu02], program evaluation and specialization [JGS93], generative reuse [Big98],
software maintenance, evolution and configuration [CE00a], middleware appli-
cations [CS02], XML-based web applications and web component deployment
[LN02].
Applications of meta-programming also include compiler construction, BNF
(Backus-Naur Form) used in compiler generators such as Lex and Yacc [LMB92],
macros, higher-order functions in logic meta-programming [Pas04, Tem95], re-
cursion, reflection [MJD96] including introspection and intercession [CE00b],
meta-classes [KRB91], meta-object protocols [Chi95], template meta-programming
[Tah99], anticipatory optimization [Big98], mixin-based programming [Pet96],
design patterns [Din03], scripting [Ous98], partial evaluation [JGS93], soft IP
(Intellectual Property component) design [
ˇ
SD02], design of generative learning
objects [

ˇ
SD08] and markup languages.
Many, if not all, of the presented cases can be summarized as multi-stage pro-
gramming [Dam05, She01, Tah99], that is, the development of programs in several
different stages. Other approaches such as parameterized programming [Gog96],
generative programming [CE00a], generic programming [DS98, MS89]andre-
flection-oriented programming [Rid99] are very similar or use 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. Meta-
programming as a conceptual approach continues to evolve and its principles
are adapted to the ever-higher levels of abstraction. Examples include meta-
modelling [AK02], meta-design [Dam06, FGYC04], model-driven engineering
(MDE) [Sch06]andmeta-engineering [Pal02].
www.it-ebooks.info
1.3 Other Definitions of Meta-Programming 7
As the pursuit for increased productivity in software engineering continues, the
role of meta-programming is destined to increase. However, meta-programming
is almost never consciously and explicitly integrated in the software development
processes. Gaining awareness of its role is required to achieve progress in this
domain. Understanding what concepts characterize meta-programming is important
to both practitioners, who are aiming to adopt novel design methods, as well as to
researchers.
1.3 Other Definitions of Meta-Programming
There are many viewpoints meta-programming can be analysed from, such as
abstraction, languages, tools or programming techniques. Perhaps, the most popular
is the abstraction-based view explained below. Therefore, we extend the previously
introduced definitions of meta-programming.

Software systems typically consist of several levels of abstraction such as ma-
chine (or object) code, assembly code, algorithmic or object-oriented language code
or directives for preprocessing. Meta-programming, with respect to the abstraction
level, should be understood as programming at a higher-level of abstraction. For
example, Cordy and Shukla give the following definition [CS92]:
Meta-programming is ‘the technique of specifying generic software source templates from
which classes of software components, or parts thereof, can be automatically instantiated
to produce new software components’.
A meta-language, which is a mechanism for introducing a higher-level of
abstraction, does not appear in this definition. It is assumed that ‘source templates’
(such as CCC templates) are higher-level generic abstractions of the source (or
domain) language itself.
Another definition introduces a concept of a meta-language explicitly: ‘any
language or symbolic system used to discuss, describe, or analyze another language
or symbolic system is a meta-language’[Bat98].
A program written in a meta-language is a meta-program. According to
Czarnecki and Eisenecker [CE00b], a meta-program is ‘a program that generates
the source of the application ::: by composing pre-written code fragments’.
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-programmingin program generation
explicitly. He says that in a meta-programming system, ‘meta-programs manipulate
object-programs’. A meta-program is a program, which ‘may construct object-
programs, combine object-program fragments into larger object-programs, observe
the structure and other properties of object-programs’.
Rideau gives a similar definition: ‘Meta-programming, the art of programming
programs that read, transform, or write other programs’[Rid99].
www.it-ebooks.info
8 1 Introduction

The Bartlett’s definition is: ‘Meta-programming is writing programs that
themselves write code’[Bar05].
Veldhuizen expends the view to meta-programming, stating that meta-
programming is ‘the study of generalizations in software and a meta-language
is the one, in which we express those generalizations’[Ve l06].
We accept the latter definition as a roadmap for our vision to the field. On this
basis, we, first, construct the conceptual framework of the topic in Part I of this
book. And, second, we consider also the generalization aspects of 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 a specific kind of pro-
gramming, enabling to achieve higher productivity in system development. Though
there are many driving forces stimulating higher productivity in software design, we
emphasize two dominating factors: (a) complexity of systems to be designed grows
continuously and (b) those systems require more and more software content.
It has already been stated that the basic driving forces that move programming
towards higher abstraction levels resulting in the increased degree of automation
and, in particular, motivate meta-programming are as follows: (a) complexity of
systems and (b) the need for more software in system designs.
These two factors are interrelated and have a tremendous influence on trends,
methods and approaches used in computer-related sciences and engineering. There-
fore, it is vitally important to look at the roots of the problem. First, we look at the
complexity problem in system design from the methodological perspective.
Complexity is the intrinsic attribute of systems and processes through which
systems are created. Complexity measures allow reasoning about system structure,
understanding system behaviour, comparing and evaluating systems or foreseeing
their evolution. As there is no precise definition of the term ‘system’, we refer to

a system as an application with software and hardware parts, such as a program or
a component. The concept of complexity is discussed in many different contexts,
such as system theory, informatics, software engineering and system-on-chip (SoC)
design. Here we discuss the complexity issues from software engineering and SoC
design perspective.
How serious the problem of complexity in the evolution of computing is, we
can conceive from the observation given by Ozzie, the Chief Software Architect of
Microsoft in 2006–2010 [Mul06]:
Complexity kills. It sucks the life out of developers, it makes products difficult to plan,
build and test, it introduces security challenges, and it causes end-user and administrator
frustration.
www.it-ebooks.info
1.4 Why Is Meta-Programming Needed? 9
As computing becomes ever more central to business and society, complexity in
the digital world is becoming indeed a great challenge, and as Ozzie observes, it
goes ‘beyond our control’.
What is the main reason of the software complexity growth? The answer is
simple – advancement of technology. Therefore, we need to look at the complexity
problem from the technological point of view.
Usually technology advancements in computing hardware are characterized by
Moore’s law, which describes trends of the silicon revolution [Bon98]. Moore,
one of the founders of Intel Inc., observed in an article published in the April 19,
1965, issue of Electronics magazine that innovations in technology would allow a
doubling of the number of transistors in a given space every year, and that the speed
of those transistors would increase. Ten years later, in an update article in 1975,
Moore adjusted the rate to every 2 years (and yet later to 18 months) to account for
the growing complexity of chips [Hir05]. What is less well known is that Moore
also stated that manufacturing costs would dramatically drop as the technology
advanced.
Moore’s prediction, now popularly known as Moore’s law, had some startling

implications, predicting that computing technology would increase in value at
the same time it would actually decrease in cost. This was an unusual idea
at the time since, in a typical industry, building a faster, better widget with twice
the functionality also usually means doubling the widget’s cost. However, in the
case of solid-state electronics, the opposite statement is true: each time transistor
size shrinks, integrated circuits (ICs) become cheaper and perform better.
Driven by Moore’s law and the continually increasing power of ICs, worldwide
revenue for semiconductors (basic blocks for electronic industry) has grown at over
14% per year. However, there were periods of the slower growth in electronic
systems that have lead to a slowdown in semiconductor growth to approximately
6% [Jon04].
Though the technology steadily advances, the digital world requires more and
more computing capacities such as the ones for super computers [Deb04], for
handset computers, for mobile computers, etc. With the advance of technology, the
design of systems, such as SoC, based on that technology is becoming extremely
challenging. With today’s SoC-based designs, Pete Hardee, Director of Product
Marketing (CoWare, Inc.), presents a design team with five facets of complexity
that range from ‘functional complexity, architectural and verification challenges to
design team communication and deep submicron implementation’.
The complexity challenges are also known as ‘design productivity gap’, indicat-
ing that complexity of SoC in terms of logic transistors that can be integrated on
a chip is increasing at the rate of 58 % per year (Moore’s law), while the design
productivity is increasing at the rate of 21 % per year only [SIA01].
As a result of advance in technology, the need for software is steadily in-
creasing too. And this is happening even at a much larger extent than advance
in technology per se. The main reason is that SoC design methodologies are
based on a system-level design paradigm, in which the software solutions pre-
vail. Examples are high-level modelling and validation tools based on hardware
www.it-ebooks.info
10 1 Introduction

description languages; software-based reconfiguring design systems; and external
repositories for searching, sharing and reusing of IP components among multiple
shareholders. These examples are based on meta-level software solutions, UML,
metadata, generators and meta-generators [BMP07, MM05].
The second reason is that the bigger part of functionality implemented within
SoC is realized using software and the content of software in such designs is steadily
increasing. On the other hand, SoCs are components of larger systems, where the
application level is governed by software. Finally, today the Internet along with
modern appliances, such as e-commerce, e-government, e-learning, etc., are the
‘largest eaters’ of software content and resources.
The complexity growth forces designers and researches to seek for the adequate
means for managing complexity issues. The primary task is the understanding of a
complexity problem and finding the relevant measures for evaluating complexity.
These issues may have a direct influence on performance, efficiency and other
characteristics of systems to be designed.
How to manage complexity? Many factors have the influence to better managing
of complexity, which we discuss later in Chap. 12. At this point, the reader should
be aware of the commonly recognized principles for managing complexity, which
are as follows: reducing the amount of information, decomposing a system into
modules, abstracting or hiding information, as well as providing different levels
of abstractions.
The above-mentionedprinciples are general; however, when applied in a concrete
context, they may have a specific interpretation. For example, the principles of meta-
programming (they will be discussed in detail in Chap. 3) also deal with information
hiding, decomposition of programs into parts, provision of different levels of
abstractions, etc., through the introduction of a specific means and mechanisms.
Meta-programming also contributes to complexity management. The more we
use program generators, the less code we need to write manually; hence, the more
complex software systems are developed, the better is their quality and the shorter
is the time to market.

As a consequence of complexity growth, system design methodologies should
be reconsidered and re-evaluated through the introduction of new concepts and
integration of these concepts into the methodologies. The concepts of ‘design-for-
change’, ‘product line’or‘software families’ anticipate the introduction of variants
in design of multiple applications as early as possible. The anticipated variability
should be implemented using some technology and techniques. Meta-programming
can be seen as the technology that enables expressing anticipated variability in a
domain explicitly even at the analysis stage and in this way leads to the effective
implementation of domain tasks. When using meta-programming methods, it is
possible to alter the view to the design process per se and to change responsibilities
and roles of designers. For example, a meta-designer develops meta-programs to
implement the repetitive and difficult tasks that relate to variability managing. This
enables a designer to concentrate efforts less on programming tasks and more on
integrating tasks, that is, on system design tasks.
www.it-ebooks.info
1.6 The Topics This Book Addresses 11
1.5 Meta-Programming as a Higher-Level Thinking
Paradigm to Develop Systems
So far we have treated meta-programming as a technology to support program
generation. The discussed definitions of meta-programming were focused on the
technology-basedview. This view does not consider the entire development cycle of
a meta-program but rather takes an emphasis on the coding phase. The development
of any software system or its part, however, starts from the formulation of require-
ments and domain analysis. Even more, the state-of-the-art development currently
focuses not on the development of a separate system but rather on the development
of a system of systems (also known as a product line of software families, see,
e.g., [HHU08]) in order to achieve higher pay-offs through the increased scope of
reuse. On the other hand, the complexity issues push design paradigms towards
higher abstraction levels. In such a context, the understanding of a domain to be
implemented by software plays an extremely significant role.

The domain understanding through its modelling is a well-founded approach that
is widely exploited for more than two decades in software engineering. Abstractly,
if one ignores implementation details (e.g., when designing or using some tools),
modelling can be conceived of as building of domain models or system models.
Actually the development of a program or meta-program starts when we try to
create models. The model-driven approach prevails in modern design paradigms
now [Sch06]. Thus, modelling is a higher-level activity aiming to plan the whole
design at the early stage in order to facilitate the implementation of the design
separate phases later. Such an activity requires a great deal of competency of actors
who provide the planning. The competency is not only the needed knowledge. What
is more important is that the competency means also another way of 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 gener-
alize all these terms using one word – meta-thinking. In terms of meta-programming,
by 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.
1.6 The Topics This Book Addresses
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, generalization aspects of heterogeneous
www.it-ebooks.info

×