Add some methods in ReplaceAll 58/290158/1
authorjh9216.park <jh9216.park@samsung.com>
Tue, 21 Mar 2023 03:32:59 +0000 (23:32 -0400)
committerjh9216.park <jh9216.park@samsung.com>
Tue, 21 Mar 2023 03:32:59 +0000 (23:32 -0400)
commit3cbb3d6bc91414ba286ad7380c836f53e3a58e1b
tree0a6faf62fe85daf68e09084e4923605aa447cf36
parentcaebc9f226364dc6cbe94947e897bfce43b98b39
Add some methods in ReplaceAll

- Add Repeat() method
- Add Remove() method
- Add Replace() method

- Example
constexpr const char CB_FUNCTION[] =
R"__rs_cb(
            pub fn <FN_NAME>(&self, <PARAMS>) <RET>{
                let p = Parcel::new();
                let port = self.proxy.get_port(PortType::Main);
                p.write_i32(MethodId::<METHOD_ID> as i32);
                <SENDER_BODY*><ID>.write_parcel(&mut p);</SENDER_BODY*>
                p.send(&port);

                <SYNC?>let parcel_received = Parcel::from(&port);
                <RECEIVER_BODY*><ID>.read_parcel(&mut parcel_received);</RECEIVER_BODY*>

                <HAS_RETURN?>let mut __ret: <TYPE> = Default::default();
                __ret.read_parcel(&mut parcel_received);
                __ret</HAS_RETURN?></SYNC?>
            }
)__rs_cb";

ret += ReplaceAll(::CB_FUNCTION)
        .Replace("FN_NAME", i->GetID())
        .Replace("PARAMS", GetParameters(i->GetParameters()))
        .Replace("RET", GetRetExpr(*i))
        .Replace("METHOD_ID", (*i).GetID())
        .Repeat("SENDER_BODY", (*i).GetParameters(),
            [](ReplaceAll* ra, const std::unique_ptr<tidl::Parameter>& i) {
          if (i->GetParameterType().GetDirection() == ParameterType::Direction::OUT)
            return false;
          ra->Replace("ID", i->GetID());
          return true;
        })
        .Remove("SYNC", (*i).GetMethodType() == Declaration::MethodType::ASYNC)
        .Repeat("RECEIVER_BODY", (*i).GetParameters(),
            [](ReplaceAll* ra, const std::unique_ptr<tidl::Parameter>& i) {
          if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN)
            return false;
          ra->Replace("ID", i->GetID());
          return true;
        })
        .Remove("HAS_RETURN", (*i).GetType().ToString() == "void" )
        .Replace("TYPE", [&]() {
          return ConvertTypeToString((*i).GetType());
        });

Change-Id: Ic77369977767690181f192ebd6c21df802920ca6
Signed-off-by: jh9216.park <jh9216.park@samsung.com>
idlc/gen/replace_all.cc
idlc/gen/replace_all.h