mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Merge pull request #4968 from lioncash/const-parser
ExpressionParser: Const-correctness changes
This commit is contained in:
commit
a62711de55
@ -58,7 +58,7 @@ public:
|
|||||||
|
|
||||||
Token(TokenType type_) : type(type_) {}
|
Token(TokenType type_) : type(type_) {}
|
||||||
Token(TokenType type_, ControlQualifier qualifier_) : type(type_), qualifier(qualifier_) {}
|
Token(TokenType type_, ControlQualifier qualifier_) : type(type_), qualifier(qualifier_) {}
|
||||||
operator std::string()
|
operator std::string() const
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@ -211,10 +211,10 @@ class ExpressionNode
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~ExpressionNode() {}
|
virtual ~ExpressionNode() {}
|
||||||
virtual ControlState GetValue() { return 0; }
|
virtual ControlState GetValue() const { return 0; }
|
||||||
virtual void SetValue(ControlState state) {}
|
virtual void SetValue(ControlState state) {}
|
||||||
virtual int CountNumControls() { return 0; }
|
virtual int CountNumControls() const { return 0; }
|
||||||
virtual operator std::string() { return ""; }
|
virtual operator std::string() const { return ""; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class DummyExpression : public ExpressionNode
|
class DummyExpression : public ExpressionNode
|
||||||
@ -223,10 +223,10 @@ public:
|
|||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
DummyExpression(const std::string& name_) : name(name_) {}
|
DummyExpression(const std::string& name_) : name(name_) {}
|
||||||
ControlState GetValue() override { return 0.0; }
|
ControlState GetValue() const override { return 0.0; }
|
||||||
void SetValue(ControlState value) override {}
|
void SetValue(ControlState value) override {}
|
||||||
int CountNumControls() override { return 0; }
|
int CountNumControls() const override { return 0; }
|
||||||
operator std::string() override { return "`" + name + "`"; }
|
operator std::string() const override { return "`" + name + "`"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class ControlExpression : public ExpressionNode
|
class ControlExpression : public ExpressionNode
|
||||||
@ -241,10 +241,10 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlState GetValue() override { return control->ToInput()->GetState(); }
|
ControlState GetValue() const override { return control->ToInput()->GetState(); }
|
||||||
void SetValue(ControlState value) override { control->ToOutput()->SetState(value); }
|
void SetValue(ControlState value) override { control->ToOutput()->SetState(value); }
|
||||||
int CountNumControls() override { return 1; }
|
int CountNumControls() const override { return 1; }
|
||||||
operator std::string() override { return "`" + (std::string)qualifier + "`"; }
|
operator std::string() const override { return "`" + (std::string)qualifier + "`"; }
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Device> m_device;
|
std::shared_ptr<Device> m_device;
|
||||||
};
|
};
|
||||||
@ -266,7 +266,7 @@ public:
|
|||||||
delete rhs;
|
delete rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlState GetValue() override
|
ControlState GetValue() const override
|
||||||
{
|
{
|
||||||
ControlState lhsValue = lhs->GetValue();
|
ControlState lhsValue = lhs->GetValue();
|
||||||
ControlState rhsValue = rhs->GetValue();
|
ControlState rhsValue = rhs->GetValue();
|
||||||
@ -292,8 +292,12 @@ public:
|
|||||||
rhs->SetValue(value);
|
rhs->SetValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CountNumControls() override { return lhs->CountNumControls() + rhs->CountNumControls(); }
|
int CountNumControls() const override
|
||||||
operator std::string() override
|
{
|
||||||
|
return lhs->CountNumControls() + rhs->CountNumControls();
|
||||||
|
}
|
||||||
|
|
||||||
|
operator std::string() const override
|
||||||
{
|
{
|
||||||
return OpName(op) + "(" + (std::string)(*lhs) + ", " + (std::string)(*rhs) + ")";
|
return OpName(op) + "(" + (std::string)(*lhs) + ", " + (std::string)(*rhs) + ")";
|
||||||
}
|
}
|
||||||
@ -307,7 +311,7 @@ public:
|
|||||||
|
|
||||||
UnaryExpression(TokenType op_, ExpressionNode* inner_) : op(op_), inner(inner_) {}
|
UnaryExpression(TokenType op_, ExpressionNode* inner_) : op(op_), inner(inner_) {}
|
||||||
virtual ~UnaryExpression() { delete inner; }
|
virtual ~UnaryExpression() { delete inner; }
|
||||||
ControlState GetValue() override
|
ControlState GetValue() const override
|
||||||
{
|
{
|
||||||
ControlState value = inner->GetValue();
|
ControlState value = inner->GetValue();
|
||||||
switch (op)
|
switch (op)
|
||||||
@ -333,11 +337,11 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CountNumControls() override { return inner->CountNumControls(); }
|
int CountNumControls() const override { return inner->CountNumControls(); }
|
||||||
operator std::string() override { return OpName(op) + "(" + (std::string)(*inner) + ")"; }
|
operator std::string() const override { return OpName(op) + "(" + (std::string)(*inner) + ")"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<Device> ControlFinder::FindDevice(ControlQualifier qualifier)
|
std::shared_ptr<Device> ControlFinder::FindDevice(ControlQualifier qualifier) const
|
||||||
{
|
{
|
||||||
if (qualifier.has_device)
|
if (qualifier.has_device)
|
||||||
return container.FindDevice(qualifier.device_qualifier);
|
return container.FindDevice(qualifier.device_qualifier);
|
||||||
@ -345,7 +349,7 @@ std::shared_ptr<Device> ControlFinder::FindDevice(ControlQualifier qualifier)
|
|||||||
return container.FindDevice(default_device);
|
return container.FindDevice(default_device);
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::Control* ControlFinder::FindControl(ControlQualifier qualifier)
|
Device::Control* ControlFinder::FindControl(ControlQualifier qualifier) const
|
||||||
{
|
{
|
||||||
const std::shared_ptr<Device> device = FindDevice(qualifier);
|
const std::shared_ptr<Device> device = FindDevice(qualifier);
|
||||||
if (!device)
|
if (!device)
|
||||||
@ -497,7 +501,7 @@ private:
|
|||||||
ExpressionParseStatus Toplevel(ExpressionNode** expr_out) { return Binary(expr_out); }
|
ExpressionParseStatus Toplevel(ExpressionNode** expr_out) { return Binary(expr_out); }
|
||||||
};
|
};
|
||||||
|
|
||||||
ControlState Expression::GetValue()
|
ControlState Expression::GetValue() const
|
||||||
{
|
{
|
||||||
return node->GetValue();
|
return node->GetValue();
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
std::string control_name;
|
std::string control_name;
|
||||||
|
|
||||||
ControlQualifier() : has_device(false) {}
|
ControlQualifier() : has_device(false) {}
|
||||||
operator std::string()
|
operator std::string() const
|
||||||
{
|
{
|
||||||
if (has_device)
|
if (has_device)
|
||||||
return device_qualifier.ToString() + ":" + control_name;
|
return device_qualifier.ToString() + ":" + control_name;
|
||||||
@ -37,8 +37,8 @@ public:
|
|||||||
: container(container_), default_device(default_), is_input(is_input_)
|
: container(container_), default_device(default_), is_input(is_input_)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
std::shared_ptr<Core::Device> FindDevice(ControlQualifier qualifier);
|
std::shared_ptr<Core::Device> FindDevice(ControlQualifier qualifier) const;
|
||||||
Core::Device::Control* FindControl(ControlQualifier qualifier);
|
Core::Device::Control* FindControl(ControlQualifier qualifier) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Core::DeviceContainer& container;
|
const Core::DeviceContainer& container;
|
||||||
@ -53,7 +53,7 @@ public:
|
|||||||
Expression() : node(nullptr) {}
|
Expression() : node(nullptr) {}
|
||||||
Expression(ExpressionNode* node);
|
Expression(ExpressionNode* node);
|
||||||
~Expression();
|
~Expression();
|
||||||
ControlState GetValue();
|
ControlState GetValue() const;
|
||||||
void SetValue(ControlState state);
|
void SetValue(ControlState state);
|
||||||
int num_controls;
|
int num_controls;
|
||||||
ExpressionNode* node;
|
ExpressionNode* node;
|
||||||
|
Loading…
Reference in New Issue
Block a user