X-Git-Url: https://ginac.de/ginac.git//ginac.git?a=blobdiff_plain;ds=inline;f=ginac%2Fstructure.pl;h=809ae2682f7548e8be01123b05e921b30af2e381;hb=2e3eaaf5665eba012287220683995817cb371a13;hp=c7ec0b2701086f08b78bf9edb83dc57d4ea17dbc;hpb=956eeb82c513a723e864edefa857133282cf692b;p=ginac.git diff --git a/ginac/structure.pl b/ginac/structure.pl index c7ec0b27..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,23 +50,23 @@ $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; @@ -125,7 +125,7 @@ $interface=<(*(X).bp)) - -#ifndef NO_NAMESPACE_GINAC } // namespace GiNaC -#endif // ndef NO_NAMESPACE_GINAC #endif // ndef _${STRUCTURE_UC}_H_ @@ -234,7 +224,7 @@ $implementation=< +#include #include "${STRUCTURE}.h" +#include "print.h" -#ifndef NO_NAMESPACE_GINAC namespace GiNaC { -#endif // ndef NO_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}()"; -} - -void ${STRUCTURE}::print(ostream & os, unsigned upper_precedence) const -{ - debugmsg("${STRUCTURE} print",LOGLEVEL_PRINT); - os << "${STRUCTURE}()"; + return new ${STRUCTURE}(*this); } -void ${STRUCTURE}::printtree(ostream & os, unsigned indent) const +void ${STRUCTURE}::print(const print_context & c, unsigned level) 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 i) { - GINAC_ASSERT(i>=0); - GINAC_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 @@ -421,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. */ + 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(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(const basic & other) const { - GINAC_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(const basic & other) const { - GINAC_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; } ////////// @@ -497,7 +464,7 @@ unsigned ${STRUCTURE}::return_type(void) const bool ${STRUCTURE}::types_ok(void) const { ${types_ok_statements} - return true; + return true; } ////////// @@ -514,9 +481,7 @@ const ${STRUCTURE} some_${STRUCTURE}; const type_info & typeid_${STRUCTURE}=typeid(some_${STRUCTURE}); const unsigned tinfo_${STRUCTURE}=structure::register_new("${STRUCTURE}"); -#ifndef NO_NAMESPACE_GINAC } // namespace GiNaC -#endif // ndef NO_NAMESPACE_GINAC END_OF_IMPLEMENTATION