Puma Reference Manual Puma: Puma::Semantic Class Reference



Puma::Semantic Class Reference

Semantic analysis base class. More...

#include <Puma/Semantic.h>

Inherits PtrStack< CObjectInfo >.

Inherited by Puma::CSemantic.

List of all members.

Public Member Functions

virtual void init (CSemDatabase &db, Unit &file)
 Initialize the semantic analysis.
virtual void configure (Config &c)
 Configure the semantic analysis.
void error_sink (ErrorSink &e)
 Set the error output stream object.
void undo (CTree *tree)
 Undo the declaration analysis of the given syntax tree node.
CTreePrivateName ()
 Create a new anonymous (private) name.
void save_state ()
 Save the current semantic analysis state.
void forget_state ()
 Discard the saved semantic analysis state.
void restore_state ()
 Restore the saved semantic analysis state.
CFileInfogetFile ()
 Get the root node of the semantic tree.
void enter_local_scope ()
 Enter a local scope.
void leave_scopes ()
 Leave all scopes entered up to the current scope.
virtual void enter_param_decl_clause ()
 Enter a function parameter declaration clause.
virtual void leave_param_decl_clause ()
 Leave a function parameter declaration clause.
bool in_param_decl_clause ()
 Check if in the declaration of a function parameter clause.
void finish_decl ()
 Finish the analysis of the current declaration.
void finish_declarator ()
 Finish the analysis of the current declarator.

Protected Member Functions

 Semantic ()
 Constructor.
virtual ~Semantic ()
 Destructor.
void common_settings (CObjectInfo *info, CTree *tree)
 Apply command settings on the given semantic object.
void common_settings (CObjectInfo *info, CTree *tree, CSemDeclarator *d)
 Apply command settings on the given semantic object.
virtual void Delete ()
 Delete the top item on the semantic stack.
void Push (CObjectInfo *info)
 Push the given semantic information object on the semantic stack.
bool in_decl () const
 Check if currently analysing a declaration.
void decl_begin (CSemDeclSpecs *ds)
 Begin analysing a declaration.
void decl_end ()
 Finish analysing a declaration.
void decl_specs_begin (CT_DeclSpecSeq *dss)
 Begin analysing a declaration specifier sequence.
void decl_specs_end ()
 Finish analysing a declaration specifier sequence.
CSemDeclSpecssem_decl_specs () const
 Get the semantic information for the currently analysed declaration specifier sequence.
CT_DeclSpecSeqdecl_specs () const
 Get the currently analysed declaration specifier sequence.
virtual void enter_scope (CStructure *scope)
 Enter the given scope.
virtual void reenter_scope (CStructure *scope)
 Reenter the given scope.

Protected Attributes

CSemDatabase_db
 Database of all semantic objects of the semantic tree.
CFileInfo_file
 Top level semantic object representing the file scope.
ErrorSink_err
 Error output stream.
long _Anonymous
 Counter for generating anonymous (private) names.
CEnumInfocurrent_enum
 The current enumeration, if inside the definition of an enumeration.
CStructurecurrent_fct
 The current function, if inside the definition of a function.
CStructurecurrent_scope
 The current scope.
BCStack< CSemDeclSpecs *, 256 > _sem_decl_specs
 Stack for the type analysis of declarations.
BCStack< CT_DeclSpecSeq *, 256 > _decl_specs
 Stack for collecting declaration specifiers.
BCStack< bool, 256 > _in_param_decl_clause
 Stack for the state of analysing a function parameter list.
BCStack< bool, 256 > _in_decl
 Stack for the state of analysing a declaration.

Detailed Description

Semantic analysis base class.

Implements the basic semantic analysis tasks. To be derived to implement language specific semantic analyses.

There are two kinds of semantic analyses in Puma. The first is the semantic analysis performed in parallel with the syntactic analysis (see Syntax) of the source code to differentiate ambigous syntactic constructs, resolve names, and so on. The other is an additional semantic analysis of the syntax tree (mainly of expressions) based on a tree visitor (see CVisitor) to resolve function calls, calculate the value of constant expressions, resolve the type of an expression, and so on. This class performs the first kind of semantic analysis.

The semantic object is organized as a multi-level stack. If a grammar rule is parsed then a new stack level is created. The semantic objects created while parsing the rule are pushed on this level of the stack. When parsing the grammar rule is finished, then the current stack level is discarded. If the grammar rule could not be parsed successfully then the semantic objects pushed on the stack are destroyed before the current stack level is discarded.


Constructor & Destructor Documentation

Puma::Semantic::Semantic (  )  [inline, protected]

Constructor.

virtual Puma::Semantic::~Semantic (  )  [protected, virtual]

Destructor.


Member Function Documentation

void Puma::Semantic::common_settings ( CObjectInfo info,
CTree tree,
CSemDeclarator d 
) [protected]

Apply command settings on the given semantic object.

That is setting the semantic database, the source file, the start token of the analysed syntactic construct, the syntax tree node, the type, and the name.

