Previous Up Next

2  Metavariables for transformations

The rulename portion of the metavariable declaration can specify properties of a rule such as its name, the names of the rules that it depends on, the isomorphisms to be used in processing the rule, and whether quantification over paths should be universal or existential. The optional annotation expression indicates that the pattern is to be considered as matching an expression, and thus can be used to avoid some parsing problems.

The metadecl portion of the metavariable declaration defines various types of metavariables that will be used for matching in the transformation section.

metavariables   ::=  @@ metadecl * @@
|@ rulename @ metadecl * @@
rulename   ::=  id [extends id] [depends on dep] [iso] [disable-iso] [exists] [expression]
|script:language [depends on dep]
script_init_final   ::=  initialize:language
|finalize:language
dep   ::=  pnrule
|dep && dep
|dep || dep
pnrule   ::=  id
|!id
|ever id
|never id
|(dep)
iso   ::=  using string (, string) *
disable-iso   ::=  disable COMMA_LIST(id)
exists   ::=  exists
|forall
COMMA_LIST(elem)   ::=  elem (, elem) *

The keyword disable is normally used with the names of isomorphisms defined in standard.iso or whatever isomorphism file has been included. There are, however, some other isomorphisms that are built into the implementation of Coccinelle and that can be disabled as well. Their names are given below. In each case, the text descibes the standard behavior. Using disable-iso with the given name disables this behavior.

The possible types of metavariable declarations are defined by the grammar rule below. Metavariables should occur at least once in the transformation immediately following their declaration. Fresh metavariables must only be used in + code. These properties are not expressed in the grammar, but are checked by a subsequent analysis. The metavariables are designated according to the kind of terms they can match, such as a statement, an identifier, or an expression. An expression metavariable can be further constrained by its type.

metadecl   ::=  fresh identifier ids ;
|identifier COMMA_LIST(pmid_with_not_eq) ;
|parameter [list] ids ;
|parameter list [ id ] ids ;
|type ids ;
|statement [list] ids ;
|typedef ids ;
|declarer name ids ;
 |declarer COMMA_LIST(pmid_with_not_eq) ;
|iterator name ids ;
|iterator COMMA_LIST(pmid_with_not_eq) ;
 |[local] idexpression [ctype] COMMA_LIST(pmid_with_not_eq) ;
|[local] idexpression [{ctypes} * *] COMMA_LIST(pmid_with_not_eq) ;
|[local] idexpression * + COMMA_LIST(pmid_with_not_eq) ;
|expression list ids ;
|expression * + COMMA_LIST(pmid_with_not_eq) ;
|expression COMMA_LIST(pmid_with_not_ceq) ;
|expression list [ ident ] ids ;
|ctype [ ] COMMA_LIST(pmid_with_not_eq) ;
|ctype COMMA_LIST(pmid_with_not_ceq) ;
|{ctypes} * * COMMA_LIST(pmid_with_not_ceq) ;
|{ctypes} * * [ ] COMMA_LIST(pmid_with_not_eq) ;
|constant [ctype] COMMA_LIST(pmid_with_not_eq) ;
|constant [{ctypes} * *] COMMA_LIST(pmid_with_not_eq) ;
|position [any] COMMA_LIST(pmid_with_not_eq_mid) ;
ids   ::=  COMMA_LIST(pmid)
pmid   ::=  id
|mid
mid   ::=  rulename_id.id
pmid_with_not_eq   ::=  pmid [!= id]
|pmid [!= { COMMA_LIST(id) }]
pmid_with_not_ceq   ::=  pmid [!= id_or_cst]
|pmid [!= { COMMA_LIST(id_or_cst) }]
id_or_cst   ::=  id
|integer
pmid_with_not_eq_mid   ::=  pmid [!= mid]
|pmid [!= { COMMA_LIST(mid) }]

Subsequently, we refer to arbitrary metavariables as metaidty, where ty indicates the metakind used in the declaration of the variable. For example, metaidType refers to a metavariable that was declared using type and stands for any type.

The ctype and ctypes nonterminals are used by both the grammar of metavariable declarations and the grammar of transformations, and are defined on page ??.


Previous Up Next