URL:
https://svn.lrde.epita.fr/svn/scool/trunk
ChangeLog:
2008-04-10 Maxime van Noppen <yabo(a)lrde.epita.fr>
Handle concept declarations
* pp-cxx/CxxExp.str: Handle the constructor 'CxxAdressOf'.
* pp-cxx/CxxId.str: Handle more complicated C++ identifiers as scoped
or parametered ones.
* pp-cxx/CxxDecl.str: Handle the pointer on methods constructor.
* pp-cxx/CxxExp.meta: New.
* pp-cxx/CxxType.str: Handle parametered types (e.g. E<T>), namespaces
and the use of the 'typename' keyword when
approriate.
* scoolt/Concept.str: Generate the C++ code for concepts.
* scoolt/Tools.str: Fix bug in strategy name.
* scoolt/Decl.str: Handle concept declarations.
* scoolt/Program.str: Separate the generation of the C++ declarations
and implementations.
* cxx-syn/CxxDecl.sdf: Add pointer to methods and the use of the
'typename' keyword.
* cxx-syn/CxxExp.sdf: Add the operator '&' as 'adress of'.
* cxx-syn/Lexical.sdf: Fix a bug in grammar that forbade 'E<T>::'
expressions.
cxx-syn/CxxDecl.sdf | 7 +++++--
cxx-syn/CxxExp.sdf | 2 +-
cxx-syn/Lexical.sdf | 2 +-
pp-cxx/CxxDecl.str | 14 +++++++++++++-
pp-cxx/CxxExp.meta | 1 +
pp-cxx/CxxExp.str | 3 +++
pp-cxx/CxxId.str | 6 +++---
pp-cxx/CxxType.str | 9 +++++++++
scoolt/Concept.str | 38 +++++++++++++++++++++++++++++---------
scoolt/Decl.str | 8 +++++++-
scoolt/Program.str | 5 ++++-
scoolt/Tools.str | 2 +-
12 files changed, 77 insertions(+), 20 deletions(-)
Index: trunk/src/pp-cxx/CxxFun.str
===================================================================
Index: trunk/src/pp-cxx/CxxId.str
===================================================================
--- trunk/src/pp-cxx/CxxId.str (revision 57)
+++ trunk/src/pp-cxx/CxxId.str (revision 58)
@@ -1,12 +1,12 @@
module CxxId
-imports Cxx Box libstratego-lib
+imports Cxx Box CxxType libstratego-lib
rules
CxxIdToAbox:
x -> S(x)
- where not(<?CxxScope(_, _)> x)
+ where <is-string> x
CxxIdToAbox:
- CxxScope(idf1, idf2) -> H hs=0 [ ~<CxxIdToAbox>idf1 "::"
~<CxxIdToAbox>idf2 ]
+ x -> <CxxTypeToAbox> x
Index: trunk/src/pp-cxx/CxxExp.str
===================================================================
--- trunk/src/pp-cxx/CxxExp.str (revision 57)
+++ trunk/src/pp-cxx/CxxExp.str (revision 58)
@@ -31,6 +31,9 @@
CxxExpToStr:
CxxProgram(exp) -> exp
+ CxxExpToAbox:
+ CxxAdressOf(idf) -> H hs=0 [ "&" ~<CxxIdToAbox> idf ]
+
CxxExpToStr:
x -> x
where <is-string> x
Index: trunk/src/pp-cxx/CxxDecl.str
===================================================================
--- trunk/src/pp-cxx/CxxDecl.str (revision 57)
+++ trunk/src/pp-cxx/CxxDecl.str (revision 58)
@@ -1,6 +1,6 @@
module CxxDecl
-imports Cxx Box libstratego-lib CxxType CxxExp CxxId
+imports Cxx Box libstratego-lib CxxType CxxExp CxxId CxxFun
rules
@@ -16,6 +16,18 @@
CxxTopLevelToAbox:
CxxDecl(t, idf, v) -> H hs=0 [ H hs=1 [ ~<CxxTypeToAbox>t
~<CxxIdToAbox>idf "=" ~<CxxExpToAbox> v] ";"]
+ // Declare a pointer on method : base_type (class::*idf)();
+ CxxTopLevelToAbox:
+ CxxAffect(CxxDecl(base_type, class, idf, args), exp) ->
+ H hs=0 [
+ H hs=1 [
+ ~<CxxTypeToAbox> base_type
+ H hs=0 [
+ "(" ~<CxxTypeToAbox> class "::*" ~<CxxTypeToAbox> idf
")(" ~<map (CxxArgDefToAbox)> args")"
+ ] "=" ~<CxxExpToAbox> exp
+ ] ";"
+ ]
+
CxxTopLevelToAbox:
CxxArrayDecl(t, idf, n) -> H hs=0 [ H hs=1 [ ~<CxxTypeToAbox> t
~<CxxIdToAbox> idf] "[" ~<CxxExpToAbox> n "]"
";" ]
Index: trunk/src/pp-cxx/CxxExp.meta
===================================================================
--- trunk/src/pp-cxx/CxxExp.meta (revision 0)
+++ trunk/src/pp-cxx/CxxExp.meta (revision 58)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx/CxxType.str
===================================================================
--- trunk/src/pp-cxx/CxxType.str (revision 57)
+++ trunk/src/pp-cxx/CxxType.str (revision 58)
@@ -8,6 +8,9 @@
CxxType(idf) -> <CxxIdToAbox> idf
CxxTypeToAbox:
+ CxxType(idf, l) -> S(<concat-strings> [ idf, "<",
<foldr(!"", conc-strings)> l, ">" ])
+
+ CxxTypeToAbox:
CxxRefType(t) -> H hs=0 [ ~<CxxTypeToAbox> t "&" ]
CxxTypeToAbox:
@@ -21,3 +24,9 @@
CxxTypeToAbox:
CxxFunCall(idf, args) -> H hs=0 [ ~<CxxIdToAbox>idf "(" H hs=1 [
~*<CxxListToAbox(CxxTypeToAbox <+ CxxExpToAbox|",")>args ]
")"]
+
+ CxxTypeToAbox:
+ CxxScope(idf1, idf2) -> H hs=0 [ ~<CxxTypeToAbox> idf1 "::"
~<CxxIdToAbox> idf2 ]
+
+ CxxTypeToAbox:
+ CxxTypename(t) -> H hs=1 [ "typename" ~<CxxTypeToAbox> t ]
Index: trunk/src/scoolt/Concept.str
===================================================================
--- trunk/src/scoolt/Concept.str (revision 57)
+++ trunk/src/scoolt/Concept.str (revision 58)
@@ -1,9 +1,14 @@
module Concept
-imports libstratego-lib Cxx AsFix Scool
+imports libstratego-lib Cxx AsFix Scool Decl
rules
+ // FIXME: This is rather the role of the pretty-printer. However, currently
+ // a CxxComment() node only accepts a text parameter, so we have to
+ // build it. An idea would be to extend the CxxComment() node to accept
+ // an AST as parameter and let the pretty printer do the printing stuff.
+
TypeToStr:
Var(t) -> "typedef"
where <eq> (t, "type")
@@ -15,20 +20,35 @@
FunType([], _) -> ""
ArgsToStr:
- FunType([ e | []], _) -> ""
+ FunType([ e | []], _) -> <ArgToStr> e
ArgsToStr:
- FunType([e | l], _) -> <concat-strings> [ e, ", ",
<ArgsToStr> l ]
+ FunType([e | l], _) -> <concat-strings> [ <ArgToStr> e, ","
]
+
+ ArgToStr:
+ FunArg(idf, Var(type)) -> <concat-strings> [ type, " ", idf ]
- ConceptBodyToCxx:
- ConstDec([], idf, None(), t) -> CxxComment(<concat-strings>[
<TypeToStr> t, " ", idf, ";" ])
+ ConceptBodyToStr:
+ ConstDec([], idf, None(), t) ->
+ CxxComment(<concat-strings>[ <TypeToStr> t, " ", idf,
";" ])
- ConceptBodyToCxx:
+ ConceptBodyToStr:
ConstDec(["decl"], idf, None(), t) ->
- CxxComment(<concat-strings>[ <TypeToStr> t, " ", idf,
"(", <ArgsToStr> 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], [], [])])
+ ConceptToCxxImpl:
+ ConstDec([], idf, None(), Var("type")) ->
CxxTypedef(CxxScope(CxxTypename(CxxType("E")), idf), idf)
+
+ ConceptToCxxImpl:
+ ConstDec(["decl"], idf, None(), FunType(args, Var(return_type))) ->
+ [
+ CxxAffect(CxxDecl(CxxType(return_type), CxxType("E"), CxxType(new_idf),
<map (ArgDefToCxx)> args), CxxAdressOf(CxxScope(CxxType("E"), idf))),
+ CxxExpStm(CxxAffect(new_idf, CxxInt("0")))
+ ]
+ where <concat-strings> [ "m", <int-to-string> <Count> ]
=> new_idf
+
Index: trunk/src/scoolt/Tools.str
===================================================================
--- trunk/src/scoolt/Tools.str (revision 57)
+++ trunk/src/scoolt/Tools.str (revision 58)
@@ -19,7 +19,7 @@
Count =
if count_ => res then
rules(count_:- _)
- ; rules(count_: _ -> <sum> (res, 1))
+ ; rules(count_: _ -> <add> (res, 1))
else
rules(count_: _ -> 1)
end
Index: trunk/src/scoolt/Decl.str
===================================================================
--- trunk/src/scoolt/Decl.str (revision 57)
+++ trunk/src/scoolt/Decl.str (revision 58)
@@ -199,9 +199,15 @@
<conc>
(
[ CxxComment("To be provided by classes that models this concept\n") ],
- <map (ConceptBodyToCxx)> body,
+ <map (ConceptBodyToStr)> body,
[ <ConceptAddCxxConstructor> idf ]
))
+ where
+ rules(
+ ImplToCxx:
+ Concept(idf, body) ->
+ CxxFun([(Typename, "E")], CxxType(""), <concat-strings>[
idf, "<E>::", idf], [], <flatten-list> <map
(ConceptToCxxImpl)> body)
+ )
ParamToCxx:
Index: trunk/src/scoolt/Program.str
===================================================================
--- trunk/src/scoolt/Program.str (revision 57)
+++ trunk/src/scoolt/Program.str (revision 58)
@@ -4,5 +4,8 @@
rules
+ CxxEmpty:
+ _ -> []
+
ProgramToCxx:
- Program(l) -> CxxProgram(<map(DeclToCxx)> l)
+ Program(l) -> CxxProgram(<conc> (<map(DeclToCxx)> l, <map(ImplToCxx
<+ CxxEmpty)> l))
Index: trunk/src/cxx-syn/CxxDecl.sdf
===================================================================
--- trunk/src/cxx-syn/CxxDecl.sdf (revision 57)
+++ trunk/src/cxx-syn/CxxDecl.sdf (revision 58)
@@ -11,6 +11,10 @@
CxxType CxxId ("[" CxxExp "]")? ";" ->
CxxDecl {cons("CxxArrayDecl")}
CxxType CxxId "=" CxxExp ";" ->
CxxDecl {cons("CxxDecl")}
+ CxxDecl "=" CxxExp ";" -> CxxExp {cons("CxxAffect")}
+
+ CxxType "(" CxxType "::*" CxxType ")" ("("
{(CxxType CxxId) ","}* ")")?
+ -> CxxDecl {cons("CxxDecl")}
"typedef" CxxType CxxId ";" ->
CxxDecl {cons("CxxTypedef")}
@@ -26,9 +30,8 @@
-> CxxDecl {cons("CxxClassDecl")}
"typename" -> CxxType {cons("Typename")}
-
+ "typename" CxxType -> CxxType {cons("CxxTypename")}
"//" CxxText -> CxxTopLevel {cons("CxxComment")}
-
"public" ":" CxxTopLevel* ->
CxxTopLevel {cons("CxxPublic")}
"protected" ":" CxxTopLevel* ->
CxxTopLevel {cons("CxxProtected")}
"private" ":" CxxTopLevel* ->
CxxTopLevel {cons("CxxPrivate")}
Index: trunk/src/cxx-syn/CxxExp.sdf
===================================================================
--- trunk/src/cxx-syn/CxxExp.sdf (revision 57)
+++ trunk/src/cxx-syn/CxxExp.sdf (revision 58)
@@ -9,7 +9,7 @@
CxxInt -> CxxExp {cons("CxxInt")}
CxxId "(" {CxxExp ","}* ")" ->
CxxExp {cons("CxxFunCall")}
-
CxxId CxxExp ";" -> CxxExp {cons("CxxKeyword")}
CxxId "=" CxxExp ";" -> CxxExp {cons("CxxAffect")}
CxxExp "+" CxxExp -> CxxExp {cons("CxxSum")}
+ "&" CxxExp -> CxxExp {cons("CxxAdressOf")}
Index: trunk/src/cxx-syn/Lexical.sdf
===================================================================
--- trunk/src/cxx-syn/Lexical.sdf (revision 57)
+++ trunk/src/cxx-syn/Lexical.sdf (revision 58)
@@ -12,4 +12,4 @@
"protected" -> CxxAccessModifier
context-free syntax
- CxxId "::" CxxId -> CxxId {cons("CxxScope")}
+ CxxType "::" CxxId -> CxxId {cons("CxxScope")}
--
\__/ \__/
(00) Maxime `yabo` van Noppen (00)
___) \ Epita 2009 / (___
(_____/ Président de Prologin \_____)