ScriptAPIDump.cpp 26 KB

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