ここには 2 つのネストされた式があり、代入の Left ノードを格納してから、2 番目のバイナリ式ノードまで完全なパターンを使用して AST をさらにトラバースし、add の左右のノードを取得します。例えば:
// BinaryExpr [getOperationCode() = KTC_OPCODE_ASSIGN] [$exprOL:= Left]
ここで、代入式の左ノードを見つけて保存します。
// BinaryExpr [getOperationCode() = KTC_OPCODE_ASSIGN] [$exprOL:= Left] / Right::BinaryExpr [getOperationCode() = KTC_OPCODE_ADD]
そして、加算式を取得し続けます。最後に、この式の Left と Right を取得できます。
// BinaryExpr [getOperationCode() = KTC_OPCODE_ASSIGN] [$exprOL:= Left] / Right::BinaryExpr [getOperationCode() = KTC_OPCODE_ADD]
[$exprL:= Left]
[$exprR:= Right]
これをテストするには、println() 関数を使用できます。だから完全な表現
// BinaryExpr [getOperationCode() = KTC_OPCODE_ASSIGN] [$exprOL:= Left] / Right::BinaryExpr [getOperationCode() = KTC_OPCODE_ADD]
[$exprL:= Left]
[$exprR:= Right]
[$exprOL.getName().println()]
[$exprL.getName().println()]
[$exprR.getName().println()]
次のコードの場合:
int func (int x, int y)
{
int local;
local = x;
local = x + y;
local = y - x;
return local;
}
印刷します:
local
x
y