3#ifndef ROSE_AST_SNIPPET
4#define ROSE_AST_SNIPPET
10#include <boost/shared_ptr.hpp>
11#include <boost/enable_shared_from_this.hpp>
34std::ostream& operator<<(std::ostream&,
const SnippetInsertion&);
51class SnippetFile:
public boost::enable_shared_from_this<SnippetFile> {
60 std::set<SgGlobal*> globals;
61 std::map<std::string, std::set<SgGlobal*>> headersIncluded;
66 static std::vector<std::string> varNameList;
67 bool copyAllSnippetDefinitions;
71 std::vector<SnippetInsertion> insertions;
76 : fileName(fileName), ast(ast), copyAllSnippetDefinitions(false) {}
89 const std::string&
getName()
const {
return fileName; }
51class SnippetFile:
public boost::enable_shared_from_this<SnippetFile> {
…};
342 bool insertRecursively;
349 insertRecursively(true), fixupAst(true) {
350 assert(!name.empty());
364 const std::string&
getName() const {
return name; }
460 void traverse(
SgNode *ast);
461 virtual void operator()(
SgNode*, AstSimpleProcessing::Order) = 0;
Extends std::map with methods that return optional values.
Java-aware AST traversal.
Represents a source file containing related snippets.
bool globallyInjected(SgGlobal *destination_scope)
Indicates that global entities have been injected.
void setCopyAllSnippetDefinitions(bool b=true)
Accessor for the property that controls whether snippet definitions are copied into the global scope.
bool fileIsIncluded(const std::string &filename, SgGlobal *destination_scope)
Indicates that the specified file has been included into the specified scope.
void doNotInsert(const std::string &name, SgType *type=NULL)
Black list.
const std::vector< SnippetInsertion > & getInsertedItems() const
Information about things that have been inserted.
static std::string randomVariableName()
Return a random variable name.
const std::string & getName() const
Returns the name of the file.
std::vector< SnippetPtr > findSnippets(const std::string &snippetName)
Returns all snippets having the specified name.
void clearCopyAllSnippetDefinitions()
Accessor for the property that controls whether snippet definitions are copied into the global scope.
SgFile * getAst() const
Get the AST for the entire snippet file.
std::vector< std::string > getSnippetNames() const
Returns the list of snippet names.
static size_t loadVariableNames(const std::string &fileName)
Load variable names from a file.
SnippetPtr findSnippet(const std::string &snippetName)
Return a Snippet having the specified name.
static SnippetFilePtr instance(const std::string &fileName, SgSourceFile *snippetAst=NULL)
Constructor.
void expandSnippets(SgNode *ast)
Insert snippets in marked code.
void addInsertionRecord(const SnippetInsertion &inserted)
Add an insertion record.
bool getCopyAllSnippetDefinitions() const
Accessor for the property that controls whether snippet definitions are copied into the global scope.
SnippetFile(const std::string &fileName, SgSourceFile *ast=NULL)
Use instance() instead.
static SnippetFilePtr lookup(const std::string &fileName)
Look up the SnippetFile for this file name.
bool isBlackListed(SgDeclarationStatement *)
Return true if the declaration is black listed.
void findSnippetFunctions()
Find all snippet functions (they are the top-level function definitions) and add them to this Snippet...
static SgSourceFile * parse(const std::string &fileName)
Parse the snippet file.
Simple mechanism for inserting statements into a specimen.
InsertMechanism getInsertMechanism() const
Accessor for the snippet insertion mechanism.
void setFixupAst(bool b=true)
Determines whether the target AST should be fixed up after insertion.
bool getInsertRecursively() const
Accessor for the property that indicates whether an insert() should be recursive.
LocalDeclarationPosition
Determines where local declarations are injected when using INSERT_STMTS.
@ LOCDECLS_AT_CURSOR
Local declarations are not moved to a declarations area.
@ LOCDECLS_AT_BEGINNING
Local declarations inserted at beginning of function.
@ LOCDECLS_AT_END
Local declarations inserted at end of leading declarations.
void setInsertRecursively(bool b=true)
Accessor for the property that indicates whether an insert() should be recursive.
static SnippetPtr instanceFromFile(const std::string &snippetName, const std::string &fileName)
Construct a new Snippet.
static SnippetPtr instance(const std::string &snippetName, const SnippetFilePtr &snippetFile)
Construct a new Snippet.
SnippetFilePtr getFile() const
Return the file where this snippet is defined.
void setInsertMechanism(InsertMechanism im)
Accessor for the snippet insertion mechanism.
SgFunctionDefinition * getDefinition() const
Return the function definition for this snippet.
void insert(SgStatement *insertionPoint, const std::vector< SgNode * > &args)
Insert a snippet into the project.
InsertMechanism
Determines how a snippet is injected at the insertion point.
@ INSERT_BODY
Insert entire snippet body as a single scope.
@ INSERT_STMTS
Insert snippet statements one at a time.
void insert(SgStatement *insertionPoint, SgNode *arg1, SgNode *arg2)
Insert a snippet into the project.
void insertRelatedThingsForC(SgStatement *snippetInsertionPoint)
C-specific things that need to be copied from the snippet file to the target file.
bool getFixupAst() const
Determines whether the target AST should be fixed up after insertion.
void clearFixupAst()
Determines whether the target AST should be fixed up after insertion.
void insert(SgStatement *insertionPoint, SgNode *arg1, SgNode *arg2, SgNode *arg3, SgNode *arg4)
Insert a snippet into the project.
void insert(SgStatement *insertionPoint, SgNode *arg1, SgNode *arg2, SgNode *arg3)
Insert a snippet into the project.
static void removeIncludeDirectives(SgNode *)
Remove C preprocessor #include directives from the specified node.
static void replaceVariable(SgVarRefExp *, SgExpression *)
Replace a variable reference with some other expression.
void insert(SgStatement *insertionPoint)
Insert a snippet into the project.
static void replaceArguments(SgNode *ast, const ArgumentBindings &)
Replace formal argument occurrances with actual values.
void causeUnparsing(SgNode *ast, Sg_File_Info *targetLocation)
Mark nodes so they're unparsed when the insertion point is unparsed.
void renameTemporaries(SgNode *ast)
Rename snippet local variables so they don't interfere with names visible at the insertion point.
void insert(SgStatement *insertionPoint, SgNode *arg1)
Insert a snippet into the project.
const std::string & getName() const
Return the snippet name.
void setLocalDeclarationPosition(LocalDeclarationPosition pos)
Accessor for local declaration insertion position.
void insertRelatedThingsForJava(SgStatement *snippetInsertionPoint)
Java-specific things that need to be copied from the snippet file to the target file.
size_t numberOfArguments() const
Returns the number of formal arguments for the snippet.
void insertRelatedThings(SgStatement *snippetInsertionPoint)
Insert other things from the snippet file into the target file.
LocalDeclarationPosition getLocalDeclarationPosition() const
Accessor for local declaration insertion position.
void clearInsertRecursively()
Accessor for the property that indicates whether an insert() should be recursive.
This class represents the concept of a declaration statement.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes,...
This class represents a source file for a project (which may contian many source files and or directo...
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
This class represents the concept of a namespace definition.
This class represents the base class for all IR nodes within Sage III.
This class represents the notion of a statement.
This class represents the base class for all types.
This class represents the variable refernece in expressions.
This class represents the location of the code associated with the IR node in the original source cod...
boost::shared_ptr< class Snippet > SnippetPtr
Shared-ownership pointer to a Snippet object.
boost::shared_ptr< class SnippetFile > SnippetFilePtr
Shared-ownership pointer to a SnippetFile object.
Information about something that was inserted.
SgNode * inserted
What was inserted.
SgNode * original
Copied from this node of the snippet file.
SgNode * insertedBefore
Inserted before this node in the target file.