Skip to content

Commit

Permalink
#6189: Clear the syntax block invalidated flag when a new block has b…
Browse files Browse the repository at this point in the history
…een assigned.

Also ensure the base methods are invoked in all overrides.
  • Loading branch information
codereader committed Dec 30, 2022
1 parent 57a3085 commit e6304ab
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
10 changes: 10 additions & 0 deletions libs/decl/EditableDeclaration.h
Expand Up @@ -62,6 +62,16 @@ class EditableDeclaration :
}

protected:
void onSyntaxBlockAssigned(const DeclarationBlockSyntax& block) override
{
// Assigning a new syntax block overrides any previous edits to the decl
// Otherwise the block contents would immediately get overwritten again
// in getBlockSyntax() by invoking generateSyntax()
_syntaxBlockInvalidated = false;

DeclarationBase<DeclarationInterface>::onSyntaxBlockAssigned(block);
}

// Needs to be called by subclasses when members change and the
// syntax block (that has been used to parse them) is no longer valid
// The next time client code will acquire the syntax block, the subclass
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/eclass/EntityClass.cpp
Expand Up @@ -61,6 +61,8 @@ sigc::signal<void>& EntityClass::changedSignal()

void EntityClass::onSyntaxBlockAssigned(const decl::DeclarationBlockSyntax& block)
{
DeclarationBase<IEntityClass>::onSyntaxBlockAssigned(block);

clear();
emitChangedSignal();
}
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/particles/ParticleDef.cpp
Expand Up @@ -159,6 +159,8 @@ void ParticleDef::parseFromTokens(parser::DefTokeniser& tokeniser)

void ParticleDef::onSyntaxBlockAssigned(const decl::DeclarationBlockSyntax& block)
{
EditableDeclaration<IParticleDef>::onSyntaxBlockAssigned(block);

_changedSignal.emit();
}

Expand Down
2 changes: 2 additions & 0 deletions radiantcore/shaders/ShaderTemplate.cpp
Expand Up @@ -1534,6 +1534,8 @@ std::string ShaderTemplate::generateSyntax()

void ShaderTemplate::onSyntaxBlockAssigned(const decl::DeclarationBlockSyntax& block)
{
EditableDeclaration<IShaderTemplate>::onSyntaxBlockAssigned(block);

// Don't call onTemplateChanged() since that is meant is to be used
// when the template is modified after parsing
// Just emit the template changed signal
Expand Down
11 changes: 8 additions & 3 deletions test/DeclManager.cpp
Expand Up @@ -113,6 +113,8 @@ class TestDeclaration :

void parseFromTokens(parser::DefTokeniser& tokeniser) override
{
_keyValues.clear();

while (tokeniser.hasMoreTokens())
{
// Read key/value pairs until end of decl
Expand Down Expand Up @@ -1736,16 +1738,19 @@ TEST_F(DeclManagerTest, AssigningSyntaxBlockOverridesModification)
auto decl = std::static_pointer_cast<TestDeclaration>(
GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/numbers/3"));

// Retrieve a valid syntax block
auto syntax = decl->getBlockSyntax();

// This will internally mark the declaration as "modified after parsing"
decl->setKeyValue("description", "This decl is missing and has been modified");
decl->setFileInfo(vfs::FileInfo(TEST_DECL_FOLDER, "_autogenerated.decl", vfs::Visibility::NORMAL));

auto newSyntax = decl->getBlockSyntax();
newSyntax.contents = R"(
syntax.contents = R"(
"description" "assigned"
)";

// Assigning a new syntax block after parsing should work even if the decl has been modified
decl->setBlockSyntax(newSyntax);
decl->setBlockSyntax(syntax);

EXPECT_EQ(decl->getKeyValue("description"), "assigned") << "Assigned syntax block didn't take effect";
}
Expand Down

0 comments on commit e6304ab

Please sign in to comment.