• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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
17typedef (String or f64 or boolean) es2panda_variantDoubleCharArrayBool;
18
19
20[Entity=Class] interface es2panda_Config {};
21[Entity=Class] interface es2panda_Context {};
22[Entity=Class] interface es2panda_Program {};
23[Entity=Class] interface es2panda_ExternalSource {};
24[Entity=Class] interface es2panda_ArkTsConfig {};
25[Entity=Class] interface es2panda_AstNode {};
26[Entity=Class] interface es2panda_FunctionSignature {};
27[Entity=Class] interface es2panda_SourcePosition {};
28[Entity=Class] interface es2panda_SourceRange {};
29[Entity=Class] interface es2panda_SrcDumper {};
30[Entity=Class] interface es2panda_AstDumper {};
31[Entity=Class] interface es2panda_LabelPair {};
32[Entity=Class] interface es2panda_ScriptFunctionData {};
33[Entity=Class] interface es2panda_ImportSource {};
34[Entity=Class] interface es2panda_Signature {};
35[Entity=Class] interface es2panda_SignatureInfo {};
36[Entity=Class] interface es2panda_CheckerContext {};
37[Entity=Class] interface es2panda_ResolveResult {};
38[Entity=Class] interface es2panda_ValidationInfo {};
39[Entity=Class] interface es2panda_Type {};
40[Entity=Class] interface es2panda_TypeRelation {};
41[Entity=Class] interface es2panda_IndexInfo {};
42[Entity=Class] interface es2panda_GlobalTypesHolder {};
43[Entity=Class] interface es2panda_ObjectDescriptor {};
44[Entity=Class] interface es2panda_Variable {};
45[Entity=Class] interface es2panda_Scope {};
46[Entity=Class] interface es2panda_ScopeFindResult {};
47[Entity=Class] interface es2panda_BindingProps {};
48[Entity=Class] interface es2panda_Declaration {};
49[Entity=Class] interface es2panda_RecordTable {};
50[Entity=Class] interface es2panda_BoundContext {};
51[Entity=Class] interface es2panda_AstVisitor {};
52[Entity=Class] interface es2panda_AstVerifier {};
53[Entity=Class] interface es2panda_VerifierMessage {};
54[Entity=Class] interface es2panda_CodeGen {};
55[Entity=Class] interface es2panda_VReg {};
56[Entity=Class] interface es2panda_IRNode {};
57[Entity=Class] interface es2panda_ErrorLogger {};
58[Entity=Class] interface es2panda_VerificationContext {};
59[Entity=Class] interface es2panda_ImportPathManager {};
60[Entity=Class] interface es2panda_Path {};
61[Entity=Class] interface es2panda_Options {};
62
63
64interface NodeTraverser {
65    void Do(ir.AstNode e2p_node);
66};
67
68interface NodeTransformer {
69    ir.AstNode Do(ir.AstNode e2p_node);
70};
71
72interface NodePredicate {
73    boolean Do(ir.AstNode e2p_node);
74};
75
76interface PropertyProcessor {
77    varbinder.Variable Do(varbinder.Variable e2p_variable, checker.Type e2p_type);
78};
79
80interface PropertyTraverser {
81    void Do(varbinder.Variable e2p_variable);
82};
83
84interface ClassBuilder {
85    void Do(sequence<ir.AstNode> e2p_node, u32 size);
86};
87
88interface MethodBuilder {
89    void Do(sequence<ir.Statement> statements, u32 sizeStatements, sequence<ir.Expression> expression,
90        u32 sizeExpression, sequence<checker.Type> e2p_type);
91};
92
93interface ClassInitializerBuilder {
94    void Do(sequence<ir.Statement> statements, u32 sizeStatements, sequence<ir.Expression> expression,
95        u32 sizeExpression);
96};
97
98interface AstNodeForEachFunction {
99    void Do(ir.AstNode node, VoidPtr arg);
100};
101
102interface es2panda_DynamicImportData {
103    attribute ir.ETSImportDeclaration import_node;
104    attribute ir.AstNode specifier;
105    attribute varbinder.Variable variable;
106};
107
108interface es2panda_OverloadInfo {
109    attribute u32 minArg;
110    attribute u32 maxArg;
111    attribute boolean needHelperOverload;
112    attribute boolean isDeclare;
113    attribute boolean hasRestVar;
114    attribute boolean returnVoid;
115};
116
117dictionary es2panda_ContextState {
118    i32 ES2PANDA_STATE_NEW = 0;
119    i32 ES2PANDA_STATE_PARSED = 1;
120    i32 ES2PANDA_STATE_BOUND = 2;
121    i32 ES2PANDA_STATE_CHECKED = 3;
122    i32 ES2PANDA_STATE_LOWERED = 4;
123    i32 ES2PANDA_STATE_ASM_GENERATED = 5;
124    i32 ES2PANDA_STATE_BIN_GENERATED = 6;
125    i32 ES2PANDA_STATE_ERROR = 7;
126};
127
128interface es2panda_SuggestionInfo {
129    attribute es2panda_DiagnosticKind kind;
130    attribute sequence<String> args;
131    attribute u32 argc;
132    attribute String substitutionCode;
133};
134
135interface es2panda_DiagnosticInfo {
136    attribute es2panda_DiagnosticKind kind;
137    attribute sequence<String> args;
138    attribute u32 argc;
139};
140
141dictionary es2panda_PluginDiagnosticType {
142    i32 ES2PANDA_PLUGIN_WARNING = 0;
143    i32 ES2PANDA_PLUGIN_ERROR = 1;
144    i32 ES2PANDA_PLUGIN_SUGGESTION = 2;
145};
146
147[Entity=Class] interface VoidPtr {}; // void *
148
149
150% Enums::enums&.each do |name, enum|
151% if enum.flags.length > 0
152% if enum.flags.length <= 32 || enum.type == "int"
153dictionary Es2panda<%= name %> {
154% enum.all_flags_with_value&.each do |flag_name, value|
155    i32 <%= enum.name_to_upper_snake %>_<%= flag_name %> = <%= value %>;
156% end
157};
158
159% else
160
161typedef u64 Es2panda<%= name %>;
162
163% end
164% end
165% end
166
167
168interface es2panda_Impl {
169    es2panda_Config CreateConfig(i32 argc, sequence<String> argv);
170    void DestroyConfig(es2panda_Config config);
171    String GetAllErrorMessages(es2panda_Context context);
172    es2panda_Options ConfigGetOptions(es2panda_Config config);
173
174    es2panda_Context CreateContextFromFile(es2panda_Config config, String source_file_name);
175    es2panda_Context CreateContextFromString(es2panda_Config config, String source, String file_name);
176    es2panda_Context CreateContextGenerateAbcForExternalSourceFiles(es2panda_Config config, i32 fileNamesCount, sequence<String> fileNames);
177    es2panda_Context ProceedToState(es2panda_Context context, es2panda_ContextState state);  // context is consumed
178    void DestroyContext(es2panda_Context context);
179
180    es2panda_ContextState ContextState(es2panda_Context context);
181    String ContextErrorMessage(es2panda_Context context);
182
183    es2panda_Program ContextProgram(es2panda_Context context);
184    String ExternalSourceName(es2panda_ExternalSource e_source);
185    sequence<es2panda_Program> ExternalSourcePrograms(es2panda_ExternalSource e_source, sequence<u32> len_p);
186
187    void AstNodeForEach(ir.AstNode ast, AstNodeForEachFunction func, VoidPtr arg);
188
189    VoidPtr AllocMemory(es2panda_Context context, u32 numberOfElements, u32 sizeOfElement);
190
191    es2panda_SourcePosition CreateSourcePosition(es2panda_Context context, u32 index, u32 line);
192    es2panda_SourceRange CreateSourceRange(es2panda_Context context, es2panda_SourcePosition start,
193                                               es2panda_SourcePosition end);
194    u32 SourcePositionIndex(es2panda_Context context, es2panda_SourcePosition position);
195    u32 SourcePositionLine(es2panda_Context context, es2panda_SourcePosition position);
196    es2panda_SourcePosition SourceRangeStart(es2panda_Context context, es2panda_SourceRange range);
197    es2panda_SourcePosition SourceRangeEnd(es2panda_Context context, es2panda_SourceRange range);
198    es2panda_DiagnosticInfo CreateDiagnosticInfo(es2panda_Context context, es2panda_DiagnosticKind kind,
199                                        sequence<String> args, u32 argc);
200    es2panda_SuggestionInfo CreateDiagnosticInfo(es2panda_Context context, es2panda_DiagnosticKind kind,
201                                        sequence<String> args, u32 argc, String substitutionCode);
202    void LogDiagnosticWithSuggestion(es2panda_Context context, es2panda_DiagnosticInfo diagnosticInfo,
203                                        es2panda_SuggestionInfo suggestionInfo, es2panda_SourceRange range);
204    void LogTypeError(es2panda_Context context, String errorMsg, es2panda_SourcePosition pos);
205    void LogWarning(es2panda_Context context, String warnMsg, es2panda_SourcePosition pos);
206    void LogSyntaxError(es2panda_Context context, String errorMsg, es2panda_SourcePosition pos);
207    boolean IsAnyError(es2panda_Context context);
208    varbinder.Scope AstNodeFindNearestScope(es2panda_Context ctx, ir.AstNode node);
209    varbinder.Scope AstNodeRebind(es2panda_Context ctx, ir.AstNode node);
210    void AstNodeRecheck(es2panda_Context ctx, ir.AstNode node);
211    Es2pandaEnum Es2pandaEnumFromString(es2panda_Context ctx, String str);
212    String Es2pandaEnumToString(es2panda_Context ctx, Es2pandaEnum id);
213    ir.AstNode DeclarationFromIdentifier(es2panda_Context ctx, ir.Identifier node);
214    ir.AstNode FirstDeclarationByNameFromNode(es2panda_Context ctx, ir.AstNode node, String name);
215    ir.AstNode FirstDeclarationByNameFromProgram(es2panda_Context ctx, es2panda_Program program, String name);
216    sequence<ir.AstNode> AllDeclarationsByNameFromNode(es2panda_Context ctx, ir.AstNode node, String name);
217    sequence<ir.AstNode> AllDeclarationsByNameFromProgram(es2panda_Context ctx, es2panda_Program program, String name);
218    void InsertETSImportDeclarationAndParse(es2panda_Context context, es2panda_Program program,
219                                            ETSImportDeclaration node);
220    i32 GenerateStaticDeclarationsFromContext(es2panda_Context context, String outputPath);
221
222% Es2pandaLibApi::ast_nodes&.each do |ast_node|
223%   if ast_node != 'AstNode' && ast_node != 'TypeNode'
224    boolean Is<%= ast_node %>(ir.AstNode ast);
225%   end
226% end
227
228% Es2pandaLibApi::scopes&.each do |scope|
229%   if scope != 'Scope'
230    boolean ScopeIs<%= scope %>(varbinder.Scope scope);
231%   end
232% end
233
234% Es2pandaLibApi::ast_types&.each do |type|
235%   if type != 'Type'
236    boolean TypeIs<%= type %>(checker.Type type);
237%   end
238% end
239
240% Es2pandaLibApi::ast_variables&.each do |variable|
241%   if variable[1] != 'Variable'
242    boolean VariableIs<%= variable[1] %>(varbinder.Variable variable);
243%   end
244% end
245
246    String AstNodeName(ir.AstNode ast);
247};
248
249
250namespace ir {
251
252% number_literal_ast_node_type = Enums::enums['AstNodeType'].all_flags_with_value['NUMBER_LITERAL']
253[Entity=Class, Es2pandaAstNodeType=<%= number_literal_ast_node_type %>, c_type=es2panda_AstNode] interface NumberLiteral: Literal {
254    ir.AstNode Create(es2panda_Context ctx, i32 value);
255    ir.AstNode Create1(es2panda_Context ctx, i64 value);
256    ir.AstNode Create2(es2panda_Context ctx, f64 value);
257    ir.AstNode Create3(es2panda_Context ctx, f32 value);
258
259    ir.AstNode Update(es2panda_Context ctx, ir.AstNode original, i32 value);
260    ir.AstNode Update1(es2panda_Context ctx, ir.AstNode original, i64 value);
261    ir.AstNode Update2(es2panda_Context ctx, ir.AstNode original, f64 value);
262    ir.AstNode Update3(es2panda_Context ctx, ir.AstNode original, f32 value);
263
264    boolean SetInt(ir.AstNode node, i32 new_value);
265    boolean SetLong(ir.AstNode node, i64 new_value);
266    boolean SetDouble(ir.AstNode node, f64 new_value);
267    boolean SetFloat(ir.AstNode node, f32 new_value);
268
269    [get] String StrConst(es2panda_Context context);
270};
271
272};  // namespace ir
273
274
275% Es2pandaLibApi::classes&.each do |namespaceName, namespaceClasses|
276
277namespace <%= namespaceName %> {
278
279%   namespaceClasses&.each do |className, classData|
280[Entity=Class<%=
281    classData.ast_node_type_value ? ", Es2pandaAstNodeType=#{classData.ast_node_type_value}" : ''
282%><%= classData.class_c_type %>] interface <%= className %><%=
283    ": #{classData.extends_classname}" if classData && classData.extends_classname
284%> {
285%     classData.class_constructors&.each_with_index do |constructor, index|
286%     api_class_type = Es2pandaLibApi::Arg.type_to_idl(classData.constructor_type.idl_type)
287
288    /* <%= constructor['raw_decl'] %> */
289    static <%= api_class_type %> Create<%= constructor['idl_overload'] %>(es2panda_Context context<%=
290    constructor['args']&.map { |arg| if arg.lib_args_to_str.strip != ''
291     then ', ' + arg.lib_args_to_idl end}&.join('')
292%>);
293%       if classData.updater_allowed
294    static <%= api_class_type %> Update<%= constructor['idl_overload'] %>(es2panda_Context context, <%=
295        api_class_type %> original<%=
296    constructor['args']&.map { |arg| if arg.lib_args_to_str.strip != ''
297     then ', ' + arg.lib_args_to_idl end}&.join('')
298%>);
299%       end   # Updater
300%     end    # Constructor
301%     classData.class_methods&.each_with_index do |method_info, index|
302
303    /* <%= method_info['raw_decl'] %> */
304    <%=
305    method_info['get_modifier'] ? "[#{method_info['get_modifier']}] " : ''
306%><%=
307    Es2pandaLibApi::Arg.type_to_idl(method_info['return_type'].idl_type)
308%> <%=method_info['idl_name']%>(es2panda_Context context<%=
309    method_info['args']&.map { |arg| if arg.lib_args_to_str.strip != '' && arg.lib_args_to_str.strip != 'const'
310    then ', ' + arg.lib_args_to_idl end}&.join('')
311%><%=
312    method_info['return_type'].return_args_to_idl
313%>);
314%     end    # Method
315};
316
317%   end    # namespaceClasses
318};  // namespace <%= namespaceName %>
319% end    # classes
320