scool r121: Add the 'mutable' keyword

17 Oct
2008
17 Oct
'08
6:50 p.m.
From: Maxime van Noppen <yabo@lrde.epita.fr> To: transformers-patches@lrde.epita.fr, olena-patches@lrde.epita.fr Subject: scool r121: Add the 'mutable' keyword URL: https://svn.lrde.epita.fr/svn/scool/branches/scool-ng ChangeLog: 2008-10-17 Maxime van Noppen <yabo@lrde.epita.fr> Add the 'mutable' keyword. * pp-cxx/CxxFun.str: Pretty-print the 'const' keyword when it is * present. * cxx-syn/CxxFun.sdf: Add the 'const-method' production. * scl-syn/Expression.sdf: Use the C++ semantic regarding '=' and * '=='. * scoolt/Class.str: Add a dynamic-rule system to scope translations * of declarations so that it is possible to detect wether the * translation takes place or not inside a class context. * scoolt/Declaration.str: Handle function modifiers. * scoolt/Expression.str: Handle the Assign constructor. * scoolt/Function.str: Don't add the 'const' keywords when either * the method is mutable or that it is a function and not a method. * scoolt/Program.str: Initialize the dynamic rule system for scoped * translation rules. --- cxx-syn/CxxFun.sdf | 7 +++++++ pp-cxx/CxxFun.str | 14 ++++++++++---- scl-syn/Expression.sdf | 12 ++++++------ scoolt/Class.str | 15 ++++++++++++++- scoolt/Declaration.str | 8 ++++++-- scoolt/Expression.str | 6 +++++- scoolt/Function.str | 19 +++++++++++++++++++ scoolt/Program.str | 5 ++++- 8 files changed, 71 insertions(+), 15 deletions(-) Index: branches/scool-ng/src/pp-cxx/CxxFun.str =================================================================== --- branches/scool-ng/src/pp-cxx/CxxFun.str (revision 120) +++ branches/scool-ng/src/pp-cxx/CxxFun.str (revision 121) @@ -4,14 +4,20 @@ rules + IsConst: + Const() -> S(" const") + + IsConst: + None() -> S("") + CxxTopLevelToAbox: - CxxFun(params, t, idf, args) -> + CxxFun(params, t, idf, const, args) -> V vs=0 [ ~<CxxParamsToAbox> params H hs=0 [ - H hs=1 [ ~<CxxTypeToAbox> t ~<CxxIdToAbox> idf ] "(" H hs=1 [ ~*<CxxListToAbox(CxxArgDefToAbox|",")> args ] ")" ";" + H hs=1 [ ~<CxxTypeToAbox> t ~<CxxIdToAbox> idf ] "(" H hs=1 [ ~*<CxxListToAbox(CxxArgDefToAbox|",")> args ] ")" ~<IsConst> const ";" ] ] @@ -27,12 +33,12 @@ ] CxxTopLevelToAbox: - CxxFun(params, t, idf, args, body) -> + CxxFun(params, t, idf, args, const, body) -> V vs=0 [ ~<CxxParamsToAbox> params H hs=0 [ - H hs=1 [ ~<CxxTypeToAbox> t ~<CxxIdToAbox> idf] "(" H hs=1 [ ~*<CxxListToAbox(CxxArgDefToAbox|",")> args ] ")" + H hs=1 [ ~<CxxTypeToAbox> t ~<CxxIdToAbox> idf] "(" H hs=1 [ ~*<CxxListToAbox(CxxArgDefToAbox|",")> args ] ")" ~<IsConst> const ] V vs=0 is=2 [ Index: branches/scool-ng/src/scoolt/Expression.str =================================================================== --- branches/scool-ng/src/scoolt/Expression.str (revision 120) +++ branches/scool-ng/src/scoolt/Expression.str (revision 121) @@ -28,7 +28,6 @@ String(str) -> <un-double-quote> str ExpressionToCxx: -// |[ ~exp:e1 + ~exp:e2; ]| -> CxxSum(cxx_e1, cxx_e2) Sum(e1, e2) -> CxxSum(cxx_e1, cxx_e2) where <ExpressionToCxx> e1 => cxx_e1 @@ -41,6 +40,11 @@ ; <ParametersToCxx> params => cxx_params ; <ArgumentsToCxx> args => cxx_args + ExpressionToCxx: + Assign(lvalue, rvalue) -> CxxAssign(cxx_lvalue, cxx_rvalue) + where + <IdentifierToCxx> lvalue => cxx_lvalue // FIXME: lvalue might not be an identifier + ; <ExpressionToCxx> rvalue => cxx_rvalue StaticExpressionToCxx: Index: branches/scool-ng/src/scoolt/Class.str =================================================================== --- branches/scool-ng/src/scoolt/Class.str (revision 120) +++ branches/scool-ng/src/scoolt/Class.str (revision 121) @@ -32,8 +32,14 @@ ClassStatementToCxx: decl -> cxx_decl where - <map (DeclarationToCxx)> decl => cxx_decl + <map (ClassDeclarationToCxx)> decl => cxx_decl + ClassDeclarationToCxx: + decl -> cxx_decl + where + InClass + ; <DeclarationToCxx> decl => cxx_decl + ; OutClass // Add the exact type parameter if the class is not final AddExactType(|cqualif): @@ -108,3 +114,10 @@ ; <IdentifierToCxx> idf => cxx_idf ; <InheritanceToCxx(| cqualif, cxx_idf)> mother => cxx_mother +strategies + + ClassInit = rules(IsInClass: _ -> 0) + + InClass = rules(IsInClass:- _) ; rules(IsInClass: _ -> 1) + + OutClass = rules(IsInClass: _ -> 0) ; rules(IsInClass:- _) Index: branches/scool-ng/src/scoolt/Declaration.str =================================================================== --- branches/scool-ng/src/scoolt/Declaration.str (revision 120) +++ branches/scool-ng/src/scoolt/Declaration.str (revision 121) @@ -42,21 +42,25 @@ //////////////////////////////////////////////////////////////////////////////// DeclarationToCxx: - |[ ~idf : ~ftype:fun_type; ]| -> CxxFun(cxx_params, cxx_ret_type, cxx_idf, cxx_args) +// |[ ~idf : ~ftype:fun_type; ]| -> CxxFun(cxx_params, cxx_ret_type, cxx_idf, const, cxx_args) + FunctionDeclaration(modifier, idf, fun_type) -> CxxFun(cxx_params, cxx_ret_type, cxx_idf, const, cxx_args) where <IdentifierToCxx> idf => cxx_idf ; <TypeToCxx> <GetReturnType> fun_type => cxx_ret_type ; <ParametersToCxx> <GetParameters> fun_type => cxx_params ; <ArgumentsToCxx> <GetArguments> fun_type => cxx_args + ; <IsMethodConst> modifier => const DeclarationToCxx: - |[ ~idf : ~ftype:fun_type = { ~fbody:body } ]| -> CxxFun(cxx_params, cxx_ret_type, cxx_idf, cxx_args, cxx_body) +// |[ ~idf : ~ftype:fun_type = { ~fbody:body } ]| -> CxxFun(cxx_params, cxx_ret_type, cxx_idf, cxx_args, Const, cxx_body) + FunctionDefinition(modifier, idf, fun_type, FunctionBlock(body)) -> CxxFun(cxx_params, cxx_ret_type, cxx_idf, cxx_args, const, cxx_body) where <IdentifierToCxx> idf => cxx_idf ; <TypeToCxx> <GetReturnType> fun_type => cxx_ret_type ; <ParametersToCxx> <GetParameters> fun_type => cxx_params ; <ArgumentsToCxx> <GetArguments> fun_type => cxx_args ; <FunctionBodyToCxx> body => cxx_body + ; <IsMethodConst> modifier => const //////////////////////////////////////////////////////////////////////////////// Index: branches/scool-ng/src/scoolt/Function.str =================================================================== --- branches/scool-ng/src/scoolt/Function.str (revision 120) +++ branches/scool-ng/src/scoolt/Function.str (revision 121) @@ -4,6 +4,25 @@ rules + // Detect the constness of the method regarding to the modifier + + IsMethodConst: + Some("mutable") -> None() + + IsMethodConst: + _ -> None() + where + <eq> (<IsInClass>, 0) + + IsMethodConst: + x -> Const() + where + <not (?Some("mutable"))> x + ; <eq> (<IsInClass>, 1) + + + + // Extract data from a FunctionType GetParameters: Index: branches/scool-ng/src/scoolt/Program.str =================================================================== --- branches/scool-ng/src/scoolt/Program.str (revision 120) +++ branches/scool-ng/src/scoolt/Program.str (revision 121) @@ -6,6 +6,9 @@ rules ProgramToCxx: - Program(stm_list) -> CxxProgram(<map (StatementToCxx)> stm_list) + Program(stm_list) -> cxx_program + where + ClassInit + ; !CxxProgram(<map (StatementToCxx)> stm_list) => cxx_program // Program(l) -> CxxProgram(<conc> (<map(DeclToCxx)> l, <map(ImplToCxx <+ CxxEmpty)> l)) Index: branches/scool-ng/src/scl-syn/Expression.sdf =================================================================== --- branches/scool-ng/src/scl-syn/Expression.sdf (revision 120) +++ branches/scool-ng/src/scl-syn/Expression.sdf (revision 121) @@ -26,7 +26,7 @@ Expression "-" Expression -> Expression {cons("Substraction")} Expression "*" Expression -> Expression {cons("Multiplication")} Expression "/" Expression -> Expression {cons("Division")} - Expression "=" Expression -> Expression {cons("Equal")} + Expression "==" Expression -> Expression {cons("Equal")} Expression "!=" Expression -> Expression {cons("Different")} Expression "<" Expression -> Expression {cons("StrictInferior")} Expression ">" Expression -> Expression {cons("StrictSuperior")} @@ -35,7 +35,7 @@ Expression "or" Expression -> Expression {cons("Or")} Expression "and" Expression -> Expression {cons("And")} - %%Identifier ":=" Expression -> Expression {cons("Assign")} + Identifier "=" Expression -> Expression {cons("Assign")} %%Expression "." Identifier -> Expression {cons("Field")} @@ -54,7 +54,7 @@ Expression "-" Expression -> Expression } > {left: - Expression "=" Expression -> Expression + Expression "==" Expression -> Expression } > {left: Expression "and" Expression -> Expression @@ -62,6 +62,6 @@ > {left: Expression "or" Expression -> Expression } -%%> {right: -%% Identifier ":=" Expression -> Expression -%% } +> {right: + Identifier "=" Expression -> Expression + } Index: branches/scool-ng/src/cxx-syn/CxxFun.sdf =================================================================== --- branches/scool-ng/src/cxx-syn/CxxFun.sdf (revision 120) +++ branches/scool-ng/src/cxx-syn/CxxFun.sdf (revision 121) @@ -15,6 +15,13 @@ -> CxxTopLevel {cons("CxxFun")} "template" "<" {(CxxType CxxId) ","}* ">" + CxxType CxxId "(" {(CxxType CxxId) ","}* ")" Const? + "{" + CxxStm* + "}" + -> CxxTopLevel {cons("CxxFun")} + + "template" "<" {(CxxType CxxId) ","}* ">" CxxType CxxId "(" {(CxxType CxxId) ","}* ")" ";" -> CxxTopLevel {cons("CxxFun")} "template" "<" {(CxxType CxxId) ","}* ">"
6177
Age (days ago)
6177
Last active (days ago)
0 comments
1 participants
participants (1)
-
Maxime van Noppen