summaryrefslogtreecommitdiff
path: root/tools/doc/doc_data.cpp
blob: d51dc886b2bfb153b4b40bae43133e1afb6ef09a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
/*************************************************************************/
/*  doc_data.cpp                                                         */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                    http://www.godotengine.org                         */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the       */
/* "Software"), to deal in the Software without restriction, including   */
/* without limitation the rights to use, copy, modify, merge, publish,   */
/* distribute, sublicense, and/or sell copies of the Software, and to    */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions:                                             */
/*                                                                       */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/
#include "doc_data.h"

#include "version.h"
#include "global_constants.h"
#include "globals.h"
#include "script_language.h"
#include "io/marshalls.h"
#include "io/compression.h"
#include "scene/resources/theme.h"

void DocData::merge_from(const DocData& p_data) {

	for( Map<String,ClassDoc>::Element *E=class_list.front();E;E=E->next()) {


		ClassDoc &c = E->get();

		if (!p_data.class_list.has(c.name))
			continue;

		const ClassDoc &cf = p_data.class_list[c.name];

		c.description=cf.description;
		c.brief_description=cf.brief_description;

		for(int i=0;i<c.methods.size();i++) {

			MethodDoc &m = c.methods[i];

			for(int j=0;j<cf.methods.size();j++) {

				if (cf.methods[j].name!=m.name)
					continue;
				if (cf.methods[j].arguments.size()!=m.arguments.size())
					continue;
				// since polymorphic functions are allowed we need to check the type of
				// the arguments so we make sure they are different.
				int arg_count = cf.methods[j].arguments.size();
				Vector<bool> arg_used;
				arg_used.resize(arg_count);
				for (int l = 0; l < arg_count; ++l) arg_used[l] = false;
				// also there is no guarantee that argument ordering will match, so we
				// have to check one by one so we make sure we have an exact match
				for (int k = 0; k < arg_count; ++k) {
					for (int l = 0; l < arg_count; ++l)
						if (cf.methods[j].arguments[k].type == m.arguments[l].type && !arg_used[l]) {
							arg_used[l] = true;
							break;
						}
				}
				bool not_the_same = false;
				for (int l = 0; l < arg_count; ++l)
					if (!arg_used[l]) // at least one of the arguments was different
						not_the_same = true;
				if (not_the_same)
					continue;

				const MethodDoc &mf = cf.methods[j];

				m.description=mf.description;
				break;
			}
		}


		for(int i=0;i<c.signals.size();i++) {

			MethodDoc &m = c.signals[i];

			for(int j=0;j<cf.signals.size();j++) {

				if (cf.signals[j].name!=m.name)
					continue;
				const MethodDoc &mf = cf.signals[j];

				m.description=mf.description;
				break;
			}
		}

		for(int i=0;i<c.constants.size();i++) {

			ConstantDoc &m = c.constants[i];

			for(int j=0;j<cf.constants.size();j++) {

				if (cf.constants[j].name!=m.name)
					continue;
				const ConstantDoc &mf = cf.constants[j];

				m.description=mf.description;
				break;
			}
		}

		for(int i=0;i<c.properties.size();i++) {

			PropertyDoc &p = c.properties[i];

			for(int j=0;j<cf.properties.size();j++) {

				if (cf.properties[j].name!=p.name)
					continue;
				const PropertyDoc &pf = cf.properties[j];

				p.description=pf.description;
				p.setter=pf.setter;
				p.getter=pf.getter;

				break;
			}
		}

		for(int i=0;i<c.theme_properties.size();i++) {

			PropertyDoc &p = c.theme_properties[i];

			for(int j=0;j<cf.theme_properties.size();j++) {

				if (cf.theme_properties[j].name!=p.name)
					continue;
				const PropertyDoc &pf = cf.theme_properties[j];

				p.description=pf.description;
				break;
			}
		}

	}

}

