Puma Reference Manual Puma: Puma::Unit Class Reference



Puma::Unit Class Reference

#include <Puma/Unit.h>

Inheritance diagram for Puma::Unit:

Inheritance graph

List of all members.


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

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.
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.

Constructor & Destructor Documentation

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

Constructor.

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

Copy-constructor.

Parameters:
list The token chain to copy.

virtual Puma::Unit::~Unit (  )  [virtual]

Destructor.

Destroys the tokens.


Member Function Documentation

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

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

Parameters:
name The name.

Reimplemented in Puma::FileUnit.

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

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

virtual void Puma::Unit::print ( ostream &  os  )  const [virtual]

Print the tokens of the unit on the given stream.

Parameters:
os The output stream.

Implements Puma::Printable.

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.

UnitState& Puma::Unit::state (  )  [inline]

Get the state of the unit.

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.

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.

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.




Puma Reference Manual. Created on 11 Jul 2008.