| 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 |
#pragma once |
| 32 |
|
| 33 |
#include "gdscript.h" |
| 34 |
|
| 35 |
#include "core/object/ref_counted.h" |
| 36 |
#include "core/os/safe_binary_mutex.h" |
| 37 |
#include "core/templates/hash_map.h" |
| 38 |
#include "core/templates/hash_set.h" |
| 39 |
|
| 40 |
class GDScriptAnalyzer; |
| 41 |
class GDScriptParser; |
| 42 |
|
| 43 |
class GDScriptParserRef : public RefCounted { |
| 44 |
GDSOFTCLASS(GDScriptParserRef, RefCounted); |
| 45 |
|
| 46 |
public: |
| 47 |
enum Status { |
| 48 |
EMPTY, |
| 49 |
PARSED, |
| 50 |
INHERITANCE_SOLVED, |
| 51 |
INTERFACE_SOLVED, |
| 52 |
FULLY_SOLVED, |
| 53 |
}; |
| 54 |
|
| 55 |
private: |
| 56 |
GDScriptParser *parser = nullptr; |
| 57 |
GDScriptAnalyzer *analyzer = nullptr; |
| 58 |
Status status = EMPTY; |
| 59 |
Error result = OK; |
| 60 |
String path; |
| 61 |
uint32_t source_hash = 0; |
| 62 |
bool clearing = false; |
| 63 |
bool abandoned = false; |
| 64 |
|
| 65 |
friend class GDScriptCache; |
| 66 |
friend class GDScript; |
| 67 |
|
| 68 |
public: |
| 69 |
Status get_status() const; |
| 70 |
String get_path() const; |
| 71 |
uint32_t get_source_hash() const; |
| 72 |
GDScriptParser *get_parser(); |
| 73 |
GDScriptAnalyzer *get_analyzer(); |
| 74 |
Error raise_status(Status p_new_status); |
| 75 |
void clear(); |
| 76 |
|
| 77 |
GDScriptParserRef() {} |
| 78 |
~GDScriptParserRef(); |
| 79 |
}; |
| 80 |
|
| 81 |
#ifdef TESTS_ENABLED |
| 82 |
namespace GDScriptTests { |
| 83 |
class TestGDScriptCacheAccessor; |
| 84 |
} |
| 85 |
#endif |
| 86 |
|
| 87 |
class GDScriptCache { |
| 88 |
|
| 89 |
HashMap<String, GDScriptParserRef *> parser_map; |
| 90 |
HashMap<String, Vector<ObjectID>> abandoned_parser_map; |
| 91 |
HashMap<String, Ref<GDScript>> shallow_gdscript_cache; |
| 92 |
HashMap<String, Ref<GDScript>> full_gdscript_cache; |
| 93 |
HashMap<String, Ref<GDScript>> static_gdscript_cache; |
| 94 |
HashMap<String, HashSet<String>> dependencies; |
| 95 |
HashMap<String, HashSet<String>> parser_inverse_dependencies; |
| 96 |
|
| 97 |
friend class GDScript; |
| 98 |
friend class GDScriptParserRef; |
| 99 |
friend class GDScriptInstance; |
| 100 |
#ifdef TESTS_ENABLED |
| 101 |
friend class GDScriptTests::TestGDScriptCacheAccessor; |
| 102 |
#endif |
| 103 |
|
| 104 |
static GDScriptCache *singleton; |
| 105 |
|
| 106 |
bool cleared = false; |
| 107 |
|
| 108 |
public: |
| 109 |
static const int BINARY_MUTEX_TAG = 2; |
| 110 |
|
| 111 |
private: |
| 112 |
static SafeBinaryMutex<BINARY_MUTEX_TAG> mutex; |
| 113 |
friend SafeBinaryMutex<BINARY_MUTEX_TAG> &_get_gdscript_cache_mutex(); |
| 114 |
|
| 115 |
public: |
| 116 |
static void move_script(const String &p_from, const String &p_to); |
| 117 |
static void remove_script(const String &p_path); |
| 118 |
static Ref<GDScriptParserRef> get_parser(const String &p_path, GDScriptParserRef::Status status, Error &r_error, const String &p_owner = String()); |
| 119 |
static bool has_parser(const String &p_path); |
| 120 |
static void remove_parser(const String &p_path); |
| 121 |
static String get_source_code(const String &p_path); |
| 122 |
static Vector<uint8_t> get_binary_tokens(const String &p_path); |
| 123 |
static Ref<GDScript> get_shallow_script(const String &p_path, Error &r_error, const String &p_owner = String()); |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
static Ref<GDScript> get_full_script(const String &p_path, Error &r_error, const String &p_owner = String(), bool p_update_from_disk = false); |
| 130 |
static Ref<GDScript> get_cached_script(const String &p_path); |
| 131 |
static Error finish_compiling(const String &p_owner); |
| 132 |
static void add_static_script(Ref<GDScript> p_script); |
| 133 |
static void remove_static_script(const String &p_fqcn); |
| 134 |
|
| 135 |
static void clear(); |
| 136 |
|
| 137 |
GDScriptCache(); |
| 138 |
~GDScriptCache(); |
| 139 |
}; |