ScriptAPIDump.cpp 26 KB

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