PUMA Library Reference Manual
|
#include <Puma/Unit.h>
Token chain abstraction of a source file or string.
A unit is the result of scanning a file or string containing recognizable source code. The unit consists of a list of tokens that directly map to the characters and words of the source code.
A unit can have different states, such as being modified. After changing something on a unit, its state should be set to being modified.
All source code manipulations resp. transformations provided by PUMA are based on manipulating the token chain. Tokens can be added, moved, removed, and so on.
Translating the token chain back to the source code text is done by printing the unit using method Puma::Unit::print() or as shown in the following example.
Public Member Functions | |
Unit () | |
Constructor. | |
Unit (const List &list) | |
Copy-constructor. | |
virtual | ~Unit () |
Destructor. | |
virtual void | name (const char *name) |
Set the name of the unit (usually the file name). | |
char * | name () const |
Get the name of the unit (usually the file name). | |
virtual void | print (std::ostream &os) const |
Print the tokens of the unit on the given stream. | |
virtual bool | isFile () const |
Check if this is a unit for a file. | |
virtual bool | isMacroExp () const |
Check if this is a unit for a macro expansion. | |
virtual bool | isTemplateInstance () const |
Check if this is a unit for a template instance. | |
UnitState & | state () |
Get the state of the unit. | |
char * | toString () const |
Serialize the tokens of the unit. | |
Token * | first () const |
Get the first token in the unit. | |
Token * | last () const |
Get the last token in the unit. | |
Token * | next (const Token *token) const |
Get the next token of the given token. | |
Token * | prev (const Token *token) const |
Get the previous token of the given token. | |
Public Member Functions inherited from Puma::List | |
List () | |
Constructor. | |
List (const List ©) | |
Copy-constructor. | |
~List () | |
Destructor. | |
List & | operator= (const List ©) |
Assignment operator. | |
List & | operator+= (const List &list) |
Append the given list. | |
List | operator+ (const List &list) |
Create a new list containing the elements of this list followed by the elements of the given list. | |
void | clear () |
Destroy the list elements. | |
void | append (ListElement &element) |
Append an element to the list. | |
void | prepend (ListElement &element) |
Prepend an element to the list. | |
void | insert (ListElement *at, ListElement &element) |
Insert an element at the given list position. | |
void | remove (ListElement *element) |
Remove the given element from the list. | |
void | kill (ListElement *from, ListElement *to=(ListElement *) 0) |
Remove and destroy all elements between the given list elements. | |
void | cut (List &out, ListElement *from, ListElement *to=(ListElement *) 0) |
Cut all elements between the given list elements. | |
List * | copy (ListElement *from=(ListElement *) 0, ListElement *to=(ListElement *) 0) |
Copy all elements between the given list elements. | |
void | paste (ListElement *at, const List &l) |
Insert copies of the elements of the given list at the given list position. | |
void | paste_before (ListElement *at, const List &l) |
Insert copies of the elements of the given list before the given list position. | |
void | move (ListElement *at, List &l) |
Insert the elements of the given list at the given list position. | |
void | move_before (ListElement *at, List &l) |
Insert the elements of the given list before the given list position. | |
bool | empty () const |
Check if the list is empty. | |
const ListElement * | first () const |
Get the first element in the list. | |
const ListElement * | last () const |
Get the last element in the list. | |
const ListElement * | next (const ListElement *element) const |
Get the next element of the given element. | |
const ListElement * | prev (const ListElement *element) const |
Get the previous element of the given element. | |
Public Member Functions inherited from Puma::Printable | |
virtual | ~Printable () |
Destructor. | |
|
inline |
Constructor.
|
inline |
Copy-constructor.
list | The token chain to copy. |
|
virtual |
Destructor.
Destroys the tokens.
|
inline |
Get the first token in the unit.
|
inlinevirtual |
Check if this is a unit for a file.
Reimplemented in Puma::FileUnit.
|
inlinevirtual |
Check if this is a unit for a macro expansion.
Reimplemented in Puma::MacroUnit.
|
inlinevirtual |
Check if this is a unit for a template instance.
|
inline |
Get the last token in the unit.
|
inline |
Get the name of the unit (usually the file name).
|
virtual |
Set the name of the unit (usually the file name).
name | The name. |
Reimplemented in Puma::FileUnit.
Get the next token of the given token.
Get the previous token of the given token.
|
virtual |
Print the tokens of the unit on the given stream.
os | The output stream. |
Implements Puma::Printable.
|
inline |
Get the state of the unit.
char * Puma::Unit::toString | ( | ) | const |
Serialize the tokens of the unit.