public static bool TryGetLogicalExpressionValueFast(List <string> sOperands, List <string> sOperators, out DHJassValue value) { if (IsTracing) { if (expressionDepth == 0) { traceFound = false; } expressionDepth++; } List <DHJassBoolean> operands = new List <DHJassBoolean>(sOperands.Count); List <string> operators = new List <string>(sOperators.Count); ////////////////////////////////// // collect operands ////////////////////////////////// foreach (string ccOperand in sOperands) { DHJassBoolean operand = new DHJassBoolean(); operand.SetValue(ccOperand); operands.Add(operand); } //////////////////////////////////// // collect operators //////////////////////////////////// foreach (string ccOperator in sOperators) { operators.Add(ccOperator); } ////////////////////////////////////// // process expression ////////////////////////////////////// if (operands.Count == 0) { value = null; return(false); } DHJassBoolean operand2; DHJassBoolean result; result = operands[0]; for (int i = 0; i < operators.Count; i++) { string Operator = operators[i]; if (Operator == "and") { operand2 = operands[i + 1]; result = result.And(operand2); } else if (Operator == "or") { operand2 = operands[i + 1]; result = result.Or(operand2); } else { continue; } } if (IsTracing) { expressionDepth--; //if (expressionDepth == 0 && traceFound) // Console.WriteLine("Found reference in:" + match.Value); } value = result; return(true); }
public static bool TryGetValue(string code, out DHJassValue value) { if (String.IsNullOrEmpty(code)) { value = null; return(false); } string name; string param; List <string> operands; List <string> operators; object parsedValue; unsafe { fixed(char *pStr = code) { char *ptr = DHJassSyntax.removeWsRbRecursive(pStr, pStr + code.Length); code = new string(ptr); if (DHJassSyntax.checkDirectValueSyntaxFast(*pStr)) { foreach (DHJassValue parser in DbJassTypeValueKnowledge.TypeValuePairs.Values) { if (parser.TryParseDirect(code, out parsedValue)) { value = parser.GetNew(); value.Value = parsedValue; return(true); } } } else { switch (code) { case "null": value = new DHJassUnusedType(); return(true); case "true": value = new DHJassBoolean(null, true); return(true); case "false": value = new DHJassBoolean(null, false); return(true); } } if (DHJassSyntax.checkLogicalExpressionsSyntaxFast(ptr, out operands, out operators)) { return(TryGetLogicalExpressionValueFast(operands, operators, out value)); } else if (DHJassSyntax.checkRelationalExpressionsSyntaxFast(ptr, out operands, out operators)) //, out match)) { return(TryGetRelationalExpressionValueFast(operands, operators, out value)); //match, out value); } else if (DHJassSyntax.checkArithmeticExpressionsSyntaxFast(ptr, out operands, out operators)) //, out match)) { return(TryGetArithmeticExpressionValueFast(operands, operators, out value)); //match, out value); } else if (DHJassSyntax.checkTypeVariableUsageSyntaxFast(code, out name)) { return(TryGetVariable(name, out value)); } else if (DHJassSyntax.checkArrayVariableUsageSyntaxFast(ptr, out name, out param)) { DHJassValue array; if (TryGetVariable(name, out array) && array is DHJassArray) { int index; if (DHJassInt.TryParse(param, out index)) { value = (array as DHJassArray)[index]; return(true); } } } else if (DHJassSyntax.checkFunctionUsageSyntaxFast(ptr, out name, out operands)) // out match)) { return(TryCallFunctionFast(name, operands, out value)); // match, out value); } else if (DHJassSyntax.checkFunctionPointerUsageSyntaxFast(ptr, out name)) { return(TryGetFunctionPointer(name, out value)); } } } value = null; return(false); }