This patch supports map and set container types.
Change-Id: I9bf1e9164b1b7050b94584194064b8f339d24112
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
ps->ReportError("syntax error. The file should be included in only one container.", @1.begin.line);
}
+ if ($1->ToString() == "set") {
+ if (!tidl::BaseType::IsKeyType($3)) {
+ ps->ReportError("syntax error. The key type should be 'char', 'int', 'short', 'long', 'string', 'bool', 'float' and 'double.", @1.begin.line);
+ }
+ }
+
$$ = new tidl::BaseType($1->ToString(), $1->GetComments());
$$->SetMetaType($3);
delete $1;
ps->ReportError("syntax error. The container type must be \"map\".", @1.begin.line);
delete $1;
} else {
+ if (!tidl::BaseType::IsKeyType($3)) {
+ ps->ReportError("syntax error. The key type should be 'char', 'int', 'short', 'long', 'string', 'bool', 'float' and 'double.", @1.begin.line);
+ }
+
$$ = new tidl::BaseType($1->ToString(), $1->GetComments());
$$->SetKeyType($3);
$$->SetValueType($5);
635, 640, 644, 648, 652, 656, 662, 670, 681, 687,
690, 693, 698, 701, 705, 711, 714, 720, 723, 740,
743, 747, 751, 755, 759, 763, 767, 771, 781, 785,
- 789, 837, 864, 878, 891, 895, 899, 907
+ 789, 837, 864, 884, 901, 905, 909, 917
};
#endif
ps->ReportError("syntax error. The file should be included in only one container.", (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-3)].yystate.yyloc).begin.line);
}
+ if ((YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->ToString() == "set") {
+ if (!tidl::BaseType::IsKeyType((YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.b_type))) {
+ ps->ReportError("syntax error. The key type should be 'char', 'int', 'short', 'long', 'string', 'bool', 'float' and 'double.", (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-3)].yystate.yyloc).begin.line);
+ }
+ }
+
((*yyvalp).b_type) = new tidl::BaseType((YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->ToString(), (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->GetComments());
((*yyvalp).b_type)->SetMetaType((YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.b_type));
delete (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
}
}
-#line 2579 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
+#line 2585 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
break;
case 93:
-#line 878 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc.yy"
+#line 884 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc.yy"
{
if ((YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token)->ToString() != "map") {
ps->ReportError("syntax error. The container type must be \"map\".", (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-5)].yystate.yyloc).begin.line);
delete (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token);
} else {
+ if (!tidl::BaseType::IsKeyType((YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.b_type))) {
+ ps->ReportError("syntax error. The key type should be 'char', 'int', 'short', 'long', 'string', 'bool', 'float' and 'double.", (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-5)].yystate.yyloc).begin.line);
+ }
+
((*yyvalp).b_type) = new tidl::BaseType((YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token)->ToString(), (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token)->GetComments());
((*yyvalp).b_type)->SetKeyType((YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.b_type));
((*yyvalp).b_type)->SetValueType((YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.b_type));
delete (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token);
}
}
-#line 2595 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
+#line 2605 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
break;
case 94:
-#line 891 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc.yy"
+#line 901 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc.yy"
{
((*yyvalp).token) = new tidl::Token("list", (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
delete (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
}
-#line 2604 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
+#line 2614 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
break;
case 95:
-#line 895 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc.yy"
+#line 905 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc.yy"
{
((*yyvalp).token) = new tidl::Token("array", (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
delete (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
}
-#line 2613 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
+#line 2623 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
break;
case 96:
-#line 899 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc.yy"
+#line 909 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc.yy"
{
if (ps->GetVersion() < 2) {
ps->ReportError("syntax error. \"No identifier\".", (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
((*yyvalp).token) = new tidl::Token("map", (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
delete (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
}
-#line 2626 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
+#line 2636 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
break;
case 97:
-#line 907 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc.yy"
+#line 917 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc.yy"
{
if (ps->GetVersion() < 2) {
ps->ReportError("syntax error. \"No identifier\".", (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
((*yyvalp).token) = new tidl::Token("set", (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
delete (YY_CAST (yyGLRStackItem const *, yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
}
-#line 2639 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
+#line 2649 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
break;
-#line 2643 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
+#line 2653 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
default: break;
}
// User initialization code.
yylloc.initialize ();
-#line 4105 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
+#line 4115 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
if (! yyinitGLRStack (yystackp, YYINITDEPTH))
-#line 917 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc.yy"
+#line 927 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc.yy"
#include <ctype.h>
}
-#line 4405 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
+#line 4415 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
/*------------------.
| Report an error. |
namespace yy {
-#line 4421 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
+#line 4431 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
/// Build a parser object.
parser::parser (tidl::Parser* ps_yyarg)
#endif
} // yy
-#line 4509 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
+#line 4519 "/opt/data/tizen/public/platform/core/appfw/tidl/idlc/ast/tidlc_y.cpp"
return type->ToString() == "file";
}
+bool BaseType::IsKeyType(const BaseType* type) {
+ if (type == nullptr)
+ return false;
+
+ if (type->GetMetaType() != nullptr ||
+ type->GetKeyType() != nullptr)
+ return false;
+
+ if (type->ToString() == "char" ||
+ type->ToString() == "int" ||
+ type->ToString() == "short" ||
+ type->ToString() == "string" ||
+ type->ToString() == "bool" ||
+ type->ToString() == "float" ||
+ type->ToString() == "double")
+ return true;
+
+ return false;
+}
+
ParameterType::ParameterType(BaseType* type)
: type_(type),
dir_(Direction::IN) {
}
static bool IsFile(const BaseType* type);
+ static bool IsKeyType(const BaseType* type);
private:
std::unique_ptr<BaseType> meta_type_;
bool IsObject(const BaseType& type) {
if (type.IsUserDefinedType() ||
type.GetMetaType() != nullptr ||
+ type.GetKeyType() != nullptr ||
type.ToString() == "string" ||
type.ToString() == "bundle" ||
type.ToString() == "file")
{"file", "File"},
{"bundle", "Bundle"},
{"void", "void"},
- {"array", "std::vector"}
+ {"array", "std::vector"},
+ {"map", "std::map"},
+ {"set", "std::set"}
};
parcel_type_map_ = {
ConvertTypeToString(*(type.GetMetaType())) + ">";
}
+ if (type.GetKeyType() != nullptr && type.GetValueType() != nullptr) {
+ return type_map_[type.ToString()] + "<" +
+ ConvertTypeToString(*(type.GetKeyType())) + ", " +
+ ConvertTypeToString(*(type.GetValueType())) + ">";
+ }
+
return type_map_[type.ToString()];
}
AddUnitType("delegate",
BaseType(iface.GetID() + "::CallbackBase", "", true));
AddUnitType(decl->GetID(), BaseType(decl->GetID(), "", true));
+ } else if (decl->GetMethodType() == Declaration::MethodType::SYNC) {
+ auto& type = decl->GetType();
+ AddUnitType(type.GetFullName(false), BaseType(type));
}
for (const auto& param : decl->GetParameters()) {
AddUnitType(meta_type->GetFullName(false), BaseType(*meta_type));
}
+ if (type.GetKeyType() != nullptr) {
+ auto key_type = type.GetKeyType();
+ AddUnitType(key_type->GetFullName(false), BaseType(*key_type));
+
+ if (type.GetValueType() != nullptr) {
+ auto value_type = type.GetValueType();
+ AddUnitType(value_type->GetFullName(false), BaseType(*value_type));
+ }
+ }
+
unit_types_[std::move(name)] = std::move(type);
}
std::string CppGeneratorBase::GenUnitImplSerializer(const BaseType& type) {
std::string code;
- if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) {
+ if (type.IsUserDefinedType() || type.GetMetaType() != nullptr ||
+ type.GetKeyType() != nullptr) {
if (IsDelegateType(type)) {
code = CB_UNIT_IMPL_SERIALIZER_DELEGATE;
} else {
code = CB_UNIT_MAP_ARRAY_WRITE;
} else if (type.ToString() == "list") {
code = CB_UNIT_MAP_LIST_WRITE;
+ } else if (type.ToString() == "map") {
+ code = CB_UNIT_MAP_MAP_WRITE;
+ } else if (type.ToString() == "set") {
+ code = CB_UNIT_MAP_SET_WRITE;
} else {
for (auto& block : GetDocument().GetBlocks()) {
if (block->GetType() == Block::TYPE_STRUCTURE) {
std::string CppGeneratorBase::GenUnitImplDeserializer(const BaseType& type) {
std::string code;
- if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) {
+ if (type.IsUserDefinedType() || type.GetMetaType() != nullptr ||
+ type.GetKeyType() != nullptr) {
if (IsDelegateType(type)) {
code = ReplaceAll(CB_UNIT_IMPL_DESERIALIZER_DELEGATE)
.Change("<IFACE_NAME>", GetInterfaceNameFromDelegate(type));
} else if (type.ToString() == "list") {
code = ReplaceAll(CB_UNIT_MAP_LIST_READ)
.Change("<TYPE>", ConvertTypeToString(*type.GetMetaType()));
+ } else if (type.ToString() == "map") {
+ code = ReplaceAll(CB_UNIT_MAP_MAP_READ)
+ .Change("<KEY_TYPE>", ConvertTypeToString(*type.GetKeyType()))
+ .Change("<VALUE_TYPE>", ConvertTypeToString(*type.GetValueType()));
+ } else if (type.ToString() == "set") {
+ code = ReplaceAll(CB_UNIT_MAP_SET_READ)
+ .Change("<KEY_TYPE>", ConvertTypeToString(*type.GetMetaType()));
} else {
for (auto& block : GetDocument().GetBlocks()) {
if (block->GetType() == Block::TYPE_STRUCTURE) {
#include <rpc-port.h>
#include <rpc-port-parcel.h>
+#include <map>
#include <memory>
+#include <set>
#include <string>
#include <stdexcept>
#include <utility>
#include <atomic>
#include <functional>
#include <list>
+#include <map>
#include <memory>
#include <mutex>
+#include <set>
#include <string>
#include <vector>
#include <unordered_map>
unit_map.Write(std::to_string(index++), data);
)__cpp_cb";
+constexpr const char CB_UNIT_MAP_MAP_WRITE[] =
+R"__cpp_cb(
+unit_map.Write("size", static_cast<int>(value.size() & INT_MAX));
+
+int index = 0;
+for (auto& iter : value) {
+ auto& key = iter.first;
+ unit_map.Write("key-" + std::to_string(index), key);
+ auto& val = iter.second;
+ unit_map.Write("value-" + std::to_string(index++), val);
+}
+)__cpp_cb";
+
+constexpr const char CB_UNIT_MAP_SET_WRITE[] =
+R"__cpp_cb(
+unit_map.Write("size", static_cast<int>(value.size() & INT_MAX));
+
+int index = 0;
+for (auto& key : value)
+ unit_map.Write("key-" + std::to_string(index++), key);
+)__cpp_cb";
+
/**
* <NAME> The name of the element of the value.
*/
}
)__cpp_cb";
+/**
+ * <KEY_TYPE> The type of the key of the map.
+ * <VALUE_TYPE> The type of the value of the map.
+ */
+constexpr const char CB_UNIT_MAP_MAP_READ[] =
+R"__cpp_cb(
+int tmp_size = 0;
+unit_map.Read("size", tmp_size);
+
+for (int index = 0; index < tmp_size; ++index) {
+ <KEY_TYPE> tmp_key;
+ unit_map.Read("key-" + std::to_string(index), tmp_key);
+ <VALUE_TYPE> tmp_value;
+ unit_map.Read("value-" + std::to_string(index), tmp_value);
+ value[tmp_key] = tmp_value;
+}
+)__cpp_cb";
+
+/**
+ * <KEY_TYPE> The type of the key of the map.
+ */
+constexpr const char CB_UNIT_MAP_SET_READ[] =
+R"__cpp_cb(
+int tmp_size = 0;
+unit_map.Read("size", tmp_size);
+
+for (int index = 0; index < tmp_size; ++index) {
+ <KEY_TYPE> tmp_key;
+ unit_map.Read("key-" + std::to_string(index), tmp_key);
+ value.insert(tmp_key);
+}
+)__cpp_cb";
+
/**
* <NAME> The name of the element of the value.
*/
struct Envelope {
list<string> string_list;
array<bundle> bundle_array;
+ map<string, int> string_int_map;
+ set<string> string_iset;
}
interface Message {
int Send(string msg);
int SendFiles(list<file> files);
int SendFile(file f);
+ int SendEnvelope(Envelope envelope);
}