1 Star 0 Fork 153

klooer/sig_arkcompiler_ets_frontend

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ETSBinder.h 5.82 KB
一键复制 编辑 原始数据 按行查看 历史
/**
* Copyright (c) 2021 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_BINDER_ETS_BINDER_H
#define ES2PANDA_BINDER_ETS_BINDER_H
#include "plugins/ecmascript/es2panda/binder/TypedBinder.h"
#include "plugins/ecmascript/es2panda/binder/recordTable.h"
namespace panda::es2panda::binder {
using ComputedLambdaObjects =
ArenaUnorderedMap<const ir::AstNode *, std::pair<ir::ClassDefinition *, checker::Signature *>>;
class ETSBinder : public TypedBinder {
public:
explicit ETSBinder(ArenaAllocator *allocator)
: TypedBinder(allocator),
global_record_table_(allocator, Program(), RecordTableFlags::NONE),
record_table_(&global_record_table_),
external_record_table_(Allocator()->Adapter()),
default_imports_(Allocator()->Adapter()),
lambda_objects_(Allocator()->Adapter())
{
InitImplicitThisParam();
}
NO_COPY_SEMANTIC(ETSBinder);
NO_MOVE_SEMANTIC(ETSBinder);
~ETSBinder() = default;
ScriptExtension Extension() const override
{
return ScriptExtension::ETS;
}
ResolveBindingOptions BindingOptions() const override
{
return ResolveBindingOptions::BINDINGS;
}
RecordTable *GetRecordTable()
{
return record_table_;
}
const RecordTable *GetRecordTable() const
{
return record_table_;
}
RecordTable *GetGlobalRecordTable()
{
return &global_record_table_;
}
const RecordTable *GetGlobalRecordTable() const
{
return &global_record_table_;
}
ArenaUnorderedMap<parser::Program *, RecordTable *> &GetExternalRecordTable()
{
return external_record_table_;
}
const ArenaUnorderedMap<parser::Program *, RecordTable *> &GetExternalRecordTable() const
{
return external_record_table_;
}
const ComputedLambdaObjects &LambdaObjects() const
{
return lambda_objects_;
}
ComputedLambdaObjects &LambdaObjects()
{
return lambda_objects_;
}
void HandleCustomNodes(ir::AstNode *child_node) override;
void IdentifierAnalysis() override;
void BuildClassDefinition(ir::ClassDefinition *class_def) override;
void BuildClassProperty(const ir::ClassProperty *prop) override;
void LookupIdentReference(ir::Identifier *ident) override;
bool BuildInternalName(ir::ScriptFunction *script_func) override;
void AddCompilableFunction(ir::ScriptFunction *func) override;
void LookupTypeReference(ir::Identifier *ident);
void LookupTypeArgumentReferences(ir::ETSTypeReference *type_ref);
void BuildInterfaceDeclaration(ir::TSInterfaceDeclaration *decl);
void BuildMemberExpression(ir::MemberExpression *member_expr);
void BuildMethodDefinition(ir::MethodDefinition *method_def);
void BuildImportDeclaration(ir::ImportDeclaration *decl);
void BuildETSNewClassInstanceExpression(ir::ETSNewClassInstanceExpression *class_instance);
void BuildMethodReferenceExpression(ir::ETSMethodReferenceExpression *method_ref);
void AddSpecifiersToTopBindings(ir::AstNode *specifier, const ir::StringLiteral *import_path);
void ResolveInterfaceDeclaration(ir::TSInterfaceDeclaration *decl);
void ResolveMethodDefinition(ir::MethodDefinition *method_def);
LocalScope *ResolvePropertyReference(ir::ClassProperty *prop, ClassScope *scope);
void ResolveEnumDeclaration(ir::TSEnumDeclaration *enum_decl);
void InitializeInterfaceIdent(ir::TSInterfaceDeclaration *decl);
void BuildExternalProgram(parser::Program *ext_program);
void BuildProgram();
void BuildFunctionName(const ir::ScriptFunction *func) const;
void BuildFunctionType(ir::ETSFunctionType *func_type);
void BuildProxyMethod(ir::ScriptFunction *func, const util::StringView &containing_class_name, bool is_static);
void BuildLambdaObject(ir::AstNode *ref_node, ir::ClassDefinition *lambda_object, checker::Signature *signature);
void AddLambdaFunctionThisParam(ir::ScriptFunction *func);
void AddInvokeFunctionThisParam(ir::ScriptFunction *func);
void BuildLambdaObjectName(const ir::AstNode *ref_node);
void FormLambdaName(util::UString &name, const util::StringView &signature);
void FormFunctionalInterfaceName(util::UString &name, const util::StringView &signature);
void BuildFunctionalInterfaceName(ir::ETSFunctionType *func_type);
void SetDefaultImports(ArenaVector<ir::ImportDeclaration *> default_imports)
{
default_imports_ = std::move(default_imports);
}
static constexpr std::string_view DEFAULT_IMPORT_SOURCE_FILE = "<default_import>.ets";
static constexpr std::string_view DEFAULT_IMPORT_SOURCE = R"(
import * from "std/core";
import * from "std/math";
import * from "std/containers";
import * from "std/time";
)";
private:
void BuildClassDefinitionImpl(ir::ClassDefinition *class_def);
void InitImplicitThisParam();
void HandleStarImport(ir::TSQualifiedName *import_name, util::StringView full_path);
void ImportGlobalProperties(ir::ClassDefinition *class_def);
RecordTable global_record_table_;
RecordTable *record_table_;
ArenaUnorderedMap<parser::Program *, RecordTable *> external_record_table_;
ArenaVector<ir::ImportDeclaration *> default_imports_;
ComputedLambdaObjects lambda_objects_;
ir::Identifier *this_param_ {};
};
} // namespace panda::es2panda::binder
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/klooer/sig_arkcompiler_ets_frontend.git
git@gitee.com:klooer/sig_arkcompiler_ets_frontend.git
klooer
sig_arkcompiler_ets_frontend
sig_arkcompiler_ets_frontend
master

搜索帮助