class_view.hpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  1. #ifndef __CODE_GENERATOR_CODE_ANALYSIS_H__
  2. #define __CODE_GENERATOR_CODE_ANALYSIS_H__
  3. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  4. #pragma once
  5. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  6. #include <iostream>
  7. #include <filesystem>
  8. #include <regex>
  9. #include <fstream>
  10. #include "../robot/robotics/utils.hpp"
  11. using namespace robotics;
  12. struct file_info {
  13. /**
  14. * @brief 路径
  15. */
  16. std::string file_path;
  17. /**
  18. * @brief 代码
  19. */
  20. std::vector<std::string> content;
  21. /**
  22. * @brief 类型 0控制器 1实体类 2soap
  23. */
  24. int class_type = 0;
  25. };
  26. struct PropertyInfo {
  27. /**
  28. * @brief 类型名称
  29. */
  30. std::string type_name;
  31. /**
  32. * @brief 属性名称
  33. */
  34. std::string prop_name;
  35. /**
  36. * @brief json字段名称
  37. */
  38. std::string json_name;
  39. /**
  40. * @brief 数据库字段名称
  41. */
  42. std::string sql_name;
  43. /**
  44. * @brief excel字段名称
  45. */
  46. std::string excel_name;
  47. /**
  48. * @brief 不序列化json 默认false
  49. */
  50. bool no_json = false;
  51. /**
  52. * @brief 不创建数据库字段 默认false
  53. */
  54. bool no_sql = false;
  55. /**
  56. * @brief 不导出excel字段 默认false
  57. */
  58. bool no_excel = false;
  59. /**
  60. * @brief 字段索引
  61. */
  62. bool sql_key = false;
  63. /**
  64. * @brief 二进制序列化
  65. */
  66. bool no_archive = false;
  67. };
  68. struct ParameterInfo {
  69. /**
  70. * @brief 参数名称
  71. */
  72. std::string name;
  73. /**
  74. * @brief 参数类型
  75. */
  76. std::string type;
  77. /**
  78. * @brief 参数名称
  79. */
  80. std::string parameter_name;
  81. /**
  82. * @brief 类型名称
  83. */
  84. std::string argument_type = "robotics::v3::mvc::argument_type::Binary";
  85. /**
  86. * @brief 提取位置 QUERY Body Header
  87. */
  88. std::string from_storage_type = "robotics::v3::mvc::from_storage_type::QUERY";
  89. };
  90. struct MethodInfo {
  91. /**
  92. * @brief 身份验证
  93. */
  94. bool authen = true;
  95. /**
  96. * @brief 未登录跳转
  97. */
  98. std::string authen_jump;
  99. /**
  100. * @brief
  101. */
  102. std::string method = "robotics::v3::mvc::http_method::GET";
  103. /**
  104. * @brief
  105. */
  106. std::string content_type = "application/x-www-form-urlencoded";
  107. /**
  108. * @brief
  109. */
  110. std::string action_type;
  111. /**
  112. * @brief
  113. */
  114. std::string file_mapping;
  115. /**
  116. * @brief
  117. */
  118. std::string route;
  119. /**
  120. * @brief
  121. */
  122. std::string name;
  123. /**
  124. * @brief 函数签名
  125. */
  126. std::string signature;
  127. /**
  128. * @brief 参数
  129. */
  130. std::vector<ParameterInfo> parameters;
  131. };
  132. struct SoapParameterInfo {
  133. /**
  134. * @brief 类型
  135. */
  136. std::string type = "std::string";
  137. /**
  138. * @brief 参数类型
  139. */
  140. std::string argument_type = "robotics::v3::mvc::soap_argument_type::String";
  141. /**
  142. * @brief 参数名称
  143. */
  144. std::string parameter_name = "value";
  145. };
  146. struct soap_method_info {
  147. /**
  148. * @brief 方法名称
  149. */
  150. std::string name;
  151. /**
  152. * @brief 路由方法名称
  153. */
  154. std::string action_name;
  155. /**
  156. * @brief 函数签名
  157. */
  158. std::string signature;
  159. /**
  160. * @brief 参数
  161. */
  162. std::vector<SoapParameterInfo> parameters;
  163. };
  164. struct class_view_info {
  165. /**
  166. * @brief 0:控制器 1:实体类 2:soap
  167. */
  168. int class_type = 0;
  169. /**
  170. * @brief 是否是模板
  171. */
  172. bool is_template = false;
  173. /**
  174. * @brief 模板类型列表
  175. */
  176. std::vector<std::string> template_types;
  177. /**
  178. * @brief 模板参数列表
  179. */
  180. std::vector<std::string> template_parameters;
  181. /**
  182. * @brief 类名称
  183. */
  184. std::string class_name;
  185. /**
  186. * @brief 数据库表名称
  187. */
  188. std::string sql_table_name;
  189. /**
  190. * @brief 属性列表
  191. */
  192. std::vector<PropertyInfo> propertys;
  193. /**
  194. * @brief 控制器列表
  195. */
  196. std::vector<MethodInfo> methods;
  197. /**
  198. * @brief soap 方法列表
  199. */
  200. std::vector<soap_method_info> soap_methods;
  201. /**
  202. * @brief soap版本
  203. */
  204. std::string soap_version = "1.1";
  205. /**
  206. * @brief soap命名空间
  207. */
  208. std::string soap_namepsace = "http://tempuri.org/";
  209. /**
  210. * @brief soap路由
  211. */
  212. std::string soap_route;
  213. /**
  214. * @brief soap wsdl文件
  215. */
  216. std::string soap_wsdl;
  217. /**
  218. * @brief 头文件
  219. */
  220. std::string include;
  221. /**
  222. * @brief 反射
  223. */
  224. bool is_reflect = true;
  225. };
  226. class code_analysis_core {
  227. public:
  228. static std::vector<class_view_info> getClassView(std::filesystem::path path) {
  229. return code_analysis_core(path).getClassView();
  230. }
  231. protected:
  232. code_analysis_core(std::filesystem::path path) :
  233. _path(path) {
  234. }
  235. private:
  236. std::vector<class_view_info> getClassView() {
  237. std::vector<class_view_info> result;
  238. auto fileInfos = getiFileInfo();
  239. //控制器
  240. for (auto& it : fileInfos) {
  241. if (it.class_type != 0)
  242. continue;
  243. for (auto code : it.content) {
  244. std::regex pattern("class[ \r\n\t]{1,30}([a-zA-Z_0-9]{1,100})");
  245. std::smatch smatch;
  246. if (std::regex_search(code, smatch, pattern)) {
  247. if (smatch.size() == 2) {
  248. class_view_info add;
  249. add.include = it.file_path;
  250. add.class_type = 0;
  251. add.class_name = smatch[1];
  252. add.methods = getMethods(smatch.suffix());
  253. result.push_back(add);
  254. }
  255. }
  256. }
  257. }
  258. //实体类
  259. for (auto& it : fileInfos) {
  260. if (it.class_type != 1)
  261. continue;
  262. for (auto code : it.content) {
  263. //普通模板结构体
  264. {
  265. std::regex pattern("template[ \r\n\t]{0,30}<([\\s\\S]*?)>[ \r\n\t]{0,30}struct[ \r\n\t]{1,30}([a-zA-Z_0-9]{1,100})");
  266. std::smatch smatch;
  267. if (std::regex_search(code, smatch, pattern)) {
  268. if (smatch.size() == 3) {
  269. class_view_info add;
  270. add.include = it.file_path;
  271. add.class_type = 1;
  272. add.class_name = smatch[2];
  273. add.is_template = true;
  274. add.sql_table_name = smatch[2];
  275. auto templteTypeList = v3::utils::split(smatch[1], ",");
  276. for (auto& tempType : templteTypeList) {
  277. auto tempValue = v3::utils::split(tempType, " ");
  278. if (tempValue.size() == 2) {
  279. add.template_types.push_back(v3::utils::trim(tempValue[1]));
  280. }
  281. }
  282. add.propertys = getPropertys(smatch.suffix());
  283. result.push_back(add);
  284. code = smatch.suffix();
  285. }
  286. }
  287. }
  288. //带特性模板结构体
  289. {
  290. std::regex pattern("template[ \r\n\t]{0,30}<([\\s\\S]*?)>[ \r\n\t]{0,30}struct[ \r\n\t]{0,30}(\\[\\[[\\s\\S]*?\\]\\])[ \r\n\t]{0,30}([a-zA-Z_0-9]{1,100})[ \r\n\t]{0,30}\\{");
  291. std::smatch smatch;
  292. if (std::regex_search(code, smatch, pattern)) {
  293. if (smatch.size() == 4) {
  294. class_view_info add;
  295. add.include = it.file_path;
  296. add.class_type = 1;
  297. add.class_name = smatch[3];
  298. add.is_template = true;
  299. auto templteTypeList = v3::utils::split(smatch[1], ",");
  300. for (auto& tempType : templteTypeList) {
  301. auto tempValue = v3::utils::split(tempType, " ");
  302. if (tempValue.size() == 2) {
  303. add.template_types.push_back(v3::utils::trim(tempValue[1]));
  304. }
  305. }
  306. getTemplateParameter(smatch[2], add.template_types.size(), add);
  307. add.sql_table_name = add.sql_table_name.empty() ? add.class_name : add.sql_table_name;
  308. add.propertys = getPropertys("{" + smatch.suffix().str());
  309. result.push_back(add);
  310. code = smatch.suffix();
  311. }
  312. }
  313. }
  314. //普通结构体
  315. {
  316. std::regex pattern("struct[ \r\n\t]{1,30}([a-zA-Z_0-9]{1,100})");
  317. std::smatch smatch;
  318. if (std::regex_search(code, smatch, pattern)) {
  319. if (smatch.size() == 2) {
  320. class_view_info add;
  321. add.include = it.file_path;
  322. add.class_type = 1;
  323. add.class_name = smatch[1];
  324. add.sql_table_name = smatch[1];
  325. add.propertys = getPropertys(smatch.suffix());
  326. result.push_back(add);
  327. code = smatch.suffix();
  328. }
  329. }
  330. }
  331. //带反射特性结构体
  332. {
  333. std::regex pattern("struct[ \r\n\t]{0,30}\\[\\[NoReflect\\]\\][ \r\n\t]{0,30}([a-zA-Z_0-9]{1,100})");
  334. std::smatch smatch;
  335. if (std::regex_search(code, smatch, pattern)) {
  336. if (smatch.size() == 2) {
  337. class_view_info add;
  338. add.include = it.file_path;
  339. add.class_type = 1;
  340. add.class_name = smatch[1];
  341. add.sql_table_name = smatch[1].length() == 0 ? add.class_name : smatch[1];
  342. add.propertys = getPropertys(smatch.suffix());
  343. add.is_reflect = false;
  344. result.push_back(add);
  345. code = smatch.suffix();
  346. }
  347. }
  348. }
  349. //带数据库特性结构体
  350. {
  351. std::regex pattern("struct[ \r\n\t]{0,30}\\[\\[SqlTable\\(\"(.*?)\"\\)\\]\\][ \r\n\t]{0,30}([a-zA-Z_0-9]{1,100})");
  352. std::smatch smatch;
  353. if (std::regex_search(code, smatch, pattern)) {
  354. if (smatch.size() == 3) {
  355. class_view_info add;
  356. add.include = it.file_path;
  357. add.class_type = 1;
  358. add.class_name = smatch[2];
  359. add.sql_table_name = smatch[1].length() == 0 ? add.class_name : smatch[1];
  360. add.propertys = getPropertys(smatch.suffix());
  361. result.push_back(add);
  362. code = smatch.suffix();
  363. }
  364. }
  365. }
  366. //带数据库反射特性结构体
  367. {
  368. std::regex pattern("struct[ \r\n\t]{0,30}\\[\\[NoReflect\\]\\][ \r\n\t]{0,30}\\[\\[SqlTable\\(\"(.*?)\"\\)\\]\\][ \r\n\t]{0,30}([a-zA-Z_0-9]{1,100})");
  369. std::smatch smatch;
  370. if (std::regex_search(code, smatch, pattern)) {
  371. if (smatch.size() == 3) {
  372. class_view_info add;
  373. add.include = it.file_path;
  374. add.class_type = 1;
  375. add.class_name = smatch[2];
  376. add.sql_table_name = smatch[1].length() == 0 ? add.class_name : smatch[1];
  377. add.propertys = getPropertys(smatch.suffix());
  378. add.is_reflect = false;
  379. result.push_back(add);
  380. code = smatch.suffix();
  381. }
  382. }
  383. }
  384. }
  385. }
  386. //soap
  387. for (auto& it : fileInfos) {
  388. if (it.class_type != 2)
  389. continue;
  390. for (auto code : it.content) {
  391. std::regex pattern("class[ \r\n\t]{1,30}\\[\\[(.*?)\\]\\][ \r\n\t]{1,30}\\[\\[(.*?)\\]\\][ \r\n\t]{1,30}\\[\\[(.*?)\\]\\][ \r\n\t]{1,30}\\[\\[(.*?)\\]\\][ \r\n\t]{1,30}([a-zA-Z_0-9]{1,100})");
  392. std::smatch smatch;
  393. if (std::regex_search(code, smatch, pattern)) {
  394. if (smatch.size() == 6) {
  395. class_view_info add;
  396. add.include = it.file_path;
  397. add.class_type = 2;
  398. getSoapAttribute(smatch[1], add);
  399. getSoapAttribute(smatch[2], add);
  400. getSoapAttribute(smatch[3], add);
  401. getSoapAttribute(smatch[4], add);
  402. add.class_name = smatch[5];
  403. add.soap_methods = getSoapMethods(smatch.suffix());
  404. result.push_back(add);
  405. }
  406. }
  407. }
  408. }
  409. std::string rootPath = _path.string();
  410. rootPath = v3::utils::replace(rootPath, "\\", "/");
  411. if (rootPath[rootPath.size() - 1] != '/') {
  412. rootPath += "/";
  413. }
  414. for (auto& it : result) {
  415. it.include = v3::utils::replace(it.include, rootPath, "");
  416. }
  417. return result;
  418. }
  419. std::vector<file_info> getiFileInfo() {
  420. std::vector<file_info> result;
  421. auto controllerFiles = getControllerFiles();
  422. auto modelFiles = getModelsFiles();
  423. auto webServiceFiles = getWebServicesFiles();
  424. for (auto& item : controllerFiles) {
  425. file_info add;
  426. //获取代码
  427. std::string code = getCode(item);
  428. //剔除无用代码
  429. eliminateNotes(code);
  430. //
  431. add.class_type = 0;
  432. add.content = getStructContent(code);
  433. for (auto& it : add.content) {
  434. eliminateController(it);
  435. }
  436. add.file_path = v3::utils::replace(item.string(), "\\", "/");
  437. result.push_back(add);
  438. }
  439. for (auto& item : modelFiles) {
  440. file_info add;
  441. //获取代码
  442. std::string code = getCode(item);
  443. //剔除无用代码
  444. eliminateNotes(code);
  445. //
  446. add.class_type = 1;
  447. add.content = getStructContent(code);
  448. add.file_path = v3::utils::replace(item.string(), "\\", "/");
  449. result.push_back(add);
  450. }
  451. for (auto& item : webServiceFiles) {
  452. file_info add;
  453. //获取代码
  454. std::string code = getCode(item);
  455. //剔除无用代码
  456. eliminateNotes(code);
  457. //
  458. add.class_type = 2;
  459. add.content = getStructContent(code);
  460. for (auto& it : add.content) {
  461. eliminateWebService(it);
  462. }
  463. add.file_path = v3::utils::replace(item.string(), "\\", "/");
  464. result.push_back(add);
  465. }
  466. return result;
  467. }
  468. std::vector<std::filesystem::path> getControllerFiles() {
  469. std::filesystem::path controllersPath = _path;
  470. controllersPath /= "controllers";
  471. std::vector<std::filesystem::path> files;
  472. getFiles(controllersPath, { ".hpp" }, files);
  473. return files;
  474. }
  475. std::vector<std::filesystem::path> getModelsFiles() {
  476. std::filesystem::path modelsPath = _path;
  477. modelsPath /= "models";
  478. std::vector<std::filesystem::path> files;
  479. getFiles(modelsPath, { ".h" }, files);
  480. return files;
  481. }
  482. std::vector<std::filesystem::path> getWebServicesFiles() {
  483. std::filesystem::path webServicesPath = _path;
  484. webServicesPath /= "webservices";
  485. std::vector<std::filesystem::path> files;
  486. getFiles(webServicesPath, { ".hpp" }, files);
  487. return files;
  488. }
  489. void getFiles(std::filesystem::path path, std::vector<std::string> extension, std::vector<std::filesystem::path>& files)
  490. {
  491. if (!std::filesystem::is_directory(path)) {
  492. return;
  493. }
  494. for (auto& itr : std::filesystem::directory_iterator(path))
  495. {
  496. if (std::filesystem::is_directory(itr.status()))
  497. {
  498. getFiles(itr.path(), extension, files);
  499. }
  500. else
  501. {
  502. if (std::find(extension.begin(), extension.end(), itr.path().extension()) != extension.end()) {
  503. files.push_back(itr.path());
  504. }
  505. }
  506. }
  507. }
  508. std::string getCode(std::filesystem::path const& path) {
  509. std::ifstream file(path, std::ios::out);
  510. if (file.is_open()) {
  511. return std::string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
  512. }
  513. return "";
  514. }
  515. void eliminateNotes(std::string& code) {
  516. std::vector<std::pair<std::string, std::string>> notes = {
  517. {"/*","*/"},
  518. {"//","\n"},
  519. {"#include","\n"},
  520. {"#pragma", "\n"},
  521. {"#ifndef", "\n"},
  522. {"#define", "\n"},
  523. {"#if", "\n"},
  524. {"#endif", "\n"}
  525. };
  526. for (auto& note : notes) {
  527. std::size_t begin = 0;
  528. std::size_t end = 0;
  529. while ((begin = code.find(note.first, begin)) != std::string::npos && (end = code.find(note.second, begin)) != std::string::npos) {
  530. if (begin > 0 && code[begin - 1] == ':') {
  531. begin += note.second.size();
  532. continue;
  533. }
  534. code.erase(begin, end - begin + note.second.size());
  535. }
  536. }
  537. }
  538. void eliminateController(std::string& code) {
  539. std::string tmpCode = code;
  540. std::regex pattern("WebResponse[ \r\n\t]{1,30}[a-zA-Z_0-9]{1,100}[ \r\n\t]{0,30}([a-zA-Z0-9\",\\[\\], \r\n\t:<>_\\(\\)]{0,500})");
  541. std::smatch smatch;
  542. while (std::regex_search(tmpCode, smatch, pattern)) {
  543. std::string value = smatch[0];
  544. std::size_t pos = code.find(value);
  545. if (pos == std::string::npos)
  546. break;
  547. pos += value.size();
  548. int begin = 0;
  549. int end = 0;
  550. for (std::size_t i = pos; i < code.size(); ++i) {
  551. if (code[i] == '"') {
  552. int tmpBegin = 0;
  553. for (std::size_t i1 = i; i1 < code.size(); ++i1) {
  554. if (code[i1] == '"') {
  555. tmpBegin++;
  556. }
  557. code.erase(i1, 1);
  558. i1--;
  559. if (tmpBegin == 2) {
  560. break;
  561. }
  562. }
  563. }
  564. if (code[i] == '{') {
  565. begin++;
  566. }
  567. else if (code[i] == '}') {
  568. end++;
  569. }
  570. code.erase(i, 1);
  571. i--;
  572. if (begin > 0 && end == begin) {
  573. code.insert(code.begin() + i, ';');
  574. break;
  575. }
  576. }
  577. tmpCode = smatch.suffix();
  578. }
  579. }
  580. void eliminateWebService(std::string& code) {
  581. std::string tmpCode = code;
  582. std::regex pattern("SoapResponse[ \r\n\t]{1,30}[a-zA-Z_0-9]{1,100}[ \r\n\t]{0,30}([a-zA-Z0-9\",\\[\\], \r\n\t:<>_\\(\\)]{0,500})");
  583. std::smatch smatch;
  584. while (std::regex_search(tmpCode, smatch, pattern)) {
  585. std::string value = smatch[0];
  586. std::size_t pos = code.find(value);
  587. if (pos == std::string::npos)
  588. break;
  589. pos += value.size();
  590. int begin = 0;
  591. int end = 0;
  592. for (std::size_t i = pos; i < code.size(); ++i) {
  593. if (code[i] == '"') {
  594. int tmpBegin = 0;
  595. for (std::size_t i1 = i; i1 < code.size(); ++i1) {
  596. if (code[i1] == '"') {
  597. tmpBegin++;
  598. }
  599. code.erase(i1, 1);
  600. i1--;
  601. if (tmpBegin == 2) {
  602. break;
  603. }
  604. }
  605. }
  606. if (code[i] == '{') {
  607. begin++;
  608. }
  609. else if (code[i] == '}') {
  610. end++;
  611. }
  612. code.erase(i, 1);
  613. i--;
  614. if (begin > 0 && end == begin) {
  615. code.insert(code.begin() + i, ';');
  616. break;
  617. }
  618. }
  619. tmpCode = smatch.suffix();
  620. }
  621. }
  622. std::vector<std::string> getStructContent(std::string code) {
  623. std::vector<std::string> result;
  624. auto func = [](std::string reg, std::string code) {
  625. std::vector<std::string> result;
  626. std::regex pattern(reg);
  627. std::smatch smatch;
  628. while (std::regex_search(code, smatch, pattern)) {
  629. std::string structContent = smatch[0];
  630. std::size_t pos = code.find(structContent);
  631. if (pos == std::string::npos)
  632. break;
  633. int begin = 0;
  634. int end = 0;
  635. std::string content;
  636. for (int i = pos; i < code.size(); ++i) {
  637. content += code[i];
  638. if (code[i] == '{') {
  639. begin++;
  640. }
  641. else if (code[i] == '}') {
  642. end++;
  643. }
  644. if (begin > 0 && begin == end) {
  645. break;
  646. }
  647. }
  648. result.push_back(content);
  649. code = smatch.suffix();
  650. }
  651. return result;
  652. };
  653. std::vector<std::string> regList;
  654. //普通模板结构体
  655. regList.push_back("template[ \r\n\t]{0,30}<[\\s\\S]*?>[ \r\n\t]{0,30}struct[ \r\n\t]{1,30}[a-zA-Z_0-9]{1,100}");
  656. //带特性模板结构体
  657. regList.push_back("template[ \r\n\t]{0,30}<[\\s\\S]*?>[ \r\n\t]{0,30}struct[ \r\n\t]{0,30}\\[\\[[\\s\\S]*?\\]\\][ \r\n\t]{0,30}[a-zA-Z_0-9]{1,100}[ \r\n\t]{0,30}\\{");
  658. //普通结构体
  659. regList.push_back("struct[ \r\n\t]{1,30}[a-zA-Z_0-9]{1,100}");
  660. //带特性结构体
  661. regList.push_back("struct[ \r\n\t]{0,30}\\[\\[NoReflect\\]\\][ \r\n\t]{0,30}[a-zA-Z_0-9]{1,100}");
  662. //带特性结构体
  663. regList.push_back("struct[ \r\n\t]{0,30}\\[\\[SqlTable\\(\".*?\"\\)\\]\\][ \r\n\t]{0,30}[a-zA-Z_0-9]{1,100}");
  664. //带特性结构体
  665. regList.push_back("struct[ \r\n\t]{0,30}\\[\\[NoReflect\\]\\][ \r\n\t]{0,30}\\[\\[SqlTable\\(\".*?\"\\)\\]\\][ \r\n\t]{0,30}[a-zA-Z_0-9]{1,100}");
  666. //控制器
  667. regList.push_back("class[ \r\n\t]{1,30}[a-zA-Z_0-9]{1,200}");
  668. //soap
  669. regList.push_back("class[ \r\n\t]{1,30}\\[\\[.*?\\]\\][ \r\n\t]{1,30}\\[\\[.*?\\]\\][ \r\n\t]{1,30}\\[\\[.*?\\]\\][ \r\n\t]{1,30}\\[\\[.*?\\]\\][ \r\n\t]{1,30}[a-zA-Z_0-9]{1,100}");
  670. std::string tmpCode = code;
  671. for (auto& it : regList) {
  672. auto values = func(it, tmpCode);
  673. for (auto& item : values) {
  674. std::size_t pos = 0;
  675. if ((pos = tmpCode.find(item)) != std::string::npos) {
  676. tmpCode.erase(pos, item.size());
  677. }
  678. }
  679. result.insert(result.end(), values.begin(), values.end());
  680. }
  681. return result;
  682. }
  683. void getTemplateParameter(std::string code, int count, class_view_info& result) {
  684. auto attributes = v3::utils::split(code, "]]");
  685. for (auto& it : attributes) {
  686. std::size_t begin = 0;
  687. std::size_t end = 0;
  688. //TemplateType
  689. if (it.find("TemplateType") != std::string::npos && (begin = it.find("\"")) != std::string::npos && (end = it.rfind("\"")) != std::string::npos) {
  690. std::string value = it.substr(begin, end - begin + 1);
  691. auto values = v3::utils::split(value, ",");
  692. if (values.size() != count)
  693. continue;
  694. std::vector<std::string> addItem;
  695. for (auto temp : values) {
  696. if ((begin = temp.find("\"")) != std::string::npos && (end = temp.rfind("\"")) != std::string::npos) {
  697. if (begin == end)
  698. continue;
  699. addItem.push_back(temp.substr(begin + 1, end - begin - 1));
  700. }
  701. }
  702. if (addItem.size() != count)
  703. continue;
  704. result.template_parameters.push_back(v3::utils::format("{}", v3::utils::join(addItem, ",")));
  705. }
  706. //SqlTable
  707. else if (it.find("SqlTable") != std::string::npos && (begin = it.find("\"")) != std::string::npos && (end = it.rfind("\"")) != std::string::npos) {
  708. result.sql_table_name = it.substr(begin + 1, end - begin - 1);
  709. }
  710. }
  711. }
  712. //获取属性
  713. std::vector<PropertyInfo> getPropertys(std::string code) {
  714. std::vector<PropertyInfo> result;
  715. code.erase(code.find("{"), 1);
  716. code.erase(code.rfind("}"), 1);
  717. std::vector<std::string> propertyCodes = v3::utils::split(code, ";");
  718. for (auto& prop : propertyCodes) {
  719. PropertyInfo add;
  720. //提取特性
  721. {
  722. std::regex pattern("\\[\\[(.*?)\\]\\]");
  723. std::smatch smatch;
  724. while (std::regex_search(prop, smatch, pattern)) {
  725. std::string attribute = smatch[1];
  726. std::string Json = "Json";
  727. std::string NoJson = "NoJson";
  728. std::string Sql = "Sql";
  729. std::string NoSql = "NoSql";
  730. std::string SqlKey = "SqlKey";
  731. std::string Excel = "Excel";
  732. std::string NoExcel = "NoExcel";
  733. std::string NoArchive = "NoArchive";
  734. if (attribute.size() > Json.size() && attribute.substr(0, Json.size()) == Json) {
  735. auto values = v3::utils::split(attribute, "\"");
  736. if (values.size() == 3) {
  737. add.json_name = values[1];
  738. std::size_t pos = values[2].find("false");
  739. add.no_json = pos != std::string::npos;
  740. }
  741. }
  742. else if (attribute.size() > NoJson.size() && attribute.substr(0, NoJson.size()) == NoJson) {
  743. attribute = v3::utils::to_upper(attribute);
  744. if (attribute.find("TRUE") != std::string::npos) {
  745. add.no_json = true;
  746. }
  747. }
  748. else if (attribute.size() > SqlKey.size() && attribute.substr(0, SqlKey.size()) == SqlKey) {
  749. attribute = v3::utils::to_upper(attribute);
  750. if (attribute.find("TRUE") != std::string::npos) {
  751. add.sql_key = true;
  752. }
  753. }
  754. else if (attribute.size() > Sql.size() && attribute.substr(0, Sql.size()) == Sql) {
  755. auto values = v3::utils::split(attribute, "\"");
  756. if (values.size() == 3) {
  757. add.sql_name = values[1];
  758. std::size_t pos = values[2].find("false");
  759. add.no_sql = pos != std::string::npos;
  760. }
  761. }
  762. else if (attribute.size() > NoSql.size() && attribute.substr(0, NoSql.size()) == NoSql) {
  763. attribute = v3::utils::to_upper(attribute);
  764. if (attribute.find("TRUE") != std::string::npos) {
  765. add.no_sql = true;
  766. }
  767. }
  768. else if (attribute.size() > Excel.size() && attribute.substr(0, Excel.size()) == Excel) {
  769. auto values = v3::utils::split(attribute, "\"");
  770. if (values.size() == 3) {
  771. add.excel_name = values[1];
  772. std::size_t pos = values[2].find("false");
  773. add.no_excel = pos != std::string::npos;
  774. }
  775. }
  776. else if (attribute.size() > NoExcel.size() && attribute.substr(0, NoExcel.size()) == NoExcel) {
  777. attribute = v3::utils::to_upper(attribute);
  778. if (attribute.find("TRUE") != std::string::npos) {
  779. add.no_excel = true;
  780. }
  781. }
  782. else if (attribute.size() > NoArchive.size() && attribute.substr(0, NoArchive.size()) == NoArchive) {
  783. attribute = v3::utils::to_upper(attribute);
  784. if (attribute.find("TRUE") != std::string::npos) {
  785. add.no_archive = true;
  786. }
  787. }
  788. prop = smatch.suffix();
  789. }
  790. }
  791. //提取属性
  792. {
  793. std::regex pattern("([a-zA-Z_0-9:<>]{1,100})[ \r\n\t]{1,30}([a-zA-Z_0-9]{1,100})");
  794. std::smatch smatch;
  795. if (std::regex_search(prop, smatch, pattern)) {
  796. if (smatch.size() == 3 &&
  797. ((smatch[1].str().find('<') != std::string::npos && smatch[1].str().find('>') != std::string::npos) ||
  798. (smatch[1].str().find('<') == std::string::npos && smatch[1].str().find('>') == std::string::npos))) {
  799. add.type_name = smatch[1];
  800. add.prop_name = smatch[2];
  801. add.json_name = add.json_name.empty() ? add.prop_name : add.json_name;
  802. add.sql_name = add.sql_name.empty() ? add.prop_name : add.sql_name;
  803. add.excel_name = add.excel_name.empty() ? add.prop_name : add.excel_name;
  804. result.push_back(add);
  805. }
  806. }
  807. }
  808. }
  809. return result;
  810. }
  811. //获取方法
  812. std::vector<MethodInfo> getMethods(std::string code) {
  813. std::vector<MethodInfo> result;
  814. std::vector<std::pair<std::string, std::string>> funcList;
  815. //提取方法列表
  816. {
  817. std::regex pattern("WebResponse[ \r\n\t]{1,30}[a-zA-Z_0-9]{1,100}[ \r\n\t]{0,30}\\([a-zA-Z0-9\",\\[\\], \r\n\t:<>_\\(\\)]{0,500}\\)");
  818. std::smatch smatch;
  819. while (std::regex_search(code, smatch, pattern)) {
  820. std::string value = smatch[0];
  821. std::size_t pos = code.find(value);
  822. if (pos == std::string::npos)
  823. break;
  824. if (pos > 0)
  825. pos--;
  826. std::string func;
  827. for (int i = pos; i >= 0; --i) {
  828. if (code[i] == ']') {
  829. int count = 0;
  830. for (; i >= 0; --i) {
  831. if (code[i] == '[')
  832. count++;
  833. func += code[i];
  834. if (count == 2) {
  835. i--;
  836. break;
  837. }
  838. }
  839. }
  840. if (!(code[i] == '\r' || code[i] == '\n' || code[i] == '\t' || code[i] == ' ')) {
  841. break;
  842. }
  843. }
  844. std::reverse(func.begin(), func.end());
  845. funcList.push_back(std::make_pair(value, func));
  846. code = smatch.suffix();
  847. }
  848. }
  849. for (auto& it : funcList) {
  850. MethodInfo add;
  851. //特性
  852. methodAttribute(it.second, add);
  853. methodParameter(it.first, add);
  854. result.push_back(add);
  855. }
  856. return result;
  857. }
  858. //提取特性
  859. void methodAttribute(std::string code, MethodInfo& result) {
  860. auto attributes = v3::utils::split(code, "]]");
  861. for (auto it : attributes) {
  862. std::size_t begin = 0;
  863. std::size_t end = 0;
  864. //[[ActionType("Page")]]
  865. if (it.find("[[ActionType") != std::string::npos && (begin = it.find("\"")) != std::string::npos && (end = it.rfind("\"")) != std::string::npos) {
  866. result.action_type = it.substr(begin + 1, end - begin - 1);
  867. }
  868. //[[Method("POST")]]
  869. if (it.find("[[Method") != std::string::npos && (begin = it.find("\"")) != std::string::npos && (end = it.rfind("\"")) != std::string::npos) {
  870. std::string value = it.substr(begin + 1, end - begin - 1);
  871. if (value == "GET") {
  872. result.method = "robotics::v3::mvc::http_method::GET";
  873. }
  874. else {
  875. result.method = "robotics::v3::mvc::http_method::POST";
  876. }
  877. }
  878. //[[Authen(false,"Home/Index")]]
  879. if (it.find("[[Authen") != std::string::npos && (begin = it.find("(")) != std::string::npos && (end = it.find(")")) != std::string::npos && (begin = it.find("\"")) != std::string::npos && (end = it.rfind("\"")) != std::string::npos) {
  880. if (it.find("false") != std::string::npos) {
  881. result.authen_jump = it.substr(begin + 1, end - begin - 1);
  882. result.authen = false;
  883. }
  884. else {
  885. result.authen_jump = it.substr(begin + 1, end - begin - 1);
  886. result.authen = true;
  887. }
  888. }
  889. //[[Authen(false)]]
  890. else if (it.find("[[Authen") != std::string::npos && (begin = it.find("(")) != std::string::npos && (end = it.find(")")) != std::string::npos) {
  891. std::string value = v3::utils::to_upper(it.substr(begin, end - begin + 1));
  892. result.authen = value.find("FALSE") == std::string::npos;
  893. }
  894. //[[Route("Account/Login")]]
  895. if (it.find("[[Route") != std::string::npos && (begin = it.find("\"")) != std::string::npos && (end = it.rfind("\"")) != std::string::npos) {
  896. result.route = it.substr(begin + 1, end - begin - 1);
  897. if (result.route.find('<') != std::string::npos) {
  898. }
  899. }
  900. //[[ContentType("application/x-www-form-urlencoded")]]
  901. if (it.find("[[ContentType") != std::string::npos && (begin = it.find("\"")) != std::string::npos && (end = it.rfind("\"")) != std::string::npos) {
  902. result.content_type = it.substr(begin + 1, end - begin - 1);
  903. }
  904. //[[FileMapping("Account/Index.html")]]
  905. if (it.find("[[FileMapping") != std::string::npos && (begin = it.find("\"")) != std::string::npos && (end = it.rfind("\"")) != std::string::npos) {
  906. result.file_mapping = it.substr(begin + 1, end - begin - 1);
  907. }
  908. }
  909. }
  910. //
  911. void methodParameter(std::string code, MethodInfo& result) {
  912. bool succ = false;
  913. std::string parameter;
  914. std::string funcName;
  915. //提取方法列表
  916. {
  917. std::regex pattern("WebResponse[ \r\n\t]{1,30}([a-zA-Z_0-9]{1,100})[ \r\n\t]{0,30}\\(([a-zA-Z0-9\",\\[\\], \r\n\t:<>_\\(\\)]{0,500})\\)");
  918. std::smatch smatch;
  919. if (std::regex_search(code, smatch, pattern)) {
  920. if (smatch.size() == 3) {
  921. succ = true;
  922. funcName = smatch[1];
  923. parameter = smatch[2];
  924. }
  925. }
  926. }
  927. if (!succ)return;
  928. std::vector<ParameterInfo> parameterValues;
  929. {
  930. auto parameters = v3::utils::split(parameter, ",");
  931. for (auto& it : parameters) {
  932. //带特性
  933. {
  934. std::regex pattern("\\[\\[(.*?)\\]\\][\r\n\t ]{0,30}([a-zA-Z_0-9<>:]{1,100})[\r\n\t ]{1,30}([a-zA-Z0-9_]{1,100})");
  935. std::smatch smatch;
  936. if (std::regex_search(it, smatch, pattern)) {
  937. if (smatch.size() == 4) {
  938. ParameterInfo add;
  939. std::string attribute = smatch[1];
  940. std::string paramType = smatch[2];
  941. std::string paramName = smatch[3];
  942. for (int i = 0; i < paramType.size(); ++i) {
  943. if (paramType[i] == ' ') {
  944. paramType.erase(i, 1);
  945. --i;
  946. }
  947. }
  948. parameterType(paramType, add);
  949. parameterAttribute(attribute, add);
  950. if (add.parameter_name.empty()) {
  951. add.parameter_name = paramName;
  952. }
  953. if (add.parameter_name == " ") {
  954. add.parameter_name = "";
  955. }
  956. add.name = paramName;
  957. add.type = paramType;
  958. parameterValues.push_back(add);
  959. continue;
  960. }
  961. }
  962. }
  963. //不带特性
  964. {
  965. std::regex pattern("([a-zA-Z_0-9<>:]{1,100})[\r\n\t ]{1,30}([a-zA-Z0-9_]{1,100})");
  966. std::smatch smatch;
  967. if (std::regex_search(it, smatch, pattern)) {
  968. if (smatch.size() == 3) {
  969. ParameterInfo add;
  970. std::string paramType = smatch[1];
  971. std::string paramName = smatch[2];
  972. for (int i = 0; i < paramType.size(); ++i) {
  973. if (paramType[i] == ' ') {
  974. paramType.erase(i, 1);
  975. --i;
  976. }
  977. }
  978. parameterType(paramType, add);
  979. add.name = paramName;
  980. add.type = paramType;
  981. add.parameter_name = paramName;
  982. parameterValues.push_back(add);
  983. continue;
  984. }
  985. }
  986. }
  987. }
  988. }
  989. result.parameters = parameterValues;
  990. std::string signature = "WebResponse({})";
  991. std::vector<std::string> tmpParams;
  992. for (auto& it : result.parameters) {
  993. tmpParams.push_back(it.type);
  994. }
  995. signature = v3::utils::format(signature, v3::utils::join(tmpParams, ","));
  996. result.signature = signature;
  997. result.name = funcName;
  998. }
  999. void parameterType(std::string code, ParameterInfo& parameter) {
  1000. if (code == "robotics::v3::mvc::multipart_value" || code == "v3::mvc::multipart_value" || code == "mvc::multipart_value" || code == "multipart_value") {
  1001. parameter.argument_type = "robotics::v3::mvc::argument_type::Multipart";
  1002. }
  1003. else if (code == "int") {
  1004. parameter.argument_type = "robotics::v3::mvc::argument_type::Int";
  1005. }
  1006. else if (code == "std::uint64_t") {
  1007. parameter.argument_type = "robotics::v3::mvc::argument_type::Int64";
  1008. }
  1009. else if (code == "float") {
  1010. parameter.argument_type = "robotics::v3::mvc::argument_type::Float";
  1011. }
  1012. else if (code == "double") {
  1013. parameter.argument_type = "robotics::v3::mvc::argument_type::Double";
  1014. }
  1015. else if (code == "long") {
  1016. parameter.argument_type = "robotics::v3::mvc::argument_type::Long";
  1017. }
  1018. else if (code == "bool") {
  1019. parameter.argument_type = "robotics::v3::mvc::argument_type::Bool_";
  1020. }
  1021. else if (code == "std::string") {
  1022. parameter.argument_type = "robotics::v3::mvc::argument_type::String";
  1023. }
  1024. else if (code == "robotics::v3::datetime" || code == "v3::datetime" || code == "datetime") {
  1025. parameter.argument_type = "robotics::v3::mvc::argument_type::DateTime";
  1026. }
  1027. else if (code == "std::vector<std::uint8_t>") {
  1028. parameter.argument_type = "robotics::v3::mvc::argument_type::Binary";
  1029. }
  1030. else if (code == "std::vector<int>") {
  1031. parameter.argument_type = "robotics::v3::mvc::argument_type::VecInt";
  1032. }
  1033. else if (code == "std::vector<std::uint64_t>") {
  1034. parameter.argument_type = "robotics::v3::mvc::argument_type::VecInt64";
  1035. }
  1036. else if (code == "std::vector<float>") {
  1037. parameter.argument_type = "robotics::v3::mvc::argument_type::VecFloat";
  1038. }
  1039. else if (code == "std::vector<double>") {
  1040. parameter.argument_type = "robotics::v3::mvc::argument_type::VecDouble";
  1041. }
  1042. else if (code == "std::vector<long>") {
  1043. parameter.argument_type = "robotics::v3::mvc::argument_type::VecLong";
  1044. }
  1045. else if (code == "std::vector<bool>") {
  1046. parameter.argument_type = "robotics::v3::mvc::argument_type::VecBool";
  1047. }
  1048. else if (code == "std::vector<std::string>") {
  1049. parameter.argument_type = "robotics::v3::mvc::argument_type::VecString";
  1050. }
  1051. else if (code == "std::vector<robotics::v3::datetime>" || code == "std::vector<v3::datetime>" || code == "std::vector<datetime>") {
  1052. parameter.argument_type = "robotics::v3::mvc::argument_type::VecDateTime";
  1053. }
  1054. else if (code.size() > 12 && code.substr(0, 11) == "std::vector") {
  1055. parameter.argument_type = "robotics::v3::mvc::argument_type::VecJson";
  1056. }
  1057. else {
  1058. parameter.argument_type = "robotics::v3::mvc::argument_type::Json";
  1059. }
  1060. }
  1061. void parameterAttribute(std::string code, ParameterInfo& parameter) {
  1062. std::size_t begin = 0;
  1063. std::size_t end = 0;
  1064. //FromQuery
  1065. if (code.find("FromQuery") != std::string::npos && (begin = code.find("\"")) != std::string::npos && (end = code.rfind("\"")) != std::string::npos) {
  1066. parameter.from_storage_type = "robotics::v3::mvc::from_storage_type::QUERY";
  1067. parameter.parameter_name = code.substr(begin + 1, end - begin - 1);
  1068. }
  1069. //FromBody
  1070. else if (code.find("FromBody") != std::string::npos && (begin = code.find("\"")) != std::string::npos && (end = code.rfind("\"")) != std::string::npos) {
  1071. parameter.from_storage_type = "robotics::v3::mvc::from_storage_type::BODY";
  1072. parameter.parameter_name = code.substr(begin + 1, end - begin - 1);
  1073. if (parameter.parameter_name.empty()) {
  1074. parameter.parameter_name = " ";
  1075. }
  1076. }
  1077. //FromHeader
  1078. else if (code.find("FromHeader") != std::string::npos && (begin = code.find("\"")) != std::string::npos && (end = code.rfind("\"")) != std::string::npos) {
  1079. parameter.from_storage_type = "robotics::v3::mvc::from_storage_type::HEADER";
  1080. parameter.parameter_name = code.substr(begin + 1, end - begin - 1);
  1081. }
  1082. //FromUrl
  1083. else if (code.find("FromUrl") != std::string::npos && (begin = code.find("\"")) != std::string::npos && (end = code.rfind("\"")) != std::string::npos) {
  1084. parameter.from_storage_type = "robotics::v3::mvc::from_storage_type::URL";
  1085. parameter.parameter_name = code.substr(begin + 1, end - begin - 1);
  1086. }
  1087. }
  1088. void getSoapAttribute(std::string code, class_view_info& result) {
  1089. std::size_t begin = 0;
  1090. std::size_t end = 0;
  1091. //Version
  1092. if (code.find("Version") != std::string::npos && (begin = code.find("\"")) != std::string::npos && (end = code.rfind("\"")) != std::string::npos) {
  1093. result.soap_version = code.substr(begin + 1, end - begin - 1);
  1094. }
  1095. //Namepsace
  1096. else if (code.find("Namespace") != std::string::npos && (begin = code.find("\"")) != std::string::npos && (end = code.rfind("\"")) != std::string::npos) {
  1097. result.soap_namepsace = code.substr(begin + 1, end - begin - 1);
  1098. }
  1099. //Route
  1100. else if (code.find("Route") != std::string::npos && (begin = code.find("\"")) != std::string::npos && (end = code.rfind("\"")) != std::string::npos) {
  1101. result.soap_route = code.substr(begin + 1, end - begin - 1);
  1102. }
  1103. //Wsdl
  1104. else if (code.find("Wsdl") != std::string::npos && (begin = code.find("\"")) != std::string::npos && (end = code.rfind("\"")) != std::string::npos) {
  1105. result.soap_wsdl = code.substr(begin + 1, end - begin - 1);
  1106. }
  1107. }
  1108. std::vector<soap_method_info> getSoapMethods(std::string code) {
  1109. std::vector<soap_method_info> result;
  1110. std::vector<std::pair<std::string, std::string>> funcList;
  1111. //提取方法列表
  1112. {
  1113. std::regex pattern("SoapResponse[ \r\n\t]{1,30}[a-zA-Z_0-9]{1,100}[ \r\n\t]{0,30}\\([a-zA-Z0-9\",\\[\\], \r\n\t:<>_\\(\\)]{0,500}\\)");
  1114. std::smatch smatch;
  1115. while (std::regex_search(code, smatch, pattern)) {
  1116. std::string value = smatch[0];
  1117. std::size_t pos = code.find(value);
  1118. if (pos == std::string::npos)
  1119. break;
  1120. if (pos > 0)
  1121. pos--;
  1122. std::string func;
  1123. for (int i = pos; i >= 0; --i) {
  1124. if (code[i] == ']') {
  1125. int count = 0;
  1126. for (; i >= 0; --i) {
  1127. if (code[i] == '[')
  1128. count++;
  1129. func += code[i];
  1130. if (count == 2) {
  1131. i--;
  1132. break;
  1133. }
  1134. }
  1135. }
  1136. if (!(code[i] == '\r' || code[i] == '\n' || code[i] == '\t' || code[i] == ' ')) {
  1137. break;
  1138. }
  1139. }
  1140. std::reverse(func.begin(), func.end());
  1141. funcList.push_back(std::make_pair(value, func));
  1142. code = smatch.suffix();
  1143. }
  1144. }
  1145. for (auto& it : funcList) {
  1146. soap_method_info add;
  1147. //特性
  1148. soapMethodAttribute(it.second, add);
  1149. soapMethodParameter(it.first, add);
  1150. result.push_back(add);
  1151. }
  1152. return result;
  1153. }
  1154. void soapMethodAttribute(std::string code, soap_method_info& result) {
  1155. auto attributes = v3::utils::split(code, "]]");
  1156. for (auto it : attributes) {
  1157. std::size_t begin = 0;
  1158. std::size_t end = 0;
  1159. //[[Method("get")]]
  1160. if (it.find("Method") != std::string::npos && (begin = it.find("\"")) != std::string::npos && (end = it.rfind("\"")) != std::string::npos) {
  1161. result.action_name = it.substr(begin + 1, end - begin - 1);
  1162. }
  1163. }
  1164. }
  1165. void soapMethodParameter(std::string code, soap_method_info& result) {
  1166. std::regex pattern("SoapResponse[ \r\n\t]{1,30}([a-zA-Z_0-9]{1,100})[ \r\n\t]{0,30}\\(([a-zA-Z0-9\",\\[\\], \r\n\t:<>_\\(\\)]{0,500})\\)");
  1167. std::smatch smatch;
  1168. std::vector<SoapParameterInfo> parameterValues;
  1169. while (std::regex_search(code, smatch, pattern)) {
  1170. if (smatch.size() == 3) {
  1171. result.name = smatch[1];
  1172. if (result.action_name.empty()) {
  1173. result.action_name = result.name;
  1174. }
  1175. auto parameters = v3::utils::split(smatch[2], ",");
  1176. for (auto& it : parameters)
  1177. {
  1178. std::regex pattern1("([a-zA-Z_0-9<>:]{1,100})[\r\n\t ]{1,30}([a-zA-Z0-9_]{1,100})");
  1179. std::smatch smatch1;
  1180. if (std::regex_search(it, smatch1, pattern1)) {
  1181. if (smatch1.size() == 3) {
  1182. SoapParameterInfo add;
  1183. std::string paramType = smatch1[1];
  1184. std::string paramName = smatch1[2];
  1185. for (int i = 0; i < paramType.size(); ++i) {
  1186. if (paramType[i] == ' ') {
  1187. paramType.erase(i, 1);
  1188. --i;
  1189. }
  1190. }
  1191. soapParameterType(paramType, add);
  1192. add.parameter_name = paramName;
  1193. add.type = paramType;
  1194. parameterValues.push_back(add);
  1195. continue;
  1196. }
  1197. }
  1198. }
  1199. }
  1200. break;
  1201. }
  1202. result.parameters = parameterValues;
  1203. std::string signature = "SoapResponse({})";
  1204. std::vector<std::string> tmpParams;
  1205. for (auto& it : result.parameters) {
  1206. tmpParams.push_back(it.type);
  1207. }
  1208. signature = v3::utils::format(signature, v3::utils::join(tmpParams, ","));
  1209. result.signature = signature;
  1210. }
  1211. void soapParameterType(std::string code, SoapParameterInfo& parameter) {
  1212. if (code == "int") {
  1213. parameter.argument_type = "robotics::v3::soap::soap_argument_type::Int";
  1214. }
  1215. else if (code == "std::uint64_t") {
  1216. parameter.argument_type = "robotics::v3::soap::soap_argument_type::Int64";
  1217. }
  1218. else if (code == "float") {
  1219. parameter.argument_type = "robotics::v3::soap::soap_argument_type::Float";
  1220. }
  1221. else if (code == "double") {
  1222. parameter.argument_type = "robotics::v3::soap::soap_argument_type::Double";
  1223. }
  1224. else if (code == "long") {
  1225. parameter.argument_type = "robotics::v3::soap::soap_argument_type::Long";
  1226. }
  1227. else if (code == "bool") {
  1228. parameter.argument_type = "robotics::v3::soap::soap_argument_type::Bool_";
  1229. }
  1230. else if (code == "std::string") {
  1231. parameter.argument_type = "robotics::v3::soap::soap_argument_type::String";
  1232. }
  1233. else if (code == "robotics::v3::datetime" || code == "v3::datetime" || code == "datetime") {
  1234. parameter.argument_type = "robotics::v3::soap::soap_argument_type::DateTime";
  1235. }
  1236. else {
  1237. parameter.argument_type = "robotics::v3::soap_argument_type::Json";
  1238. }
  1239. }
  1240. private:
  1241. std::filesystem::path _path;
  1242. };
  1243. #endif //!__CODE_GENERATOR_CODE_ANALYSIS_H__