📄 afunction.hpp
字号:
bool ell=false) :n(7),t(tt),ellipse(ell) {t[0]=a,t[1]=b;t[2]=c;t[3]=d; t[4]=e; t[5]=f; t[6]=g; } // (6 args) Added by Fabian Dortu explicit ArrayOfaType(const aType & a,const aType & b,const aType & c,const aType & d,const aType & e, const aType & f,const aType & g,const aType & h, bool ell=false) :n(8),t(tt),ellipse(ell) {t[0]=a,t[1]=b;t[2]=c;t[3]=d; t[4]=e; t[5]=f; t[6]=g; t[7]=h; } // (7 args) Added by Fabian Dortu explicit ArrayOfaType(const aType & a,const aType & b,const aType & c,const aType & d,const aType & e, const aType & f,const aType & g,const aType & h, const aType & i, bool ell=false) :n(9),t(tt),ellipse(ell) {t[0]=a,t[1]=b;t[2]=c;t[3]=d; t[4]=e; t[5]=f; t[6]=g; t[7]=h; t[8]=i; } // (8 args) Added by Fabian Dortu explicit ArrayOfaType(const aType & a,const aType & b,const aType & c,const aType & d, const aType & e, const aType & f,const aType & g,const aType & h, const aType & i, const aType & j, bool ell=false) :n(10),t(tt),ellipse(ell) {t[0]=a,t[1]=b;t[2]=c;t[3]=d; t[4]=e; t[5]=f; t[6]=g; t[7]=h; t[8]=i; t[9]=j; } // (10 args) Added by Fabian Dortu explicit ArrayOfaType(const aType & a,const aType & b,const aType & c,const aType & d,const aType & e,const aType & f,const aType & g,const aType & h, const aType & i, const aType & j, const aType & k,bool ell=false) :n(11),t(tt),ellipse(ell) {t[0]=a,t[1]=b;t[2]=c;t[3]=d; t[4]=e; t[5]=f; t[6]=g; t[7]=h; t[8]=i; t[9]=j; t[10]=k; } // (10 args) Added by Fabian Dortu ArrayOfaType(const basicAC_F0 & ) ; ArrayOfaType(const ArrayOfaType & ); // ArrayOfaType(const ListOfId * l); ~ArrayOfaType() { if(t && t != tt) delete [] t;t=0;n=0;} bool WithOutCast( const ArrayOfaType & a) const ; bool WithCast( const ArrayOfaType & a,int nbcast=100000) const ; // return the number of cast // exactly comparaison bool operator==( const ArrayOfaType & a) const { if (a.n != n || a.ellipse !=ellipse) return false; for (int i=0;i<n;i++) if (t[i] != a.t[i]) return false; return true;} friend ostream & operator<<(ostream & f,const ArrayOfaType & a);}; class OneOperator : public ArrayOfaType { friend class MakeVectSpaceN; friend class basicForEachType; const basicForEachType * r; // return type OneOperator *next; // to make a list of OneOperator public: int pref; // to try to solve ambiguity for binary operator // 10 for bool, 20 for int , 30 for long , 40, for float, 50 double, 60 for complex, 70 string // string+ 1 => string // 1+string => string OneOperator(aType rr) ;// : r(rr),ArrayOfaType(),next(0),pref(0) {throwassert(r);} OneOperator(aType rr,aType a) ;//: r(rr),ArrayOfaType(a,false),next(0),pref(0) {throwassert(rr && a );} OneOperator(aType rr,aType a,aType b);// : r(rr),ArrayOfaType(a,b,false),next(0),pref(0) { // throwassert(rr && a && b);} OneOperator(aType rr,aType a,aType b,aType c) ; //: r(rr),ArrayOfaType(a,b,c,false),next(0),pref(0) {throwassert(rr && a && b && c);} OneOperator(aType rr,aType a,aType b,aType c,aType d) ; //: r(rr),ArrayOfaType(a,b,c,d,false),next(0),pref(0) {throwassert(rr && a && b && c);} OneOperator(aType rr,aType a,aType b,aType c,aType d,aType e) ; //: r(rr),ArrayOfaType(a,b,c,d,e,false),next(0),pref(0) {throwassert(rr && a && b && c && d);} // Added by Fabian Dortu (5 parameters) OneOperator(aType rr,aType a,aType b,aType c,aType d,aType e,aType f) ; //: r(rr),ArrayOfaType(a,b,c,d,e,f,false),next(0),pref(0) {throwassert(rr && a && b && c && d && e && f);} // Added by Fabian Dortu (6 parameters) OneOperator(aType rr,aType a,aType b,aType c,aType d,aType e,aType f, aType g); // : r(rr),ArrayOfaType(a,b,c,d,e,f,g,false),next(0),pref(0) {throwassert(rr && a && b && c && d && e && f && g);} // Added by Fabian Dortu (7 parameters) OneOperator(aType rr,aType a,aType b,aType c,aType d,aType e,aType f, aType g, aType h); // : r(rr),ArrayOfaType(a,b,c,d,e,f,g,h,false),next(0),pref(0) {throwassert(rr && a && b && c && d && e && f && g && h);} // Added by Fabian Dortu (8 parameters) OneOperator(aType rr,aType a,aType b,aType c,aType d,aType e,aType f, aType g, aType h, aType i) ; //: r(rr),ArrayOfaType(a,b,c,d,e,f,g,h,i,false),next(0),pref(0) {throwassert(rr && a && b && c && d && e && f && g && h && i);} // Added by Fabian Dortu (9 parameters) OneOperator(aType rr,aType a,aType b,aType c,aType d,aType e,aType f, aType g, aType h, aType i, aType j); // : r(rr),ArrayOfaType(a,b,c,d,e,f,g,h,i,j,false),next(0),pref(0) {throwassert(rr && a && b && c && d && e && f && g && h && i && j);} // Added by Fabian Dortu (10 parameters) OneOperator(aType rr,const ArrayOfaType &ta) ; //: r(rr),ArrayOfaType(ta),next(0),pref(0) {throwassert(rr);} OneOperator(aType rr,bool ellipse) ; //: r(rr),ArrayOfaType(ellipse),next(0),pref(0) {throwassert(rr );} OneOperator(aType rr,const ListOfId *l) ; //: r(rr),ArrayOfaType(l),next(0),pref(0) {throwassert(rr );} typedef pair<const OneOperator *,int> pair_find; void operator+=(OneOperator &a){throwassert(a.next==0);a.next=next;next=&a;} // a way to make none recurve delete good virtual ~OneOperator(); pair_find Find(const ArrayOfaType & at) const ; pair_find FindWithOutCast(const ArrayOfaType & at) const ; // for OneOperator * FindSameR(const ArrayOfaType & at) ; void Show(const ArrayOfaType & at,ostream &f=cerr) const; void Show(ostream &f=cerr) const; operator aType () const { return r;} virtual E_F0 * code(const basicAC_F0 &) const =0; virtual C_F0 code2(const basicAC_F0 &a) const ; // {return code(code(a),r);} const OneOperator * Simple() const { return next||n?0:this;} friend ostream & operator<<(ostream & f,const OneOperator & a); };class Polymorphic: public E_F0mps { // a list of type // simple, array or function private: typedef const char * Key; typedef OneOperator * Value; // struct Keyless : binary_function<Key,Key, bool> // { bool operator()(const Key& x, const Key& y) const{ return strcmp(x,y)<0;} }; typedef map<Key,Value,Keyless> maptype; // typedef maptype::const_iterator const_iterator; // typedef maptype::iterator iterator; // // remark the map is mutable because // a expression is const E_F0 * // So There is a incompatibility between // we save an expression in a variable // we have to add thing to a polymorphisme expression mutable maptype m; // all polymorphisme of the Identifier Expression e; // default expression public: Polymorphic() : m(),e(0) {} // by default Empty and do nothing virtual AnyType operator()(Stack ) const { return Nothing;} virtual bool Empty() const {return true;} // by default Empty void clear() { m.clear();} const OneOperator * Find(const char *op, const ArrayOfaType &at) const; const OneOperator * FindWithOutCast(const char *op,const ArrayOfaType &at) const; void Show(const char *op,const ArrayOfaType & at,ostream &f=cerr)const ; void Add(const char * op,OneOperator * p0 ,OneOperator * p1=0,OneOperator * p2=0, OneOperator * p3=0,OneOperator * p4=0,OneOperator * p5=0, OneOperator * p6=0,OneOperator * p7=0,OneOperator * p8=0, OneOperator * p9=0,OneOperator * pa=0,OneOperator * pb=0, OneOperator * pc=0,OneOperator * pd=0,OneOperator * pe=0 ) const {Addp(op,p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,pa,pb,pc,pd,pe,0);} void Add(const char * op,OneOperator ** pp) const ; private: void Addp(const char * op,OneOperator * pp,...) const ; friend ostream & operator<<(ostream & f,const Polymorphic & a); };// the type for polymorphisme of id // compile time expression class basicAC_F0; class C_F0 { friend class CC_F0; protected: Expression f; // the expression code aType r; // the expression type public: // the constructeur C_F0() :f(0),r(0) {} C_F0(const C_F0 & c):f(c.f),r(c.r) {} C_F0(const C_F0 & a,const C_F0 & b); // concatenation C_F0(const Type_Expr & a):f(a.second),r(a.first) {} C_F0(const Polymorphic *,const char *,const basicAC_F0 & ); C_F0(const Polymorphic *,const char *, AC_F0 & ); // function, array .. C_F0(const C_F0 & e,const char *op,const basicAC_F0 & p) ; C_F0(const C_F0 & e,const char *op, AC_F0 & p) ; C_F0(const C_F0 & e,const char *op,const C_F0 & ee) ; C_F0(const C_F0 & e,const char *op,const C_F0 & a,const C_F0 & b) ; C_F0(const C_F0 & e,const char *nm) ; // without parameter ex f() C_F0(const Polymorphic * pop,const char *op); // unary operator C_F0(const Polymorphic * pop,const char *op,const C_F0 & a); // binary operator C_F0(const Polymorphic * pop,const char *op,const C_F0 & a,const C_F0 & b); // ternary operator C_F0(const Polymorphic * pop,const char *op,const C_F0 & a,const C_F0 & b,const C_F0 & c); C_F0( Expression ff,aType rr ): f(ff),r(rr) { // cout << "C_F0: " << * rr << endl;// dec 2007 FH // if (!rr && ff) cerr << "Type Null" << endl; } // operator Expression() const {return f;} AnyType eval(Stack s) const {return (*f)(s);} Expression RightValue() const { return r->RightValueExpr(f);} Expression LeftValue() const; aType left() const {return r;} aType right() const {return r->right();} C_F0 RightExp() const { return C_F0(RightValue(),right());} // FH add 07/2005 operator E_F0 * () const {return f;} bool Empty() const {return !f || f->Empty();} bool NotNull() const {return f;} int TYPEOFID() const { return r ? r->TYPEOFID(): 0;} int nbitem() const { return f ? f->nbitem() : 0;} bool EvaluableWithOutStack() const { return f && f->EvaluableWithOutStack();} Expression Destroy() { return r->Destroy(*this);} operator const Polymorphic * () const {return dynamic_cast<const Polymorphic *>(f);} bool operator==(const C_F0 & a) const {return f==a.f && r == a.r;} bool operator!=(const C_F0 & a) const {return f!=a.f || r != a.r;}// Type_Expr SetParam(const ListOfId * l,size_t & top) const ; bool MeshIndependent() const { return f ==0 ? f->MeshIndependent() : false;}private:friend class Block; friend class TableOfIdentifier; C_F0( Expression ff ): f(ff),r(0) {} };// for bison class CListOfInst; // a => b // f => t||f // t => t // (a =>b) <=> (!a || b ) // warning ------------------class ForTypeVoid: public basicForEachType{public: ForTypeVoid():basicForEachType(typeid(void),0,0,0,0,0) {}};template<class T> class ForEachType: public basicForEachType{public: ForEachType(Function1 iv=0,Function1 id=0):basicForEachType(typeid(T),sizeof(T),0,0,iv,id) { if (sizeof(T) > sizeof(AnyTypeWithOutCheck) ) { cout << " Sorry the " <<typeid(T).name() << " is too large ( " << sizeof(T) << " > " << sizeof(AnyTypeWithOutCheck) << " ) " << endl; throwassert(sizeof(T) <= sizeof(AnyTypeWithOutCheck) ); } }};template<class T> class ForEachType<T*>: public basicForEachType{public: ForEachType(Function1 iv=0,Function1 id=0):basicForEachType(typeid(T),sizeof(T),0,0,iv,id) { }};template<class A,class B> AnyType UnRef(Stack,const AnyType &a) ; template<class A> AnyType Initialize(Stack,const AnyType &a) ; template<class A> AnyType Destroy(Stack,const AnyType &a) ; // the type of variable is pointer because we need to write in template<class T> class ForEachTypePtr: public basicForEachType { public: ForEachTypePtr(); ForEachTypePtr(Function1 init,Function1 dl); ForEachTypePtr(Function1 dl);};template<class T> class ForEachTypePtr<T*>: public basicForEachType { public: ForEachTypePtr(); ForEachTypePtr(Function1 init,Function1 dl); ForEachTypePtr(Function1 dl);};template<class T,int RTYPE> class ForEachTypePtrfspace: public ForEachTypePtr<T> { public: ForEachTypePtrfspace():ForEachTypePtr<T>() {} int TYPEOFID() const {return RTYPE;} };class ForTypeAnyType: public basicForEachType{public: ForTypeAnyType(): basicForEachType(typeid(AnyType),sizeof(AnyType)) {} bool CastingFrom(const basicForEachType * ) const {return true;} C_F0 CastTo(const C_F0 & e) const {return e;} };// for cast and get value associed to a pointer template<class A,class B> AnyType Cast(Stack,const AnyType &b) { return SetAny<A>(static_cast<A>(GetAny<B>(b)));} template<class A,class B,A F(const B &)> AnyType FCast(Stack s,const AnyType &b) { return SetAny<A>(Add2StackOfPtr2Free(s,F(GetAny<B>(b))));} template<class A> AnyType UnRef(Stack,const AnyType &a) { return SetAny<A>(*PGetAny<A>(a));}template<class A,class B> AnyType UnRef(Stack,const AnyType &a) { return SetAny<A>(*PGetAny<B>(a));} template<class A> AnyType UnRefCopyPtr(Stack s,const AnyType &a) { A ** ppa=PGetAny<A*>(a); A * pc = new A(**ppa); return SetAny<A*>(Add2StackOfPtr2Free(s,pc)) ;} template<class A> AnyType Initialize(Stack,const AnyType &x){ A * a=PGetAny<A>(x); A *b=new A;// memcpy(a,b,sizeof(A));// bitcopy ::operator delete(b); // delete with no destruction return SetAny<A*>(a);}template<class A> AnyType InitializePtr(Stack stack,const AnyType &x){ A * a=PGetAny<A>(x); SHOWVERB( cout << " init ptr " << typeid(A*).name() << (char *) a - (char*) stack<< endl); *a=0; return x;}template<class A> inline AnyType Delete(Stack,const AnyType &x){ A * a=PGetAny<A>(x); SHOWVERB(cout << "DESTROY " <<typeid(A).name() << " " << a << endl); (*a).~A(); return Nothing;}template<class A> inline AnyType Destroy(Stack,const AnyType &x){ A * a=PGetAny<A>(x); SHOWVERB(cout << "DESTROY " <<typeid(A).name() << " " << a << endl); a->destroy(); return Nothing;}template<class A> inline AnyType DestroyS(Stack,const AnyType &x){ A a=GetAny<A>(x); SHOWVERB(cout << "DESTROY " <<typeid(A).name() << " " << a << endl); a.destroy(); return Nothing;}template<class A> inline AnyType InitS(Stack,const AnyType &x){ A a=GetAny<A>(x); SHOWVERB(cout << "InitS " <<typeid(A).name() << " " << a << endl); a.init(); return Nothing;}template<class A> inline AnyType InitP(Stack,const AnyType &x){ A *a=PGetAny<A>(x); SHOWVERB(cout << "InitP " <<typeid(A).name() << " " << a << endl); a->init(); return Nothing;}template<class A> inline AnyType DestroyPtr(Stack,const AnyType &x) { const A * a=PGetAny<A>(x); SHOWVERB(cout << "DestroyPtr " << typeid(A).name() << *a << endl); (*a)->destroy(); // delete *a; return Nothing; };template<class A> inline AnyType DeletePtr(Stack,const AnyType &x) { const A * a=PGetAny<A>(x); SHOWVERB(cout << "DeletePtr " << typeid(A).name() << *a << endl); // (*a)->destroy(); delete *a; return Nothing; };template<> AnyType inline DestroyPtr<string *>(Stack,const AnyType &x) { string ** a=PGetAny<string*>(x); SHOWVERB( cout << "DestroyPtr " << typeid(string*).name() << *a << endl); delete *a; return Nothing; };template<class A> AnyType Initialize(Stack,const AnyType &x,const AnyType &y){ A * a=PGetAny<A>(x); A *b=new A(GetAny<A>(x));// memcpy(a,b,sizeof(A));// bitcopy ::operator delete(b); // delete with no destruction return SetAny<A*>(a);} class E_F0_CFunc2 :public E_F0mps { public: CFunction2 f2; E_F0 *a,*b; AnyType operator()(Stack s) const {return f2(s,a,b);} E_F0_CFunc2( CFunction2 ff,E_F0 *aa,E_F0 *bb) : f2(ff),a(aa),b(bb){} bool EvaluableWithOutStack() const {return a->EvaluableWithOutStack() && b->EvaluableWithOutStack();} // operator aType () const { return atype<void>();} };class E_F0_CFunc4 :public E_F0mps { public: CFunction4 f4; E_F0 *a,*b,*c,*d; AnyType operator()(Stack s) const {return f4(s,a,b,c,d);} E_F0_CFunc4( CFunction4 ff,E_F0 *aa,E_F0 *bb,E_F0 *cc,E_F0 *dd) : f4(ff),a(aa),b(bb),c(cc),d(dd){} operator aType () const { return atype<void>();} };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -