Coccinelle patterns are designed to match source code that contains some construct. The following is a technique that can be used to match source code that does not contain some construct. For instance, to match all if-statements whose then arm contains a statement that is not a compound statement, i.e., not enclosed in curly brackets.

The idea is to create two patterns, one that matches just the construct that is not required and another that matches a generalised set of that construct and use position meta-variables to exclude the specific cases from the general cases.

@curly_if@

position p;
@@

if@p (...) { ... }

@simple_if@
position p != curly_if.p;
statement S;
@@

if@p (...) S

The all_if pattern will match all if-statements, but the requirement that p != curly_if.p excludes those cases where the statement has the form of a compound statement.

 
matching_code_that_does_not_contain_some_construct.txt · Last modified: 2009/08/21 21:31 by derek_jones
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki