From 43c9214e33fae9197b8454c9214018b367bd1163 Mon Sep 17 00:00:00 2001 From: codereader Date: Sat, 25 Jun 2022 06:30:11 +0200 Subject: [PATCH] #5977: Change IDeclarationParser to IDeclarationCreator. The declaration instances will work with the DeclarationBlockSyntax. --- include/ideclmanager.h | 27 ++--- plugins/sound/SoundManager.cpp | 3 +- plugins/sound/SoundShader.cpp | 17 ++-- plugins/sound/SoundShader.h | 3 +- plugins/sound/SoundShaderParser.h | 8 +- radiantcore/decl/DeclarationFileParser.cpp | 36 +++---- radiantcore/decl/DeclarationFileParser.h | 10 +- radiantcore/decl/DeclarationFolderParser.cpp | 4 +- radiantcore/decl/DeclarationFolderParser.h | 2 +- radiantcore/decl/DeclarationManager.cpp | 36 +++---- radiantcore/decl/DeclarationManager.h | 6 +- test/DeclManager.cpp | 102 +++++++++---------- 12 files changed, 133 insertions(+), 121 deletions(-) diff --git a/include/ideclmanager.h b/include/ideclmanager.h index a13b77fd29..12f90aa3b6 100644 --- a/include/ideclmanager.h +++ b/include/ideclmanager.h @@ -52,24 +52,27 @@ class IDeclaration // The raw syntax block (without the outer curly braces) used to construct this decl virtual const DeclarationBlockSyntax& getBlockSyntax() const = 0; + + // Parse (or reparse) the declaration contents from the given block syntax + virtual void parseFromBlock(const DeclarationBlockSyntax& block) = 0; }; using NamedDeclarations = std::map; -// Interface of a parser that can handle a single declaration type -class IDeclarationParser +// Factory interface being able to create a single declaration type +class IDeclarationCreator { public: - virtual ~IDeclarationParser() + virtual ~IDeclarationCreator() {} - using Ptr = std::shared_ptr; + using Ptr = std::shared_ptr; - // Returns the declaration type this parser can handle + // Returns the declaration type this creator can handle virtual Type getDeclType() const = 0; - // Create a new declaration instance from the given block - virtual IDeclaration::Ptr parseFromBlock(const DeclarationBlockSyntax& block) = 0; + // Creates an empty declaration with the given name + virtual IDeclaration::Ptr createDeclaration(const std::string& name) = 0; }; // Central service class holding all the declarations in the active game, @@ -83,16 +86,16 @@ class IDeclarationManager : virtual ~IDeclarationManager() override {} - // Registers the declaration typename (e.g. "material") and associates it with the given parser - // It's not allowed to register more than one parser for a single typename - virtual void registerDeclType(const std::string& typeName, const IDeclarationParser::Ptr& parser) = 0; + // Registers the declaration typename (e.g. "material") and associates it with the given creator + // It's not allowed to register more than one creator for a single typename + virtual void registerDeclType(const std::string& typeName, const IDeclarationCreator::Ptr& creator) = 0; - // Unregisters the given typename and the associated parser + // Unregisters the given typename and the associated creator virtual void unregisterDeclType(const std::string& typeName) = 0; // Associates the given VFS folder (with trailing slash) to a certain declaration type // all files matching the given file extension (without dot) will be searched and parsed. - // The folder will not be recursively searched for files, only immediate children will be parsed. + // The folder will not be recursively searched for files, only immediate children will be processed. // Any untyped declaration blocks found in the files will be assumed to be of the given defaultType. // All explicitly typed resources will be processed using the parser that has been previously // associated in registerDeclType() diff --git a/plugins/sound/SoundManager.cpp b/plugins/sound/SoundManager.cpp index e8d6f461f6..dc980d85c9 100644 --- a/plugins/sound/SoundManager.cpp +++ b/plugins/sound/SoundManager.cpp @@ -69,7 +69,8 @@ SoundManager::SoundManager() decl::DeclarationBlockSyntax defaultBlock; defaultBlock.fileInfo = vfs::FileInfo("sounds/", "_autogenerated_by_darkradiant_.sndshd", vfs::Visibility::HIDDEN); - _emptyShader = std::make_unique(defaultBlock); + _emptyShader = std::make_unique(""); + _emptyShader->parseFromBlock(defaultBlock); } void SoundManager::forEachShader(std::function functor) diff --git a/plugins/sound/SoundShader.cpp b/plugins/sound/SoundShader.cpp index a57540f716..d3f3007018 100644 --- a/plugins/sound/SoundShader.cpp +++ b/plugins/sound/SoundShader.cpp @@ -20,11 +20,8 @@ struct SoundShader::ParsedContents std::string displayFolder; }; -SoundShader::SoundShader(const decl::DeclarationBlockSyntax& block) -: _name(block.name), - _declBlock(block), - _fileInfo(block.fileInfo), - _modName(block.getModName()) +SoundShader::SoundShader(const std::string& name) +: _name(name) { } // Destructor must be defined with ParsedContents definition visible, otherwise @@ -34,7 +31,7 @@ SoundShader::~SoundShader() void SoundShader::parseDefinition() const { - _contents.reset(new ParsedContents); + _contents = std::make_unique(); // Get a new tokeniser and parse the block parser::BasicDefTokeniser tok(_declBlock.contents); @@ -105,4 +102,12 @@ const decl::DeclarationBlockSyntax& SoundShader::getBlockSyntax() const return _declBlock; } +void SoundShader::parseFromBlock(const decl::DeclarationBlockSyntax& block) +{ + _declBlock = block; + _fileInfo = block.fileInfo; + _modName = block.getModName(); + _contents.reset(); +} + } // namespace sound diff --git a/plugins/sound/SoundShader.h b/plugins/sound/SoundShader.h index d5e398d5b1..7618a2e9dc 100644 --- a/plugins/sound/SoundShader.h +++ b/plugins/sound/SoundShader.h @@ -34,7 +34,7 @@ class SoundShader final : public: using Ptr = std::shared_ptr; - SoundShader(const decl::DeclarationBlockSyntax& block); + SoundShader(const std::string& name); ~SoundShader(); @@ -49,6 +49,7 @@ class SoundShader final : std::string getDefinition() const override; const decl::DeclarationBlockSyntax& getBlockSyntax() const override; + void parseFromBlock(const decl::DeclarationBlockSyntax& block) override; }; } diff --git a/plugins/sound/SoundShaderParser.h b/plugins/sound/SoundShaderParser.h index 420a032098..e33b6f35d2 100644 --- a/plugins/sound/SoundShaderParser.h +++ b/plugins/sound/SoundShaderParser.h @@ -7,10 +7,10 @@ namespace sound { /** - * Declaration parser capable of dealing with sound shader blocks + * Declaration creator capable of dealing with sound shader blocks */ class SoundShaderParser final : - public decl::IDeclarationParser + public decl::IDeclarationCreator { public: decl::Type getDeclType() const override @@ -18,9 +18,9 @@ class SoundShaderParser final : return decl::Type::SoundShader; } - decl::IDeclaration::Ptr parseFromBlock(const decl::DeclarationBlockSyntax& block) override + decl::IDeclaration::Ptr createDeclaration(const std::string& name) override { - return std::make_shared(block); + return std::make_shared(name); } }; diff --git a/radiantcore/decl/DeclarationFileParser.cpp b/radiantcore/decl/DeclarationFileParser.cpp index 4d46141f34..ce13ad13a9 100644 --- a/radiantcore/decl/DeclarationFileParser.cpp +++ b/radiantcore/decl/DeclarationFileParser.cpp @@ -26,15 +26,15 @@ namespace } DeclarationFileParser::DeclarationFileParser(Type declType, - const std::map& parsersByTypename) : + const std::map& creatorsByTypename) : _defaultDeclType(declType), - _parsersByTypename(parsersByTypename) + _creatorsByTypename(creatorsByTypename) { - _defaultTypeParser = getParserByType(declType); + _defaultTypeCreator = getCreatorByType(declType); - if (!_defaultTypeParser) + if (!_defaultTypeCreator) { - throw std::invalid_argument("No parser has been associated to the default type " + getTypeName(declType)); + throw std::invalid_argument("No creator has been associated to the default type " + getTypeName(declType)); } } @@ -71,17 +71,17 @@ void DeclarationFileParser::parse(std::istream& stream, const vfs::FileInfo& fil if (spacePos == std::string::npos) { - // No type specified, use the default type parser - parseBlock(*_defaultTypeParser, blockSyntax); + // No type specified, use the default type creator + processBlock(*_defaultTypeCreator, blockSyntax); continue; } - // Locate a parser capable of handling that block - auto parser = _parsersByTypename.find(block.name.substr(0, spacePos)); + // Locate a creator capable of handling that block + auto creator = _creatorsByTypename.find(block.name.substr(0, spacePos)); - if (parser != _parsersByTypename.end()) + if (creator != _creatorsByTypename.end()) { - parseBlock(*parser->second, blockSyntax); + processBlock(*creator->second, blockSyntax); continue; } @@ -90,20 +90,22 @@ void DeclarationFileParser::parse(std::istream& stream, const vfs::FileInfo& fil } } -void DeclarationFileParser::parseBlock(IDeclarationParser& parser, const DeclarationBlockSyntax& block) +void DeclarationFileParser::processBlock(IDeclarationCreator& creator, const DeclarationBlockSyntax& block) { - auto declaration = parser.parseFromBlock(block); + auto declaration = creator.createDeclaration(block.name); - auto& declMap = _parsedDecls.try_emplace(parser.getDeclType(), NamedDeclarations()).first->second; + declaration->parseFromBlock(block); + + auto& declMap = _parsedDecls.try_emplace(creator.getDeclType(), NamedDeclarations()).first->second; // Insert into map, emit a warning on duplicates DeclarationManager::InsertDeclaration(declMap, std::move(declaration)); } -IDeclarationParser::Ptr DeclarationFileParser::getParserByType(Type declType) const +IDeclarationCreator::Ptr DeclarationFileParser::getCreatorByType(Type declType) const { - // Get the default type parser - for (const auto& pair : _parsersByTypename) + // Get the default type creator + for (const auto& pair : _creatorsByTypename) { if (pair.second->getDeclType() == declType) { diff --git a/radiantcore/decl/DeclarationFileParser.h b/radiantcore/decl/DeclarationFileParser.h index 02ef3d60e3..dffb17b6bb 100644 --- a/radiantcore/decl/DeclarationFileParser.h +++ b/radiantcore/decl/DeclarationFileParser.h @@ -13,8 +13,8 @@ class DeclarationFileParser private: Type _defaultDeclType; - std::map _parsersByTypename; - IDeclarationParser::Ptr _defaultTypeParser; + std::map _creatorsByTypename; + IDeclarationCreator::Ptr _defaultTypeCreator; std::set _parsedFiles; std::map _parsedDecls; @@ -22,7 +22,7 @@ class DeclarationFileParser std::vector _unrecognisedBlocks; public: - DeclarationFileParser(Type declType, const std::map& parsersByTypename); + DeclarationFileParser(Type declType, const std::map& creatorsByTypename); void parse(std::istream& stream, const vfs::FileInfo& fileInfo, const std::string& modDir); @@ -31,8 +31,8 @@ class DeclarationFileParser const std::vector& getUnrecognisedBlocks() const; private: - void parseBlock(IDeclarationParser& parser, const DeclarationBlockSyntax& block); - IDeclarationParser::Ptr getParserByType(Type declType) const; + void processBlock(IDeclarationCreator& creator, const DeclarationBlockSyntax& block); + IDeclarationCreator::Ptr getCreatorByType(Type declType) const; }; } diff --git a/radiantcore/decl/DeclarationFolderParser.cpp b/radiantcore/decl/DeclarationFolderParser.cpp index b76c697ca9..6cfe7d9359 100644 --- a/radiantcore/decl/DeclarationFolderParser.cpp +++ b/radiantcore/decl/DeclarationFolderParser.cpp @@ -7,10 +7,10 @@ namespace decl DeclarationFolderParser::DeclarationFolderParser(DeclarationManager& owner, Type declType, const std::string& baseDir, const std::string& extension, - const std::map& parsersByTypename) : + const std::map& creatorsByTypename) : ThreadedDeclParser(declType, baseDir, extension, 1), _owner(owner), - _fileParser(declType, parsersByTypename), + _fileParser(declType, creatorsByTypename), _defaultDeclType(declType) {} diff --git a/radiantcore/decl/DeclarationFolderParser.h b/radiantcore/decl/DeclarationFolderParser.h index 9efeae3013..a36518c041 100644 --- a/radiantcore/decl/DeclarationFolderParser.h +++ b/radiantcore/decl/DeclarationFolderParser.h @@ -25,7 +25,7 @@ class DeclarationFolderParser : public: DeclarationFolderParser(DeclarationManager& owner, Type declType, const std::string& baseDir, const std::string& extension, - const std::map& parsersByTypename); + const std::map& creatorsByTypename); protected: void parse(std::istream& stream, const vfs::FileInfo& fileInfo, const std::string& modDir) override; diff --git a/radiantcore/decl/DeclarationManager.cpp b/radiantcore/decl/DeclarationManager.cpp index 807e80202e..954931fb96 100644 --- a/radiantcore/decl/DeclarationManager.cpp +++ b/radiantcore/decl/DeclarationManager.cpp @@ -10,16 +10,16 @@ namespace decl { -void DeclarationManager::registerDeclType(const std::string& typeName, const IDeclarationParser::Ptr& parser) +void DeclarationManager::registerDeclType(const std::string& typeName, const IDeclarationCreator::Ptr& parser) { - std::lock_guard parserLock(_parserLock); + std::lock_guard parserLock(_creatorLock); - if (_parsersByTypename.count(typeName) > 0) + if (_creatorsByTypename.count(typeName) > 0) { throw std::logic_error("Type name " + typeName + " has already been registered"); } - _parsersByTypename.emplace(typeName, parser); + _creatorsByTypename.emplace(typeName, parser); // A new parser might be able to parse some of the unrecognised blocks handleUnrecognisedBlocks(); @@ -27,16 +27,16 @@ void DeclarationManager::registerDeclType(const std::string& typeName, const IDe void DeclarationManager::unregisterDeclType(const std::string& typeName) { - std::lock_guard parserLock(_parserLock); + std::lock_guard parserLock(_creatorLock); - auto existing = _parsersByTypename.find(typeName); + auto existing = _creatorsByTypename.find(typeName); - if (existing == _parsersByTypename.end()) + if (existing == _creatorsByTypename.end()) { throw std::logic_error("Type name " + typeName + " has not been registered"); } - _parsersByTypename.erase(existing); + _creatorsByTypename.erase(existing); } void DeclarationManager::registerDeclFolder(Type defaultType, const std::string& inputFolder, const std::string& inputExtension) @@ -51,7 +51,7 @@ void DeclarationManager::registerDeclFolder(Type defaultType, const std::string& auto& decls = _declarationsByType.try_emplace(defaultType, Declarations()).first->second; // Start the parser thread - decls.parser = std::make_unique(*this, defaultType, vfsPath, extension, _parsersByTypename); + decls.parser = std::make_unique(*this, defaultType, vfsPath, extension, _creatorsByTypename); decls.parser->start(); } @@ -110,11 +110,11 @@ void DeclarationManager::doWithDeclarations(Type type, const std::function fileLock(_parsedFileLock); - std::lock_guard parserLock(_parserLock); + std::lock_guard parserLock(_creatorLock); for (const auto& [type, files] : _parsedFilesByDefaultType) { - DeclarationFileParser parser(type, _parsersByTypename); + DeclarationFileParser parser(type, _creatorsByTypename); for (const auto& file : files) { @@ -185,19 +185,19 @@ void DeclarationManager::handleUnrecognisedBlocks() std::lock_guard lock(_unrecognisedBlockLock); // Check each of the unrecognised blocks - for (auto b = _unrecognisedBlocks.begin(); b != _unrecognisedBlocks.end();) + for (auto block = _unrecognisedBlocks.begin(); block != _unrecognisedBlocks.end();) { - auto parser = _parsersByTypename.find(b->typeName); + auto parser = _creatorsByTypename.find(block->typeName); - if (parser == _parsersByTypename.end()) + if (parser == _creatorsByTypename.end()) { - ++b; + ++block; continue; // still not recognised } // We found a parser, handle it now - auto declaration = parser->second->parseFromBlock(*b); - _unrecognisedBlocks.erase(b++); + auto declaration = parser->second->createDeclaration(block->name); + _unrecognisedBlocks.erase(block++); // Insert into our main library std::lock_guard declLock(_declarationLock); @@ -263,7 +263,7 @@ void DeclarationManager::shutdownModule() _parsedFilesByDefaultType.clear(); _unrecognisedBlocks.clear(); _declarationsByType.clear(); - _parsersByTypename.clear(); + _creatorsByTypename.clear(); _declsReloadedSignals.clear(); } diff --git a/radiantcore/decl/DeclarationManager.h b/radiantcore/decl/DeclarationManager.h index 481e9159a0..ee35d60932 100644 --- a/radiantcore/decl/DeclarationManager.h +++ b/radiantcore/decl/DeclarationManager.h @@ -17,8 +17,8 @@ class DeclarationManager : public IDeclarationManager { private: - std::map _parsersByTypename; - std::mutex _parserLock; + std::map _creatorsByTypename; + std::mutex _creatorLock; struct RegisteredFolder { @@ -51,7 +51,7 @@ class DeclarationManager : std::map> _declsReloadedSignals; public: - void registerDeclType(const std::string& typeName, const IDeclarationParser::Ptr& parser) override; + void registerDeclType(const std::string& typeName, const IDeclarationCreator::Ptr& parser) override; void unregisterDeclType(const std::string& typeName) override; void registerDeclFolder(Type defaultType, const std::string& inputFolder, const std::string& inputExtension) override; IDeclaration::Ptr findDeclaration(Type type, const std::string& name) override; diff --git a/test/DeclManager.cpp b/test/DeclManager.cpp index 997b31b45c..3b30ee8433 100644 --- a/test/DeclManager.cpp +++ b/test/DeclManager.cpp @@ -17,10 +17,9 @@ class TestDeclaration : decl::DeclarationBlockSyntax _block; public: - TestDeclaration(decl::Type type, const decl::DeclarationBlockSyntax& block) : + TestDeclaration(decl::Type type, const std::string& name) : _type(type), - _block(block), - _name(block.name) + _name(name) {} const std::string& getDeclName() const override @@ -37,22 +36,25 @@ class TestDeclaration : { return _block; } + + void parseFromBlock(const decl::DeclarationBlockSyntax& block) override + { + _block = block; + } }; -class TestDeclarationParser : - public decl::IDeclarationParser +class TestDeclarationCreator : + public decl::IDeclarationCreator { public: bool processingDisabled = false; - // Returns the declaration type this parser can handle decl::Type getDeclType() const override { return decl::Type::Material; } - // Create a new declaration instance from the given block - decl::IDeclaration::Ptr parseFromBlock(const decl::DeclarationBlockSyntax& block) override + decl::IDeclaration::Ptr createDeclaration(const std::string& name) override { while (processingDisabled) { @@ -60,46 +62,44 @@ class TestDeclarationParser : std::this_thread::sleep_for(20ms); } - return std::make_shared(getDeclType(), block); + return std::make_shared(getDeclType(), name); } }; -class TestDeclaration2Parser : - public decl::IDeclarationParser +class TestDeclaration2Creator : + public decl::IDeclarationCreator { public: - // Returns the declaration type this parser can handle decl::Type getDeclType() const override { return decl::Type::Model; } - // Create a new declaration instance from the given block - decl::IDeclaration::Ptr parseFromBlock(const decl::DeclarationBlockSyntax& block) override + decl::IDeclaration::Ptr createDeclaration(const std::string& name) override { - return std::make_shared(getDeclType(), block); + return std::make_shared(getDeclType(), name); } }; TEST_F(DeclManagerTest, DeclTypeRegistration) { - auto parser = std::make_shared(); - EXPECT_NO_THROW(GlobalDeclarationManager().registerDeclType("testdecl", parser)); + auto creator = std::make_shared(); + EXPECT_NO_THROW(GlobalDeclarationManager().registerDeclType("testdecl", creator)); // Registering the same type name twice should result in an exception - EXPECT_THROW(GlobalDeclarationManager().registerDeclType("testdecl", parser), std::logic_error); + EXPECT_THROW(GlobalDeclarationManager().registerDeclType("testdecl", creator), std::logic_error); - // Passing a new parser instance doesn't help either - auto parser2 = std::make_shared(); - EXPECT_THROW(GlobalDeclarationManager().registerDeclType("testdecl", parser2), std::logic_error); + // Passing a new creator instance doesn't help either + auto creator2 = std::make_shared(); + EXPECT_THROW(GlobalDeclarationManager().registerDeclType("testdecl", creator2), std::logic_error); } TEST_F(DeclManagerTest, DeclTypeUnregistration) { - auto parser = std::make_shared(); - GlobalDeclarationManager().registerDeclType("testdecl", parser); + auto creator = std::make_shared(); + GlobalDeclarationManager().registerDeclType("testdecl", creator); - // Unregistering the parser should succeed + // Unregistering the creator should succeed EXPECT_NO_THROW(GlobalDeclarationManager().unregisterDeclType("testdecl")); // Trying to unregister it twice should result in an exception @@ -153,7 +153,7 @@ inline void checkKnownTestDecl2Names() TEST_F(DeclManagerTest, DeclFolderRegistration) { - GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); + GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); GlobalDeclarationManager().registerDeclFolder(decl::Type::Material, "testdecls/", "decl"); @@ -162,7 +162,7 @@ TEST_F(DeclManagerTest, DeclFolderRegistration) TEST_F(DeclManagerTest, DeclFolderRegistrationWithoutSlash) { - GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); + GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); // Omit the trailing slash, should work just fine GlobalDeclarationManager().registerDeclFolder(decl::Type::Material, "testdecls", "decl"); @@ -172,7 +172,7 @@ TEST_F(DeclManagerTest, DeclFolderRegistrationWithoutSlash) TEST_F(DeclManagerTest, DeclFolderRegistrationWithExtensionDot) { - GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); + GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); // Add the dot to the file extension, should work just fine GlobalDeclarationManager().registerDeclFolder(decl::Type::Material, "testdecls", ".decl"); @@ -180,11 +180,11 @@ TEST_F(DeclManagerTest, DeclFolderRegistrationWithExtensionDot) checkKnownTestDeclNames(); } -// Test a second decl parser -TEST_F(DeclManagerTest, DeclTypeParserRegistration) +// Test a second decl creator +TEST_F(DeclManagerTest, DeclTypeCreatorRegistration) { - GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); - GlobalDeclarationManager().registerDeclType("testdecl2", std::make_shared()); + GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); + GlobalDeclarationManager().registerDeclType("testdecl2", std::make_shared()); // Parse this folder, it contains decls of type testdecl and testdecl2 in the .decl files GlobalDeclarationManager().registerDeclFolder(decl::Type::Material, "testdecls", ".decl"); @@ -193,17 +193,17 @@ TEST_F(DeclManagerTest, DeclTypeParserRegistration) checkKnownTestDecl2Names(); } -// Test that a parser coming late to the party is immediately fed with the buffered decl blocks -TEST_F(DeclManagerTest, LateParserRegistration) +// Test that a creator coming late to the party is immediately fed with the buffered decl blocks +TEST_F(DeclManagerTest, LateCreatorRegistration) { - auto parser = std::make_shared(); + auto creator = std::make_shared(); - GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); + GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); // Parse this folder, it contains decls of type testdecl and testdecl2 in the .decl files GlobalDeclarationManager().registerDeclFolder(decl::Type::Material, "testdecls", ".decl"); - // Let the testdecl parser finish its work + // Let the testdecl creator finish its work getAllDeclNames(decl::Type::Material); auto foundTestDecl2Names = getAllDeclNames(decl::Type::Model); @@ -211,21 +211,21 @@ TEST_F(DeclManagerTest, LateParserRegistration) EXPECT_FALSE(foundTestDecl2Names.count("decltable2") > 0); EXPECT_FALSE(foundTestDecl2Names.count("decltable3") > 0); - // Register the testdecl2 parser now, it should be used by the decl manager to parse the missing pieces - GlobalDeclarationManager().registerDeclType("testdecl2", std::make_shared()); + // Register the testdecl2 creator now, it should be used by the decl manager to parse the missing pieces + GlobalDeclarationManager().registerDeclType("testdecl2", std::make_shared()); // Everything should be registered now checkKnownTestDecl2Names(); } -TEST_F(DeclManagerTest, ParserRegistrationDuringRunningThread) +TEST_F(DeclManagerTest, CreatorRegistrationDuringRunningThread) { - auto parser = std::make_shared(); + auto creator = std::make_shared(); - // Hold back this parser until we let it go in this fixture - parser->processingDisabled = true; + // Hold back this creator until we let it go in this fixture + creator->processingDisabled = true; - GlobalDeclarationManager().registerDeclType("testdecl", parser); + GlobalDeclarationManager().registerDeclType("testdecl", creator); // Parse this folder, it contains decls of type testdecl and testdecl2 in the .decl files GlobalDeclarationManager().registerDeclFolder(decl::Type::Material, "testdecls", ".decl"); @@ -233,15 +233,15 @@ TEST_F(DeclManagerTest, ParserRegistrationDuringRunningThread) auto foundTestDecl2Names = getAllDeclNames(decl::Type::Model); EXPECT_FALSE(foundTestDecl2Names.count("decltable1") > 0); - // Register the testdecl2 parser now, it should be used by the decl manager to parse the missing pieces - GlobalDeclarationManager().registerDeclType("testdecl2", std::make_shared()); + // Register the testdecl2 creator now, it should be used by the decl manager to parse the missing pieces + GlobalDeclarationManager().registerDeclType("testdecl2", std::make_shared()); // The first thread is still running, so we didn't get any unrecognised decls reported foundTestDecl2Names = getAllDeclNames(decl::Type::Model); EXPECT_FALSE(foundTestDecl2Names.count("decltable1") > 0); - // Let the testdecl parser finish its work - parser->processingDisabled = false; + // Let the testdecl creator finish its work + creator->processingDisabled = false; getAllDeclNames(decl::Type::Material); // Everything should be registered now @@ -250,8 +250,8 @@ TEST_F(DeclManagerTest, ParserRegistrationDuringRunningThread) TEST_F(DeclManagerTest, DeclsReloadedSignal) { - auto parser = std::make_shared(); - GlobalDeclarationManager().registerDeclType("testdecl", parser); + auto creator = std::make_shared(); + GlobalDeclarationManager().registerDeclType("testdecl", creator); bool materialSignalFired = false; bool modelSignalFired = false; @@ -274,7 +274,7 @@ TEST_F(DeclManagerTest, DeclsReloadedSignal) TEST_F(DeclManagerTest, FindDeclaration) { - GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); + GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); GlobalDeclarationManager().registerDeclFolder(decl::Type::Material, "testdecls", ".decl"); EXPECT_TRUE(GlobalDeclarationManager().findDeclaration(decl::Type::Material, "decl/exporttest/guisurf1")); @@ -298,7 +298,7 @@ decl/temporary/12 )"); - GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); + GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); GlobalDeclarationManager().registerDeclFolder(decl::Type::Material, "testdecls", ".decl"); auto temp12 = GlobalDeclarationManager().findDeclaration(decl::Type::Material, "decl/temporary/12");