* Copyright (c) 2024-2026 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ES2PANDA_PUBLIC_ES2PANDA_LIB
#define ES2PANDA_PUBLIC_ES2PANDA_LIB
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <uchar.h>
#ifdef __cplusplus
extern "C" {
#endif
#define ES2PANDA_LIB_VERSION 1
#ifndef CAPI_EXPORT
#ifdef PANDA_TARGET_WINDOWS
#define CAPI_EXPORT __declspec(dllexport)
#else
#define CAPI_EXPORT __attribute__((visibility("default")))
#endif
#endif
typedef struct es2panda_Config es2panda_Config;
typedef struct es2panda_Context es2panda_Context;
typedef struct es2panda_GlobalContext es2panda_GlobalContext;
typedef struct es2panda_TsDeclgen es2panda_TsDeclgen;
typedef struct es2panda_variantDoubleCharArrayBool {
int index;
union {
double d;
char *c;
bool b;
} variant;
} es2panda_variantDoubleCharArrayBool;
enum es2panda_variantIndex {
CAPI_DOUBLE = 0,
CAPI_CHAR = 1,
CAPI_BOOL = 2,
};
typedef struct es2panda_Program es2panda_Program;
typedef struct es2panda_RecordTableHolder es2panda_RecordTableHolder;
typedef struct es2panda_ExternalSource es2panda_ExternalSource;
typedef struct es2panda_ArkTsConfig es2panda_ArkTsConfig;
typedef struct es2panda_AstNode es2panda_AstNode;
typedef struct es2panda_FunctionSignature es2panda_FunctionSignature;
typedef struct es2panda_SourcePosition es2panda_SourcePosition;
typedef struct es2panda_SourceRange es2panda_SourceRange;
typedef struct es2panda_SrcDumper es2panda_SrcDumper;
typedef struct es2panda_AstDumper es2panda_AstDumper;
typedef struct es2panda_LabelPair es2panda_LabelPair;
typedef struct es2panda_ScriptFunctionData es2panda_ScriptFunctionData;
typedef struct es2panda_ImportSource es2panda_ImportSource;
typedef struct es2panda_Signature es2panda_Signature;
typedef struct es2panda_SignatureInfo es2panda_SignatureInfo;
typedef struct es2panda_CheckerContext es2panda_CheckerContext;
typedef struct es2panda_ResolveResult es2panda_ResolveResult;
typedef struct es2panda_ValidationInfo es2panda_ValidationInfo;
typedef struct es2panda_Type es2panda_Type;
typedef struct es2panda_TypeRelation es2panda_TypeRelation;
typedef struct es2panda_IndexInfo es2panda_IndexInfo;
typedef struct es2panda_GlobalTypesHolder es2panda_GlobalTypesHolder;
typedef struct es2panda_ObjectDescriptor es2panda_ObjectDescriptor;
typedef struct es2panda_Variable es2panda_Variable;
typedef struct es2panda_Scope es2panda_Scope;
typedef struct es2panda_ScopeFindResult es2panda_ScopeFindResult;
typedef struct es2panda_BindingProps es2panda_BindingProps;
typedef struct es2panda_Declaration es2panda_Declaration;
typedef struct es2panda_RecordTable es2panda_RecordTable;
typedef struct es2panda_BoundContext es2panda_BoundContext;
typedef struct es2panda_AstVisitor es2panda_AstVisitor;
typedef struct es2panda_AstVerifier es2panda_AstVerifier;
typedef struct es2panda_VerifierMessage es2panda_VerifierMessage;
typedef struct es2panda_CodeGen es2panda_CodeGen;
typedef struct es2panda_VReg es2panda_VReg;
typedef struct es2panda_IRNode es2panda_IRNode;
typedef struct es2panda_ErrorLogger es2panda_ErrorLogger;
typedef struct es2panda_VerificationContext es2panda_VerificationContext;
typedef struct es2panda_ImportPathManager es2panda_ImportPathManager;
typedef struct es2panda_DiagnosticKind es2panda_DiagnosticKind;
typedef struct es2panda_DiagnosticMessageParams es2panda_DiagnosticMessageParams;
typedef struct es2panda_DiagnosticStorage es2panda_DiagnosticStorage;
typedef struct es2panda_Path es2panda_Path;
typedef struct es2panda_Options es2panda_Options;
typedef void (*NodeTraverser)(es2panda_AstNode *);
typedef es2panda_AstNode *(*NodeTransformer)(es2panda_AstNode *);
typedef bool (*NodePredicate)(es2panda_AstNode *);
typedef es2panda_Variable *(*PropertyProcessor)(es2panda_Variable *, es2panda_Type *);
typedef void (*PropertyTraverser)(const es2panda_Variable *);
typedef void (*ClassBuilder)(es2panda_AstNode **nodes, size_t size);
typedef void (*MethodBuilder)(es2panda_AstNode **statements, size_t sizeStatements, es2panda_AstNode **expression,
size_t sizeExpression, es2panda_Type **type);
typedef void (*ClassInitializerBuilder)(es2panda_AstNode **statements, size_t sizeStatements,
es2panda_AstNode **expression, size_t sizeExpression);
typedef struct es2panda_DynamicImportData {
const es2panda_AstNode *import;
const es2panda_AstNode *specifier;
es2panda_Variable *variable;
} es2panda_DynamicImportData;
typedef struct es2panda_OverloadInfo {
uint32_t minArg;
size_t maxArg;
bool needHelperOverload;
bool isDeclare;
bool hasRestVar;
} es2panda_OverloadInfo;
enum es2panda_ContextState {
ES2PANDA_STATE_NEW,
ES2PANDA_STATE_PARSED,
ES2PANDA_STATE_BOUND,
ES2PANDA_STATE_CHECKED,
ES2PANDA_STATE_LOWERED,
ES2PANDA_STATE_ASM_GENERATED,
ES2PANDA_STATE_BIN_GENERATED,
ES2PANDA_STATE_ERROR
};
typedef struct es2panda_SuggestionInfo {
const es2panda_DiagnosticKind *kind;
const char **args;
size_t argc;
const char *substitutionCode;
const char *title;
es2panda_SourceRange *range;
} es2panda_SuggestionInfo;
typedef struct es2panda_DiagnosticInfo {
const es2panda_DiagnosticKind *kind;
const char **args;
size_t argc;
es2panda_SourcePosition *pos;
} es2panda_DiagnosticInfo;
enum es2panda_PluginDiagnosticType { ES2PANDA_PLUGIN_WARNING, ES2PANDA_PLUGIN_ERROR, ES2PANDA_PLUGIN_SUGGESTION };
typedef enum Es2pandaLanguage {
LANGUAGE_AS,
LANGUAGE_JS,
LANGUAGE_TS,
LANGUAGE_ETS,
} Es2pandaLanguage;
typedef enum es2panda_PluginDiagnosticType es2panda_PluginDiagnosticType;
typedef enum es2panda_ContextState es2panda_ContextState;
#include "generated/es2panda_lib/es2panda_lib_enums.inc"
struct CAPI_EXPORT es2panda_Impl {
int version;
void (*MemInitialize)();
void (*MemFinalize)();
es2panda_Config *(*CreateConfig)(int argc, char const *const *argv);
void (*DestroyConfig)(es2panda_Config *config);
void (*DestroyConfigWithoutLog)(es2panda_Config *config);
char const *(*GetAllErrorMessages)(es2panda_Context *context);
const es2panda_Options *(*ConfigGetOptions)(es2panda_Config *config);
es2panda_Context *(*CreateContextFromFile)(es2panda_Config *config, char const *source_file_name);
es2panda_Context *(*CreateCacheContextFromFile)(es2panda_Config *config, char const *source_file_name,
es2panda_GlobalContext *globalContext, bool isExternal);
es2panda_Context *(*CreateContextFromString)(es2panda_Config *config, const char *source, char const *file_name);
es2panda_Context *(*CreateContextFromStringWithHistory)(es2panda_Config *config, const char *source,
char const *file_name);
es2panda_Context *(*CreateCacheContextFromString)(es2panda_Config *config, const char *source,
char const *file_name, es2panda_GlobalContext *globalContext,
bool isExternal, bool isLspUsage);
es2panda_Context *(*CreateContextGenerateAbcForExternalSourceFiles)(es2panda_Config *config, int fileNamesCount,
char const *const *fileNames);
es2panda_Context *(*CreateContextSimultaneousMode)(es2panda_Config *config, int fileNamesCount,
char const *const *fileNames);
es2panda_Context *(*CreateContextSimultaneousModeForLsp)(es2panda_Config *config, int fileNamesCount,
char const *const *fileNames, bool isLspUsage);
es2panda_Context *(*ProceedToState)(es2panda_Context *context, es2panda_ContextState state);
void (*DestroyContext)(es2panda_Context *context);
es2panda_GlobalContext *(*CreateGlobalContext)(es2panda_Config *config, const char **externalFileList,
size_t fileNum, bool LspUsage);
void (*DestroyGlobalContext)(es2panda_GlobalContext *globalContext);
es2panda_ContextState (*ContextState)(es2panda_Context *context);
char const *(*ContextErrorMessage)(es2panda_Context *context);
es2panda_Program *(*ContextProgram)(es2panda_Context *context);
es2panda_ExternalSource **(*ProgramExternalSources)(es2panda_Context *context, es2panda_Program *program,
size_t *lenP);
es2panda_ExternalSource **(*ProgramDirectExternalSources)(es2panda_Context *context, es2panda_Program *program,
size_t *lenP);
char const *(*ExternalSourceName)(es2panda_ExternalSource *e_source);
es2panda_Program **(*ExternalSourcePrograms)(es2panda_ExternalSource *e_source, size_t *len_p);
void (*AstNodeForEach)(es2panda_AstNode *ast, void (*func)(es2panda_AstNode *, void *), void *arg);
#define NUMBER_LITERAL_SET_DECL(name, type) bool (*NumberLiteralSet##name)(es2panda_AstNode * node, type new_value)
NUMBER_LITERAL_SET_DECL(Int, int32_t);
NUMBER_LITERAL_SET_DECL(Long, int64_t);
NUMBER_LITERAL_SET_DECL(Double, double);
NUMBER_LITERAL_SET_DECL(Float, float);
#undef NUMBER_LITERAL_SET_DECL
#define CREATE_UPDATE_NUMBER_LITERAL_IMPL(num, type) \
es2panda_AstNode *(*CreateNumberLiteral##num)(es2panda_Context * ctx, type value); \
es2panda_AstNode *(*UpdateNumberLiteral##num)(es2panda_Context * ctx, es2panda_AstNode * original, type value)
CREATE_UPDATE_NUMBER_LITERAL_IMPL(, int32_t);
CREATE_UPDATE_NUMBER_LITERAL_IMPL(1, int64_t);
CREATE_UPDATE_NUMBER_LITERAL_IMPL(2, double);
CREATE_UPDATE_NUMBER_LITERAL_IMPL(3, float);
#undef CREATE_UPDATE_NUMBER_LITERAL_IMPL
const char *(*NumberLiteralStrConst)(es2panda_Context *context, es2panda_AstNode *classInstance);
void *(*AllocMemory)(es2panda_Context *context, size_t numberOfElements, size_t sizeOfElement);
es2panda_SourcePosition *(*CreateSourcePosition)(es2panda_Context *context, size_t index, size_t line);
es2panda_SourceRange *(*CreateSourceRange)(es2panda_Context *context, es2panda_SourcePosition *start,
es2panda_SourcePosition *end);
size_t (*SourcePositionCol)(es2panda_Context *context, es2panda_SourcePosition *position);
size_t (*SourcePositionIndex)(es2panda_Context *context, es2panda_SourcePosition *position);
size_t (*SourcePositionLine)(es2panda_Context *context, es2panda_SourcePosition *position);
es2panda_SourcePosition *(*SourceRangeStart)(es2panda_Context *context, es2panda_SourceRange *range);
es2panda_SourcePosition *(*SourceRangeEnd)(es2panda_Context *context, es2panda_SourceRange *range);
void (*AstNodeSetNoDebugLineFlag)(es2panda_Context *context, es2panda_AstNode *node);
const es2panda_DiagnosticKind *(*CreateDiagnosticKind)(es2panda_Context *context, const char *dmessage,
es2panda_PluginDiagnosticType etype);
es2panda_DiagnosticInfo *(*CreateDiagnosticInfo)(es2panda_Context *context, const es2panda_DiagnosticKind *kind,
const char **args, size_t argc, es2panda_SourcePosition *position);
es2panda_SuggestionInfo *(*CreateSuggestionInfo)(es2panda_Context *context, const es2panda_DiagnosticKind *kind,
const char **args, size_t argc, const char *substitutionCode,
const char *title, es2panda_SourceRange *range);
void (*LogDiagnosticWithSuggestions)(es2panda_Context *context, const es2panda_DiagnosticInfo *diagnosticInfo,
es2panda_SuggestionInfo **suggestionInfos, size_t suggestionCount);
void (*LogDiagnosticWithSuggestion)(es2panda_Context *context, const es2panda_DiagnosticInfo *diagnosticInfo,
const es2panda_SuggestionInfo *suggestionInfo);
void (*LogDiagnostic)(es2panda_Context *context, const es2panda_DiagnosticKind *kind, const char **args,
size_t argc, es2panda_SourcePosition *pos);
const es2panda_DiagnosticStorage *(*GetSemanticErrors)(es2panda_Context *context);
const es2panda_DiagnosticStorage *(*GetSyntaxErrors)(es2panda_Context *context);
const es2panda_DiagnosticStorage *(*GetPluginErrors)(es2panda_Context *context);
const es2panda_DiagnosticStorage *(*GetWarnings)(es2panda_Context *context);
bool (*IsAnyError)(es2panda_Context *context);
es2panda_Scope *(*AstNodeFindNearestScope)(es2panda_Context *ctx, es2panda_AstNode *node);
es2panda_Scope *(*AstNodeRebind)(es2panda_Context *ctx, es2panda_AstNode *node);
void (*AstNodeRecheck)(es2panda_Context *ctx, es2panda_AstNode *node);
Es2pandaEnum (*Es2pandaEnumFromString)(es2panda_Context *ctx, const char *str);
char *(*Es2pandaEnumToString)(es2panda_Context *ctx, Es2pandaEnum id);
es2panda_AstNode *(*DeclarationFromIdentifier)(es2panda_Context *ctx, es2panda_AstNode *node);
bool (*IsImportTypeKind)(es2panda_Context *ctx, es2panda_AstNode *node);
char *(*JsdocStringFromDeclaration)(es2panda_Context *ctx, es2panda_AstNode *node);
char *(*GetLicenseFromRootNode)(es2panda_Context *ctx, es2panda_AstNode *node);
es2panda_AstNode *(*FirstDeclarationByNameFromNode)(es2panda_Context *ctx, const es2panda_AstNode *node,
const char *name);
es2panda_AstNode *(*FirstDeclarationByNameFromProgram)(es2panda_Context *ctx, const es2panda_Program *program,
const char *name);
es2panda_AstNode **(*AllDeclarationsByNameFromNode)(es2panda_Context *ctx, const es2panda_AstNode *node,
const char *name, size_t *declsLen);
es2panda_AstNode **(*AllDeclarationsByNameFromProgram)(es2panda_Context *ctx, const es2panda_Program *program,
const char *name, size_t *declsLen);
es2panda_TsDeclgen *(*CreateTsDeclgen)(es2panda_Context *context, size_t fileNamesCount,
const char *const *inputFiles, const char *const *outputDeclEts,
const char *const *outputEts, bool exportAll, bool isolated,
const char *recordFile, bool genAnnotations);
int (*GenerateTsDeclarationsAfterParsed)(es2panda_TsDeclgen *declgen);
int (*GenerateTsDeclarationsAfterCheck)(es2panda_TsDeclgen *declgen);
int (*WriteTsDeclarations)(es2panda_TsDeclgen *declgen);
void (*DestroyTsDeclgen)(es2panda_TsDeclgen *declgen);
char *(*FormOutputPathForFile)(es2panda_Context *context, const char *inputPath);
void (*InsertETSImportDeclarationAndParse)(es2panda_Context *context, es2panda_Program *program,
es2panda_AstNode *importDeclaration);
int (*GenerateStaticDeclarationsFromContext)(es2panda_Context *context, const char *outputPath);
void (*InvalidateFileCache)(es2panda_GlobalContext *globalContext, const char *fileName);
void (*RemoveFileCache)(es2panda_GlobalContext *globalContext, const char *fileName);
void (*AddFileCache)(es2panda_GlobalContext *globalContext, const char *fileName);
int (*IncrementalPrepareProgram)(es2panda_Context *context, const char *fileName, const char *sourceText,
bool isChanged);
void (*FreeCompilerPartMemory)(es2panda_Context *context);
void (*ResetCounters)();
int (*ExtractDeclarationsFromAbcFile)(const char *abcFile, const char *cacheDir);
#include "generated/es2panda_lib/es2panda_lib_decl.inc"
};
CAPI_EXPORT struct es2panda_Impl const *es2panda_GetImpl(int version);
#ifdef __cplusplus
}
#endif
#endif