Zen
A cross-platform functional programming language

Unit Class Reference

AST Node for a compilation unit. More...

#include <Ast.hpp>

Inheritance diagram for Unit:
RootTypeSpec TypeSpec Node

List of all members.

Public Types

typedef z::list< const
Ast::ImportStatement * > 
ImportList
 List of import statements in this unit.
typedef z::list< const
Ast::ImplItem * > 
ImplList
 List of all implementation items in this unit.

Public Member Functions

 Unit (const AccessType::T &accessType)
 Default constructor.
void setProjectDef (const Ast::StructInitExpr &expr)
 Set the project definition, if this is a project unit This is used only if unit represents project file.
const Ast::StructInitExprgetProjectDef ()
 Return the project defjinition, if this is a project unit.
void setMainContinuation (const Ast::ContinuationImplItem &continuation)
 Set the main continuation, if this compilation has a main() function.
bool hasMainContinuation () const
 Check if this compilation has a main() function.
const Ast::ContinuationImplItemgetMainContinuation () const
 Return the main continuation.
void setFilename (const z::string &filename)
 Set the filename for this compilation unit.
const z::stringgetFilename () const
 Return the filename for this compilation unit.
Ast::ImportStatementaddImport (Ast::ImportStatement &stmt)
 Add an import statement to the unit.
void addUnitNS (const z::string &name)
 Add a namespace to the unit.
void addItem (const ImplItem &item)
 Add an implementation item to the unit.
template<typename T >
T & addNode (T *node)
 Add an AST node to the unit.
NamespacegetRootNS ()
 Return a reference to the root namespace for this compilation unit.
const NamespacegetRootNS () const
 Return a const reference to the root namespace for this compilation unit.
NamespacegetImportNS ()
 Return a reference to the import namespace for this compilation unit.
const NamespacegetImportNS () const
 Return a const reference to the import namespace for this compilation unit.
const z::stringlistgetUnitNS () const
 Return the name of namespace for this compilation unit.
const ImportListgetImportList () const
 Return the list of imports for this compilation unit.
const ImplListgetImplList () const
 Return the list of implementations for this compilation unit.

Private Types

typedef z::sharedptr< NodePtr
 Shared NodePtr.

Private Member Functions

virtual void visit (TypeSpec::Visitor &visitor) const
 Abstract visitor function.

Private Attributes

z::string _filename
 The filename.
ImportList _importList
 The list of imports in this unit.
Ast::Namespace _importNS
 This NS contains all imported typespec's. It is not used for source file generation, only for reference.
Namespace _rootNS
 This NS contains all types defined in the current compilation unit.
z::stringlist _unitNS
 The NS for the current compilation unit.
ImplList _implList
 List of all ImplItem nodes in this unit.
z::list< Ptr_nodeList
 The owner list of all nodes in this unit.
const Ast::ContinuationImplItem_mainContinuation
 This is non-zero if this compilation has a main function.
const Ast::StructInitExpr_projectDef
 This is non-zero if this is AST for a project file.

Detailed Description

AST Node for a compilation unit.

The Unit AST node is the owner for all AST nodes in the unit. This node maintains two namespace hierarchies

  • the root namespace is the namespace for all types defined in this unit
  • the import namespace is the namespace for all types imported into the unit from other modules.

Constructor & Destructor Documentation

Unit ( const AccessType::T accessType) [inline]

Default constructor.

Parameters:
accessTypeSpecifies the AccessType for this type, for example, whether it is a public or a private type.

Member Function Documentation

Ast::ImportStatement& addImport ( Ast::ImportStatement stmt) [inline]

Add an import statement to the unit.

Parameters:
stmtThe import statement to add.
Returns:
A reference to the import statement just added.
void addItem ( const ImplItem item) [inline]

Add an implementation item to the unit.

Parameters:
itemThe item to add
T& addNode ( T *  node) [inline]

Add an AST node to the unit.

Parameters:
nodeA pointer to the node to add
Returns:
A reference to the newly added node
void addUnitNS ( const z::string name) [inline]

Add a namespace to the unit.

Parameters:
nameThe namespace to add
const z::string& getFilename ( ) const [inline]

Return the filename for this compilation unit.

Returns:
The filename
const ImplList& getImplList ( ) const [inline]

Return the list of implementations for this compilation unit.

Returns:
The implementation list
const ImportList& getImportList ( ) const [inline]

Return the list of imports for this compilation unit.

Returns:
The import list
Namespace& getImportNS ( ) [inline]

Return a reference to the import namespace for this compilation unit.

Returns:
The import namespace
const Namespace& getImportNS ( ) const [inline]

Return a const reference to the import namespace for this compilation unit.

Returns:
The import namespace
const Ast::ContinuationImplItem& getMainContinuation ( ) const [inline]

Return the main continuation.

Returns:
The main continuation
const Ast::StructInitExpr& getProjectDef ( ) [inline]

Return the project defjinition, if this is a project unit.

Returns:
The project definition
Namespace& getRootNS ( ) [inline]

Return a reference to the root namespace for this compilation unit.

Returns:
The root namespace
const Namespace& getRootNS ( ) const [inline]

Return a const reference to the root namespace for this compilation unit.

Returns:
The root namespace
const z::stringlist& getUnitNS ( ) const [inline]

Return the name of namespace for this compilation unit.

Returns:
The unit namespace
bool hasMainContinuation ( ) const [inline]

Check if this compilation has a main() function.

Returns:
True, if unit has a main continuation
void setFilename ( const z::string filename) [inline]

Set the filename for this compilation unit.

Parameters:
filenameThe filename
void setMainContinuation ( const Ast::ContinuationImplItem continuation) [inline]

Set the main continuation, if this compilation has a main() function.

Parameters:
continuationThe main continuation
void setProjectDef ( const Ast::StructInitExpr expr) [inline]

Set the project definition, if this is a project unit This is used only if unit represents project file.

Parameters:
exprThe project definition
void visit ( TypeSpec::Visitor visitor) const [private, virtual]

Abstract visitor function.

Parameters:
visitorThe visitor object.

Implements TypeSpec.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines