MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / Build

Method Build

Sources/Jazz2/Scripting/ScriptLoader.cpp:336–496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334 }
335
336 ScriptBuildResult ScriptLoader::Build()
337 {
338 std::int32_t r = _module->Build();
339 if (r < 0) {
340 return (ScriptBuildResult)r;
341 }
342
343 // After the script has been built, the metadata strings should be stored for later lookup
344 for (auto& decl : _foundDeclarations) {
345 _module->SetDefaultNamespace(decl.Namespace.data());
346 switch (decl.Type) {
347 case MetadataType::Type: {
348 std::int32_t typeId = _module->GetTypeIdByDecl(decl.Declaration.data());
349 if (typeId >= 0) {
350 auto entry = _typeMetadataMap.emplace(typeId, Array<String>(NoInit, decl.Metadata.size())).first;
351 std::uninitialized_move(decl.Metadata.begin(), decl.Metadata.end(), entry->second.data());
352 }
353 break;
354 }
355 case MetadataType::Function: {
356 if (decl.ParentClass.empty()) {
357 asIScriptFunction* func = _module->GetFunctionByDecl(decl.Declaration.data());
358 if (func != nullptr) {
359 auto entry = _funcMetadataMap.emplace(func->GetId(), Array<String>(NoInit, decl.Metadata.size())).first;
360 std::uninitialized_move(decl.Metadata.begin(), decl.Metadata.end(), entry->second.data());
361 }
362 } else {
363 std::int32_t typeId = _module->GetTypeIdByDecl(decl.ParentClass.data());
364 asITypeInfo* type = _engine->GetTypeInfoById(typeId);
365 asIScriptFunction* func = type->GetMethodByDecl(decl.Declaration.data());
366 if (func != nullptr) {
367 auto it = _classMetadataMap.find(typeId);
368 if (it == _classMetadataMap.end()) {
369 it = _classMetadataMap.emplace(typeId, ClassMetadata()).first;
370 }
371
372 auto entry = it->second.FuncMetadataMap.emplace(func->GetId(), Array<String>(NoInit, decl.Metadata.size())).first;
373 std::uninitialized_move(decl.Metadata.begin(), decl.Metadata.end(), entry->second.data());
374 }
375 }
376 break;
377 }
378 case MetadataType::VirtualProperty: {
379 if (decl.ParentClass.empty()) {
380 asIScriptFunction* func = _module->GetFunctionByName(String("get_"_s + decl.Declaration).data());
381 if (func != nullptr) {
382 auto entry = _funcMetadataMap.emplace(func->GetId(), Array<String>(NoInit, decl.Metadata.size())).first;
383 std::uninitialized_copy(decl.Metadata.begin(), decl.Metadata.end(), entry->second.data());
384 }
385 func = _module->GetFunctionByName(String("set_"_s + decl.Declaration).data());
386 if (func != nullptr) {
387 auto entry = _funcMetadataMap.emplace(func->GetId(), Array<String>(NoInit, decl.Metadata.size())).first;
388 std::uninitialized_move(decl.Metadata.begin(), decl.Metadata.end(), entry->second.data());
389 }
390 } else {
391 std::int32_t typeId = _module->GetTypeIdByDecl(decl.ParentClass.data());
392 auto it = _classMetadataMap.find(typeId);
393 if (it == _classMetadataMap.end()) {

Callers

nothing calls this directly

Calls 11

ClassMetadataClass · 0.85
StringClass · 0.50
dataMethod · 0.45
emplaceMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
GetIdMethod · 0.45
findMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected