Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
March 2008
- 12 participants
- 83 discussions
03 Mar '08
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-03-03 Caroline Vigouroux <vigour_c(a)epita.fr>
loading image and convertion in new color mode test.
* color/is_HSI.cc: test conversion.
* color/my_hsi.hh: correct a bug.
* color/rgb_to_hsi.hh: correct a bug.
* color/rgb_to_xyz.hh: correct a bug.
* color/tests.cc: test conversion.
* load.cc: New loader.
* tests.cc: New tests.
---
color/is_HSI.cc | 13 +++++++
color/my_hsi.hh | 94 ++++++++++++++++++++++++++--------------------------
color/rgb_to_hsi.hh | 66 +++++++++++++++++++++++++++++-------
color/rgb_to_xyz.hh | 3 -
color/tests.cc | 3 +
load.cc | 38 +++++++++++++++++++++
tests.cc | 31 +++++++++++++++++
7 files changed, 186 insertions(+), 62 deletions(-)
Index: trunk/milena/sandbox/vigouroux/load.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/load.cc (revision 0)
+++ trunk/milena/sandbox/vigouroux/load.cc (revision 1760)
@@ -0,0 +1,38 @@
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/display/save_and_show.hh>
+#include <mln/value/rgb.hh>
+#include <mln/value/rgb8.hh>
+
+#include <mln/io/ppm/load.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/math/round.hh>
+#include <mln/level/transform.hh>
+
+#include <mln/core/w_window2d_float.hh>
+#include <mln/border/thickness.hh>
+#include <mln/linear/convolve.hh>
+
+# include <mln/display/save.hh>
+# include <mln/display/show.hh>
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+ image2d<mln::value::rgb8> lena;
+ io::ppm::load(lena, "../../img/lena.ppm");
+// image2d<mln::value::hsi_3x8> inter(lena.domain());
+ image2d<mln::value::rgb8> out(lena.domain());
+ const image2d<mln::value::rgb8> input = exact(lena);
+
+// mln_piter(image2d<mln::value::rgb8>) p(input.domain());
+// for_all(p)
+// {
+// inter(p) = fun::v2v::f_rgb_to_hsi_3x8(p);
+
+// }
+
+ display::save_and_show (lena, "display", 1);
+}
+
Index: trunk/milena/sandbox/vigouroux/tests.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/tests.cc (revision 0)
+++ trunk/milena/sandbox/vigouroux/tests.cc (revision 1760)
@@ -0,0 +1,31 @@
+#include <mln/core/image_if_value.hh>
+#include <mln/core/inplace.hh>
+#include <mln/core/w_window2d_int.hh>
+#include <mln/display/show.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/display/save_and_show.hh>
+#include <mln/level/fill.hh>
+
+#include "rgb_to_yuv.hh"
+#include "my_yuv.hh"
+
+#include "rgb_to_xyz.hh"
+#include "my_xyz.hh"
+
+#include "rgb_to_cmy.hh"
+#include "my_cmy.hh"
+
+#include "rgb_to_hsi.hh"
+#include "my_hsi.hh"
+
+int main()
+{
+ using namespace mln;
+
+ struct value::yuv<8> yuv(4, 4, 4);
+ std::cout << yuv.y() << std::endl;
+ std::cout << yuv.u() << std::endl;
+ std::cout << yuv.v() << std::endl;
+
+ return (0);
+}
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_xyz.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_xyz.hh (revision 1759)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_xyz.hh (revision 1760)
@@ -25,7 +25,7 @@
xyz.z(0.010 * rgb.green() + 0.990 * rgb.blue());
return (xyz);
-_ }
+ }
};
struct f_xyz_to_rgb
@@ -33,7 +33,6 @@
struct value::rgb<8>
doit(const struct value::xyz<8> xyz) const
{
- struct value::rgb<8> rgb;
int r;
int g;
int b;
Index: trunk/milena/sandbox/vigouroux/color/tests.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/color/tests.cc (revision 1759)
+++ trunk/milena/sandbox/vigouroux/color/tests.cc (revision 1760)
@@ -9,6 +9,9 @@
#include "rgb_to_yuv.hh"
#include "my_yuv.hh"
+#include "rgb_to_xyz.hh"
+#include "my_xyz.hh"
+
#include "rgb_to_cmy.hh"
#include "my_cmy.hh"
Index: trunk/milena/sandbox/vigouroux/color/my_hsi.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1759)
+++ trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1760)
@@ -21,14 +21,14 @@
{
};
- template <typename F>
- class hsi_ : public HSI< hsi_<F> >
+ template <typename H, typename S, typename I>
+ class hsi_ : public HSI< hsi_<H,S,I> >
{
public:
- typedef F h_type;
- typedef F s_type;
- typedef F i_type;
+ typedef H h_type;
+ typedef S s_type;
+ typedef I i_type;
/// Constructor without argument.
hsi_()
@@ -36,50 +36,50 @@
}
/// Constructor from component values.
- hsi_(const F& h, const F& s, const F& i)
- : h_(h),
- s_(s),
- i_(i)
+ hsi_(const H& hue, const S& sat, const I& i)
+ : hue_(hue),
+ sat_(sat),
+ int_(i)
{
}
- /// Read-only access to the h component.
- const F& h() const
+ /// Read-only access to the hue component.
+ const H& hue() const
{
- return this->h_;
+ return this->hue_;
}
- const F& s() const
+ const S& sat() const
{
- return this->s_;
+ return this->sat_;
}
- const F& i() const
+ const I& i() const
{
- return this->i_;
+ return this->int_;
}
- /// Read-write access to the h component.
- F& h()
+ /// Read-write access to the hue component.
+ H& hue()
{
- return this->h_;
+ return this->hue_;
}
- F& s()
+ S& sat()
{
- return this->s_;
+ return this->sat_;
}
- F& i()
+ I& i()
{
- return this->i_;
+ return this->int_;
}
private:
- F h_;
- F s_;
- F i_;
+ H hue_;
+ S sat_;
+ I int_;
};
- typedef hsi_<float01_8> hsi_3x8;
+ typedef hsi_<float, float, float> hsi_3x8;
- typedef hsi_<double> hsi_d;
+ typedef hsi_<double, double, double> hsi_d;
@@ -91,32 +91,32 @@
hsi<n>();
/// Constructor from component values.
- hsi<n>(int h, int s, int i);
+ hsi<n>(double hue, double sat, double i);
/// Access to component values.
- double h() const { return this->h_; }
- double s() const { return this->s_; }
- double i() const { return this->i_; }
+ double hue() const { return this->hue_; }
+ double sat() const { return this->sat_; }
+ double i() const { return this->int_; }
/// Set component values.
- void h(double h)
+ void hue(double hue)
{
- this->h_ = h;
+ this->hue_ = hue;
}
- void s(double s)
+ void sat(double sat)
{
- this->s_ = s;
+ this->sat_ = sat;
}
void i(double i)
{
mln_precondition(i >= 0);
- this->i_ = i;
+ this->int_ = i;
}
private:
- double h_;
- double s_;
- double i_;
+ double hue_;
+ double sat_;
+ double int_;
};
@@ -125,19 +125,19 @@
template <unsigned n>
inline
hsi<n>::hsi()
- :h_(0), s_(0), i_(0)
+ :hue_(0), sat_(0), int_(0)
{
}
template <unsigned n>
inline
- hsi<n>::hsi(int h, int s, int i)
+ hsi<n>::hsi(double h, double sat, double i)
{
- mln_precondition(h >= 0);
- mln_precondition(s >= 0);
- mln_precondition(i >= 0);
- this->h_ = h;
- this->s_ = s;
+ mln_invariant(h >= 0);
+ mln_invariant(sat >= 0);
+ mln_invariant(i >= 0);
+ this->hue_ = h;
+ this->sat_ = sat;
this->i_ = i;
}
Index: trunk/milena/sandbox/vigouroux/color/is_HSI.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/color/is_HSI.cc (revision 1759)
+++ trunk/milena/sandbox/vigouroux/color/is_HSI.cc (revision 1760)
@@ -16,5 +16,18 @@
std::cout << mlc_is_a(rgb8, HSI)::value << std::endl;
rgb8 c(255, 10, 1);
+ rgb8 other(10, 20, 30);
+
+ // Essai en 0 255
+
hsi_3x8 c_hsi = fun::v2v::f_rgb_to_hsi_3x8(c);
+ rgb8 c2 = fun::v2v::f_hsi_to_rgb_3x8(c_hsi);
+ std::cout << "c = " << c << std::endl;
+ std::cout << "c2 = " << c2 << std::endl;
+
+ hsi_3x8 c_cool = fun::v2v::f_rgb_to_hsi_3x8(other);
+ rgb8 coucou = fun::v2v::f_hsi_to_rgb_3x8(c_cool);
+
+ std::cout << "c = " << other << std::endl;
+ std::cout << "c2 = " << coucou << std::endl;
}
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1759)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1760)
@@ -1,3 +1,4 @@
+
#include <cmath>
#include <mln/core/image_if_value.hh>
@@ -49,11 +50,11 @@
std::cout << "FIXME: " << tmp << std::endl;
}
- hsi.h() = atan2(beta, alpha) / 3.1415 * 180.0;
- if (hsi.h() < 0)
- hsi.h() = hsi.h() + 360.0;
- mln_invariant(hsi.h() >= 0);
- hsi.s() = std::sqrt(alpha * alpha + beta * beta);
+ hsi.hue() = atan2(beta, alpha) / 3.1415 * 180.0;
+ if (hsi.hue() < 0)
+ hsi.hue() = hsi.hue() + 360.0;
+ mln_invariant(hsi.hue() >= 0);
+ hsi.sat() = std::sqrt(alpha * alpha + beta * beta);
hsi.i() = sqrt3_3 * rgb.red() + sqrt3_3 * rgb.green() + sqrt3_3 * rgb.blue();
return hsi;
@@ -66,6 +67,45 @@
// end of NEW
+ // NEW2
+
+ template <typename T_rgb>
+ struct f_hsi_to_rgb_ : public Function_v2v< f_hsi_to_rgb_<T_rgb> >
+ {
+ typedef T_rgb result;
+
+ template <typename T_hsi>
+ T_rgb operator()(const T_hsi& hsi) const
+ {
+ int r;
+ int g;
+ int b;
+
+ static const double sqrt3_3 = sqrt(3) / 3;
+ static const double inv_sqrt6 = 1 / sqrt(6);
+ static const double inv_sqrt2 = 1 / sqrt(2);
+
+ double h = hsi.hue() / 180.0 * 3.1415;
+ double alpha = hsi.sat() * cos(h);
+ double beta = hsi.sat() * sin(h);
+
+ r = int(sqrt3_3 * hsi.i() + 2 * inv_sqrt6 * beta);
+ g = int(sqrt3_3 * hsi.i() + inv_sqrt2 * alpha - inv_sqrt6 * beta);
+ b = int(sqrt3_3 * hsi.i() - inv_sqrt2 * alpha - inv_sqrt6 * beta);
+
+ T_rgb rgb(r, g, b);
+
+ return rgb;
+ }
+ };
+
+ typedef f_hsi_to_rgb_<value::rgb8> f_hsi_to_rgb_3x8_t;
+
+ f_hsi_to_rgb_3x8_t f_hsi_to_rgb_3x8;
+
+ // end of NEW2
+
+
} // end of namespace fun::v2v
} // end of namespace fun
@@ -88,11 +128,11 @@
double alpha = inv_sqrt2 * rgb.green() - inv_sqrt2 * rgb.blue();
double beta = 2 * inv_sqrt6 * rgb.red() - inv_sqrt6 * rgb.green() - inv_sqrt6 * rgb.blue();
- hsi.h(atan2(beta, alpha) / 3.1415 * 180.0);
- if (hsi.h() < 0)
- hsi.h(hsi.h() + 360.0);
- mln_precondition(hsi.h() >= 0);
- hsi.s(sqrt(alpha * alpha + beta * beta));
+ hsi.hue(atan2(beta, alpha) / 3.1415 * 180.0);
+ if (hsi.hue() < 0)
+ hsi.hue(hsi.hue() + 360.0);
+ mln_precondition(hsi.hue() >= 0);
+ hsi.sat(sqrt(alpha * alpha + beta * beta));
hsi.i(sqrt3_3 * rgb.red() + sqrt3_3 * rgb.green() + sqrt3_3 * rgb.blue());
return hsi;
@@ -113,9 +153,9 @@
double inv_sqrt6 = 1 / sqrt(6);
double inv_sqrt2 = 1 / sqrt(2);
- double h = hsi.h() / 180.0 * 3.1415;
- double alpha = hsi.s() * cos(h);
- double beta = hsi.s() * sin(h);
+ double h = hsi.hue() / 180.0 * 3.1415;
+ double alpha = hsi.sat() * cos(h);
+ double beta = hsi.sat() * sin(h);
r = int(sqrt3_3 * hsi.i() + 2 * inv_sqrt6 * beta);
g = int(sqrt3_3 * hsi.i() + inv_sqrt2 * alpha - inv_sqrt6 * beta);
1
0
https://svn.lrde.epita.fr/svn/oln/trunk
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Start a description of image types.
* milena/doc/tutorial/image_types.txt: New.
image_types.txt | 364 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 364 insertions(+)
Index: milena/doc/tutorial/image_types.txt
--- milena/doc/tutorial/image_types.txt (revision 0)
+++ milena/doc/tutorial/image_types.txt (revision 0)
@@ -0,0 +1,364 @@
+ -*- outline -*-
+
+
+* image interface
+
+** at a glance
+
+ima : domain -> destination
+ p -> ima(p)
+
+
+object type
+---------------------------
+ima I
+
+ima.domain I::pset
+ima.destination() I::vset
+
+p like I::site
+ima(p) like I::value
+
+
+impl detail:
+signature is "ima(p : psite) : rvalue"
+
+
+** about domain and destination
+
+ima.domain is usually a mathematical set. Yet it can be a
+multiset (a bag) but then weird things might happen...
+
+ima.destination is a set. Every value, that is ima(p) with p in
+ima.domain, is taken from this set. For instance, a color image can
+be defined with the destination being of type value::set<rgb_3x8>.
+
+Classically, some image types are defined by couples (p,v) where v +ima(p). A given cell, location in RAM or in a file, corresponds to a
+point p and stores the corresponding value. So when we have N points,
+we also have N value cells. To iterate over pixel values, we then
+iterate over the definition domain and access values through ima(p):
+
+code A)
+ for all p of ima.domain
+ | v = ima(p)
+ | print v.
+
+The set of possible taken values in ima is the destination set. If
+this set has a reasonable size, we can iterate over:
+
+code B)
+ for all v of ima.destination
+ | print v.
+
+Sometimes, the number of value cells is much less than the number of
+points. To access the image values, it is more efficient to iterate
+over those cells:
+
+code C)
+ for all v of ima.values
+ | print v.
+
+Consider for instance the following image:
+
++-----+
+| 2 |
+| 111|
+| 22 |
++-----+
+
+The value type is int_u2 (unsigned integer on 2 bit), that is, the
+type of the interval [0,3] of N. The image is defined by a run-length
+encoding with a single value per run. Precisely, this image is:
+
+{ ((a,1),2), ((b,3),1), ((c,2),2) }
+ ^^^ ^
+1st run |
+ value of the 1st run
+
+where a, b, and c designate the respective starting point of each run:
+
++-----+
+| a |
+| b |
+| c |
++-----+
+
+It leads to:
+ code A) 211122 because we browse points
+ code B) 0123 because we browse [0,3]N
+and with :
+ code C) 212 because we browse the image value cells;
+ those cells are depicted below.
+ v v v
+ { ((a,1),2), ((b,3),1), ((c,2),2) }
+
+
+** associated types
+
+mesh (? support)
+pset (? domain_t)
+site
+psite
+
+value
+rvalue
+lvalue
+vset
+
+coord
+dpoint
+
+fwd_piter
+bkd_piter
+
+skeleton
+
+
+** methods
+
+*** values
+
+bool has_data() const
+// FIXME: ? better name is is_allocated Nota bene: is_initialized means "has relevant data"!
+
+const pset& domain() const
+bool has(const psite& p) const
+bool owns_(const psite& p) const
+
+const box_<point>& bbox() const
+std::size_t npoints() const
+
+rvalue operator()(const psite& p) const
+lvalue operator()(const psite& p)
+
+const vset& destination() const // was: values()
+
+
+
+* properties
+
+
+** general
+
+
+*** category
+|
++ -- primary
+|
++ -- /morpher/
+ |
+ + -- identity_morpher
+ |
+ + -- domain_morpher
+ |
+ + -- value_morpher
+
+**** primary
+
+Image type instantiable at the first place (without any prior image
+being defined).
+
+**** morpher
+
+Image type that relies on another image type or on several
+ones; it looks like M<I>. In the following, ima' (of type I') is a
+morpher instance where ima (of type I) is the underlying pre-existing
+image.
+
+**** domain_morpher
+
+A morpher that only changes the definition domain;
+we have ima'.domain != ima.domain but I'::value = I::value and
+for all p in ima'.domain inter ima.domain, ima'(p) = ima(p).
+
+The resulting domain can be larger or smaller than the first one.
+
+FIXME: What about changing only the "extended domain" (via modifying
+the behavior of owns_)?
+
+**** value_morpher
+
+A morpher that only changes the values; we have ima'.domain =
+ima.domain but the function ima' is different from ima because either
+some values change (for some p, ima'(p) != ima(p)) or the type of
+values change.
+
+**** identity_morpher
+
+A morpher that does not change the domain nor the values.
+So ima'.domain = ima.domain and for all p, ima'(p) = ima(p).
+
+
+
+** related to value
+
+
+*** kind
+|
++ -- color
+|
++ -- gray
+|
++ ----------- label
+| |
+| +-- named
++ -- /logic/ |
+| | |
+| + -- /mvlogic/
+| | |
+| | + -- binary
+| | |
+| | + -- ternary
+| |
+| + -- fuzzy
+|
++ -- data
+|
+|
++ -- /map/
+ |
+ + -- distance
+
+FIXME: Apply change on mln.
+IDEA: map or field (for deformation field).
+
+Nota bene: mvlogic stands for "multi-valued logic".
+
+
+*** quant
+|
++ -- low
+|
++ -- high
+
+****
+
+*** value
+|
++ -- scalar
+|
++ -- vectorial
+|
++ -- structed
+|
++ -- pointer
+
+FIXME: Make the difference between homogeneous and heterogeneous
+vectors...
+
+
+
+** related to pset
+
+
+*** access
+|
++ -- random
+|
++ -- browsing
+
+
+*** space
+|
++ -- one_d
+|
++ -- two_d
+|
++ -- three_d
+
+
+*** size
+|
++ -- huge
+|
++ -- regular
+
+
+*** support
+|
++ -- irregular
+|
++ -- regular
+ |
+ + -- aligned
+
+
+** global
+
+
+*** border
+|
++ -- none
+|
++ -- /some/
+ |
+ + -- stored
+ |
+ + -- computed
+
+
+*** neighb
+|
++ -- none
+|
++ -- /some/
+
+
+*** data
+|
++ -- stored
+| |
+| + -- semilinear
+| |
+| + -- oneblock
+|
++ -- computed
+
+Was: stored > linear > raw.
+
+FIXME: What about mmap?
+
+
+*** io
+|
++ ------------------------ /read/
+| | \
+| | + -- read_only
+| |
++ -- /write/ |
+ | \ |
+ | + -- write_only |
+ | |
+ \_________________ |
+ \ |
+ read_write
+
+*** speed
+|
++ -- slow
+|
++ -- fast
+ |
+ + -- fastest
+
+fastest = ( data = oneblock
+ and border = stored
+ and support = aligned
+ and size = regular )
+
+
+* primary images
+
+** image2d<T>
+
+** fun_image<S,F>
+
+pset = S
+f : p -> v
+read_only
+
+
+* value morpher
+
+pset is
\ No newline at end of file
1
0
URL: https://svn.lrde.epita.fr/svn/scool/trunk
ChangeLog:
2008-03-01 Maxime van Noppen <yabo(a)lrde.epita.fr>
Migrate from SCOOP to Milena
* Makefile: Remove.
* pp-cxx-ng: New.
* scoolt-ng: New.
* pp-cxx/CxxProgram.str: Remove any.hh and find_exact.hh from generated code.
* pp-cxx/CxxType.str: Fix typo.
* scoolt/Decl.str: Remove the static stuff.
pp-cxx-ng/CxxDecl.meta | 1
pp-cxx-ng/CxxDecl.str | 90 ++++++++++++++++++
pp-cxx-ng/CxxExp.str | 31 ++++++
pp-cxx-ng/CxxFun.meta | 1
pp-cxx-ng/CxxFun.str | 69 +++++++++++++
pp-cxx-ng/CxxId.meta | 1
pp-cxx-ng/CxxId.str | 12 ++
pp-cxx-ng/CxxProgram.meta | 1
pp-cxx-ng/CxxProgram.str | 15 +++
pp-cxx-ng/CxxStm.meta | 1
pp-cxx-ng/CxxStm.str | 8 +
pp-cxx-ng/CxxType.meta | 1
pp-cxx-ng/CxxType.str | 25 +++++
pp-cxx-ng/Makefile.am | 21 ++++
pp-cxx-ng/pp-cxx.meta | 1
pp-cxx-ng/pp-cxx.str | 6 +
pp-cxx/CxxProgram.str | 5 -
pp-cxx/CxxType.str | 2
scoolt-ng/Access.str | 15 +++
scoolt-ng/Decl.str | 229 ++++++++++++++++++++++++++++++++++++++++++++++
scoolt-ng/Exp.str | 21 ++++
scoolt-ng/Makefile.am | 21 ++++
scoolt-ng/Program.str | 8 +
scoolt-ng/Stm.str | 21 ++++
scoolt-ng/Tools.str | 29 +++++
scoolt-ng/Type.str | 32 ++++++
scoolt-ng/scoolt.str | 184 ++++++++++++++++++++++++++++++++++++
scoolt/Decl.str | 39 +++----
28 files changed, 866 insertions(+), 24 deletions(-)
Index: trunk/src/Makefile (deleted)
===================================================================
Index: trunk/src/pp-cxx/CxxProgram.str
===================================================================
--- trunk/src/pp-cxx/CxxProgram.str (revision 49)
+++ trunk/src/pp-cxx/CxxProgram.str (revision 50)
@@ -8,8 +8,9 @@
CxxProgram(l) ->
V vs=1 [
V vs=0 [
- "#include <stc/any.hh>"
- "#include <stc/find_exact.hh>"
+ // FIXME: includes
+ //"#include <stc/any.hh>"
+ //"#include <stc/find_exact.hh>"
]
V vs=0 [ ~*<map(CxxTopLevelToAbox)> l ]
]
Index: trunk/src/pp-cxx/CxxType.str
===================================================================
--- trunk/src/pp-cxx/CxxType.str (revision 49)
+++ trunk/src/pp-cxx/CxxType.str (revision 50)
@@ -19,7 +19,7 @@
CxxTypeToAbox:
Typename -> S("typename")
- /* These function are actually macros */
+ /* These functions are actually macros */
CxxTypeToAbox:
CxxFunCall(idf, args) -> H hs=0 [ ~<CxxIdToAbox>idf "(" H hs=1 [ ~*<CxxListToAbox(CxxTypeToAbox <+ CxxExpToAbox|",")>args ] ")"]
Index: trunk/src/pp-cxx-ng/CxxProgram.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxProgram.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxProgram.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxDecl.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxDecl.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxDecl.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxFun.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxFun.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxFun.str (revision 50)
@@ -0,0 +1,69 @@
+module CxxFun
+
+imports Cxx Box libstratego-lib CxxType CxxExp CxxStm CxxId
+
+rules
+
+ CxxTopLevelToAbox:
+ CxxFun(params, t, idf, args) ->
+ V vs=0
+ [
+ ~<CxxParamsToAbox> params
+ H hs=0
+ [
+ H hs=1 [ ~<CxxTypeToAbox> t ~<CxxIdToAbox> idf ] "(" H hs=1 [ ~*<CxxListToAbox(CxxArgDefToAbox|",")> args ] ")" ";"
+ ]
+ ]
+
+ CxxTopLevelToAbox:
+ CxxFun(params, t, idf, args, body) ->
+ V vs=0
+ [
+ ~<CxxParamsToAbox> params
+ H hs=0 [
+ H hs=1 [ ~<CxxTypeToAbox>t ~<CxxIdToAbox>idf] "(" H hs=1 [ ~*<CxxListToAbox(CxxArgDefToAbox|",")> args ] ")"
+ ]
+ V vs=0 is=2
+ [
+ "{"
+ ~*<map(CxxStmToAbox <+ CxxTopLevelToAbox)>body
+ ]
+ "}"
+ ]
+
+ CxxTopLevelToAbox:
+ CxxTypedef(t, idf) ->
+ H hs=0 [ H hs=1 [ "typedef" ~<CxxTypeToAbox> t ~S(idf)] ";" ]
+
+ CxxArgDefToAbox:
+ (t, idf) ->
+ H hs = 1
+ [
+ ~<CxxTypeToAbox>t
+ ~<CxxIdToAbox>idf
+ ]
+
+ CxxListToAbox(sub|sep):
+ [e| [h|tail] ] ->
+ [
+ H hs=1 [
+ H hs=0 [
+ ~<sub>e
+ ~S(sep)
+ ]
+ ~<CxxListToAbox(sub|sep)> [h|tail]
+ ]
+ ]
+
+ CxxListToAbox(sub|sep):
+ [e| [] ] ->
+ [
+ H hs=0 [
+ ~<sub>e
+ ]
+ ]
+
+ CxxListToAbox(sub|sep):
+ [] ->
+ [ H [] ]
+
Index: trunk/src/pp-cxx-ng/pp-cxx.str
===================================================================
--- trunk/src/pp-cxx-ng/pp-cxx.str (revision 0)
+++ trunk/src/pp-cxx-ng/pp-cxx.str (revision 50)
@@ -0,0 +1,6 @@
+module pp-cxx
+
+imports Cxx Box libstratego-lib CxxProgram
+
+strategies
+ pp-cxx = io-wrap(CxxProgramToAbox)
Index: trunk/src/pp-cxx-ng/CxxId.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxId.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxId.str (revision 50)
@@ -0,0 +1,12 @@
+module CxxId
+
+imports Cxx Box libstratego-lib
+
+rules
+
+ CxxIdToAbox:
+ x -> S(x)
+ where not(<?CxxScope(_, _)> x)
+
+ CxxIdToAbox:
+ CxxScope(idf1, idf2) -> H hs=0 [ ~<CxxIdToAbox>idf1 "::" ~<CxxIdToAbox>idf2 ]
Index: trunk/src/pp-cxx-ng/CxxExp.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxExp.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxExp.str (revision 50)
@@ -0,0 +1,31 @@
+module CxxExp
+
+imports Cxx Box libstratego-lib CxxId
+
+rules
+
+ CxxExpToAbox:
+ CxxInt(i) -> S(i)
+
+ CxxExpToStr:
+ CxxInt(i) -> i
+
+ CxxExpToStr:
+ CxxSum(e1, e2) -> <concat-strings> [<CxxExpToStr> e1, " + ", <CxxExpToStr> e2]
+
+ CxxExpToStr:
+ x -> x
+ where <is-string> x
+
+ /*
+ * Handle the CxxKeyword ctor.
+ * TODO: Generalize the type of exp.
+ */
+ CxxExpToAbox:
+ CxxKeyword(idf, exp) -> S(<concat-strings> [idf, " ", <CxxExpToStr> exp, ";"])
+
+ CxxExpToAbox:
+ CxxAffect(idf, exp) -> S(<concat-strings> [idf, " = ", <CxxExpToStr> exp, ";"])
+
+ CxxExpToAbox:
+ x -> S(x)
Index: trunk/src/pp-cxx-ng/CxxType.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxType.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxType.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxStm.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxStm.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxStm.str (revision 50)
@@ -0,0 +1,8 @@
+module CxxStm
+
+imports Cxx Box libstratego-lib CxxType CxxExp CxxId
+
+rules
+
+ CxxStmToAbox:
+ CxxExpStm(e) -> <CxxExpToAbox> e
Index: trunk/src/pp-cxx-ng/CxxFun.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxFun.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxFun.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxProgram.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxProgram.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxProgram.str (revision 50)
@@ -0,0 +1,15 @@
+module CxxProgram
+
+imports Cxx Box libstratego-lib CxxDecl CxxFun
+
+rules
+
+ CxxProgramToAbox:
+ CxxProgram(l) ->
+ V vs=1 [
+ V vs=0 [
+ "#include <stc/any.hh>"
+ "#include <stc/find_exact.hh>"
+ ]
+ V vs=0 [ ~*<map(CxxTopLevelToAbox)> l ]
+ ]
Index: trunk/src/pp-cxx-ng/CxxDecl.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxDecl.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxDecl.str (revision 50)
@@ -0,0 +1,90 @@
+module CxxDecl
+
+imports Cxx Box libstratego-lib CxxType CxxExp CxxId
+
+rules
+
+ CxxTopLevelToAbox:
+ l ->
+ V vs=1 [
+ ~*<map(CxxTopLevelToAbox)>l
+ ]
+
+ CxxTopLevelToAbox:
+ CxxDecl(t, idf) -> H hs=0 [ H hs=1 [ ~<CxxTypeToAbox>t ~<CxxIdToAbox>idf ] ";"]
+
+ CxxTopLevelToAbox:
+ CxxDecl(t, idf, v) -> H hs=0 [ H hs=1 [ ~<CxxTypeToAbox>t ~<CxxIdToAbox>idf "=" ~<CxxExpToAbox> v] ";"]
+
+ CxxTopLevelToAbox:
+ CxxArrayDecl(t, idf, n) -> H hs=0 [ H hs=1 [ ~<CxxTypeToAbox> t ~<CxxIdToAbox> idf] "[" ~<CxxExpToAbox> n "]" ";" ]
+
+ CxxTopLevelToAbox:
+ CxxClassDecl(params, idf, parents) ->
+ V vs=0 [
+ ~<CxxParamsToAbox> params
+ H hs=0 [
+ H hs=1 [ "class" ~<CxxIdToAbox>idf ]
+ ~<CxxParentsToAbox>parents
+ ";"
+ ]
+ ]
+
+ CxxTopLevelToAbox:
+ CxxClassDecl(params, idf, parents) ->
+ V vs=0 [
+ ~<CxxParamsToAbox> params
+ H hs=0 [
+ H hs=1 [ "class" ~<CxxIdToAbox>idf ]
+ ~<CxxParentsToAbox>parents
+ ";"
+ ]
+ ]
+
+ CxxTopLevelToAbox:
+ CxxComment(txt) ->
+ H hs=1 [ "//" ~S(txt) ]
+
+// FIXME: MERGE!!!
+
+ CxxBodyToAbox:
+ CxxPublic(b) -> V is=2 [ "public:" V [ ~*<map(CxxTopLevelToAbox)> b ] ]
+
+ CxxBodyToAbox:
+ CxxProtected(b) -> V is=2 [ "private:" V [ ~*<map(CxxTopLevelToAbox)> b ] ]
+
+ CxxBodyToAbox:
+ CxxPrivate(b) -> V is=2 [ "private:" V [ ~*<map(CxxTopLevelToAbox)> b ] ]
+
+ CxxTopLevelToAbox:
+ CxxClassDecl(params, idf, parents, body) ->
+ V vs=0 [
+ ~<CxxParamsToAbox> params
+ H hs=0 [
+ H hs=1 [ "class" ~<CxxIdToAbox> idf ]
+ ~<CxxParentsToAbox> parents
+ ]
+ V vs=0 is=2 [ "{" V vs=1 [ ~*<map (CxxBodyToAbox)> body ] ]
+ H hs=0 [ "}" ";" ]
+ ]
+
+ CxxParamsToAbox:
+ [] -> H []
+
+ CxxParamsToAbox:
+ params -> H hs=1 [ "template" "<" ~<CxxListToAbox(CxxParamToAbox|",")> params ">" ]
+ where not(<?[]> params)
+
+ CxxParamToAbox:
+ (t, idf) -> H hs = 1 [ ~<CxxTypeToAbox> t ~<CxxIdToAbox> idf ]
+
+ CxxParentsToAbox:
+ [] -> H []
+
+ CxxParentsToAbox:
+ parents -> H hs=1 [ ":" ~<CxxListToAbox(CxxParentToAbox|",")>parents ]
+ where not(<?[]> parents)
+
+ CxxParentToAbox:
+ (modifier, t) ->
+ H hs=1 [ ~S(modifier) ~<CxxTypeToAbox>t ]
Index: trunk/src/pp-cxx-ng/pp-cxx.meta
===================================================================
--- trunk/src/pp-cxx-ng/pp-cxx.meta (revision 0)
+++ trunk/src/pp-cxx-ng/pp-cxx.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxId.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxId.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxId.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/Makefile.am
===================================================================
--- trunk/src/pp-cxx-ng/Makefile.am (revision 0)
+++ trunk/src/pp-cxx-ng/Makefile.am (revision 50)
@@ -0,0 +1,21 @@
+# Makefile.am -*-Makefile-*-
+
+MODULES = pp-cxx
+
+include $(top_srcdir)/config/Makefile.xt
+-include $(MODULES:=.c.dep)
+
+SCFLAGS = --main $* --verbose 0
+STRINCLUDES = -I $(top_builddir)/src/scl-syn \
+ -I $(top_builddir)/src/cxx-syn \
+ -I `dirname \`xtc get Stratego-Box.tbl\`` \
+ -I $(srcdir) \
+ -la stratego-lib
+
+libexec_PROGRAMS = pp-cxx
+
+nodist_pp_cxx_SOURCES = pp-cxx.c
+
+EXTRA_DIST = $(MODULES:=.str)
+
+CLEANFILES = $(MODULES:=.c) $(MODULES:=.c.dep)
Index: trunk/src/pp-cxx-ng/CxxType.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxType.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxType.str (revision 50)
@@ -0,0 +1,25 @@
+module CxxType
+
+imports Cxx Box libstratego-lib CxxId
+
+rules
+
+ CxxTypeToAbox:
+ CxxType(idf) -> <CxxIdToAbox> idf
+
+ CxxTypeToAbox:
+ CxxRefType(t) -> H hs=0 [ ~<CxxTypeToAbox> t "&" ]
+
+ CxxTypeToAbox:
+ CxxType(idf, params) -> H hs=0 [ ~<CxxIdToAbox> idf "<" ~<CxxListToAbox(CxxTypeToAbox|",")> params ">" ]
+
+ CxxTypeToAbox:
+ CxxConstType(t) -> H [ "const" ~<CxxTypeToAbox> t]
+
+ CxxTypeToAbox:
+ Typename -> S("typename")
+
+ /* These function are actually macros */
+
+ CxxTypeToAbox:
+ CxxFunCall(idf, args) -> H hs=0 [ ~<CxxIdToAbox>idf "(" H hs=1 [ ~*<CxxListToAbox(CxxTypeToAbox <+ CxxExpToAbox|",")>args ] ")"]
Index: trunk/src/pp-cxx-ng/CxxStm.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxStm.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxStm.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/scoolt/Tools.str
===================================================================
Index: trunk/src/scoolt/Decl.str
===================================================================
--- trunk/src/scoolt/Decl.str (revision 49)
+++ trunk/src/scoolt/Decl.str (revision 50)
@@ -79,10 +79,9 @@
ConstDec([], idf, cs, Class) ->
CxxClassDecl(
[(Typename, "T")],
- nidf,
+ idf,
[]
)
- where <conc-strings> (idf, "_") => nidf
/*
* Root Class declaration
@@ -90,23 +89,24 @@
*/
DeclToCxx:
ConstDec(specs, idf, Class, ClassVal(v)) ->
- <try(AddTypedef(|specs, idf)); AddClassComment(|idf)>
+ <AddClassComment(|idf)>
[
CxxClassDecl(
- [(Typename, "T")],
- nidf,
+ [(Typename, "E")],
+ idf,
[
- (
+ /*(
"public",
CxxType(CxxScope("stc", "any"), [CxxFunCall("stc_find_exact", [CxxType(nidf), CxxType("T")])])
- )
+ )*/
+ // FIXME: Add a way to specify if a root class should inherit from Object or not
],
<map (AccessToCxx)> v
//[]
)
]
- where <SclNewIdf>idf => nidf
- ; rules(CxxTypeToStc(|T): CxxType(idf) -> CxxType(<SclNewIdf>idf, [T]))
+ where
+ rules(AddTemplate(|T): CxxType(idf) -> CxxType(idf, [T]))
/*
* Final Class declaration
@@ -114,11 +114,11 @@
*/
DeclToCxx:
ConstDec(specs, idf, Class(p), v) ->
- <try(AddTypedef(|specs, idf)); AddClassComment(|idf)>
+ <AddClassComment(|idf)>
[
CxxClassDecl(
params,
- nidf,
+ idf,
[
(
"public",
@@ -132,24 +132,21 @@
; if
(
<one(?"final")> specs
- ; !idf => nidf
- ; <CxxTypeToStc(|CxxType(idf))>cxxp => parent
- )
- <+ (
- <SclNewIdf>idf => nidf
- ; <CxxTypeToStc(|CxxFunCall("stc_find_exact", [CxxType(nidf), CxxType("T")]))>cxxp => parent
+ ; <AddTemplate(|CxxType(idf))> cxxp => parent
)
+ <+
+ <AddTemplate(|CxxType("E"))> cxxp => parent
then
if <one(?"final")> specs then
- rules(CxxTypeToStcError: CxxType(idf) -> <concat-strings> [idf, " is final."])
+ rules(IsFinal: CxxType(idf) -> <concat-strings> [idf, " is final."])
; ![] => params
else
- rules(CxxTypeToStc(|T): CxxType(idf) -> CxxType(<SclNewIdf> idf, [T]))
- ; ![(Typename, "T")] => params
+ rules(AddTemplate(|T): CxxType(idf) -> CxxType(idf, [T]))
+ ; ![(Typename, "E")] => params
end
else
say(!<concat-strings> [idf, " cannot inherit from ", <CxxTypeToIdf> cxxp])
- ; if <CxxTypeToStcError> cxxp => error then
+ ; if <IsFinal> cxxp => error then
say(!error)
else
say(!<concat-strings> [<CxxTypeToIdf>cxxp, " does not exist."])
Index: trunk/src/scoolt-ng/Exp.str
===================================================================
--- trunk/src/scoolt-ng/Exp.str (revision 0)
+++ trunk/src/scoolt-ng/Exp.str (revision 50)
@@ -0,0 +1,21 @@
+module Exp
+
+imports libstratego-lib Cxx AsFix Scool
+
+rules
+
+ ExpToCxx:
+ Int(i) -> CxxInt(i)
+
+ ExpToCxx:
+ Var(v) -> v
+
+ ExpToCxx:
+ Sum(e1, e2) -> CxxSum(<ExpToCxx> e1, <ExpToCxx> e2)
+
+ ExpToCxx:
+ Affect(Var(v), e) -> CxxAffect(v, <ExpToCxx> e)
+ where <debug> e
+
+ ExpToCxx:
+ Cxx(s) -> s
Index: trunk/src/scoolt-ng/Tools.str
===================================================================
--- trunk/src/scoolt-ng/Tools.str (revision 0)
+++ trunk/src/scoolt-ng/Tools.str (revision 50)
@@ -0,0 +1,29 @@
+module Tools
+
+imports libstratego-lib Cxx AsFix Scool
+
+rules
+
+ SclNewIdf:
+ idf -> <conc-strings> (idf, "_")
+
+ CxxTypeToIdf:
+ CxxType(idf) -> idf
+ where <is-string> idf
+
+strategies
+
+ NewCount =
+ rules(count_:- _)
+
+ Count =
+ if count_ => res then
+ rules(count_:- _)
+ ; rules(count_: _ -> <sum> (res, 1))
+ else
+ rules(count_: _ -> 1)
+ end
+ ; count_
+
+ GetCount =
+ count_ <+ !0
Index: trunk/src/scoolt-ng/Access.str
===================================================================
--- trunk/src/scoolt-ng/Access.str (revision 0)
+++ trunk/src/scoolt-ng/Access.str (revision 50)
@@ -0,0 +1,15 @@
+module Access
+
+imports libstratego-lib Cxx Type Exp Stm Tools AsFix Scool
+
+rules
+
+ AccessToCxx:
+ Accessblock(Public, l) -> CxxPublic(<map (DeclToCxx)> l)
+
+ AccessToCxx:
+ Accessblock(Private, l) -> CxxPrivate(<map (DeclToCxx)> l)
+
+ AccessToCxx:
+ Accessblock(Protected, l) -> CxxProtected(<map (DeclToCxx)> l)
+
Index: trunk/src/scoolt-ng/Type.str
===================================================================
--- trunk/src/scoolt-ng/Type.str (revision 0)
+++ trunk/src/scoolt-ng/Type.str (revision 50)
@@ -0,0 +1,32 @@
+module Type
+
+imports libstratego-lib Cxx AsFix Scool
+
+rules
+
+ IsScalar:
+ t -> t
+ where
+ (
+ <eq> (t, "char")
+ <+ <eq> (t, "bool")
+ <+ <eq> (t, "short")
+ <+ <eq> (t, "int")
+ <+ <eq> (t, "float")
+ <+ <eq> (t, "double")
+ )
+
+ TypeToCxx:
+ Var(x) -> CxxType(x)
+
+ TypeToCxx:
+ RefType(t) -> CxxRefType(<TypeToCxx> t)
+
+ // Constify + Referencify a type
+ TypeToConstRefCxx:
+ Var(t) -> CxxConstType(CxxRefType(CxxType(t)))
+ where
+ (
+ <is-string> t
+ ; <not (IsScalar)> t
+ )
Index: trunk/src/scoolt-ng/Makefile.am
===================================================================
--- trunk/src/scoolt-ng/Makefile.am (revision 0)
+++ trunk/src/scoolt-ng/Makefile.am (revision 50)
@@ -0,0 +1,21 @@
+# Makefile.am -*-Makefile-*-
+
+MODULES = scoolt
+
+include $(top_srcdir)/config/Makefile.xt
+-include $(MODULES:=.c.dep)
+
+SCFLAGS = --main $* --verbose 0 --asfix
+STRINCLUDES = -I $(top_builddir)/src/scl-syn \
+ -I $(top_builddir)/src/cxx-syn \
+ -I `dirname \`xtc get Stratego-Box.tbl\`` \
+ -I $(srcdir) \
+ -la stratego-lib
+
+libexec_PROGRAMS = scoolt
+
+nodist_scoolt_SOURCES = scoolt.c
+
+EXTRA_DIST = $(MODULES:=.str)
+
+CLEANFILES = $(MODULES:=.c) $(MODULES:=.c.dep)
Index: trunk/src/scoolt-ng/Stm.str
===================================================================
--- trunk/src/scoolt-ng/Stm.str (revision 0)
+++ trunk/src/scoolt-ng/Stm.str (revision 50)
@@ -0,0 +1,21 @@
+module Stm
+
+imports libstratego-lib Cxx Type Exp AsFix Scool
+
+rules
+
+ StmToCxx:
+ ExpStm(e) -> CxxExpStm(<ExpToCxx> e)
+ where <debug> e
+
+ /* Handle the 'return' statement */
+ StmToCxx:
+ Return(e) -> CxxExpStm(CxxKeyword("return", <ExpToCxx> e))
+
+ StmToCxx:
+ VarDec([], idf, t, i) -> <DeclToCxx> VarDec([], idf, t, i)
+ where <debug> idf
+
+ StmToCxx:
+ x -> <DeclToCxx> x
+ where <debug> x
Index: trunk/src/scoolt-ng/scoolt.str
===================================================================
--- trunk/src/scoolt-ng/scoolt.str (revision 0)
+++ trunk/src/scoolt-ng/scoolt.str (revision 50)
@@ -0,0 +1,184 @@
+module scoolt
+
+imports libstratego-lib Cxx Program AsFix Scool
+
+strategies
+
+ scoolt = io-wrap(ProgramToCxx)
+
+
+
+/*
+ t-Program:
+ Program(l) -> Cxx(<collect-vtypes> l, <map(t-Decl)> l)
+
+
+
+ t-Decl:
+ VarDec(i, t) -> CxxVarDec(<t-Type> t, i)
+ where not(<?Var("type")> t)
+
+ t-Decl:
+ VarDec(i, t, v) -> CxxVarDec(<t-Type> t, i, <t-Exp> v)
+ where not(<?Var("type")> t)
+
+ t-Decl:
+ ConsDec(_, i, t) -> CxxVarDec(CxxConsType(<t-Type> t), i)
+ where not(<?Var("type")> t)
+
+ t-Decl:
+ ConsDec(_, i, t, v) -> CxxVarDec(CxxConsType(<t-Type> t), i, <t-Exp> v)
+ where not(<?Var("type")> t)
+
+
+
+
+ t-Decl:
+ ConsDec(_, i, t) -> CxxEscape(<concat-strings> ["/", "/ virtual typedef /abstract/ ", i, ";"] )
+ where <?Var("type")> t
+
+ t-Decl: // FIXME : vvvvvv
+ ConsDec(_, i, t, Var(v)) -> CxxEscape(<concat-strings> ["/", "/ virtual typedef ", v, " ", i, ";"] )
+ where <?Var("type")> t
+
+
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class, ClassVal(l)) -> [CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic, CxxTemplateType(CxxScope("stc", "any"), "E"), <map(t-ABlock)> l), CxxTypedef(CxxTemplateType(newname, "itself"), name)] where <conc-strings> (name, "_") => newname
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class(parent), ClassVal(l)) -> [CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic, CxxTemplateType(<t-r-Type> parent, "E"), <map(t-ABlock)> l), CxxTypedef(CxxTemplateType(newname, "itself"), name)] where <conc-strings> (name, "_") => newname; <not(one(?"final"))> qualifiers
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class(parent)) -> [CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic, CxxTemplateType(<t-r-Type> parent, "E"), []), CxxTypedef(CxxTemplateType(newname, "itself"), name)] where <conc-strings> (name, "_") => newname; <not(one(?"final"))> qualifiers
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class) -> [CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic, CxxTemplateType(CxxScope("stc", "any"), "E"), []), CxxTypedef(CxxTemplateType(newname, "itself"), name)] where <conc-strings> (name, "_") => newname
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class(parent), ClassVal(l)) -> [CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic, CxxTemplateType(<t-r-Type> parent, "E"), <map(t-ABlock)> l), CxxTypedef(CxxTemplateType(newname, "itself"), name)] where <conc-strings> (name, "_") => newname
+
+
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class(parent), ClassVal(l)) ->
+ [CxxClassDec (
+ newname,
+ CxxPublic,
+ CxxTemplateType(<t-r-Type> parent, newname),
+ <map(t-ABlock)> l
+ ),
+ CxxTypedef(newname, name)
+ ]
+ where <conc-strings> (name, "_") => newname; <one(?"final")> qualifiers
+
+ t-ABlock:
+ Accessblock(acc, decs) -> CxxAccessBlock(<t-ASpecifier> acc, <map(t-Decl)> decs)
+
+ t-ASpecifier:
+ Public -> CxxPublic
+
+ t-ASpecifier:
+ Private -> CxxPrivate
+
+ t-Decl:
+ FunDec(_, name, args, ret, body) -> CxxFunDec(<t-Type> ret, name, <map(t-Arg)> args, <map(t-Stm + t-Decl)> body)
+
+
+ t-Decl:
+ BiFunDec(qualifiers, name, s-args, args, rettype, body) ->
+ CxxOverloadingCase( name,
+ CxxInt(index),
+ <t-StaticCond>s-args,
+ <t-Type>rettype,
+ <map(t-Arg)>args,
+ <map(t-Stm + t-Decl)>body
+ )
+ where
+ <one(?"overloading")> qualifiers
+ ; if not(<index-over> name) then
+// say(!"first"); debug
+ !1 => index
+ ; rules(index-over: name -> 2)
+ else
+// say(!"not first"); debug
+ <index-over> name => index
+ ; rules(index-over: name -> <add>(index, 1))
+ end
+
+
+
+ t-Arg:
+ (name, type, guard) -> <t-Arg> (name, type)
+
+ t-Arg:
+ (name, type) -> (<t-Type> type, name)
+
+
+
+ t-Type:
+ Var(n) -> n
+
+ t-r-Type:
+ Var(n) -> <conc-strings> (n, "_")
+
+ t-Exp:
+ Int(n) -> CxxInt(n)
+
+ t-Exp:
+ Mul(e1, e2) -> CxxMul(<t-Exp> e1, <t-Exp> e2)
+
+ t-Exp:
+ Var(n) -> CxxVar(n)
+
+ t-Exp:
+ Cpp(cxx) -> CxxEscape(cxx)
+
+ t-Stm:
+ Return(e) -> CxxReturn(<t-Exp> e)
+
+ t-Decl:
+ Cpp(cxx) -> CxxEscape(cxx)
+
+ t-StaticCond:
+ [] -> CxxStaticTrue
+
+ t-StaticCond:
+ [h|[]] -> <t-StaticCond> h
+
+ t-StaticCond:
+ [h|t] -> CxxStaticAnd(<t-StaticCond> h, <t-StaticCond> t)
+ where not(<?[]>t)
+
+ t-StaticCond:
+ (idf, type, Guard(guard)) -> <t-StaticCond> guard
+
+ t-StaticCond:
+ (idf, type) -> CxxStaticTrue
+
+ t-StaticCond:
+ Eq(e1, e2) -> CxxStaticEq(<t-Type> e1, <t-Type> e2)
+
+ t-StaticCond:
+ Or(e1, e2) -> CxxStaticOr(<t-StaticCond> e1, <t-StaticCond> e2)
+
+ t-StaticCond:
+ Inf(e1, e2) -> CxxStaticIsA(<t-Type> e1, <t-Type> e2)
+
+ t-StaticCond:
+ Var("true") -> CxxStaticTrue
+
+ t-StaticCond:
+ Var("false") -> CxxStaticFalse
+
+
+
+ strategies
+
+ collect-vtypes =
+ collect(?ConsDec(attr, _, Var("type")); where (<one(?"decl")> attr) )
+ ; map(?ConsDec(_, <id>, _))
+ ; make-set
+
+
+*/
Index: trunk/src/scoolt-ng/Decl.str
===================================================================
--- trunk/src/scoolt-ng/Decl.str (revision 0)
+++ trunk/src/scoolt-ng/Decl.str (revision 50)
@@ -0,0 +1,229 @@
+module Decl
+
+imports libstratego-lib Cxx Type Exp Stm Tools AsFix Scool Access
+
+rules
+
+ /*
+ * Variable declaration.
+ * Grammar: "var" idf ":" t ";"
+ */
+ DeclToCxx:
+ VarDec([], idf, t) -> CxxDecl(<TypeToCxx> t, idf)
+
+ /*
+ * Array declaration.
+ * Grammar: "var" idf ":" "array" "[" t "," n "]" ";"
+ */
+ DeclToCxx:
+ VarDec([], idf, StaticFunCall(st, [t, n])) ->
+ <if <eq> ("array", st) then
+ ! CxxArrayDecl(<TypeToCxx> t, idf, <ExpToCxx> n)
+ else
+ say(<concat-strings> ["Unkown construction: ", st])
+ ; <exit> 1
+ end>
+
+ /*
+ * Buffer declaration.
+ * Grammar: "var" idf ":" "buffer" "[" t "]" ";"
+ */
+ DeclToCxx:
+ VarDec([], idf, StaticFunCall(st, [t])) ->
+ <if <eq> ("buffer", st) then
+ ! CxxDecl(CxxType(CxxScope("std", "vector"), [<TypeToCxx> t]), idf)
+ else
+ say(<concat-strings> ["Unkown construction: ", st])
+ ; <exit> 1
+ end>
+
+ /*
+ * Variable declaration with initialisation.
+ * Grammar: "var" idf ":" t ":=" v ";"
+ */
+ DeclToCxx:
+ VarDec([], idf, t, v) -> CxxDecl(<TypeToCxx> t, idf, <ExpToCxx> v)
+
+ UnVar:
+ Var(x) -> x
+
+ /*
+ * Constant declaration.
+ * Grammar: idf ":" t ";"
+ */
+ DeclToCxx:
+ ConstDec([], idf, cs, t) ->
+ <if <eq> ("type", <UnVar> t) then
+ ! CxxDecl(<TypeToCxx> t, idf)
+ else
+ ! CxxDecl(CxxConstType(<TypeToCxx> t), idf)
+ end>
+ where not(<?Class> t)
+
+ /*
+ * Constant declaration with initialisation.
+ * Grammar: idf ":" t "=" v ";"
+ */
+ DeclToCxx:
+ ConstDec([], idf, t, v) -> CxxDecl(CxxConstType(<TypeToCxx> t), idf, <ExpToCxx> v)
+ where not(<?Class> t)
+
+ DeclToCxx:
+ ConstDec(["decl"], idf, cs, FunType(args, ret)) -> CxxFun([], <TypeToCxx> ret, idf, <map (ArgDefToCxx)> args)
+
+ /*
+ * Root Class predeclaration
+ * Grammar: idf ":" "class" ";"
+ */
+ DeclToCxx:
+ ConstDec([], idf, cs, Class) ->
+ CxxClassDecl(
+ [(Typename, "T")],
+ nidf,
+ []
+ )
+ where <conc-strings> (idf, "_") => nidf
+
+ /*
+ * Root Class declaration
+ * Grammar: specs idf ":" "class" "=" "{" v "}" ";"
+ */
+ DeclToCxx:
+ ConstDec(specs, idf, Class, ClassVal(v)) ->
+ <try(AddTypedef(|specs, idf)); AddClassComment(|idf)>
+ [
+ CxxClassDecl(
+ [(Typename, "T")],
+ nidf,
+ [
+ (
+ "public",
+ CxxType(CxxScope("stc", "any"), [CxxFunCall("stc_find_exact", [CxxType(nidf), CxxType("T")])])
+ )
+ ],
+ <map (AccessToCxx)> v
+ //[]
+ )
+ ]
+ where <SclNewIdf>idf => nidf
+ ; rules(CxxTypeToStc(|T): CxxType(idf) -> CxxType(<SclNewIdf>idf, [T]))
+
+ /*
+ * Final Class declaration
+ * Grammar: final idf ":" "class" "=" "{" v "}" ";"
+ */
+ DeclToCxx:
+ ConstDec(specs, idf, Class(p), v) ->
+ <try(AddTypedef(|specs, idf)); AddClassComment(|idf)>
+ [
+ CxxClassDecl(
+ params,
+ nidf,
+ [
+ (
+ "public",
+ parent
+ )
+ ],
+ [] // fixme
+ )
+ ]
+ where <TypeToCxx> p => cxxp
+ ; if
+ (
+ <one(?"final")> specs
+ ; !idf => nidf
+ ; <CxxTypeToStc(|CxxType(idf))>cxxp => parent
+ )
+ <+ (
+ <SclNewIdf>idf => nidf
+ ; <CxxTypeToStc(|CxxFunCall("stc_find_exact", [CxxType(nidf), CxxType("T")]))>cxxp => parent
+ )
+ then
+ if <one(?"final")> specs then
+ rules(CxxTypeToStcError: CxxType(idf) -> <concat-strings> [idf, " is final."])
+ ; ![] => params
+ else
+ rules(CxxTypeToStc(|T): CxxType(idf) -> CxxType(<SclNewIdf> idf, [T]))
+ ; ![(Typename, "T")] => params
+ end
+ else
+ say(!<concat-strings> [idf, " cannot inherit from ", <CxxTypeToIdf> cxxp])
+ ; if <CxxTypeToStcError> cxxp => error then
+ say(!error)
+ else
+ say(!<concat-strings> [<CxxTypeToIdf>cxxp, " does not exist."])
+ end
+ end
+
+ /*
+ * Handle class declarations with inheritance
+ * Grammar: idf ":" "class" "<" parent ";"
+ */
+ DeclToCxx:
+ ConstDec([], idf, cs, Class(parent)) -> CxxClassDecl([], idf, [("public", <TypeToCxx> parent)])
+ where <conc-strings> (idf, "_") => nidf
+
+ /*
+ * Handle functions
+ * Grammar: idf ":" "(" args ")" "->" t "=" "{" body "}"
+ * TODO: Handle templates
+ */
+ DeclToCxx:
+ FunDec([], idf, args, t, body) -> CxxFun([], <TypeToCxx> t, idf, <map(ArgDefToCxx)> args, <map(StmToCxx)> body)
+ //where <debug> body
+ //FunDec([], idf, args, t, body) -> <AddParameters(|<GetCount> 0)> CxxFun([], <TypeToCxx> t, idf, nargs, <map(StmToCxx)>body)
+ //where <NewCount; map(ArgDefToCxx)>args => nargs
+ /*
+ * Handle functions
+ * Grammar: idf ":" "(" args ")" "->" t "=>" Exp
+ * TODO: Handle templates
+ */
+ DeclToCxx:
+ FunDec([], idf, args, t, ExpStm(body)) -> CxxFun([], <TypeToCxx> t, idf, <map(ArgDefToCxx)> args, [<StmToCxx> Return(body)])
+ //where <debug> body
+
+ DeclToCxx:
+ StaticFunDec(l, idf, params, Class(), body) -> CxxClassDecl(<map (ParamToCxx)> params, idf, [], <map (AccessToCxx)> body)
+
+ DeclToCxx:
+ BiFunDec(l, idf, params, args, t, body) -> CxxFun(<map (ParamToCxx)> params, <TypeToCxx> t, idf, <map (ArgDefToCxx)> args, <map (StmToCxx)> body)
+
+ DeclToCxx:
+ BiFunDec(l, idf, params, args, t, ExpStm(body)) -> CxxFun(<map (ParamToCxx)> params, <TypeToCxx> t, idf, <map (ArgDefToCxx)> args, [<StmToCxx> Return(body)])
+
+ ParamToCxx:
+ (idf, Var(t), wclause) ->
+ <if <eq> (t, "type") then
+ ! (CxxType("class"), idf)
+ else
+ ! (CxxType(t), idf)
+ end>
+
+ ArgDefToCxx:
+ (idf, t) -> (<TypeToConstRefCxx <+ TypeToCxx> t, idf)
+ //(idf, t) -> (<TypeToCxx; try(CxxTypeToStc(|CxxType(p-idf)))> t, idf)
+ //where <concat-strings; SclNewIdf> ["T", <Count; int-to-string> 0] => p-idf
+
+ ArgDefToCxx:
+ FunArg(idf, t) -> <ArgDefToCxx> (idf, t)
+
+ AddTypedef(|specs, idf):
+ [x] -> [x, CxxTypedef(CxxType(<SclNewIdf>idf, [CxxType(CxxScope("stc", "itself"))]), idf)]
+ where <not(one(?"abstract"))> specs
+
+ AddClassComment(|idf):
+ l -> [CxxComment(<concat-strings> ["Class ", idf])|l]
+
+ AddParameters(|n):
+ CxxFun(p, t, idf, args, body) -> CxxFun(<Parameters(|n)> p, t, idf, args, body)
+ //where <debug> n
+
+ Parameters(|n):
+ l -> <Parameters(|<subt>(n, 1))>[(Typename, idf)|l]
+ where <not(?0)> n
+ ; <concat-strings; SclNewIdf> ["T", <int-to-string> n] => idf
+
+ Parameters(|n):
+ l -> l
+ where <?0> n
Index: trunk/src/scoolt-ng/Program.str
===================================================================
--- trunk/src/scoolt-ng/Program.str (revision 0)
+++ trunk/src/scoolt-ng/Program.str (revision 50)
@@ -0,0 +1,8 @@
+module Program
+
+imports libstratego-lib Cxx Decl AsFix Scool
+
+rules
+
+ ProgramToCxx:
+ Program(l) -> CxxProgram(<map(DeclToCxx)> l)
--
\__/ \__/
(00) Maxime `yabo` van Noppen (00)
___) \ Epita 2009 / (___
(_____/ Président de Prologin \_____)
1
0