
URL: https://svn.lrde.epita.fr/svn/scool/branches/scool-ng ChangeLog: 2008-09-12 Maxime van Noppen <yabo@lrde.epita.fr> Handle functions and the 'var' keyword * concrete-syn/concrete-syn.sdf: Add escape sequence for FunctionType. * scoolt/Declaration.str: Handle function declarations and the 'var' keyword. * scoolt/Expression.str: Consider identifiers as expressions. * scoolt/Function.str: New. * scoolt/Type.str: Const-reference non-scalar types. concrete-syn/concrete-syn.sdf | 1 scoolt/Declaration.str | 49 +++++++++++++++++++++++++++++------------- scoolt/Expression.str | 5 ++++ scoolt/Function.str | 17 ++++++++++++++ scoolt/Type.str | 20 +++++++++++++++-- 5 files changed, 75 insertions(+), 17 deletions(-) Index: branches/scool-ng/src/scoolt/Expression.str =================================================================== --- branches/scool-ng/src/scoolt/Expression.str (revision 77) +++ branches/scool-ng/src/scoolt/Expression.str (revision 78) @@ -9,3 +9,8 @@ ExpressionToCxx: Integer(int) -> CxxInt(int) + + ExpressionToCxx: + idf -> cxx_idf + where + <IdentifierToCxx> idf => cxx_idf Index: branches/scool-ng/src/scoolt/Type.str =================================================================== --- branches/scool-ng/src/scoolt/Type.str (revision 77) +++ branches/scool-ng/src/scoolt/Type.str (revision 78) @@ -1,8 +1,24 @@ module Type -imports libstratego-lib Cxx Scool Type +imports libstratego-lib Cxx Scool rules + IsScalar: + SimpleType(type) -> type + where + <eq> (type, "char") + <+ <eq> (type, "bool") + <+ <eq> (type, "short") + <+ <eq> (type, "int") + <+ <eq> (type, "float") + <+ <eq> (type, "double") + TypeToCxx: - SimpleType(t) -> CxxType(t) + SimpleType(type) -> CxxType(type) + + TypeToConstRefCxx: + type -> CxxConstType(CxxRefType(<TypeToCxx> type)) + where + <not (IsScalar)> type + ; <not (?ReferenceType(_))> type Index: branches/scool-ng/src/scoolt/Declaration.str =================================================================== --- branches/scool-ng/src/scoolt/Declaration.str (revision 77) +++ branches/scool-ng/src/scoolt/Declaration.str (revision 78) @@ -1,32 +1,51 @@ module Declaration -imports libstratego-lib Cxx Scool Type Expression +imports libstratego-lib Cxx Scool Type Expression Function rules + //////////////////////////////////////////////////////////////////////////////// + // Variables // + //////////////////////////////////////////////////////////////////////////////// + DeclarationToCxx: - |[ ~i : ~t; ]| -> ![ const ~cxx_t ~cxx_i; ]! + |[ ~idf : ~type; ]| -> ![ const ~cxx_type ~cxx_idf; ]! where - <TypeToCxx> t => cxx_t - ; <IdentifierToCxx> i => cxx_i + <TypeToCxx> type => cxx_type + ; <IdentifierToCxx> idf => cxx_idf DeclarationToCxx: - |[ var ~i : ~t; ]| -> ![ ~cxx_t ~cxx_i; ]! +// |[ var ~i : ~t; ]| -> ![ ~cxx_t ~cxx_i; ]! + SimpleDeclaration(Some("var"), idf, type, None()) -> ![ ~cxx_type ~cxx_idf; ]! where - <TypeToCxx> t => cxx_t - ; <IdentifierToCxx> i => cxx_i + <TypeToCxx> type => cxx_type + ; <IdentifierToCxx> idf => cxx_idf DeclarationToCxx: - |[ ~i : ~t = ~exp:e; ]| -> ![ const ~cxx_t ~cxx_i = ~exp:cxx_e; ]! + |[ ~idf : ~type = ~exp:exp; ]| -> ![ const ~cxx_type ~cxx_idf = ~exp:cxx_exp; ]! where - <TypeToCxx> t => cxx_t - ; <IdentifierToCxx> i => cxx_i - ; <ExpressionToCxx> e => cxx_e + <TypeToCxx> type => cxx_type + ; <IdentifierToCxx> idf => cxx_idf + ; <ExpressionToCxx> exp => cxx_exp DeclarationToCxx: - |[ var ~i : ~t = ~exp:e; ]| -> ![ ~cxx_t ~cxx_i = ~exp:cxx_e; ]! +// |[ var ~i : ~t = ~exp:exp; ]| -> ![ ~cxx_t ~cxx_i = ~exp:cxx_exp; ]! + SimpleDeclaration(Some("var"), idf, type, Some(Initialiser(exp))) -> ![ ~cxx_type ~cxx_idf = ~exp:cxx_exp; ]! where - <TypeToCxx> t => cxx_t - ; <IdentifierToCxx> i => cxx_i - ; <ExpressionToCxx> e => cxx_e + <TypeToCxx> type => cxx_type + ; <IdentifierToCxx> idf => cxx_idf + ; <ExpressionToCxx> exp => cxx_exp + + + //////////////////////////////////////////////////////////////////////////////// + // Functions // + //////////////////////////////////////////////////////////////////////////////// + + DeclarationToCxx: + |[ ~idf : ~ft:fun_type; ]| -> CxxFun([], cxx_ret_type, cxx_idf, cxx_args) + where + <IdentifierToCxx> idf => cxx_idf + ; <TypeToCxx> <GetReturnType> fun_type => cxx_ret_type + ; <ArgumentsToCxx> <GetArguments> fun_type => cxx_args + Index: branches/scool-ng/src/scoolt/Function.str =================================================================== --- branches/scool-ng/src/scoolt/Function.str (revision 0) +++ branches/scool-ng/src/scoolt/Function.str (revision 78) @@ -0,0 +1,17 @@ +module Function + +imports libstratego-lib Cxx Scool Type + +rules + + GetReturnType: + FunctionType(_, _, ret_type) -> ret_type + + GetArguments: + FunctionType(_, args, _) -> args + + ArgumentsToCxx: + ArgumentsDeclaration(arg_list) -> <map (ArgumentToCxx)> arg_list + + ArgumentToCxx: + TypedId(idf, type) -> (<TypeToConstRefCxx <+ TypeToCxx> type, <IdentifierToCxx> idf) Index: branches/scool-ng/src/concrete-syn/concrete-syn.sdf =================================================================== --- branches/scool-ng/src/concrete-syn/concrete-syn.sdf (revision 77) +++ branches/scool-ng/src/concrete-syn/concrete-syn.sdf (revision 78) @@ -13,6 +13,7 @@ "~" StrategoTerm -> Identifier {cons("FromTerm"), prefer} "~" StrategoTerm -> SimpleType {cons("FromTerm"), prefer} + "~ft:" StrategoTerm -> FunctionType {cons("FromTerm"), prefer} "~exp:" StrategoTerm -> Expression {cons("FromTerm"), prefer} -- \__/ \__/ (00) Maxime `yabo` van Noppen (00) ___) \ Epita 2009 / (___ (_____/ \_____)