Beispiel #1
0
        private static EvaluationResult Relocate(Context context, AbsolutePath receiver, EvaluationResult[] args, EvaluationStackFrame captures)
        {
            var pathTable = context.FrontEndContext.PathTable;

            Args.AsPathOrDirectory(args, 0, out AbsolutePath sourceContainer, out DirectoryArtifact sourceDirContainer);
            sourceContainer = sourceDirContainer.IsValid ? sourceDirContainer.Path : sourceContainer;

            if (!receiver.IsWithin(pathTable, sourceContainer))
            {
                string message = string.Format(CultureInfo.CurrentCulture, $"Relocated path '{receiver.ToString(pathTable)}' is not inside the relocation source '{sourceContainer.ToString(pathTable)}'");
                throw new InvalidPathOperationException(message, new ErrorContext(pos: 1));
            }

            Args.AsPathOrDirectory(args, 1, out AbsolutePath targetContainer, out DirectoryArtifact targetDirContainer);
            targetContainer = targetDirContainer.IsValid ? targetDirContainer.Path : targetContainer;

            object newExtension = Args.AsIs(args, 2);

            AbsolutePath result;

            if (newExtension == UndefinedValue.Instance)
            {
                result = receiver.Relocate(pathTable, sourceContainer, targetContainer);
            }
            else
            {
                var      stringTable = context.FrontEndContext.StringTable;
                PathAtom newExt      = Converter.ExpectPathAtomFromStringOrPathAtom(stringTable, args[2], new ConversionContext(pos: 3));

                result = receiver.Relocate(pathTable, sourceContainer, targetContainer, newExt);
            }

            return(result.IsValid ? EvaluationResult.Create(result) : EvaluationResult.Undefined);
        }