[go: nahoru, domu]

Skip to content

Commit

Permalink
Add a '--no-reference-resolution' command line argument
Browse files Browse the repository at this point in the history
Useful for disabling reference resolution when it's buggy
  • Loading branch information
dimitar-asenov committed Jun 22, 2016
1 parent e173852 commit 1602cf2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ModelBase/src/ModelBasePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ModelBasePlugin.h"

#include "model/AllTreeManagers.h"
#include "nodes/Reference.h"
#include "test_nodes/BinaryNode.h"
#include "test_nodes/PositionExtension.h"

Expand All @@ -49,6 +50,9 @@ bool ModelBasePlugin::initialize(Core::EnvisionManager&)

Core::TypeRegistry::initializeNewTypes();

if (QCoreApplication::arguments().contains("--no-reference-resolution"))
Reference::setReferenceResolutionEnabled(false);

return true;
}

Expand Down
9 changes: 8 additions & 1 deletion ModelBase/src/nodes/Reference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ QList<Reference*> Reference::allReferences_;
QSet<Reference*> Reference::pendingResolution_;
QList<std::function<void (Node* subTree)>> Reference::unresolutionSteps_;

bool Reference::enableGlobalReferenceResolution_{true};

void Reference::setReferenceResolutionEnabled(bool enable)
{
enableGlobalReferenceResolution_ = enable;
}

Reference::Reference(Node *parent) : Super{parent}
{
allReferences_.append(this);
Expand Down Expand Up @@ -95,7 +102,7 @@ bool Reference::resolveHelper(bool indirect)
if (state_ != ReferenceNeedsToBeResolved) return isResolved();
state_ = ReferenceIsBeingResolved;

Node* newTarget = computeTarget();
Node* newTarget = enableGlobalReferenceResolution_ ? computeTarget() : nullptr;

Q_ASSERT(!newTarget || (newTarget->definesSymbol() && newTarget->symbolName() == name_));

Expand Down
7 changes: 7 additions & 0 deletions ModelBase/src/nodes/Reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class MODELBASE_API Reference: public Super<Node>

static void resolvePending();

static void setReferenceResolutionEnabled(bool enable);
static bool isReferenceResolutionEnabled();

private:
Node* target_{};
QString name_;
Expand Down Expand Up @@ -128,6 +131,8 @@ class MODELBASE_API Reference: public Super<Node>
static void forAll(Node* subTree, std::function<void (NodeType* node)> function);

virtual void targetChanged(Node* oldTarget);

static bool enableGlobalReferenceResolution_;
};

inline const QString& Reference::name() const { return name_; }
Expand All @@ -151,4 +156,6 @@ void Reference::forAll(Node* subTree, std::function<void(NodeType* node)> functi
}
}

inline bool Reference::isReferenceResolutionEnabled() { return enableGlobalReferenceResolution_; }

}
4 changes: 3 additions & 1 deletion OOVisualization/src/expressions/VReferenceExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ void VReferenceExpression::determineChildren()
auto nameStyle = &style()->resolvedName();
if (name_->node()->name() == "this") nameStyle = &style()->thisIdentifier();
else if (name_->node()->name() == "class") nameStyle = &style()->classIdentifier();
else if (style()->showUnresolved() && !node()->ref()->isResolved()) nameStyle = &style()->unresolvedName();
else if (style()->showUnresolved() && !node()->ref()->isResolved()
&& Model::Reference::isReferenceResolutionEnabled())
nameStyle = &style()->unresolvedName();
name_->setStyle( nameStyle );
if (prefix_) separator_->setStyle( separatorStyle );
if (typeArguments_)
Expand Down

0 comments on commit 1602cf2

Please sign in to comment.