4#include <Rosebud/BasicTypes.h>
6#include <Sawyer/Cached.h>
7#include <Sawyer/Tree.h>
69 std::shared_ptr<T> findAncestor() {
70 return traverseReverse<T>([](
const std::shared_ptr<T> &node,
TraversalEvent) {
121 std::vector<Token>::iterator
begin() {
124 std::vector<Token>::iterator
end() {
203 EdgeVector<TokenList> elmts;
369 using Inheritance = std::vector<std::pair<std::string , std::string>>;
481 bool matches(
size_t lookAhead,
const std::string&);
489 bool matchesAny(
size_t tokenPosition,
const std::vector<std::string>&);
517 std::string
content(
size_t begin,
size_t end);
A node that holds a list of arguments.
ArgumentListPtr Ptr
Shared-ownership pointer.
static Ptr instance()
Allocating constructor.
An attribute adjusting the details for a definition.
Attribute()
Default constructor used only by derived classes.
std::vector< Token > nameTokens
One or more tokens associated with the name.
Edge< ArgumentList > arguments
Attribute arguments.
std::string fqName
Fully qualified name.
static Ptr instance()
Allocating constructor.
static Ptr instance(const std::string &fqName, const std::vector< Token > &nameTokens)
Allocating constructor.
AttributePtr Ptr
Shared-ownership pointer.
Represents a class definition.
std::vector< std::pair< std::string, std::string > > Inheritance
A list of access specifiers and class names used for class inheritance.
Class()
Default constructor used only by derived classes.
std::string tag
If non-empty, overrides the tag name for this type.
EdgeVector< Property > properties
Non-null list of zero or more properties.
Inheritance inheritance
Information about base classes.
std::string qualifiedNamespace
If non-empty, the qualified namespace in which this class is defined.
Token endTextToken
Token that encloses endText.
static Ptr instance()
Allocating constructor.
ClassPtr Ptr
Shared-ownership pointer.
std::string endText
Text after the last member definition.
Information about C preprocessor conditional compilation directives.
std::list< Directive > Level
The CPP directives that belong to the same level.
static bool process(const FilePtr &, const Token &directive, Stack &runningStack)
Adjust the stack based on the C preprocessor directive.
Type
Type of CPP directive.
@ OTHER
Not a conditional compilation directive.
@ IF
#if, #ifdef, or #ifndef.
void emitOpen(std::ostream &)
Emit all control flow directives in this stack.
std::vector< Level > Stack
A stack of nested conditional compilation directives.
static Type type(const std::string &directive)
Type of directive.
bool printError(const FilePtr &file) const
Print an error message for the top of the stack if there's something wrong with it.
void emitClose(std::ostream &)
Emit matching #endif for all control flow directives in this stack.
Stack stack
The stack of nested conditional compilation directives.
CppStack()
Default constructor used only by derived classes.
static Ptr instance()
Allocating constructor.
CppStackPtr Ptr
Shared-ownership pointer.
Base class for class and property definitions.
std::string doc
Doxygen documentation comment.
Definition()
Default constructor used only by derived classes.
DefinitionPtr Ptr
Shared-ownership pointer.
Edge< CppStack > cppStack
C preprocessor pending conditional compilation directives.
EdgeVector< Attribute > attributes
Non-null pointer to the list of attributes controlling this property.
std::string priorText
Input text before the definition.
AttributePtr findAttribute(const std::string &fqName)
Finds an attribute with the specified fully qualified name.
Token docToken
Token associated with the Doxygen comment.
Token startToken
Token at the start of the definition.
Token nameToken
Token for the definition's unqualified name.
std::string name
Unqualified name for the definition.
Token priorTextToken
Token describing the location of the prior text.
void emitContext(std::ostream &, const Token &first, const Token &locus, const Token &last)
Emit the context for a diagnostic message.
std::string name()
Name of the input file.
FilePtr Ptr
Shared-ownership pointer.
std::string endText
Text after the last class definition until the end of the file.
bool matches(size_t lookAhead, const char *)
Test whether a token matches a string.
std::string content(size_t begin, size_t end)
Part of file.
std::string trimmedContent(size_t begin, size_t end, Token &outputToken)
Input string for file region.
std::string lexeme(size_t position=0)
Text associated with a token.
static Ptr instance(const std::string &name)
Allocating constructor.
bool matches(const Token &, const char *)
Test whether a token matches a string.
bool matchesAny(size_t tokenPosition, const std::vector< std::string > &)
Test whether a token matches any text.
std::string trimmedContent(size_t begin, size_t end, const Token &exclude, Token &outputToken)
Input string for file region.
const Token token(size_t lookAhead=0)
Current or future token.
bool startsWith(const Token &, const char *)
Test whether a token starts with a certain string.
bool matches(const Token &, const std::string &)
Test whether a token matches a string.
EdgeVector< Class > classes
Non-null list of zero or more class definitions.
void consume(size_t n)
Consume tokens.
Token consume()
Consume tokens.
bool matches(const char *)
Test whether a token matches a string.
bool matches(const std::string &)
Test whether a token matches a string.
File(const std::string &name)
Constructor used only by derived classes.
std::string lexeme(const Token &)
Text associated with a token.
bool matches(size_t lookAhead, const std::string &)
Test whether a token matches a string.
TokenStream & tokenStream()
Token stream for the file.
std::string content(const std::vector< Token > &, Expand)
Input string for token list.
Token endTextToken
Token that encloses endText.
Base class of all AST nodes for Rosebud.
Root of an AST for one or more input files.
ClassPtr findClassByName(const std::string &)
Find a class by name.
EdgeVector< File > files
Non-null list of input files.
ProjectPtr Ptr
Shared-ownership pointer.
std::vector< ClassPtr > allClassesFileOrder()
Return all classes defined in the input.
Project()
Default constructor used only by derived classes.
static Ptr instance()
Allocating constructor.
Represents a class property definition.
Sawyer::Optional< std::vector< std::string > > accessorNames
Optional override for accessor names.
Sawyer::Optional< std::vector< std::string > > mutatorNames
Optional override for mutator names.
Edge< TokenList > cType
Optional pointer to tokens that define the property type.
Edge< TokenList > cInit
Optional pointer to tokens that define the property's initial value.
Sawyer::Optional< std::string > serializerBaseName
Optional override for the serializer name.
PropertyPtr Ptr
Shared-ownership pointer.
static Ptr instance()
Allocating constructor.
Sawyer::Optional< std::string > dataMemberName
Optional data member name override.
Property()
Default constructor used only by derived classes.
Node that holds a sequence of consecutive tokens from an input file.
size_t size() const
Number of tokens.
TokenListPtr Ptr
Shared-ownership pointer.
void string(const std::string &)
Return the text for all tokens in this list.
std::vector< Token >::iterator begin()
Iterators.
std::vector< Token > tokens
The ordered tokens.
void push_back(const Token &token)
Insert a token at the end of the list.
std::string string()
Return the text for all tokens in this list.
bool empty() const
True if there are no tokens in this node.
TokenList()
Default constructor used only by derived classes.
std::string string(const FilePtr &)
Return the text for all tokens in this list.
static Ptr instance()
Allocating constructor.
std::vector< Token >::iterator end()
Iterators.
Implements cache data members.
Holds a value or nothing.
Base class for tree vertices.
std::shared_ptr< Class > ClassPtr
Shared-ownership pointer to a Class.
std::shared_ptr< Property > PropertyPtr
Shared-ownership pointer to a Property.
std::shared_ptr< Node > NodePtr
Shared-ownership pointer to a Node.
std::shared_ptr< Definition > DefinitionPtr
Shared-ownership pointer to a Definition.
std::shared_ptr< ArgumentList > ArgumentListPtr
Shared-ownership pointer to a ArgumentList.
std::shared_ptr< Project > ProjectPtr
Shared-ownership pointer to a Project.
std::shared_ptr< CppStack > CppStackPtr
Shared-ownership pointer to a CppStack.
std::shared_ptr< File > FilePtr
Shared-ownership pointer to a File.
std::shared_ptr< TokenList > TokenListPtr
Shared-ownership pointer to a TokenList.
std::shared_ptr< Attribute > AttributePtr
Shared-ownership pointer to a Attribute.
Rosebud is a tool to generate abstract syntax trees.
Expand
How to obtain text when converting a sequence of tokens to a string.
TraversalEvent
Traversal event.
Conditional compilation directive.
Token token
Token representing the conditional compilation directive.
std::string lexeme
Cached lexeme.
Type type
Type of conditional compilation directive.