AFortran2RSL-LoopExpr.atl APascal2RSL-LoopExpr.atl
1-- @atlcompiler atl2006 1-- @atlcompiler atl2006
2module AFortran2RSL; 2module APascal2RSL;
3create OUT : RSL from IN : AFortran; 3create OUT : RSL from IN : APascal;
4  4 
5helper context String 5helper context String
6    def: startsWith(s : String) : Boolean = 6    def: startsWith(s : String) : Boolean =
7        s.size() <= self.size() and self.substring(1, s.size()) = s; 7        s.size() <= self.size() and self.substring(1, s.size()) = s;
8  8 
9helper context String 9helper context String
10    def: endsWith(s : String) : Boolean = 10    def: endsWith(s : String) : Boolean =
11        let start : Integer = self.size() - s.size() + 1 in 11        let start : Integer = self.size() - s.size() + 1 in
12            start > 0 and self.substring(start, self.size()) = s; 12            start > 0 and self.substring(start, self.size()) = s;
13  13 
14  14 
15rule AFortran2RSL { 15rule APascal2RSL {
16    from 16    from
17        s:  AFortran!AFortran 17        s:  APascal!APascal
18    to 18    to
19        t:  RSL!RSL ( 19        t:  RSL!RSL (
20            domain <-  s.domain, 20            domain <-  s.domain,
21            rslelems <-     Sequence { 21            rslelems <-     Sequence {
22                                  s.advice, 22                                  s.advice,
23                                  thisModule.PointCutExprToInitExpr(s.pointcut->first().pctexpr->first()), 23                                  thisModule.PointCutExprToInitExpr(s.pointcut->first().pctexpr->first()),
24                                  thisModule.PointCutExprToExitExpr(s.pointcut->first().pctexpr->first()), 24                                  thisModule.PointCutExprToExitExpr(s.pointcut->first().pctexpr->first()),
25                                  thisModule.PointCutExprToWithinCode(s.pointcut->first().pctexpr->last()), 25                                  thisModule.PointCutExprToWithinCode(s.pointcut->first().pctexpr->last()),
26                                  s.pointcut->collect(e | thisModule.PointCutToExternalPattern(e)), 26                                  s.pointcut->collect(e | thisModule.PointCutToExternalPattern(e)),
27                                  s.pointcut->collect(e | thisModule.PointCutToRule(e)) 27                                  s.pointcut->collect(e | thisModule.PointCutToRule(e))
28                                 }, 28                                 },
29            ruleset <- rs 29            ruleset <- rs
30        ), 30        ),
31        rs : RSL!RuleSet ( 31        rs : RSL!RuleSet (
32            rsname <- s.name, 32            rsname <- s.name,
33            rname <- s.pointcut->collect(e|e.name) 33            rname <- s.pointcut->collect(e|e.name)
34        ) 34        )
35} 35}
36  36 
37rule ApDomain2RSLDomain { 37rule ApDomain2RSLDomain {
38    from 38    from
39        s : AFortran!Domain 39        s : APascal!Domain
40    to 40    to
41        t : RSL!Domain ( 41        t : RSL!Domain (
42            dname <- s.name 42            dname <- s.name
43        ) 43        )
44} 44}
45  45 
46rule BeforeAdvice2Pattern { 46rule BeforeAdvice2Pattern {
47    from 47    from
48        s : AFortran!BeforeAdvice 48        s : APascal!BeforeAdvice
49    to 49    to
50        t : RSL!Pattern ( 50        t : RSL!Pattern (
51            phead <- ph, 51            phead <- ph,
52            ptoken <- 'execution_part_construct_list', 52            ptoken <- 'statement_list',
53            ptext <- spt 53            ptext <- spt
54        ), 54        ),
55        ph : RSL!PatternHead ( 55        ph : RSL!PatternHead (
56            name <- 'before_advice_stmt' 56            name <- 'before_advice_stmt'
57        ), 57        ),
58        spt : RSL!SimplePatternText ( 58        spt : RSL!SimplePatternText (
59            ptext <- s.advStmt->iterate(e; acc : String = '' | acc + if acc = '' then '' else '\r\n\t' endif + e.stmt) 59            ptext <- s.advStmt->iterate(e; acc : String = '' | acc + if acc = '' then '' else '\r\n\t' endif + e.stmt)
60        ) 60        )
61} 61}
62  62 
63rule GenerateAfterAdviceDummy extends BeforeAdvice2Pattern { 63rule GenerateAfterAdviceDummy extends BeforeAdvice2Pattern {
64    from 64    from
65        s : AFortran!BeforeAdvice ( 65        s : APascal!BeforeAdvice (
66            not s.aspect.advice->exists(e | e.oclIsKindOf(AFortran!AfterAdvice)) 66            not s.aspect.advice->exists(e | e.oclIsKindOf(APascal!AfterAdvice))
67        ) 67        )
68    to 68    to
69        t : RSL!Pattern, 69        t : RSL!Pattern,
70        at : RSL!Pattern ( 70        at : RSL!Pattern (
71            rsl <- s.aspect, 71            rsl <- s.aspect,
72            phead <- aph, 72            phead <- aph,
73            ptoken <- 'execution_part_construct_list', 73            ptoken <- 'statement_list',
74            ptext <- aspt 74            ptext <- aspt
75        ), 75        ),
76        aph : RSL!PatternHead ( 76        aph : RSL!PatternHead (
77            name <- 'after_advice_stmt' 77            name <- 'after_advice_stmt'
78        ), 78        ),
79        aspt : RSL!SimplePatternText ( 79        aspt : RSL!SimplePatternText (
80            ptext <- '' 80            ptext <- ''
81        ) 81        )
82} 82}
83  83 
84rule AfterAdvice2Pattern { 84rule AfterAdvice2Pattern {
85    from 85    from
86        s : AFortran!AfterAdvice 86        s : APascal!AfterAdvice
87    to 87    to
88        t : RSL!Pattern ( 88        t : RSL!Pattern (
89            phead <- ph, 89            phead <- ph,
90            ptoken <- 'execution_part_construct_list', 90            ptoken <- 'statement_list',
91            ptext <- spt 91            ptext <- spt
92        ), 92        ),
93        ph : RSL!PatternHead ( 93        ph : RSL!PatternHead (
94            name <- 'after_advice_stmt' 94            name <- 'after_advice_stmt'
95        ), 95        ),
96        spt : RSL!SimplePatternText ( 96        spt : RSL!SimplePatternText (
97            ptext <- s.advStmt->iterate(e; acc : String = '' | acc + if acc = '' then '' else '\r\n\t' endif + e.stmt) 97            ptext <- s.advStmt->iterate(e; acc : String = '' | acc + if acc = '' then '' else '\r\n\t' endif + e.stmt)
98        ) 98        )
99} 99}
100rule GenerateBeforeAdviceDummy extends AfterAdvice2Pattern{ 100rule GenerateBeforeAdviceDummy extends AfterAdvice2Pattern{
101    from 101    from
102        s : AFortran!AfterAdvice ( 102        s : APascal!AfterAdvice (
103            not s.aspect.advice->exists(e | e.oclIsKindOf(AFortran!BeforeAdvice)) 103            not s.aspect.advice->exists(e | e.oclIsKindOf(APascal!BeforeAdvice))
104        ) 104        )
105    to 105    to
106        t : RSL!Pattern, 106        t : RSL!Pattern,
107        bt: RSL!Pattern ( 107        bt: RSL!Pattern (
108            rsl <- s.aspect, 108            rsl <- s.aspect,
109            phead <- bph, 109            phead <- bph,
110            ptoken <- 'execution_part_construct_list', 110            ptoken <- 'statement_list',
111            ptext <- bspt 111            ptext <- bspt
112        ), 112        ),
113        bph : RSL!PatternHead ( 113        bph : RSL!PatternHead (
114            name <- 'before_advice_stmt' 114            name <- 'before_advice_stmt'
115        ), 115        ),
116        bspt : RSL!SimplePatternText ( 116        bspt : RSL!SimplePatternText (
117            ptext <- '' 117            ptext <- ''
118        ) 118        )
119} 119}
120  120 
121lazy rule PointCutExprToInitExpr { 121lazy rule PointCutExprToInitExpr {
122    from 122    from
123        s : AFortran!Expression 123        s : APascal!Expression
124    to 124    to
125        t : RSL!Pattern ( 125        t : RSL!Pattern (
126            ptext <- spt, 126            ptext <- spt,
127            ptoken <- 'LABEL', 127            ptoken <- 'NATURAL_NUMBER',
128            phead <- ph 128            phead <- ph
129        ), 129        ),
130        ph : RSL!PatternHead ( 130        ph : RSL!PatternHead (
131            name <-   'init' 131            name <-   'init'
132        ), 132        ),
133        spt : RSL!SimplePatternText ( 133        spt : RSL!SimplePatternText (
134        ptext <-    if s.loopStmt.loopInitCondition.condition.toString() = '*'  then 134        ptext <-    if s.loopStmt.loopInitCondition.condition.toString() = '*'  then
135                       '12345' 135                       '123456789'
136                    else 136                    else
137                        s.loopStmt.loopInitCondition.condition.toString() 137                        s.loopStmt.loopInitCondition.condition.toString()
138                    endif 138                    endif
139        ) 139        )
140  140 
141} 141}
142  142 
143lazy rule PointCutExprToExitExpr { 143lazy rule PointCutExprToExitExpr {
144    from 144    from
145        s : AFortran!Expression 145        s : APascal!Expression
146    to 146    to
147        t : RSL!Pattern ( 147        t : RSL!Pattern (
148            ptext <- spt, 148            ptext <- spt,
149            ptoken <- 'LABEL', 149            ptoken <- 'NATURAL_NUMBER',
150            phead <- ph 150            phead <- ph
151        ), 151        ),
152        ph : RSL!PatternHead ( 152        ph : RSL!PatternHead (
153            name <-   'exit' 153            name <-   'exit'
154        ), 154        ),
155        spt : RSL!SimplePatternText ( 155        spt : RSL!SimplePatternText (
156        ptext <-    if s.loopStmt.loopExitCondition.condition.toString() = '*'  then 156        ptext <-    if s.loopStmt.loopExitCondition.condition.toString() = '*'  then
157                       '12345' 157                       '123456789'
158                    else 158                    else
159                       s.loopStmt.loopExitCondition.condition.toString() 159                       s.loopStmt.loopExitCondition.condition.toString()
160                    endif 160                    endif
161        ) 161        )
162  162 
163} 163}
164  164 
165lazy rule PointCutExprToWithinCode { 165lazy rule PointCutExprToWithinCode {
166    from 166    from
167        s : AFortran!Expression 167        s : APascal!Expression
168    to 168    to
169        t : RSL!Pattern ( 169        t : RSL!Pattern (
170            ptext <- spt , 170            ptext <- spt ,
171            ptoken <- 'NAME', 171            ptoken <- 'IDENTIFIER',
172            phead <- ph 172            phead <- ph
173        ), 173        ),
174        ph : RSL!PatternHead ( 174        ph : RSL!PatternHead (
175            name <-   'within_code' 175            name <-   'within_code'
176        ), 176        ),
177        spt : RSL!SimplePatternText ( 177        spt : RSL!SimplePatternText (
178        ptext <- if s.pointcut.pctexpr.size() > 1 then 178        ptext <- if s.pointcut.pctexpr.size() > 1 then
179                     ' '+ s.func_sub_Sig.name 179                     ' '+ s.funcOrProcSig.name
180                 else ' ' + 'wc_' endif 180                 else ' ' + 'wc_' endif
181  181 
182        ) 182        )
183} 183}
184  184 
185lazy rule PointCutToExternalPattern { 185lazy rule PointCutToExternalPattern {
186    from 186    from
187        s : AFortran!Pointcut 187        s : APascal!Pointcut
188    to 188    to
189        t : RSL!ExternalPattern ( 189        t : RSL!ExternalPattern (
190            dname <-  'FORTRAN', 190            dname <-  'ObjectPascal',
191            eptext <- 'around_advice_for', 191            eptext <- 'around_advice_for',
192            ptoken <- 'Fortran90_program', 192            ptoken <- 'ObjectPascal',
193            phead <- ph 193            phead <- ph
194        ), 194        ),
195        ph : RSL!PatternHead ( 195        ph : RSL!PatternHead (
196            name <-   'around_advice_for', 196            name <-   'around_advice_for',
197            params <- Sequence {pp1,pp2,pp3,pp4,pp5,pp6} 197            params <- Sequence {pp1,pp2,pp3,pp4,pp5,pp6}
198        ), 198        ),
199        pp1 : RSL!PatternParameter ( 199        pp1 : RSL!PatternParameter (
200            name <- 'program', 200            name <- 'program',
201            referTo <- 'Fortran90_program' 201            referTo <- 'ObjectPascal'
202        ), 202        ),
203        pp2 : RSL!PatternParameter ( 203        pp2 : RSL!PatternParameter (
204            name <- 'proceed_bef', 204            name <- 'proceed_bef',
205            referTo <- 'execution_part_construct_list' 205            referTo <- 'statement_list'
206        ), 206        ),
207        pp3 : RSL!PatternParameter ( 207        pp3 : RSL!PatternParameter (
208            name <- 'proceed_after', 208            name <- 'proceed_after',
209            referTo <- 'execution_part_construct_list' 209            referTo <- 'statement_list'
210        ), 210        ),
211        pp4 : RSL!PatternParameter ( 211        pp4 : RSL!PatternParameter (
212            name <- 'withincode', 212            name <- 'withincode',
213            referTo <- 'NAME' 213            referTo <- 'IDENTIFIER'
214        ), 214        ),
215        pp5 : RSL!PatternParameter ( 215        pp5 : RSL!PatternParameter (
216            name <- 'init', 216            name <- 'init',
217            referTo <- 'LABEL' 217            referTo <- 'NATURAL_NUMBER'
218        ), 218        ),
219        pp6 : RSL!PatternParameter ( 219        pp6 : RSL!PatternParameter (
220            name <- 'exit', 220            name <- 'exit',
221            referTo <- 'LABEL' 221            referTo <- 'NATURAL_NUMBER'
222        ) 222        )
223} 223}
224  224 
225lazy rule PointCutToRule { 225lazy rule PointCutToRule {
226    from 226    from
227        s : AFortran!Pointcut 227        s : APascal!Pointcut
228    to 228    to
229        t : RSL!Rule ( 229        t : RSL!Rule (
230  230 
231                rname <- s.name, 231                rname <- s.name,
232                type <-   'Fortran90_program', 232                type <-   'ObjectPascal',
233                params <- Sequence {rp1}, 233                params <- Sequence {rp1},
234                r_lhs_pattern <- rlhsp, 234                r_lhs_pattern <- rlhsp,
235                r_rhs_pattern <- rrhsp 235                r_rhs_pattern <- rrhsp
236            ), 236            ),
237            rp1: RSL!RuleParameter ( 237            rp1: RSL!RuleParameter (
238                name <- 'program', 238                name <- 'program',
239                referTo <- 'Fortran90_program' 239                referTo <- 'ObjectPascal'
240            ), 240            ),
241            rlhsp : RSL!RuleLHS ( 241            rlhsp : RSL!RuleLHS (
242                    ruletext <-   irt -- IDRuleText 242                    ruletext <-   irt -- IDRuleText
243            ), 243            ),
244            irt : RSL!IDRuleText ( 244            irt : RSL!IDRuleText (
245                text <- 'program' 245                text <- 'program'
246            ), 246            ),
247            rrhsp : RSL!RuleRHS ( 247            rrhsp : RSL!RuleRHS (
248                    ruletext <-   crt, -- ComplexRuleText 248                    ruletext <-   crt, -- ComplexRuleText
249                    condition <- Sequence {rcon} 249                    condition <- Sequence {rcon}
250            ), 250            ),
251            crt : RSL!ComplexRuleText ( 251            crt : RSL!ComplexRuleText (
252                pref <- rule_rhs_pattern 252                pref <- rule_rhs_pattern
253            ), 253            ),
254            rule_rhs_pattern : RSL!PatternRef ( 254            rule_rhs_pattern : RSL!PatternRef (
255                    name <-   'around_advice_for', 255                    name <-   'around_advice_for',
256                    params <- Sequence {param1,param2,param3,param4,param5,param6} 256                    params <- Sequence {param1,param2,param3,param4,param5,param6}
257            ), 257            ),
258            param1 : RSL!RealParameter ( 258            param1 : RSL!RealParameter (
259                      name <- 'program' 259                      name <- 'program'
260            ), 260            ),
261            param2 : RSL!PatternRef ( 261            param2 : RSL!PatternRef (
262                      name <- 'before_advice_stmt' 262                      name <- 'before_advice_stmt'
263            ), 263            ),
264  264 
265            param3 : RSL!PatternRef ( 265            param3 : RSL!PatternRef (
266                      name <- 'after_advice_stmt' 266                      name <- 'after_advice_stmt'
267            ), 267            ),
268            param4 : RSL!PatternRef ( 268            param4 : RSL!PatternRef (
269                      name <- 'within_code' 269                      name <- 'within_code'
270            ), 270            ),
271            param5 : RSL!PatternRef ( 271            param5 : RSL!PatternRef (
272                      name <- 'init' 272                      name <- 'init'
273            ), 273            ),
274            param6 : RSL!PatternRef ( 274            param6 : RSL!PatternRef (
275                      name <- 'exit' 275                      name <- 'exit'
276            ), 276            ),
277            rcon :  RSL!RuleNotEqCondition ( 277            rcon :  RSL!RuleNotEqCondition (
278                    lhs <- 'program', 278                    lhs <- 'program',
279                    pref <- rule_rhs_cond 279                    pref <- rule_rhs_cond
280            ), 280            ),
281            rule_rhs_cond : RSL!PatternRef ( 281            rule_rhs_cond : RSL!PatternRef (
282                    name <-   'around_advice_for', 282                    name <-   'around_advice_for',
283                    params <- Sequence {p1,p2,p3,p4,p5,p6} 283                    params <- Sequence {p1,p2,p3,p4,p5,p6}
284            ), 284            ),
285            p1 : RSL!RealParameter ( 285            p1 : RSL!RealParameter (
286                      name <- 'program' 286                      name <- 'program'
287            ), 287            ),
288            p2 : RSL!PatternRef ( 288            p2 : RSL!PatternRef (
289                      name <- 'before_advice_stmt' 289                      name <- 'before_advice_stmt'
290            ), 290            ),
291  291 
292            p3 : RSL!PatternRef ( 292            p3 : RSL!PatternRef (
293                      name <- 'after_advice_stmt' 293                      name <- 'after_advice_stmt'
294            ), 294            ),
295            p4 : RSL!PatternRef ( 295            p4 : RSL!PatternRef (
296                      name <- 'within_code' 296                      name <- 'within_code'
297            ), 297            ),
298            p5 : RSL!PatternRef ( 298            p5 : RSL!PatternRef (
299                      name <- 'init' 299                      name <- 'init'
300            ), 300            ),
301            p6 : RSL!PatternRef ( 301            p6 : RSL!PatternRef (
302                      name <- 'exit' 302                      name <- 'exit'
303            ) 303            )
  304 
  305 
304} 306}
305  307