|
| 1 | +// Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include <functional> |
| 16 | +#include <sstream> |
| 17 | +#include <stdexcept> |
| 18 | +#include "paddle/ap/include/axpr/abstract_list.h" |
| 19 | +#include "paddle/ap/include/axpr/bool_helper.h" |
| 20 | +#include "paddle/ap/include/axpr/bool_int_double_helper.h" |
| 21 | +#include "paddle/ap/include/axpr/builtin_frame_util.h" |
| 22 | +#include "paddle/ap/include/axpr/builtin_high_order_func_type.h" |
| 23 | +#include "paddle/ap/include/axpr/callable_helper.h" |
| 24 | +#include "paddle/ap/include/axpr/data_value_util.h" |
| 25 | +#include "paddle/ap/include/axpr/exception_method_class.h" |
| 26 | +#include "paddle/ap/include/axpr/interpreter.h" |
| 27 | +#include "paddle/ap/include/axpr/lambda_expr_builder.h" |
| 28 | +#include "paddle/ap/include/axpr/method_class.h" |
| 29 | +#include "paddle/ap/include/axpr/string_util.h" |
| 30 | +#include "paddle/ap/include/axpr/value.h" |
| 31 | +#include "paddle/ap/include/axpr/value_method_class.h" |
| 32 | +#include "paddle/ap/include/fs/builtin_functions.h" |
| 33 | +#include "paddle/ap/include/memory/guard.h" |
| 34 | + |
| 35 | +namespace ap::axpr { |
| 36 | + |
| 37 | +adt::Result<axpr::Value> DirName(const axpr::Value&, |
| 38 | + const std::vector<axpr::Value>& args) { |
| 39 | + ADT_CHECK(args.size() == 1) |
| 40 | + << adt::errors::TypeError{"dirname() takes 1 argument, but " + |
| 41 | + std::to_string(args.size()) + "were given."}; |
| 42 | + ADT_LET_CONST_REF(filepath, args.at(0).template CastTo<std::string>()); |
| 43 | + std::size_t pos = filepath.find_last_of("/\\"); |
| 44 | + if (pos == std::string::npos) return std::string{}; |
| 45 | + return filepath.substr(0, pos); |
| 46 | +} |
| 47 | + |
| 48 | +adt::Result<axpr::Value> BaseName(const axpr::Value&, |
| 49 | + const std::vector<axpr::Value>& args) { |
| 50 | + ADT_CHECK(args.size() == 1) |
| 51 | + << adt::errors::TypeError{"basename() takes 1 argument, but " + |
| 52 | + std::to_string(args.size()) + "were given."}; |
| 53 | + ADT_LET_CONST_REF(filepath, args.at(0).template CastTo<std::string>()); |
| 54 | + std::size_t pos = filepath.find_last_of("/\\"); |
| 55 | + if (pos == std::string::npos) return filepath; |
| 56 | + return filepath.substr(pos + 1); |
| 57 | +} |
| 58 | + |
| 59 | +void ForceLink() {} |
| 60 | + |
| 61 | +} // namespace ap::axpr |
0 commit comments