Ejemplo n.º 1
0
        public static IApiMethodBuilderResult CreateTestExpression(ApiBaseFunction func, ExpressionBuilderParams p,
                                                                   FunctionCallStatement functionCallStatement, TestExpressionCreator createTestExpression)
        {
            func.AssertParameters(p, functionCallStatement.Parameters);

            var result = createTestExpression(p, functionCallStatement);

            if (p.UsageContext is IfElseStatement)
            {
                return(new ApiMethodBuilderRawResult(new ExpressionResult(
                                                         func.TypeDescriptor,
                                                         result.Expression,
                                                         result.Template
                                                         )));
            }

            p.NonInlinePartWriter.WriteLine(result.Expression);

            var varName = BashVariableDefinitionStatementTranspiler.WriteLastStatusCodeStoreVariableDefinition(
                p.Context, p.Scope,
                p.NonInlinePartWriter, $"{functionCallStatement.Fqn}_Result");

            return(new ApiMethodBuilderRawResult(new ExpressionResult(
                                                     func.TypeDescriptor,
                                                     $"${varName}",
                                                     new VariableAccessStatement(varName, functionCallStatement.Info),
                                                     ExpressionBuilderBase.PinRequiredNotice
                                                     )));
        }
            public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                                          FunctionCallStatement functionCallStatement)
            {
                AssertParameters(p, functionCallStatement.Parameters);

                var param = functionCallStatement.Parameters[0];

                var dt = param.GetDataType(p.Context, p.Scope);

                EvaluationStatement exp;

                if (dt.IsBoolean() || dt.IsNumber())
                {
                    //create an string concatenation expression, ExpressionBuilder has this functionality inside.
                    exp = new ArithmeticEvaluationStatement(param, new AdditionOperator(param.Info),
                                                            new ConstantValueStatement(TypeDescriptor.String, "", param.Info), param.Info,
                                                            param.ParentStatement);

                    param.ParentStatement = exp;
                }
                else if (dt.IsString())
                {
                    exp = param;
                }
                else
                {
                    throw new MethodParameterMismatchCompilerException(Name, functionCallStatement.Info);
                }

                var transpiler = p.Context.GetEvaluationTranspilerForStatement(exp);
                var result     = transpiler.GetExpression(p, exp);

                return(new ApiMethodBuilderRawResult(result));
            }
Ejemplo n.º 3
0
 void IStatementVisitor.Visit(FunctionCallStatement statement)
 {
     statement.FunctionCall.AcceptInternal(this);
     if (statement.FunctionCall.ResultType != DataType.None)
     {
         generator.Emit(OpCodes.Pop);
     }
 }
            public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                                          FunctionCallStatement functionCallStatement)
            {
                AssertParameters(p, functionCallStatement.Parameters);

                var result = CreateVariableAccess(TypeDescriptor, "LANG", functionCallStatement.Info);

                return(new ApiMethodBuilderRawResult(result));
            }
Ejemplo n.º 5
0
 public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                               FunctionCallStatement functionCallStatement)
 {
     return(BashTestCommand.CreateTestExpression(this, p, functionCallStatement, (p1, fcs) =>
                                                 new ExpressionResult(
                                                     TypeDescriptor,
                                                     $"[ $(whoami) == 'root' ]",
                                                     functionCallStatement
                                                     )));
 }
Ejemplo n.º 6
0
            public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                                          FunctionCallStatement functionCallStatement)
            {
                AssertParameters(p, functionCallStatement.Parameters);

                var param = functionCallStatement.Parameters[0];

                var transpiler = p.Context.GetEvaluationTranspilerForStatement(param);
                var result     = transpiler.GetExpression(p, param);

                return(new ApiMethodBuilderRawResult(result));
            }
Ejemplo n.º 7
0
        public bool IsIdentifierExists(FunctionCallStatement functionCallStatement)
        {
            var that = this;

            do
            {
                if (that._identifiers.Contains(functionCallStatement.Fqn))
                {
                    return(true);
                }
            } while ((that = that.Parent) != null);

            return(false);
        }
Ejemplo n.º 8
0
            public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                                          FunctionCallStatement functionCallStatement)
            {
                AssertParameters(p, functionCallStatement.Parameters);

                var number = functionCallStatement.Parameters[0];

                switch (number)
                {
                case ConstantValueStatement constantValueStatement:
                {
                    return(InlineConstant(constantValueStatement.TypeDescriptor, constantValueStatement.Value,
                                          constantValueStatement));
                }

                case VariableAccessStatement variableAccessStatement:
                {
                    if (p.Scope.TryGetVariableInfo(variableAccessStatement, out var varInfo))
                    {
                        if (varInfo.TypeDescriptor.IsInteger())
                        {
                            return(new ApiMethodBuilderRawResult(new ExpressionResult(
                                                                     varInfo.TypeDescriptor,
                                                                     $"${{{varInfo.AccessName}#-}}",
                                                                     variableAccessStatement
                                                                     )));
                        }

                        return(CreateNativeMethodWithUtilityExpressionSelector(this, p, _functionInfo,
                                                                               _absUtilityExpressions, functionCallStatement.Parameters,
                                                                               functionCallStatement.Info));
                    }

                    if (p.Scope.TryGetConstantInfo(variableAccessStatement, out var constInfo))
                    {
                        return(InlineConstant(constInfo.TypeDescriptor, constInfo.Value, variableAccessStatement));
                    }

                    throw new IdentifierNotFoundCompilerException(variableAccessStatement);
                }

                default:
                {
                    return(CreateNativeMethodWithUtilityExpressionSelector(this, p, _functionInfo,
                                                                           _absUtilityExpressions, functionCallStatement.Parameters, functionCallStatement.Info));
                }
                }
            }
Ejemplo n.º 9
0
        public bool TryGetVariableInfo(FunctionCallStatement functionCallStatement, out VariableInfo variableInfo)
        {
            var varInfo = new VariableInfo(functionCallStatement.ClassName, functionCallStatement.FunctionName);

            var that = this;

            do
            {
                if (that._variables.TryGetValue(varInfo, out variableInfo))
                {
                    return(true);
                }
            } while ((that = that.Parent) != null);

            return(false);
        }
Ejemplo n.º 10
0
        public bool TryGetFunctionInfo(FunctionCallStatement functionCallStatement, out FunctionInfo functionInfo)
        {
            var funcInfo = new FunctionInfo(functionCallStatement.ClassName, functionCallStatement.FunctionName);

            var that = this;

            do
            {
                if (that._functions.TryGetValue(funcInfo, out functionInfo))
                {
                    return(true);
                }
            } while ((that = that.Parent) != null);

            return(false);
        }
Ejemplo n.º 11
0
            public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                                          FunctionCallStatement functionCallStatement)
            {
                AssertParameters(p, functionCallStatement.Parameters);

                var str = functionCallStatement.Parameters[0];

                switch (str)
                {
                case ConstantValueStatement constantValueStatement:
                {
                    return(InlineConstant(constantValueStatement.TypeDescriptor, constantValueStatement.Value,
                                          constantValueStatement));
                }

                case VariableAccessStatement variableAccessStatement:
                {
                    if (p.Scope.TryGetVariableInfo(variableAccessStatement, out var varInfo))
                    {
                        if (varInfo.TypeDescriptor.IsString())
                        {
                            return(new ApiMethodBuilderRawResult(new ExpressionResult(
                                                                     TypeDescriptor,
                                                                     $"${{#{varInfo.AccessName}}}",
                                                                     variableAccessStatement
                                                                     )));
                        }

                        throw new TypeMismatchCompilerException(varInfo.TypeDescriptor, TypeDescriptor.String,
                                                                variableAccessStatement.Info);
                    }

                    if (p.Scope.TryGetConstantInfo(variableAccessStatement, out var constInfo))
                    {
                        return(InlineConstant(constInfo.TypeDescriptor, constInfo.Value, variableAccessStatement));
                    }

                    throw new IdentifierNotFoundCompilerException(variableAccessStatement);
                }

                default:
                {
                    return(WriteNativeMethod(this, p, "echo ${#1}", _functionInfo,
                                             functionCallStatement.Parameters, functionCallStatement.Info));
                }
                }
            }
