public override PinnedVariableResult PinFloatingPointExpressionToVariable(
            ExpressionBuilderParams p,
            TypeDescriptor typeDescriptor,
            string nameHint,
            string expression,
            EvaluationStatement template)
        {
            var variableName = p.Scope.NewHelperVariable(typeDescriptor, nameHint);

            expression = $"`awk \"BEGIN {{print ({expression})}}\"`";

            BashVariableDefinitionStatementTranspiler.WriteVariableDefinition(
                p.Context,
                p.Scope,
                p.NonInlinePartWriter,
                variableName,
                expression
                );

            template = new VariableAccessStatement(variableName, template.Info);

            return(new PinnedVariableResult(
                       typeDescriptor,
                       variableName,
                       FormatVariableAccessExpression(p,
                                                      typeDescriptor,
                                                      variableName,
                                                      template
                                                      ),
                       template));
        }
Example #2
0
        public static string GetUtilityLookupTestVariableName(Context context, TextWriter metaWriter,
                                                              IThirdPartyUtility utility)
        {
            var utilName = utility.Name;

            if (UtilitiesLookupTestVariableName.TryGetValue(utilName, out var name))
            {
                return($"${name} -ne 0");
            }

            var condition = utility.WriteExistenceCondition(context, metaWriter);

            metaWriter.WriteLine($"if [ {condition} ]");
            metaWriter.WriteLine("then");

            name = context.GeneralScope.NewHelperVariable(TypeDescriptor.Boolean, $"{utilName}_existence");
            BashVariableDefinitionStatementTranspiler.WriteVariableDefinition(context, context.GeneralScope, metaWriter,
                                                                              name, "1");

            metaWriter.WriteLine("else");

            BashVariableDefinitionStatementTranspiler.WriteVariableDefinition(context, context.GeneralScope, metaWriter,
                                                                              name, "0");

            metaWriter.WriteLine("fi");

            return($"${name} -ne 0");
        }
        public override PinnedVariableResult PinExpressionToVariable(ExpressionBuilderParams p, string nameHint,
                                                                     ExpressionResult result)
        {
            var variableName = p.Scope.NewHelperVariable(result.TypeDescriptor, nameHint);

            BashVariableDefinitionStatementTranspiler.WriteVariableDefinition(
                p.Context,
                p.Scope,
                p.NonInlinePartWriter,
                variableName,
                result.Expression
                );

            var template = new VariableAccessStatement(variableName, result.Template.Info);

            return(new PinnedVariableResult(
                       result.TypeDescriptor,
                       variableName,
                       FormatVariableAccessExpression(p,
                                                      result.TypeDescriptor,
                                                      variableName,
                                                      template
                                                      ),
                       template));
        }
Example #4
0
        public string GetLastFunctionCallStorageVariable(TypeDescriptor typeDescriptor, TextWriter metaTextWriter)
        {
            const string VariableName = "LastFunctionCall";

            var existed = GeneralScope.ReserveOrUpdateNewVariable(typeDescriptor, VariableName);

            if (!existed)
            {
                BashVariableDefinitionStatementTranspiler.WriteVariableDefinition(this, GeneralScope, metaTextWriter,
                                                                                  VariableName, "0");
            }

            return(VariableName);
        }