Example #1
0
        public static AphidPreprocessorDirectiveMutator Create()
        {
            AphidPreprocessorDirectiveMutator aphidPreprocessorDirectiveMutator
                = new AphidPreprocessorDirectiveMutator();

            return(aphidPreprocessorDirectiveMutator);

            // TODO: Edit factory method of AphidPreprocessorDirectiveMutator
            // This method should be able to configure the object in all possible ways.
            // Add as many parameters as needed,
            // and assign their values to each field by using the API.
        }
Example #2
0
        protected override List <AphidExpression> MutateCore(AphidExpression expression, out bool hasChanged)
        {
            LoadScriptExpression loadExp;
            AphidExpression      scriptExp;

            if (expression.Type != AphidExpressionType.LoadScriptExpression)
            {
                hasChanged = false;

                return(null);
            }
            else if ((loadExp = (LoadScriptExpression)expression).FileExpression.Type !=
                     AphidExpressionType.StringExpression)
            {
                var constantFolder = new ConstantFoldingMutator();
                var mutated        = constantFolder.Mutate(new List <AphidExpression> {
                    loadExp.FileExpression
                });

                if (mutated.Count != 1 || (scriptExp = mutated[0]).Type != AphidExpressionType.StringExpression)
                {
                    hasChanged = false;

                    return(null);
                    //throw new AphidParserException("Invalid load script operand", loadExp);
                }
            }
            else
            {
                scriptExp = loadExp.FileExpression;
            }

            var scriptStr = StringParser.Parse(((StringExpression)scriptExp).Value);

            var script = Loader.FindScriptFile(_applicationDirectory, scriptStr);

            if (!File.Exists(script))
            {
                throw new AphidParserException(
                          string.Format(
                              "Could not find script {0}",
                              scriptStr),
                          scriptExp);
            }

            Included.Add(script);

            List <AphidExpression> ast;

            if (AphidConfig.Current.ScriptCaching && !DisableCaching)
            {
                AphidByteCodeCache cache;

                if (UseImplicitReturns)
                {
                    cache = new AphidByteCodeCache(Loader.SearchPaths.ToArray());
                }
                else
                {
                    cache = new AphidByteCodeCache(Loader.SearchPaths.ToArray(), 0x1);
                }

                ast = cache.Read(script, out var cacheSources);

                for (var i = 0; i < cacheSources.Length; i++)
                {
                    Included.Add(cacheSources[i].Name);
                }
            }
            else
            {
                var code = AphidScript.Read(script);
                ast = AphidParser.Parse(code, script, useImplicitReturns: UseImplicitReturns);
            }

            if (PerformCommonTransformations)
            {
                var mutatedAst = new PartialOperatorMutator().Mutate(ast);
                mutatedAst = new AphidMacroMutator().Mutate(mutatedAst);
                mutatedAst = new AphidPreprocessorDirectiveMutator().Mutate(mutatedAst);
                mutatedAst = new ConstantFoldingMutator().Mutate(mutatedAst);
                hasChanged = true;

                return(mutatedAst);
            }

            hasChanged = true;

            return(ast);
        }