scool r60: Handle concepts in where clauses

URL: https://svn.lrde.epita.fr/svn/scool/trunk ChangeLog: 2008-04-12 Maxime van Noppen <yabo@lrde.epita.fr> Handle concepts in where clauses * scoolt/Concept.str: Handle the where clause node. * scoolt/Type.str: Little fix. * scoolt/Decl.str: Add strategies to compute the actual * type regarding to the given where-clause. * scl-syn/Concept.sdf: Add the 'models' keyword * scl-syn/Decl.sdf: Clean indentation. * scl-syn/Lexical.sdf: Add the 'model' keyword. scl-syn/Concept.sdf | 1 + scl-syn/Decl.sdf | 15 ++++++--------- scl-syn/Lexical.sdf | 2 ++ scoolt/Concept.str | 22 ++++++++++++++++++++++ scoolt/Decl.str | 25 +++++++++++++++++-------- scoolt/Type.str | 8 ++++---- 6 files changed, 52 insertions(+), 21 deletions(-) Index: trunk/src/scoolt/Concept.str =================================================================== --- trunk/src/scoolt/Concept.str (revision 59) +++ trunk/src/scoolt/Concept.str (revision 60) @@ -52,3 +52,25 @@ ] where <concat-strings> [ "m", <int-to-string> <Count> ] => new_idf + GetWhereClause_: + Some(wclause) -> <GetWhereClause> wclause + + GetWhereClause_: + _#([Parenthesis(wclause)]) -> <GetWhereClause> wclause + + GetWhereClause_: + _#([wclause]) -> <GetWhereClause> wclause + where + <not (?Parenthesis(x))> wclause + + GetWhereClause: + wclause -> <GetWhereClause_ <+ id> wclause + + // FIXME: check that what we declared in the where-clause is consistent with the argument (e.g. : [T : type where (E models my-concept)] is not consistent) + WhereClauseToCxx: + (wclause, arg) -> (CxxConstType(CxxRefType(<ModelToCxx> (<GetWhereClause> wclause, arg))), "c") + + + ModelToCxx: + (Model(t, concept), arg) -> CxxType(concept, [t]) + Index: trunk/src/scoolt/Type.str =================================================================== --- trunk/src/scoolt/Type.str (revision 59) +++ trunk/src/scoolt/Type.str (revision 60) @@ -5,7 +5,7 @@ rules IsScalar: - t -> t + Var(t) -> t where ( <eq> (t, "char") @@ -24,9 +24,9 @@ // Constify + Referencify a type TypeToConstRefCxx: - Var(t) -> CxxConstType(CxxRefType(CxxType(t))) + t -> CxxConstType(CxxRefType(<TypeToCxx> t)) where ( - <is-string> t - ; <not (IsScalar)> t + <not (IsScalar)> t + ; <not (?RefType(x))> t ) Index: trunk/src/scoolt/Decl.str =================================================================== --- trunk/src/scoolt/Decl.str (revision 59) +++ trunk/src/scoolt/Decl.str (revision 60) @@ -198,7 +198,7 @@ Concept(idf, body) -> CxxClassDecl([(Typename, "E")], idf, [], <conc> ( - [ CxxComment("To be provided by classes that models this concept\n") ], + [ CxxComment("To be provided by classes that model this concept.\n") ], <map (ConceptBodyToStr)> body, [ <ConceptAddCxxConstructor> idf ] )) @@ -211,16 +211,25 @@ ParamToCxx: - (idf, Var(t), wclause) -> - <if <eq> (t, "type") then - ! (CxxType("class"), idf) - else - ! (CxxType(t), idf) - end> + (idf1, Var("type"), wclause) -> (CxxType("class"), idf1) + where + rules( + RealTypeToCxx: + arg -> <WhereClauseToCxx> (wclause, arg) + ) + + ParamToCxx: + (idf, Var(t), wclause) -> (CxxType(t), idf) + where + <not(?"test")> t + ArgDefToCxx: + arg -> <RealTypeToCxx> arg ArgDefToCxx: - (idf, t) -> (<TypeToConstRefCxx <+ TypeToCxx> t, idf) + (idf, t) -> ((<TypeToConstRefCxx <+ TypeToCxx> t), idf) + where + <not (RealTypeToCxx)> (idf, t) //(idf, t) -> (<TypeToCxx; try(CxxTypeToStc(|CxxType(p-idf)))> t, idf) //where <concat-strings; SclNewIdf> ["T", <Count; int-to-string> 0] => p-idf Index: trunk/src/scl-syn/Decl.sdf =================================================================== --- trunk/src/scl-syn/Decl.sdf (revision 59) +++ trunk/src/scl-syn/Decl.sdf (revision 60) @@ -23,20 +23,17 @@ Qualifier* Id ":" Constifier? Type ";" -> Decl {cons("ConstDec")} - Qualifier* Id ":" "(" {(Id ":" Type) ","}* ")" "->" Type "=>" Stm -> Decl { cons("FunDec") } + Qualifier* Id ":" "(" {(Id ":" Type) ","}* ")" "->" Type "=>" Stm + -> Decl { cons("FunDec") } Qualifier* Id ":" "(" {(Id ":" Type) ","}* ")" "->" Type - "=" "{" Stm* "}" -> Decl - {cons("FunDec")} + "=" "{" Stm* "}" -> Decl {cons("FunDec")} Qualifier* Id ":" "[" {(Id ":" Type ("where" Exp)?) ","}* "]" "->" Type - "=" "{" Stm* "}" -> Decl - {cons("StaticFunDec")} + "=" "{" Stm* "}" -> Decl {cons("StaticFunDec")} Qualifier* Id ":" "[" {(Id ":" Type ("where" Exp)?) ","}* "]" "(" {(Id ":" Type) ","}* ")" "->" Type - "=" "{" Stm* "}" -> Decl - {cons("BiFunDec")} + "=" "{" Stm* "}" -> Decl {cons("BiFunDec")} Qualifier* Id ":" "[" {(Id ":" Type ("where" Exp)?) ","}* "]" "(" {(Id ":" Type) ","}* ")" "->" Type - "=>" Stm -> Decl - {cons("BiFunDec")} + "=>" Stm -> Decl {cons("BiFunDec")} Index: trunk/src/scl-syn/Concept.sdf =================================================================== --- trunk/src/scl-syn/Concept.sdf (revision 59) +++ trunk/src/scl-syn/Concept.sdf (revision 60) @@ -7,3 +7,4 @@ sorts Concept context-free syntax Id ":" "concept" "=" "{" Decl* "}" -> Concept {cons("Concept")} + Id "models" Id -> Exp {cons("Model")} Index: trunk/src/scl-syn/Lexical.sdf =================================================================== --- trunk/src/scl-syn/Lexical.sdf (revision 59) +++ trunk/src/scl-syn/Lexical.sdf (revision 60) @@ -33,6 +33,8 @@ "decl" -> Qualifier "abstract" -> Qualifier + "models" -> TypeQualifier + "const" -> Constifier lexical restrictions -- \__/ \__/ (00) Maxime `yabo` van Noppen (00) ___) \ Epita 2009 / (___ (_____/ Président de Prologin \_____)
participants (1)
-
Maxime van Noppen