• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
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 
16 #ifndef ES2PANDA_IR_ETS_IMPORT_DECLARATION_H
17 #define ES2PANDA_IR_ETS_IMPORT_DECLARATION_H
18 
19 #include "ir/module/importDeclaration.h"
20 #include "ir/expressions/literals/stringLiteral.h"
21 #include "util/importPathManager.h"
22 #include "util/language.h"
23 #include "util/ustring.h"
24 
25 namespace ark::es2panda::ir {
26 class StringLiteral;
27 
28 class ETSImportDeclaration : public ImportDeclaration {
29 public:
30     ETSImportDeclaration(ir::StringLiteral *importPath, util::ImportPathManager::ImportMetadata importMetadata,
31                          ArenaVector<AstNode *> &&specifiers, const ImportKinds importKinds = ImportKinds::ALL)
ImportDeclaration(importPath,std::move (specifiers),importKinds)32         : ImportDeclaration(importPath, std::move(specifiers), importKinds), importMetadata_(importMetadata)
33     {
34         SetType(AstNodeType::ETS_IMPORT_DECLARATION);
35     }
36 
37     ETSImportDeclaration(ir::StringLiteral *importPath, ArenaVector<AstNode *> &&specifiers,
38                          const ImportKinds importKinds = ImportKinds::ALL)
ETSImportDeclaration(importPath,util::ImportPathManager::ImportMetadata{},std::move (specifiers),importKinds)39         : ETSImportDeclaration(importPath, util::ImportPathManager::ImportMetadata {}, std::move(specifiers),
40                                importKinds)
41     {
42     }
43 
SetImportMetadata(util::ImportFlags importFlags,Language::Id lang,std::string_view resolvedSource,std::string_view declPath,std::string_view ohmUrl)44     void SetImportMetadata(util::ImportFlags importFlags, Language::Id lang, std::string_view resolvedSource,
45                            std::string_view declPath, std::string_view ohmUrl)
46     {
47         importMetadata_.importFlags = importFlags;
48         importMetadata_.lang = lang;
49         importMetadata_.resolvedSource = resolvedSource;
50         importMetadata_.declPath = declPath;
51         importMetadata_.ohmUrl = ohmUrl;
52     }
53 
Language()54     es2panda::Language Language() const
55     {
56         return es2panda::Language {importMetadata_.lang};
57     }
58 
DeclPath()59     std::string_view DeclPath() const
60     {
61         return importMetadata_.declPath;
62     }
63 
OhmUrl()64     std::string_view OhmUrl() const
65     {
66         return importMetadata_.ohmUrl;
67     }
68 
IsValid()69     bool IsValid() const
70     {
71         return (Source()->Str() != ERROR_LITERAL) && importMetadata_.IsValid();
72     }
73 
IsPureDynamic()74     bool IsPureDynamic() const
75     {
76         return IsValid() && DeclPath().empty() && Language().IsDynamic();
77     }
78 
AssemblerName()79     util::StringView &AssemblerName()
80     {
81         return assemblerName_;
82     }
83 
AssemblerName()84     const util::StringView &AssemblerName() const
85     {
86         return assemblerName_;
87     }
88 
ResolvedSource()89     std::string_view ResolvedSource() const
90     {
91         return importMetadata_.resolvedSource;
92     }
93 
ImportMetadata()94     const auto &ImportMetadata() const
95     {
96         return importMetadata_;
97     }
98 
Accept(ASTVisitorT * v)99     void Accept(ASTVisitorT *v) override
100     {
101         v->Accept(this);
102     }
103 
104 private:
105     util::ImportPathManager::ImportMetadata importMetadata_;
106     util::StringView assemblerName_ {};
107 };
108 }  // namespace ark::es2panda::ir
109 
110 #endif
111