Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

IopcTranslator Class Reference

Main class of IOPC SP. Called by OpenC++ framework to translate individual pieces of parsed source tree. More...

#include <iopcTranslator.h>

Inheritance diagram for IopcTranslator:

Inheritance graph
[legend]
Collaboration diagram for IopcTranslator:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual void TranslateClass (Environment *env)
virtual void TranslateMemberFunction (Environment *env, Member &member)
virtual PtreeTranslateMemberRead (Environment *env, Ptree *object, Ptree *access_op, Ptree *member)
virtual PtreeTranslateMemberRead (Environment *env, Ptree *member)
virtual PtreeTranslateMemberWrite (Environment *env, Ptree *object, Ptree *access_op, Ptree *member, Ptree *assign_op, Ptree *expr)
virtual PtreeTranslateMemberWrite (Environment *env, Ptree *member, Ptree *assign_op, Ptree *expr)
virtual PtreeTranslatePostfixOnMember (Environment *env, Ptree *object, Ptree *access_op, Ptree *member, Ptree *postfix_op)
virtual PtreeTranslatePostfixOnMember (Environment *env, Ptree *member, Ptree *postfix_op)
virtual PtreeTranslateUnaryOnMember (Environment *env, Ptree *unary_op, Ptree *object, Ptree *access_op, Ptree *member)
virtual PtreeTranslateUnaryOnMember (Environment *env, Ptree *unary_op, Ptree *member)

Protected Member Functions

PtreeTranslateMemberReadImpl (Environment *env, Ptree *member, Ptree *object=NULL, Ptree *accessOp=NULL)
PtreeTranslateMemberWriteImpl (Environment *env, Ptree *member, Ptree *assignOp, Ptree *expr, Ptree *object=NULL, Ptree *accessOp=NULL)
PtreeTranslatePostfixOnMemberImpl (Environment *env, Ptree *member, Ptree *postfixOp, Ptree *object=NULL, Ptree *accessOp=NULL)
PtreeTranslateUnaryOnMemberImpl (Environment *env, Ptree *member, Ptree *unaryOp, Ptree *object=NULL, Ptree *accessOp=NULL)
void PrintTranslationError (Environment *env, Ptree *where, const char *format,...)
CStdString GetQualifiedClassName (Environment *env)
int TestPersistence (Ptree *member, char *&className, char *&attrName, char *&namespaceOrClassSpecification)

Static Protected Member Functions

CStdString GetFileAndLineNumber (Ptree *tree, Environment *env)

Protected Attributes

bool isInDestructor

Static Protected Attributes

GeneralClassMap allClassesMap
IopcTranslatingSupport translatingSupport

Detailed Description

Main class of IOPC SP. Called by OpenC++ framework to translate individual pieces of parsed source tree.

The first goal of this class is to gather information about source file object model (classes, attributes, inheritance) and then store them as mapping metadata (using MetadataWriter). The second goal is to add methods needed to make a class persistent to all the ancestors of IopcPersistentObject. The implementation of these methods is created by calls to IopcTranslatingSupport (translatingSupport).

If TranslateMemberRead(), TranslateMemberWrite(), TranslatePostfixOnMember() or TranslateUnaryOnMember() is called for some code from a class destructor, the attributes in translated code are accessed directly, not using getters and setters. The reason is that we don't want to load attributes (strings) from the database in destructor. Without this "exception" typical string destruction code "if (str != NULL) delete str;" would cause loading str from DB.

Note:
IopcTranslator isn't singleton. Open C++ creates an instance of the class for each class in the translated source. So all IopcTranslator's data members have to be static.


Member Function Documentation

void IopcTranslator::TranslateClass Environment env  )  [virtual]
 

Translates declaration of whole class.

Note:
Functions TranslateMemberRead() etc. are called also on statements in methods inlined in class declaration. So, there's no need to translate these reads / writes in TranslateClass().
Parameters:
env OpenC++'s environment to which this translated class belongs.

Reimplemented from Class.

void IopcTranslator::TranslateMemberFunction Environment env,
Member member
[virtual]
 

Translates declaration of a member function.

This function is called both for functions declared inline in class declaration and for functions declared out of the class declaration.

Parameters:
env OpenC++'s environment to which the translated function belongs.
member Representation of the member function - piece of program code tree.

Reimplemented from Class.

Ptree * IopcTranslator::TranslateMemberRead Environment env,
Ptree object,
Ptree access_op,
Ptree member
[virtual]
 

Translates read access to an attribute. Called if the attribute is accessed using object name - i.e. something like "object.attr" or "object->attr".

Implemented as a call to TranslateMemberReadImpl().

Parameters:
env OpenC++'s environment to which appropriate piece of code belongs.
object The object that is accessed.
access_op The access operator ("." or "->").
member The attribute that is accessed.
Returns:
Traslated piece of parsed source code tree.

Reimplemented from Class.

Ptree * IopcTranslator::TranslateMemberRead Environment env,
Ptree member
[virtual]
 

Translates read access to an attribute. Called if the attribute is accessed using attribute name separately - i.e. something like "attr" (not "object.attr" or "object->attr").

Implemented as a call to TranslateMemberReadImpl().

Parameters:
env OpenC++'s environment to which appropriate piece of code belongs.
member The attribute that is accessed.
Returns:
Traslated piece of parsed source code tree.

Reimplemented from Class.

Ptree * IopcTranslator::TranslateMemberWrite Environment env,
Ptree object,
Ptree access_op,
Ptree member,
Ptree assign_op,
Ptree expr
[virtual]
 

Translates write access to an attribute. Called if the attribute is accessed using object name - i.e. something like "object.attr" or "object->attr".

Implemented as a call to TranslateMemberWriteImpl().

Parameters:
env OpenC++'s environment to which appropriate piece of code belongs.
object The object that is accessed.
access_op The access operator ("." or "->").
member The attribute that is accessed.
assign_op The assign operator ("=" or "+=" etc.).
expr Parsed expression that is assigned to the attribute.
Returns:
Traslated piece of parsed source code tree.

Reimplemented from Class.

Ptree * IopcTranslator::TranslateMemberWrite Environment env,
Ptree member,
Ptree assign_op,
Ptree expr
[virtual]
 

Translates write access to an attribute. Called if the attribute is accessed using attribute name separately - i.e. something like "attr" (not "object.attr" or "object->attr").

Implemented as a call to TranslateMemberWriteImpl().

Parameters:
env OpenC++'s environment to which appropriate piece of code belongs.
member The attribute that is accessed.
assign_op The assign operator ("=" or "+=" etc.).
expr Parsed expression that is assigned to the attribute.
Returns:
Traslated piece of parsed source code tree.

Reimplemented from Class.

Ptree * IopcTranslator::TranslatePostfixOnMember Environment env,
Ptree object,
Ptree access_op,
Ptree member,
Ptree postfix_op
[virtual]
 

Translates a postfix operator applied to some attribute. Called if the attribute is accessed using object name - i.e. something like "object.attr" or "object->attr".

Implemented as a call to TranslatePostfixOnMemberImpl().

Parameters:
env OpenC++'s environment to which appropriate piece of code belongs.
object The object that is accessed.
access_op The access operator ("." or "->").
member The attribute that is accessed.
postfix_op The postfix operator ("++" or "--").
Returns:
Traslated piece of parsed source code tree.

Reimplemented from Class.

Ptree * IopcTranslator::TranslatePostfixOnMember Environment env,
Ptree member,
Ptree postfix_op
[virtual]
 

Translates a postfix operator applied to some attribute. Called if the attribute is accessed using attribute name separately - i.e. something like "attr" (not "object.attr" or "object->attr").

Implemented as a call to TranslatePostfixOnMemberImpl().

Parameters:
env OpenC++'s environment to which appropriate piece of code belongs.
member The attribute that is accessed.
postfix_op The postfix operator ("++" or "--").
Returns:
Traslated piece of parsed source code tree.

Reimplemented from Class.

Ptree * IopcTranslator::TranslateUnaryOnMember Environment env,
Ptree unary_op,
Ptree object,
Ptree access_op,
Ptree member
[virtual]
 

Translates a prefix unary operator applied to some attribute. Called if the attribute is accessed using object name - i.e. something like "object.attr" or "object->attr".