Parameters:
info The semantic information object.
tree The analysed syntax tree.
d Declarator information object.
void Puma::Semantic::common_settings ( CObjectInfo info,
CTree tree 
) [protected]

Apply command settings on the given semantic object.

That is setting the semantic database, the source file, the start token of the analysed syntactic construct, and the syntax tree node.

Parameters:
info The semantic information object.
tree The analysed syntax tree.
virtual void Puma::Semantic::configure ( Config c  )  [inline, virtual]

Configure the semantic analysis.

Parameters:
c The configuration settings.

Reimplemented in Puma::CSemantic.

void Puma::Semantic::decl_begin ( CSemDeclSpecs ds  )  [protected]

Begin analysing a declaration.

Parameters:
ds The declaration specifiers.
void Puma::Semantic::decl_end (  )  [protected]

Finish analysing a declaration.

CT_DeclSpecSeq * Puma::Semantic::decl_specs (  )  const [inline, protected]

Get the currently analysed declaration specifier sequence.

void Puma::Semantic::decl_specs_begin ( CT_DeclSpecSeq dss  )  [inline, protected]

Begin analysing a declaration specifier sequence.

Parameters:
dss Empty object for the declaration specifiers.
void Puma::Semantic::decl_specs_end (  )  [inline, protected]

Finish analysing a declaration specifier sequence.

virtual void Puma::Semantic::Delete (  )  [protected, virtual]

Delete the top item on the semantic stack.

To be implemented by derived classes.

Reimplemented from Puma::PtrStack< CObjectInfo >.

Reimplemented in Puma::CCSemantic, and Puma::CSemantic.

void Puma::Semantic::enter_local_scope (  ) 

Enter a local scope.

Creates a new CLocalScope and pushes it on the scope stack.

virtual void Puma::Semantic::enter_param_decl_clause (  )  [virtual]

Enter a function parameter declaration clause.

Reimplemented in Puma::CCSemantic.

virtual void Puma::Semantic::enter_scope ( CStructure scope  )  [protected, virtual]

Enter the given scope.

Sets the parent of the entered scope to the current scope.

Parameters:
scope The scope to enter.

Reimplemented in Puma::CCSemantic.

void Puma::Semantic::error_sink ( ErrorSink e  )  [inline]

Set the error output stream object.

Parameters:
e The error output stream.
void Puma::Semantic::finish_decl (  )  [inline]

Finish the analysis of the current declaration.

void Puma::Semantic::finish_declarator (  ) 

Finish the analysis of the current declarator.

void Puma::Semantic::forget_state (  )  [inline]

Discard the saved semantic analysis state.

CFileInfo * Puma::Semantic::getFile (  )  [inline]

Get the root node of the semantic tree.

bool Puma::Semantic::in_decl (  )  const [inline, protected]

Check if currently analysing a declaration.

bool Puma::Semantic::in_param_decl_clause (  ) 

Check if in the declaration of a function parameter clause.

virtual void Puma::Semantic::init ( CSemDatabase db,
Unit file 
) [virtual]

Initialize the semantic analysis.

Parameters:
db The semantic object database.
file The input file.

Reimplemented in Puma::CCSemantic, and Puma::CSemantic.

virtual void Puma::Semantic::leave_param_decl_clause (  )  [virtual]

Leave a function parameter declaration clause.

Reimplemented in Puma::CCSemantic.

void Puma::Semantic::leave_scopes (  ) 

Leave all scopes entered up to the current scope.

Make the parent scope of the current scope to the current scope.

CTree* Puma::Semantic::PrivateName (  ) 

Create a new anonymous (private) name.

Returns:
A newly allocated node of type CT_PrivateName. Has to be destroyed by the caller.
void Puma::Semantic::Push ( CObjectInfo info  )  [protected]

Push the given semantic information object on the semantic stack.

Parameters:
info The semantic object.
virtual void Puma::Semantic::reenter_scope ( CStructure scope  )  [protected, virtual]

Reenter the given scope.

Does not reset the parent of entered scope.

Parameters:
scope The scope to reenter.
void Puma::Semantic::restore_state (  )  [inline]

Restore the saved semantic analysis state.

void Puma::Semantic::save_state (  )  [inline]

Save the current semantic analysis state.

CSemDeclSpecs * Puma::Semantic::sem_decl_specs (  )  const [inline, protected]

Get the semantic information for the currently analysed declaration specifier sequence.

void Puma::Semantic::undo ( CTree tree  ) 

Undo the declaration analysis of the given syntax tree node.

Parameters:
tree The syntax tree node.

Member Data Documentation

long Puma::Semantic::_Anonymous [protected]

Counter for generating anonymous (private) names.

Database of all semantic objects of the semantic tree.

Stack for collecting declaration specifiers.

Error output stream.

Top level semantic object representing the file scope.

BCStack<bool, 256> Puma::Semantic::_in_decl [protected]

Stack for the state of analysing a declaration.

Stack for the state of analysing a function parameter list.

Stack for the type analysis of declarations.

The current enumeration, if inside the definition of an enumeration.

The current function, if inside the definition of a function.

The current scope.




Puma Reference Manual. Created on 11 Sep 2009.