|
From: <bl...@us...> - 2003-04-02 16:23:03
|
Update of /cvsroot/cpptool/rfta/src/pyrfta
In directory sc8-pr-cvs1:/tmp/cvs-serv3921/src/pyrfta
Modified Files:
pyrfta.cpp
Log Message:
* added a few statements
* struggling with virtual functions overiding in python
Index: pyrfta.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/pyrfta/pyrfta.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** pyrfta.cpp 1 Apr 2003 08:43:36 -0000 1.2
--- pyrfta.cpp 2 Apr 2003 16:22:54 -0000 1.3
***************
*** 1,3 ****
--- 1,4 ----
#include <boost/python.hpp>
+ #include <rfta/refactoring/CodeModelVisitor.h>
#include <rfta/refactoring/CodeModelStatements.h>
#include <rfta/refactoring/CodeModelExpressions.h>
***************
*** 6,10 ****
// Notes: compiler memory allocation limits was reached after declaring two classes.
// => fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
! // Flags /Zm added to command line to increase the memory allocation limits.
using namespace boost::python;
--- 7,11 ----
// Notes: compiler memory allocation limits was reached after declaring two classes.
// => fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
! // Flags /Zm200 added to command line to increase the memory allocation limits.
using namespace boost::python;
***************
*** 13,26 ****
BOOST_PYTHON_MODULE(pyrfta)
{
! class_<Element>( "Element" )
! .def( "isFromSource", &Element::isFromSource )
! .def( "getSourceText", &Element::getSourceText )
! .def( "getSourceRange", &Element::getSourceRange )
! // .def( "setSource", &Element::setSource )
! .def( "accept", &Element::accept )
;
class_<Change>( "Change" )
--- 14,252 ----
+ /* Boost.Python documentation bug:
+
+ ** Virtual Functions with Default Implementations
+ struct BaseWrap : Base
+ {
+ BaseWrap(PyObject* self_)
+ : self(self_) {}
+ int f() { return call_method<int>(self, "f"); }
+ int default_f() { return Base::f(); } // <<=== ***ADDED***
+ PyObject* self;
+ };
+
+ The following constructor is missing for successful compilation with VC6:
+
+ BaseWrap(PyObject* self_, const Base &other)
+ : Base(other)
+ , self(self_) {}
+
+ */
+
+
+ class StatementVisitorWrap : public StatementVisitor
+ {
+ public:
+ PyObject *self;
+
+ StatementVisitorWrap( PyObject *self_ )
+ : self(self_)
+ {
+ }
+
+ void visit( BreakStatement &statement )
+ {
+ call_method<void>( self, "visitBreakStatement" );
+ }
+
+ void visit( CaseStatement &statement )
+ {
+ call_method<void>( self, "visitCaseStatement" );
+ }
+
+ void visit( CompoundStatement &statement )
+ {
+ call_method<void>( self, "visitCompoundStatement" );
+ }
+
+ void visit( ConditionStatement &statement )
+ {
+ call_method<void>( self, "visitConditionStatement" );
+ }
+
+ void visit( ContinueStatement &statement )
+ {
+ call_method<void>( self, "visitContinueStatement" );
+ }
+
+ void visit( DefaultStatement &statement )
+ {
+ call_method<void>( self, "visitDefaultStatement" );
+ }
+
+ void visit( DeclarationStatement &statement )
+ {
+ call_method<void>( self, "visitDeclarationStatement" );
+ }
+
+ void visit( DoStatement &statement )
+ {
+ call_method<void>( self, "visitDoStatement" );
+ }
+
+ void visit( ExpressionStatement &statement )
+ {
+ call_method<void>( self, "visitExpressionStatement" );
+ }
+
+ void visit( FlowControlStatement &statement )
+ {
+ call_method<void>( self, "visitFlowControlStatement" );
+ }
+
+ void visit( ForStatement &statement )
+ {
+ call_method<void>( self, "visitForStatementStatement" );
+ }
+
+ void visit( GotoStatement &statement )
+ {
+ call_method<void>( self, "visitGotoStatement" );
+ }
+
+ void visit( IfStatement &statement )
+ {
+ call_method<void>( self, "visitIfStatement" );
+ }
+
+ void visit( IterationStatement &statement )
+ {
+ call_method<void>( self, "visitIterationStatement" );
+ }
+
+ void visit( LabelStatement &statement )
+ {
+ call_method<void>( self, "visitLabelStatement" );
+ }
+
+ void visit( NullStatement &statement )
+ {
+ call_method<void>( self, "visitNullStatement" );
+ }
+
+ void visit( ReturnStatement &statement )
+ {
+ call_method<void>( self, "visitReturnStatement" );
+ }
+
+ void visit( SwitchLabelStatement &statement )
+ {
+ call_method<void>( self, "visitSwitchLabelStatement" );
+ }
+
+ void visit( SwitchStatement &statement )
+ {
+ call_method<void>( self, "visitSwitchStatement" );
+ }
+
+ void visit( WhileStatement &statement )
+ {
+ call_method<void>( self, "visitWhileStatement" );
+ }
+ };
+
+
+ class ExpressionVisitorWrap : public ExpressionVisitor
+ {
+ public:
+ PyObject *self;
+
+ ExpressionVisitorWrap( PyObject *self_ )
+ : self(self_)
+ {
+ }
+
+ void visit( AssignInitializerExpression &expression )
+ {
+ call_method<void>( self, "visitAssignInitializerExpression" );
+ }
+
+ void visit( ConstructorInitializerExpression &expression )
+ {
+ call_method<void>( self, "visitConstructorInitializerExpression" );
+ }
+
+ void visit( DeclaratorExpression &expression )
+ {
+ call_method<void>( self, "visitDeclaratorExpression" );
+ }
+
+ void visit( DefaultConditionExpression &expression )
+ {
+ call_method<void>( self, "visitDefaultConditionExpression" );
+ }
+
+ void visit( Expression &expression )
+ {
+ call_method<void>( self, "visitExpression" );
+ }
+
+ void visit( GenericExpression &expression )
+ {
+ call_method<void>( self, "visitGenericExpression" );
+ }
+
+ void visit( NullExpression &expression )
+ {
+ call_method<void>( self, "visitNullExpression" );
+ }
+ };
+
+
+ class ElementVisitorWrap : public ElementVisitor
+ , public StatementVisitorWrap
+ , public ExpressionVisitorWrap
+ {
+ ElementVisitorWrap( PyObject *self_ )
+ : StatementVisitorWrap( self_ )
+ , ExpressionVisitorWrap( self_ )
+ {
+ }
+ };
+
+
+ void statementAccept( StatementVisitor &visitor )
+ {
+ // statement->accept( visitor );
+ }
+
+
+
+
+
+
+ struct Base
+ {
+ virtual int f()
+ {
+ return 1;
+ }
+ };
+
+ int call_f(Base& b) { return b.f(); }
+
+
+ struct BaseWrap : Base
+ {
+ BaseWrap(PyObject* self_)
+ : self(self_) {}
+ BaseWrap(PyObject* self_, const Base &other)
+ : Base(other)
+ , self(self_) {}
+ int f() { return call_method<int>(self, "f"); }
+ int default_f() { return Base::f(); } // <<=== ***ADDED***
+ PyObject* self;
+ };
+
+
BOOST_PYTHON_MODULE(pyrfta)
{
! class_<Base, BaseWrap>("Base")
! .def("f", &Base::f, &BaseWrap::default_f)
;
+ def("call_f", call_f);
+
+
class_<Change>( "Change" )
***************
*** 55,57 ****
--- 281,336 ----
;
+ class_<StatementVisitor, StatementVisitorWrap, boost::noncopyable>( "StatementVisitor" )
+ ;
+
+ // class_<ExpressionVisitor, ExpressionVisitorWrap, boost::noncopyable>( "ExpressionVisitor", no_init )
+ ;
+
+ // class_<ElementVisitor, ElementVisitorWrap, boost::noncopyable>( "ElementVisitor", no_init )
+ ;
+
+ void (Element::*mfAcceptElementVisitor)( ElementVisitor & ) = &Element::accept;
+ class_<Element>( "Element" )
+ .def( "isFromSource", &Element::isFromSource )
+ .def( "getSourceText", &Element::getSourceText )
+ .def( "getSourceRange", &Element::getSourceRange )
+ // .def( "setSource", &Element::setSource )
+ // .def( "accept", mfAcceptElementVisitor )
+ ;
+
+ void (Statement::*mfAcceptStatementVisitor)( StatementVisitor & ) = &Statement::accept;
+ class_<Statement, bases<Element>, boost::noncopyable >( "Statement", no_init )
+ .def( "accept", mfAcceptStatementVisitor )
+ ;
+
+
+ class_<NullStatement, bases<Statement> >( "NullStatement" )
+ ;
+
+ class_<Label, bases<Element> >( "Label" )
+ .def( init<std::string>() )
+ .add_property( "labelName", &Label::getLabelName )
+ ;
+
+ class_<LabelHolderStatement>( "LabelHolderStatement", init<LabelPtr>() )
+ .add_property( "label", &LabelHolderStatement::getLabel, &LabelHolderStatement::setLabel )
+ ;
+
+ class_<LabelStatement, bases<Statement,LabelHolderStatement> >( "LabelStatement", init<LabelPtr>() )
+ ;
+
+ def( "statementAccept", &statementAccept );
}
+
+
+ /*
+ class Visitor(StatementVisitor):
+ ... def __init__( self ):
+ ... pass
+ ...
+ ... def visitNullStatement( self, statement ):
+ ... print "NullStatement visited"
+ ...
+ ... v = Visitor()
+ ... s = NullStatement()
+ */
\ No newline at end of file
|