Implemented as a call to TranslateUnaryOnMemberImpl().

Parameters:
env OpenC++'s environment to which appropriate piece of code belongs.
unary_op The unary operator ("++", "!", "*" etc.).
object The object that is accessed.
access_op The access operator ("." or "->").
member The attribute that is accessed.
Returns:
Traslated piece of parsed source code tree.

Reimplemented from Class.

Ptree * IopcTranslator::TranslateUnaryOnMember Environment env,
Ptree unary_op,
Ptree member
[virtual]
 

Translates a prefix unary operator applied to some attribute. Called if the attribute is accessed using attribute name separately - i.e. something like "attr" (not "object.attr" or "object->attr").

Implemented as a call to TranslateUnaryOnMemberImpl().

Parameters:
env OpenC++'s environment to which appropriate piece of code belongs.
unary_op The unary operator ("++", "!", "*" etc.).
member The attribute that is accessed.
Returns:
Traslated piece of parsed source code tree.

Reimplemented from Class.

Ptree * IopcTranslator::TranslateMemberReadImpl Environment env,
Ptree member,
Ptree object = NULL,
Ptree accessOp = NULL
[protected]
 

Translates read access to an attribute.

  • If the read access is not in destructor, creates source code tree that calls getter for appropriate attribute - i.e. something like "object.get_attr()".

  • If the translated piece of code is in destructor, the function returns something like "object.m_attr".

Uses TestPersistence() and IopcTranslatingSupport::createGetterCall().

Parameters:
env OpenC++'s environment to which appropriate piece of code belongs.
member The attribute that is accessed.
object The object that is accessed. NULL if called from TranslateMemberRead(Environment*, Ptree*).
accessOp The access operator ("." or "->"). NULL if called from TranslateMemberRead(Environment*, Ptree*).
Returns:
Traslated piece of parsed source code tree.
See also:
isInDestructor, VARIABLE_NAME, GETTER_PREFIX

Ptree * IopcTranslator::TranslateMemberWriteImpl Environment env,
Ptree member,
Ptree assignOp,
Ptree expr,
Ptree object = NULL,
Ptree accessOp = NULL
[protected]
 

Translates write access to an attribute.

  • If the assignment is not in destructor, creates source code tree that calls setter for appropriate attribute - i.e. something like "object.set_attr(translated_expr)". If assignOp is not "=", it is necessary to call getter too - the returned code for "object.attr += expr" will be something like "object->set_attr(object->get_attr() + (translated_expr))".

  • If the assignment is in destructor, the function returns something like "object.m_attr = translated_expr".

Uses TestPersistence(), IopcTranslatingSupport::createGetterCall() and IopcTranslatingSupport::createSetterCall().

Parameters:
env OpenC++'s environment to which appropriate piece of code belongs.
assignOp The assign operator ("=" or "+=" etc.).
expr Parsed expression that is assigned to the attribute.
member The attribute that is accessed.
object The object that is accessed. NULL if called from TranslateMemberWrite(Environment*, Ptree*, Ptree*, Ptree*).
accessOp The access operator ("." or "->"). NULL if called from TranslateMemberWrite(Environment*, Ptree*, Ptree*, Ptree*).
Returns:
Traslated piece of parsed source code tree.
See also:
isInDestructor, VARIABLE_NAME, GETTER_PREFIX, SETTER_PREFIX

Ptree * IopcTranslator::TranslatePostfixOnMemberImpl Environment env,
Ptree member,
Ptree postfixOp,
Ptree object = NULL,
Ptree accessOp = NULL
[protected]
 

Translates a postfix operator applied to some attribute.

  • If the piece of code is not in destructor, creates source code tree that calls both getter and setter to emulate the postfix operator. For "object.attr ++" returns "(object.set_attr(object.get_attr() + 1) - 1)".

  • If the piece of code is in destructor, the function returns something like "object.m_attr++".

Uses TestPersistence(), IopcTranslatingSupport::createGetterCall() and IopcTranslatingSupport::createSetterCall().

