ROSE 0.11.145.281
|
Represents a source file containing related snippets.
See Snippet class for top-level documentation.
A SnippetFile represents a source file that contains one or more related snippet functions along with other necessary information at the global scope. Each Snippet is associated with exactly one SnippetFile and whenever any snippet from the file is inserted into a specimen, certain statements from the snippet file's global scope are copied into the specimen's global scope. This copying happens only once per SnippetFile-specimen pair. By placing related snippets in the same source file we can be sure that only one copy of the snippet's global prerequisites are injected into the specimen. By keeping unrelated snippets in separate files we can prevent global prerequisites for one snippet to be inserted when an unrelated snippet is injected.
The SnippetFile class keeps a list of all its objects and returns a pointer to an existing SnippetFile in preference to creating a new one. The lookup is performed according to the source file name supplied to the instance() constructor (no attempt is made to determine when unequal names resolve to the same source file).
#include <midend/astSnippet/Snippet.h>
Public Member Functions | |
const std::string & | getName () const |
Returns the name of the file. | |
std::vector< std::string > | getSnippetNames () const |
Returns the list of snippet names. | |
SnippetPtr | findSnippet (const std::string &snippetName) |
Return a Snippet having the specified name. | |
std::vector< SnippetPtr > | findSnippets (const std::string &snippetName) |
Returns all snippets having the specified name. | |
void | expandSnippets (SgNode *ast) |
Insert snippets in marked code. | |
bool | globallyInjected (SgGlobal *destination_scope) |
Indicates that global entities have been injected. | |
bool | fileIsIncluded (const std::string &filename, SgGlobal *destination_scope) |
Indicates that the specified file has been included into the specified scope. | |
SgFile * | getAst () const |
Get the AST for the entire snippet file. | |
void | doNotInsert (const std::string &name, SgType *type=NULL) |
Black list. | |
bool | isBlackListed (SgDeclarationStatement *) |
Return true if the declaration is black listed. | |
const std::vector< SnippetInsertion > & | getInsertedItems () const |
Information about things that have been inserted. | |
bool | getCopyAllSnippetDefinitions () const |
Accessor for the property that controls whether snippet definitions are copied into the global scope. | |
void | setCopyAllSnippetDefinitions (bool b=true) |
Accessor for the property that controls whether snippet definitions are copied into the global scope. | |
void | clearCopyAllSnippetDefinitions () |
Accessor for the property that controls whether snippet definitions are copied into the global scope. | |
Static Public Member Functions | |
static SnippetFilePtr | instance (const std::string &fileName, SgSourceFile *snippetAst=NULL) |
Constructor. | |
static SnippetFilePtr | lookup (const std::string &fileName) |
Look up the SnippetFile for this file name. | |
static size_t | loadVariableNames (const std::string &fileName) |
Load variable names from a file. | |
static std::string | randomVariableName () |
Return a random variable name. | |
Protected Member Functions | |
SnippetFile (const std::string &fileName, SgSourceFile *ast=NULL) | |
Use instance() instead. | |
void | findSnippetFunctions () |
Find all snippet functions (they are the top-level function definitions) and add them to this SnippetFile. | |
void | addInsertionRecord (const SnippetInsertion &inserted) |
Add an insertion record. | |
Static Protected Member Functions | |
static SgSourceFile * | parse (const std::string &fileName) |
Parse the snippet file. | |
|
inlineexplicitprotected |
Use instance() instead.
|
static |
Constructor.
Returns an existing SnippetFile if one has previosly been created for this file name, or creates a new one. No attempt is made to determine whether unequal names resolve to the same file. If a new SnippetFile needs to be created then we either use the provided AST or we parse the file.
|
static |
Look up the SnippetFile for this file name.
Returns the SnippetFile for this file if it exists, otherwise returns null. No attempt is made to determine whether unequal names resolve to the same file.
|
inline |
Returns the name of the file.
This is the same name given to the instance() constructor.
SnippetPtr Rose::SnippetFile::findSnippet | ( | const std::string & | snippetName | ) |
Return a Snippet having the specified name.
The name must be fully a fully qualified function name. Returns null if the snippet cannot be found in this SnippetFile. If there is more than one snippet with this name then only one is returned (the first one).
std::vector< SnippetPtr > Rose::SnippetFile::findSnippets | ( | const std::string & | snippetName | ) |
Returns all snippets having the specified name.
All snippets in this snippet file that have the specified name are returned in the order they are defined in the file.
void Rose::SnippetFile::expandSnippets | ( | SgNode * | ast | ) |
Insert snippets in marked code.
The specified AST is traversed and function calls to snippets which are defined in this SnippetFile are recursively expanded.
bool Rose::SnippetFile::globallyInjected | ( | SgGlobal * | destination_scope | ) |
Indicates that global entities have been injected.
For every snippet injected into a larger specimen some things from the snippet's global scope need to be injected into the speicmen's global scope. This global injection should only happen once per SnippetFile/specimen pair regardless of how many times a snippet is injected or how many snippets from the same SnippetFile are injected.
This method records the fact that global entities from this SnippetFile have been injected into the specified global scope, and returns a boolean to indicate whether they had already been injected (true if injected, false if not).
bool Rose::SnippetFile::fileIsIncluded | ( | const std::string & | filename, |
SgGlobal * | destination_scope | ||
) |
Indicates that the specified file has been included into the specified scope.
Returns the previous value.
|
static |
Load variable names from a file.
The file should have one name per line. Returns the number of variable names added to the list.
|
inline |
|
inline |
|
inline |
|
inline |
void Rose::SnippetFile::doNotInsert | ( | const std::string & | name, |
SgType * | type = NULL |
||
) |
Black list.
This is a list of declarations that should not be copied from the snippet file to the target file. Declarations are specified with a qualified name and an optional type. If the type is omitted then only names are compared.
|
inline |
|
staticprotected |
Parse the snippet file.
Snippet files are normally parsed when the SnippetFile object is constructed via instance() class method. Throws an std::runtime_error on failure.
|
inlineprotected |