载入中...
搜索中...
未找到
ScriptCompiler.h
浏览该文件的文档.
1#pragma once
2
4
5#include "common/Export.h"
6
7#include <simplesquirrel/script.hpp>
8
9#include <cstddef>
10#include <cstdint>
11#include <memory>
12#include <optional>
13#include <string>
14#include <string_view>
15#include <unordered_map>
16#include <unordered_set>
17#include <vector>
18
19namespace ssq {
20class VM;
21}
22
23namespace eve::script {
24
25class ScriptModuleResolver;
26
29
32 uint32_t line = 1;
33 uint32_t column = 1;
34};
35
38 std::string code;
39 ScriptDiagnosticSeverity severity = ScriptDiagnosticSeverity::Error;
40 std::string message;
41 std::string canonicalUri;
43 std::string related;
44 std::string fix;
45};
46
52
55 std::string canonicalUri;
56 std::vector<ScriptSourceMapEntry> entries;
57
59 ScriptSourcePosition originalPosition(ScriptSourcePosition generated) const noexcept;
61 ScriptSourcePosition generatedPosition(ScriptSourcePosition original) const noexcept;
62};
63
71
74 std::string name;
75 std::string erasedType;
77 std::unordered_map<std::string, std::string> attributes;
78 std::vector<std::string> choices;
79};
80
83 uint32_t languageVersion = 1;
84 std::string sourceHash;
85 std::string canonicalUri;
86 std::string providerOrigin;
87 std::vector<std::string> imports;
88 std::vector<std::string> exports;
89 std::vector<std::string> dependencies;
90 std::vector<std::string> reverseDependencies;
91 std::vector<ScriptSymbolMetadata> symbols;
92 std::vector<ScriptPropertyMetadata> properties;
93 std::vector<std::string> persistRoots;
94 std::vector<std::string> moduleReferences;
95 std::vector<std::string> asyncFunctions;
96 std::vector<ScriptSourcePosition> awaitLocations;
98 std::vector<ScriptDiagnostic> diagnostics;
99};
100
103 std::string label;
104 std::string kind;
105 std::string detail;
106 std::string insertText;
107};
108
115
118
121 std::string name;
122 std::string type = "dynamic";
123 bool nullable = false;
124 std::optional<std::string> scriptDefault;
125 ScriptUnit unit = ScriptUnit::None;
126 std::vector<std::string> choices;
127};
128
131 std::string module;
132 std::string scriptClass;
133 std::string method;
134 std::vector<BindingParameterContract> parameters;
135 std::string returnType = "dynamic";
136 bool returnNullable = false;
137 std::string ownership;
138 std::string threadAffinity = "main";
139 std::vector<std::string> platforms;
140 std::string documentationId;
141
143 std::string key() const;
148 std::string toJson() const;
149};
150
156
159public:
161 void registerContract(BindingContract contract);
163 bool unregisterContract(std::string_view key);
171 const BindingContract* find(std::string_view key) const noexcept;
179 const BindingContract* findMethod(std::string_view method) const noexcept;
187 const BindingContract* findMethod(std::string_view scriptClass, std::string_view method) const noexcept;
189 bool hasScriptClass(std::string_view scriptClass) const noexcept;
191 std::vector<BindingContract> snapshot() const;
200 std::vector<BindingSearchHit> search(std::string_view query, std::string_view moduleFilter = {},
201 std::string_view classFilter = {}, size_t limit = 20) const;
202
203private:
204 struct Storage {
205 std::unordered_map<std::string, BindingContract> contracts;
206 };
207
208 void ensureUnique();
209 std::shared_ptr<Storage> storage_ = std::make_shared<Storage>();
210};
211
214public:
216 ScriptCompiler(ssq::VM& vm, ScriptModuleResolver& modules);
219
221 ssq::Script compileSource(std::string_view source, std::string_view sourceName);
223 ssq::Script compileFile(std::string_view path);
231 [[nodiscard]] eve::OptionalRef<const ScriptMetadata> metadata(std::string_view canonicalUri) const noexcept;
233 std::vector<ScriptMetadata> metadataSnapshot() const;
237 const BindingContractRegistry& bindings() const noexcept;
239 void registerAnnotation(std::string name);
241 bool unregisterAnnotation(std::string_view name);
243 std::vector<ScriptCompletion> completions(std::string_view canonicalUri, std::string_view prefix = {}) const;
245 std::optional<ScriptHover> hover(std::string_view canonicalUri, std::string_view symbol) const;
247 std::vector<ScriptDiagnostic> diagnostics(std::string_view canonicalUri) const;
249 bool setSourceMap(std::string_view canonicalUri, ScriptSourceMap sourceMap);
251 static ScriptSourcePosition toOriginalPosition(std::string_view source, ScriptSourcePosition generated);
253 static ScriptSourcePosition toGeneratedPosition(std::string_view source, ScriptSourcePosition original);
255 static SQRESULT compileBuffer(HSQUIRRELVM vm, const SQChar* source, SQInteger size, const SQChar* sourceName,
256 SQBool raiseError);
258 static std::vector<ScriptDiagnostic> validateProjectConfig(std::string_view source, std::string_view canonicalUri,
259 const std::vector<std::string>& knownModules,
260 const std::vector<std::string>& activeModules);
261
263 static ScriptMetadata analyze(std::string_view source, std::string_view canonicalUri);
264
265private:
266 void refreshDependencyMetadata();
267 ssq::VM* vm_;
268 ScriptModuleResolver* modules_;
269 BindingContractRegistry bindings_;
270 std::unordered_set<std::string> nativeGlobals_;
271 std::unordered_set<std::string> annotations_;
272 std::unordered_map<std::string, ScriptMetadata> metadata_;
273};
274
275} // namespace eve::script
double score
Definition Agent.cpp:50
Vocabulary aliases for nullable and checked borrowed references.
struct SQVM * HSQUIRRELVM
int column
HSQUIRRELVM vm
Definition ECS.cpp:20
std::uint16_t method
#define EVENGINE_API_FOUNDATION_INLINE
仅供"只有内联成员"的类型使用的组宏:拥有者 dllexport,消费方不导入。
Definition Export.h:170
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
#define EVENGINE_API
宿主(eve / libmain)导出宏;插件从进程导入同一批符号。
Definition Export.h:31
std::uint32_t key
HexSearchContext search
Frontier reused by the land-growth and erosion searches.
std::string name
std::vector< std::shared_ptr< DeviceBytes > > bindings
Definition OnnxGpgpu.cpp:38
std::string path
Definition PlayHost.cpp:110
TacticalUnit * unit
int limit
Definition TreeMesh.cpp:164
float size
Definition TreeMesh.cpp:156
const UnitySourceAsset & source
Registry consumed by compiler checks and tooling protocol adapters.
Unified Runtime compiler facade for metadata, diagnostics, and module preparation.
Owns providers, the static dependency graph, compiled closures, and module instances.
ScriptUnit
Unit attached to a binding parameter or return value.
ScriptDiagnosticSeverity
Severity of a structured EveScript compiler diagnostic.
std::optional< std::reference_wrapper< T > > OptionalRef
Optional borrowed reference; it does not extend T's lifetime.
Definition BorrowedRef.h:24
EVEngine ECS 集成层:底层实现使用 sunxfancy/ECS.hpp https://github.com/sunxfancy/ECS.hpp
Definition ECS.h:14
Complete script-facing contract for a native function or method.
std::vector< BindingParameterContract > parameters
std::vector< std::string > platforms
std::string std::string scriptClass
One native binding parameter visible to EveScript tools and named arguments.
std::vector< std::string > choices
std::optional< std::string > scriptDefault
Ranked Binding Contract hit from text search.
Tool-neutral completion item suitable for LSP, MCP, and editor adapters.
Stable structured diagnostic shared by Runtime, LSP, MCP, and editor tools.
ScriptSourcePosition position
Tool-neutral hover result for one script or binding symbol.
ScriptSourcePosition position
Metadata retained for one compiled EveScript source unit.
std::vector< std::string > imports
std::vector< std::string > moduleReferences
std::vector< ScriptSourcePosition > awaitLocations
std::vector< std::string > dependencies
std::vector< ScriptPropertyMetadata > properties
std::vector< ScriptDiagnostic > diagnostics
std::vector< std::string > asyncFunctions
std::vector< std::string > persistRoots
std::vector< ScriptSymbolMetadata > symbols
std::vector< std::string > exports
std::vector< std::string > reverseDependencies
Inspector-facing metadata for one annotated script property.
std::vector< std::string > choices
std::unordered_map< std::string, std::string > attributes
One generated-to-original mapping segment. Native syntax uses identity mappings.
Source map for a compiled script.
std::vector< ScriptSourceMapEntry > entries
Original EveScript source position. Lines and columns are one-based.
Erased source-level symbol retained for tooling.