]> www.ginac.de Git - ginac.git/blobdiff - ginac/structure.pl
- prepared for 1.0.13 release
[ginac.git] / ginac / structure.pl
index b6137d0b41f57c2ddec32b254b9d07d621215377..5ec55af485cdf4adc4f72d6c6d4aa36646964f13 100755 (executable)
@@ -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");
@@ -125,7 +125,7 @@ $interface=<<END_OF_INTERFACE;
  *  This file was generated automatically by structure.pl.
  *  Please do not modify it directly, edit the perl script instead!
  *
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -148,7 +148,7 @@ ${input_structure}
 #ifndef __GINAC_${STRUCTURE_UC}_H__
 #define __GINAC_${STRUCTURE_UC}_H__
 
-#include <ginac/structure.h>
+#include "structure.h"
 
 namespace GiNaC {
 
@@ -156,48 +156,46 @@ 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}
@@ -208,13 +206,9 @@ ${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_
@@ -230,7 +224,7 @@ $implementation=<<END_OF_IMPLEMENTATION;
  *  This file was generated automatically by STRUCTURE.pl.
  *  Please do not modify it directly, edit the perl script instead!
  *
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -251,163 +245,144 @@ $implementation=<<END_OF_IMPLEMENTATION;
 ${input_structure}
 
 #include <iostream>
+#include <stdexcept>
 
 #include "${STRUCTURE}.h"
+#include "print.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}()";
-}
-
-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 const i)
+ex & ${STRUCTURE}::let_op(int i)
 {
-    ASSERT(i>=0);
-    ASSERT(i<nops());
+       GINAC_ASSERT(i>=0);
+       GINAC_ASSERT(i<nops());
 
-    switch (i) {
+       switch (i) {
 ${let_op_statements}
-    }
-    errormsg("${STRUCTURE}::let_op(): should not reach this point");
-    return *new ex(fail());
+       }
+       throw(std::runtime_error("${STRUCTURE}::let_op(): should not have reached this point"));
 }
 
 ex ${STRUCTURE}::expand(unsigned options) const
 {
-    bool all_are_trivially_equal=true;
+       bool all_are_trivially_equal=true;
 ${expand_statements}
-    if (all_are_trivially_equal) {
-        return *this;
-    }
-    return ${STRUCTURE}(${temporary_arglist});
+       if (all_are_trivially_equal) {
+               return *this;
+       }
+       return ${STRUCTURE}(${temporary_arglist});
 }
 
 // a ${STRUCTURE} 'has' an expression if it is this expression itself or a child 'has' it
 
-bool ${STRUCTURE}::has(ex const & other) const
+bool ${STRUCTURE}::has(const ex & other) const
 {
-    ASSERT(other.bp!=0);
-    if (is_equal(*other.bp)) return true;
+       GINAC_ASSERT(other.bp!=0);
+       if (is_equal(*other.bp)) return true;
 ${has_statements}
-    return false;
+       return false;
 }
 
 ex ${STRUCTURE}::eval(int level) const
 {
-    if (level==1) {
-        return this->hold();
-    }
-    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
@@ -415,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<basic &>(other));
-    int cmpval;
+       GINAC_ASSERT(is_of_type(other,${STRUCTURE}));
+       ${STRUCTURE} const &o = static_cast<const ${STRUCTURE} &>(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<basic &>(other));
+       GINAC_ASSERT(is_of_type(other,${STRUCTURE}));
+       ${STRUCTURE} const &o = static_cast<const ${STRUCTURE} &>(other);
 ${is_equal_statements}
-    return true;
+       return true;
 }
 
 unsigned ${STRUCTURE}::return_type(void) const
 {
-    return return_types::noncommutative_composite;
+       return return_types::noncommutative_composite;
 }
 
 //////////
@@ -491,7 +464,7 @@ unsigned ${STRUCTURE}::return_type(void) const
 bool ${STRUCTURE}::types_ok(void) const
 {
 ${types_ok_statements}
-    return true;
+       return true;
 }
 
 //////////
@@ -505,7 +478,7 @@ ${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