载入中...
搜索中...
未找到
ScriptCompiler.h
浏览该文件的文档.
1#pragma once
2
4
5#include "common/Export.h"
8
9#include <simplesquirrel/script.hpp>
10
11#include <cstddef>
12#include <cstdint>
13#include <memory>
14#include <optional>
15#include <string>
16#include <string_view>
17#include <unordered_map>
18#include <unordered_set>
19#include <vector>
20
21namespace ssq {
22class VM;
23}
24
25namespace eve::script {
26
27class ScriptModuleResolver;
28
31
34 uint32_t line = 1;
35 uint32_t column = 1;
36};
37
40 std::string code;
41 ScriptDiagnosticSeverity severity = ScriptDiagnosticSeverity::Error;
42 std::string message;
43 std::string canonicalUri;
45 std::string related;
46 std::string fix;
47};
48
54
57 std::string canonicalUri;
58 std::vector<ScriptSourceMapEntry> entries;
59
61 ScriptSourcePosition originalPosition(ScriptSourcePosition generated) const noexcept;
63 ScriptSourcePosition generatedPosition(ScriptSourcePosition original) const noexcept;
64};
65
73
76 std::string name;
77 std::string erasedType;
79 std::unordered_map<std::string, std::string> attributes;
80 std::vector<std::string> choices;
81};
82
87 uint32_t languageVersion = 1;
88 std::string sourceHash;
89 std::string canonicalUri;
90 std::string providerOrigin;
91 std::vector<std::string> imports;
92 std::vector<std::string> exports;
93 std::vector<std::string> dependencies;
94 std::vector<std::string> reverseDependencies;
95 std::vector<ScriptSymbolMetadata> symbols;
96 std::vector<ScriptPropertyMetadata> properties;
97 std::vector<std::string> persistRoots;
98 std::vector<std::string> moduleReferences;
99 std::vector<std::string> asyncFunctions;
100 std::vector<ScriptSourcePosition> awaitLocations;
102 std::vector<ScriptDiagnostic> diagnostics;
103};
104
107 std::string label;
108 std::string kind;
109 std::string detail;
110 std::string insertText;
111};
112
119
122
125 std::string name;
126 std::string type = "dynamic";
127 bool nullable = false;
128 std::optional<std::string> scriptDefault;
129 ScriptUnit unit = ScriptUnit::None;
130 std::vector<std::string> choices;
131};
132
141 std::string stateOwner;
142 std::string ownerSource;
143 std::string inputHash;
144 std::string limitations;
145 std::vector<std::string> writes;
146 std::vector<std::string> tests;
147 std::vector<std::string> reads;
148};
149
152 std::string factory, role, resultClass;
153 int identityArgument = -1, relatedArgument = -1;
155 std::string schemaJson;
156};
157
160 std::string module;
161 std::string scriptClass;
162 std::string method;
163 std::vector<BindingParameterContract> parameters;
164 std::string returnType = "dynamic";
165 bool returnNullable = false;
166 std::string ownership;
167 std::string threadAffinity = "main";
168 std::vector<std::string> platforms;
169 std::string documentationId;
171 std::string source;
173 std::string cppSymbol;
175 std::optional<BindingArchitectureContract> architecture;
177 std::optional<BindingSemanticContract> semantics;
178
180 std::string key() const;
185 std::string toJson() const;
186};
187
193
196public:
198 void registerContract(BindingContract contract);
200 bool unregisterContract(std::string_view key);
208 const BindingContract* find(std::string_view key) const noexcept;
216 const BindingContract* findMethod(std::string_view method) const noexcept;
224 const BindingContract* findMethod(std::string_view scriptClass, std::string_view method) const noexcept;
226 bool hasScriptClass(std::string_view scriptClass) const noexcept;
228 std::vector<BindingContract> snapshot() const;
237 std::vector<BindingSearchHit> search(std::string_view query, std::string_view moduleFilter = {},
238 std::string_view classFilter = {}, size_t limit = 20) const;
239
240private:
241 struct Storage {
242 std::unordered_map<std::string, BindingContract> contracts;
243 };
244
245 void ensureUnique();
246 std::shared_ptr<Storage> storage_ = std::make_shared<Storage>();
247};
248
251public:
253 ScriptCompiler(ssq::VM& vm, ScriptModuleResolver& modules);
256
258 ssq::Script compileSource(std::string_view source, std::string_view sourceName);
260 ssq::Script compileFile(std::string_view path);
268 [[nodiscard]] eve::OptionalRef<const ScriptMetadata> metadata(std::string_view canonicalUri) const noexcept;
270 std::vector<ScriptMetadata> metadataSnapshot() const;
274 const BindingContractRegistry& bindings() const noexcept;
276 void registerAnnotation(std::string name);
278 bool unregisterAnnotation(std::string_view name);
280 std::vector<ScriptCompletion> completions(std::string_view canonicalUri, std::string_view prefix = {}) const;
282 std::optional<ScriptHover> hover(std::string_view canonicalUri, std::string_view symbol) const;
284 std::vector<ScriptDiagnostic> diagnostics(std::string_view canonicalUri) const;
286 bool setSourceMap(std::string_view canonicalUri, ScriptSourceMap sourceMap);
288 static ScriptSourcePosition toOriginalPosition(std::string_view source, ScriptSourcePosition generated);
290 static ScriptSourcePosition toGeneratedPosition(std::string_view source, ScriptSourcePosition original);
292 static SQRESULT compileBuffer(HSQUIRRELVM vm, const SQChar* source, SQInteger size, const SQChar* sourceName,
293 SQBool raiseError);
295 static std::vector<ScriptDiagnostic> validateProjectConfig(std::string_view source, std::string_view canonicalUri,
296 const std::vector<std::string>& knownModules,
297 const std::vector<std::string>& activeModules);
298
300 static ScriptMetadata analyze(std::string_view source, std::string_view canonicalUri);
301
302private:
303 void refreshDependencyMetadata();
304 ssq::VM* vm_;
305 ScriptModuleResolver* modules_;
306 BindingContractRegistry bindings_;
307 std::unordered_set<std::string> nativeGlobals_;
308 std::unordered_set<std::string> annotations_;
309 std::unordered_map<std::string, ScriptMetadata> metadata_;
310};
311
312} // namespace eve::script
double score
Definition Agent.cpp:51
Vocabulary aliases for nullable and checked borrowed references.
struct SQVM * HSQUIRRELVM
HSQUIRRELVM vm
Definition ECS.cpp:38
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
EnvironmentMetricContract contract
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
HexSearchContext search
Frontier reused by the land-growth and erosion searches.
Snapshot snapshot
std::vector< ParticleBakeMaterial > bindings
std::string path
Definition PlayHost.cpp:111
unsigned line
std::string_view source
unsigned column
Share string attribute map operations through the Windows Foundation DLL.
TacticalUnit * unit
int limit
Definition TreeMesh.cpp:166
float size
Definition TreeMesh.cpp:158
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:21
Static implementation evidence and reviewed owner metadata for a binding. @ownership Owns strings and...
Complete script-facing contract for a native function or method.
std::optional< BindingSemanticContract > semantics
Engine-owned source semantics; never supplied by a project relation manifest.
std::vector< BindingParameterContract > parameters
std::string cppSymbol
Direct member target; empty for unresolved lambda/dynamic targets.
std::string source
Actual native registration location.
std::vector< std::string > platforms
std::optional< BindingArchitectureContract > architecture
Optional reviewed mapping; absence is explicitly reported as unknown.
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.
Complete script-facing contract for a native function or method.
std::string schemaJson
Generator-validated JSON schema projection; empty when no source schema is supplied.
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
ScriptStructure structure
Lexed source structure retained for compiler and project tooling; not a runtime trace.
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.
Bounded structural analysis, independent of VM execution and binding resolution.
Erased source-level symbol retained for tooling.