Ejemplo n.º 12
0
            public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                                          FunctionCallStatement functionCallStatement)
            {
                AssertParameters(p, functionCallStatement.Parameters);

                var number = functionCallStatement.Parameters[0];

                switch (number)
                {
                case ConstantValueStatement constantValueStatement:
                {
                    return(InlineConstant(constantValueStatement.TypeDescriptor, constantValueStatement.Value,
                                          constantValueStatement));
                }

                case VariableAccessStatement variableAccessStatement:
                {
                    if (p.Scope.TryGetVariableInfo(variableAccessStatement, out var varInfo))
                    {
                        if (varInfo.TypeDescriptor.IsString())
                        {
                            return(new ApiMethodBuilderRawResult(new ExpressionResult(
                                                                     TypeDescriptor,
                                                                     $"[[ -z ${{{varInfo.AccessName}// }} ]]",
                                                                     variableAccessStatement
                                                                     )));
                        }
                    }
                    else if (p.Scope.TryGetConstantInfo(variableAccessStatement, out var constInfo))
                    {
                        return(InlineConstant(constInfo.TypeDescriptor, constInfo.Value, variableAccessStatement));
                    }

                    throw new IdentifierNotFoundCompilerException(variableAccessStatement);
                }

                default:
                {
                    throw new NotImplementedException();
                }
                }
            }
        public static FunctionInfo GetFunctionInfoFromFunctionCall(Context context, Scope scope,
                                                                   FunctionCallStatement functionCallStatement, out ILanguageObjectInfo sourceObjectInfo)
        {
            if (!scope.TryGetFunctionInfo(functionCallStatement, out var funcInfo) &&
                !scope.TryGetPrototypeInfo(functionCallStatement, out funcInfo))
            {
                if (!scope.TryGetVariableInfo(functionCallStatement, out var variableInfo))
                {
                    throw new IdentifierNotFoundCompilerException(functionCallStatement.Fqn,
                                                                  functionCallStatement.Info);
                }

                sourceObjectInfo = variableInfo;

                var type = variableInfo.TypeDescriptor;

                if (type.DataType != DataTypes.Delegate &&
                    type.DataType != DataTypes.Lookup ||
                    type.Lookup == null)
                {
                    throw new InvalidStatementStructureCompilerException(functionCallStatement.Fqn,
                                                                         functionCallStatement.Info);
                }

                var lookup = type.Lookup.Value;

                if (!scope.TryGetFunctionInfo(lookup.ClassName, lookup.Name, out funcInfo) &&
                    !scope.TryGetPrototypeInfo(lookup.ClassName, lookup.Name, out funcInfo))
                {
                    throw new InvalidStatementStructureCompilerException(functionCallStatement.Fqn,
                                                                         functionCallStatement.Info);
                }
            }
            else
            {
                sourceObjectInfo = funcInfo;
            }

            return(funcInfo);
        }
Ejemplo n.º 14
0
            public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                                          FunctionCallStatement functionCallStatement)
            {
                AssertParameters(p, functionCallStatement.Parameters);

                var endpoint = functionCallStatement.Parameters[0];

                p.FormatString = false;

                var transpiler = p.Context.GetEvaluationTranspilerForStatement(endpoint);
                var result     = transpiler.GetExpression(p, endpoint);

                if (!result.TypeDescriptor.IsString())
                {
                    throw ThrowInvalidParameterType(result);
                }

                return(new ApiMethodBuilderRawResult(new ExpressionResult(
                                                         TypeDescriptor,
                                                         $"`ping {result.Expression}`",
                                                         result.Template
                                                         )));
            }
Ejemplo n.º 15
0
            public static IApiMethodBuilderResult BuildHelper(Call call, ExpressionBuilderParams p,
                                                              FunctionCallStatement functionCallStatement)
            {
                call.AssertParameters(p, functionCallStatement.Parameters);

                var parameter = functionCallStatement.Parameters[0];

                p.FormatString = false;

                var transpiler = p.Context.GetEvaluationTranspilerForStatement(parameter);
                var result     = transpiler.GetExpression(p, parameter);

                if (!result.TypeDescriptor.IsString())
                {
                    throw ThrowInvalidParameterType(result);
                }

                return(new ApiMethodBuilderRawResult(new ExpressionResult(
                                                         call.TypeDescriptor,
                                                         $"`{result.Expression}`",
                                                         result.Template
                                                         )));
            }
