Category: Tutorial

Match expressions when assigned to a boolean variable

In this example, we propose to write a patch that matches usages of expressions assigned to a boolean variable. Here, you will get familiar with the concept of expression. The following semantic patch also uses inheritance of metavariable between rules, the definition of custom types and type restriction for expressions. @find_expression@ typedef bool; bool id; …

Continue reading

Match structure usage

In this example we address the case where the type of the variables we want to match the usage is in fact a structure. The study of the following semantic patch will teach you about how to impose constraints on expressions and specifically how to specify the type of a variable when it is a …

Continue reading

Matching variable declarations if they have the same type as a variable named “foo”

In this example we try to find variables of a specific type. It is similar to the first example but instead of using a fixed type we want to consider all types that were used to declare any variable named “foo”. You will learn how to inherit metavariable bindings from one rule to another and …

Continue reading

Matching usage of bool variables

In this example we write a semantic patch to match the uses of a variable having a user defined type. This tutorial explains how to name rules. We introduce two metavariable types, namely typedef and idexpression. Here we will be studying the following patch: @find_usage@ typedef bool; idexpression bool id; @@   * id@find_usage@ typedef …

Continue reading

Matching int variable declaration

One of the first things you might want to do is find every context in which a variable of a specific type is defined. In this example you will learn about semantic rules and metavariables. You will be introduced to one specific type of metavariable namely identifier. The notion of statement is also an important …

Continue reading