ROSE  0.11.145.0
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
Rosebud Namespace Reference

Description

Rosebud is a tool to generate code for ROSE.

Namespaces

 Ast
 Abstract syntax tree.
 

Classes

class  BoostSerializer
 Class serializer using Boost Serialization. More...
 
class  CxxGenerator
 Base class for generators that produce C++ code. More...
 
class  Generator
 Base class for backend code generators. More...
 
struct  HierarchyKey
 Key for ordering classes in the class hierarchy. More...
 
class  NoneGenerator
 Generator that produces a YAML description of the input. More...
 
class  NoneSerializer
 Class serializer using None Serialization. More...
 
class  RoseGenerator
 Generator that produces ROSE code. More...
 
class  RosettaGenerator
 Generator that produces ROSETTA output. More...
 
class  Serializer
 Base class for serialization generators. More...
 
struct  Settings
 Command-line settings for the rosebud tool. More...
 
class  YamlGenerator
 Generator that produces a YAML description of the input. More...
 

Typedefs

using Token = Sawyer::Language::Clexer::Token
 A token parsed from the input file. More...
 
using TokenStream = Sawyer::Language::Clexer::TokenStream
 A stream of tokens from the input file. More...
 
using GeneratorPtr = std::shared_ptr< Generator >
 Shared-ownership pointer to a Generator. More...
 
using SerializerPtr = std::shared_ptr< Serializer >
 Shared-ownership pointer to a Serializer. More...
 
using Hierarchy = Sawyer::Container::Graph< Ast::ClassPtr, Sawyer::Nothing, HierarchyKey >
 Class hierarchy. More...
 
using Classes = std::vector< Ast::ClassPtr >
 Ordered sequence of classes. More...
 

Enumerations

enum  Expand {
  Expand::NONE,
  Expand::INTER,
  Expand::PRIOR
}
 How to obtain text when converting a sequence of tokens to a string. More...
 
enum  When {
  When::NEVER,
  When::ALWAYS,
  When::AUTO
}
 When something should be done. More...
 
enum  Access {
  Access::PRIVATE,
  Access::PROTECTED,
  Access::PUBLIC
}
 Kinds of access. More...
 

Functions

std::vector< std::string > splitIntoLines (const std::string &)
 Split a multi-line string into one string per line. More...
 
void eraseBlankLines (std::vector< std::string > &)
 Remove lines that are empty or contain only white space. More...
 
void trimBlankLines (std::vector< std::string > &)
 Trim leading, trailing, and internal blank lines and trailing white space. More...
 
size_t editDistance (const std::string &src, const std::string &tgt)
 Compute the Damerau-Levenshtein edit distance between two strings. More...
 
double relativeDifference (const std::string &src, const std::string &tgt)
 Compute the relative difference between two strings. More...
 
std::string bestMatch (const std::vector< std::string > &candidates, const std::string &sample)
 Returns the best match. More...
 
std::string toString (Access)
 Convert an access enum to a C++ string. More...
 
boost::filesystem::path findRoseRootDir (const boost::filesystem::path &)
 Find the root of the ROSE source tree. More...
 
boost::filesystem::path relativeToRoseSource (const boost::filesystem::path &)
 Convert a file path to a ROSE-relative path. More...
 
boost::filesystem::path toPath (const std::string &symbol, const std::string &extension)
 Convert a qualified C++ name to a relative path. More...
 
std::string appendToDoxygen (const std::string &existingComment, const std::string &newText)
 Append text to a Doxygen comment. More...
 
bool usingColor ()
 True if we're using color output for diagnostics. More...
 
std::string messageString (Sawyer::Message::Importance, const std::string &mesg)
 Convert an importance level and message to an error output string. More...
 
Hierarchy classHierarchy (const Classes &)
 Generate the class hierarchy from the specified class definitions. More...
 
void checkClassHierarchy (Hierarchy &)
 Check for problems such as cycles in the class hiearchy and report them as errors. More...
 
Classes topDown (Hierarchy &)
 Return all the class definitions so that base classes are before derived classes. More...
 
Classes bottomUp (Hierarchy &)
 Return all the class definitions so that derived classes appear before base classes. More...
 
Classes derivedClasses (const Ast::ClassPtr &, const Hierarchy &)
 Return all known subclasses. More...
 
bool isBaseClass (const Ast::ClassPtr &, const Hierarchy &)
 True if the class is a base class of some other class. More...
 
std::vector< Ast::PropertyPtrallConstructorArguments (const Ast::ClassPtr &, const Hierarchy &)
 Properties that form constructor arguments. More...
 
std::string firstPublicBaseClass (const Ast::ClassPtr &)
 Name of first public base class. More...
 
std::string constRef (const std::string &type)
 Turn a type into a const reference to the type. More...
 
std::string removeVolatileMutable (const std::string &type)
 Rmove "volatile" and "mutable" from the beginning of a type string. More...
 
std::string toCppSymbol (const std::string &)
 Convert a C++ qualified name to a CPP symbol. More...
 
std::vector< std::string > extractCpp (std::string &, const std::regex &, size_t capture)
 Extract all matching C preprocessor directives from the text. More...
 
std::string matching (const std::string &)
 Return the matching opening or closing construct. More...
 
char matching (char)
 Return the matching opening or closing construct. More...
 
std::string prefixLines (const std::string &s, const std::string &prefix)
 Add a prefix to every line.
 
void prefixLines (std::vector< std::string > &lines, const std::string &prefix)
 Add a prefix to every line.
 
std::string makeBlockComment (const std::string &text, const std::string &opening)
 Make a block comment. More...
 
std::vector< std::string > makeBlockComment (const std::vector< std::string > &textLines, const std::string &opening)
 Make a block comment. More...
 
std::string makeTitleComment (const std::string &multiLine, const std::string &prefix, char bar, size_t width)
 Make a title comment that spans the entire width of the source code. More...
 
std::vector< std::string > makeTitleComment (const std::vector< std::string > &lines, const std::string &prefix, char bar, size_t width)
 Make a title comment that spans the entire width of the source code. More...
 
void message (Sawyer::Message::Importance, const Ast::FilePtr &, const Token &, const std::string &mesg)
 Print a diagnostic message to standard error. More...
 
void message (Sawyer::Message::Importance, const Ast::FilePtr &, const Token &begin, const Token &focus, const Token &end, const std::string &mesg)
 Print a diagnostic message to standard error. More...
 
void message (Sawyer::Message::Importance, const Ast::FilePtr &, const std::vector< Token > &, const std::string &mesg)
 Print a diagnostic message to standard error. More...
 
void message (Sawyer::Message::Importance, const std::string &mesg)
 Print a diagnostic message to standard error. More...
 
void message (Sawyer::Message::Importance, const Ast::FilePtr &, const std::string &mesg)
 Print a diagnostic message to standard error. More...
 
std::string locationDirective (size_t line, const std::string &file)
 Input location information. More...
 
std::string locationDirective (const Ast::NodePtr &, const Token &)
 Input location information. More...
 

Variables

Settings settings
 Command-line settings for the rosebud tool. More...
 
size_t nErrors
 Number of error messages reported. More...
 

Typedef Documentation

A token parsed from the input file.

Definition at line 10 of file ud/BasicTypes.h.

A stream of tokens from the input file.

Definition at line 13 of file ud/BasicTypes.h.

using Rosebud::GeneratorPtr = typedef std::shared_ptr<Generator>

Shared-ownership pointer to a Generator.

Definition at line 30 of file ud/BasicTypes.h.

using Rosebud::SerializerPtr = typedef std::shared_ptr<Serializer>

Shared-ownership pointer to a Serializer.

Definition at line 32 of file ud/BasicTypes.h.

Class hierarchy.

The vertices are pointers to AST class nodes. The edges point from base classes to derived classes.

Definition at line 213 of file ud/Utility.h.

using Rosebud::Classes = typedef std::vector<Ast::ClassPtr>

Ordered sequence of classes.

Definition at line 216 of file ud/Utility.h.

Enumeration Type Documentation

enum Rosebud::Expand
strong

How to obtain text when converting a sequence of tokens to a string.

Enumerator
NONE 

Each token's [begin,end) individually.

INTER 

From first token's begin to last token's end.

PRIOR 

From first token's prior to last token's end.

Definition at line 16 of file ud/BasicTypes.h.

enum Rosebud::When
strong

When something should be done.

Enumerator
NEVER 

Never do it.

ALWAYS 

Always do it.

AUTO 

Sometimes do it.

Definition at line 23 of file ud/BasicTypes.h.

enum Rosebud::Access
strong

Kinds of access.

Enumerator
PRIVATE 

Like C++ private access.

PROTECTED 

Like C++ protected access.

PUBLIC 

Like C++ public access.

Definition at line 20 of file ud/Utility.h.

Function Documentation

std::string Rosebud::matching ( const std::string &  )

Return the matching opening or closing construct.

E.g., if input is "{" then output is "}" and vice versa.

char Rosebud::matching ( char  )

Return the matching opening or closing construct.

E.g., if input is "{" then output is "}" and vice versa.

std::vector<std::string> Rosebud::splitIntoLines ( const std::string &  )

Split a multi-line string into one string per line.

Splits the input string at its line termination characters and return a vector of the resulting lines without their line termination characters. Since ROSE source code is prohibited from using carriage returns, we only have to worry about line feeds.

void Rosebud::eraseBlankLines ( std::vector< std::string > &  )

Remove lines that are empty or contain only white space.

void Rosebud::trimBlankLines ( std::vector< std::string > &  )

Trim leading, trailing, and internal blank lines and trailing white space.

  • Trailing white space is removed from each line.
  • Leading blank lines are removed.
  • Trailing blank lines are removed.
  • Two or more consecutive blank lines are replaced by a single blank line
size_t Rosebud::editDistance ( const std::string &  src,
const std::string &  tgt 
)

Compute the Damerau-Levenshtein edit distance between two strings.

double Rosebud::relativeDifference ( const std::string &  src,
const std::string &  tgt 
)

Compute the relative difference between two strings.

Computes the editDistance as a ratio of the string length, returning a value between zero and one.

std::string Rosebud::bestMatch ( const std::vector< std::string > &  candidates,
const std::string &  sample 
)

Returns the best match.

Given a list of candidate strings and a sample, return the candidate that is most similar to the sample.

std::string Rosebud::toString ( Access  )

Convert an access enum to a C++ string.

boost::filesystem::path Rosebud::findRoseRootDir ( const boost::filesystem::path &  )

Find the root of the ROSE source tree.

Given the name of a file inside the ROSE source tree, return the absolute name of the root directory of the ROSE source tree. If the root directory cannot be found (e.g., the specified file is not inside the ROSE source tree), then return an empty path. The file need not exist.

boost::filesystem::path Rosebud::relativeToRoseSource ( const boost::filesystem::path &  )

Convert a file path to a ROSE-relative path.

If the specified file name is inside the ROSE source tree, then return the name of the file relative to the root of the ROSE source tree. Returns the empty path if the file is not inside the ROSE source tree. The file need not exist.

boost::filesystem::path Rosebud::toPath ( const std::string &  symbol,
const std::string &  extension 
)

Convert a qualified C++ name to a relative path.

The return value is a relative path of components separated by the system's path component separator ("/" on POSIX systems). The components of the path are the components of the C++ qualified name that are separated by "::". The file name extension is appended to the result before returning.

std::string Rosebud::makeBlockComment ( const std::string &  text,
const std::string &  opening 
)

Make a block comment.

The string is split into lines. The first line is prefixed with the opening text and the prefix for the following lines is created automatically from the opening text. This works for both C-style and C++-style comments. If the opening contains neither a C-style nor C++-style comment opening, then C-style is assumed and the opening is used as-is for the prefix for all lines. The closing token for C-style comments hangs on the last line of text. If there is no text, then the return value is similarly empty.

std::vector<std::string> Rosebud::makeBlockComment ( const std::vector< std::string > &  textLines,
const std::string &  opening 
)

Make a block comment.

The string is split into lines. The first line is prefixed with the opening text and the prefix for the following lines is created automatically from the opening text. This works for both C-style and C++-style comments. If the opening contains neither a C-style nor C++-style comment opening, then C-style is assumed and the opening is used as-is for the prefix for all lines. The closing token for C-style comments hangs on the last line of text. If there is no text, then the return value is similarly empty.

std::string Rosebud::makeTitleComment ( const std::string &  multiLine,
const std::string &  prefix,
char  bar,
size_t  width 
)

Make a title comment that spans the entire width of the source code.

This is similar to the wide //////... comments in this header file.

std::vector<std::string> Rosebud::makeTitleComment ( const std::vector< std::string > &  lines,
const std::string &  prefix,
char  bar,
size_t  width 
)

Make a title comment that spans the entire width of the source code.

This is similar to the wide //////... comments in this header file.

std::string Rosebud::appendToDoxygen ( const std::string &  existingComment,
const std::string &  newText 
)

Append text to a Doxygen comment.

Given a Doxygen block comment (or nothing), append the specified multi-line text to the end of the comment. The new text should not include start or end with C-style comment delimiters or contain C++-style or box decorations at the start of each line of new text; these will be added automatically.

bool Rosebud::usingColor ( )

True if we're using color output for diagnostics.

std::string Rosebud::messageString ( Sawyer::Message::Importance  ,
const std::string &  mesg 
)

Convert an importance level and message to an error output string.

The returned string may have ANSI color codes and will have line termination.

void Rosebud::message ( Sawyer::Message::Importance  ,
const Ast::FilePtr ,
const Token ,
const std::string &  mesg 
)

Print a diagnostic message to standard error.

Messages contain the following parts:

  • The multi-line message
  • The importance
  • The file name if a file is provided, otherwise the program name
  • The line and column number if a token is provided
  • The lines from the source file if a token is provided
  • An indication of the important part of the line if a token is provided and a source line is emitted