void DocData::generate(bool p_basic_types) {


	List<StringName> classes;
	ClassDB::get_class_list(&classes);
	classes.sort_custom<StringName::AlphCompare>();

	while(classes.size()) {

		String name=classes.front()->get();
		String cname=name;
		if (cname.begins_with("_")) //proxy class
			cname=cname.substr(1,name.length());

		class_list[cname]=ClassDoc();
		ClassDoc& c = class_list[cname];
		c.name=cname;
		c.inherits=ClassDB::get_parent_class(name);
		c.category=ClassDB::get_category(name);


		List<PropertyInfo> properties;
		ClassDB::get_property_list(name,&properties,true);

		for(List<PropertyInfo>::Element *E=properties.front();E;E=E->next()) {
			if (E->get().usage& PROPERTY_USAGE_GROUP || E->get().usage& PROPERTY_USAGE_CATEGORY)
				continue;

			PropertyDoc prop;
			StringName setter = ClassDB::get_property_setter(name,E->get().name);
			StringName getter = ClassDB::get_property_getter(name,E->get().name);

			prop.name=E->get().name;
			prop.setter=setter;
			prop.getter=getter;
			if (E->get().type==Variant::OBJECT && E->get().hint==PROPERTY_HINT_RESOURCE_TYPE)
				prop.type=E->get().hint_string;
			else
				prop.type=Variant::get_type_name(E->get().type);

			c.properties.push_back(prop);
		}


		List<MethodInfo> method_list;
		ClassDB::get_method_list(name,&method_list,true);
		method_list.sort();


		for(List<MethodInfo>::Element *E=method_list.front();E;E=E->next()) {

			if (E->get().name=="" || (E->get().name[0]=='_' && !(E->get().flags&METHOD_FLAG_VIRTUAL)))
				continue; //hiden, dont count

			MethodDoc method;

			method.name=E->get().name;

			MethodBind *m = ClassDB::get_method(name,E->get().name);


			if (E->get().flags&METHOD_FLAG_VIRTUAL)
				method.qualifiers="virtual";
			if (E->get().flags&METHOD_FLAG_CONST) {
				if (method.qualifiers!="")
					method.qualifiers+=" ";
				method.qualifiers+="const";

			} else if (E->get().flags&METHOD_FLAG_VARARG) {
				if (method.qualifiers!="")
					method.qualifiers+=" ";
				method.qualifiers+="vararg";
			}

			for(int i=-1;i<E->get().arguments.size();i++) {

				PropertyInfo arginfo;

				if (i==-1) {


					arginfo=E->get().return_val;
#ifdef DEBUG_METHODS_ENABLED
					if (m && m->get_return_type()!=StringName())
						method.return_type=m->get_return_type();
					else if (method.name.find(":")!=-1) {
						method.return_type=method.name.get_slice(":",1);
						method.name=method.name.get_slice(":",0);

					} else if (arginfo.type!=Variant::NIL) // {
#endif
						method.return_type=(arginfo.hint==PROPERTY_HINT_RESOURCE_TYPE)?arginfo.hint_string:Variant::get_type_name(arginfo.type);
					//}

				} else {

					ArgumentDoc argument;

					arginfo=E->get().arguments[i];

					String type_name;

					if (arginfo.name.find(":")!=-1) {
						type_name=arginfo.name.get_slice(":",1);
						arginfo.name=arginfo.name.get_slice(":",0);

					} else if (arginfo.hint==PROPERTY_HINT_RESOURCE_TYPE) {
						type_name=arginfo.hint_string;
					} else if (arginfo.type==Variant::NIL)
						type_name="Variant";
					else
						type_name=Variant::get_type_name(arginfo.type);

					if (arginfo.type==Variant::OBJECT) {

						//print_line("validate: "+cname+"::"+method.name);
					}

					if (m && m->has_default_argument(i)) {
						Variant default_arg=m->get_default_argument(i);
						String default_arg_text=m->get_default_argument(i);

						switch(default_arg.get_type()) {

							case Variant::NIL:
								default_arg_text="NULL";
								break;
							// atomic types
							case Variant::BOOL:
								if (bool(default_arg))
									default_arg_text="true";
								else
									default_arg_text="false";
								break;
							case Variant::INT:
							case Variant::REAL:
								//keep it
								break;
							case Variant::STRING:		// 15
							case Variant::NODE_PATH:		// 15
								default_arg_text="\""+default_arg_text+"\"";
								break;
							case Variant::TRANSFORM:
								if (default_arg.operator Transform()==Transform()) {
									default_arg_text="";
								}

								default_arg_text=Variant::get_type_name(default_arg.get_type())+"("+default_arg_text+")";
								break;

							case Variant::RECT3: //sorry naming convention fail :( not like it's used often // 10
							case Variant::COLOR:
							case Variant::PLANE:
							case Variant::POOL_BYTE_ARRAY:
							case Variant::POOL_INT_ARRAY:
							case Variant::POOL_REAL_ARRAY:
							case Variant::POOL_STRING_ARRAY:	//25
							case Variant::POOL_VECTOR2_ARRAY:
							case Variant::POOL_VECTOR3_ARRAY:
							case Variant::POOL_COLOR_ARRAY:
								default_arg_text=Variant::get_type_name(default_arg.get_type())+"("+default_arg_text+")";
								break;
							case Variant::VECTOR2:		// 5
							case Variant::RECT2:
							case Variant::VECTOR3:
							case Variant::QUAT:
							case Variant::BASIS:
								default_arg_text=Variant::get_type_name(default_arg.get_type())+default_arg_text;
								break;
							case Variant::OBJECT:
								if (default_arg.is_zero()) {
									default_arg_text="NULL";
									break;
								}
							case Variant::INPUT_EVENT:
							case Variant::DICTIONARY:		// 20
							case Variant::ARRAY:
							case Variant::_RID:
							case Variant::IMAGE:
							//case Variant::RESOURCE:

								default_arg_text=Variant::get_type_name(default_arg.get_type())+"()";
								break;
							default: {}

						}


						argument.type=type_name;
						argument.name=arginfo.name;
						argument.default_value=default_arg_text;
					} else {

						argument.type=type_name;
						argument.name=arginfo.name;
					}

					if (arginfo.type==Variant::OBJECT) {

						//print_line("validate: "+cname+"::"+method.name);
					}

					method.arguments.push_back(argument);
				}

/*
				String hint;
				switch(arginfo.hint) {
					case PROPERTY_HINT_DIR: hint="A directory."; break;
					case PROPERTY_HINT_RANGE: hint="Range - min: "+arginfo.hint_string.get_slice(",",0)+" max: "+arginfo.hint_string.get_slice(",",1)+" step: "+arginfo.hint_string.get_slice(",",2); break;
					case PROPERTY_HINT_ENUM: hint="Values: "; for(int j=0;j<arginfo.hint_string.get_slice_count(",");j++) { if (j>0) hint+=", "; hint+=arginfo.hint_string.get_slice(",",j)+"="+itos(j); } break;
					case PROPERTY_HINT_LENGTH: hint="Length: "+arginfo.hint_string; break;
					case PROPERTY_HINT_FLAGS: hint="Values: "; for(int j=0;j<arginfo.hint_string.get_slice_count(",");j++) { if (j>0) hint+=", "; hint+=arginfo.hint_string.get_slice(",",j)+"="+itos(1<<j); } break;
					case PROPERTY_HINT_FILE: hint="A file:"; break;
					//case PROPERTY_HINT_RESOURCE_TYPE: hint="Type: "+arginfo.hint_string; break;
				};
				if (hint!="")
					_write_string(f,4,hint);
*/


			}

			c.methods.push_back(method);
		}

		List<MethodInfo> signal_list;
		ClassDB::get_signal_list(name,&signal_list,true);

		if (signal_list.size()) {


			for(List<MethodInfo>::Element *EV=signal_list.front();EV;EV=EV->next()) {

				MethodDoc signal;
				signal.name=EV->get().name;
				for(int i=0;i<EV->get().arguments.size();i++) {

					PropertyInfo arginfo=EV->get().arguments[i];
					ArgumentDoc argument;
					argument.name=arginfo.name;
					argument.type=Variant::get_type_name(arginfo.type);
					signal.arguments.push_back(argument);
				}

				c.signals.push_back(signal);
			}


		}

		List<String> constant_list;
		ClassDB::get_integer_constant_list(name, &constant_list, true);

		for(List<String>::Element *E=constant_list.front();E;E=E->next()) {

			ConstantDoc constant;
			constant.name=E->get();
			constant.value=itos(ClassDB::get_integer_constant(name, E->get()));
			c.constants.push_back(constant);
		}

		//theme stuff

		{
			List<StringName> l;
			Theme::get_default()->get_constant_list(cname,&l);
			for (List<StringName>::Element*E=l.front();E;E=E->next()) {

				PropertyDoc pd;
				pd.name=E->get();
				pd.type="int";
				c.theme_properties.push_back(pd);
			}

			l.clear();
			Theme::get_default()->get_color_list(cname,&l);
			for (List<StringName>::Element*E=l.front();E;E=E->next()) {

				PropertyDoc pd;
				pd.name=E->get();
				pd.type="Color";
				c.theme_properties.push_back(pd);
			}

			l.clear();
			Theme::get_default()->get_icon_list(cname,&l);
			for (List<StringName>::Element*E=l.front();E;E=E->next()) {

				PropertyDoc pd;
				pd.name=E->get();
				pd.type="Texture";
				c.theme_properties.push_back(pd);
			}
			l.clear();
			Theme::get_default()->get_font_list(cname,&l);
			for (List<StringName>::Element*E=l.front();E;E=E->next()) {

				PropertyDoc pd;
				pd.name=E->get();
				pd.type="Font";
				c.theme_properties.push_back(pd);
			}
			l.clear();
			Theme::get_default()->get_stylebox_list(cname,&l);
			for (List<StringName>::Element*E=l.front();E;E=E->next()) {

				PropertyDoc pd;
				pd.name=E->get();
				pd.type="StyleBox";
				c.theme_properties.push_back(pd);
			}

		}


		classes.pop_front();
	}


	{
		//so it can be documented that it does not exist
		class_list["Variant"]=ClassDoc();
		class_list["Variant"].name="Variant";
	}

	if (!p_basic_types)
		return;

	for (int i=0;i<Variant::VARIANT_MAX;i++) {

		if (i==Variant::OBJECT)
			continue; //use the core type instead

		int loops=1;

		if (i==Variant::INPUT_EVENT)
			loops=InputEvent::TYPE_MAX;

		for(int j=0;j<loops;j++) {

			String cname=Variant::get_type_name(Variant::Type(i));

			if (i==Variant::INPUT_EVENT) {
				static const char* ie_type[InputEvent::TYPE_MAX]={
					"","Key","MouseMotion","MouseButton","JoypadMotion","JoypadButton","ScreenTouch","ScreenDrag","Action"
				};
				cname+=ie_type[j];
			}


			class_list[cname]=ClassDoc();
			ClassDoc& c = class_list[cname];
			c.name=cname;
			c.category="Built-In Types";

			Variant::CallError cerror;
			Variant v=Variant::construct(Variant::Type(i),NULL,0,cerror);

			if (i==Variant::INPUT_EVENT) {
				v.set("type",j);
			}

			List<MethodInfo> method_list;
			v.get_method_list(&method_list);
			method_list.sort();
			Variant::get_constructor_list(Variant::Type(i),&method_list);


			for(List<MethodInfo>::Element *E=method_list.front();E;E=E->next()) {

				MethodInfo &mi=E->get();
				MethodDoc method;

				method.name=mi.name;

				for(int i=0;i<mi.arguments.size();i++) {

					ArgumentDoc arg;
					PropertyInfo pi=mi.arguments[i];

					arg.name=pi.name;
					//print_line("arg name: "+arg.name);
					if (pi.type==Variant::NIL)
						arg.type="var";
					else
						arg.type=Variant::get_type_name(pi.type);
					int defarg = mi.default_arguments.size() - mi.arguments.size() + i;
					if (defarg >=0)
						arg.default_value=mi.default_arguments[defarg];

					method.arguments.push_back(arg);
				}

				if (mi.return_val.type==Variant::NIL) {
					if (mi.return_val.name!="")
					    method.return_type="var";

				} else {
					method.return_type=Variant::get_type_name(mi.return_val.type);
				}

				c.methods.push_back(method);
			}


			List<PropertyInfo> properties;
			v.get_property_list(&properties);
			for(List<PropertyInfo>::Element *E=properties.front();E;E=E->next()) {

				PropertyInfo pi=E->get();
				PropertyDoc property;
				property.name=pi.name;
				property.type=Variant::get_type_name(pi.type);

				c.properties.push_back(property);
			}

			List<StringName> constants;
			Variant::get_numeric_constants_for_type(Variant::Type(i),&constants);

			for(List<StringName>::Element *E=constants.front();E;E=E->next()) {

				ConstantDoc constant;
				constant.name=E->get();
				constant.value=itos(Variant::get_numeric_constant_value(Variant::Type(i),E->get()));
				c.constants.push_back(constant);
			}
		}

	}

	//built in constants and functions

	{

		String cname="@Global Scope";
		class_list[cname]=ClassDoc();
		ClassDoc& c = class_list[cname];
		c.name=cname;


		for(int i=0;i<GlobalConstants::get_global_constant_count();i++) {

			ConstantDoc cd;
			cd.name=GlobalConstants::get_global_constant_name(i);
			cd.value=itos(GlobalConstants::get_global_constant_value(i));
			c.constants.push_back(cd);
		}

		List<GlobalConfig::Singleton> singletons;
		GlobalConfig::get_singleton()->get_singletons(&singletons);

		//servers (this is kind of hackish)
		for(List<GlobalConfig::Singleton>::Element *E=singletons.front();E;E=E->next()) {

			PropertyDoc pd;
			GlobalConfig::Singleton &s=E->get();
			pd.name=s.name;
			pd.type=s.ptr->get_class();
			while (String(ClassDB::get_parent_class(pd.type))!="Object")
				pd.type=ClassDB::get_parent_class(pd.type);
			if (pd.type.begins_with("_"))
				pd.type=pd.type.substr(1,pd.type.length());
			c.properties.push_back(pd);

		}

	}

	//built in script reference

	{


		for(int i=0;i<ScriptServer::get_language_count();i++) {


			ScriptLanguage *lang = ScriptServer::get_language(i);
			String cname="@"+lang->get_name();
			class_list[cname]=ClassDoc();
			ClassDoc& c = class_list[cname];
			c.name=cname;

			List<MethodInfo> minfo;

			lang->get_public_functions(&minfo);


			for(List<MethodInfo>::Element *E=minfo.front();E;E=E->next()) {

				MethodInfo &mi=E->get();
				MethodDoc md;
				md.name=mi.name;
				if (mi.return_val.name!="")
					md.return_type=mi.return_val.name;
				else if (mi.name.find(":")!=-1) {
					md.return_type=mi.name.get_slice(":",1);
					md.name=mi.name.get_slice(":",0);
				} else
					md.return_type=Variant::get_type_name(mi.return_val.type);

				for(int i=0;i<mi.arguments.size();i++) {

					PropertyInfo &pi=mi.arguments[i];

					ArgumentDoc ad;
					ad.name=pi.name;


					if (pi.type==Variant::NIL)
						ad.type="Variant";
					else
						ad.type=Variant::get_type_name( pi.type );

					md.arguments.push_back(ad);
				}

				c.methods.push_back(md);

			}

			List<Pair<String,Variant> > cinfo;
			lang->get_public_constants(&cinfo);


			for(List<Pair<String,Variant> >::Element *E=cinfo.front();E;E=E->next()) {

				ConstantDoc cd;
				cd.name=E->get().first;
				cd.value=E->get().second;
				c.constants.push_back(cd);
			}
		}
	}


}


static Error _parse_methods(Ref<XMLParser>& parser,Vector<DocData::MethodDoc>& methods) {

	String section=parser->get_node_name();
	String element=section.substr(0,section.length()-1);

	while(parser->read()==OK) {

		if (parser->get_node_type() == XMLParser::NODE_ELEMENT)	{

			if (parser->get_node_name()==element) {

				DocData::MethodDoc method;
				ERR_FAIL_COND_V(!parser->has_attribute("name"),ERR_FILE_CORRUPT);
				method.name=parser->get_attribute_value("name");
				if (parser->has_attribute("qualifiers"))
					method.qualifiers=parser->get_attribute_value("qualifiers");


				while(parser->read()==OK) {

					if (parser->get_node_type() == XMLParser::NODE_ELEMENT)	{

						String name=parser->get_node_name();
						if (name=="return") {

							ERR_FAIL_COND_V(!parser->has_attribute("type"),ERR_FILE_CORRUPT);
							method.return_type=parser->get_attribute_value("type");
						} else if (name=="argument") {

							DocData::ArgumentDoc argument;
							ERR_FAIL_COND_V(!parser->has_attribute("name"),ERR_FILE_CORRUPT);
							argument.name=parser->get_attribute_value("name");
							ERR_FAIL_COND_V(!parser->has_attribute("type"),ERR_FILE_CORRUPT);
							argument.type=parser->get_attribute_value("type");

							method.arguments.push_back(argument);

						} else if (name=="description") {

							parser->read();
							if (parser->get_node_type()==XMLParser::NODE_TEXT)
								method.description=parser->get_node_data().strip_edges();
						}

					} else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name()==element)
						break;
				}

				methods.push_back(method);

			} else {
				ERR_EXPLAIN("Invalid tag in doc file: "+parser->get_node_name());
				ERR_FAIL_V(ERR_FILE_CORRUPT);
			}

		} else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name()==section)
			break;
	}

	return OK;
}

Error DocData::load(const String& p_path) {

	Ref<XMLParser> parser=memnew(XMLParser);
	Error err = parser->open(p_path);
	if (err)
		return err;
	return _load(parser);

}
Error DocData::_load(Ref<XMLParser> parser) {

	Error err=OK;

	while((err=parser->read())==OK) {

		if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {

			if (parser->get_node_name() == "doc") {
				break;
			} else if (!parser->is_empty())
				parser->skip_section();// unknown section, likely headers
		}
	}

	if (parser->has_attribute("version"))
		version=parser->get_attribute_value("version");


	while((err=parser->read())==OK) {


		if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name()=="doc")
			break; //end of <doc>

		if (parser->get_node_type() != XMLParser::NODE_ELEMENT)
			continue; //no idea what this may be, but skipping anyway

		ERR_FAIL_COND_V( parser->get_node_name()!="class", ERR_FILE_CORRUPT );

		ERR_FAIL_COND_V( !parser->has_attribute("name"), ERR_FILE_CORRUPT);
		String name = parser->get_attribute_value("name");
		class_list[name]=ClassDoc();
		ClassDoc& c = class_list[name];

		//print_line("class: "+name);
		c.name=name;
		if (parser->has_attribute("inherits"))
			c.inherits = parser->get_attribute_value("inherits");
		if (parser->has_attribute("category"))
			c.category = parser->get_attribute_value("category");

		while(parser->read()==OK) {

			if (parser->get_node_type() == XMLParser::NODE_ELEMENT)	{

				String name = parser->get_node_name();

				if (name=="brief_description") {

					parser->read();
					if (parser->get_node_type()==XMLParser::NODE_TEXT)
						c.brief_description=parser->get_node_data().strip_edges();

				} else if (name=="description") {
					parser->read();
					if (parser->get_node_type()==XMLParser::NODE_TEXT)
						c.description=parser->get_node_data().strip_edges();
				} else if (name=="methods") {

					Error err = _parse_methods(parser,c.methods);
					ERR_FAIL_COND_V(err,err);

				} else if (name=="signals") {

					Error err = _parse_methods(parser,c.signals);
					ERR_FAIL_COND_V(err,err);
				} else if (name=="members") {

					while(parser->read()==OK) {

						if (parser->get_node_type() == XMLParser::NODE_ELEMENT)	{

							String name = parser->get_node_name();

							if (name=="member") {

								PropertyDoc prop;

								ERR_FAIL_COND_V(!parser->has_attribute("name"),ERR_FILE_CORRUPT);
								prop.name=parser->get_attribute_value("name");
								ERR_FAIL_COND_V(!parser->has_attribute("type"),ERR_FILE_CORRUPT);
								prop.type=parser->get_attribute_value("type");
								if (parser->has_attribute("setter"))
									prop.setter=parser->get_attribute_value("setter");
								if (parser->has_attribute("getter"))
									prop.getter=parser->get_attribute_value("getter");
								if (parser->has_attribute("brief"))
									prop.brief_description=parser->get_attribute_value("brief").xml_unescape();

								parser->read();
								if (parser->get_node_type()==XMLParser::NODE_TEXT)
									prop.description=parser->get_node_data().strip_edges();
								c.properties.push_back(prop);
							} else {
								ERR_EXPLAIN("Invalid tag in doc file: "+name);
								ERR_FAIL_V(ERR_FILE_CORRUPT);
							}

						} else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name()=="members")
							break; //end of <constants>
					}

				} else if (name=="theme_items") {

					while(parser->read()==OK) {

						if (parser->get_node_type() == XMLParser::NODE_ELEMENT)	{

							String name = parser->get_node_name();

							if (name=="theme_item") {

								PropertyDoc prop;

								ERR_FAIL_COND_V(!parser->has_attribute("name"),ERR_FILE_CORRUPT);
								prop.name=parser->get_attribute_value("name");
								ERR_FAIL_COND_V(!parser->has_attribute("type"),ERR_FILE_CORRUPT);
								prop.type=parser->get_attribute_value("type");
								parser->read();
								if (parser->get_node_type()==XMLParser::NODE_TEXT)
									prop.description=parser->get_node_data().strip_edges();
								c.theme_properties.push_back(prop);
							} else {
								ERR_EXPLAIN("Invalid tag in doc file: "+name);
								ERR_FAIL_V(ERR_FILE_CORRUPT);
							}

						} else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name()=="theme_items")
							break; //end of <constants>
					}

				} else if (name=="constants") {

					while(parser->read()==OK) {

						if (parser->get_node_type() == XMLParser::NODE_ELEMENT)	{

							String name=parser->get_node_name();

							if (name=="constant") {

								ConstantDoc constant;
								ERR_FAIL_COND_V(!parser->has_attribute("name"),ERR_FILE_CORRUPT);
								constant.name=parser->get_attribute_value("name");
								ERR_FAIL_COND_V(!parser->has_attribute("value"),ERR_FILE_CORRUPT);
								constant.value=parser->get_attribute_value("value");
								parser->read();
								if (parser->get_node_type()==XMLParser::NODE_TEXT)
									constant.description=parser->get_node_data().strip_edges();
								c.constants.push_back(constant);
							} else {
								ERR_EXPLAIN("Invalid tag in doc file: "+name);
								ERR_FAIL_V(ERR_FILE_CORRUPT);
							}

						} else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name()=="constants")
							break; //end of <constants>
					}

				} else {

					ERR_EXPLAIN("Invalid tag in doc file: "+name);
					ERR_FAIL_V(ERR_FILE_CORRUPT);
				}


			} else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name()=="class")
				break; //end of <asset>
		}


	}

	return OK;
}


static void _write_string(FileAccess *f,int p_tablevel,const String& p_string) {

	String tab;
	for(int i=0;i<p_tablevel;i++) tab+="\t";
	f->store_string(tab+p_string+"\n");
}

Error DocData::save(const String& p_path) {

	Error err;
	FileAccess *f = FileAccess::open(p_path,FileAccess::WRITE,&err);

	if (err) {
		ERR_EXPLAIN("Can't write doc file: "+p_path);

		ERR_FAIL_V(err);

	}

	_write_string(f,0,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
	_write_string(f,0,"<doc version=\""+String(VERSION_MKSTRING)+"\" name=\"Engine Types\">");

	for( Map<String,ClassDoc>::Element *E=class_list.front();E;E=E->next()) {

		ClassDoc &c=E->get();

		String header="<class name=\""+c.name+"\"";
		if (c.inherits!="")
			header+=" inherits=\""+c.inherits+"\"";

		String category=c.category;
		if (c.category=="")
			category="Core";
		header+=" category=\""+category+"\"";
		header+=">";
		_write_string(f,0,header);
		_write_string(f,1,"<brief_description>");
		if (c.brief_description!="")
			_write_string(f,2,c.brief_description.xml_escape());
		_write_string(f,1,"</brief_description>");
		_write_string(f,1,"<description>");
		if (c.description!="")
			_write_string(f,2,c.description.xml_escape());
		_write_string(f,1,"</description>");
		_write_string(f,1,"<methods>");

		c.methods.sort();

		for(int i=0;i<c.methods.size();i++) {

			MethodDoc &m=c.methods[i];

			String qualifiers;
			if (m.qualifiers!="")
				qualifiers+=" qualifiers=\""+m.qualifiers.xml_escape()+"\"";

			_write_string(f,2,"<method name=\""+m.name+"\""+qualifiers+">");

			if (m.return_type!="") {

				_write_string(f,3,"<return type=\""+m.return_type+"\">");
				_write_string(f,3,"</return>");
			}

			for(int j=0;j<m.arguments.size();j++) {

				ArgumentDoc &a = m.arguments[j];
				if (a.default_value!="")
					_write_string(f,3,"<argument index=\""+itos(j)+"\" name=\""+a.name.xml_escape()+"\" type=\""+a.type.xml_escape()+"\" default=\""+a.default_value.xml_escape(true)+"\">");
				else
					_write_string(f,3,"<argument index=\""+itos(j)+"\" name=\""+a.name.xml_escape()+"\" type=\""+a.type.xml_escape()+"\">");

				_write_string(f,3,"</argument>");

			}

			_write_string(f,3,"<description>");
			if (m.description!="")
				_write_string(f,4,m.description.xml_escape());
			_write_string(f,3,"</description>");

			_write_string(f,2,"</method>");

		}

		_write_string(f,1,"</methods>");

		if (c.properties.size()) {
			_write_string(f,1,"<members>");

			c.properties.sort();

			for(int i=0;i<c.properties.size();i++) {


				PropertyDoc &p=c.properties[i];
				_write_string(f,2,"<member name=\""+p.name+"\" type=\""+p.type+"\" setter=\""+p.setter+"\" getter=\""+p.getter+"\" brief=\""+p.brief_description.xml_escape(true)+"\">");
				if (p.description!="")
					_write_string(f,3,p.description.xml_escape());
				_write_string(f,2,"</member>");

			}
			_write_string(f,1,"</members>");
		}

		if (c.signals.size()) {

			c.signals.sort();

			_write_string(f,1,"<signals>");
			for(int i=0;i<c.signals.size();i++) {

				MethodDoc &m=c.signals[i];
				_write_string(f,2,"<signal name=\""+m.name+"\">");
				for(int j=0;j<m.arguments.size();j++) {

					ArgumentDoc &a = m.arguments[j];
						_write_string(f,3,"<argument index=\""+itos(j)+"\" name=\""+a.name.xml_escape()+"\" type=\""+a.type.xml_escape()+"\">");
						_write_string(f,3,"</argument>");

				}

				_write_string(f,3,"<description>");
				if (m.description!="")
					_write_string(f,4,m.description.xml_escape());
				_write_string(f,3,"</description>");

				_write_string(f,2,"</signal>");
			}

			_write_string(f,1,"</signals>");
		}

		_write_string(f,1,"<constants>");


		for(int i=0;i<c.constants.size();i++) {

			ConstantDoc &k=c.constants[i];
			_write_string(f,2,"<constant name=\""+k.name+"\" value=\""+k.value+"\">");
			if (k.description!="")
				_write_string(f,3,k.description.xml_escape());
			_write_string(f,2,"</constant>");
		}

		_write_string(f,1,"</constants>");

		if (c.theme_properties.size()) {

			c.theme_properties.sort();

			_write_string(f,1,"<theme_items>");
			for(int i=0;i<c.theme_properties.size();i++) {


				PropertyDoc &p=c.theme_properties[i];
				_write_string(f,2,"<theme_item name=\""+p.name+"\" type=\""+p.type+"\">");
				_write_string(f,2,"</theme_item>");

			}
			_write_string(f,1,"</theme_items>");
		}

		_write_string(f,0,"</class>");

	}

	_write_string(f,0,"</doc>");
	f->close();
	memdelete(f);

	return OK;
}


Error DocData::load_compressed(const uint8_t *p_data, int p_compressed_size, int p_uncompressed_size) {

	Vector<uint8_t> data;
	data.resize(p_uncompressed_size);
	Compression::decompress(data.ptr(),p_uncompressed_size,p_data,p_compressed_size,Compression::MODE_DEFLATE);
	class_list.clear();

	Ref<XMLParser> parser = memnew( XMLParser );
	Error err = parser->open_buffer(data);
	if (err)
		return err;

	_load(parser);

	return OK;

}