Commit 37934681 authored by GoshaZotov's avatar GoshaZotov

replace IncrementArguments/DecrementArguments/getArguments call into parse function

parent 87371906
...@@ -4819,6 +4819,7 @@ parserFormula.prototype.setFormula = function(formula) { ...@@ -4819,6 +4819,7 @@ parserFormula.prototype.setFormula = function(formula) {
this.operand_expected = true; this.operand_expected = true;
var wasLeftParentheses = false, wasRigthParentheses = false, found_operand = null, _3DRefTmp = null, _tableTMP = null; var wasLeftParentheses = false, wasRigthParentheses = false, found_operand = null, _3DRefTmp = null, _tableTMP = null;
cFormulaList = (local && AscCommonExcel.cFormulaFunctionLocalized) ? AscCommonExcel.cFormulaFunctionLocalized : cFormulaFunction; cFormulaList = (local && AscCommonExcel.cFormulaFunctionLocalized) ? AscCommonExcel.cFormulaFunctionLocalized : cFormulaFunction;
var leftParentArgumentsCurrentArr = [];
var t = this; var t = this;
var parseOperators = function(){ var parseOperators = function(){
...@@ -4892,6 +4893,7 @@ parserFormula.prototype.setFormula = function(formula) { ...@@ -4892,6 +4893,7 @@ parserFormula.prototype.setFormula = function(formula) {
found_operand = null; found_operand = null;
t.elemArr.push(new cFormulaOperators[t.operand_str]()); t.elemArr.push(new cFormulaOperators[t.operand_str]());
t.f.push(new cFormulaOperators[t.operand_str]()); t.f.push(new cFormulaOperators[t.operand_str]());
leftParentArgumentsCurrentArr[t.elemArr.length - 1] = 1;
if(startSumproduct){ if(startSumproduct){
counterSumproduct++; counterSumproduct++;
...@@ -4906,12 +4908,15 @@ parserFormula.prototype.setFormula = function(formula) { ...@@ -4906,12 +4908,15 @@ parserFormula.prototype.setFormula = function(formula) {
t.f.push(new cFormulaOperators[t.operand_str]()); t.f.push(new cFormulaOperators[t.operand_str]());
wasRigthParentheses = true; wasRigthParentheses = true;
var top_elem = null; var top_elem = null;
var top_elem_arg_count = null;
if (0 !== t.elemArr.length && ( (top_elem = t.elemArr[t.elemArr.length - 1]).name === '(' ) && if (0 !== t.elemArr.length && ( (top_elem = t.elemArr[t.elemArr.length - 1]).name === '(' ) &&
t.operand_expected) { t.operand_expected) {
if (top_elem.getArguments() > 1) { top_elem_arg_count = leftParentArgumentsCurrentArr[t.elemArr.length - 1];
if (top_elem_arg_count > 1) {
t.outStack.push(new cEmpty()); t.outStack.push(new cEmpty());
} else { } else {
top_elem.DecrementArguments(); leftParentArgumentsCurrentArr[t.elemArr.length - 1]--;
top_elem_arg_count = leftParentArgumentsCurrentArr[t.elemArr.length - 1];
} }
} else { } else {
while (0 !== t.elemArr.length && while (0 !== t.elemArr.length &&
...@@ -4924,6 +4929,7 @@ parserFormula.prototype.setFormula = function(formula) { ...@@ -4924,6 +4929,7 @@ parserFormula.prototype.setFormula = function(formula) {
} }
t.outStack.push(t.elemArr.pop()); t.outStack.push(t.elemArr.pop());
} }
top_elem_arg_count = leftParentArgumentsCurrentArr[t.elemArr.length - 1];
} }
if (0 === t.elemArr.length || null === top_elem/* && !wasLeftParentheses */) { if (0 === t.elemArr.length || null === top_elem/* && !wasLeftParentheses */) {
...@@ -4938,15 +4944,15 @@ parserFormula.prototype.setFormula = function(formula) { ...@@ -4938,15 +4944,15 @@ parserFormula.prototype.setFormula = function(formula) {
if (0 !== t.elemArr.length && if (0 !== t.elemArr.length &&
( func = t.elemArr[t.elemArr.length - 1] ).type === cElementType.func) { ( func = t.elemArr[t.elemArr.length - 1] ).type === cElementType.func) {
p = t.elemArr.pop(); p = t.elemArr.pop();
if (top_elem.getArguments() > func.argumentsMax) { if (top_elem_arg_count > func.argumentsMax) {
t.outStack = []; t.outStack = [];
t.elemArr = []; t.elemArr = [];
t.error.push(c_oAscError.ID.FrmlWrongMaxArgument); t.error.push(c_oAscError.ID.FrmlWrongMaxArgument);
return false; return false;
} else { } else {
if (top_elem.getArguments() >= func.argumentsMin) { if (top_elem_arg_count >= func.argumentsMin) {
t.outStack.push(top_elem.getArguments()); t.outStack.push(top_elem_arg_count);
if (!func.checkArguments(top_elem.getArguments())) { if (!func.checkArguments(top_elem_arg_count)) {
bError = true; bError = true;
} }
} else { } else {
...@@ -4991,16 +4997,18 @@ parserFormula.prototype.setFormula = function(formula) { ...@@ -4991,16 +4997,18 @@ parserFormula.prototype.setFormula = function(formula) {
var parseCommaAndArgumentsUnion = function(){ var parseCommaAndArgumentsUnion = function(){
wasLeftParentheses = false; wasLeftParentheses = false;
wasRigthParentheses = false; wasRigthParentheses = false;
var stackLength = t.elemArr.length, top_elem = null; var stackLength = t.elemArr.length, top_elem = null, top_elem_arg_pos;
if (t.elemArr.length != 0 && t.elemArr[stackLength - 1].name == "(" && t.operand_expected) { if (t.elemArr.length != 0 && t.elemArr[stackLength - 1].name == "(" && t.operand_expected) {
t.outStack.push(new cEmpty()); t.outStack.push(new cEmpty());
top_elem = t.elemArr[stackLength - 1]; top_elem = t.elemArr[stackLength - 1];
top_elem_arg_pos = stackLength - 1;
wasLeftParentheses = true; wasLeftParentheses = true;
t.operand_expected = false; t.operand_expected = false;
} else { } else {
while (stackLength != 0) { while (stackLength != 0) {
top_elem = t.elemArr[stackLength - 1]; top_elem = t.elemArr[stackLength - 1];
top_elem_arg_pos = stackLength - 1;
if (top_elem.name == "(") { if (top_elem.name == "(") {
wasLeftParentheses = true; wasLeftParentheses = true;
break; break;
...@@ -5024,7 +5032,7 @@ parserFormula.prototype.setFormula = function(formula) { ...@@ -5024,7 +5032,7 @@ parserFormula.prototype.setFormula = function(formula) {
t.elemArr = []; t.elemArr = [];
return false; return false;
} }
top_elem.IncrementArguments(); leftParentArgumentsCurrentArr[top_elem_arg_pos]++;
t.operand_expected = true; t.operand_expected = true;
return true; return true;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment