Пример #1
0
 public DHJassGetValueCommand(string code)
 {
     if (!TryParseCode(code, out command))
     {
         command = new DHJassPassValueCommand(new DHJassUnusedType());
     }
 }
Пример #2
0
        public bool TryParseCode(string code, out DHJassCommand command)
        {
            if (code != "nothing")
            {
                string name = null;
                DHJassGetValueOnDemandCommand value = null;

                DHJassValue   variable;
                List <string> args;

                if (DHJassValue.TryParseDeclaration(code, out variable, out args))
                {
                    name  = args[0];
                    value = new DHJassGetValueOnDemandCommand(args.Count > 1 ? args[1] : string.Empty);
                }
                else
                {
                    variable = new DHJassUnusedType();
                    name     = "error!";
                    value    = null;
                }

                command = new DHJassPassValueCopyCommand(variable, name, value);
                return(true);
            }

            command = null;
            return(false);
        }
Пример #3
0
 public override DHJassValue GetResult()
 {
     if (command == null)
     {
         if (!TryParseCode(code, out command))
         {
             command = new DHJassPassValueCommand(new DHJassUnusedType());
         }
     }
     return(command.GetResult());
 }
Пример #4
0
        public static bool TryGetFunctionPointerCommand(string name, out DHJassCommand functionPointer)
        {
            DHJassFunction function;

            if (DHJassExecutor.Functions.TryGetValue(name, out function))
            {
                functionPointer = new DHJassPassValueCommand(new DHJassCode(null, function));
                return(true);
            }

            functionPointer = new DHJassPassValueCommand(null);
            return(false);
        }
Пример #5
0
        public bool TryParseCode(string name_usage, string valueToSet, out DHJassCommand command)
        {
            string name;
            string param;

            if (DHJassSyntax.checkTypeVariableUsageSyntaxFast(name_usage, out name))
            {
                command = new DHJassPassVariableCommand(name);
                value   = new DHJassGetValueOnDemandCommand(valueToSet);
                return(true);
            }
            else
            if (DHJassSyntax.checkArrayVariableUsageSyntaxFast(name_usage, out name, out param))
            {
                command = new DHJassPassVariableCommand(name);
                index   = new DHJassGetValueOnDemandCommand(param);
                value   = new DHJassGetValueOnDemandCommand(valueToSet);

                return(true);
            }

            command = null;
            return(false);
        }
Пример #6
0
        public static bool TryGetRelationalExpressionCommandFast(List<string> sOperands, List<string> operators, out DHJassCommand value)
        {
            List<DHJassCommand> operands = new List<DHJassCommand>(sOperands.Count);

            //////////////////////////////////
            //  collect operands
            //////////////////////////////////
            foreach (string ccOperand in sOperands)
            {
                //DHJassValue operand = DHJassValue.CreateValueFromCode(ccOperand.Value);
                DHJassCommand operand = new DHJassGetValueCommand(ccOperand);
                operands.Add(operand);
            }

            //////////////////////////////////////
            //  process expression
            //////////////////////////////////////

            if (operands.Count == 0)
            {
                value = null;
                return false;
            }

            //DHJassBoolean operand1;
            DHJassCommand operand2;
            DHJassCommand result;

            result = operands[0];

            for (int i = 0; i < operators.Count; i++)
            {
                string Operator = operators[i];
                operand2 = operands[i + 1];

                switch (Operator)
                {
                    case ">":
                        result = new DHJassOperationCommand(result, operand2, AnyOperation.Greater);
                        break;

                    case ">=":
                        result = new DHJassOperationCommand(result, operand2, AnyOperation.GreaterOrEqual);
                        break;

                    case "<":
                        result = new DHJassOperationCommand(result, operand2, AnyOperation.Less);
                        break;

                    case "<=":
                        result = new DHJassOperationCommand(result, operand2, AnyOperation.LessOrEqual);
                        break;

                    case "==":
                        result = new DHJassOperationCommand(result, operand2, AnyOperation.Equal);
                        break;

                    case "!=":
                        result = new DHJassOperationCommand(result, operand2, AnyOperation.NotEqual);
                        break;
                }
            }

            value = result;
            return true;
        }
