| 687 | } |
| 688 | |
| 689 | void ShaderPreprocessor::process_include(Tokenizer *p_tokenizer) { |
| 690 | const int line = p_tokenizer->get_line(); |
| 691 | |
| 692 | p_tokenizer->advance('"'); |
| 693 | String path = tokens_to_string(p_tokenizer->advance('"')); |
| 694 | for (int i = 0; i < path.length(); i++) { |
| 695 | if (path[i] == '\n') { |
| 696 | break; //stop parsing |
| 697 | } |
| 698 | if (path[i] == CURSOR) { |
| 699 | state->completion_type = COMPLETION_TYPE_INCLUDE_PATH; |
| 700 | break; |
| 701 | } |
| 702 | } |
| 703 | path = path.substr(0, path.length() - 1); |
| 704 | |
| 705 | if (path.is_empty() || !p_tokenizer->consume_empty_line()) { |
| 706 | set_error(RTR("Invalid path."), line); |
| 707 | return; |
| 708 | } |
| 709 | |
| 710 | path = path.simplify_path(); |
| 711 | if (path.is_relative_path()) { |
| 712 | path = state->current_filename.get_base_dir().path_join(path); |
| 713 | } |
| 714 | |
| 715 | if (!ResourceLoader::exists(path)) { |
| 716 | set_error(RTR("Shader include file does not exist:") + " " + path, line); |
| 717 | return; |
| 718 | } |
| 719 | |
| 720 | Ref<Resource> res = ResourceLoader::load(path); |
| 721 | if (res.is_null()) { |
| 722 | set_error(RTR("Shader include load failed. Does the shader include exist? Is there a cyclic dependency?"), line); |
| 723 | return; |
| 724 | } |
| 725 | |
| 726 | Ref<ShaderInclude> shader_inc = res; |
| 727 | if (shader_inc.is_null()) { |
| 728 | set_error(RTR("Shader include resource type is wrong."), line); |
| 729 | return; |
| 730 | } |
| 731 | |
| 732 | String included = shader_inc->get_code(); |
| 733 | if (!included.is_empty()) { |
| 734 | uint64_t code_hash = included.hash64(); |
| 735 | if (state->cyclic_include_hashes.find(code_hash)) { |
| 736 | set_error(RTR("Cyclic include found") + ": " + path, line); |
| 737 | return; |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | state->shader_includes.insert(shader_inc); |
| 742 | |
| 743 | const String real_path = shader_inc->get_path(); |
| 744 | if (state->includes.has(real_path)) { |
| 745 | // Already included, skip. |
| 746 | // This is a valid check because 2 separate include paths could use some |
nothing calls this directly
no test coverage detected