Puma Reference Manual | Puma: Puma::Unit Class Reference |
Token chain abstraction of a source file or string. More...
#include <Puma/Unit.h>
Inherits Puma::List, and Puma::Printable.
Inherited by Puma::CUnit, Puma::FileUnit, and Puma::MacroUnit.
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 (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. | |
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. |
Token chain abstraction of a source file or string.
A token 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 or not. 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.
...
std::ofstream file("code.cc");
file << unit;
file.close();
Puma::Unit::Unit | ( | ) | [inline] |
Constructor.
Puma::Unit::Unit | ( | const List & | list | ) | [inline] |
Copy-constructor.
list | The token chain to copy. |
virtual Puma::Unit::~Unit | ( | ) | [virtual] |
Destructor.
Destroys the tokens.
Token* Puma::Unit::first | ( | ) | const [inline] |
Get the first token in the unit.
Reimplemented from Puma::List.
virtual bool Puma::Unit::isFile | ( | ) | const [inline, virtual] |
Check if this is a unit for a file.
Reimplemented in Puma::FileUnit.
virtual bool Puma::Unit::isMacroExp | ( | ) | const [inline, virtual] |
Check if this is a unit for a macro expansion.
Reimplemented in Puma::MacroUnit.
virtual bool Puma::Unit::isTemplateInstance | ( | ) | const [inline, virtual] |
Check if this is a unit for a template instance.
Reimplemented in Puma::TemplateInstanceUnit.
Token* Puma::Unit::last | ( | ) | const [inline] |
Get the last token in the unit.
Reimplemented from Puma::List.
char* Puma::Unit::name | ( | ) | const [inline] |
Get the name of the unit (usually the file name).
virtual void Puma::Unit::name | ( | const char * | 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 void Puma::Unit::print | ( | ostream & | os | ) | const [virtual] |
Print the tokens of the unit on the given stream.
os | The output stream. |
Implements Puma::Printable.
UnitState& Puma::Unit::state | ( | ) | [inline] |
Get the state of the unit.