ScriptAPIDump.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. // Copyright (c) 2008-2022 the Urho3D project
  2. // License: MIT
  3. #include "../Precompiled.h"
  4. #include "../AngelScript/Script.h"
  5. #include "../Core/Context.h"
  6. #include "../IO/File.h"
  7. #include "../IO/FileSystem.h"
  8. #include "../IO/Log.h"
  9. #include <AngelScript/angelscript.h>
  10. #include "../DebugNew.h"
  11. namespace Urho3D
  12. {
  13. /// %Object property info for scripting API dump.
  14. struct PropertyInfo
  15. {
  16. /// Construct.
  17. PropertyInfo() :
  18. read_(false),
  19. write_(false),
  20. indexed_(false)
  21. {
  22. }
  23. /// Property name.
  24. String name_;
  25. /// Property data type.
  26. String type_;
  27. /// Reading supported flag.
  28. bool read_;
  29. /// Writing supported flag.
  30. bool write_;
  31. /// Indexed flag.
  32. bool indexed_;
  33. };
  34. /// Header information for dumping events.
  35. struct HeaderFile
  36. {
  37. /// Full path to header file.
  38. String fileName;
  39. /// Event section name.
  40. String sectionName;
  41. };
  42. bool CompareHeaderFiles(const HeaderFile& lhs, const HeaderFile& rhs)
  43. {
  44. return lhs.sectionName < rhs.sectionName;
  45. }
  46. void ExtractPropertyInfo(const String& functionName, const String& declaration, Vector<PropertyInfo>& propertyInfos)
  47. {
  48. String propertyName = functionName.Substring(4);
  49. PropertyInfo* info = nullptr;
  50. for (unsigned k = 0; k < propertyInfos.Size(); ++k)
  51. {
  52. if (propertyInfos[k].name_ == propertyName)
  53. {
  54. info = &propertyInfos[k];
  55. break;
  56. }
  57. }
  58. if (!info)
  59. {
  60. propertyInfos.Resize(propertyInfos.Size() + 1);
  61. info = &propertyInfos.Back();
  62. info->name_ = propertyName;
  63. }
  64. if (functionName.Contains("get_"))
  65. {
  66. info->read_ = true;
  67. // Extract type from the return value
  68. Vector<String> parts = declaration.Split(' ');
  69. if (parts.Size())
  70. {
  71. if (parts[0] != "const")
  72. info->type_ = parts[0];
  73. else if (parts.Size() > 1)
  74. info->type_ = parts[1];
  75. }
  76. // If get method has parameters, it is indexed
  77. if (!declaration.Contains("()"))
  78. {
  79. info->indexed_ = true;
  80. info->type_ += "[]";
  81. }
  82. // Sanitate the reference operator away
  83. info->type_.Replace("&", "");
  84. }
  85. if (functionName.Contains("set_"))
  86. {
  87. info->write_ = true;
  88. if (info->type_.Empty())
  89. {
  90. // Extract type from parameters
  91. i32 begin = declaration.Find(',');
  92. if (begin == String::NPOS)
  93. begin = declaration.Find('(');
  94. else
  95. info->indexed_ = true;
  96. if (begin != String::NPOS)
  97. {
  98. ++begin;
  99. i32 end = declaration.Find(')');
  100. if (end != String::NPOS)
  101. {
  102. info->type_ = declaration.Substring(begin, end - begin);
  103. // Sanitate const & reference operator away
  104. info->type_.Replace("const ", "");
  105. info->type_.Replace("&in", "");
  106. info->type_.Replace("&", "");
  107. }
  108. }
  109. }
  110. }
  111. }
  112. bool ComparePropertyStrings(const String& lhs, const String& rhs)
  113. {
  114. i32 spaceLhs = lhs.Find(' ');
  115. i32 spaceRhs = rhs.Find(' ');
  116. if (spaceLhs != String::NPOS && spaceRhs != String::NPOS)
  117. return String::Compare(lhs.CString() + spaceLhs, rhs.CString() + spaceRhs, true) < 0;
  118. else
  119. return String::Compare(lhs.CString(), rhs.CString(), true) < 0;
  120. }
  121. bool ComparePropertyInfos(const PropertyInfo& lhs, const PropertyInfo& rhs)
  122. {
  123. return String::Compare(lhs.name_.CString(), rhs.name_.CString(), true) < 0;
  124. }
  125. void Script::OutputAPIRow(DumpMode mode, const String& row, bool removeReference, const String& separator)
  126. {
  127. String out(row.Trimmed());
  128. out.Replace("&in", "&");
  129. out.Replace("&out", "&");
  130. if (removeReference)
  131. out.Replace("&", "");
  132. if (mode == DOXYGEN)
  133. Log::WriteRaw("- " + out + "\n");
  134. else if (mode == C_HEADER)
  135. {
  136. out.Replace("@", "");
  137. out.Replace("?&", "void*");
  138. // s/(\w+)\[\]/Array<\1>/g
  139. i32 posBegin = String::NPOS;
  140. while (true) // Loop to cater for array of array of T
  141. {
  142. i32 posEnd = out.Find("[]");
  143. if (posEnd == String::NPOS)
  144. break;
  145. if (posBegin == String::NPOS)
  146. posBegin = posEnd - 1;
  147. while (posBegin >= 0 && isalnum(out[posBegin]))
  148. --posBegin;
  149. ++posBegin;
  150. out.Replace(posBegin, posEnd - posBegin + 2, "Array<" + out.Substring(posBegin, posEnd - posBegin) + ">");
  151. }
  152. // "opIndex" early was replaced to "operator[ ]", so not replaced here to Array<operator>
  153. out.Replace("[ ]", "[]");
  154. Log::WriteRaw(out + separator + "\n");
  155. }
  156. }
  157. void Script::DumpAPI(DumpMode mode, const String& sourceTree)
  158. {
  159. // Does not use URHO3D_LOGRAW macro here to ensure the messages are always dumped regardless of URHO3D_LOGGING compiler directive
  160. // and of Log subsystem availability
  161. // Dump event descriptions and attribute definitions in Doxygen mode. For events, this means going through the header files,
  162. // as the information is not available otherwise.
  163. /// \todo Dump events + attributes before the actual script API because the remarks (readonly / writeonly) seem to throw off
  164. // Doxygen parsing and the following page definition(s) may not be properly recognized
  165. if (mode == DOXYGEN)
  166. {
  167. Log::WriteRaw("namespace Urho3D\n{\n\n/**\n");
  168. auto* fileSystem = GetSubsystem<FileSystem>();
  169. Vector<String> headerFileNames;
  170. String path = AddTrailingSlash(sourceTree);
  171. if (!path.Empty())
  172. path.Append("Source/Urho3D/");
  173. fileSystem->ScanDir(headerFileNames, path, "*.h", SCAN_FILES, true);
  174. /// \hack Rename any Events2D to 2DEvents to work with the event category creation correctly (currently PhysicsEvents2D)
  175. Vector<HeaderFile> headerFiles;
  176. for (const String& headerFileName : headerFileNames)
  177. {
  178. HeaderFile entry;
  179. entry.fileName = headerFileName;
  180. entry.sectionName = GetFileNameAndExtension(entry.fileName).Replaced("Events2D", "2DEvents");
  181. if (entry.sectionName.EndsWith("Events.h"))
  182. headerFiles.Push(entry);
  183. }
  184. if (!headerFiles.Empty())
  185. {
  186. Log::WriteRaw("\n\\page EventList Event list\n");
  187. Sort(headerFiles.Begin(), headerFiles.End(), CompareHeaderFiles);
  188. for (const HeaderFile& headerFile : headerFiles)
  189. {
  190. SharedPtr<File> file(new File(context_, path + headerFile.fileName, FILE_READ));
  191. if (!file->IsOpen())
  192. continue;
  193. const String& sectionName = headerFile.sectionName;
  194. i32 start = sectionName.Find('/') + 1;
  195. i32 end = sectionName.Find("Events.h");
  196. Log::WriteRaw("\n## %" + sectionName.Substring(start, end - start) + " events\n");
  197. while (!file->IsEof())
  198. {
  199. String line = file->ReadLine();
  200. if (line.StartsWith("URHO3D_EVENT"))
  201. {
  202. Vector<String> parts = line.Split(',');
  203. if (parts.Size() == 2)
  204. Log::WriteRaw("\n### " + parts[1].Substring(0, parts[1].Length() - 1).Trimmed() + "\n");
  205. }
  206. if (line.Contains("URHO3D_PARAM"))
  207. {
  208. Vector<String> parts = line.Split(',');
  209. if (parts.Size() == 2)
  210. {
  211. String paramName = parts[1].Substring(0, parts[1].Find(')')).Trimmed();
  212. String paramType = parts[1].Substring(parts[1].Find("// ") + 3);
  213. if (!paramName.Empty() && !paramType.Empty())
  214. Log::WriteRaw("- %" + paramName + " : " + paramType + "\n");
  215. }
  216. }
  217. }
  218. }
  219. Log::WriteRaw("\n");
  220. }
  221. Log::WriteRaw("\n\\page AttributeList Attribute list\n");
  222. const HashMap<StringHash, Vector<AttributeInfo>>& attributes = context_->GetAllAttributes();
  223. Vector<String> objectTypes;
  224. for (HashMap<StringHash, Vector<AttributeInfo>>::ConstIterator i = attributes.Begin(); i != attributes.End(); ++i)
  225. objectTypes.Push(context_->GetTypeName(i->first_));
  226. Sort(objectTypes.Begin(), objectTypes.End());
  227. for (const String& objectType : objectTypes)
  228. {
  229. const Vector<AttributeInfo>& attrs = attributes.Find(objectType)->second_;
  230. bool hasEditableAttr = false;
  231. for (const AttributeInfo& attr : attrs)
  232. {
  233. // Attributes that are not shown in the editor are typically internal and not usable for eg. attribute
  234. // animation
  235. if (!(attr.mode_ & AM_NOEDIT))
  236. {
  237. hasEditableAttr = true;
  238. break;
  239. }
  240. }
  241. if (!hasEditableAttr)
  242. continue;
  243. Log::WriteRaw("\n### " + objectType + "\n");
  244. for (const AttributeInfo& attr : attrs)
  245. {
  246. if (attr.mode_ & AM_NOEDIT)
  247. continue;
  248. // Prepend each word in the attribute name with % to prevent unintended links
  249. Vector<String> nameParts = attr.name_.Split(' ');
  250. for (String& namePart : nameParts)
  251. {
  252. if (namePart.Length() > 1 && IsAlpha((unsigned)namePart[0]))
  253. namePart = "%" + namePart;
  254. }
  255. String name;
  256. name.Join(nameParts, " ");
  257. String type = Variant::GetTypeName(attr.type_);
  258. // Variant typenames are all uppercase. Convert primitive types to the proper lowercase form for the documentation
  259. if (type == "Int" || type == "Bool" || type == "Float")
  260. type[0] = (char)ToLower((unsigned)type[0]);
  261. Log::WriteRaw("- " + name + " : " + type + "\n");
  262. }
  263. }
  264. Log::WriteRaw("\n");
  265. }
  266. if (mode == DOXYGEN)
  267. Log::WriteRaw("\n\\page ScriptAPI Scripting API\n\n");
  268. else if (mode == C_HEADER)
  269. Log::WriteRaw(
  270. "// Script API header intended to be 'force included' in IDE for AngelScript content assist / code completion\n\n"
  271. "#define int8 signed char\n"
  272. "#define int16 signed short\n"
  273. "#define int64 long\n"
  274. "#define uint unsigned\n"
  275. "#define uint8 unsigned char\n"
  276. "#define uint16 unsigned short\n"
  277. "#define uint64 unsigned long\n"
  278. "#define null 0\n"
  279. "#define in\n"
  280. "#define out\n"
  281. "#define inout\n"
  282. "#define is ==\n"
  283. "#define interface struct\n"
  284. "#define class struct\n"
  285. "#define cast reinterpret_cast\n"
  286. "#define mixin\n"
  287. "#define funcdef\n"
  288. "#define protected\n"
  289. "#define private\n"
  290. );
  291. unsigned types = scriptEngine_->GetObjectTypeCount();
  292. Vector<Pair<String, unsigned>> sortedTypes;
  293. for (unsigned i = 0; i < types; ++i)
  294. {
  295. asITypeInfo* type = scriptEngine_->GetObjectTypeByIndex(i);
  296. if (type)
  297. {
  298. String typeName(type->GetName());
  299. sortedTypes.Push(MakePair(typeName, i));
  300. }
  301. }
  302. Sort(sortedTypes.Begin(), sortedTypes.End());
  303. // Get global constants by namespace
  304. HashMap<String, Vector<String>> globalConstants;
  305. unsigned properties = scriptEngine_->GetGlobalPropertyCount();
  306. for (unsigned i = 0; i < properties; ++i)
  307. {
  308. const char* propertyName;
  309. const char* propertyDeclaration;
  310. const char* propertyNameSpace;
  311. int typeId;
  312. scriptEngine_->GetGlobalPropertyByIndex(i, &propertyName, &propertyNameSpace, &typeId);
  313. propertyDeclaration = scriptEngine_->GetTypeDeclaration(typeId);
  314. String type(propertyDeclaration);
  315. globalConstants[String(propertyNameSpace)].Push(type + " " + String(propertyName));
  316. }
  317. for (HashMap<String, Vector<String>>::Iterator i = globalConstants.Begin(); i != globalConstants.End(); ++i)
  318. Sort(i->second_.Begin(), i->second_.End(), ComparePropertyStrings);
  319. if (mode == DOXYGEN)
  320. {
  321. Log::WriteRaw("\\section ScriptAPI_TableOfContents Table of contents\n"
  322. "\\ref ScriptAPI_ClassList \"Class list\"<br>\n"
  323. "\\ref ScriptAPI_Classes \"Classes\"<br>\n"
  324. "\\ref ScriptAPI_Enums \"Enumerations\"<br>\n"
  325. "\\ref ScriptAPI_GlobalFunctions \"Global functions\"<br>\n"
  326. "\\ref ScriptAPI_GlobalProperties \"Global properties\"<br>\n"
  327. "\\ref ScriptAPI_GlobalConstants \"Global constants\"<br>\n\n");
  328. Log::WriteRaw("\\section ScriptAPI_ClassList Class list\n\n");
  329. for (unsigned i = 0; i < sortedTypes.Size(); ++i)
  330. {
  331. asITypeInfo* type = scriptEngine_->GetObjectTypeByIndex(sortedTypes[i].second_);
  332. if (type)
  333. {
  334. String typeName(type->GetName());
  335. Log::WriteRaw("<a href=\"#Class_" + typeName + "\"><b>" + typeName + "</b></a>\n");
  336. }
  337. }
  338. Log::WriteRaw("\n\\section ScriptAPI_Classes Classes\n");
  339. }
  340. else if (mode == C_HEADER)
  341. Log::WriteRaw("\n// Classes\n");
  342. for (unsigned i = 0; i < sortedTypes.Size(); ++i)
  343. {
  344. asITypeInfo* type = scriptEngine_->GetObjectTypeByIndex(sortedTypes[i].second_);
  345. if (type)
  346. {
  347. String typeName(type->GetName());
  348. Vector<String> methodDeclarations;
  349. Vector<PropertyInfo> propertyInfos;
  350. if (mode == DOXYGEN)
  351. {
  352. Log::WriteRaw("<a name=\"Class_" + typeName + "\"></a>\n");
  353. Log::WriteRaw("\n### " + typeName + "\n");
  354. }
  355. else if (mode == C_HEADER)
  356. {
  357. if (type->GetFlags() & asOBJ_TEMPLATE) {
  358. String str = "\ntemplate <";
  359. for (asUINT tt = 0, ttm = type->GetSubTypeCount(); tt < ttm; tt++) {
  360. asITypeInfo* pSubType = type->GetSubType(tt);
  361. str += String("typename ") + pSubType->GetName() + (tt < ttm - 1 ? ", " : ">");
  362. }
  363. Log::WriteRaw(str);
  364. }
  365. Log::WriteRaw("\nclass " + typeName + "\n{\npublic:\n");
  366. for (asUINT m = 0, mc = type->GetBehaviourCount(); m < mc; m++) {
  367. asEBehaviours bh;
  368. asIScriptFunction* pM = type->GetBehaviourByIndex(m, &bh);
  369. if (bh == asBEHAVE_CONSTRUCT || bh == asBEHAVE_DESTRUCT)
  370. Log::WriteRaw(String(pM->GetDeclaration(false, false, true)) + ";\n");
  371. }
  372. for (asUINT m = 0, mc = type->GetFactoryCount(); m < mc; m++) {
  373. asIScriptFunction* pM = type->GetFactoryByIndex(m);
  374. String declaration(pM->GetDeclaration(false, false, true));
  375. declaration = declaration.Substring(declaration.Find(' ') + 1);
  376. declaration.Replace("@", "&");
  377. Log::WriteRaw(declaration + ";\n");
  378. }
  379. if (typeName == "String")
  380. Log::WriteRaw("String(const char*);\n");
  381. }
  382. unsigned methods = type->GetMethodCount();
  383. for (unsigned j = 0; j < methods; ++j)
  384. {
  385. asIScriptFunction* method = type->GetMethodByIndex(j);
  386. String methodName(method->GetName());
  387. String declaration(method->GetDeclaration(true, false, true));
  388. // Recreate tab escape sequences
  389. declaration.Replace("\t", "\\t");
  390. if (methodName.Contains("get_") || methodName.Contains("set_"))
  391. ExtractPropertyInfo(methodName, declaration, propertyInfos);
  392. else
  393. {
  394. // Sanitate the method name. For some operators fix name
  395. if (declaration.Contains("::op")) {
  396. declaration.Replace("::opEquals(", ":: operator==(");
  397. declaration.Replace("::opAssign(", ":: operator=(");
  398. declaration.Replace("::opAddAssign(", ":: operator+=(");
  399. declaration.Replace("::opAdd(", ":: operator+(");
  400. declaration.Replace("::opCmp(", ":: operator<(");
  401. declaration.Replace("::opPreInc(", ":: operator++(");
  402. declaration.Replace("::opPostInc()", ":: operator++(int)");
  403. declaration.Replace("::opIndex(", ":: operator[ ](");
  404. if (declaration.Contains("::opImplCast()") || declaration.Contains("::opImplConv()")) {
  405. int sp = declaration.Find(' ');
  406. String retType = declaration.Substring(0, sp);
  407. if (retType == "const")
  408. {
  409. sp = declaration.Find(' ', sp + 1);
  410. retType = declaration.Substring(0, sp);
  411. }
  412. declaration = "operator " + retType + "() const";
  413. }
  414. }
  415. if (!declaration.Contains("::op"))
  416. {
  417. String prefix(typeName + "::");
  418. declaration.Replace(prefix, "");
  419. ///\todo Is there a better way to mark deprecated API bindings for AngelScript?
  420. i32 posBegin = declaration.FindLast("const String&in = \"deprecated:");
  421. if (posBegin != String::NPOS)
  422. {
  423. // Assume this 'mark' is added as the last parameter
  424. i32 posEnd = declaration.Find(')', posBegin);
  425. if (posEnd != String::NPOS)
  426. {
  427. declaration.Replace(posBegin, posEnd - posBegin, "");
  428. posBegin = declaration.Find(", ", posBegin - 2);
  429. if (posBegin != String::NPOS)
  430. declaration.Replace(posBegin, 2, "");
  431. if (mode == DOXYGEN)
  432. declaration += " // deprecated";
  433. else if (mode == C_HEADER)
  434. declaration = "/* deprecated */\n" + declaration;
  435. }
  436. }
  437. methodDeclarations.Push(declaration);
  438. }
  439. }
  440. }
  441. // Assume that the same property is never both an accessor property, and a direct one
  442. unsigned properties = type->GetPropertyCount();
  443. for (unsigned j = 0; j < properties; ++j)
  444. {
  445. const char* propertyName;
  446. const char* propertyDeclaration;
  447. int typeId;
  448. type->GetProperty(j, &propertyName, &typeId);
  449. propertyDeclaration = scriptEngine_->GetTypeDeclaration(typeId);
  450. PropertyInfo newInfo;
  451. newInfo.name_ = String(propertyName);
  452. newInfo.type_ = String(propertyDeclaration);
  453. newInfo.read_ = newInfo.write_ = true;
  454. propertyInfos.Push(newInfo);
  455. }
  456. Sort(methodDeclarations.Begin(), methodDeclarations.End(), ComparePropertyStrings);
  457. Sort(propertyInfos.Begin(), propertyInfos.End(), ComparePropertyInfos);
  458. if (!methodDeclarations.Empty())
  459. {
  460. if (mode == DOXYGEN)
  461. Log::WriteRaw("\nMethods:\n\n");
  462. else if (mode == C_HEADER)
  463. Log::WriteRaw("// Methods:\n");
  464. for (const String& methodDeclaration : methodDeclarations)
  465. OutputAPIRow(mode, methodDeclaration);
  466. }
  467. if (!propertyInfos.Empty())
  468. {
  469. if (mode == DOXYGEN)
  470. Log::WriteRaw("\nProperties:\n\n");
  471. else if (mode == C_HEADER)
  472. Log::WriteRaw("\n// Properties:\n");
  473. for (const PropertyInfo& propertyInfo : propertyInfos)
  474. {
  475. String remark;
  476. String cppdoc;
  477. if (!propertyInfo.write_)
  478. remark = "readonly";
  479. else if (!propertyInfo.read_)
  480. remark = "writeonly";
  481. if (!remark.Empty())
  482. {
  483. if (mode == DOXYGEN)
  484. {
  485. remark = " // " + remark;
  486. }
  487. else if (mode == C_HEADER)
  488. {
  489. cppdoc = "/* " + remark + " */\n";
  490. remark.Clear();
  491. }
  492. }
  493. OutputAPIRow(mode, cppdoc + propertyInfo.type_ + " " + propertyInfo.name_ + remark);
  494. }
  495. }
  496. // Check for namespaced constants to be included in the class documentation
  497. HashMap<String, Vector<String>>::ConstIterator gcIt = globalConstants.Find(typeName);
  498. if (gcIt != globalConstants.End())
  499. {
  500. String prefix;
  501. if (mode == DOXYGEN)
  502. {
  503. Log::WriteRaw("\nConstants:\n\n");
  504. }
  505. else if (mode == C_HEADER)
  506. {
  507. Log::WriteRaw("\n// Constants:\n");
  508. prefix = "static const ";
  509. }
  510. const Vector<String>& constants = gcIt->second_;
  511. for (const String& constant : constants)
  512. OutputAPIRow(mode, prefix + constant);
  513. }
  514. if (mode == DOXYGEN)
  515. Log::WriteRaw("\n");
  516. else if (mode == C_HEADER)
  517. Log::WriteRaw("};\n");
  518. }
  519. }
  520. Vector<PropertyInfo> globalPropertyInfos;
  521. Vector<String> globalFunctions;
  522. unsigned functions = scriptEngine_->GetGlobalFunctionCount();
  523. for (unsigned i = 0; i < functions; ++i)
  524. {
  525. asIScriptFunction* function = scriptEngine_->GetGlobalFunctionByIndex(i);
  526. String functionName(function->GetName());
  527. String declaration(function->GetDeclaration(true, false, true));
  528. // Recreate tab escape sequences
  529. declaration.Replace("\t", "\\t");
  530. if (functionName.Contains("set_") || functionName.Contains("get_"))
  531. ExtractPropertyInfo(functionName, declaration, globalPropertyInfos);
  532. else
  533. globalFunctions.Push(declaration);
  534. }
  535. Sort(globalFunctions.Begin(), globalFunctions.End(), ComparePropertyStrings);
  536. Sort(globalPropertyInfos.Begin(), globalPropertyInfos.End(), ComparePropertyInfos);
  537. if (mode == DOXYGEN)
  538. Log::WriteRaw("\\section ScriptAPI_Enums Enumerations\n");
  539. else if (mode == C_HEADER)
  540. Log::WriteRaw("\n// Enumerations\n");
  541. unsigned enums = scriptEngine_->GetEnumCount();
  542. Vector<Pair<String, unsigned>> sortedEnums;
  543. for (unsigned i = 0; i < enums; ++i)
  544. sortedEnums.Push(MakePair(String(scriptEngine_->GetEnumByIndex(i)->GetName()), i));
  545. Sort(sortedEnums.Begin(), sortedEnums.End());
  546. for (unsigned i = 0; i < sortedEnums.Size(); ++i)
  547. {
  548. asITypeInfo* enumType = scriptEngine_->GetEnumByIndex(sortedEnums[i].second_);
  549. int typeId = enumType->GetTypeId();
  550. if (mode == DOXYGEN)
  551. Log::WriteRaw("\n### " + String(enumType->GetName()) + "\n\n");
  552. else if (mode == C_HEADER)
  553. Log::WriteRaw("\nenum " + String(enumType->GetName()) + "\n{\n");
  554. for (unsigned j = 0; j < enumType->GetEnumValueCount(); ++j)
  555. {
  556. int value = 0;
  557. const char* name = enumType->GetEnumValueByIndex(j, &value);
  558. OutputAPIRow(mode, String(name), false, ",");
  559. }
  560. if (mode == DOXYGEN)
  561. Log::WriteRaw("\n");
  562. else if (mode == C_HEADER)
  563. Log::WriteRaw("};\n");
  564. }
  565. if (mode == DOXYGEN)
  566. Log::WriteRaw("\\section ScriptAPI_GlobalFunctions Global functions\n");
  567. else if (mode == C_HEADER)
  568. Log::WriteRaw("\n// Global functions\n");
  569. for (const String& globalFunction : globalFunctions)
  570. OutputAPIRow(mode, globalFunction);
  571. if (mode == DOXYGEN)
  572. Log::WriteRaw("\\section ScriptAPI_GlobalProperties Global properties\n");
  573. else if (mode == C_HEADER)
  574. Log::WriteRaw("\n// Global properties\n");
  575. for (const PropertyInfo& globalPropertyInfo : globalPropertyInfos)
  576. OutputAPIRow(mode, globalPropertyInfo.type_ + " " + globalPropertyInfo.name_, true);
  577. if (mode == DOXYGEN)
  578. Log::WriteRaw("\\section ScriptAPI_GlobalConstants Global constants\n");
  579. else if (mode == C_HEADER)
  580. Log::WriteRaw("\n// Global constants\n");
  581. const Vector<String>& noNameSpaceConstants = globalConstants[String()];
  582. for (const String& noNameSpaceConstant : noNameSpaceConstants)
  583. OutputAPIRow(mode, noNameSpaceConstant, true);
  584. if (mode == DOXYGEN)
  585. Log::WriteRaw("*/\n\n}\n");
  586. }
  587. }