Content deleted Content added
linking |
mNo edit summary |
||
Line 37:
DMS provides [[attribute grammar]] evaluators for computing custom analyses over ASTs, such as metrics, and including special support for [[symbol table]] construction. Other program facts can be extracted by built-in control- and data- [[flow analysis]] engines, local and global [[pointer analysis]], whole-program [[call graph]] extraction, and symbolic range analysis by [[abstract interpretation]].
Changes to ASTs can be accomplished by both procedural methods coded in PARLANSE and source-to-source tree transformations coded as [[rewrite rule]]s using surface-syntax conditioned by any extracted program facts, using DMS's Rule Specification Language (RSL). The rewrite rule engine supporting RSL handles associative and commutative rules. A rewrite rule for C to replace a complex condition by the
<syntaxhighlight lang="text">
rule simplify_conditional_assignment(v:left_hand_side,e1:expression,e2:expression,e3:expression)
:statement->statement
Line 44:
-> " \v=\e1?\e2:\e3; "
if no_side_effects(v);
</syntaxhighlight>
Rewrite '''rule'''s have names, e.g. '''simplify_conditional_assignment'''. Each rule has a ''"match this"'' and ''"replace by that"'' pattern pair separated by '''->''', in our example, on separate lines for readability. The patterns must correspond to language syntax categories; in this case, both patterns must be of syntax category '''statement''' also separated in sympathy with the patterns by '''->'''. Target language (e.g., C) surface syntax is coded inside meta-quotes '''"''', to separate rewrite-rule syntax from that of the target language. Backslashes inside meta-quotes represent ___domain escapes, to indicate pattern meta variables (e.g., '''\v''', '''\e1''', '''\e2''') that match any language construct corresponding to the metavariable declaration in the signature line, e.g., '''e1''' must be of syntactic category: ''(any) expression''. If a metavariable is mentioned multiple times in the ''match'' pattern, it must match to identical subtrees; the same identically shaped '''v''' must occur in both assignments in the match pattern in this example. Metavariables in the ''replace'' pattern are replaced by the corresponding matches from the left side. A conditional clause '''if''' provides an additional condition that must be met for the rule to apply, e.g., that the matched metavariable '''v''', being an arbitrary left-hand side, must not have a side effect (e.g., cannot be of the form of '''a[i++]'''; the '''no_side_effects''' predicate is defined by an analyzer built with other DMS mechanisms).
|