10.07.2015 Views

all FREECO11-workshop-papers.pdf - trese

all FREECO11-workshop-papers.pdf - trese

all FREECO11-workshop-papers.pdf - trese

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Towards Modular Code Generators Using SymmetricLanguage-Aware AspectsSteffen ZschalerKing’s College London,Department of Informatics, London, UKszschaler@acm.orgAwais RashidSchool of Computing and Communications,Lancaster University, Lancaster, UKawais@comp.lancs.ac.ukABSTRACTModel-driven engineering, especi<strong>all</strong>y using domain-specific languages,<strong>all</strong>ows constructing software from abstractions that are moreclosely fitted to the problem domain and that better hide technicaldetails of the solution space. Code generation is used to produce executablecode from these abstractions, which may result in individualconcerns being scattered and tangled throughout the generatedcode. The ch<strong>all</strong>enge, then, becomes how to modularise the codegeneratortemplates to avoid scattering and tangling of concernswithin the templates themselves. This paper shows how symmetric,language-aware approaches to aspect orientation can be appliedto code generation to improve modularisation support.Categories and Subject DescriptorsD2.3 [Software Engineering]: Coding Tools and TechniquesKeywordsmodel-driven engineering, code generation, symmetric aspects1. INTRODUCTIONIn model-driven engineering (MDE), domain-specific languages(DSLs) are typic<strong>all</strong>y accompanied by code generators, which expandthe abstract DSL concepts into source code in a target programminglanguage, typic<strong>all</strong>y taking into consideration a particulartarget platform (e.g., middleware, hardware, distribution andconcurrency model, etc.). Such expansions can be limited to thegeneration of standard, ‘boiler-plate’ code, but, more interestingly,may include so-c<strong>all</strong>ed local-to-global or global-to-local transformations[14]. A local-to-global transformation means that informationfrom one element in a DSL program may be scattered acrossmultiple elements in the generated source code—for example, adata description may affect user-interface code as well as datadefinitionscripts for setting up a database back end. A globalto-localtransformation, on the other hand, means that informationfrom a number of DSL elements may need to be tangled within oneelement in the generated source code—for example, both informationfrom a layout policy and the data description must be tangledPermission to make digital or hard copies of <strong>all</strong> or part of this work forpersonal or classroom use is granted without fee provided that copies arenot made or distributed for profit or commercial advantage and that copiesbear this notice and the full citation on the first page. To copy otherwise, torepublish, to post on servers or to redistribute to lists, requires prior specificpermission and/or a fee.FREECO’11, July 26, 2011, Lancaster, UK.Copyright 2011 ACM 978-1-4503-0892-2/11/07 ...$10.00.in user-interface code generated.The ch<strong>all</strong>enge in the presence of local-to-global and global-tolocaltransformations is how to cleanly modularise the code-generationtemplates so that, while tangling and scattering occur inthe code generated, the templates themselves do not suffer from it.Moreover, the code-generators themselves may need to address arange of technical concerns, such as consistency management [6],performance, security, different target platforms, etc., which arenot captured in the source models. Of course, we would also liketo avoid scattering and tangling of technical concerns in generationtemplates. This becomes particularly important where DSLsshould be reused in different projects, which may require to addresssome technical concerns in a different manner or may requireadaptations to the DSL concepts provided. In this case, generatormodularisation becomes essential, as it enables a ‘mix and match’approach to DSL adaptation and reuse [16]. Ide<strong>all</strong>y, we would liketo modularise code generators such that each technical concern aswell as each concern modelled in a DSL could be realised in a separatecode-generation module as independently as possible of theother concerns.Existing code-generation frameworks (e.g., [4, 7, 8, 11]) assumethat one target file will be produced by one code-generation template(even though this may import and invoke additional generationrules). Thus, any scattering and tangling that occurs in thegenerated code automatic<strong>all</strong>y also occurs in the generation templates.To address this issue, aspect-oriented approaches to codegeneration have been proposed [10,15]. However, they are not fullyadequate for <strong>all</strong> needs of code-generator modularisation: Becausethey are asymmetric approaches [5], they require an explicit basetemplate, often imply the use of scaffolding (e.g., empty rules inthe base template whose only purpose is to serve as hooks for theaspect templates), and lack sufficient support for weaving contexts.Furthermore, because they are language-agnostic, any languagespecificweaving semantics must be implemented in the generationtemplates, which is not always possible.This paper proposes a novel approach for modularising codegenerators. This approach maintains the benefits of reduced tanglingintroduced by [10, 15], but also addresses the short-comingsof these approaches:• It is a symmetric aspect-oriented approach, addressing theissues connected to asymmetry in current approaches.• It is also a language-aware approach to address the issue oflanguage agnosticism.Thus, the contributions of this paper are the following:1. We identify four shortcomings of existing asymmetric AOapproaches to code generation that stand in the way of effectiveseparation of concerns for code generators.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!