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

Description

Rosebud is a tool to generate abstract syntax trees.

The Rosebud tool (rosebud command) reads class definitions for abstract syntax tree (AST) vertex types and generates C++ source code.

The definition language is C++-like, enabling any C++ programmer to author or modify AST vertex classes. The C++-like language means the input is natively understood by integrated development environments (IDEs) and code editors. Rosebud aims to make common class definitions easy, and more complex definitions possible. The language supports Doxygen-style comments, delayed-decision conditional compilation, independent AST class hierarchies, abstract classes with pure virtual member functions, read-only properties, and more.

The Rosebud tool uses modern translation techniques such as referential lexical tokens and partial parsing. Rosebud can process the 400 "SgAsm" AST definitions and generate code in a fraction of a second. Its diagnostic messages (warnings and errors) follow the LLVM style, are readable by almost all IDEs, include the input source line and position indicators, and are colorized. Rosebud's AST for its intermediate representation is self hosted and fully documented.

Depending on which backend is chosen, the generated code uses modern C++ features such as reference counted pointers for clearly documented vertex ownership and safe, automatic deletion; exception safe adjustment to the tree edges (vertex connectivity); immediate tree consistency checks with violations reported by exceptions; and automatic, read-only parent pointers. Generated definitions make heavy use of automatically-generated forward declarations to achieve efficient compilation (although this is currently heavily counteracted by the policy that all ROSE source code includes the huge "sage3basic.h" or "rose.h" header files).

Input Language

The input language is a subset of the C preprocessor and C++. As such, the input easily understood by experienced C++ programmers and can be operated on in almost any integrated development environment or code editor.

The various code-generation backends have slightly different rules for what they support. The documentation below indicates which backends support which input language features when support is not universal. The "yaml" backend supports everything since it simply emits the AST as a YAML document.

Input files

Each AST vertex class definition appears in its own header file. The header file name reflects the name of the class, and the directory path [reflects the namespace containing the class (Sawyer)] [is chosen based on the set of rosebud command-line options that are needed (ROSETTA)]. These files are typically named with a ".h" extension so that IDEs and code editors can recognize them as C++ without any special configuration. For instance, the [Rose::Sarif::Log class is defined in "src/AstNodes/Rose/Sarif/Log.h"] [SgAsmGenericSection class is defined in "src/AstNodes/BinaryAnalysis" (ROSETTA)].

Class definition

A Rosebud class definition is similar to a C++ class definition. The class is introduced by a Doxygen double-asterisk C-style comment, followed by an optional list of C++ attributes (some of which are special Rosebud attributes), followed by the word "class", the class name, an optional base class list, an opening curly brace, member specifications, a closing curly brace, and the terminating semi-colon.

The following Rosebud class attributes are understood:

Property members

A property is a ROSE IR feature where a value is stored in an object and is accessed and modified with special generated functions. The Rosebud syntax for a property looks like a C++ data member. It consists of the Doxygen documentation comment, the list of C++ attributes one or more of which must be a Rosebud attribute, the data member type, the data member name, the optional initialization constexpr, and the terminating semicolon.

The only thing that sets a property apart from a normal data member is the presence of at least one Rosebud attribute. The following Rosebud attributes are understood:

Backend Generators

The rosebud tool parses the definitions from the input files (described above) to create an intermediate representation (AST) and then one or more "backends" traverse the AST to emit C++ source code or other information. The three main backends are:

Features of the ROSETTA backend

The ROSETTA backend does not use a special type to indicate that a pointer data member is also an edge in the tree. Instead, the data member is marked with the Rosebud::traverse attribute, like this:

class SgParent: public SgNode {
public:
// This property is an edge in the tree
[[using Rosebud: rosetta, traverse]]
SgChild *child = nullptr;
// This property is not a tree edge.
[[Rosebud::rosetta]]
SgChild *other = nullptr;
};
This class represents the base class for all IR nodes within Sage III.
Rosebud is a tool to generate abstract syntax trees.
Definition Ast.h:14

The accessor and mutator functions are, by default, named by prepending "get_" and "set_". However, much code in ROSE accesses the property data members directly by prepending "p_". This is a bad practice since it bypasses any other actions (such as invariant checking, mutex aquisition, signaling, etc) that might also need to occur when a property is modified.

parent->p_other = node; // don't do this
parent->set_other(node); // do this instead

Each vertex class has an automatically generated parent pointer that must be manually adjusted so the child points back to the parent, like this:

parent->set_child(child);
if (child)
child->set_parent(parent);

Detaching a node is similarly difficult:

if (auto child = parent->get_child()) {
parent->set_child(nullptr);
child->set_parent(nullptr);
}

Failing to set the child's parent pointer correctly is a detectable runtime error, but the check is delayed until the user remembers to call the appropriate whole-tree checking function at a later tmie. Similarly for other programming errors such as creating a cycle or having multiple vertices pointing to the same child–checks are delayed until some point at which the user remembers to check the tree consistency.

A ROSETTA-generated type should not have edges that point to individual children intermixed with vectors that point to many children. In order to do that reliably one must create an intermediate type to hold the vector:

class SgArgumentList: public SgNode {
public:
[[Rosebud::traverse]]
std::vector<SgArgument*> arguments;
};
class SgFunctionCall: public SgNode {
public:
[[Rosebud::traverse]]
SgName *name;
[[Rosebud::traverse]]
SgArgumentList *arguments = nullptr;
};
SgFunctionCall* makeBinaryCall(SgName *name, SgArgument *arg1, SgArgument *arg2) {
auto call = new SgFunctionCall;
call->set_name(name);
if (name)
name->set_parent(call);
auto argList = new SgArgumentList;
call->set_arguments(argList);
argList->set_parent(call);
argList->get_arguments().push_back(arg1);
if (arg1)
arg1->set_parent(argList);
argList->get_arguments().push_back(arg2);
if (arg2)
arg2->set_parent(argList);
return call;
}
This class represents strings within the IR nodes.

Since ROSETTA uses raw pointers, it is up to the user to know when an object is no longer part of any tree and no longer pointed to by anything else in ROSE. Sometimes an analysis will cache its results, and thus have pointers into the AST. The best practice with ROSETTA-generated code is to never free any AST vertex.

if (auto child = parent->get_child()) {
parent->set_child(nullptr);
child->set_parent(nullptr);
SageInterface::deleteAST(child); // UNSAFE -- never do this!
}
ROSE_DLL_API void deleteAST(SgNode *node)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...

Features of the Sawyer backend

The Sawyer backend generates AST vertex classes that inherit from Sawyer::Tree::Vertex, and it uses smart pointers. The smart pointer types have the names Ptr and ConstPtr both as members of the vertex class and by appending those names to the name of the class. The latter are useful in places like header files where one doesn't want the compiler to spend time parsing the class definition and only incomplete types are needed. Unlike the ROSETTA backend, the smart pointer data members do not need to be explicitly initialized to nullptr (their constructors take care of that). An AST edge is indicated with the type Edge, like this:

class SgParent: public SgNode {
public:
// This property is an edge in the tree
[[Rosebud::property]]
// This property is not a tree edge
[[Rosebud::property]]
SgChildPtr other;

The accessor and mutator functions are, by default, named the same thing as the property. The data members for the properties are effectively hidden by being given names that include a random string. Therefore the bad practice of setting the data member directly is no longer possible–all property modifications must go through the generated mutators.

parent->p_other = node; // compile-time error
parent->other(node); // do this instead
parent->forceSetOther(node); // or do this in the defining class if there are no public mutators

Each vertex class has an automatically generated parent pointer. Unlike ROSETTA, this pointer does not need to be adjusted explicitly, and trying to do so is a compile-time error.

parent->child(child); // now child->parent() == parent

Detaching a node is similarly easy:

parent->child(nullptr); // previous child (if any) now has a null parent pointer

Failing to set the parent correctly is not possible like it is with the ROSETTA backend. Also, the Sawyer backend immediately checks that the tree is not malformed in these ways, which are all exception safe:

The Sawyer backend supports mixing scalar and vector edge types within a single AST vertex class. Unlike the ROSETTA backend, there is no need to define an intermediate class to hold the vector.

class SgFunctionCall: public SgNode {
public:
[[Rosebud::property]]
[[Rosebud::property]]
EdgeVector<SgArgument> arguments;
};
SgFunctionCall* makeBinaryCall(const SgName::Ptr &name, const SgArgument::Ptr &arg1, const SgArgument::Ptr &arg2) {
auto call = SgFunctionCall::instance();
call->name(name); // name->parent() == call
call->arguments().push_back(arg1); // arg1->parent() == call
call->arguments().push_back(arg2); // arg2->parent() == call
return call;
}

Since Sawyer uses reference counting pointers, objects that are no longer part of a tree and which are no longer pointed to by anything else in the program are automatically and immediately deleted. The user should not evern explicitly delete AST vertices. However, the user must be careful not to introduce self-referential data structures since cycles will prevent the objects from being deleted even if there are no other pointers to the data structure. This backend does not yet support weak pointers.

parent->child(nullptr); // previous child is deleted if no other references

Building and running Rosebud

Rosebud is distributed as part of the ROSE library source code under the same license. It is built and installed automatically as part of building and installing the ROSE library.

The ROSE library has a number of AST class hierarchies that are generated by Rosebud. Some of these are also passed through the ROSETTA CxxGrammarMetaProgram tool using Rosebud's --backend=rosetta switch, and others are translated to C++ directly using Rosebud's --backend=sawyer switch. Other switches are also necessary in certain situations. The generate script makes sure the correct rosebud commands are run to produce all generated files. The generated files are currently checked into the ROSE library source repository for improved stability while Rosebud is being developed.

To regenerate files, go to the "src/Rosebud" directory in the build tree and build the rosebud executable by running your preferred build system. Then generate files by running this command from that same directory, replacing "$ROSE_SOURCE" with the top-level directory of the ROSE library repository:

$ $ROSE_SOURCE/src/Rosebud/generate ./rosebud

You may need to add the --source=$ROSE_SOURCE switch before "./rosebud" if the script cannot determine the locaton of the ROSE source directory.

The following directories are used:

Comparison with ROSETTA

ROSETTA is/was the previous AST vertex class definition mechanism and is still used for most parts of the main AST. It has served well for many years, but its main drawbacks are:

Namespaces

namespace  Ast
 Abstract syntax tree.
 

Classes

class  BoostSerializer
 Class serializer using Boost Serialization. More...
 
class  CerealSerializer
 Class serializer producing JSON. 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  RosettaGenerator
 Generator that produces ROSETTA output. More...
 
class  SawyerGenerator
 Generator that produces Sawyer::Tree class hierarchies. 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.
 
using TokenStream = Sawyer::Language::Clexer::TokenStream
 A stream of tokens from the input file.
 
using GeneratorPtr = std::shared_ptr< Generator >
 Shared-ownership pointer to a Generator.
 
using SerializerPtr = std::shared_ptr< Serializer >
 Shared-ownership pointer to a Serializer.
 
using Hierarchy = Sawyer::Container::Graph< Ast::ClassPtr, Sawyer::Nothing, HierarchyKey >
 Class hierarchy.
 
using Classes = std::vector< Ast::ClassPtr >
 Ordered sequence of classes.
 

Enumerations

enum class  Expand {
  NONE ,
  INTER ,
  PRIOR
}
 How to obtain text when converting a sequence of tokens to a string. More...
 
enum class  When {
  NEVER ,
  ALWAYS ,
  AUTO
}
 When something should be done. More...
 
enum class  Access {
  PRIVATE ,
  PROTECTED ,
  PUBLIC ,
  DEFAULT
}
 Kinds of access. More...
 
enum class  CamelCase {
  LOWER ,
  UPPER ,
  UNCHANGED
}
 What to do with the first letter of the return value. More...
 

Functions

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

Variables

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

Typedef Documentation

◆ Token

A token parsed from the input file.

Definition at line 459 of file Rosebud/BasicTypes.h.

◆ TokenStream

A stream of tokens from the input file.

Definition at line 462 of file Rosebud/BasicTypes.h.

◆ GeneratorPtr

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

Shared-ownership pointer to a Generator.

Definition at line 479 of file Rosebud/BasicTypes.h.

◆ SerializerPtr

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

Shared-ownership pointer to a Serializer.

Definition at line 481 of file Rosebud/BasicTypes.h.

◆ Hierarchy

Class hierarchy.

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

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

◆ Classes

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

Ordered sequence of classes.

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

Enumeration Type Documentation

◆ Expand

enum class 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 465 of file Rosebud/BasicTypes.h.

◆ When

enum class Rosebud::When
strong

When something should be done.

Enumerator
NEVER 

Never do it.

ALWAYS 

Always do it.

AUTO 

Sometimes do it.

Definition at line 472 of file Rosebud/BasicTypes.h.

◆ Access

enum class Rosebud::Access
strong

Kinds of access.

Enumerator
PRIVATE 

Like C++ private access.

PROTECTED 

Like C++ protected access.

PUBLIC 

Like C++ public access.

DEFAULT 

Use whatever access is already present.

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

◆ CamelCase

enum class Rosebud::CamelCase
strong

What to do with the first letter of the return value.

Enumerator
LOWER 

Make the first character lower case.

UPPER 

Make the first character upper case.

UNCHANGED 

Leave the first character as it is in the input.

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

Function Documentation

◆ matching() [1/2]

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.

◆ matching() [2/2]

char Rosebud::matching ( char  )

Return the matching opening or closing construct.

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

◆ splitIntoLines()

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.

◆ trimBlankLines()

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

◆ relativeDifference()

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.

◆ bestMatch()

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.

◆ findRoseRootDir()

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.

◆ relativeToRoseSource()

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.

◆ toPath()

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.

◆ makeBlockComment() [1/2]

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.

◆ makeBlockComment() [2/2]

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.

◆ makeTitleComment() [1/2]

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.

◆ makeTitleComment() [2/2]

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.

◆ appendToDoxygen()

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.

◆ messageString()

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.

◆ message() [1/5]

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

◆ message() [2/5]

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

◆ message() [3/5]

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

◆ message() [4/5]

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

◆ message() [5/5]

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

◆ classHierarchy()

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.

◆ constRef()

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&

◆ locationDirective() [1/2]

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.

◆ locationDirective() [2/2]

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.

◆ toCppSymbol()

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

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

This is done by replacing all the "::" with "_". Leading underscores are removed. A leading "Rose_" string is replaced with "ROSE_".

◆ extractCpp()

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.