Пример #7
0
 public static bool TryGetArrayElementCommand(string name, string indexCode, out DHJassCommand element)
 {
     element = new DHJassGetArrayElementCommand(name, indexCode);
     return(true);
 }
Пример #8
0
 public static bool TryGetVariableCommand(string name, out DHJassCommand variable)
 {
     variable = new DHJassPassVariableCommand(name);
     return(true);
 }
Пример #9
0
        public bool TryParseCode(string code, out DHJassCommand command)
        {
            if (code != "nothing")
            {
                string name = null;
                DHJassGetValueOnDemandCommand value = null;

                DHJassValue variable;
                List<string> args;

                if (DHJassValue.TryParseDeclaration(code, out variable, out args))
                {
                    name = args[0];
                    value = new DHJassGetValueOnDemandCommand(args.Count > 1 ? args[1] : string.Empty);
                }
                else
                {
                    variable = new DHJassUnusedType();
                    name = "error!";
                    value = null;
                }

                command = new DHJassPassValueCopyCommand(variable, name, value);
                return true;
            }

            command = null;
            return false;
        }
Пример #10
0
 public DHJassGetArrayElementCommand(string name, string indexCode)
 {
     this.name = name;
     this.index = new DHJassGetValueCommand(indexCode);
 }
Пример #11
0
        public bool TryParseCode(string code, out DHJassCommand command)
        {
            if (String.IsNullOrEmpty(code))
            {
                command = null;
                return(false);
            }

            string        name;
            string        param;
            List <string> operands;
            List <string> operators;
            bool          isDirectValue;
            object        parsedValue;

            unsafe
            {
                fixed(char *pStr = code)
                {
                    char *ptr = DHJassSyntax.removeWsRbRecursive(pStr, pStr + code.Length);

                    code = new string(ptr);

                    if (isDirectValue = DHJassSyntax.checkDirectValueSyntaxFast(*ptr))
                    {
                        foreach (DHJassValue parser in DbJassTypeValueKnowledge.TypeValuePairs.Values)
                        {
                            if (parser.TryParseDirect(code, out parsedValue))
                            {
                                DHJassValue value = parser.GetNew();
                                value.Value = parsedValue;
                                command     = new DHJassPassValueCommand(value);
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        switch (code)
                        {
                        case "null":
                            command = new DHJassPassValueCommand(new DHJassUnusedType());
                            return(true);

                        case "true":
                            command = new DHJassPassValueCommand(new DHJassBoolean(null, true));
                            return(true);

                        case "false":
                            command = new DHJassPassValueCommand(new DHJassBoolean(null, false));
                            return(true);
                        }
                    }

                    if (DHJassSyntax.checkLogicalExpressionsSyntaxFast(ptr, out operands, out operators))//code, out match))
                    {
                        return(TryGetLogicalExpressionCommandFast(operands, operators, out command));
                    }
                    else
                    if (DHJassSyntax.checkRelationalExpressionsSyntaxFast(ptr, out operands, out operators)) // out match))
                    {
                        return(TryGetRelationalExpressionCommandFast(operands, operators, out command));     //match, out command);
                    }
                    else
                    if (DHJassSyntax.checkArithmeticExpressionsSyntaxFast(ptr, out operands, out operators))    // out match))
                    {
                        return(TryGetArithmeticExpressionCommandFast(operands, operators, out command));        //match, out command);
                    }
                    else
                    if (!isDirectValue)
                    {
                        if (DHJassSyntax.checkNegativeOperatorUsageSyntaxFast(ptr, out name))
                        {
                            return(TryGetNegativeOperatorCommand(name, out command));
                        }
                        else
                        if (DHJassSyntax.checkTypeVariableUsageSyntaxFast(ptr, out name))
                        {
                            return(TryGetVariableCommand(name, out command));
                        }
                        else
                        if (DHJassSyntax.checkArrayVariableUsageSyntaxFast(ptr, out name, out param))
                        {
                            return(TryGetArrayElementCommand(name, param, out command));
                        }
                        else
                        if (DHJassSyntax.checkFunctionUsageSyntaxFast(ptr, out name, out operands))                        // out match))
                        {
                            return(TryGetCallFunctionCommandFast(name, operands, out command));
                        }
                        else
                        if (DHJassSyntax.checkFunctionPointerUsageSyntaxFast(ptr, out name))
                        {
                            return(TryGetFunctionPointerCommand(name, out command));
                        }
                    }
                }
            }

            command = null;
            return(false);
        }
Пример #12
0
 public DHJassGetValueCommand(string code)
 {
     if (!TryParseCode(code, out command))
         command = new DHJassPassValueCommand(new DHJassUnusedType());
 }
Пример #13
0
        public static bool TryGetRelationalExpressionCommandFast(List <string> sOperands, List <string> operators, out DHJassCommand value)
        {
            List <DHJassCommand> operands = new List <DHJassCommand>(sOperands.Count);

            //////////////////////////////////
            //  collect operands
            //////////////////////////////////
            foreach (string ccOperand in sOperands)
            {
                //DHJassValue operand = DHJassValue.CreateValueFromCode(ccOperand.Value);
                DHJassCommand operand = new DHJassGetValueCommand(ccOperand);
                operands.Add(operand);
            }

            //////////////////////////////////////
            //  process expression
            //////////////////////////////////////

            if (operands.Count == 0)
            {
                value = null;
                return(false);
            }

            //DHJassBoolean operand1;
            DHJassCommand operand2;
            DHJassCommand result;

            result = operands[0];

            for (int i = 0; i < operators.Count; i++)
            {
                string Operator = operators[i];
                operand2 = operands[i + 1];

                switch (Operator)
                {
                case ">":
                    result = new DHJassOperationCommand(result, operand2, AnyOperation.Greater);
                    break;

                case ">=":
                    result = new DHJassOperationCommand(result, operand2, AnyOperation.GreaterOrEqual);
                    break;

                case "<":
                    result = new DHJassOperationCommand(result, operand2, AnyOperation.Less);
                    break;

                case "<=":
                    result = new DHJassOperationCommand(result, operand2, AnyOperation.LessOrEqual);
                    break;

                case "==":
                    result = new DHJassOperationCommand(result, operand2, AnyOperation.Equal);
                    break;

                case "!=":
                    result = new DHJassOperationCommand(result, operand2, AnyOperation.NotEqual);
                    break;
                }
            }

            value = result;
            return(true);
        }
Пример #14
0
 public static bool TryGetNegativeOperatorCommand(string operand, out DHJassCommand command)
 {
     command = new DHJassOperationCommand(new DHJassGetValueOnDemandCommand(operand), AnyOperation.Not);
     return true;
 }
Пример #15
0
        public static bool TryGetLogicalExpressionCommandFast(List <string> sOperands, List <string> operators, out DHJassCommand value)
        {
            List <DHJassCommand> operands = new List <DHJassCommand>(sOperands.Count);

            //////////////////////////////////
            //  collect operands
            //////////////////////////////////
            foreach (string ccOperand in sOperands)
            {
                //DHJassBoolean operand = new DHJassBoolean();
                //operand.SetValue(ccOperand.Value);
                DHJassCommand operand = new DHJassGetValueCommand(ccOperand);
                operands.Add(operand);
            }

            //////////////////////////////////////
            //  process expression
            //////////////////////////////////////

            if (operands.Count == 0)
            {
                value = null;
                return(false);
            }

            DHJassCommand operand2;
            DHJassCommand result;

            result = operands[0];

            for (int i = 0; i < operators.Count; i++)
            {
                string Operator = operators[i];

                if (Operator == "and")
                {
                    operand2 = operands[i + 1];
                    result   = new DHJassOperationCommand(result, operand2, AnyOperation.AND);
                }
                else
                if (Operator == "or")
                {
                    operand2 = operands[i + 1];
                    result   = new DHJassOperationCommand(result, operand2, AnyOperation.OR);
                }
                else
                {
                    continue;
                }
            }

            value = result;
            return(true);
        }
Пример #16
0
        public static bool TryGetLogicalExpressionCommandFast(List<string> sOperands, List<string> operators, out DHJassCommand value)
        {
            List<DHJassCommand> operands = new List<DHJassCommand>(sOperands.Count);

            //////////////////////////////////
            //  collect operands
            //////////////////////////////////
            foreach (string ccOperand in sOperands)
            {
                //DHJassBoolean operand = new DHJassBoolean();
                //operand.SetValue(ccOperand.Value);
                DHJassCommand operand = new DHJassGetValueCommand(ccOperand);
                operands.Add(operand);
            }

            //////////////////////////////////////
            //  process expression
            //////////////////////////////////////

            if (operands.Count == 0)
            {
                value = null;
                return false;
            }

            DHJassCommand operand2;
            DHJassCommand result;

            result = operands[0];

            for (int i = 0; i < operators.Count; i++)
            {
                string Operator = operators[i];

                if (Operator == "and")
                {
                    operand2 = operands[i + 1];
                    result = new DHJassOperationCommand(result, operand2, AnyOperation.AND);
                }
                else
                    if (Operator == "or")
                    {
                        operand2 = operands[i + 1];
                        result = new DHJassOperationCommand(result, operand2, AnyOperation.OR);
                    }
                    else
                        continue;
            }

            value = result;
            return true;
        }
Пример #17
0
        public static bool TryGetFunctionPointerCommand(string name, out DHJassCommand functionPointer)
        {
            DHJassFunction function;
            if (DHJassExecutor.Functions.TryGetValue(name, out function))
            {
                functionPointer = new DHJassPassValueCommand(new DHJassCode(null, function));
                return true;
            }

            functionPointer = new DHJassPassValueCommand(null);
            return false;
        }
Пример #18
0
 public static bool TryGetCallFunctionCommandFast(string name, List<string> args, out DHJassCommand functionCall)
 {
     functionCall = new DHJassCallFunctionCommand(name, args);
     return true;
 }
Пример #19
0
 public static bool TryGetArrayElementCommand(string name, string indexCode, out DHJassCommand element)
 {
     element = new DHJassGetArrayElementCommand(name, indexCode);
     return true;
 }
Пример #20
0
        public static bool TryGetArithmeticExpressionCommandFast(List<string> sOperands, List<string> operators, out DHJassCommand value)
        {
            List<DHJassCommand> operands = new List<DHJassCommand>(sOperands.Count);

            //////////////////////////////////
            //  collect operands
            //////////////////////////////////
            foreach (string ccOperand in sOperands)
            {
                DHJassCommand operand = new DHJassGetValueCommand(ccOperand);
                operands.Add(operand);
            }

            //////////////////////////////////////
            //  process expression
            //////////////////////////////////////

            if (operands.Count == 0)
            {
                value = null;
                return false;
            }

            DHJassCommand operand1;
            DHJassCommand operand2;
            DHJassCommand result;

            // process '*' and '/' first

            for (int i = 0; i < operators.Count; i++)
            {
                string Operator = operators[i];

                if (Operator == "*")
                {
                    operand1 = operands[i];
                    operand2 = operands[i + 1];
                    result = new DHJassOperationCommand(operand1, operand2, AnyOperation.Multiply);
                }
                else
                    if (Operator == "/")
                    {
                        operand1 = operands[i];
                        operand2 = operands[i + 1];
                        result = new DHJassOperationCommand(operand1, operand2, AnyOperation.Divide);
                    }
                    else
                        continue;

                operands[i] = result;
                operands.RemoveAt(i + 1);
                operators.RemoveAt(i);
                i--;
            }

            // now '+' and '-'

            result = operands[0];

            for (int i = 0; i < operators.Count; i++)
            {
                string Operator = operators[i];

                if (Operator == "+")
                {
                    operand2 = operands[i + 1];
                    result = new DHJassOperationCommand(result, operand2, AnyOperation.Add);
                }
                else
                    if (Operator == "-")
                    {
                        operand2 = operands[i + 1];
                        result = new DHJassOperationCommand(result, operand2, AnyOperation.Subtract);
                    }
                    else
                        continue;
            }

            value = result;
            return true;
        }
Пример #21
0
        public static bool TryGetArithmeticExpressionCommandFast(List <string> sOperands, List <string> operators, out DHJassCommand value)
        {
            List <DHJassCommand> operands = new List <DHJassCommand>(sOperands.Count);

            //////////////////////////////////
            //  collect operands
            //////////////////////////////////
            foreach (string ccOperand in sOperands)
            {
                DHJassCommand operand = new DHJassGetValueCommand(ccOperand);
                operands.Add(operand);
            }

            //////////////////////////////////////
            //  process expression
            //////////////////////////////////////

            if (operands.Count == 0)
            {
                value = null;
                return(false);
            }

            DHJassCommand operand1;
            DHJassCommand operand2;
            DHJassCommand result;

            // process '*' and '/' first

            for (int i = 0; i < operators.Count; i++)
            {
                string Operator = operators[i];

                if (Operator == "*")
                {
                    operand1 = operands[i];
                    operand2 = operands[i + 1];
                    result   = new DHJassOperationCommand(operand1, operand2, AnyOperation.Multiply);
                }
                else
                if (Operator == "/")
                {
                    operand1 = operands[i];
                    operand2 = operands[i + 1];
                    result   = new DHJassOperationCommand(operand1, operand2, AnyOperation.Divide);
                }
                else
                {
                    continue;
                }

                operands[i] = result;
                operands.RemoveAt(i + 1);
                operators.RemoveAt(i);
                i--;
            }

            // now '+' and '-'

            result = operands[0];

            for (int i = 0; i < operators.Count; i++)
            {
                string Operator = operators[i];

                if (Operator == "+")
                {
                    operand2 = operands[i + 1];
                    result   = new DHJassOperationCommand(result, operand2, AnyOperation.Add);
                }
                else
                if (Operator == "-")
                {
                    operand2 = operands[i + 1];
                    result   = new DHJassOperationCommand(result, operand2, AnyOperation.Subtract);
                }
                else
                {
                    continue;
                }
            }

            value = result;
            return(true);
        }
Пример #22
0
 public static bool TryGetVariableCommand(string name, out DHJassCommand variable)
 {
     variable = new DHJassPassVariableCommand(name);
     return true;
 }
Пример #23
0
 public static bool TryGetCallFunctionCommandFast(string name, List <string> args, out DHJassCommand functionCall)
 {
     functionCall = new DHJassCallFunctionCommand(name, args);
     return(true);
 }
Пример #24
0
        public bool TryParseCode(string code, out DHJassCommand command)
        {
            if (String.IsNullOrEmpty(code))
            {
                command = null;
                return false;
            }

            string name;
            string param;
            List<string> operands;
            List<string> operators;
            bool isDirectValue;
            object parsedValue;

            unsafe
            {
                fixed (char* pStr = code)
                {
                    char* ptr = DHJassSyntax.removeWsRbRecursive(pStr, pStr + code.Length);
                    code = new string(ptr);

                    if (isDirectValue = DHJassSyntax.checkDirectValueSyntaxFast(*ptr))
                    {
                        foreach (DHJassValue parser in DbJassTypeValueKnowledge.TypeValuePairs.Values)
                            if (parser.TryParseDirect(code, out parsedValue))
                            {
                                DHJassValue value = parser.GetNew();
                                value.Value = parsedValue;
                                command = new DHJassPassValueCommand(value);
                                return true;
                            }
                    }
                    else
                        switch (code)
                        {
                            case "null":
                                command = new DHJassPassValueCommand(new DHJassUnusedType());
                                return true;

                            case "true":
                                command = new DHJassPassValueCommand(new DHJassBoolean(null, true));
                                return true;

                            case "false":
                                command = new DHJassPassValueCommand(new DHJassBoolean(null, false));
                                return true;
                        }

                    if (DHJassSyntax.checkLogicalExpressionsSyntaxFast(ptr, out operands, out operators))//code, out match))
                        return TryGetLogicalExpressionCommandFast(operands, operators, out command);
                    else
                        if (DHJassSyntax.checkRelationalExpressionsSyntaxFast(ptr, out operands, out operators))// out match))
                            return TryGetRelationalExpressionCommandFast(operands, operators, out command);//match, out command);
                        else
                            if (DHJassSyntax.checkArithmeticExpressionsSyntaxFast(ptr, out operands, out operators))// out match))
                                return TryGetArithmeticExpressionCommandFast(operands, operators, out command); //match, out command);
                            else
                                if (!isDirectValue)
                                {
                                    if (DHJassSyntax.checkNegativeOperatorUsageSyntaxFast(ptr, out name))
                                        return TryGetNegativeOperatorCommand(name, out command);
                                    else
                                        if (DHJassSyntax.checkTypeVariableUsageSyntaxFast(ptr, out name))
                                            return TryGetVariableCommand(name, out command);
                                        else
                                            if (DHJassSyntax.checkArrayVariableUsageSyntaxFast(ptr, out name, out param))
                                                return TryGetArrayElementCommand(name, param, out command);
                                            else
                                                if (DHJassSyntax.checkFunctionUsageSyntaxFast(ptr, out name, out operands))// out match))
                                                    return TryGetCallFunctionCommandFast(name, operands, out command);
                                                else
                                                    if (DHJassSyntax.checkFunctionPointerUsageSyntaxFast(ptr, out name))
                                                        return TryGetFunctionPointerCommand(name, out command);
                                }
                }
            }

            command = null;
            return false;
        }
Пример #25
0
 public DHJassPassValueCopyCommand(DHJassValue value, string copyName, DHJassCommand copyValue)
 {
     this.variable = value;
     this.name     = copyName;
     this.value    = copyValue;
 }
Пример #26
0
 public DHJassOperationCommand(DHJassCommand a, AnyOperation operation)
 {
     this.a = a;
     this.operation = operation;
 }
Пример #27
0
 public DHJassGetArrayElementCommand(string name, string indexCode)
 {
     this.name  = name;
     this.index = new DHJassGetValueCommand(indexCode);
 }
Пример #28
0
 public DHJassPassValueCopyCommand(DHJassValue value, string copyName, DHJassCommand copyValue)
 {
     this.variable = value;
     this.name = copyName;
     this.value = copyValue;
 }
Пример #29
0
 public DHJassOperationCommand(DHJassCommand a, AnyOperation operation)
 {
     this.a         = a;
     this.operation = operation;
 }
Пример #30
0
        public bool TryParseCode(string name_usage, string valueToSet, out DHJassCommand command)
        {
            string name;
            string param;

            if (DHJassSyntax.checkTypeVariableUsageSyntaxFast(name_usage, out name))
            {
                command = new DHJassPassVariableCommand(name);
                value = new DHJassGetValueOnDemandCommand(valueToSet);
                return true;
            }
            else
                if (DHJassSyntax.checkArrayVariableUsageSyntaxFast(name_usage, out name, out param))
                {
                    command = new DHJassPassVariableCommand(name);
                    index = new DHJassGetValueOnDemandCommand(param);
                    value = new DHJassGetValueOnDemandCommand(valueToSet);

                    return true;
                }

            command = null;
            return false;
        }
Пример #31
0
 public static bool TryGetNegativeOperatorCommand(string operand, out DHJassCommand command)
 {
     command = new DHJassOperationCommand(new DHJassGetValueOnDemandCommand(operand), AnyOperation.Not);
     return(true);
 }
Пример #32
0
 public override DHJassValue GetResult()
 {
     if (command == null)
     {
         if (!TryParseCode(code, out command))
             command = new DHJassPassValueCommand(new DHJassUnusedType());
     }
     return command.GetResult();
 }