• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "lexer/token.h"
10 
11 #include <unordered_map>
12 
13 #include "util/common.h"
14 #include "util/file.h"
15 #include "util/string_builder.h"
16 #include "util/string_helper.h"
17 
18 namespace OHOS {
19 namespace HDI {
Dump()20 std::string Token::Dump()
21 {
22     StringBuilder sb;
23     sb.AppendFormat("{kind:%u, row:%u, col:%u, value:%s}",
24         static_cast<size_t>(kind), location.row, location.col, value.c_str());
25     return sb.ToString();
26 }
27 
LocInfo(const Token & token)28 std::string LocInfo(const Token &token)
29 {
30     size_t index = token.location.filePath.rfind(SEPARATOR);
31     std::string fileName =
32         (index == std::string::npos) ? token.location.filePath : token.location.filePath.substr(index + 1);
33     return StringHelper::Format("%s:%zu:%zu", fileName.c_str(), token.location.row, token.location.col);
34 }
35 } // namespace HDI
36 } // namespace OHOS