gd_editor.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. /*************************************************************************/
  2. /* gd_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "gd_script.h"
  30. #include "gd_compiler.h"
  31. void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
  32. p_delimiters->push_back("#");
  33. }
  34. void GDScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const {
  35. p_delimiters->push_back("\" \"");
  36. p_delimiters->push_back("' '");
  37. }
  38. String GDScriptLanguage::get_template(const String& p_class_name, const String& p_base_class_name) const {
  39. String _template = String()+
  40. "\nextends %BASE%\n\n"+
  41. "# member variables here, example:\n"+
  42. "# var a=2\n"+
  43. "# var b=\"textvar\"\n\n"+
  44. "func _ready():\n"+
  45. "\t# Initalization here\n"+
  46. "\tpass\n"+
  47. "\n"+
  48. "\n";
  49. return _template.replace("%BASE%",p_base_class_name);
  50. }
  51. bool GDScriptLanguage::validate(const String& p_script, int &r_line_error,int &r_col_error,String& r_test_error, const String& p_path,List<String> *r_functions) const {
  52. GDParser parser;
  53. Error err = parser.parse(p_script,p_path.get_base_dir());
  54. if (err) {
  55. r_line_error=parser.get_error_line();
  56. r_col_error=parser.get_error_column();
  57. r_test_error=parser.get_error();
  58. return false;
  59. } else {
  60. const GDParser::Node *root = parser.get_parse_tree();
  61. ERR_FAIL_COND_V(root->type!=GDParser::Node::TYPE_CLASS,false);
  62. const GDParser::ClassNode *cl = static_cast<const GDParser::ClassNode*>(root);
  63. Map<int,String> funcs;
  64. for(int i=0;i<cl->functions.size();i++) {
  65. funcs[cl->functions[i]->line]=cl->functions[i]->name;
  66. }
  67. for(int i=0;i<cl->static_functions.size();i++) {
  68. funcs[cl->static_functions[i]->line]=cl->static_functions[i]->name;
  69. }
  70. for (Map<int,String>::Element *E=funcs.front();E;E=E->next()) {
  71. r_functions->push_back(E->get()+":"+itos(E->key()));
  72. }
  73. }
  74. return true;
  75. }
  76. bool GDScriptLanguage::has_named_classes() const {
  77. return false;
  78. }
  79. int GDScriptLanguage::find_function(const String& p_function,const String& p_code) const {
  80. GDTokenizer tokenizer;
  81. tokenizer.set_code(p_code);
  82. int indent=0;
  83. while(tokenizer.get_token()!=GDTokenizer::TK_EOF && tokenizer.get_token()!=GDTokenizer::TK_ERROR) {
  84. if (tokenizer.get_token()==GDTokenizer::TK_NEWLINE) {
  85. indent=tokenizer.get_token_line_indent();
  86. }
  87. if (indent==0 && tokenizer.get_token()==GDTokenizer::TK_PR_FUNCTION && tokenizer.get_token(1)==GDTokenizer::TK_IDENTIFIER) {
  88. String identifier = tokenizer.get_token_identifier(1);
  89. if (identifier==p_function) {
  90. return tokenizer.get_token_line();
  91. }
  92. }
  93. tokenizer.advance();
  94. }
  95. return -1;
  96. }
  97. Script *GDScriptLanguage::create_script() const {
  98. return memnew( GDScript );
  99. }
  100. /* DEBUGGER FUNCTIONS */
  101. bool GDScriptLanguage::debug_break_parse(const String& p_file, int p_line,const String& p_error) {
  102. //break because of parse error
  103. if (ScriptDebugger::get_singleton() && Thread::get_caller_ID()==Thread::get_main_ID()) {
  104. _debug_parse_err_line=p_line;
  105. _debug_parse_err_file=p_file;
  106. _debug_error=p_error;
  107. ScriptDebugger::get_singleton()->debug(this,false);
  108. return true;
  109. } else {
  110. return false;
  111. }
  112. }
  113. bool GDScriptLanguage::debug_break(const String& p_error,bool p_allow_continue) {
  114. if (ScriptDebugger::get_singleton() && Thread::get_caller_ID()==Thread::get_main_ID()) {
  115. _debug_parse_err_line=-1;
  116. _debug_parse_err_file="";
  117. _debug_error=p_error;
  118. ScriptDebugger::get_singleton()->debug(this,p_allow_continue);
  119. return true;
  120. } else {
  121. return false;
  122. }
  123. }
  124. String GDScriptLanguage::debug_get_error() const {
  125. return _debug_error;
  126. }
  127. int GDScriptLanguage::debug_get_stack_level_count() const {
  128. if (_debug_parse_err_line>=0)
  129. return 1;
  130. return _debug_call_stack_pos;
  131. }
  132. int GDScriptLanguage::debug_get_stack_level_line(int p_level) const {
  133. if (_debug_parse_err_line>=0)
  134. return _debug_parse_err_line;
  135. ERR_FAIL_INDEX_V(p_level,_debug_call_stack_pos,-1);
  136. int l = _debug_call_stack_pos - p_level -1;
  137. return *(_call_stack[l].line);
  138. }
  139. String GDScriptLanguage::debug_get_stack_level_function(int p_level) const {
  140. if (_debug_parse_err_line>=0)
  141. return "";
  142. ERR_FAIL_INDEX_V(p_level,_debug_call_stack_pos,"");
  143. int l = _debug_call_stack_pos - p_level -1;
  144. return _call_stack[l].function->get_name();
  145. }
  146. String GDScriptLanguage::debug_get_stack_level_source(int p_level) const {
  147. if (_debug_parse_err_line>=0)
  148. return _debug_parse_err_file;
  149. ERR_FAIL_INDEX_V(p_level,_debug_call_stack_pos,"");
  150. int l = _debug_call_stack_pos - p_level -1;
  151. return _call_stack[l].function->get_script()->get_path();
  152. }
  153. void GDScriptLanguage::debug_get_stack_level_locals(int p_level,List<String> *p_locals, List<Variant> *p_values, int p_max_subitems,int p_max_depth) {
  154. if (_debug_parse_err_line>=0)
  155. return;
  156. ERR_FAIL_INDEX(p_level,_debug_call_stack_pos);
  157. int l = _debug_call_stack_pos - p_level -1;
  158. GDFunction *f = _call_stack[l].function;
  159. List<Pair<StringName,int> > locals;
  160. f->debug_get_stack_member_state(*_call_stack[l].line,&locals);
  161. for( List<Pair<StringName,int> >::Element *E = locals.front();E;E=E->next() ) {
  162. p_locals->push_back(E->get().first);
  163. p_values->push_back(_call_stack[l].stack[E->get().second]);
  164. }
  165. }
  166. void GDScriptLanguage::debug_get_stack_level_members(int p_level,List<String> *p_members, List<Variant> *p_values, int p_max_subitems,int p_max_depth) {
  167. if (_debug_parse_err_line>=0)
  168. return;
  169. ERR_FAIL_INDEX(p_level,_debug_call_stack_pos);
  170. int l = _debug_call_stack_pos - p_level -1;
  171. GDInstance *instance = _call_stack[l].instance;
  172. if (!instance)
  173. return;
  174. Ref<GDScript> script = instance->get_script();
  175. ERR_FAIL_COND( script.is_null() );
  176. const Map<StringName,int>& mi = script->debug_get_member_indices();
  177. for(const Map<StringName,int>::Element *E=mi.front();E;E=E->next()) {
  178. p_members->push_back(E->key());
  179. p_values->push_back( instance->debug_get_member_by_index(E->get()));
  180. }
  181. }
  182. void GDScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems,int p_max_depth) {
  183. //no globals are really reachable in gdscript
  184. }
  185. String GDScriptLanguage::debug_parse_stack_level_expression(int p_level,const String& p_expression,int p_max_subitems,int p_max_depth) {
  186. if (_debug_parse_err_line>=0)
  187. return "";
  188. return "";
  189. }
  190. void GDScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const {
  191. p_extensions->push_back("gd");
  192. }
  193. void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const {
  194. for(int i=0;i<GDFunctions::FUNC_MAX;i++) {
  195. p_functions->push_back(GDFunctions::get_info(GDFunctions::Function(i)));
  196. }
  197. }
  198. String GDScriptLanguage::make_function(const String& p_class,const String& p_name,const StringArray& p_args) const {
  199. String s="func "+p_name+"(";
  200. if (p_args.size()) {
  201. s+=" ";
  202. for(int i=0;i<p_args.size();i++) {
  203. if (i>0)
  204. s+=", ";
  205. s+=p_args[i];
  206. }
  207. s+=" ";
  208. }
  209. s+="):\n\tpass # replace with function body\n";
  210. return s;
  211. }
  212. static void _parse_native_symbols(const StringName& p_native,bool p_static,List<String>* r_options) {
  213. if (!p_static) {
  214. List<MethodInfo> methods;
  215. ObjectTypeDB::get_method_list(p_native,&methods);
  216. for(List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
  217. if (!E->get().name.begins_with("_")) {
  218. r_options->push_back(E->get().name);
  219. }
  220. }
  221. }
  222. List<String> constants;
  223. ObjectTypeDB::get_integer_constant_list(p_native,&constants);
  224. for(List<String>::Element *E=constants.front();E;E=E->next()) {
  225. r_options->push_back(E->get());
  226. }
  227. }
  228. static bool _parse_script_symbols(const Ref<GDScript>& p_script,bool p_static,List<String>* r_options,List<String>::Element *p_indices);
  229. static bool _parse_completion_variant(const Variant& p_var,List<String>* r_options,List<String>::Element *p_indices) {
  230. if (p_indices) {
  231. bool ok;
  232. Variant si = p_var.get(p_indices->get(),&ok);
  233. if (!ok)
  234. return false;
  235. return _parse_completion_variant(si,r_options,p_indices->next());
  236. } else {
  237. switch(p_var.get_type()) {
  238. case Variant::DICTIONARY: {
  239. Dictionary d=p_var;
  240. List<Variant> vl;
  241. d.get_key_list(&vl);
  242. for (List<Variant>::Element *E=vl.front();E;E=E->next()) {
  243. if (E->get().get_type()==Variant::STRING)
  244. r_options->push_back(E->get());
  245. }
  246. List<MethodInfo> ml;
  247. p_var.get_method_list(&ml);
  248. for(List<MethodInfo>::Element *E=ml.front();E;E=E->next()) {
  249. r_options->push_back(E->get().name);
  250. }
  251. } break;
  252. case Variant::OBJECT: {
  253. Object *o=p_var;
  254. if (o) {
  255. print_line("OBJECT: "+o->get_type());
  256. if (p_var.is_ref() && o->cast_to<GDScript>()) {
  257. Ref<GDScript> gds = p_var;
  258. _parse_script_symbols(gds,true,r_options,NULL);
  259. } else if (o->is_type("GDNativeClass")){
  260. GDNativeClass *gnc = o->cast_to<GDNativeClass>();
  261. _parse_native_symbols(gnc->get_name(),false,r_options);
  262. } else {
  263. print_line("REGULAR BLEND");
  264. _parse_native_symbols(o->get_type(),false,r_options);
  265. }
  266. }
  267. } break;
  268. default: {
  269. List<PropertyInfo> pi;
  270. p_var.get_property_list(&pi);
  271. for(List<PropertyInfo>::Element *E=pi.front();E;E=E->next()) {
  272. r_options->push_back(E->get().name);
  273. }
  274. List<StringName> cl;
  275. p_var.get_numeric_constants_for_type(p_var.get_type(),&cl);
  276. for(List<StringName>::Element *E=cl.front();E;E=E->next()) {
  277. r_options->push_back(E->get());
  278. }
  279. List<MethodInfo> ml;
  280. p_var.get_method_list(&ml);
  281. for(List<MethodInfo>::Element *E=ml.front();E;E=E->next()) {
  282. r_options->push_back(E->get().name);
  283. }
  284. } break;
  285. }
  286. return true;
  287. }
  288. }
  289. static void _parse_expression_node(const GDParser::Node *p_node,List<String>* r_options,List<String>::Element *p_indices) {
  290. if (p_node->type==GDParser::Node::TYPE_CONSTANT) {
  291. const GDParser::ConstantNode *cn=static_cast<const GDParser::ConstantNode *>(p_node);
  292. _parse_completion_variant(cn->value,r_options,p_indices?p_indices->next():NULL);
  293. } else if (p_node->type==GDParser::Node::TYPE_DICTIONARY) {
  294. const GDParser::DictionaryNode *dn=static_cast<const GDParser::DictionaryNode*>(p_node);
  295. for(int i=0;i<dn->elements.size();i++) {
  296. if (dn->elements[i].key->type==GDParser::Node::TYPE_CONSTANT) {
  297. const GDParser::ConstantNode *cn=static_cast<const GDParser::ConstantNode *>(dn->elements[i].key);
  298. if (cn->value.get_type()==Variant::STRING) {
  299. String str=cn->value;
  300. if (p_indices) {
  301. if (str==p_indices->get()) {
  302. _parse_expression_node(dn->elements[i].value,r_options,p_indices->next());
  303. return;
  304. }
  305. } else {
  306. r_options->push_back(str);
  307. }
  308. }
  309. }
  310. }
  311. }
  312. }
  313. static bool _parse_completion_block(const GDParser::BlockNode *p_block,int p_line,List<String>* r_options,List<String>::Element *p_indices) {
  314. for(int i=0;i<p_block->sub_blocks.size();i++) {
  315. //parse inner first
  316. if (p_line>=p_block->sub_blocks[i]->line && (p_line<=p_block->sub_blocks[i]->end_line || p_block->sub_blocks[i]->end_line==-1)) {
  317. if (_parse_completion_block(p_block->sub_blocks[i],p_line,r_options,p_indices))
  318. return true;
  319. }
  320. }
  321. if (p_indices) {
  322. //parse indices in expressions :|
  323. for (int i=0;i<p_block->statements.size();i++) {
  324. if (p_block->statements[i]->line>p_line)
  325. break;
  326. if (p_block->statements[i]->type==GDParser::BlockNode::TYPE_LOCAL_VAR) {
  327. const GDParser::LocalVarNode *lv=static_cast<const GDParser::LocalVarNode *>(p_block->statements[i]);
  328. if (lv->assign && String(lv->name)==p_indices->get()) {
  329. _parse_expression_node(lv->assign,r_options,p_indices->next());
  330. return true;
  331. }
  332. }
  333. }
  334. } else {
  335. for(int i=0;i<p_block->variables.size();i++) {
  336. //parse variables second
  337. if (p_line>=p_block->variable_lines[i]) {
  338. r_options->push_back(p_block->variables[i]);
  339. }
  340. else break;
  341. }
  342. }
  343. return false;
  344. }
  345. static bool _parse_script_symbols(const Ref<GDScript>& p_script,bool p_static,List<String>* r_options,List<String>::Element *p_indices) {
  346. //for (Map<StringName,Ref<GDScript> >::Element ?
  347. if (!p_static && !p_indices) {
  348. for(const Set<StringName>::Element *E=p_script->get_members().front();E;E=E->next()) {
  349. r_options->push_back(E->get());
  350. }
  351. }
  352. for (const Map<StringName,Variant >::Element *E=p_script->get_constants().front();E;E=E->next()) {
  353. if( p_indices) {
  354. if (p_indices->get()==String(E->get())) {
  355. _parse_completion_variant(E->get(),r_options,p_indices->next());
  356. return true;
  357. }
  358. } else {
  359. r_options->push_back(E->key());
  360. }
  361. }
  362. if (!p_indices){
  363. for (const Map<StringName,GDFunction>::Element *E=p_script->get_member_functions().front();E;E=E->next()) {
  364. if (E->get().is_static() || !p_static)
  365. r_options->push_back(E->key());
  366. }
  367. }
  368. if (p_script->get_base().is_valid()){
  369. if (_parse_script_symbols(p_script->get_base(),p_static,r_options,p_indices))
  370. return true;
  371. } else if (p_script->get_native().is_valid() && !p_indices) {
  372. _parse_native_symbols(p_script->get_native()->get_name(),p_static,r_options);
  373. }
  374. return false;
  375. }
  376. static bool _parse_completion_class(const String& p_base_path,const GDParser::ClassNode *p_class,int p_line,List<String>* r_options,List<String>::Element *p_indices) {
  377. static const char*_type_names[Variant::VARIANT_MAX]={
  378. "null","bool","int","float","String","Vector2","Rect2","Vector3","Matrix32","Plane","Quat","AABB","Matrix3","Trasnform",
  379. "Color","Image","NodePath","RID","Object","InputEvent","Dictionary","Array","RawArray","IntArray","FloatArray","StringArray",
  380. "Vector2Array","Vector3Array","ColorArray"};
  381. if (p_indices && !p_indices->next()) {
  382. for(int i=0;i<Variant::VARIANT_MAX;i++) {
  383. if (p_indices->get()==_type_names[i]) {
  384. List<StringName> ic;
  385. Variant::get_numeric_constants_for_type(Variant::Type(i),&ic);
  386. for(List<StringName>::Element *E=ic.front();E;E=E->next()) {
  387. r_options->push_back(E->get());
  388. }
  389. return true;
  390. }
  391. }
  392. }
  393. for(int i=0;i<p_class->subclasses.size();i++) {
  394. if (p_line>=p_class->subclasses[i]->line && (p_line<=p_class->subclasses[i]->end_line || p_class->subclasses[i]->end_line==-1)) {
  395. if (_parse_completion_class(p_base_path,p_class->subclasses[i],p_line,r_options,p_indices))
  396. return true;
  397. }
  398. }
  399. bool in_static_func=false;
  400. for(int i=0;i<p_class->functions.size();i++) {
  401. const GDParser::FunctionNode *fu = p_class->functions[i];
  402. if (p_line>=fu->body->line && (p_line<=fu->body->end_line || fu->body->end_line==-1)) {
  403. //if in function, first block stuff from outer to inner
  404. if (_parse_completion_block(fu->body,p_line,r_options,p_indices))
  405. return true;
  406. //then function arguments
  407. if (!p_indices) {
  408. for(int j=0;j<fu->arguments.size();j++) {
  409. r_options->push_back(fu->arguments[j]);
  410. }
  411. }
  412. }
  413. }
  414. for(int i=0;i<p_class->static_functions.size();i++) {
  415. const GDParser::FunctionNode *fu = p_class->static_functions[i];
  416. if (p_line>=fu->body->line && (p_line<=fu->body->end_line || fu->body->end_line==-1)) {
  417. //if in function, first block stuff from outer to inne
  418. if (_parse_completion_block(fu->body,p_line,r_options,p_indices))
  419. return true;
  420. //then function arguments
  421. if (!p_indices) {
  422. for(int j=0;j<fu->arguments.size();j++) {
  423. r_options->push_back(fu->arguments[j]);
  424. }
  425. }
  426. in_static_func=true;
  427. }
  428. }
  429. //add all local names
  430. if (!p_indices) {
  431. if (!in_static_func) {
  432. for(int i=0;i<p_class->variables.size();i++) {
  433. r_options->push_back(p_class->variables[i].identifier);
  434. }
  435. }
  436. for(int i=0;i<p_class->constant_expressions.size();i++) {
  437. r_options->push_back(p_class->constant_expressions[i].identifier);
  438. }
  439. if (!in_static_func) {
  440. for(int i=0;i<p_class->functions.size();i++) {
  441. r_options->push_back(p_class->functions[i]->name);
  442. }
  443. }
  444. for(int i=0;i<p_class->static_functions.size();i++) {
  445. r_options->push_back(p_class->static_functions[i]->name);
  446. }
  447. }
  448. if (p_class->extends_used) {
  449. //do inheritance
  450. String path = p_class->extends_file;
  451. Ref<GDScript> script;
  452. Ref<GDNativeClass> native;
  453. if (path!="") {
  454. //path (and optionally subclasses)
  455. script = ResourceLoader::load(path);
  456. if (script.is_null()) {
  457. return false;
  458. }
  459. if (p_class->extends_class.size()) {
  460. for(int i=0;i<p_class->extends_class.size();i++) {
  461. String sub = p_class->extends_class[i];
  462. if (script->get_subclasses().has(sub)) {
  463. script=script->get_subclasses()[sub];
  464. } else {
  465. return false;
  466. }
  467. }
  468. }
  469. } else {
  470. ERR_FAIL_COND_V(p_class->extends_class.size()==0,false);
  471. //look around for the subclasses
  472. String base=p_class->extends_class[0];
  473. Ref<GDScript> base_class;
  474. #if 0
  475. while(p) {
  476. if (p->subclasses.has(base)) {
  477. base_class=p->subclasses[base];
  478. break;
  479. }
  480. p=p->_owner;
  481. }
  482. if (base_class.is_valid()) {
  483. for(int i=1;i<p_class->extends_class.size();i++) {
  484. String subclass=p_class->extends_class[i];
  485. if (base_class->subclasses.has(subclass)) {
  486. base_class=base_class->subclasses[subclass];
  487. } else {
  488. _set_error("Could not find subclass: "+subclass,p_class);
  489. return ERR_FILE_NOT_FOUND;
  490. }
  491. }
  492. } else {
  493. #endif
  494. if (p_class->extends_class.size()>1) {
  495. return false;
  496. }
  497. //if not found, try engine classes
  498. if (!GDScriptLanguage::get_singleton()->get_global_map().has(base)) {
  499. return false;
  500. }
  501. int base_idx = GDScriptLanguage::get_singleton()->get_global_map()[base];
  502. native = GDScriptLanguage::get_singleton()->get_global_array()[base_idx];
  503. if (!native.is_valid()) {
  504. return false;
  505. }
  506. #if 0
  507. }
  508. #endif
  509. }
  510. if (script.is_valid()) {
  511. if (_parse_script_symbols(script,in_static_func,r_options,p_indices))
  512. return true;
  513. } else if (native.is_valid() && !p_indices) {
  514. _parse_native_symbols(native->get_name(),in_static_func,r_options);
  515. }
  516. }
  517. return false;
  518. }
  519. Error GDScriptLanguage::complete_keyword(const String& p_code, int p_line, const String& p_base_path, const String& p_base, List<String>* r_options) {
  520. GDParser p;
  521. Error err = p.parse(p_code,p_base_path);
  522. // don't care much about error I guess
  523. const GDParser::Node* root = p.get_parse_tree();
  524. ERR_FAIL_COND_V(root->type!=GDParser::Node::TYPE_CLASS,ERR_INVALID_DATA);
  525. const GDParser::ClassNode *cl = static_cast<const GDParser::ClassNode*>(root);
  526. List<String> indices;
  527. Vector<String> spl = p_base.split(".");
  528. for(int i=0;i<spl.size()-1;i++) {
  529. indices.push_back(spl[i]);
  530. }
  531. if (_parse_completion_class(p_base,cl,p_line,r_options,indices.front()))
  532. return OK;
  533. //and the globals x_x?
  534. for(Map<StringName,int>::Element *E=globals.front();E;E=E->next()) {
  535. if (!indices.empty()) {
  536. if (String(E->key())==indices.front()->get()) {
  537. _parse_completion_variant(global_array[E->get()],r_options,indices.front()->next());
  538. return OK;
  539. }
  540. } else {
  541. r_options->push_back(E->key());
  542. }
  543. }
  544. return OK;
  545. }