The message will include the name of the input file, the position in the input file, and a copy of the relevant part of the input file

void Rosebud::message ( Sawyer::Message::Importance  ,
const Ast::FilePtr ,
const Token begin,
const Token focus,
const Token end,
const std::string &  mesg 
)

Print a diagnostic message to standard error.

Messages contain the following parts:

  • The multi-line message
  • The importance
  • The file name if a file is provided, otherwise the program name
  • The line and column number if a token is provided
  • The lines from the source file if a token is provided
  • An indication of the important part of the line if a token is provided and a source line is emitted

The message will include the name of the input file, the position in the input file, and a copy of the relevant part of the input file

void Rosebud::message ( Sawyer::Message::Importance  ,
const Ast::FilePtr ,
const std::vector< Token > &  ,
const std::string &  mesg 
)

Print a diagnostic message to standard error.

Messages contain the following parts:

  • The multi-line message
  • The importance
  • The file name if a file is provided, otherwise the program name
  • The line and column number if a token is provided
  • The lines from the source file if a token is provided
  • An indication of the important part of the line if a token is provided and a source line is emitted

The message will include the name of the input file, the position in the input file, and a copy of the relevant part of the input file

void Rosebud::message ( Sawyer::Message::Importance  ,
const std::string &  mesg 
)

Print a diagnostic message to standard error.

Messages contain the following parts:

  • The multi-line message
  • The importance
  • The file name if a file is provided, otherwise the program name
  • The line and column number if a token is provided
  • The lines from the source file if a token is provided
  • An indication of the important part of the line if a token is provided and a source line is emitted

The message will include the name of the input file, the position in the input file, and a copy of the relevant part of the input file

void Rosebud::message ( Sawyer::Message::Importance  ,
const Ast::FilePtr ,
const std::string &  mesg 
)

Print a diagnostic message to standard error.

Messages contain the following parts:

  • The multi-line message
  • The importance
  • The file name if a file is provided, otherwise the program name
  • The line and column number if a token is provided
  • The lines from the source file if a token is provided
  • An indication of the important part of the line if a token is provided and a source line is emitted

The message will include the name of the input file, the position in the input file, and a copy of the relevant part of the input file

Hierarchy Rosebud::classHierarchy ( const Classes )

Generate the class hierarchy from the specified class definitions.

The edges in the graph point from base classes to derived classes.

void Rosebud::checkClassHierarchy ( Hierarchy )

Check for problems such as cycles in the class hiearchy and report them as errors.

Classes Rosebud::topDown ( Hierarchy )

Return all the class definitions so that base classes are before derived classes.

Classes Rosebud::bottomUp ( Hierarchy )

Return all the class definitions so that derived classes appear before base classes.

Classes Rosebud::derivedClasses ( const Ast::ClassPtr ,
const Hierarchy  
)

Return all known subclasses.

bool Rosebud::isBaseClass ( const Ast::ClassPtr ,
const Hierarchy  
)

True if the class is a base class of some other class.

std::vector<Ast::PropertyPtr> Rosebud::allConstructorArguments ( const Ast::ClassPtr ,
const Hierarchy  
)

Properties that form constructor arguments.

std::string Rosebud::firstPublicBaseClass ( const Ast::ClassPtr )

Name of first public base class.

std::string Rosebud::constRef ( const std::string &  type)

Turn a type into a const reference to the type.

Input Output
--------------- ----------
char char const&
char* char* const&
const char* const char* const&
std::string Rosebud::removeVolatileMutable ( const std::string &  type)

Rmove "volatile" and "mutable" from the beginning of a type string.

std::string Rosebud::locationDirective ( size_t  line,
const std::string &  file 
)

Input location information.

This returns a C preprocessor #line directive with line termintion that resets source information as specified. If location information is disabled, then the empty string is returned.

std::string Rosebud::locationDirective ( const Ast::NodePtr ,
const Token  
)

Input location information.

This returns a C preprocessor #line directive with line termintion that resets source information as specified. If location information is disabled, then the empty string is returned.

std::string Rosebud::toCppSymbol ( const std::string &  )

Convert a C++ qualified name to a CPP symbol.

This is done by replacing all the "::" with "_".

std::vector<std::string> Rosebud::extractCpp ( std::string &  ,
const std::regex &  ,
size_t  capture 
)

Extract all matching C preprocessor directives from the text.

Modifies the string in place and returns one preprocessor directive per vector element. If capture is non-zero, then it refers to a parenthetical capture group in the regular expression, and just that group is saved in the return vector.

Variable Documentation

Settings Rosebud::settings

Command-line settings for the rosebud tool.

size_t Rosebud::nErrors

Number of error messages reported.