URL:
https://svn.lrde.epita.fr/svn/scool/trunk
ChangeLog:
2008-03-26 Maxime van Noppen <yabo(a)lrde.epita.fr>
Work on concepts
* src/pp-cxx/CxxFun.str: Pretty-print C++ constructors correctly.
* src/pp-cxx/CxxDecl.str: Fix bug in access blocks pretty-print.
* src/pp-cxx/CxxType.str: Remove useless comment.
* src/scoolt/Concept.str: New.
* src/scoolt/Decl.str: Handle Concept constructor.
pp-cxx/CxxDecl.str | 4 ++--
pp-cxx/CxxFun.str | 11 +++++++++++
pp-cxx/CxxType.str | 2 --
scoolt/Concept.str | 34 ++++++++++++++++++++++++++++++++++
scoolt/Decl.str | 19 +++++++++++++++++--
5 files changed, 64 insertions(+), 6 deletions(-)
Index: trunk/src/pp-cxx/CxxFun.str
===================================================================
--- trunk/src/pp-cxx/CxxFun.str (revision 55)
+++ trunk/src/pp-cxx/CxxFun.str (revision 56)
@@ -16,6 +16,17 @@
]
CxxTopLevelToAbox:
+ CxxFun(params, None(), idf, args) ->
+ V vs=0
+ [
+ ~<CxxParamsToAbox> params
+ H hs=0
+ [
+ H hs=1 [ ~<CxxIdToAbox> idf ] "(" H hs=1 [
~*<CxxListToAbox(CxxArgDefToAbox|",")> args ] ")" ";"
+ ]
+ ]
+
+ CxxTopLevelToAbox:
CxxFun(params, t, idf, args, body) ->
V vs=0
[
Index: trunk/src/pp-cxx/CxxDecl.str
===================================================================
--- trunk/src/pp-cxx/CxxDecl.str (revision 55)
+++ trunk/src/pp-cxx/CxxDecl.str (revision 56)
@@ -49,7 +49,7 @@
CxxPublic(b) -> V is=2 [ "public:" V [ ~*<map(CxxTopLevelToAbox)> b
] ]
CxxBodyToAbox:
- CxxProtected(b) -> V is=2 [ "private:" V [
~*<map(CxxTopLevelToAbox)> b ] ]
+ CxxProtected(b) -> V is=2 [ "protected:" V [
~*<map(CxxTopLevelToAbox)> b ] ]
CxxBodyToAbox:
CxxPrivate(b) -> V is=2 [ "private:" V [ ~*<map(CxxTopLevelToAbox)>
b ] ]
@@ -62,7 +62,7 @@
H hs=1 [ "class" ~<CxxIdToAbox> idf ]
~<CxxParentsToAbox> parents
]
- V vs=0 is=2 [ "{" V vs=1 [ ~*<map (CxxBodyToAbox)> body ] ]
+ V vs=0 is=2 [ "{" V vs=0 [ ~*<map (CxxBodyToAbox <+
CxxTopLevelToAbox)> body ] ]
H hs=0 [ "}" ";" ]
]
Index: trunk/src/pp-cxx/CxxType.str
===================================================================
--- trunk/src/pp-cxx/CxxType.str (revision 55)
+++ trunk/src/pp-cxx/CxxType.str (revision 56)
@@ -19,7 +19,5 @@
CxxTypeToAbox:
Typename -> S("typename")
- /* These functions are actually macros */
-
CxxTypeToAbox:
CxxFunCall(idf, args) -> H hs=0 [ ~<CxxIdToAbox>idf "(" H hs=1 [
~*<CxxListToAbox(CxxTypeToAbox <+ CxxExpToAbox|",")>args ]
")"]
Index: trunk/src/scoolt/Concept.str
===================================================================
--- trunk/src/scoolt/Concept.str (revision 0)
+++ trunk/src/scoolt/Concept.str (revision 56)
@@ -0,0 +1,34 @@
+module Concept
+
+imports libstratego-lib Cxx AsFix Scool
+
+rules
+
+ TypeToStr:
+ Var(t) -> "typedef"
+ where <eq> (t, "type")
+
+ TypeToStr:
+ FunType(_, Var(t)) -> t
+
+ ArgsToStr:
+ FunType([], _) -> ""
+
+ ArgsToStr:
+ FunType([ e | []], _) -> ""
+
+ ArgsToStr:
+ FunType([e | l], _) -> <concat-strings> [ e, ", ",
<ArgsToStr> l ]
+
+ ConceptBodyToCxx:
+ ConstDec([], idf, None(), t) -> CxxComment(<concat-strings>[
<TypeToStr> t, " ", idf, ";" ])
+
+ ConceptBodyToCxx:
+ ConstDec(["decl"], idf, None(), t) ->
+ CxxComment(<concat-strings>[ <TypeToStr> t, " ", idf,
"(", <ArgsToStr> t, ")", ";"])
+
+ ConceptAddCxxConstructor:
+ idf -> CxxProtected([CxxFun([], None(), idf, [])])
+
+// ConceptAddCxxConstructor(| idf):
+// _ -> CxxProtected([CxxFun([(Typename, "E")], "",
<concat-strings>[ idf, "<E>::", idf], [], [])])
Index: trunk/src/scoolt/Decl.str
===================================================================
--- trunk/src/scoolt/Decl.str (revision 55)
+++ trunk/src/scoolt/Decl.str (revision 56)
@@ -1,6 +1,6 @@
module Decl
-imports libstratego-lib Cxx Type Exp Stm Tools AsFix Scool Access
+imports libstratego-lib Cxx Type Exp Stm Tools AsFix Scool Access Concept
rules
@@ -158,7 +158,7 @@
* Grammar: idf ":" "class" "<" parent ";"
*/
DeclToCxx:
- ConstDec([], idf, cs, Class(parent)) -> CxxClassDecl([], idf, [("public",
<TypeToCxx> parent)])
+ ConstDec([], idf, cs, Class(Var(parent))) -> CxxClassDecl([], idf,
[("public", CxxType(parent))])
where <conc-strings> (idf, "_") => nidf
/*
@@ -189,6 +189,21 @@
DeclToCxx:
BiFunDec(l, idf, params, args, t, ExpStm(body)) -> CxxFun(<map (ParamToCxx)>
params, <TypeToCxx> t, idf, <map (ArgDefToCxx)> args, [<StmToCxx>
Return(body)])
+
+ /*
+ * Handle concept declarations
+ * Grammar : idf ":" "concept" "{" body "}"
+ */
+ DeclToCxx:
+ Concept(idf, body) -> CxxClassDecl([(Typename, "E")], idf, [],
+ <conc>
+ (
+ [ CxxComment("To be provided by classes that models this concept\n") ],
+ <map (ConceptBodyToCxx)> body,
+ [ <ConceptAddCxxConstructor> idf ]
+ ))
+
+
ParamToCxx:
(idf, Var(t), wclause) ->
<if <eq> (t, "type") then
--
\__/ \__/
(00) Maxime `yabo` van Noppen (00)
___) \ Epita 2009 / (___
(_____/ Président de Prologin \_____)