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
id ftwikibooks:enwikibooks:69319:384075
record_format openpolar
spelling ftwikibooks:enwikibooks:69319:384075 2023-06-18T03:43:20+02:00 Wikibooks: ROSE Compiler Framework/AST Matching https://en.wikibooks.org/wiki/ROSE_Compiler_Framework/AST_Matching eng eng Book ftwikibooks 2023-06-02T13:41:25Z 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 ... Book The Pointers WikiBooks - Open-content textbooks
institution Open Polar
collection WikiBooks - Open-content textbooks
op_collection_id ftwikibooks
language English
description 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 ...
format Book
title Wikibooks: ROSE Compiler Framework/AST Matching
spellingShingle Wikibooks: ROSE Compiler Framework/AST Matching
title_short Wikibooks: ROSE Compiler Framework/AST Matching
title_full Wikibooks: ROSE Compiler Framework/AST Matching
title_fullStr Wikibooks: ROSE Compiler Framework/AST Matching
title_full_unstemmed Wikibooks: ROSE Compiler Framework/AST Matching
title_sort wikibooks: rose compiler framework/ast matching
url https://en.wikibooks.org/wiki/ROSE_Compiler_Framework/AST_Matching
genre The Pointers
genre_facet The Pointers
_version_ 1769009674544218112