C++ Source File

This source code has been fetched from different files, to illustrate some majour features: templates, classes, declarations, instructions.


template <class T>
inline T min2(T a, T b) {
  return (a) < (b) ? (a) : (b);
};

template <class T> inline T max2(T a, T b) { return (a) > (b) ? (a) : (b); };

class TPoint : public TSuperClass { public: TPoint (void); TPoint (int, int); TPoint (TPoint&);

int GetX (void) const; int GetY (void) const; void SetX (int); void SetY (int); void Set (TPoint&); void Set (TPoint*); void Set (int, int);

double Distance(TPoint* p);

void Display (ostream& cout) const; ostream& operator<< (ostream&) const;

char * ObjectInfo (void);

void operator+= (const TPoint&); void operator-= (const TPoint&); void operator+= (int); void operator-= (int); void operator*= (double); void operator/= (double);

private: int x_; int y_; };

inline int TPoint::GetX(void) const {return x_;} inline int TPoint::GetY(void) const {return y_;}

class TEllipse : public TSuperClass { public: TEllipse (void); TEllipse (TPoint&, int, int); TEllipse (int, int, int, int);

~TEllipse (void);

void Set (TEllipse& iw); void Set (TEllipse* iw); void Set (TPoint&, int, int); void Set (int, int, int, int);

TPoint* Center (void) const; int GetCenterX (void) const; int GetCenterY (void) const; int RadiusX (void) const; int RadiusY (void) const;

char * ObjectInfo (void);

private: TPoint center; int radiusX; int radiusY; };

AST Translation


(c-declare
  template
  min2
  (c-declare
    inline
    min2
    (-> ((c-dcl #f a T) (c-dcl #f b T)) T)
    (c-compound (return (? (< a b) (: a b)))))
  ((c-dcl #f T class))
  ((T (opdef #f #f . #[procedure]))))   ; don't worry about these procedures

(c-declare template max2 (c-declare inline max2 (-> ((c-dcl #f a T) (c-dcl #f b T)) T) (c-compound (return (? (> a b) (: a b))))) ((c-dcl #f T class)) ((T (opdef #f #f . #[procedure]))))

(c-declare class TPoint (((public (c-declare #f class-constructor (-> void (* TPoint))) (c-declare #f class-constructor (-> ((c-dcl #f () (int #f #f)) (c-dcl #f () (int #f #f))) (* TPoint))) (c-declare #f class-constructor (-> ((c-dcl #f () (& TPoint))) (* TPoint))) (c-declare #f GetX (-> void (int #f #f))) (c-declare #f GetY (-> void (int #f #f))) (c-declare #f SetX (-> ((c-dcl #f () (int #f #f))) void)) (c-declare #f SetY (-> ((c-dcl #f () (int #f #f))) void)) (c-declare #f Set (-> ((c-dcl #f () (& TPoint))) void)) (c-declare #f Set (-> ((c-dcl #f () (* TPoint))) void)) (c-declare #f Set (-> ((c-dcl #f () (int #f #f)) (c-dcl #f () (int #f #f))) void)) (c-declare #f Distance (-> ((c-dcl #f p (* TPoint))) double)) (c-declare #f Display (-> ((c-dcl #f cout (& ostream))) void)) (c-declare #f (c-operator <<) (-> ((c-dcl #f () (& ostream))) (& ostream))) (c-declare #f ObjectInfo (-> void (* (int #f char)))) (c-declare #f (c-operator +=) (-> ((c-dcl #f () (& (qual-type const TPoint)))) void)) (c-declare #f (c-operator -=) (-> ((c-dcl #f () (& (qual-type const TPoint)))) void)) (c-declare #f (c-operator +=) (-> ((c-dcl #f () (int #f #f))) void)) (c-declare #f (c-operator -=) (-> ((c-dcl #f () (int #f #f))) void)) (c-declare #f (c-operator *=) (-> ((c-dcl #f () double)) void)) (c-declare #f (c-operator /=) (-> ((c-dcl #f () double)) void))) (private (c-declare #f x_ (int #f #f)) (c-declare #f y_ (int #f #f)))) ((TSuperClass (public) #f)) #f))

(c-declare inline (:: TPoint GetX) (-> void (int #f #f)) (c-compound (return x_)))

(c-declare inline (:: TPoint GetY) (-> void (int #f #f)) (c-compound (return y_)))

(c-declare class TEllipse (((public (c-declare #f class-constructor (-> void (* TEllipse))) (c-declare #f class-constructor (-> ((c-dcl #f () (& TPoint)) (c-dcl #f () (int #f #f)) (c-dcl #f () (int #f #f))) (* TEllipse))) (c-declare #f class-constructor (-> ((c-dcl #f () (int #f #f)) (c-dcl #f () (int #f #f)) (c-dcl #f () (int #f #f)) (c-dcl #f () (int #f #f))) (* TEllipse))) (c-declare #f class-destructor (-> void void)) (c-declare #f Set (-> ((c-dcl #f iw (& TEllipse))) void)) (c-declare #f Set (-> ((c-dcl #f iw (* TEllipse))) void)) (c-declare #f Set (-> ((c-dcl #f () (& TPoint)) (c-dcl #f () (int #f #f)) (c-dcl #f () (int #f #f))) void)) (c-declare #f Set (-> ((c-dcl #f () (int #f #f)) (c-dcl #f () (int #f #f)) (c-dcl #f () (int #f #f)) (c-dcl #f () (int #f #f))) void)) (c-declare #f Center (-> void (* TPoint))) (c-declare #f GetCenterX (-> void (int #f #f))) (c-declare #f GetCenterY (-> void (int #f #f))) (c-declare #f RadiusX (-> void (int #f #f))) (c-declare #f RadiusY (-> void (int #f #f))) (c-declare #f ObjectInfo (-> void (* (int #f char))))) (private (c-declare #f center TPoint) (c-declare #f radiusX (int #f #f)) (c-declare #f radiusY (int #f #f)))) ((TSuperClass (public) #f)) #f))