1#ifndef Rosebud_Utility_H
2#define Rosebud_Utility_H
3#include <Rosebud/Ast.h>
5#include <Sawyer/Graph.h>
6#include <Sawyer/Message.h>
7#include <Sawyer/Optional.h>
9#include <boost/filesystem.hpp>
15#define THIS_LOCATION locationDirective(__LINE__, __FILE__)
74std::string
prefixLines(
const std::string &s,
const std::string &prefix);
75void prefixLines(std::vector<std::string> &lines,
const std::string &prefix);
79size_t editDistance(
const std::string &src,
const std::string &tgt);
89std::string
bestMatch(
const std::vector<std::string> &candidates,
const std::string &sample);
111std::string
cEscape(
char ch,
char context =
'\'');
112std::string
cEscape(
const std::string&,
char context =
'"');
150boost::filesystem::path
toPath(
const std::string &symbol,
const std::string &extension);
166std::vector<std::string>
makeBlockComment(
const std::vector<std::string> &textLines,
const std::string &opening);
174std::string
makeTitleComment(
const std::string &multiLine,
const std::string &prefix,
char bar,
size_t width);
175std::vector<std::string>
makeTitleComment(
const std::vector<std::string> &lines,
const std::string &prefix,
char bar,
size_t width);
183std::string
appendToDoxygen(
const std::string &existingComment,
const std::string &newText);
216 const Token &end,
const std::string &mesg);
321std::vector<std::string>
extractCpp(std::string&,
const std::regex&,
size_t capture);
Graph containing user-defined vertices and edges.
std::shared_ptr< Class > ClassPtr
Shared-ownership pointer to a Class.
std::shared_ptr< Node > NodePtr
Shared-ownership pointer to a Node.
std::shared_ptr< File > FilePtr
Shared-ownership pointer to a File.
Rosebud is a tool to generate abstract syntax trees.
std::vector< std::string > splitIntoLines(const std::string &)
Split a multi-line string into one string per line.
Hierarchy classHierarchy(const Classes &)
Generate the class hierarchy from the specified class definitions.
std::vector< Ast::ClassPtr > Classes
Ordered sequence of classes.
size_t nErrors
Number of error messages reported.
std::string bourneEscape(const std::string &)
Quote string to make it shell safe.
std::string firstPublicBaseClass(const Ast::ClassPtr &)
Name of first public base class.
Classes bottomUp(Hierarchy &)
Return all the class definitions so that derived classes appear before base classes.
std::string camelCase(const std::string &, CamelCase=CamelCase::LOWER)
Convert snake case to camelCase.
size_t editDistance(const std::string &src, const std::string &tgt)
Compute the Damerau-Levenshtein edit distance between two strings.
std::string cEscape(char ch, char context='\'')
Escape as if in C single or double quotes.
std::string withLeadSpace(const std::string &)
String with one leading space.
bool isBaseClass(const Ast::ClassPtr &, const Hierarchy &)
True if the class is a base class of some other class.
CamelCase
What to do with the first letter of the return value.
@ UNCHANGED
Leave the first character as it is in the input.
@ UPPER
Make the first character upper case.
@ LOWER
Make the first character lower case.
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.
@ PROTECTED
Like C++ protected access.
@ DEFAULT
Use whatever access is already present.
@ PRIVATE
Like C++ private access.
@ PUBLIC
Like C++ public access.
void eraseBlankLines(std::vector< std::string > &)
Remove lines that are empty or contain only white space.
void checkClassHierarchy(Hierarchy &)
Check for problems such as cycles in the class hiearchy and report them as errors.
std::string matching(const std::string &)
Return the matching opening or closing construct.
std::string appendToDoxygen(const std::string &existingComment, const std::string &newText)
Append text to a Doxygen comment.
When
When something should be done.
void message(Sawyer::Message::Importance, const Ast::FilePtr &, const Token &, 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 removeVolatileMutable(const std::string &type)
Rmove "volatile" and "mutable" from the beginning of a type string.
std::string toString(Access)
Convert an access enum to a C++ string.
std::vector< std::string > extractCpp(std::string &, const std::regex &, size_t capture)
Extract all matching C preprocessor directives from the text.
boost::filesystem::path relativeToRoseSource(const boost::filesystem::path &)
Convert a file path to a ROSE-relative path.
std::string pascalCase(const std::string &)
Convert a symbol to PascalCase.
std::vector< Ast::PropertyPtr > allConstructorArguments(const Ast::ClassPtr &, const Hierarchy &)
Properties that form constructor arguments.
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.
bool usingColor()
True if we're using color output for diagnostics.
void trimBlankLines(std::vector< std::string > &)
Trim leading, trailing, and internal blank lines and trailing white space.
Classes topDown(Hierarchy &)
Return all the class definitions so that base classes are before derived classes.
Classes derivedClasses(const Ast::ClassPtr &, const Hierarchy &)
Return all known subclasses.
boost::filesystem::path findRoseRootDir(const boost::filesystem::path &)
Find the root of the ROSE source tree.
boost::filesystem::path toPath(const std::string &symbol, const std::string &extension)
Convert a qualified C++ name to a relative path.
std::string constRef(const std::string &type)
Turn a type into a const reference to the type.
std::string messageString(Sawyer::Message::Importance, const std::string &mesg)
Convert an importance level and message to an error output string.
std::string accessSpecifier(Access)
Return an access specifier with colon and trailing linefeed.
std::string prefixLines(const std::string &s, const std::string &prefix)
Add a prefix to every line.
std::string toCppSymbol(const std::string &)
Convert a C++ qualified name to a CPP symbol.
Settings settings
Command-line settings for the rosebud tool.
std::string makeBlockComment(const std::string &text, const std::string &opening)
Make a block comment.
Importance
Level of importance for a message.
Key for ordering classes in the class hierarchy.
bool operator<(const HierarchyKey &other) const
Compare keys.
std::string s
Class name is the key.
HierarchyKey(const std::string &s)
Construct key from name.
HierarchyKey(const Ast::ClassPtr &c)
Construct key from class.
Command-line settings for the rosebud tool.
std::vector< std::string > serializers
Name of the serializer code generator to use.
bool debugging
Generate additional debugging output.
std::string backend
Name of main backend code generator to use.
When usingColor
Use ANSI color escapes in the diagnostic output.
bool showingLocations
Output should show source location from whence it came.
bool showingWarnings
Show warnings about the input.