Previous Up Next

8  Declarations

decl_var   ::=  common_decl
|[storage] ctype COMMA_LIST(d_ident) ;
|[storage] [const_vol] id COMMA_LIST(d_ident) ;
|[storage] fn_ctype ( * d_ident ) ( PARAMSEQ(name_opt_decl, ε) ) = initialize ;
|typedef ctype COMMA_LIST(typedef_ident) ;
|typedef ctype typedef_ident [expr];
|typedef ctype typedef_ident [expr] [expr];
|OR(decl_var)
|AND(decl_var)
one_decl   ::=  common_decl
|[storage] ctype id [attribute];
|OR(one_decl)
|AND(one_decl)
 |[storage] [const_vol] id d_ident ;
common_decl   ::=  ctype;
|funproto
|[storage] ctype d_ident [attribute] = initialize ;
|[storage] [const_vol] id d_ident [attribute] = initialize ;
|[storage] fn_ctype ( * d_ident ) ( PARAMSEQ(name_opt_decl, ε) ) ;
|decl_ident ( [COMMA_LIST(expr)] ) ;
initialize   ::=  dot_expr
|metaidInitialiser
|{ [COMMA_LIST(init_list_elem)] }
init_list_elem   ::=  dot_expr
|designator = initialize
|metaidInitialiser
|metaidInitialiserList
|id : dot_expr
designator   ::=  . id
|[ dot_expr ]
|[ dot_expr ... dot_expr ]
decl_ident   ::=  DeclarerId
|metaidDeclarer

An initializer for a structure can be ordered or unordered. It is considered to be unordered if there is at least one key-value pair initializer, e.g., .x = e.

A declaration can have e.g. the form register x;. In this case, the variable implicitly has type int, and SmPL code that declares an int variable will match such a declaration. On the other hand, the implicit int type has no position. If the SmPL code tries to record the position of the type, the match will fail.

An attribute begins with __ or is declared as an attribute name in the semantic patch. In practice, only one attribute is currently allowed after the variable name in a variable declaration.

Coccinelle supports declaring multiple variables or structure fields in the C code, but not in the SmPL code. It is possible to remove a variable from within a declaration of multiple variables with a pattern that removes a complete single-variable declaration, e.g., - int x;. The type and the semicolon are only removed if all of the variables are removed. It is also possible to specify to entirely remove such a declaration and replace it with something else. The replacement of a declaration only matches if the addition is done with ++, allowing multiple additions. This is also only allowed if there is no implicitly matched information on the type, such as extern or static. When the transformation cannot be made, there is no crash, simply a match failure. A message is given for this with the --debug option.


Previous Up Next