X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fstructure.pl;h=809ae2682f7548e8be01123b05e921b30af2e381;hp=725b03a592519e0c6d7b7b038e15414f25c4c29c;hb=bb2670b06c0f98ef1a4fcb193826d65363a302dd;hpb=6b3768e8c544739ae53321539cb4d1e3112ded1b diff --git a/ginac/structure.pl b/ginac/structure.pl index 725b03a5..809ae268 100755 --- a/ginac/structure.pl +++ b/ginac/structure.pl @@ -3,45 +3,45 @@ $input_structure=''; $original_input_structure=''; while (<>) { - $input_structure .= '// '.$_; - $original_input_structure .= $_; + $input_structure .= '// '.$_; + $original_input_structure .= $_; } $original_input_structure =~ tr/ \t\n\r\f/ /; $original_input_structure =~ tr/ //s; if ($original_input_structure =~ /^struct (\w+) ?\{ ?(.*)\}\;? ?$/) { - $STRUCTURE=$1; - $decl=$2; + $STRUCTURE=$1; + $decl=$2; } else { - die "illegal struct, must match 'struct name { type var; /*comment*/ ...};': $original_input_structure"; + die "illegal struct, must match 'struct name { type var; /*comment*/ ...};': $original_input_structure"; } # split off a part 'type var[,var...];' with a possible C-comment '/* ... */' while ($decl =~ /^ ?(\w+) ([\w \,]+)\; ?((\/\*.*?\*\/)?)(.*)$/) { - $type=$1; - $member=$2; - $comment=$3; - $decl=$5; - while ($member =~ /^(\w+) ?\, ?(.*)$/) { - push @TYPES,$type; - push @MEMBERS,$1; - push @COMMENTS,$comment; - if ($comment ne '') { - $comment='/* see above */'; - } - $member=$2; - } - if ($member !~ /^\w$/) { - die "illegal struct, must match 'struct name { type var; /*comment*/ ...};': $input_structure"; - } - push @TYPES,$type; - push @MEMBERS,$member; - push @COMMENTS,$comment; + $type=$1; + $member=$2; + $comment=$3; + $decl=$5; + while ($member =~ /^(\w+) ?\, ?(.*)$/) { + push @TYPES,$type; + push @MEMBERS,$1; + push @COMMENTS,$comment; + if ($comment ne '') { + $comment='/* see above */'; + } + $member=$2; + } + if ($member !~ /^\w+$/) { + die "illegal struct, must match 'struct name { type var; /*comment*/ ...};': $input_structure"; + } + push @TYPES,$type; + push @MEMBERS,$member; + push @COMMENTS,$comment; } if ($decl !~ /^ ?$/) { - die "illegal struct, must match 'struct name { type var; /*comment*/ ...};': $input_structure"; + die "illegal struct, must match 'struct name { type var; /*comment*/ ...};': $input_structure"; } #$STRUCTURE='teststruct'; @@ -50,28 +50,28 @@ $STRUCTURE_UC=uc(${STRUCTURE}); #@MEMBERS=('q10','q20','q21'); sub generate { - my ($template,$conj)=@_; - my ($res,$N); - - $res=''; - for ($N=1; $N<=$#MEMBERS+1; $N++) { - $TYPE=$TYPES[$N-1]; - $MEMBER=$MEMBERS[$N-1]; - $COMMENT=$COMMENTS[$N-1]; - $res .= eval('"' . $template . '"'); - $TYPE=''; # to avoid main::TYPE used only once warning - $MEMBER=''; # same as above - $COMMENT=''; # same as above - if ($N!=$#MEMBERS+1) { - $res .= $conj; - } - } - return $res; + my ($template,$conj)=@_; + my ($res,$N); + + $res=''; + for ($N=1; $N<=$#MEMBERS+1; $N++) { + $TYPE=$TYPES[$N-1]; + $MEMBER=$MEMBERS[$N-1]; + $COMMENT=$COMMENTS[$N-1]; + $res .= eval('"' . $template . '"'); + $TYPE=''; # to avoid main::TYPE used only once warning + $MEMBER=''; # same as above + $COMMENT=''; # same as above + if ($N!=$#MEMBERS+1) { + $res .= $conj; + } + } + return $res; } $number_of_members=$#MEMBERS+1; $constructor_arglist=generate('ex tmp_${MEMBER}',', '); -$member_access_functions=generate(' ex const & ${MEMBER}(void) { return m_${MEMBER}; }',"\n"); +$member_access_functions=generate(' const ex & ${MEMBER}(void) { return m_${MEMBER}; }',"\n"); $op_access_indices_decl=generate(' static unsigned op_${MEMBER};',"\n"); $op_access_indices_def=generate('unsigned ${STRUCTURE}::op_${MEMBER}=${N}-1;',"\n"); $members=generate(' ex m_${MEMBER}; ${COMMENT}',"\n"); @@ -119,65 +119,83 @@ $types_ok_statements=generate( $interface=< +#include "structure.h" + +namespace GiNaC { class ${STRUCTURE} : public structure { // member functions - // default constructor, destructor, copy constructor assignment operator and helpers + // default ctor, dtor, copy ctor, assignment operator and helpers public: - ${STRUCTURE}(); - ~${STRUCTURE}(); - ${STRUCTURE}(${STRUCTURE} const & other); - ${STRUCTURE} const & operator=(${STRUCTURE} const & other); + ${STRUCTURE}(); + ~${STRUCTURE}(); + ${STRUCTURE}(${STRUCTURE} const & other); + ${STRUCTURE} const & operator=(${STRUCTURE} const & other); protected: - void copy(${STRUCTURE} const & other); - void destroy(bool call_parent); + void copy(${STRUCTURE} const & other); + void destroy(bool call_parent); - // other constructors + // other ctors public: - ${STRUCTURE}(${constructor_arglist}); + ${STRUCTURE}(${constructor_arglist}); - // functions overriding virtual functions from bases classes + // functions overriding virtual functions from base classes public: - basic * duplicate() const; - void printraw(ostream & os) const; - void print(ostream & os, unsigned upper_precedence=0) const; - void printtree(ostream & os, unsigned indent) const; - int nops() const; - ex & let_op(int const i); - ex expand(unsigned options=0) const; - bool has(ex const & other) const; - ex eval(int level=0) const; - ex evalf(int level=0) const; - ex normal(lst &sym_lst, lst &repl_lst, int level=0) const; - ex diff(symbol const & s) const; - ex subs(lst const & ls, lst const & lr) const; + basic * duplicate() const; + void print(const print_context & c, unsigned level = 0) const; + int nops() const; + ex & let_op(int i); + ex expand(unsigned options=0) const; + bool has(const ex & other) const; + ex eval(int level=0) const; + ex evalf(int level=0) const; + ex normal(lst &sym_lst, lst &repl_lst, int level=0) const; + ex diff(const symbol & s) const; + ex subs(const lst & ls, const lst & lr) const; protected: - int compare_same_type(basic const & other) const; - bool is_equal_same_type(basic const & other) const; - unsigned return_type(void) const; + int compare_same_type(const basic & other) const; + bool is_equal_same_type(const basic & other) const; + unsigned return_type(void) const; - // new virtual functions which can be overridden by derived classes - // none + // new virtual functions which can be overridden by derived classes + // none - // non-virtual functions in this class + // non-virtual functions in this class public: ${member_access_functions} - bool types_ok(void) const; - + bool types_ok(void) const; + // member variables protected: ${members} @@ -188,12 +206,10 @@ ${op_access_indices_decl} // global constants extern const ${STRUCTURE} some_${STRUCTURE}; -extern type_info const & typeid_${STRUCTURE}; +extern const type_info & typeid_${STRUCTURE}; extern const unsigned tinfo_${STRUCTURE}; -// macros - -#define ex_to_${STRUCTURE}(X) (static_cast<${STRUCTURE} const &>(*(X).bp)) +} // namespace GiNaC #endif // ndef _${STRUCTURE_UC}_H_ @@ -202,170 +218,171 @@ END_OF_INTERFACE $implementation=< +#include + +#include "${STRUCTURE}.h" +#include "print.h" -#include "ginac.h" +namespace GiNaC { ////////// -// default constructor, destructor, copy constructor assignment operator and helpers +// default ctor, destructor, copy ctor assignment operator and helpers ////////// // public ${STRUCTURE}::${STRUCTURE}() { - debugmsg("${STRUCTURE} default constructor",LOGLEVEL_CONSTRUCT); - tinfo_key=tinfo_${STRUCTURE}; + tinfo_key=tinfo_${STRUCTURE}; } ${STRUCTURE}::~${STRUCTURE}() { - debugmsg("${STRUCTURE} destructor",LOGLEVEL_DESTRUCT); - destroy(0); + destroy(false); } ${STRUCTURE}::${STRUCTURE}(${STRUCTURE} const & other) { - debugmsg("${STRUCTURE} copy constructor",LOGLEVEL_CONSTRUCT); - copy(other); + copy(other); } ${STRUCTURE} const & ${STRUCTURE}::operator=(${STRUCTURE} const & other) { - debugmsg("${STRUCTURE} operator=",LOGLEVEL_ASSIGNMENT); - if (this != &other) { - destroy(1); - copy(other); - } - return *this; + if (this != &other) { + destroy(true); + copy(other); + } + return *this; } // protected void ${STRUCTURE}::copy(${STRUCTURE} const & other) { - structure::copy(other); + structure::copy(other); ${copy_statements} } void ${STRUCTURE}::destroy(bool call_parent) { - if (call_parent) structure::destroy(call_parent); + if (call_parent) structure::destroy(call_parent); } ////////// -// other constructors +// other ctors ////////// // public ${STRUCTURE}::${STRUCTURE}(${constructor_arglist}) - : ${constructor_statements} + : ${constructor_statements} { - debugmsg("${STRUCTURE} constructor from children", - LOGLEVEL_CONSTRUCT); - tinfo_key=tinfo_${STRUCTURE}; + tinfo_key=tinfo_${STRUCTURE}; } ////////// -// functions overriding virtual functions from bases classes +// functions overriding virtual functions from base classes ////////// // public basic * ${STRUCTURE}::duplicate() const { - debugmsg("${STRUCTURE} duplicate",LOGLEVEL_DUPLICATE); - return new ${STRUCTURE}(*this); -} - -void ${STRUCTURE}::printraw(ostream & os) const -{ - debugmsg("${STRUCTURE} printraw",LOGLEVEL_PRINT); - os << "${STRUCTURE}()"; + return new ${STRUCTURE}(*this); } -void ${STRUCTURE}::print(ostream & os, unsigned upper_precedence) const +void ${STRUCTURE}::print(const print_context & c, unsigned level) const { - debugmsg("${STRUCTURE} print",LOGLEVEL_PRINT); - os << "${STRUCTURE}()"; -} - -void ${STRUCTURE}::printtree(ostream & os, unsigned indent) const -{ - debugmsg("${STRUCTURE} printtree",LOGLEVEL_PRINT); - os << "${STRUCTURE}()"; + c.s << class_name() << "()"; } int ${STRUCTURE}::nops() const { - return ${number_of_members}; + return ${number_of_members}; } -ex & ${STRUCTURE}::let_op(int const i) +ex & ${STRUCTURE}::let_op(int i) { - ASSERT(i>=0); - ASSERT(i=0); + GINAC_ASSERT(ihold(); - } - bool all_are_trivially_equal=true; + if (level==1) { + return this->hold(); + } + bool all_are_trivially_equal=true; ${eval_statements} - if (all_are_trivially_equal) { - return this->hold(); - } - return ${STRUCTURE}(${temporary_arglist}); + if (all_are_trivially_equal) { + return this->hold(); + } + return ${STRUCTURE}(${temporary_arglist}); } ex ${STRUCTURE}::evalf(int level) const { - if (level==1) { - return *this; - } - bool all_are_trivially_equal=true; + if (level==1) { + return *this; + } + bool all_are_trivially_equal=true; ${evalf_statements} - if (all_are_trivially_equal) { - return *this; - } - return ${STRUCTURE}(${temporary_arglist}); + if (all_are_trivially_equal) { + return *this; + } + return ${STRUCTURE}(${temporary_arglist}); } /** Implementation of ex::normal() for ${STRUCTURE}s. It normalizes the arguments @@ -373,61 +390,59 @@ ${evalf_statements} * \@see ex::normal */ ex ${STRUCTURE}::normal(lst &sym_lst, lst &repl_lst, int level) const { - if (level==1) { - return basic::normal(sym_lst,repl_lst,level); - } - bool all_are_trivially_equal=true; + if (level==1) { + return basic::normal(sym_lst,repl_lst,level); + } + bool all_are_trivially_equal=true; ${normal_statements} - if (all_are_trivially_equal) { - return basic::normal(sym_lst,repl_lst,level); - } - ex n=${STRUCTURE}(${temporary_arglist}); - return n.bp->basic::normal(sym_lst,repl_lst,level); + if (all_are_trivially_equal) { + return basic::normal(sym_lst,repl_lst,level); + } + ex n=${STRUCTURE}(${temporary_arglist}); + return n.bp->basic::normal(sym_lst,repl_lst,level); } /** ${STRUCTURE}::diff() differentiates the children. - there is no need to check for triavially equal, since diff usually - does not return itself unevaluated. */ -ex ${STRUCTURE}::diff(symbol const & s) const + there is no need to check for triavially equal, since diff usually + does not return itself unevaluated. */ +ex ${STRUCTURE}::diff(const symbol & s) const { ${diff_statements} - return ${STRUCTURE}(${temporary_arglist}); + return ${STRUCTURE}(${temporary_arglist}); } -ex ${STRUCTURE}::subs(lst const & ls, lst const & lr) const +ex ${STRUCTURE}::subs(const lst & ls, const lst & lr) const { - bool all_are_trivially_equal=true; + bool all_are_trivially_equal=true; ${subs_statements} - if (all_are_trivially_equal) { - return *this; - } - return ${STRUCTURE}(${temporary_arglist}); + if (all_are_trivially_equal) { + return *this; + } + return ${STRUCTURE}(${temporary_arglist}); } // protected -int ${STRUCTURE}::compare_same_type(basic const & other) const +int ${STRUCTURE}::compare_same_type(const basic & other) const { - ASSERT(is_of_type(other,${STRUCTURE})); - ${STRUCTURE} const & o=static_cast<${STRUCTURE} const &> - (const_cast(other)); - int cmpval; + GINAC_ASSERT(is_of_type(other,${STRUCTURE})); + ${STRUCTURE} const &o = static_cast(other); + int cmpval; ${compare_statements} - return 0; + return 0; } -bool ${STRUCTURE}::is_equal_same_type(basic const & other) const +bool ${STRUCTURE}::is_equal_same_type(const basic & other) const { - ASSERT(is_of_type(other,${STRUCTURE})); - ${STRUCTURE} const & o=static_cast<${STRUCTURE} const &> - (const_cast(other)); + GINAC_ASSERT(is_of_type(other,${STRUCTURE})); + ${STRUCTURE} const &o = static_cast(other); ${is_equal_statements} - return true; + return true; } unsigned ${STRUCTURE}::return_type(void) const { - return return_types::noncommutative_composite; + return return_types::noncommutative_composite; } ////////// @@ -449,7 +464,7 @@ unsigned ${STRUCTURE}::return_type(void) const bool ${STRUCTURE}::types_ok(void) const { ${types_ok_statements} - return true; + return true; } ////////// @@ -463,9 +478,11 @@ ${op_access_indices_def} ////////// const ${STRUCTURE} some_${STRUCTURE}; -type_info const & typeid_${STRUCTURE}=typeid(some_${STRUCTURE}); +const type_info & typeid_${STRUCTURE}=typeid(some_${STRUCTURE}); const unsigned tinfo_${STRUCTURE}=structure::register_new("${STRUCTURE}"); +} // namespace GiNaC + END_OF_IMPLEMENTATION print "Creating interface file ${STRUCTURE}.h...";