Parameters:
env OpenC++'s environment to which appropriate piece of code belongs.
member The attribute that is accessed.
postfixOp The postfix operator ("++" or "--").
object The object that is accessed. NULL if called from TranslatePostfixOnMember(Environment*, Ptree*, Ptree*).
accessOp The access operator ("." or "->"). NULL if called from TranslatePostfixOnMember(Environment*, Ptree*, Ptree*).
Returns:
Traslated piece of parsed source code tree.
See also:
isInDestructor, VARIABLE_NAME, GETTER_PREFIX, SETTER_PREFIX

Ptree * IopcTranslator::TranslateUnaryOnMemberImpl Environment env,
Ptree member,
Ptree unaryOp,
Ptree object = NULL,
Ptree accessOp = NULL
[protected]
 

Translates a prefix unary operator applied to some attribute.

  • Use of operator "&" on persistent attributes is not permitted - functions prints an error message and calls exitProgram().

  • Operator "*" on dereferencable attributes is translated in the same way as "+", "-", "!" and "~" (see below), on other attributes prints an error message and calls exitProgram().

  • If the piece of code is not in destructor:
    • translations of operators "++" and "--" use both getter and setter to emulate the prefix operator. For "++ object.attr" returns "object.set_attr(object.get_attr() + 1)".
    • translations of operators "+", "-", "!" and "~" calls getter and apply the operator to getter result. For "!object.attr" returns "!object.get_attr()".

  • If the piece of code is in destructor, the function returns something like "++object.m_attr" or "!object.m_attr"

Parameters:
env OpenC++'s environment to which appropriate piece of code belongs.
unaryOp The unary operator ("++", "!", "*" etc.).
object The object that is accessed.
accessOp The access operator ("." or "->"). NULL if called from TranslateUnaryOnMember(Environment*, Ptree*, Ptree*).
member The attribute that is accessed. NULL if called from TranslateUnaryOnMember(Environment*, Ptree*, Ptree*).
Returns:
Traslated piece of parsed source code tree.

void IopcTranslator::PrintTranslationError Environment env,
Ptree where,
const char *  format,
... 
[protected]
 

Called to print an error message if some error occures during translation.

Formats message given by format and following parameters (as printf() does) and calls OpenC++'s ErrorMessage().

Parameters:
env OpenC++'s environment where the error occured.
where Source code subtree where the error occured.
format printf()-style format specification.

CStdString IopcTranslator::GetFileAndLineNumber Ptree tree,
Environment env
[static, protected]
 

Gets file name and line number as string - returns something like "/mydir/myfile.cpp (253)".

Parameters:
tree Source tree of code, whose position should be retrieved.
env OpenC++'s environment into which tree belongs.

CStdString IopcTranslator::GetQualifiedClassName Environment env  )  [protected]
 

Gets qualified name of class, whose code / member is currently translated.

To be used on nested classes and in namespaces. Walks through the hierarchy of Environment-s starting from env.

Parameters:
env OpenC++'s environment that contains the class.

int IopcTranslator::TestPersistence Ptree member,
char *&  className,
char *&  attrName,
char *&  namespaceOrClassSpecification
[protected]
 

Tests whether member is persistent attribute of current class (its name is Name()).

If so, returns name of the class (className) and name of the attribute (attrName). If member uses some parent class or namespace specification (i.e. something like parentClass::attr), function returns attrName's prefix in namespaceOrClassSpecification.

It is not necessary to dealocate returned string because IOPC SP / OpenC++ uses garbage collector.

Returns:
0 if the member persistent, 1 otherwise.


Member Data Documentation

GeneralClassMap IopcTranslator::allClassesMap [static, protected]
 

Map containing all classes already seen in the file - its purpose is described GeneralClassMap's documentation.

IopcTranslatingSupport IopcTranslator::translatingSupport [static, protected]
 

Pointer to class that is able to generate implementations of methods that are needed to make a class persistent.

bool IopcTranslator::isInDestructor [protected]
 

Is IOPC SP currently translating a destructor? Set and reset in TranslateMemberFunction().

In a persistent class's destructor accesses to persistent attributes are not translated to access methods calls - we don't want to uselessly load long strings from the database in destructor. Instead of it the accesses are translated to direct accesses to attribute (of the modified name).


The documentation for this class was generated from the following files:
Generated on Wed Aug 11 22:35:41 2004 for IOPC by Doxygen 1.3.6