Ejemplo n.º 16
0
            public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                                          FunctionCallStatement functionCallStatement)
            {
                AssertParameters(p, functionCallStatement.Parameters);

                var p0 = functionCallStatement.Parameters[0];
                var p1 = functionCallStatement.Parameters[1];

                if (!(p0 is VariableAccessStatement destination))
                {
                    throw new InvalidStatementStructureCompilerException(p0, p0.Info);
                }

                if (!p.Scope.TryGetVariableInfo(destination, out var dstInfo))
                {
                    throw new IdentifierNotFoundCompilerException(destination);
                }

                var dstVarName = destination.VariableName;


                if (p1 is ArrayStatement arrayStatement)
                {
                    var elements        = arrayStatement.Elements;
                    var elementsResults = new List <string>(elements.Length);

                    foreach (var elem in elements)
                    {
                        var transpiler = p.Context.GetEvaluationTranspilerForStatement(elem);

                        var result = transpiler.GetExpression(p, elem);

                        elementsResults.Add(result.Expression);
                    }

                    if ((elementsResults.Sum(s => s.Length + 2) + dstVarName.Length + 3) <=
                        p.Context.Flags.ArrayManipulationColumnCount)
                    {
                        p.NonInlinePartWriter.Write(dstVarName);
                        p.NonInlinePartWriter.Write("=(");
                        p.NonInlinePartWriter.Write(string.Join(' ', elementsResults));
                        p.NonInlinePartWriter.WriteLine(")");
                    }
                    else
                    {
                        for (int i = 0; i < elementsResults.Count; i++)
                        {
                            p.NonInlinePartWriter.Write(dstVarName);
                            p.NonInlinePartWriter.Write('[');
                            p.NonInlinePartWriter.Write(i);
                            p.NonInlinePartWriter.Write("]=");
                            p.NonInlinePartWriter.WriteLine(elementsResults[i]);
                        }
                    }
                }
                else if (p1 is VariableAccessStatement source)
                {
                    if (!p.Scope.TryGetVariableInfo(source, out var srcInfo))
                    {
                        throw new IdentifierNotFoundCompilerException(source);
                    }

                    var srcVarName = source.VariableName;

                    var isQuoteNeeded = srcInfo.TypeDescriptor.IsString();

                    //for i in ${!a[@]}; do
                    //    b[$i]="${a[$i]}"
                    //done

                    //for i in ${!a[@]}; do
                    p.NonInlinePartWriter.Write("for i in ${!");
                    p.NonInlinePartWriter.Write(srcVarName);
                    p.NonInlinePartWriter.WriteLine("[@]}; do");

                    //b[$i]="${a[$i]}"
                    p.NonInlinePartWriter.Write(dstVarName);
                    if (isQuoteNeeded)
                    {
                        p.NonInlinePartWriter.Write("[$i]=\"${");
                    }
                    else
                    {
                        p.NonInlinePartWriter.Write("[$i]=${");
                    }

                    p.NonInlinePartWriter.Write(srcVarName);
                    if (isQuoteNeeded)
                    {
                        p.NonInlinePartWriter.Write("[$i]}\"");
                    }
                    else
                    {
                        p.NonInlinePartWriter.Write("[$i]}");
                    }

                    p.NonInlinePartWriter.WriteLine();
                    p.NonInlinePartWriter.WriteLine("done");
                }
                else if (p1 is FunctionCallStatement funcCallStatement)
                {
                    if (!p.Scope.TryGetFunctionInfo(funcCallStatement, out var funcInfo))
                    {
                        throw new IdentifierNotFoundCompilerException(funcCallStatement);
                    }

                    var transpiler = p.Context.GetTranspilerForStatement(funcCallStatement);

                    var srcVarName =
                        p.Context.GetLastFunctionCallStorageVariable(funcInfo.TypeDescriptor, p.MetaWriter);

                    var isQuoteNeeded = funcInfo.TypeDescriptor.IsString();

                    //for i in ${!a[@]}; do
                    //    b[$i]="${a[$i]}"
                    //done

                    //p.NonInlineP
                    //artWriter.Write(funcInfo.AccessName);

                    transpiler.WriteBlock(p.Context, p.Scope, p.NonInlinePartWriter, p.MetaWriter, funcCallStatement);

                    //for i in ${!a[@]}; do
                    p.NonInlinePartWriter.Write("for i in ${!");
                    p.NonInlinePartWriter.Write(srcVarName);
                    p.NonInlinePartWriter.WriteLine("[@]}; do");

                    //b[$i]="${a[$i]}"
                    p.NonInlinePartWriter.Write(dstVarName);
                    if (isQuoteNeeded)
                    {
                        p.NonInlinePartWriter.Write("[$i]=\"${");
                    }
                    else
                    {
                        p.NonInlinePartWriter.Write("[$i]=${");
                    }

                    p.NonInlinePartWriter.Write(srcVarName);
                    if (isQuoteNeeded)
                    {
                        p.NonInlinePartWriter.Write("[$i]}\"");
                    }
                    else
                    {
                        p.NonInlinePartWriter.Write("[$i]}");
                    }

                    p.NonInlinePartWriter.WriteLine();
                    p.NonInlinePartWriter.WriteLine("done");
                }
                else
                {
                    throw new InvalidStatementStructureCompilerException(p1, p1.Info);
                }

                return(new ApiMethodBuilderRawResult(new ExpressionResult(TypeDescriptor.Void, null, null,
                                                                          new IExpressionNotice[] { new PinRequiredNotice() })));
            }
 public IdentifierNotFoundCompilerException(FunctionCallStatement functionCallStatement)
     : base(CreateMessage(functionCallStatement.Fqn, functionCallStatement.Info), functionCallStatement.Info)
 {
 }
Ejemplo n.º 18
0
 public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                               FunctionCallStatement functionCallStatement)
 {
     return(CompileResourceMethod(this, p, ResourceName, _functionInfo, functionCallStatement.Parameters,
                                  functionCallStatement.Info));
 }
        public static bool ReplaceEvaluation(IStatement statement,
                                             Predicate <string> predicate, Func <string, EvaluationStatement> replace, out IStatement result)
        {
            switch (statement)
            {
            case ConstantValueStatement _:
            {
                result = statement;
                return(false);
            }

            case VariableAccessStatement variableAccessStatement:
            {
                if (predicate(variableAccessStatement.VariableName))
                {
                    var replaceValue = replace(variableAccessStatement.VariableName);
                    replaceValue.ParentStatement = variableAccessStatement.ParentStatement;

                    result = replaceValue;
                    return(true);
                }

                result = variableAccessStatement;
                return(false);
            }

            case BitwiseEvaluationStatement bitwiseEvaluationStatement:
            {
                if (bitwiseEvaluationStatement.Operator is BitwiseNotOperator bitwiseNotOperator)
                {
                    if (ReplaceEvaluation(bitwiseEvaluationStatement.Right, predicate, replace,
                                          out var right))
                    {
                        result = BitwiseEvaluationStatement.CreateNot(bitwiseNotOperator,
                                                                      (EvaluationStatement)right, bitwiseEvaluationStatement.Info,
                                                                      bitwiseEvaluationStatement.ParentStatement);
                        return(true);
                    }
                }
                else
                {
                    if (ReplaceEvaluation(bitwiseEvaluationStatement.Left, predicate, replace,
                                          out var left) |
                        ReplaceEvaluation(bitwiseEvaluationStatement.Right, predicate, replace,
                                          out var right))
                    {
                        result = new BitwiseEvaluationStatement((EvaluationStatement)left,
                                                                bitwiseEvaluationStatement.Operator, (EvaluationStatement)right,
                                                                bitwiseEvaluationStatement.Info, bitwiseEvaluationStatement.ParentStatement);
                        return(true);
                    }
                }

                break;
            }

            case LogicalEvaluationStatement logicalEvaluationStatement:
            {
                if (logicalEvaluationStatement.Operator is NotOperator logicalNotOperator)
                {
                    if (ReplaceEvaluation(logicalEvaluationStatement.Right, predicate, replace,
                                          out var right))
                    {
                        result = LogicalEvaluationStatement.CreateNot(logicalNotOperator,
                                                                      (EvaluationStatement)right, logicalEvaluationStatement.Info,
                                                                      logicalEvaluationStatement.ParentStatement);
                        return(true);
                    }
                }
                else
                {
                    if (ReplaceEvaluation(logicalEvaluationStatement.Left, predicate, replace,
                                          out var left) |
                        ReplaceEvaluation(logicalEvaluationStatement.Right, predicate, replace,
                                          out var right))
                    {
                        result = new LogicalEvaluationStatement((EvaluationStatement)left,
                                                                logicalEvaluationStatement.Operator, (EvaluationStatement)right,
                                                                logicalEvaluationStatement.Info, logicalEvaluationStatement.ParentStatement);
                        return(true);
                    }
                }

                break;
            }

            case ArithmeticEvaluationStatement arithmeticEvaluationStatement:
            {
                switch (arithmeticEvaluationStatement.Operator)
                {
                case NegativeNumberOperator negativeNumberOperator:
                {
                    if (ReplaceEvaluation(arithmeticEvaluationStatement.Right, predicate, replace,
                                          out var right))
                    {
                        result = ArithmeticEvaluationStatement.CreateNegate(negativeNumberOperator,
                                                                            (EvaluationStatement)right, arithmeticEvaluationStatement.Info,
                                                                            arithmeticEvaluationStatement.ParentStatement);
                        return(true);
                    }

                    break;
                }

                case IncrementOperator _:
                case DecrementOperator _:
                {
                    EvaluationStatement operand;
                    bool isPostfix;
                    if (arithmeticEvaluationStatement.Left == null)
                    {
                        operand   = arithmeticEvaluationStatement.Right;
                        isPostfix = false;
                    }
                    else if (arithmeticEvaluationStatement.Right == null)
                    {
                        operand   = arithmeticEvaluationStatement.Left;
                        isPostfix = true;
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }

                    if (ReplaceEvaluation(operand, predicate, replace, out var replacedOperand))
                    {
                        result = isPostfix
                                    ? ArithmeticEvaluationStatement.CreatePostfix(
                            arithmeticEvaluationStatement.Operator, (EvaluationStatement)replacedOperand,
                            arithmeticEvaluationStatement.Info,
                            arithmeticEvaluationStatement.ParentStatement)
                                    : ArithmeticEvaluationStatement.CreatePrefix(arithmeticEvaluationStatement.Operator,
                                                                                 (EvaluationStatement)replacedOperand, arithmeticEvaluationStatement.Info,
                                                                                 arithmeticEvaluationStatement.ParentStatement);
                        return(true);
                    }

                    break;
                }

                default:
                {
                    if (ReplaceEvaluation(arithmeticEvaluationStatement.Left, predicate, replace,
                                          out var left) |
                        ReplaceEvaluation(arithmeticEvaluationStatement.Right, predicate, replace,
                                          out var right))
                    {
                        result = new ArithmeticEvaluationStatement((EvaluationStatement)left,
                                                                   arithmeticEvaluationStatement.Operator, (EvaluationStatement)right,
                                                                   arithmeticEvaluationStatement.Info, arithmeticEvaluationStatement.ParentStatement);
                        return(true);
                    }

                    break;
                }
                }

                break;
            }

            case TypeCastStatement typeCastStatement:
            {
                if (ReplaceEvaluation(typeCastStatement.Target, predicate, replace, out var right))
                {
                    result = new TypeCastStatement(typeCastStatement.TypeDescriptor, (EvaluationStatement)right,
                                                   typeCastStatement.Info, typeCastStatement.ParentStatement);
                    return(true);
                }

                break;
            }

            case AssignmentStatement assignmentStatement:
            {
                if (ReplaceEvaluation(assignmentStatement.LeftSide, predicate, replace, out var left) |
                    ReplaceEvaluation(assignmentStatement.RightSide, predicate, replace, out var right))
                {
                    result = new AssignmentStatement((EvaluationStatement)left, (EvaluationStatement)right,
                                                     assignmentStatement.Info, assignmentStatement.ParentStatement);
                    return(true);
                }

                break;
            }

            case IndexerOperator indexerOperator:
            {
                throw new NotImplementedException();
            }

            case ArrayStatement arrayStatement:
            {
                throw new NotImplementedException();
            }

            case FunctionCallStatement functionCallStatement:
            {
                var parameters = functionCallStatement.Parameters;
                if (parameters != null)
                {
                    var isReplaced    = false;
                    var newParameters = new EvaluationStatement[parameters.Length];

                    for (var i = 0; i < parameters.Length; i++)
                    {
                        if (ReplaceEvaluation(parameters[i], predicate, replace, out var newP))
                        {
                            newParameters[i] = (EvaluationStatement)newP;
                            isReplaced       = true;
                        }
                    }

                    if (isReplaced)
                    {
                        result = new FunctionCallStatement(functionCallStatement.ClassName,
                                                           functionCallStatement.FunctionName, functionCallStatement.TypeDescriptor, newParameters,
                                                           functionCallStatement.Info, functionCallStatement.ParentStatement);
                        return(true);
                    }
                }

                break;
            }

            case EchoStatement echoStatement:
            {
                var parameters = echoStatement.Parameters;
                if (parameters != null)
                {
                    var isReplaced    = false;
                    var newParameters = new EvaluationStatement[parameters.Length];

                    for (var i = 0; i < parameters.Length; i++)
                    {
                        if (ReplaceEvaluation(parameters[i], predicate, replace, out var newP))
                        {
                            newParameters[i] = (EvaluationStatement)newP;
                            isReplaced       = true;
                        }
                    }

                    if (isReplaced)
                    {
                        result = new EchoStatement(newParameters, echoStatement.Info);
                        return(true);
                    }
                }

                break;
            }

            case ForStatement forStatement:
            {
                throw new NotImplementedException();
            }

            case ForEachStatement forEachStatement:
            {
                throw new NotImplementedException();
            }

            case WhileStatement whileStatement:
            {
                throw new NotImplementedException();
            }

            case DoWhileStatement doWhileStatement:
            {
                throw new NotImplementedException();
            }

            case ConditionalBlockStatement conditionalBlockStatement:
            {
                if (ReplaceEvaluation(conditionalBlockStatement.Condition, predicate, replace,
                                      out var condition) |
                    ReplaceEvaluation(conditionalBlockStatement.Statement, predicate, replace,
                                      out var stt))
                {
                    result = new ConditionalBlockStatement((EvaluationStatement)condition, stt,
                                                           conditionalBlockStatement.Info);
                    return(true);
                }

                break;
            }

            case IfElseStatement ifElseStatement:
            {
                var isChanged = ReplaceEvaluation(ifElseStatement.MainIf, predicate, replace,
                                                  out var mainIf);

                var elseIfs = new List <ConditionalBlockStatement>();

                if (ifElseStatement.ElseIfs != null && ifElseStatement.ElseIfs.Length > 0)
                {
                    foreach (var ei in ifElseStatement.ElseIfs)
                    {
                        isChanged |= ReplaceEvaluation(ei, predicate, replace,
                                                       out var newEi);

                        elseIfs.Add((ConditionalBlockStatement)newEi);
                    }
                }

                IStatement newElse = null;

                if (ifElseStatement.Else != null)
                {
                    isChanged |= ReplaceEvaluation(ifElseStatement.Else, predicate, replace,
                                                   out newElse);
                }

                if (isChanged)
                {
                    result = new IfElseStatement((ConditionalBlockStatement)mainIf,
                                                 elseIfs.Count == 0 ? null : elseIfs.ToArray(), newElse, ifElseStatement.Info);
                    return(true);
                }

                break;
            }

            case ReturnStatement returnStatement:
            {
                if (ReplaceEvaluation(returnStatement.Result, predicate, replace, out var newResult))
                {
                    result = new ReturnStatement((EvaluationStatement)newResult, returnStatement.Info);
                    return(true);
                }

                break;
            }

            case VariableDefinitionStatement variableDefinitionStatement:
            {
                if (variableDefinitionStatement.DefaultValue != null &&
                    ReplaceEvaluation(variableDefinitionStatement.DefaultValue, predicate, replace,
                                      out var newResult))
                {
                    result = new VariableDefinitionStatement(variableDefinitionStatement.TypeDescriptor,
                                                             variableDefinitionStatement.Name, variableDefinitionStatement.IsConstant,
                                                             (EvaluationStatement)newResult, variableDefinitionStatement.Info);
                    return(true);
                }

                break;
            }

            case SwitchCaseStatement switchCaseStatement:
            {
                var isChanged = ReplaceEvaluation(switchCaseStatement.SwitchTarget, predicate, replace,
                                                  out var switchTarget);

                var cases = new List <ConditionalBlockStatement>();
                if (switchCaseStatement.Cases != null && switchCaseStatement.Cases.Length > 0)
                {
                    foreach (var sCase in switchCaseStatement.Cases)
                    {
                        isChanged |= ReplaceEvaluation(sCase, predicate, replace,
                                                       out var newCase);
                        cases.Add((ConditionalBlockStatement)newCase);
                    }
                }

                IStatement newDefaultCase = null;

                if (switchCaseStatement.DefaultCase != null)
                {
                    isChanged |= ReplaceEvaluation(switchCaseStatement.DefaultCase, predicate, replace,
                                                   out newDefaultCase);
                }

                if (isChanged)
                {
                    result = new SwitchCaseStatement((EvaluationStatement)switchTarget,
                                                     cases.Count == 0 ? null : cases.ToArray(), newDefaultCase, switchCaseStatement.Info);
                    return(true);
                }

                break;
            }

            case BlockStatement blockStatement:
            {
                var isChanged  = false;
                var statements = new List <IStatement>();
                foreach (var stt in blockStatement.Statements)
                {
                    isChanged |= ReplaceEvaluation(stt, predicate, replace,
                                                   out var newStt);
                    statements.Add(newStt);
                }

                if (isChanged)
                {
                    result = new BlockStatement(statements.ToArray(), blockStatement.Info);
                    return(true);
                }

                break;
            }
            }

            result = statement;
            return(false);
        }
