Wikibooks: ROSE Compiler Framework/AST Matching

The AST Matching Mechanism rose/src/midend/astMatching The following documentation is in the following file (but not finished yet and doesn t show up in doxygen) rose/src/midend/astMatching/AstMatching.docs The examples give a good overview of what you can do with the matcher. Note it uses its own p...

Full description

Bibliographic Details
Format: Book
Language:English
Subjects:
Online Access:https://en.wikibooks.org/wiki/ROSE_Compiler_Framework/AST_Matching
Description
Summary:The AST Matching Mechanism rose/src/midend/astMatching The following documentation is in the following file (but not finished yet and doesn t show up in doxygen) rose/src/midend/astMatching/AstMatching.docs The examples give a good overview of what you can do with the matcher. Note it uses its own parser and implements its own specification language for specifying match expressions (with a number of different operators). The matcher is implemented on top of the AST iterator the matcher is for that reason a use case of the iterator. =Introduction= The AstMatching mechanism allows to specify arbitrary large patterns to be matched on any subtree in the AST. The patterns are specified as strings and the type names of the AST nodes can be used to specify the AST patterns. Additionally variables and some operators are available to allow the specification of complex patterns. Subtrees can also be ignored in the matching by using . The binary operator allows to combine different matching subexpressions into one expression. Variables are used for specifying pointers to which matched subtrees are stored in the matching result for further processing by the user. In the following example we match assignments with variables on both sides such as x=y and assign the result to the variable $R. #include rose.h #include AstTerm.h #include AstMatching.h AstMatching m MatchResult res=m.performMatching( $R=SgAssignOp(SgVarRef SgVarRef) astRoot) where astRoot is a pointer to some node in the AST. AssignOp and SgVarRef are the names of ROSE AST nodes and $R is the name of a matcher variable. In the above example all subtrees representing an assign operation with two variables as operands would be matched. The dollar sign denotes a variable. In the above example the pointers to the matched subtrees are assigned to the variable $R. The result with all matched assignments is stored in the variable res of type AstMatchingResult. The matching result is a set of maps where each map represents the results for one successful match and holds ...