00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <lestes/common.hh>
00035 #include <lestes/equality.hh>
00036 #include <lestes/lang/cplus/lex/basic_token.hh>
00037
00038 package(lestes);
00039 package(lang);
00040 package(cplus);
00041 package(lex);
00042
00043 using namespace ::std;
00044
00045
00046
00047
00048
00049
00050 class loc: public ::lestes::std::object {
00051 public:
00052
00053 bool equals(const ptr<loc> &other) const;
00054
00055 static ptr<loc> create(ulint a_position);
00056 protected:
00057
00058 loc(ulint a_position);
00059 private:
00060
00061 ulint position;
00062
00063 loc(const loc &);
00064
00065 loc &operator=(const loc &);
00066 };
00067
00068
00069
00070
00071
00072 loc::loc(ulint a_position):
00073 position(a_position)
00074 {
00075 }
00076
00077
00078
00079
00080
00081
00082 bool loc::equals(const ptr<loc> &rhs) const
00083 {
00084 return rhs && is_equal(position,rhs->position);
00085 }
00086
00087
00088
00089
00090
00091 ptr<loc> loc::create(ulint a_position) {
00092 return new loc(a_position);
00093 }
00094
00095
00096 typedef enum { POSITIVE = 1, ZERO = 0, NEGATIVE = -1 } ttype;
00097
00098
00099 typedef basic_token<ttype,ptr<loc>,int> basic_testing_token;
00100
00101
00102
00103
00104
00105
00106 class testing_token: public basic_testing_token {
00107 public:
00108
00109 ptr<testing_token> clone(void) const;
00110
00111 static ptr<testing_token> create(const location_type &a_location, const type_type &a_type,
00112 const value_type &a_value);
00113 protected:
00114
00115 testing_token(const location_type &a_location, const type_type &a_type,
00116 const value_type &a_value);
00117 };
00118
00119
00120
00121
00122
00123
00124
00125 testing_token::testing_token(const location_type &a_location, const type_type &a_type,
00126 const value_type &a_value):
00127 basic_testing_token(a_location,a_type,a_value)
00128 {
00129 }
00130
00131
00132
00133
00134
00135
00136 ptr<testing_token> testing_token::clone(void) const
00137 {
00138 return new testing_token(location_get(),type_get(),value_get());
00139 }
00140
00141
00142
00143
00144
00145
00146
00147 ptr<testing_token> testing_token::create(const location_type& a_location, const type_type &a_type,
00148 const value_type &a_value)
00149 {
00150 return new testing_token(a_location,a_type,a_value);
00151 }
00152
00153
00154
00155
00156
00157
00158 void basic_token_test(void)
00159 {
00160 ptr<loc> el = loc::create(13);
00161 ptr<loc> em = loc::create(17);
00162 ptr<testing_token> a = testing_token::create(em,ZERO,0);
00163
00164 lassert(is_equal(a,a));
00165 lassert(is_equal(a->location_get(),em));
00166 lassert(is_equal(a->type_get(),ZERO));
00167 lassert(is_equal(a->value_get(),0));
00168
00169 a = testing_token::create(el,POSITIVE,13);
00170
00171 lassert(is_equal(a,a));
00172 lassert(is_equal(a->location_get(),el));
00173 lassert(is_equal(a->type_get(),POSITIVE));
00174 lassert(is_equal(a->value_get(),13));
00175
00176 ptr<testing_token> b = testing_token::create(em,NEGATIVE,-4);
00177 ptr<testing_token> c = b->clone();
00178
00179 lassert(is_equal(c,b));
00180 lassert(is_equal(b,c));
00181 lassert(is_equal(b->type_get(),c->type_get()));
00182 lassert(is_equal(b->value_get(),c->value_get()));
00183 lassert(is_equal(b->location_get(),c->location_get()));
00184
00185 ptr<testing_token> d;
00186
00187 d = a;
00188
00189 lassert(is_equal(d,a));
00190 lassert(is_equal(a,d));
00191 lassert(is_equal(d->type_get(),POSITIVE));
00192 lassert(is_equal(d->value_get(),13));
00193 lassert(is_equal(d->location_get(),el));
00194 }
00195
00196 end_package(lex);
00197 end_package(cplus);
00198 end_package(lang);
00199 end_package(lestes);
00200
00201
00202
00203
00204
00205
00206 int main(void)
00207 {
00208 ::lestes::lang::cplus::lex::basic_token_test();
00209 return 0;
00210 }
00211