fix missing bracket folds for SUB and DIV operator replacement parallelization
This commit is contained in:
+41
-43
@@ -430,21 +430,20 @@ static void add_bracket_to(std::vector<Expression::Token>& tv, const int locatio
|
||||
{
|
||||
if (tv[i].t == Expression::Token::OPERATOR)
|
||||
{
|
||||
switch (tv[i].v.o)
|
||||
if (tv[i].v.o == Expression::Token::CPA)
|
||||
{
|
||||
case Expression::Token::OPA:
|
||||
lv--;
|
||||
break;
|
||||
case Expression::Token::CPA:
|
||||
lv++;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
if (!lv)
|
||||
{
|
||||
tv.insert(tv.begin() + i + 1, Expression::Token(Expression::Token::OPA));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
if (tv[i].v.o == Expression::Token::OPA)
|
||||
{
|
||||
lv--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -457,21 +456,20 @@ static void add_bracket_to(std::vector<Expression::Token>& tv, const int locatio
|
||||
{
|
||||
if (tv[i].t == Expression::Token::OPERATOR)
|
||||
{
|
||||
switch (tv[i].v.o)
|
||||
if (tv[i].v.o == Expression::Token::OPA)
|
||||
{
|
||||
case Expression::Token::OPA:
|
||||
lv++;
|
||||
break;
|
||||
case Expression::Token::CPA:
|
||||
lv--;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
if (!lv)
|
||||
{
|
||||
tv.insert(tv.begin() + i, Expression::Token(Expression::Token::CPA));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
if (tv[i].v.o == Expression::Token::CPA)
|
||||
{
|
||||
lv--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -649,39 +647,35 @@ void apply_corrections(std::vector<Expression::Token>& tv)
|
||||
}
|
||||
|
||||
for (int current_prio_level = mp[get_max_index(mp)]; current_prio_level >= 0; current_prio_level--)
|
||||
{
|
||||
// calculate how many ranges need to be processed at this level
|
||||
std::vector<Range> rv;
|
||||
find_select_prio_op_ranges(mp, rv, current_prio_level);
|
||||
|
||||
for (int current_range = rv.size() - 1; current_range >= 0; current_range--)
|
||||
{
|
||||
Range &outer_range = rv[current_range];
|
||||
|
||||
std::vector<int> inner_prios;
|
||||
rank_inner_ops_raw(inner_prios, tv, outer_range.start, outer_range.finish);
|
||||
|
||||
for (int inner_prio = inner_prios[get_max_index(inner_prios)]; inner_prio >= 0; inner_prio--)
|
||||
{
|
||||
std::vector<Range> inner_ranges;
|
||||
find_select_prio_op_ranges(inner_prios, inner_ranges, inner_prio);
|
||||
|
||||
for (int inner_range = inner_ranges.size() - 1; inner_range >= 0; inner_range--)
|
||||
{
|
||||
int corrections = 1;
|
||||
int relative_level = -current_prio_level;
|
||||
|
||||
Range &range = inner_ranges[inner_range];
|
||||
while (corrections)
|
||||
{
|
||||
corrections = 0;
|
||||
|
||||
int same_op_cnt = -1;
|
||||
for (int i = outer_range.start + range.start; i < outer_range.start + range.finish + 1; i++)
|
||||
for (int i = 0; i < tv.size(); i++)
|
||||
{
|
||||
int loc = get_mop_location(tv, i);
|
||||
Expression::Token& tok = tv[loc];
|
||||
Expression::Token& tok = tv[i];
|
||||
|
||||
if (tok.v.o == Expression::Token::SUB || tok.v.o == Expression::Token::DIV)
|
||||
if (tok.t == Expression::Token::OPERATOR)
|
||||
{
|
||||
if (tok.v.o == Expression::Token::OPA)
|
||||
{
|
||||
relative_level++;
|
||||
}
|
||||
else if (tok.v.o == Expression::Token::CPA)
|
||||
{
|
||||
relative_level--;
|
||||
}
|
||||
|
||||
if (relative_level < 0)
|
||||
{
|
||||
same_op_cnt = -1;
|
||||
}
|
||||
else if ((tok.v.o == Expression::Token::SUB || tok.v.o == Expression::Token::DIV) && !relative_level)
|
||||
{
|
||||
same_op_cnt++;
|
||||
|
||||
@@ -705,8 +699,14 @@ void apply_corrections(std::vector<Expression::Token>& tv)
|
||||
}
|
||||
|
||||
// inverse order to keep location valid between calls
|
||||
add_bracket_to(tv, loc, 1);
|
||||
add_bracket_to(tv, loc, -1);
|
||||
add_bracket_to(tv, i, 1);
|
||||
add_bracket_to(tv, i, -1);
|
||||
|
||||
// advance one step to compensate for inserted left bracket
|
||||
i++;
|
||||
|
||||
// elevate one level to compensate for new brackets
|
||||
relative_level++;
|
||||
|
||||
pr_debug("Updated vector:");
|
||||
Parser::print_math_vector(tv);
|
||||
@@ -717,8 +717,6 @@ void apply_corrections(std::vector<Expression::Token>& tv)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Expression::Operation> build_op_vector(const std::vector<Expression::Token>& tv)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user