ROSE  0.11.145.0
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
Rosebud::Ast::File Class Reference

Description

An input file.

Definition at line 399 of file Ast.h.

#include <Rosebud/Ast.h>

Inheritance diagram for Rosebud::Ast::File:
Inheritance graph
[legend]
Collaboration diagram for Rosebud::Ast::File:
Collaboration graph
[legend]

Public Types

using Ptr = FilePtr
 Shared-ownership pointer. More...
 
- Public Types inherited from Rosebud::Ast::Node
using Ptr = NodePtr
 
- Public Types inherited from Sawyer::Tree::Vertex< Node >
using UserBase = Node
 User's base class. More...
 
using UserBasePtr = std::shared_ptr< UserBase >
 Pointer to user's base class. More...
 
using TraversalEvent = Sawyer::Tree::TraversalEvent
 Alias for traversal events. More...
 

Public Member Functions

std::string name ()
 Name of the input file. More...
 
TokenStreamtokenStream ()
 Token stream for the file. More...
 
const Token token (size_t lookAhead=0)
 Current or future token. More...
 
bool matchesAny (size_t tokenPosition, const std::vector< std::string > &)
 Test whether a token matches any text. More...
 
bool startsWith (const Token &, const char *)
 Test whether a token starts with a certain string. More...
 
std::string content (const std::vector< Token > &, Expand)
 Input string for token list. More...
 
std::string content (size_t begin, size_t end)
 Part of file. More...
 
void emitContext (std::ostream &, const Token &first, const Token &locus, const Token &last)
 Emit the context for a diagnostic message. More...
 
std::string lexeme (size_t position=0)
 Text associated with a token. More...
 
std::string lexeme (const Token &)
 Text associated with a token. More...
 
bool matches (const Token &, const char *)
 Test whether a token matches a string. More...
 
bool matches (const Token &, const std::string &)
 Test whether a token matches a string. More...
 
bool matches (size_t lookAhead, const char *)
 Test whether a token matches a string. More...
 
bool matches (size_t lookAhead, const std::string &)
 Test whether a token matches a string. More...
 
bool matches (const char *)
 Test whether a token matches a string. More...
 
bool matches (const std::string &)
 Test whether a token matches a string. More...
 
Token consume ()
 Consume tokens. More...
 
void consume (size_t n)
 Consume tokens. More...
 
std::string trimmedContent (size_t begin, size_t end, Token &outputToken)
 Input string for file region. More...
 
std::string trimmedContent (size_t begin, size_t end, const Token &exclude, Token &outputToken)
 Input string for file region. More...
 
- Public Member Functions inherited from Rosebud::Ast::Node
template<class T >
std::shared_ptr< T > findAncestor ()
 
- Public Member Functions inherited from Sawyer::Tree::Vertex< Node >
UserBasePtr pointer ()
 Returns a shared pointer to this vertex. More...
 
std::shared_ptr< T > isa ()
 Tests whether this object is a certain type. More...
 
auto traverseReverse (const Visitor &visitor)
 Traverse in reverse direction from children to parents. More...
 
auto traverse (const Visitor &visitor)
 Traverse in forward direction from parents to children. More...
 
auto traversePre (const Visitor &visitor)
 Pre-order forward traversal. More...
 
auto traversePost (const Visitor &visitor)
 Post-order forward traversal. More...
 
std::shared_ptr< T > findFirstAncestor ()
 Traversal that finds the closest ancestor of type T or derived from T. More...
 
std::shared_ptr< T > findLastAncestor ()
 Traversal that finds the farthest ancestor of type T or derived from T. More...
 
std::vector< std::shared_ptr< T > > findDescendants ()
 Traversal that finds all the descendants of a particular type. More...
 
UserBasePtr child (size_t i) const
 Returns the pointer for a child. More...
 
size_t nChildren () const
 Returns the number of children. More...
 

Static Public Member Functions

static Ptr instance (const std::string &name)
 Allocating constructor. More...
 

Public Attributes

EdgeVector< Classclasses
 Non-null list of zero or more class definitions. More...
 
std::string endText
 Text after the last class definition until the end of the file. More...
 
Token endTextToken
 Token that encloses endText. More...
 
- Public Attributes inherited from Sawyer::Tree::Vertex< Node >
ReverseEdge parent
 Pointer to the parent in the tree. More...
 
EdgeBase * treeEdges_
 

Protected Member Functions

 File (const std::string &name)
 Constructor used only by derived classes. More...
 
- Protected Member Functions inherited from Sawyer::Tree::Vertex< Node >
virtual void destructorHelper ()
 

Member Typedef Documentation

Shared-ownership pointer.

Definition at line 402 of file Ast.h.

Constructor & Destructor Documentation

Rosebud::Ast::File::File ( const std::string &  name)
protected

Constructor used only by derived classes.

Member Function Documentation

static Ptr Rosebud::Ast::File::instance ( const std::string &  name)
static

Allocating constructor.

The specified name must be the name of an existing text file that can be opened for reading.

std::string Rosebud::Ast::File::name ( )

Name of the input file.

TokenStream& Rosebud::Ast::File::tokenStream ( )

Token stream for the file.

These tokens are consumed by parsing, but the stream itself is left here as a data member because it still contains useful information such as the file name, the content of the file as text by which tokens can be converted to strings, and information about line and column numbers.

const Token Rosebud::Ast::File::token ( size_t  lookAhead = 0)

Current or future token.

Returns the current token, or one of the future tokens.

std::string Rosebud::Ast::File::lexeme ( size_t  position = 0)

Text associated with a token.

Returns the input text that caused the current or future token.

Attention: when testing whether a token matches some string, use one of the matching functions if possible instead of obtaining a string and comparing it to another string. The matching functions are more efficient.

std::string Rosebud::Ast::File::lexeme ( const Token )

Text associated with a token.

Returns the input text that caused the current or future token.

Attention: when testing whether a token matches some string, use one of the matching functions if possible instead of obtaining a string and comparing it to another string. The matching functions are more efficient.

bool Rosebud::Ast::File::matches ( const Token ,
const char *   
)

Test whether a token matches a string.

Returns true if the specified token matches a string. A token can be passed as an argument, or specified as a future token (lookAhead > 1), or the current token (no argument, or lookAhead == 0).

bool Rosebud::Ast::File::matches ( const Token ,
const std::string &   
)

Test whether a token matches a string.

Returns true if the specified token matches a string. A token can be passed as an argument, or specified as a future token (lookAhead > 1), or the current token (no argument, or lookAhead == 0).

bool Rosebud::Ast::File::matches ( size_t  lookAhead,
const char *   
)

Test whether a token matches a string.

Returns true if the specified token matches a string. A token can be passed as an argument, or specified as a future token (lookAhead > 1), or the current token (no argument, or lookAhead == 0).

bool Rosebud::Ast::File::matches ( size_t  lookAhead,
const std::string &   
)

Test whether a token matches a string.

Returns true if the specified token matches a string. A token can be passed as an argument, or specified as a future token (lookAhead > 1), or the current token (no argument, or lookAhead == 0).

bool Rosebud::Ast::File::matches ( const char *  )

Test whether a token matches a string.

Returns true if the specified token matches a string. A token can be passed as an argument, or specified as a future token (lookAhead > 1), or the current token (no argument, or lookAhead == 0).

bool Rosebud::Ast::File::matches ( const std::string &  )

Test whether a token matches a string.

Returns true if the specified token matches a string. A token can be passed as an argument, or specified as a future token (lookAhead > 1), or the current token (no argument, or lookAhead == 0).

bool Rosebud::Ast::File::matchesAny ( size_t  tokenPosition,
const std::vector< std::string > &   
)

Test whether a token matches any text.

Returns true if the specified token matches any of the supplied strings.

bool Rosebud::Ast::File::startsWith ( const Token ,
const char *   
)

Test whether a token starts with a certain string.

Returns true if the specified token begins with the specified characters.

Token Rosebud::Ast::File::consume ( )

Consume tokens.

Consume the current token, or n tokens. This is used during parsing, so by time a backend code generator is called all the tokens have presumably been consumed and the stream is sitting at the special EOF token. Consuming the EOF token is permissible, but has no effect.

void Rosebud::Ast::File::consume ( size_t  n)

Consume tokens.

Consume the current token, or n tokens. This is used during parsing, so by time a backend code generator is called all the tokens have presumably been consumed and the stream is sitting at the special EOF token. Consuming the EOF token is permissible, but has no effect.

std::string Rosebud::Ast::File::content ( const std::vector< Token > &  ,
Expand   
)

Input string for token list.

Returns a string for the specified tokens by concatenating the strings for the individual tokens. Depending on the second argument, the returned string includes either just the token text, the text between the start of the first token and the end of the last token, or the same plus the non-token text before the first token.

std::string Rosebud::Ast::File::content ( size_t  begin,
size_t  end 
)

Part of file.

Returns some text from the file from the starting byte offset (inclusive) to the ending byte offset (exclusive).

std::string Rosebud::Ast::File::trimmedContent ( size_t  begin,
size_t  end,
Token outputToken 
)

Input string for file region.

Returns the content of the file from character position begin (inclusive) to end (exclusvie). If the end is less than or equal to begin, then an empty string is returned. The text is modified by removing trailing white space from each line, replacing consecutive blank lines with a single blank line, and removing leading and trailing blank lines. If an exclude token is specified, then its text is not included in the returned string.

std::string Rosebud::Ast::File::trimmedContent ( size_t  begin,
size_t  end,
const Token exclude,
Token outputToken 
)

Input string for file region.

Returns the content of the file from character position begin (inclusive) to end (exclusvie). If the end is less than or equal to begin, then an empty string is returned. The text is modified by removing trailing white space from each line, replacing consecutive blank lines with a single blank line, and removing leading and trailing blank lines. If an exclude token is specified, then its text is not included in the returned string.

void Rosebud::Ast::File::emitContext ( std::ostream &  ,
const Token first,
const Token locus,
const Token last 
)

Emit the context for a diagnostic message.

The input lines corresponding to the tokens are emitted to standard error. The part of that input corresponding to the tokens is marked by underlining it, and the start of the locus token is marked in a special way.

Member Data Documentation

EdgeVector<Class> Rosebud::Ast::File::classes

Non-null list of zero or more class definitions.

Definition at line 409 of file Ast.h.

std::string Rosebud::Ast::File::endText

Text after the last class definition until the end of the file.

The text is modified by removing trailing white space from each line, replacing consecutive blank lines with a single blank line, and removing leading and trailing blank lines.

Definition at line 415 of file Ast.h.

Token Rosebud::Ast::File::endTextToken

Token that encloses endText.

This generated token of type TOK_OTHER encloses the file content that produced endText.

Definition at line 420 of file Ast.h.


The documentation for this class was generated from the following file: