ROSE 0.11.145.281
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
Rose::SnippetFile Class Reference

Description

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).

Definition at line 51 of file Snippet.h.

#include <midend/astSnippet/Snippet.h>

Inheritance diagram for Rose::SnippetFile:
Inheritance graph
[legend]
Collaboration diagram for Rose::SnippetFile:
Collaboration graph
[legend]

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< SnippetPtrfindSnippets (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.
 
SgFilegetAst () 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 SgSourceFileparse (const std::string &fileName)
 Parse the snippet file.
 

Constructor & Destructor Documentation

◆ SnippetFile()

Rose::SnippetFile::SnippetFile ( const std::string &  fileName,
SgSourceFile ast = NULL 
)
inlineexplicitprotected

Use instance() instead.

Definition at line 75 of file Snippet.h.

Member Function Documentation

◆ instance()

static SnippetFilePtr Rose::SnippetFile::instance ( const std::string &  fileName,
SgSourceFile snippetAst = NULL 
)
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.

◆ lookup()

static SnippetFilePtr Rose::SnippetFile::lookup ( const std::string &  fileName)
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.

◆ getName()

const std::string & Rose::SnippetFile::getName ( ) const
inline

Returns the name of the file.

This is the same name given to the instance() constructor.

Definition at line 89 of file Snippet.h.

◆ findSnippet()

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).

◆ findSnippets()

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.

◆ expandSnippets()

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.

◆ globallyInjected()

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).

◆ fileIsIncluded()

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.

◆ loadVariableNames()

static size_t Rose::SnippetFile::loadVariableNames ( const std::string &  fileName)
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.

◆ getAst()

SgFile * Rose::SnippetFile::getAst ( ) const
inline

Get the AST for the entire snippet file.

Definition at line 127 of file Snippet.h.

◆ getCopyAllSnippetDefinitions()

bool Rose::SnippetFile::getCopyAllSnippetDefinitions ( ) const
inline

Accessor for the property that controls whether snippet definitions are copied into the global scope.

If true, then all function definitions in the snippet file are copied into the global scope of the file into which the snippet is being inserted.

Definition at line 133 of file Snippet.h.

◆ setCopyAllSnippetDefinitions()

void Rose::SnippetFile::setCopyAllSnippetDefinitions ( bool  b = true)
inline

Accessor for the property that controls whether snippet definitions are copied into the global scope.

If true, then all function definitions in the snippet file are copied into the global scope of the file into which the snippet is being inserted.

Definition at line 134 of file Snippet.h.

◆ clearCopyAllSnippetDefinitions()

void Rose::SnippetFile::clearCopyAllSnippetDefinitions ( )
inline

Accessor for the property that controls whether snippet definitions are copied into the global scope.

If true, then all function definitions in the snippet file are copied into the global scope of the file into which the snippet is being inserted.

Definition at line 135 of file Snippet.h.

◆ doNotInsert()

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.

◆ getInsertedItems()

const std::vector< SnippetInsertion > & Rose::SnippetFile::getInsertedItems ( ) const
inline

Information about things that have been inserted.

Definition at line 147 of file Snippet.h.

◆ parse()

static SgSourceFile * Rose::SnippetFile::parse ( const std::string &  fileName)
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.

◆ addInsertionRecord()

void Rose::SnippetFile::addInsertionRecord ( const SnippetInsertion inserted)
inlineprotected

Add an insertion record.

Definition at line 158 of file Snippet.h.


The documentation for this class was generated from the following file: