From d63861fd5951ab1928cb73d44675d1d9220568f8 Mon Sep 17 00:00:00 2001 From: "hiroyuki.nagata" Date: Sun, 14 Nov 2021 23:27:49 +0900 Subject: [PATCH] Update PrettyPrinter code for using smart-ptr --- source/src/BNFC/Backend/CPP/Common.hs | 15 +- source/src/BNFC/Backend/CPP/NoSTL.hs | 4 +- source/src/BNFC/Backend/CPP/PrettyPrinter.hs | 165 +++++++++++------- source/src/BNFC/Backend/CPP/STL.hs | 4 +- source/src/BNFC/Backend/CPP/STL/CFtoSTLAbs.hs | 55 +++--- source/src/BNFC/Backend/Common/OOAbstract.hs | 6 - 6 files changed, 148 insertions(+), 101 deletions(-) diff --git a/source/src/BNFC/Backend/CPP/Common.hs b/source/src/BNFC/Backend/CPP/Common.hs index 89708db2..d1c943ba 100644 --- a/source/src/BNFC/Backend/CPP/Common.hs +++ b/source/src/BNFC/Backend/CPP/Common.hs @@ -9,7 +9,7 @@ import Data.List ( intercalate ) import BNFC.CF import BNFC.TypeChecker - +import BNFC.Options ( Ansi ) import BNFC.Backend.C ( comment ) import BNFC.Backend.CPP.Naming @@ -72,3 +72,16 @@ definedRules mlc cf banner LitString s -> show s call x es = x ++ "(" ++ intercalate ", " (map loop es) ++ ")" + +data CppStdMode + = CppStdAnsi Ansi -- ^ @Ansi@ mode. + | CppStdBeyondAnsi Ansi -- ^ @BeyondAnsi@ mode. + +wrapPointerIf :: Bool -> String -> String +wrapPointerIf b v = if b then "*" ++ v else v + +wrapUniquePtrIf :: Bool -> String -> String +wrapUniquePtrIf b v = if b then "std::unique_ptr<" ++v++">" else v + +wrapMoveIf :: Bool -> String -> String +wrapMoveIf b v = if b then "std::move(" ++v++")" else v diff --git a/source/src/BNFC/Backend/CPP/NoSTL.hs b/source/src/BNFC/Backend/CPP/NoSTL.hs index 6d39db80..db015aa7 100644 --- a/source/src/BNFC/Backend/CPP/NoSTL.hs +++ b/source/src/BNFC/Backend/CPP/NoSTL.hs @@ -15,7 +15,7 @@ import BNFC.Backend.Base import BNFC.Backend.C ( bufferH, bufferC, comment, testfileHeader ) import BNFC.Backend.C.CFtoBisonC ( cf2Bison ) import BNFC.Backend.C.CFtoFlexC ( cf2flex, ParserMode(..) ) -import BNFC.Backend.CPP.Common ( commentWithEmacsModeHint ) +import BNFC.Backend.CPP.Common ( commentWithEmacsModeHint, CppStdMode(..) ) import BNFC.Backend.CPP.Makefile import BNFC.Backend.CPP.NoSTL.CFtoCPPAbs import BNFC.Backend.CPP.STL.CFtoCVisitSkelSTL @@ -37,7 +37,7 @@ makeCppNoStl opts cf = do let (skelH, skelC) = cf2CVisitSkel False Nothing cf mkCppFile "Skeleton.H" skelH mkCppFile "Skeleton.C" skelC - let (prinH, prinC) = cf2CPPPrinter False Nothing cf ".H" + let (prinH, prinC) = cf2CPPPrinter (CppStdAnsi Ansi) False Nothing cf ".H" mkCppFile "Printer.H" prinH mkCppFile "Printer.C" prinC mkCppFile "Test.C" (cpptest cf) diff --git a/source/src/BNFC/Backend/CPP/PrettyPrinter.hs b/source/src/BNFC/Backend/CPP/PrettyPrinter.hs index b6c2977a..9a4a5e64 100644 --- a/source/src/BNFC/Backend/CPP/PrettyPrinter.hs +++ b/source/src/BNFC/Backend/CPP/PrettyPrinter.hs @@ -31,13 +31,14 @@ import BNFC.Utils import BNFC.Backend.Common import BNFC.Backend.Common.NamedVariables import BNFC.Backend.Common.StrUtils (renderCharOrString) +import BNFC.Backend.CPP.Common ( CppStdMode(..), wrapUniquePtrIf, wrapPointerIf ) import BNFC.Backend.CPP.STL.STLUtils import BNFC.PrettyPrint --Produces (.H file, .C file) -cf2CPPPrinter :: Bool -> Maybe String -> CF -> String -> (String, String) -cf2CPPPrinter useStl inPackage cf hExt = - (mkHFile useStl inPackage cf groups hExt, mkCFile useStl inPackage cf groups hExt) +cf2CPPPrinter :: CppStdMode -> Bool -> Maybe String -> CF -> String -> (String, String) +cf2CPPPrinter mode useStl inPackage cf hExt = + (mkHFile mode useStl inPackage cf groups hExt, mkCFile mode useStl inPackage cf groups hExt) where groups = when useStl (positionRules cf) -- CPP/NoSTL treats position tokens as just tokens ++ fixCoercions (ruleGroupsInternals cf) @@ -51,8 +52,8 @@ positionRules cf = {- **** Header (.H) File Methods **** -} --An extremely large function to make the Header File -mkHFile :: Bool -> Maybe String -> CF -> [(Cat,[Rule])] -> String -> String -mkHFile useStl inPackage cf groups hExt = unlines +mkHFile :: CppStdMode -> Bool -> Maybe String -> CF -> [(Cat,[Rule])] -> String -> String +mkHFile mode useStl inPackage cf groups hExt = unlines [ printHeader , content , classFooter @@ -100,7 +101,7 @@ mkHFile useStl inPackage cf groups hExt = unlines " char *print(Visitable *v);" ] hdef = nsDefine inPackage "PRINTER_HEADER" - content = concatMap (prDataH useStl) groups + content = concatMap (prDataH mode useStl) groups classFooter = unlines $ [ " void visitInteger(Integer i);", @@ -185,38 +186,48 @@ mkHFile useStl inPackage cf groups hExt = unlines ] --Prints all the required method names and their parameters. -prDataH :: Bool -> (Cat, [Rule]) -> String -prDataH useSTL (cat, rules) - | isList cat = unlines $ concat - [ [ concat [ " void visit", cl, "(", cl, " *p);" ] ] - , when useSTL - [ concat [ " void iter", cl, "(", itty, " i, ", itty, " j);" ] ] - ] - | otherwise = abstract ++ concatMap prRuleH rules - where - cl = identCat (normCat cat) - itty = concat [ cl, "::", "const_iterator" ] - abstract = case lookupRule (noPosition $ catToStr cat) rules of - Just _ -> "" - Nothing -> " void visit" ++ cl ++ "(" ++ cl ++ " *p); /* abstract class */\n" +prDataH :: CppStdMode -> Bool -> (Cat, [Rule]) -> String +prDataH mode useSTL (cat, rules) + | isList cat = unlines $ concat + [ [ concat [ " void visit", cl, "(", wrapUniquePtrIf beyondAnsi cl, " ", vararg, ");" ] ] + , when useSTL + [ concat [ " void iter", cl, "(", itty, " i, ", itty, " j);" ] ] + ] + | otherwise = abstract ++ concatMap prRuleH rules + where + beyondAnsi = case mode of + CppStdBeyondAnsi _ -> True + CppStdAnsi _ -> False + cl = identCat (normCat cat) + vararg = if beyondAnsi then "p" else "*p" + prRuleH = if beyondAnsi then prRuleHBeyondAnsi else prRuleHAnsi + itty = concat [ cl, "::", "const_iterator" ] + abstract = case lookupRule (noPosition $ catToStr cat) rules of + Just _ -> "" + Nothing -> " void visit" ++ cl ++ "(" ++ wrapUniquePtrIf beyondAnsi cl +++ vararg ++ "); /* abstract class */\n" --Prints all the methods to visit a rule. -prRuleH :: IsFun f => Rul f -> String -prRuleH (Rule fun _ _ _) | isProperLabel fun = concat +prRuleHAnsi :: IsFun f => Rul f -> String +prRuleHAnsi (Rule fun _ _ _) | isProperLabel fun = concat [" void visit", funName fun, "(", funName fun, " *p);\n"] -prRuleH _ = "" +prRuleHAnsi _ = "" + +prRuleHBeyondAnsi :: IsFun f => Rul f -> String +prRuleHBeyondAnsi (Rule fun _ _ _) | isProperLabel fun = concat + [" void visit", funName fun, "(", wrapUniquePtrIf True (funName fun), " p);\n"] +prRuleHBeyondAnsi _ = "" {- **** Implementation (.C) File Methods **** -} --This makes the .C file by a similar method. -mkCFile :: Bool -> Maybe String -> CF -> [(Cat,[Rule])] -> String -> String -mkCFile useStl inPackage cf groups hExt = concat +mkCFile :: CppStdMode -> Bool -> Maybe String -> CF -> [(Cat,[Rule])] -> String -> String +mkCFile mode useStl inPackage cf groups hExt = concat [ header, nsStart inPackage ++ "\n", prRender useStl, printEntries, - concatMap (prPrintData useStl inPackage cf) groups, + concatMap (prPrintData useStl mode inPackage cf) groups, printBasics, printTokens, showEntries, @@ -226,6 +237,7 @@ mkCFile useStl inPackage cf groups hExt = concat nsEnd inPackage ++ "\n" ] where + header = unlines [ "/*** Pretty Printer and Abstract Syntax Viewer ***/", @@ -376,33 +388,30 @@ mkCFile useStl inPackage cf groups hExt = concat {- **** Pretty Printer Methods **** -} -- | Generates methods for the Pretty Printer. -prPrintData :: Bool -> Maybe String -> CF -> (Cat, [Rule]) -> String -prPrintData True {- use STL -} _ _ (cat@(ListCat _), rules) = - render $ genPrintVisitorList (cat, rules) -prPrintData False {- use STL -} _ _ (cat@(ListCat _), rules) = - genPrintVisitorListNoStl (cat, rules) --- Not a list : -prPrintData _ _inPackage cf (TokenCat cat, _rules) | isPositionCat cf cat = unlines $ - -- a position token - [ "void PrintAbsyn::visit" ++ cat ++ "(" ++ cat ++ " *p)" - , "{" - , " visitIdent(p->string_);" - , "}" - , "" - ] -prPrintData _ inPackage _cf (cat, rules) = -- Not a list - abstract ++ concatMap (prPrintRule inPackage) rules +prPrintData :: Bool -> CppStdMode -> Maybe String -> CF -> (Cat, [Rule]) -> String +prPrintData True mode _ _ (cat@(ListCat _), rules) = + render $ genPrintVisitorList (mode, cat, rules) +prPrintData False mode _ _ (cat@(ListCat _), rules) = + genPrintVisitorListNoStl (mode, cat, rules) +prPrintData _ mode _inPackage cf (TokenCat cat, _rules) | + isPositionCat cf cat = genPositionToken cat +prPrintData _ mode inPackage _cf (cat, rules) = + abstract ++ concatMap (prPrintRule beyondAnsi inPackage) rules where - cl = identCat (normCat cat) - abstract = case lookupRule (noPosition $ catToStr cat) rules of - Just _ -> "" - Nothing -> "void PrintAbsyn::visit" ++ cl ++ "(" ++ cl +++ "*p) {} //abstract class\n\n" + beyondAnsi = case mode of + CppStdBeyondAnsi _ -> True + CppStdAnsi _ -> False + cl = identCat (normCat cat) + vararg = if beyondAnsi then "p" else "*p" + abstract = case lookupRule (noPosition $ catToStr cat) rules of + Just _ -> "" + Nothing -> "void PrintAbsyn::visit" ++ cl ++ "(" ++ wrapUniquePtrIf beyondAnsi cl +++ vararg ++") {} //abstract class\n\n" -- | Generate pretty printer visitor for a list category (STL version). -- -genPrintVisitorList :: (Cat, [Rule]) -> Doc -genPrintVisitorList (cat@(ListCat _), rules) = vcat - [ "void PrintAbsyn::visit" <> lty <> parens (lty <+> "*" <> vname) +genPrintVisitorList :: (CppStdMode, Cat, [Rule]) -> Doc +genPrintVisitorList (mode, cat@(ListCat _), rules) = vcat + [ "void PrintAbsyn::visit" <> lty <> parens (ltyarg <+> varg) , codeblock 2 [ "iter" <> lty <> parens (vname <> "->begin()" <> comma <+> vname <> "->end()") <> semi ] , "" @@ -433,10 +442,15 @@ genPrintVisitorList (cat@(ListCat _), rules) = vcat , "" ] where + beyondAnsi = case mode of + CppStdBeyondAnsi _ -> True + CppStdAnsi _ -> False cl = identCat (normCat cat) - lty = text cl -- List type + lty = text cl -- List type + ltyarg = text $ wrapUniquePtrIf beyondAnsi cl -- List type arg itty = lty <> "::const_iterator" -- Iterator type vname = text $ map toLower cl + varg = text $ wrapPointerIf (not beyondAnsi) (map toLower cl) prules = sortRulesByPrecedence rules swRules f = switchByPrecedence "_i_" $ map (second $ sep . prListRule_) $ @@ -448,6 +462,16 @@ genPrintVisitorList (cat@(ListCat _), rules) = vcat genPrintVisitorList _ = error "genPrintVisitorList expects a ListCat" +genPositionToken :: String -> String +genPositionToken cat = unlines $ + -- a position token + [ "void PrintAbsyn::visit" ++ cat ++ "(" ++ cat ++ " *p)" + , "{" + , " visitIdent(p->string_);" + , "}" + , "" + ] + -- | Only render the rhs (items) of a list rule. prListRule_ :: IsFun a => Rul a -> [Doc] @@ -464,9 +488,9 @@ prListRule_ (Rule _ _ items _) = for items $ \case -- This is the only part of the pretty printer that differs significantly -- between the versions with and without STL. -- The present version has been adapted from CFtoCPrinter. -genPrintVisitorListNoStl :: (Cat, [Rule]) -> String -genPrintVisitorListNoStl (cat@(ListCat _), rules) = unlines $ concat - [ [ "void PrintAbsyn::visit" ++ cl ++ "("++ cl ++ " *" ++ vname ++ ")" +genPrintVisitorListNoStl :: (CppStdMode, Cat, [Rule]) -> String +genPrintVisitorListNoStl (mode, cat@(ListCat _), rules) = unlines $ concat + [ [ "void PrintAbsyn::visit" ++ cl ++ "("++ wrapUniquePtrIf beyondAnsi cl +++ varg ++ ")" , "{" , " if (" ++ vname +++ "== 0)" , " { /* nil */" @@ -491,20 +515,24 @@ genPrintVisitorListNoStl (cat@(ListCat _), rules) = unlines $ concat ] ] where - cl = identCat (normCat cat) - vname = map toLower cl - pre = vname ++ "->" - prules = sortRulesByPrecedence rules - swRules f = switchByPrecedence "_i_" $ + beyondAnsi = case mode of + CppStdBeyondAnsi _ -> True + CppStdAnsi _ -> False + cl = identCat (normCat cat) + vname = map toLower cl + varg = wrapPointerIf (not beyondAnsi) (map toLower cl) + pre = vname ++ "->" + prules = sortRulesByPrecedence rules + swRules f = switchByPrecedence "_i_" $ map (second $ sep . map text . prPrintRule_ pre) $ - uniqOn fst $ filter f prules - -- Discard duplicates, can only handle one rule per precedence. + uniqOn fst $ filter f prules + -- Discard duplicates, can only handle one rule per precedence. genPrintVisitorListNoStl _ = error "genPrintVisitorListNoStl expects a ListCat" --Pretty Printer methods for a rule. -prPrintRule :: Maybe String -> Rule -> String -prPrintRule inPackage r@(Rule fun _ _ _) | isProperLabel fun = unlines $ concat - [ [ "void PrintAbsyn::visit" ++ funName fun ++ "(" ++ funName fun +++ "*" ++ fnm ++ ")" +prPrintRule :: Bool -> Maybe String -> Rule -> String +prPrintRule beyondAnsi inPackage r@(Rule fun _ _ _) | isProperLabel fun = unlines $ concat + [ [ "void PrintAbsyn::visit" ++ visitFunName ++ "(" ++ vararg +++ fnm ++ ")" , "{" , " int oldi = _i_;" , parenCode "_L_PAREN" @@ -519,10 +547,13 @@ prPrintRule inPackage r@(Rule fun _ _ _) | isProperLabel fun = unlines $ concat ] ] where - p = precRule r - parenCode x = " if (oldi > " ++ show p ++ ") render(" ++ nsDefine inPackage x ++ ");" - fnm = "p" --old names could cause conflicts -prPrintRule _ _ = "" + visitFunName = funName fun + vararg = wrapUniquePtrIf beyondAnsi (funName fun) + p = precRule r + parenCode x = " if (oldi > " ++ show p ++ ") render(" ++ nsDefine inPackage x ++ ");" + fnm = if beyondAnsi then "p" else "*p" --old names could cause conflicts + +prPrintRule _ _ _ = "" prPrintRule_ :: IsFun a => String -> Rul a -> [String] prPrintRule_ pre (Rule _ _ items _) = map (prPrintItem pre) $ numVars items diff --git a/source/src/BNFC/Backend/CPP/STL.hs b/source/src/BNFC/Backend/CPP/STL.hs index d43f5e01..4eac3e2a 100644 --- a/source/src/BNFC/Backend/CPP/STL.hs +++ b/source/src/BNFC/Backend/CPP/STL.hs @@ -22,7 +22,7 @@ import BNFC.Backend.Base import BNFC.Backend.C ( bufferH, bufferC, comment, testfileHeader ) import BNFC.Backend.C.CFtoBisonC ( cf2Bison, unionBuiltinTokens, positionCats, varName ) import BNFC.Backend.C.CFtoFlexC ( cf2flex, ParserMode(..), beyondAnsi, parserPackage, parserName, stlParser ) -import BNFC.Backend.CPP.Common ( commentWithEmacsModeHint ) +import BNFC.Backend.CPP.Common ( commentWithEmacsModeHint, CppStdMode(..) ) import BNFC.Backend.CPP.Makefile import BNFC.Backend.CPP.STL.CFtoSTLAbs import BNFC.Backend.CPP.STL.CFtoCVisitSkelSTL @@ -48,7 +48,7 @@ makeCppStl opts cf = do let (skelH, skelC) = cf2CVisitSkel True (inPackage opts) cf mkCppFile ("Skeleton" ++ hExt) skelH mkCppFile ("Skeleton" ++ cppExt) skelC - let (prinH, prinC) = cf2CPPPrinter True (inPackage opts) cf hExt + let (prinH, prinC) = cf2CPPPrinter cppStdMode True (inPackage opts) cf hExt mkCppFile ("Printer" ++ hExt) prinH mkCppFile ("Printer" ++ cppExt) prinC mkCppFile ("Test" ++ cppExt) (cpptest (inPackage opts) cf hExt) diff --git a/source/src/BNFC/Backend/CPP/STL/CFtoSTLAbs.hs b/source/src/BNFC/Backend/CPP/STL/CFtoSTLAbs.hs index 73237160..4688afb8 100644 --- a/source/src/BNFC/Backend/CPP/STL/CFtoSTLAbs.hs +++ b/source/src/BNFC/Backend/CPP/STL/CFtoSTLAbs.hs @@ -31,9 +31,6 @@ import BNFC.Utils ( (+++), applyWhen ) import BNFC.Backend.CPP.Common import BNFC.Backend.CPP.STL.STLUtils -data CppStdMode - = CppStdAnsi Ansi -- ^ @Ansi@ mode. - | CppStdBeyondAnsi Ansi -- ^ @BeyondAnsi@ mode. --The result is two files (.H file, .C file) @@ -93,7 +90,7 @@ mkHFile rp mode inPackage cabs cf = unlines }, "", "/******************** Visitor Interfaces ********************/", - prVisitor cabs, + prVisitor mode cabs, "", prVisitable, "", @@ -127,20 +124,24 @@ prVisitable = unlines [ "};" ] -prVisitor :: CAbs -> String -prVisitor cf = unlines [ +prVisitor :: CppStdMode -> CAbs -> String +prVisitor mode cf = unlines [ "class Visitor", "{", "public:", " virtual ~Visitor() {}", unlines - [" virtual void visit"++c++"("++c++" *p) = 0;" | c <- allClasses cf, - notElem c (defineds cf)], + [" virtual void visit"++c++"("++ wrapUniquePtrIf isBeyondAnsi c +++ vararg ++") = 0;" | c <- allClasses cf, notElem c (defineds cf)], "", unlines - [" virtual void visit"++c++"(" ++c++" x) = 0;" | c <- allNonClasses cf], + [" virtual void visit"++c++"("++c++" x) = 0;" | c <- allNonClasses cf], "};" - ] + ] + where + isBeyondAnsi = case mode of + CppStdAnsi _ -> False + CppStdBeyondAnsi _ -> True + vararg = if isBeyondAnsi then "p" else "*p" prAbs :: CppStdMode -> RecordPositions -> String -> String prAbs mode rp c = @@ -157,7 +158,7 @@ prAbs mode rp c = "class " ++ c ++ " : public Visitable", "{", "public:", - " virtual std::unique_ptr<" ++ c ++ "> clone() const = 0;", + " virtual" +++ wrapUniquePtrIf True c +++ "clone() const = 0;", if rp == RecordPositions then " int line_number, char_number;" else "", "};" ]; @@ -229,7 +230,7 @@ prList mode (c, b) = case mode of { "class " ++c++ " : public Visitable" , "{" , "public:" - , " std::vector>" +++ childClassVarName ++ ";" + , " std::vector<" ++ wrapUniquePtrIf True childClass++ ">" +++ childClassVarName ++ ";" , "" -- ref: https://stackoverflow.com/questions/51148797/how-can-i-define-iterator-and-const-iterator-in-my-class-while-i-uses-stdvecto , " // define iterator and const_iterator, expose it" @@ -249,7 +250,7 @@ prList mode (c, b) = case mode of { , " ~" ++ c ++ "();" , " virtual void accept(Visitor *v);" , " std::unique_ptr<" ++ c ++ "> clone() const;" - , " void cons(std::unique_ptr<" ++ childClass ++ ">);" + , " void cons(" ++ wrapUniquePtrIf True childClass ++ ");" , " void reverse();" , "};" , "" @@ -291,7 +292,7 @@ prConC mode c fcs@(f,_) = unlines [ prConstructorC mode fcs, prCopyC mode fcs, prDestructorC mode fcs, - prAcceptC f, + prAcceptC mode f, prCloneC mode c f, "" ] @@ -328,7 +329,7 @@ prListC mode (c,b) = unlines c ++ "::~" ++ c ++"() = default;", ""]; } - , prAcceptC c + , prAcceptC mode c , prCloneC mode c c , prConsC mode c b ] @@ -337,13 +338,21 @@ prListC mode (c,b) = unlines --The standard accept function for the Visitor pattern -prAcceptC :: String -> String -prAcceptC ty = unlines [ - "void " ++ ty ++ "::accept(Visitor *v)", - "{", - " v->visit" ++ ty ++ "(this);", - "}" - ] +prAcceptC :: CppStdMode -> String -> String +prAcceptC mode ty = case mode of { + CppStdAnsi _ -> unlines [ + "void " ++ ty ++ "::accept(Visitor *v)", + "{", + " v->visit" ++ ty ++ "(this);", + "}" + ]; + CppStdBeyondAnsi _ -> unlines [ + "void " ++ty++ "::accept(Visitor *v)", + "{", + " v->visit" ++ ty ++ "(std::make_unique<" ++ty++ ">(*this));", + "}" + ]; + } --The cloner makes a new deep copy of the object prCloneC :: CppStdMode -> String -> String -> String @@ -355,7 +364,7 @@ prCloneC mode f c = case mode of { "}" ]; CppStdBeyondAnsi _ -> unlines [ - "std::unique_ptr<" ++ f ++ "> " ++ c ++ "::clone() const ", + wrapUniquePtrIf True f +++ c ++ "::clone() const ", "{", " return std::make_unique<" ++ c ++ ">(*this);", "}" diff --git a/source/src/BNFC/Backend/Common/OOAbstract.hs b/source/src/BNFC/Backend/Common/OOAbstract.hs index 801ef57e..881b5cfe 100644 --- a/source/src/BNFC/Backend/Common/OOAbstract.hs +++ b/source/src/BNFC/Backend/Common/OOAbstract.hs @@ -99,9 +99,3 @@ classVar c = map toLower c ++ "_" pointerIf :: Bool -> String -> String pointerIf b v = if b then "*" ++ v else v - -wrapUniquePtrIf :: Bool -> String -> String -wrapUniquePtrIf b v = if b then "std::unique_ptr<" ++v++">" else v - -wrapMoveIf :: Bool -> String -> String -wrapMoveIf b v = if b then "std::move(" ++v++")" else v