@idlizer/arktscgen 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/libarkts-copy/generator/options.json5 +155 -0
- package/build/libarkts-copy/native/meson.build +62 -0
- package/build/libarkts-copy/native/meson_options.txt +24 -0
- package/build/libarkts-copy/native/src/bridges.cc +265 -0
- package/build/libarkts-copy/native/src/common.cc +231 -0
- package/build/libarkts-copy/native/src/common.h +39 -0
- package/build/libarkts-copy/native/src/generated/bridges.cc +11979 -0
- package/build/libarkts-copy/package.json +51 -0
- package/build/libarkts-copy/src/Es2pandaEnums.ts +183 -0
- package/build/libarkts-copy/src/Es2pandaNativeModule.ts +123 -0
- package/build/libarkts-copy/src/InteropNativeModule.ts +50 -0
- package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +31 -0
- package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +147 -0
- package/build/libarkts-copy/src/arkts-api/index.ts +28 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/createCallExpression.ts +40 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/createNumberLiteral.ts +28 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/createScriptFunction.ts +55 -0
- package/build/libarkts-copy/src/arkts-api/peers/ArktsObject.ts +45 -0
- package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +121 -0
- package/build/libarkts-copy/src/arkts-api/peers/Config.ts +52 -0
- package/build/libarkts-copy/src/arkts-api/peers/Context.ts +46 -0
- package/build/libarkts-copy/src/arkts-api/peers/Program.ts +55 -0
- package/build/libarkts-copy/src/arkts-api/static/global.ts +67 -0
- package/build/libarkts-copy/src/arkts-api/utilities/nativePtrDecoder.ts +69 -0
- package/build/libarkts-copy/src/arkts-api/utilities/private.ts +156 -0
- package/build/libarkts-copy/src/arkts-api/utilities/public.ts +135 -0
- package/build/libarkts-copy/src/arkts-api/visitor.ts +297 -0
- package/build/libarkts-copy/src/es2panda.ts +277 -0
- package/build/libarkts-copy/src/generated/Es2pandaEnums.ts +1266 -0
- package/build/libarkts-copy/src/generated/Es2pandaNativeModule.ts +3745 -0
- package/build/libarkts-copy/src/generated/factory.ts +1299 -0
- package/build/libarkts-copy/src/generated/index.ts +191 -0
- package/build/libarkts-copy/src/generated/node-map.ts +182 -0
- package/build/libarkts-copy/src/generated/peers/AnnotatedAstNode.ts +39 -0
- package/build/libarkts-copy/src/generated/peers/AnnotatedExpression.ts +49 -0
- package/build/libarkts-copy/src/generated/peers/AnnotatedStatement.ts +40 -0
- package/build/libarkts-copy/src/generated/peers/AnnotationDeclaration.ts +110 -0
- package/build/libarkts-copy/src/generated/peers/AnnotationUsage.ts +74 -0
- package/build/libarkts-copy/src/generated/peers/ArrayExpression.ts +98 -0
- package/build/libarkts-copy/src/generated/peers/ArrowFunctionExpression.ts +70 -0
- package/build/libarkts-copy/src/generated/peers/AssertStatement.ts +57 -0
- package/build/libarkts-copy/src/generated/peers/AssignmentExpression.ts +95 -0
- package/build/libarkts-copy/src/generated/peers/AstDumper.ts +42 -0
- package/build/libarkts-copy/src/generated/peers/AwaitExpression.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/BigIntLiteral.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/BinaryExpression.ts +95 -0
- package/build/libarkts-copy/src/generated/peers/BlockExpression.ts +64 -0
- package/build/libarkts-copy/src/generated/peers/BlockStatement.ts +63 -0
- package/build/libarkts-copy/src/generated/peers/BooleanLiteral.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/BreakStatement.ts +65 -0
- package/build/libarkts-copy/src/generated/peers/CallExpression.ts +97 -0
- package/build/libarkts-copy/src/generated/peers/CatchClause.ts +64 -0
- package/build/libarkts-copy/src/generated/peers/ChainExpression.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/CharLiteral.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/ClassDeclaration.ts +58 -0
- package/build/libarkts-copy/src/generated/peers/ClassDefinition.ts +233 -0
- package/build/libarkts-copy/src/generated/peers/ClassElement.ts +80 -0
- package/build/libarkts-copy/src/generated/peers/ClassExpression.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/ClassProperty.ts +70 -0
- package/build/libarkts-copy/src/generated/peers/ClassStaticBlock.ts +58 -0
- package/build/libarkts-copy/src/generated/peers/ConditionalExpression.ts +74 -0
- package/build/libarkts-copy/src/generated/peers/ContinueStatement.ts +65 -0
- package/build/libarkts-copy/src/generated/peers/DebuggerStatement.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/Decorator.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/DirectEvalExpression.ts +52 -0
- package/build/libarkts-copy/src/generated/peers/DoWhileStatement.ts +58 -0
- package/build/libarkts-copy/src/generated/peers/ETSClassLiteral.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/ETSDynamicFunctionType.ts +40 -0
- package/build/libarkts-copy/src/generated/peers/ETSFunctionType.ts +84 -0
- package/build/libarkts-copy/src/generated/peers/ETSImportDeclaration.ts +68 -0
- package/build/libarkts-copy/src/generated/peers/ETSLaunchExpression.ts +57 -0
- package/build/libarkts-copy/src/generated/peers/ETSModule.ts +71 -0
- package/build/libarkts-copy/src/generated/peers/ETSNewArrayInstanceExpression.ts +62 -0
- package/build/libarkts-copy/src/generated/peers/ETSNewClassInstanceExpression.ts +69 -0
- package/build/libarkts-copy/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts +60 -0
- package/build/libarkts-copy/src/generated/peers/ETSNullType.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/ETSPackageDeclaration.ts +51 -0
- package/build/libarkts-copy/src/generated/peers/ETSParameterExpression.ts +126 -0
- package/build/libarkts-copy/src/generated/peers/ETSPrimitiveType.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/ETSReExportDeclaration.ts +51 -0
- package/build/libarkts-copy/src/generated/peers/ETSStructDeclaration.ts +51 -0
- package/build/libarkts-copy/src/generated/peers/ETSTuple.ts +73 -0
- package/build/libarkts-copy/src/generated/peers/ETSTypeReference.ts +58 -0
- package/build/libarkts-copy/src/generated/peers/ETSTypeReferencePart.ts +68 -0
- package/build/libarkts-copy/src/generated/peers/ETSUndefinedType.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/ETSUnionType.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/ETSWildcardType.ts +55 -0
- package/build/libarkts-copy/src/generated/peers/EmptyStatement.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/ExportAllDeclaration.ts +58 -0
- package/build/libarkts-copy/src/generated/peers/ExportDefaultDeclaration.ts +56 -0
- package/build/libarkts-copy/src/generated/peers/ExportNamedDeclaration.ts +73 -0
- package/build/libarkts-copy/src/generated/peers/ExportSpecifier.ts +57 -0
- package/build/libarkts-copy/src/generated/peers/Expression.ts +75 -0
- package/build/libarkts-copy/src/generated/peers/ExpressionStatement.ts +59 -0
- package/build/libarkts-copy/src/generated/peers/ForInStatement.ts +61 -0
- package/build/libarkts-copy/src/generated/peers/ForOfStatement.ts +64 -0
- package/build/libarkts-copy/src/generated/peers/ForUpdateStatement.ts +61 -0
- package/build/libarkts-copy/src/generated/peers/FunctionDecl.ts +40 -0
- package/build/libarkts-copy/src/generated/peers/FunctionDeclaration.ts +69 -0
- package/build/libarkts-copy/src/generated/peers/FunctionExpression.ts +64 -0
- package/build/libarkts-copy/src/generated/peers/FunctionSignature.ts +62 -0
- package/build/libarkts-copy/src/generated/peers/Identifier.ts +154 -0
- package/build/libarkts-copy/src/generated/peers/IfStatement.ts +65 -0
- package/build/libarkts-copy/src/generated/peers/ImportDeclaration.ts +61 -0
- package/build/libarkts-copy/src/generated/peers/ImportDefaultSpecifier.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/ImportExpression.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/ImportNamespaceSpecifier.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/ImportSource.ts +49 -0
- package/build/libarkts-copy/src/generated/peers/ImportSpecifier.ts +57 -0
- package/build/libarkts-copy/src/generated/peers/InterfaceDecl.ts +40 -0
- package/build/libarkts-copy/src/generated/peers/LabelledStatement.ts +60 -0
- package/build/libarkts-copy/src/generated/peers/Literal.ts +40 -0
- package/build/libarkts-copy/src/generated/peers/LoopStatement.ts +40 -0
- package/build/libarkts-copy/src/generated/peers/MaybeOptionalExpression.ts +48 -0
- package/build/libarkts-copy/src/generated/peers/MemberExpression.ts +95 -0
- package/build/libarkts-copy/src/generated/peers/MetaProperty.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/MethodDefinition.ts +105 -0
- package/build/libarkts-copy/src/generated/peers/NamedType.ts +76 -0
- package/build/libarkts-copy/src/generated/peers/NewExpression.ts +56 -0
- package/build/libarkts-copy/src/generated/peers/NullLiteral.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/NumberLiteral.ts +47 -0
- package/build/libarkts-copy/src/generated/peers/ObjectExpression.ts +90 -0
- package/build/libarkts-copy/src/generated/peers/OmittedExpression.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/OpaqueTypeNode.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/PrefixAssertionExpression.ts +57 -0
- package/build/libarkts-copy/src/generated/peers/Property.ts +82 -0
- package/build/libarkts-copy/src/generated/peers/RegExpLiteral.ts +57 -0
- package/build/libarkts-copy/src/generated/peers/ReturnStatement.ts +62 -0
- package/build/libarkts-copy/src/generated/peers/ScriptFunction.ts +201 -0
- package/build/libarkts-copy/src/generated/peers/SequenceExpression.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/SpreadElement.ts +79 -0
- package/build/libarkts-copy/src/generated/peers/SrcDumper.ts +82 -0
- package/build/libarkts-copy/src/generated/peers/Statement.ts +39 -0
- package/build/libarkts-copy/src/generated/peers/StringLiteral.ts +56 -0
- package/build/libarkts-copy/src/generated/peers/SuperExpression.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/SwitchCaseStatement.ts +62 -0
- package/build/libarkts-copy/src/generated/peers/SwitchStatement.ts +63 -0
- package/build/libarkts-copy/src/generated/peers/TSAnyKeyword.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/TSArrayType.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/TSAsExpression.ts +76 -0
- package/build/libarkts-copy/src/generated/peers/TSBigintKeyword.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/TSBooleanKeyword.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/TSClassImplements.ts +60 -0
- package/build/libarkts-copy/src/generated/peers/TSConditionalType.ts +63 -0
- package/build/libarkts-copy/src/generated/peers/TSConstructorType.ts +65 -0
- package/build/libarkts-copy/src/generated/peers/TSEnumDeclaration.ts +81 -0
- package/build/libarkts-copy/src/generated/peers/TSEnumMember.ts +66 -0
- package/build/libarkts-copy/src/generated/peers/TSExternalModuleReference.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/TSFunctionType.ts +67 -0
- package/build/libarkts-copy/src/generated/peers/TSImportEqualsDeclaration.ts +61 -0
- package/build/libarkts-copy/src/generated/peers/TSImportType.ts +64 -0
- package/build/libarkts-copy/src/generated/peers/TSIndexSignature.ts +65 -0
- package/build/libarkts-copy/src/generated/peers/TSIndexedAccessType.ts +56 -0
- package/build/libarkts-copy/src/generated/peers/TSInferType.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/TSInterfaceBody.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/TSInterfaceDeclaration.ts +102 -0
- package/build/libarkts-copy/src/generated/peers/TSInterfaceHeritage.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/TSIntersectionType.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/TSLiteralType.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/TSMappedType.ts +64 -0
- package/build/libarkts-copy/src/generated/peers/TSMethodSignature.ts +71 -0
- package/build/libarkts-copy/src/generated/peers/TSModuleBlock.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/TSModuleDeclaration.ts +63 -0
- package/build/libarkts-copy/src/generated/peers/TSNamedTupleMember.ts +60 -0
- package/build/libarkts-copy/src/generated/peers/TSNeverKeyword.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/TSNonNullExpression.ts +58 -0
- package/build/libarkts-copy/src/generated/peers/TSNullKeyword.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/TSNumberKeyword.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/TSObjectKeyword.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/TSParameterProperty.ts +66 -0
- package/build/libarkts-copy/src/generated/peers/TSParenthesizedType.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/TSPropertySignature.ts +72 -0
- package/build/libarkts-copy/src/generated/peers/TSQualifiedName.ts +63 -0
- package/build/libarkts-copy/src/generated/peers/TSSignatureDeclaration.ts +67 -0
- package/build/libarkts-copy/src/generated/peers/TSStringKeyword.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/TSThisType.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/TSTupleType.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/TSTypeAliasDeclaration.ts +88 -0
- package/build/libarkts-copy/src/generated/peers/TSTypeAssertion.ts +63 -0
- package/build/libarkts-copy/src/generated/peers/TSTypeLiteral.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/TSTypeOperator.ts +63 -0
- package/build/libarkts-copy/src/generated/peers/TSTypeParameter.ts +84 -0
- package/build/libarkts-copy/src/generated/peers/TSTypeParameterDeclaration.ts +62 -0
- package/build/libarkts-copy/src/generated/peers/TSTypeParameterInstantiation.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/TSTypePredicate.ts +60 -0
- package/build/libarkts-copy/src/generated/peers/TSTypeQuery.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/TSTypeReference.ts +62 -0
- package/build/libarkts-copy/src/generated/peers/TSUndefinedKeyword.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/TSUnionType.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/TSUnknownKeyword.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/TSVoidKeyword.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/TaggedTemplateExpression.ts +61 -0
- package/build/libarkts-copy/src/generated/peers/TemplateElement.ts +59 -0
- package/build/libarkts-copy/src/generated/peers/TemplateLiteral.ts +60 -0
- package/build/libarkts-copy/src/generated/peers/ThisExpression.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/ThrowStatement.ts +54 -0
- package/build/libarkts-copy/src/generated/peers/TryStatement.ts +75 -0
- package/build/libarkts-copy/src/generated/peers/TypeNode.ts +49 -0
- package/build/libarkts-copy/src/generated/peers/TypedAstNode.ts +39 -0
- package/build/libarkts-copy/src/generated/peers/TypedStatement.ts +40 -0
- package/build/libarkts-copy/src/generated/peers/TypeofExpression.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/UnaryExpression.ts +57 -0
- package/build/libarkts-copy/src/generated/peers/UndefinedLiteral.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/UpdateExpression.ts +60 -0
- package/build/libarkts-copy/src/generated/peers/ValidationInfo.ts +42 -0
- package/build/libarkts-copy/src/generated/peers/VariableDeclaration.ts +71 -0
- package/build/libarkts-copy/src/generated/peers/VariableDeclarator.ts +69 -0
- package/build/libarkts-copy/src/generated/peers/WhileStatement.ts +58 -0
- package/build/libarkts-copy/src/generated/peers/YieldExpression.ts +56 -0
- package/build/libarkts-copy/src/reexport-for-generated.ts +33 -0
- package/build/libarkts-copy/src/ts-api/factory/nodeFactory.ts +1375 -0
- package/build/libarkts-copy/src/ts-api/factory/nodeTests.ts +110 -0
- package/build/libarkts-copy/src/ts-api/index.ts +35 -0
- package/build/libarkts-copy/src/ts-api/static/enums.ts +18 -0
- package/build/libarkts-copy/src/ts-api/types.ts +920 -0
- package/build/libarkts-copy/src/ts-api/utilities/private.ts +289 -0
- package/build/libarkts-copy/src/ts-api/utilities/public.ts +55 -0
- package/build/libarkts-copy/src/ts-api/visitor/visitor.ts +155 -0
- package/build/libarkts-copy/src/utils.ts +89 -0
- package/build/libarkts-copy/tsconfig.json +15 -0
- package/lib/index.js +11858 -0
- package/package.json +54 -0
- package/templates/Es2pandaEnums.ts +16 -0
- package/templates/Es2pandaNativeModule.ts +32 -0
- package/templates/bridges.cc +18 -0
- package/templates/factory.ts +34 -0
- package/templates/index.ts +16 -0
- package/templates/node-map.ts +31 -0
- package/templates/peer.ts +32 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022-2023 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
|
+
#include <common.h>
|
|
17
|
+
|
|
18
|
+
using std::string, std::cout, std::endl, std::vector;
|
|
19
|
+
|
|
20
|
+
static es2panda_Impl *impl = nullptr;
|
|
21
|
+
|
|
22
|
+
#ifdef KOALA_WINDOWS
|
|
23
|
+
#include <windows.h>
|
|
24
|
+
#define PLUGIN_DIR "windows_host_tools"
|
|
25
|
+
#define LIB_PREFIX ""
|
|
26
|
+
#define LIB_SUFFIX ".dll"
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#ifdef KOALA_LINUX
|
|
30
|
+
#include <dlfcn.h>
|
|
31
|
+
|
|
32
|
+
#ifdef __x86_64__
|
|
33
|
+
#define PLUGIN_DIR "linux_host_tools"
|
|
34
|
+
#else
|
|
35
|
+
#define PLUGIN_DIR "linux_arm64_host_tools"
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#define LIB_PREFIX "lib"
|
|
39
|
+
#define LIB_SUFFIX ".so"
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
const char* DEFAULT_SDK_PATH = "../../../incremental/tools/panda/node_modules/@panda/sdk" ;
|
|
43
|
+
const char* NAME = LIB_PREFIX "es2panda-public" LIB_SUFFIX;
|
|
44
|
+
|
|
45
|
+
void* FindLibrary() {
|
|
46
|
+
char* envValue = getenv("PANDA_SDK_PATH");
|
|
47
|
+
if (!envValue) {
|
|
48
|
+
std::cout << "PANDA_SDK_PATH not specified, assuming " << DEFAULT_SDK_PATH << std::endl;
|
|
49
|
+
}
|
|
50
|
+
std::string prefix = envValue ? std::string(envValue) : DEFAULT_SDK_PATH;
|
|
51
|
+
std::string libraryName = prefix + ("/" PLUGIN_DIR "/lib/") + NAME;
|
|
52
|
+
return loadLibrary(libraryName);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
es2panda_Impl *GetImpl() {
|
|
56
|
+
if (impl) {
|
|
57
|
+
return impl;
|
|
58
|
+
}
|
|
59
|
+
auto library = FindLibrary();
|
|
60
|
+
if (!library) {
|
|
61
|
+
throw std::runtime_error("No library (es2panda_lib.cc)");
|
|
62
|
+
}
|
|
63
|
+
auto symbol = findSymbol(library, "es2panda_GetImpl");
|
|
64
|
+
if (!symbol) {
|
|
65
|
+
throw std::runtime_error("No entry point");
|
|
66
|
+
}
|
|
67
|
+
impl = reinterpret_cast<es2panda_Impl *(*)(int)>(symbol)(ES2PANDA_LIB_VERSION);
|
|
68
|
+
return impl;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
es2panda_ContextState intToState(KInt state)
|
|
72
|
+
{
|
|
73
|
+
return es2panda_ContextState(state);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
string getString(KStringPtr ptr) {
|
|
77
|
+
return ptr.data();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
char* getStringCopy(KStringPtr& ptr) {
|
|
81
|
+
return strdup(ptr.c_str());
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
inline KUInt unpackUInt(const KByte* bytes) {
|
|
85
|
+
const KUInt BYTE_0 = 0;
|
|
86
|
+
const KUInt BYTE_1 = 1;
|
|
87
|
+
const KUInt BYTE_2 = 2;
|
|
88
|
+
const KUInt BYTE_3 = 3;
|
|
89
|
+
|
|
90
|
+
const KUInt BYTE_1_SHIFT = 8;
|
|
91
|
+
const KUInt BYTE_2_SHIFT = 16;
|
|
92
|
+
const KUInt BYTE_3_SHIFT = 24;
|
|
93
|
+
return (
|
|
94
|
+
bytes[BYTE_0]
|
|
95
|
+
| (bytes[BYTE_1] << BYTE_1_SHIFT)
|
|
96
|
+
| (bytes[BYTE_2] << BYTE_2_SHIFT)
|
|
97
|
+
| (bytes[BYTE_3] << BYTE_3_SHIFT)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
KNativePointer impl_CreateConfig(KInt argc, KStringArray argvPtr) {
|
|
102
|
+
const std::size_t headerLen = 4;
|
|
103
|
+
|
|
104
|
+
const char** argv = new const char*[argc];
|
|
105
|
+
std::size_t position = headerLen;
|
|
106
|
+
std::size_t strLen;
|
|
107
|
+
for (std::size_t i = 0; i < static_cast<std::size_t>(argc); ++i) {
|
|
108
|
+
strLen = unpackUInt(argvPtr + position);
|
|
109
|
+
position += headerLen;
|
|
110
|
+
argv[i] = strdup(std::string(reinterpret_cast<const char*>(argvPtr + position), strLen).c_str());
|
|
111
|
+
position += strLen;
|
|
112
|
+
}
|
|
113
|
+
return GetImpl()->CreateConfig(argc, argv);
|
|
114
|
+
}
|
|
115
|
+
KOALA_INTEROP_2(CreateConfig, KNativePointer, KInt, KStringArray)
|
|
116
|
+
|
|
117
|
+
KNativePointer impl_DestroyConfig(KNativePointer configPtr) {
|
|
118
|
+
auto config = reinterpret_cast<es2panda_Config*>(configPtr);
|
|
119
|
+
GetImpl()->DestroyConfig(config);
|
|
120
|
+
return nullptr;
|
|
121
|
+
}
|
|
122
|
+
KOALA_INTEROP_1(DestroyConfig, KNativePointer, KNativePointer)
|
|
123
|
+
|
|
124
|
+
KNativePointer impl_DestroyContext(KNativePointer contextPtr) {
|
|
125
|
+
auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
|
|
126
|
+
GetImpl()->DestroyContext(context);
|
|
127
|
+
return nullptr;
|
|
128
|
+
}
|
|
129
|
+
KOALA_INTEROP_1(DestroyContext, KNativePointer, KNativePointer)
|
|
130
|
+
|
|
131
|
+
KNativePointer impl_UpdateCallExpression(
|
|
132
|
+
KNativePointer contextPtr,
|
|
133
|
+
KNativePointer nodePtr,
|
|
134
|
+
KNativePointer calleePtr,
|
|
135
|
+
KNativePointerArray argumentsPtr,
|
|
136
|
+
KInt argumentsLen,
|
|
137
|
+
KNativePointer typeParamsPtr,
|
|
138
|
+
KBoolean optionalT,
|
|
139
|
+
KBoolean trailingCommaT
|
|
140
|
+
) {
|
|
141
|
+
auto node = reinterpret_cast<es2panda_AstNode*>(nodePtr);
|
|
142
|
+
auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
|
|
143
|
+
auto callee = reinterpret_cast<es2panda_AstNode*>(calleePtr);
|
|
144
|
+
auto arguments = reinterpret_cast<es2panda_AstNode**>(argumentsPtr);
|
|
145
|
+
auto typeParams = reinterpret_cast<es2panda_AstNode*>(typeParamsPtr);
|
|
146
|
+
auto optional = static_cast<bool>(optionalT);
|
|
147
|
+
auto trailingComma = static_cast<bool>(trailingCommaT);
|
|
148
|
+
|
|
149
|
+
auto nn = GetImpl()->CreateCallExpression(
|
|
150
|
+
context, callee, arguments, argumentsLen, typeParams, optional, trailingComma
|
|
151
|
+
);
|
|
152
|
+
GetImpl()->AstNodeSetOriginalNode(context, nn, node);
|
|
153
|
+
return nn;
|
|
154
|
+
}
|
|
155
|
+
KOALA_INTEROP_8(UpdateCallExpression, KNativePointer, KNativePointer, KNativePointer, KNativePointer, KNativePointerArray, KInt, KNativePointer, KBoolean, KBoolean)
|
|
156
|
+
|
|
157
|
+
KInt impl_IdentifierIdentifierFlags(KNativePointer contextPtr, KNativePointer nodePtr) {
|
|
158
|
+
auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
|
|
159
|
+
auto node = reinterpret_cast<es2panda_AstNode*>(nodePtr);
|
|
160
|
+
|
|
161
|
+
return
|
|
162
|
+
(GetImpl()->IdentifierIsOptionalConst(context, node) ? (1 << 0) : 0) |
|
|
163
|
+
(GetImpl()->IdentifierIsReferenceConst(context, node) ? (1 << 1) : 0) |
|
|
164
|
+
(GetImpl()->IdentifierIsTdzConst(context, node) ? (1 << 2) : 0);
|
|
165
|
+
}
|
|
166
|
+
KOALA_INTEROP_2(IdentifierIdentifierFlags, KInt, KNativePointer, KNativePointer)
|
|
167
|
+
|
|
168
|
+
/*
|
|
169
|
+
TODO: NOT FROM API (shouldn't be there)
|
|
170
|
+
-----------------------------------------------------------------------------------------------------------------------------
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
es2panda_AstNode * cachedParentNode;
|
|
174
|
+
es2panda_Context * cachedContext;
|
|
175
|
+
|
|
176
|
+
static void changeParent(es2panda_AstNode *child)
|
|
177
|
+
{
|
|
178
|
+
GetImpl()->AstNodeSetParent(cachedContext, child, cachedParentNode);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
static void SetRightParent(es2panda_AstNode *node, void *arg)
|
|
182
|
+
{
|
|
183
|
+
es2panda_Context *ctx = static_cast<es2panda_Context *>(arg);
|
|
184
|
+
cachedContext = ctx;
|
|
185
|
+
cachedParentNode = node;
|
|
186
|
+
|
|
187
|
+
GetImpl()->AstNodeIterateConst(ctx, node, changeParent);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
KNativePointer impl_AstNodeUpdateAll(KNativePointer contextPtr, KNativePointer programPtr) {
|
|
191
|
+
auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
|
|
192
|
+
auto program = reinterpret_cast<es2panda_AstNode*>(programPtr);
|
|
193
|
+
|
|
194
|
+
GetImpl()->AstNodeForEach(program, SetRightParent, context);
|
|
195
|
+
return program;
|
|
196
|
+
}
|
|
197
|
+
KOALA_INTEROP_2(AstNodeUpdateAll, KNativePointer, KNativePointer, KNativePointer)
|
|
198
|
+
|
|
199
|
+
KNativePointer impl_AstNodeUpdateChildren(KNativePointer contextPtr, KNativePointer nodePtr) {
|
|
200
|
+
auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
|
|
201
|
+
auto node = reinterpret_cast<es2panda_AstNode*>(nodePtr);
|
|
202
|
+
cachedParentNode = node;
|
|
203
|
+
|
|
204
|
+
GetImpl()->AstNodeIterateConst(context, node, changeParent);
|
|
205
|
+
return node;
|
|
206
|
+
}
|
|
207
|
+
KOALA_INTEROP_2(AstNodeUpdateChildren, KNativePointer, KNativePointer, KNativePointer)
|
|
208
|
+
|
|
209
|
+
std::vector<void*> cachedChildren;
|
|
210
|
+
|
|
211
|
+
static void visitChild(es2panda_AstNode *node) {
|
|
212
|
+
cachedChildren.emplace_back(node);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
KNativePointer impl_AstNodeChildren(
|
|
216
|
+
KNativePointer contextPtr,
|
|
217
|
+
KNativePointer nodePtr
|
|
218
|
+
) {
|
|
219
|
+
auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
|
|
220
|
+
auto node = reinterpret_cast<es2panda_AstNode*>(nodePtr);
|
|
221
|
+
cachedContext = context;
|
|
222
|
+
cachedChildren.clear();
|
|
223
|
+
|
|
224
|
+
GetImpl()->AstNodeIterateConst(context, node, visitChild);
|
|
225
|
+
return new std::vector(cachedChildren);
|
|
226
|
+
}
|
|
227
|
+
KOALA_INTEROP_2(AstNodeChildren, KNativePointer, KNativePointer, KNativePointer)
|
|
228
|
+
|
|
229
|
+
/*
|
|
230
|
+
-----------------------------------------------------------------------------------------------------------------------------
|
|
231
|
+
*/
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#ifndef COMMON_H
|
|
2
|
+
#define COMMON_H
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "dynamic-loader.h"
|
|
20
|
+
#include "es2panda_lib.h"
|
|
21
|
+
#include "common-interop.h"
|
|
22
|
+
#include "stdexcept"
|
|
23
|
+
#include <string>
|
|
24
|
+
#include <iostream>
|
|
25
|
+
#include <vector>
|
|
26
|
+
|
|
27
|
+
using std::string, std::cout, std::endl, std::vector;
|
|
28
|
+
|
|
29
|
+
es2panda_Impl *GetImpl();
|
|
30
|
+
|
|
31
|
+
string getString(KStringPtr ptr);
|
|
32
|
+
|
|
33
|
+
char* getStringCopy(KStringPtr& ptr);
|
|
34
|
+
|
|
35
|
+
inline KUInt unpackUInt(const KByte* bytes);
|
|
36
|
+
|
|
37
|
+
es2panda_ContextState intToState(KInt state);
|
|
38
|
+
|
|
39
|
+
#endif // COMMON_H
|