Ejemplo n.º 20
0
 public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                               FunctionCallStatement functionCallStatement)
 {
     throw new System.NotImplementedException();
 }
 public static EvaluationStatement GetSchemeParameterValueByIndex(Context context, Scope scope,
                                                                  FunctionInfo functionInfo, FunctionCallStatement functionCallStatement, int index)
 {
     return(functionCallStatement.Parameters[index]);
 }
 /// <summary>
 /// Validates the function call by using a schema (<param name="funcInfo">funcInfo</param>).
 /// </summary>
 /// <param name="context"></param>
 /// <param name="scope"></param>
 /// <param name="funcInfo"></param>
 /// <param name="functionCallStatement"></param>
 /// <param name="exception"></param>
 /// <returns></returns>
 public static bool ValidateFunctionCall(Context context, Scope scope, FunctionInfo funcInfo,
                                         FunctionCallStatement functionCallStatement, out Exception exception)
 {
     return(ValidateParameters(context, scope, funcInfo.Parameters, functionCallStatement.Parameters,
                               out exception));
 }
Ejemplo n.º 23
0
 public abstract IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                               FunctionCallStatement functionCallStatement);
Ejemplo n.º 24
0
 public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                               FunctionCallStatement functionCallStatement) => BashCall.BuildHelper(this, p, functionCallStatement);
Ejemplo n.º 25
0
 public override IApiMethodBuilderResult Build(ExpressionBuilderParams p,
                                               FunctionCallStatement functionCallStatement)
 {
     return(BashTestCommand.CreateTestExpression(this, p, functionCallStatement, "z"));
 }