Puma Reference Manual Puma::Unit Class Reference



Puma::Unit Class Reference

Token chain abstraction of a source file or string. More...

#include <Puma/Unit.h>

Inheritance diagram for Puma::Unit:
Inheritance graph

List of all members.

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.
UnitStatestate ()
 Get the state of the unit.
Tokenfirst () const
 Get the first token in the unit.
Tokenlast () const
 Get the last token in the unit.
Tokennext (const Token *token) const
 Get the next token of the given token.
Tokenprev (const Token *token) const
 Get the previous token of the given token.

Detailed Description

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();

Constructor & Destructor Documentation

Puma::Unit::Unit ( ) [inline]

Constructor.

Puma::Unit::Unit ( const List list) [inline]

Copy-constructor.

Parameters:
listThe token chain to copy.
virtual Puma::Unit::~Unit ( ) [virtual]

Destructor.

Destroys the tokens.


Member Function Documentation

Token* Puma::Unit::first ( ) const [inline]

Get the first token in the unit.

Returns:
The token or NULL if unit is empty.

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.

Token* Puma::Unit::last ( ) const [inline]

Get the last token in the unit.

Returns:
The token or NULL if unit is empty.

Reimplemented from Puma::List.

virtual void Puma::Unit::name ( const char *  name) [virtual]

Set the name of the unit (usually the file name).

Parameters:
nameThe name.

Reimplemented in Puma::FileUnit.

char* Puma::Unit::name ( ) const [inline]

Get the name of the unit (usually the file name).

Token* Puma::Unit::next ( const Token token) const [inline]

Get the next token of the given token.

Returns:
The token or NULL if the given token is NULL.
Token* Puma::Unit::prev ( const Token token) const [inline]

Get the previous token of the given token.

Returns:
The token or NULL if the given token is NULL.
virtual void Puma::Unit::print ( ostream &  os) const [virtual]

Print the tokens of the unit on the given stream.

Parameters:
osThe output stream.

Implements Puma::Printable.

Get the state of the unit.