Date post: | 02-Jan-2016 |
Category: |
Documents |
Upload: | jane-jefferson |
View: | 213 times |
Download: | 0 times |
1
Research Directions Towards
Software Maintenance, Adaptation
and Modernization Grammar-based Software Technology -
Spring 2006 Programming Lang. Seminar
Suman Roychoudhury
2
Maintaining Legacy Code – Tool Support ?
Cobol
Legacy
Software
Fortran
Object Pascal
Commercial + Scientific Applications
200 Billion Lines of Cobol Source
Migration is not an easy task !
Infrastructure, money effort already spent
3
Current Techniques and Tools OMG MDA - Model Driven Architecture OMG KDM - Knowledge Discovery
Metamodel Aspect-Oriented Software Development Software Refactoring/Mining/Migration Eclipse IDE/ AspectJ
4
Aspect Weavers: Current Limitations
However –
1. Specific to a few popular languages (e.g., Java)
2. New tools are developed from scratch without preserving knowledge of previous construction
3. No emphasis on re-usability in a different language and platform context
Several tools and language extensions have been developed to enable aspect weaving :-
5
Research Questions
Is there a technique to construct aspect weavers for legacy languages without extending or inventing a new parser (or compiler) from scratch?
Can such construction be supported in a more generic or language-parametric (independent) way?
Can the knowledge of building a weaver from a previous construction be reused in a different language and platform context?
6
Challenges in Language-Parametric Legacy AdoptionChallenge C1 – The Parser Construction Problem
Challenge C2 – Type Analysis Problem
Challenge C3 – The Code Transformation Problem
Challenge C4 – Language-Parametric Generalization of Transformation Objectives
Challenge C5 – Accidental Complexities of Transformation Specifications
7
Challenge C1 – The Parser Construction Problem
IntermediateSyntax
IntermediateType
Analysis
Parser ConcreteSyntax
Aspect Language
Transformation System
User Inputs
Legacy System
Scalabilty Extensibility Availabilty of
AST Framework
Reusabilty C++ Object Pascal Fortan Cobol Ada Jovial VHDL
8
Parser ConcreteSyntax
Aspect Language
Transformation System
User Inputs
Legacy System
Challenge C2 – Type Analysis Problem
IntermediateSyntax
IntermediateType
Analysis
Interaction of aspects with Type System (e.g. computing sub-types for a given type)
9
Challenge C3 – The Code Transformation Problem
IntermediateSyntax
IntermediateType
Analysis
Parser ConcreteSyntax
Aspect Language
Transformation System
User Inputs
Legacy System
patternpattern probe_id_pattern1() probe_id_pattern1(): : unqualified_idunqualified_id = " printf ". = " printf ".
rulerule insert_probe1 insert_probe1(s: (s: statement_seqstatement_seq): ): function_bodyfunction_body ->-> function_bodyfunction_body = " { \s } " = " { \s } " ->-> "{ \probe_id_pattern1\(\)"{ \probe_id_pattern1\(\) (\"Entering Method…\");(\"Entering Method…\"); { \s } { \s } }".}".
10
Parser ConcreteSyntax
Aspect Language
Transformation System
User Inputs
Legacy System
Challenge C4 – Language-Parametric Generalization of Transformation Objectives
IntermediateSyntax
IntermediateType
Analysis
patternpattern probe_id_pattern1() probe_id_pattern1(): : IUnqualifiedIdIUnqualifiedId = "IFunctionName". = "IFunctionName".
rulerule insert_generic_probe1 insert_generic_probe1(s: (s: IStatementListIStatementList): ): IFunctionDeclIFunctionDecl ->-> IFunctionDeclIFunctionDecl = " \Block_Begin= " \Block_Begin \s \s \Block_End" \Block_End" ->-> "\Block_Begin"\Block_Begin \probe_id_pattern1\(\)\probe_id_pattern1\(\) (\"Entering Method…\");(\"Entering Method…\"); \Block_Begin\Block_Begin \s \Block_End\s \Block_End
\Block_End\Block_End ".".
11
Challenge C5 – Accidental Complexities of Transformation Specifications
IntermediateSyntax
IntermediateType
Analysis
Parser ConcreteSyntax
Aspect Language
Transformation System
User Inputs
Legacy System
A high level aspect language layered on top of the base system
Translates to low level specifications
aspect insert_probe1 { before(): execution (function_declaration) { // insert print statement } }
12
Goal Statement
Program Transformation
System(C1,C3)
Aspect Weavers
Low Level xForm constructs
High level language constructs
Legacy Software
Increase the level of
abstraction and reuse the
core transformation
functions across language
domains
Parametric Transforms
Goal 1 : Raise the level of abstraction (aspect layering) for end-programmers (C5)
Goal 2 : Re-use core transformations across language domains using language parametric transforms (C2, C4)
We use a commercial PTE from Semantic Designs (the Design Maintenance System - DMS)
13
Current State-of-the-Art: Rewriting Techniques object-based transforms, such as a visitor object applied
to an object model
intermediate representations that permit primitive transformations to be applied to a set of languages (e.g., .Net CodeDOM)
XML-based transforms that use an XML DOM structure
term rewriting, such as a transformation rule
14
Current State-of-the-Art:SourceWeave.Net
Uses Microsoft’s CodeDom Architecture as the underlying AST Representation
Uses XML descriptor to specify interaction between aspects and .Net components
http:// aosd.net/2004/archive/JacksonPoster.pdf
Limited availability of CodeDOM providers
CodeDOM biased towards C#, hence lack of expressiveness for other
languages
Verbosity of XML representations a serious concern for scalability
15
Current State-of-the-Art:Weave.Net
http://www.dsg.cs.tcd.ie/uploads/category144/119.pdf
Uses existing .Net Binary Component and cross-cutting specifications in an xml file as input
Advice is given separately in another .Net assembly
Limited to applications hosted within .Net
Aspect specification is difficult to comprehend due to lack of
expressiveness of XML constructs
16
Current State-of-the-Art: Aspect Cobol
http://homepages.cwi.nl/~ralf/AspectCobol/
Parse trees are exported to XML
Weaving boils down to XML DOM tree processing in Java.
XML representation of source code (intermediate form) may not scale with code size
It has been reported that such internal representations are 50 times larger and much slower to transform [Ger01]
Limited only to COBOL i.e., a more generalized approach is missing
Roy Germon, “Using XML as an Intermediate Form for Compiler Development,” XML Conference and Exposition, Orlando, FL, December 2001.
17
Current State-of-the-Art: Aspierce + GCC 4.0
http://users.ugent.be/~badams/publications/2005/language-independentaspectweaving.pdf
Proposes to use GCC 4.0 GENERIC trees
Weaving is done by modifying the GENERIC
AST representations
Lack of support for .Net Languages like C#, VB.Net and other languages like Object Pascal, Cobol etc
Still in a proposal stage, not clear whether API support is available for modifying GENERIC trees
Very little documentation available from project site
18
Background:Term Rewriting Based Program
Transformation Term rewriting is a paradigm that is used in fields such as program
transformation and theorem proving
In term rewriting, rules define a refinement to a structure by specifying a pattern to be matched and the resulting effect (closer to logic and algebraic programming)
private rule refine_expression_add(e1:expression@InfixArithmetic, e2:expression@InfixArithmetic):expression -> expression= "+ \e1\:expression \e2\:expression" -> "(\e1) + (\e2)".
Example:
19
Genericity of Aspect Transformations (Object Pascal) – Database Error Handler Synchronization………
function TExNullField.Handle (ServerType: TServerType; E: EDBEngineError): Integer; begin
<database error handling code omitted here>
end;………
TExHandleCollection (Collection).LockHandle;try
finally TExHandleCollection (Collection).UnLockHandle;end;
……rule sync_OP_meths (sl:stmt_list, id:IDENTIFIER, fps: formal_params, frt:func_result_type):
qual_func_header_decl qual_func_header_decl = "function \method_id\(\id\) \fps : \frt ; begin \sl end;" "function \method_id\(\id\) \fps : \frt ; begin \LockStmt\(\); try \sl finally \UnLockStmt\(\); end;“
Object Pascal Source File DMS Rewrite Rule
20
Genericity of Aspect Transformations ( Java) – Database Error Handler Synchronization………
public Integer HandleDBError( TServerType ServerType,
EDBEngineError E)
{
<database error handling code omitted here>
}
ErrHandlerCollction
. LockHandle(Collection);
try {
finally {
ErrHandlerCollection
. UnLockHandle(Collection);
}
……rule sync_Java_meths (s_seq:stmt_seq,m_mods: meth_modifiers, t:type,id:IDENTIFIER, fp:fparams) : method_declaration method_declaration =
"\m_mods \type \method_id\(\id\) \fp { \s_seq } ;" "\m_mods \type \method_id\(\id\) \fp { \LockStmt\(\); try { \s_seq } finally { \UnLockStmt\(\) } };”
Java Source File DMS Rewrite Rule
21
Transformation Map……rule sync_Java_meths (s_seq:stmt_seq,m_mods: meth_modifiers, t:type,id:IDENTIFIER, fp:fparams) : method_declaration method_declaration =
"\m_mods \type \method_id\(\id\) \fp { \s_seq } ;" "\m_mods \type \method_id\(\id\) \fp { \LockStmt\(\); try { \s_seq } finally { \UnLockStmt\(\) } };”
……rule sync_OP_meths (sl:stmt_list, id:IDENTIFIER, fps: formal_params, frt:func_result_type):
qual_func_header_decl qual_func_header_decl = "function \method_id\(\id\) \fps : \frt ; begin \sl end;" "function \method_id\(\id\) \fps : \frt ; begin \LockStmt\(\); try \sl finally \UnLockStmt\(\); end;“
DMS Rewrite Rule for Object PascalDMS Rewrite Rule for Java
22
Language-Parametric Synchronization Rule – Intermediate AST
st_list@iAst stml_list@OP ID_list@iAst id@OP param_list@iAst paramformal_params@OP ret_type@iAst func_result_type@OP meth_signature@iAst qual_func_header_decl@OP ----------------------------st_list@iAst stmt_seq@JavaID_list@iAst id@Javaparam_list@iAst fparams@Javaret_type@iAst type@Javameth_signature@iAst method_declaration@Java
rule sync_generic (sL:st_list, i:ID_list, pl: param_list, rt:ret_type):
std_func_decl -> std_fun_decl =
"meth_signature(\id\,\pl\,\rt) \std_start \sL \std_end" -> "meth_signature(\id\,\pl\,\rt) \std_start \LockStmt\(\); \try_finally_decl \sL \UnLockStmt\(\); \std_end“
Generic Transformation RuleMapping to Intermediate AST
23
System Workflow
Lexer/Parser
Pattern Transformer
Intermediate AST Reader
Attribute Evaluator
Symbol Table
Transformation Engine
Pretty Printer
Analyzer
Transformation Engine
Generic Transforms
CoreTransforms
Lexer/Parser
Domain Reader
InputSourceFile
RevisedSourceFile
ASTGraph
ASTGraph
unparser definitions
parserdefinitions
Phase 1 Phase 2
24
GenAWeave in Action
Lexer/Parser
Pattern Transformer
Intermediate AST Reader
Attribute Evaluator
Symbol Table
Transformation Engine
Pretty Printer
Analyzer
Transformation Engine
Generic Transforms
CoreTransforms
Lexer/Parser
Domain Reader
InputSourceFile
RevisedSourceFile
ASTGraph
ASTGraph
unparser definitions
parserdefinitions
Phase 1 Phase 2
25
GenAWeave in Action
Lexer/Parser
Pattern Transformer
Intermediate AST Reader
Attribute Evaluator
Symbol Table
Transformation Engine
Pretty Printer
Analyzer
Transformation Engine
Generic Transforms
CoreTransforms
Lexer/Parser
Domain Reader
InputSourceFile
RevisedSourceFile
ASTGraph
ASTGraph
unparser definitions
parserdefinitions
Phase 1 Phase 2
26
GenAWeave in Action
Lexer/Parser
Pattern Transformer
Intermediate AST Reader
Attribute Evaluator
Symbol Table
Transformation Engine
Pretty Printer
Analyzer
Transformation Engine
Generic Transforms
CoreTransforms
Lexer/Parser
Domain Reader
InputSourceFile
RevisedSourceFile
ASTGraph
ASTGraph
unparser definitions
parserdefinitions
Phase 1 Phase 2
27
GenAWeave in Action
Lexer/Parser
Pattern Transformer
Intermediate AST Reader
Attribute Evaluator
Symbol Table
Transformation Engine
Pretty Printer
Analyzer
Transformation Engine
Generic Transforms
CoreTransforms
Lexer/Parser
Domain Reader
InputSourceFile
RevisedSourceFile
ASTGraph
ASTGraph
unparser definitions
parserdefinitions
Phase 1 Phase 2
28
GenAWeave in Action
Lexer/Parser
Pattern Transformer
Intermediate AST Reader
Attribute Evaluator
Symbol Table
Transformation Engine
Pretty Printer
Analyzer
Transformation Engine
Generic Transforms
CoreTransforms
Lexer/Parser
Domain Reader
InputSourceFile
RevisedSourceFile
ASTGraph
ASTGraph
unparser definitions
parserdefinitions
Phase 1 Phase 2
29
GenAWeave in Action
Lexer/Parser
Pattern Transformer
Intermediate AST Reader
Attribute Evaluator
Symbol Table
Transformation Engine
Pretty Printer
Analyzer
Transformation Engine
Generic Transforms
CoreTransforms
Lexer/Parser
Domain Reader
InputSourceFile
RevisedSourceFile
ASTGraph
ASTGraph
unparser definitions
parserdefinitions
Phase 1 Phase 2
30
GenAWeave in Action
Lexer/Parser
Pattern Transformer
Intermediate AST Reader
Attribute Evaluator
Symbol Table
Transformation Engine
Pretty Printer
Analyzer
Transformation Engine
Generic Transforms
CoreTransforms
Lexer/Parser
Domain Reader
InputSourceFile
RevisedSourceFile
ASTGraph
ASTGraph
unparser definitions
parserdefinitions
Phase 1 Phase 2
31
GenAWeave in Action
Lexer/Parser
Pattern Transformer
Intermediate AST Reader
Attribute Evaluator
Symbol Table
Transformation Engine
Pretty Printer
Analyzer
Transformation Engine
Generic Transforms
CoreTransforms
Lexer/Parser
Domain Reader
InputSourceFile
RevisedSourceFile
ASTGraph
ASTGraph
unparser definitions
parserdefinitions
C2
C2
C4
C4
C4
C3
C2
C1
C1
Phase 1 Phase 2
32
Aspect Layering – Challenge C5
aspect generic_synchronize { before(): execution (mname@meth_signature) { // insert base language specific lock statement } after(): execution (mname@meth_signature) { // insert base language specific unlock statement }
Remove accidental complexities arising from term rewriting Provide an easy customized aspect language using the
Join Point Model (JPM) adapted from AspectJ The formalizations of transformation rules showed the
relationship between the JPM model of an aspect language
with respect to rewrite rules
33
Object Management Group(OMG) ASTM –Abstract Syntax Tree Meta-model “ It has long been observed that although there are
many differences between the statements in many programming languages there is a very large set of statements that are common across most languages. The Object Management Group (OMG) Architecture Driven Modernization Task Force has issued an RFP for the Abstract Syntax Tree Meta Modeling standard. The ASTM seeks to establish a single comprehensive set of modeling elements for capturing how many software languages represent the same software language constructs and concepts…”