Merge branch 'expression-parser-barewords'
This commit is contained in:
commit
c78a1ecdcb
|
@ -181,14 +181,14 @@ void GCPad::LoadDefaults(const ControllerInterface& ciface)
|
|||
set_control(m_main_stick, 4, "LSHIFT"); // Modifier
|
||||
|
||||
#elif __APPLE__
|
||||
set_control(m_c_stick, 4, "`Left Control`"); // Modifier
|
||||
set_control(m_c_stick, 4, "Left Control"); // Modifier
|
||||
|
||||
// Main Stick
|
||||
set_control(m_main_stick, 0, "`Up Arrow"); // Up
|
||||
set_control(m_main_stick, 1, "`Down Arrow`"); // Down
|
||||
set_control(m_main_stick, 2, "`Left Arrow`"); // Left
|
||||
set_control(m_main_stick, 3, "`Right Arrow`"); // Right
|
||||
set_control(m_main_stick, 4, "`Left Shift`"); // Modifier
|
||||
set_control(m_main_stick, 0, "Up Arrow"); // Up
|
||||
set_control(m_main_stick, 1, "Down Arrow"); // Down
|
||||
set_control(m_main_stick, 2, "Left Arrow"); // Left
|
||||
set_control(m_main_stick, 3, "Right Arrow"); // Right
|
||||
set_control(m_main_stick, 4, "Left Shift"); // Modifier
|
||||
#else
|
||||
// not sure if these are right
|
||||
|
||||
|
|
|
@ -897,11 +897,11 @@ void Wiimote::LoadDefaults(const ControllerInterface& ciface)
|
|||
|
||||
// Buttons
|
||||
#if defined HAVE_X11 && HAVE_X11
|
||||
set_control(m_buttons, 0, "`Click 1`"); // A
|
||||
set_control(m_buttons, 1, "`Click 3`"); // B
|
||||
set_control(m_buttons, 0, "Click 1"); // A
|
||||
set_control(m_buttons, 1, "Click 3"); // B
|
||||
#else
|
||||
set_control(m_buttons, 0, "`Click 0`"); // A
|
||||
set_control(m_buttons, 1, "`Click 1`"); // B
|
||||
set_control(m_buttons, 0, "Click 0"); // A
|
||||
set_control(m_buttons, 1, "Click 1"); // B
|
||||
#endif
|
||||
set_control(m_buttons, 2, "1"); // 1
|
||||
set_control(m_buttons, 3, "2"); // 2
|
||||
|
@ -916,13 +916,13 @@ void Wiimote::LoadDefaults(const ControllerInterface& ciface)
|
|||
|
||||
// Shake
|
||||
for (size_t i = 0; i != 3; ++i)
|
||||
set_control(m_shake, i, "`Click 2`");
|
||||
set_control(m_shake, i, "Click 2");
|
||||
|
||||
// IR
|
||||
set_control(m_ir, 0, "`Cursor Y-`");
|
||||
set_control(m_ir, 1, "`Cursor Y+`");
|
||||
set_control(m_ir, 2, "`Cursor X-`");
|
||||
set_control(m_ir, 3, "`Cursor X+`");
|
||||
set_control(m_ir, 0, "Cursor Y-");
|
||||
set_control(m_ir, 1, "Cursor Y+");
|
||||
set_control(m_ir, 2, "Cursor X-");
|
||||
set_control(m_ir, 3, "Cursor X+");
|
||||
|
||||
// DPad
|
||||
#ifdef _WIN32
|
||||
|
@ -931,10 +931,10 @@ void Wiimote::LoadDefaults(const ControllerInterface& ciface)
|
|||
set_control(m_dpad, 2, "LEFT"); // Left
|
||||
set_control(m_dpad, 3, "RIGHT"); // Right
|
||||
#elif __APPLE__
|
||||
set_control(m_dpad, 0, "`Up Arrow`"); // Up
|
||||
set_control(m_dpad, 1, "`Down Arrow`"); // Down
|
||||
set_control(m_dpad, 2, "`Left Arrow`"); // Left
|
||||
set_control(m_dpad, 3, "`Right Arrow`"); // Right
|
||||
set_control(m_dpad, 0, "Up Arrow"); // Up
|
||||
set_control(m_dpad, 1, "Down Arrow"); // Down
|
||||
set_control(m_dpad, 2, "Left Arrow"); // Left
|
||||
set_control(m_dpad, 3, "Right Arrow"); // Right
|
||||
#else
|
||||
set_control(m_dpad, 0, "Up"); // Up
|
||||
set_control(m_dpad, 1, "Down"); // Down
|
||||
|
|
|
@ -209,6 +209,7 @@ public:
|
|||
virtual ~ExpressionNode() {}
|
||||
virtual ControlState GetValue() { return 0; }
|
||||
virtual void SetValue(ControlState state) {}
|
||||
virtual int CountNumControls() { return 0; }
|
||||
virtual bool IsComplicated() { return false; }
|
||||
virtual operator std::string() { return ""; }
|
||||
};
|
||||
|
@ -231,6 +232,11 @@ public:
|
|||
control->ToOutput()->SetState(value);
|
||||
}
|
||||
|
||||
virtual int CountNumControls()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual bool IsComplicated()
|
||||
{
|
||||
return false;
|
||||
|
@ -282,6 +288,11 @@ public:
|
|||
rhs->SetValue(value);
|
||||
}
|
||||
|
||||
virtual int CountNumControls()
|
||||
{
|
||||
return lhs->CountNumControls() + rhs->CountNumControls();
|
||||
}
|
||||
|
||||
virtual bool IsComplicated()
|
||||
{
|
||||
return true;
|
||||
|
@ -329,6 +340,11 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
virtual int CountNumControls()
|
||||
{
|
||||
return inner->CountNumControls();
|
||||
}
|
||||
|
||||
virtual bool IsComplicated()
|
||||
{
|
||||
return true;
|
||||
|
@ -351,6 +367,9 @@ Device *ControlFinder::FindDevice(ControlQualifier qualifier)
|
|||
Device::Control *ControlFinder::FindControl(ControlQualifier qualifier)
|
||||
{
|
||||
Device *device = FindDevice(qualifier);
|
||||
if (!device)
|
||||
return NULL;
|
||||
|
||||
if (is_input)
|
||||
return device->FindInput(qualifier.control_name);
|
||||
else
|
||||
|
@ -368,18 +387,12 @@ public:
|
|||
|
||||
ExpressionParseStatus Parse(Expression **expr_out)
|
||||
{
|
||||
Expression *expr;
|
||||
ExpressionNode *expr_node;
|
||||
ExpressionParseStatus status = Toplevel(&expr_node);
|
||||
ExpressionNode *node;
|
||||
ExpressionParseStatus status = Toplevel(&node);
|
||||
if (status != EXPRESSION_PARSE_SUCCESS)
|
||||
return status;
|
||||
|
||||
expr = new Expression();
|
||||
expr->expr = expr_node;
|
||||
expr->num_controls = CountNumControls();
|
||||
expr->is_complicated = expr_node->IsComplicated();
|
||||
*expr_out = expr;
|
||||
|
||||
*expr_out = new Expression(node);
|
||||
return EXPRESSION_PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -510,33 +523,31 @@ private:
|
|||
{
|
||||
return Binary(expr_out);
|
||||
}
|
||||
|
||||
int CountNumControls()
|
||||
{
|
||||
int count = 0;
|
||||
for (std::vector<Token>::iterator it = tokens.begin(); it != tokens.end(); ++it)
|
||||
if (it->type == TOK_CONTROL)
|
||||
count++;
|
||||
return count;
|
||||
}
|
||||
};
|
||||
|
||||
ControlState Expression::GetValue()
|
||||
{
|
||||
return expr->GetValue();
|
||||
return node->GetValue();
|
||||
}
|
||||
|
||||
void Expression::SetValue(ControlState value)
|
||||
{
|
||||
expr->SetValue(value);
|
||||
node->SetValue(value);
|
||||
}
|
||||
|
||||
Expression::Expression(ExpressionNode *node_)
|
||||
{
|
||||
node = node_;
|
||||
num_controls = node->CountNumControls();
|
||||
is_complicated = node->IsComplicated();
|
||||
}
|
||||
|
||||
Expression::~Expression()
|
||||
{
|
||||
delete expr;
|
||||
delete node;
|
||||
}
|
||||
|
||||
ExpressionParseStatus ParseExpression(std::string str, ControlFinder &finder, Expression **expr_out)
|
||||
ExpressionParseStatus ParseExpressionInner(std::string str, ControlFinder &finder, Expression **expr_out)
|
||||
{
|
||||
ExpressionParseStatus status;
|
||||
Expression *expr;
|
||||
|
@ -560,5 +571,32 @@ ExpressionParseStatus ParseExpression(std::string str, ControlFinder &finder, Ex
|
|||
return EXPRESSION_PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
ExpressionParseStatus ParseExpression(std::string str, ControlFinder &finder, Expression **expr_out)
|
||||
{
|
||||
ExpressionParseStatus status;
|
||||
|
||||
status = ParseExpressionInner(str, finder, expr_out);
|
||||
if (status == EXPRESSION_PARSE_SUCCESS)
|
||||
return status;
|
||||
|
||||
if (status != EXPRESSION_PARSE_SYNTAX_ERROR)
|
||||
return status;
|
||||
|
||||
// Add compatibility with old simple expressions, which are simple
|
||||
// barewords control names.
|
||||
|
||||
ControlQualifier qualifier;
|
||||
qualifier.control_name = str;
|
||||
qualifier.has_device = false;
|
||||
|
||||
Device::Control *control = finder.FindControl(qualifier);
|
||||
if (control) {
|
||||
*expr_out = new Expression(new ControlExpression(qualifier, control));
|
||||
return EXPRESSION_PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
return EXPRESSION_PARSE_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,22 +41,18 @@ private:
|
|||
bool is_input;
|
||||
};
|
||||
|
||||
class Parser;
|
||||
class ExpressionNode;
|
||||
class Expression
|
||||
{
|
||||
friend class Parser;
|
||||
|
||||
public:
|
||||
Expression() : expr(NULL) {}
|
||||
Expression() : node(NULL) {}
|
||||
Expression(ExpressionNode *node);
|
||||
~Expression();
|
||||
ControlState GetValue();
|
||||
void SetValue (ControlState state);
|
||||
int num_controls;
|
||||
bool is_complicated;
|
||||
|
||||
private:
|
||||
ExpressionNode *expr;
|
||||
ExpressionNode *node;
|
||||
};
|
||||
|
||||
enum ExpressionParseStatus
|
||||
|
|
Loading…
Reference in New Issue