Changeset View
Changeset View
Standalone View
Standalone View
src/parseJson.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 41 | if (p.empty()) { | |||
---|---|---|---|---|---|
92 | f.append({ | 92 | f.append({ | ||
93 | .type = BindingType::QByteArray, | 93 | .type = BindingType::QByteArray, | ||
94 | .name = "QByteArray", | 94 | .name = "QByteArray", | ||
95 | .cppSetType = "const QByteArray&", | 95 | .cppSetType = "const QByteArray&", | ||
96 | .cSetType = "qbytearray_t", | 96 | .cSetType = "qbytearray_t", | ||
97 | .rustType = "Vec<u8>", | 97 | .rustType = "Vec<u8>", | ||
98 | .rustTypeInit = "Vec::new()" | 98 | .rustTypeInit = "Vec::new()" | ||
99 | }); | 99 | }); | ||
100 | f.append({ | ||||
101 | .type = BindingType::Void, | ||||
102 | .name = "void", | ||||
103 | .cppSetType = "void", | ||||
104 | .cSetType = "void", | ||||
105 | .rustType = "()", | ||||
106 | .rustTypeInit = "()", | ||||
107 | }); | ||||
100 | p = f; | 108 | p = f; | ||
101 | } | 109 | } | ||
102 | return p; | 110 | return p; | ||
103 | } | 111 | } | ||
104 | 112 | | |||
105 | BindingTypeProperties parseBindingType(const QString& value) { | 113 | BindingTypeProperties parseBindingType(const QString& value) { | ||
106 | for (auto type: bindingTypeProperties()) { | 114 | for (auto type: bindingTypeProperties()) { | ||
107 | if (value == type.name) { | 115 | if (value == type.name) { | ||
Show All 20 Lines | 134 | parseProperty(const QString& name, const QJsonObject& json) { | |||
128 | p.name = name; | 136 | p.name = name; | ||
129 | p.type = parseBindingType(json.value("type").toString()); | 137 | p.type = parseBindingType(json.value("type").toString()); | ||
130 | p.write = json.value("write").toBool(); | 138 | p.write = json.value("write").toBool(); | ||
131 | p.optional = json.value("optional").toBool(); | 139 | p.optional = json.value("optional").toBool(); | ||
132 | p.rustByValue = json.value("rustByValue").toBool(); | 140 | p.rustByValue = json.value("rustByValue").toBool(); | ||
133 | return p; | 141 | return p; | ||
134 | } | 142 | } | ||
135 | 143 | | |||
144 | Argument | ||||
145 | parseArgument(const QJsonObject& json) { | ||||
146 | Argument arg; | ||||
147 | arg.name = json.value("name").toString(); | ||||
148 | arg.type = parseBindingType(json.value("type").toString()); | ||||
149 | QTextStream out(stdout); | ||||
150 | out.flush(); | ||||
151 | if (arg.type.type == BindingType::Object) { | ||||
152 | QTextStream err(stderr); | ||||
153 | err << QCoreApplication::translate("main", | ||||
154 | "'%1' is not a supported type in argument \"%2\". Only use the basic QT types for now\n").arg(arg.type.name, arg.name); | ||||
155 | err.flush(); | ||||
156 | exit(1); | ||||
157 | } | ||||
158 | return arg; | ||||
159 | } | ||||
160 | | ||||
161 | QList<Argument> | ||||
162 | parseArguments(const QJsonArray& json) { | ||||
163 | QList<Argument> args; | ||||
164 | for(const auto& a: json) { | ||||
165 | args.push_back(parseArgument(a.toObject())); | ||||
166 | } | ||||
167 | return args; | ||||
168 | } | ||||
169 | | ||||
170 | Function | ||||
171 | parseFunction(const QString& name, const QJsonObject& json) { | ||||
172 | Function f; | ||||
173 | f.name = name; | ||||
174 | f.mut = json.value("mut").toBool(); | ||||
175 | f.type = parseBindingType(json.value("return").toString()); | ||||
176 | if (f.type.type == BindingType::Object) { | ||||
177 | QTextStream err(stderr); | ||||
178 | err << QCoreApplication::translate("main", | ||||
179 | "'%1' is not a supported return type in function \"%2\". Only use the basic QT types for now\n").arg(f.type.name, f.name); | ||||
180 | err.flush(); | ||||
181 | exit(1); | ||||
182 | } | ||||
183 | f.args = parseArguments(json.value("arguments").toArray()); | ||||
184 | return f; | ||||
185 | } | ||||
186 | | ||||
136 | Qt::ItemDataRole parseItemDataRole(const QString& s) { | 187 | Qt::ItemDataRole parseItemDataRole(const QString& s) { | ||
137 | const QString name = s.left(1).toUpper() + s.mid(1) + "Role"; | 188 | const QString name = s.left(1).toUpper() + s.mid(1) + "Role"; | ||
138 | int v = QMetaEnum::fromType<Qt::ItemDataRole>() | 189 | int v = QMetaEnum::fromType<Qt::ItemDataRole>() | ||
139 | .keyToValue(name.toUtf8()); | 190 | .keyToValue(name.toUtf8()); | ||
140 | if (v >= 0) { | 191 | if (v >= 0) { | ||
141 | return (Qt::ItemDataRole)v; | 192 | return (Qt::ItemDataRole)v; | ||
142 | } | 193 | } | ||
143 | QTextStream err(stderr); | 194 | QTextStream err(stderr); | ||
Show All 33 Lines | 227 | } else if (type == "Tree") { | |||
177 | o.type = ObjectType::Tree; | 228 | o.type = ObjectType::Tree; | ||
178 | } else { | 229 | } else { | ||
179 | o.type = ObjectType::Object; | 230 | o.type = ObjectType::Object; | ||
180 | } | 231 | } | ||
181 | const QJsonObject& properties = json.value("properties").toObject(); | 232 | const QJsonObject& properties = json.value("properties").toObject(); | ||
182 | for (const QString& key: properties.keys()) { | 233 | for (const QString& key: properties.keys()) { | ||
183 | o.properties.append(parseProperty(key, properties[key].toObject())); | 234 | o.properties.append(parseProperty(key, properties[key].toObject())); | ||
184 | } | 235 | } | ||
236 | const QJsonObject& functions = json.value("functions").toObject(); | ||||
237 | for (const QString& key: functions.keys()) { | ||||
238 | o.functions.append(parseFunction(key, functions[key].toObject())); | ||||
239 | } | ||||
185 | QTextStream err(stderr); | 240 | QTextStream err(stderr); | ||
186 | const QJsonObject& itemProperties = json.value("itemProperties").toObject(); | 241 | const QJsonObject& itemProperties = json.value("itemProperties").toObject(); | ||
187 | if (o.type != ObjectType::Object && itemProperties.size() == 0) { | 242 | if (o.type != ObjectType::Object && itemProperties.size() == 0) { | ||
188 | err << QCoreApplication::translate("main", | 243 | err << QCoreApplication::translate("main", | ||
189 | "No item properties are defined for %1.\n").arg(o.name); | 244 | "No item properties are defined for %1.\n").arg(o.name); | ||
190 | err.flush(); | 245 | err.flush(); | ||
191 | exit(1); | 246 | exit(1); | ||
192 | } else if (o.type == ObjectType::Object && itemProperties.size() > 0) { | 247 | } else if (o.type == ObjectType::Object && itemProperties.size() > 0) { | ||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |