Command-Line Semantic Match

## 13 Command-Line Semantic Match

It is possible to specify a semantic match on the spatch command line, using the argument --sp. In such a semantic match, any token beginning with a capital letter is assumed to be a metavariable of type metavariable. In this case, the parser must be able to figure out what kind of metavariable it is. It is also possible to specify the type of a metavariable by enclosing the type in :’s, concatenated directly to the metavariable name.

Some examples of semantic matches that can be given as an argument to --sp are as follows:

- f(e): This only matches the expression f(e).
- f(E): This matches a call to f with any argument.
- F(E): This gives a parse error; the semantic patch parser cannot figure out what kind of metavariable F is.
- F:identifier:(E): This matches any one argument function call.
- f:identifier:(e:struct foo *:): This matches any one argument function call where the argument has type struct foo *. Since the types of the metavariables are specified, it is not necessary for the metavariable names to begin with a capital letter.
- F:identifier:(F): This matches any one argument function call where the argument is the name of the function itself. This example shows that it is not necessary to repeat the metavariable type name.
- F:identifier:(F:identifier:): This matches any one argument function call where the argument is the name of the function itself. This example shows that it is possible to repeat the metavariable type name.

When constraints, e.g. when != e, are allowed but the expression e must be represented as a single token.

The generated semantic match behaves as though there were a * in front of every token.