diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index e8d2e3ead687fb1d89491ce5bb3adfc151e7914b..07e267579101264be81f74e780bbd58ae5ebdcf9 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -271,10 +271,8 @@ bool Options::Parse(int argc, const char **argv) compilerOptions_.typeExtractor = opTypeExtractor.GetValue(); if (compilerOptions_.typeExtractor) { compilerOptions_.typeDtsBuiltin = opTypeDtsBuiltin.GetValue(); -#ifndef NDEBUG - std::cout << "[LOG]TypeExtractor is enabled, type-dts-builtin: " << + DCOUT << "[LOG]TypeExtractor is enabled, type-dts-builtin: " << compilerOptions_.typeDtsBuiltin << std::endl; -#endif } }; diff --git a/es2panda/compiler/base/lexenv.cpp b/es2panda/compiler/base/lexenv.cpp index a4f2764e405d0ba864d458e38414410df5edbc4e..f199cf3b007f14399be6e1cd3c83fd3e374b3fca 100644 --- a/es2panda/compiler/base/lexenv.cpp +++ b/es2panda/compiler/base/lexenv.cpp @@ -95,7 +95,7 @@ static void ExpandStoreLexVar(PandaGen *pg, const ir::AstNode *node, const binde pg->LoadAccumulator(node, valueReg); } - pg->StoreLexicalVar(node, result.lexLevel, local->LexIdx(), local->Name()); + pg->StoreLexicalVar(node, result.lexLevel, local->LexIdx(), local); } static void ExpandStoreNormalVar(PandaGen *pg, const ir::AstNode *node, const binder::ScopeFindResult &result, @@ -118,24 +118,18 @@ static void ExpandStoreNormalVar(PandaGen *pg, const ir::AstNode *node, const bi auto typeIndex = context->TypeRecorder()->GetVariableTypeIndex(local); if (typeIndex != extractor::TypeRecorder::PRIMITIVETYPE_ANY) { pg->StoreAccumulatorWithType(node, typeIndex, localReg); -#ifndef NDEBUG - std::cout << "[LOG]Local vreg in variable has type index: " << local->Name() << "@" << + DCOUT << "[LOG]Local vreg in variable has type index: " << local->Name() << "@" << local << " | " << typeIndex << std::endl; -#endif return; } typeIndex = context->TypeRecorder()->GetNodeTypeIndex(node); if (typeIndex != extractor::TypeRecorder::PRIMITIVETYPE_ANY) { pg->StoreAccumulatorWithType(node, typeIndex, localReg); -#ifndef NDEBUG - std::cout << "[LOG]Local vreg in declnode has type index: " << local->Name() << "@" << + DCOUT << "[LOG]Local vreg in declnode has type index: " << local->Name() << "@" << local << " | " << typeIndex << std::endl; -#endif return; } -#ifndef NDEBUG - std::cout << "[WARNING]Local vreg lose type index: " << local->Name() << "@" << local << std::endl; -#endif + DCOUT << "[WARNING]Local vreg lose type index: " << local->Name() << "@" << local << std::endl; } pg->StoreAccumulator(node, localReg); } diff --git a/es2panda/compiler/core/compilerImpl.cpp b/es2panda/compiler/core/compilerImpl.cpp index 4245749bfacc7460bbca4ae3d73d2df943c0c847..ceb33745a1121e61122acf4f07a73d2f909c9b53 100644 --- a/es2panda/compiler/core/compilerImpl.cpp +++ b/es2panda/compiler/core/compilerImpl.cpp @@ -61,8 +61,9 @@ panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const e } if (program->Extension() == ScriptExtension::TS) { - context.GetEmitter()->FillTypeInfoRecord(options.typeExtractor, - options.typeExtractor ? extractor_->Recorder()->GetTypeSummaryIndex() : 0); + context.GetEmitter()->FillTypeInfoRecord(&context, options.typeExtractor, + options.typeExtractor ? extractor_->Recorder()->GetTypeSummaryIndex() : 0, + std::string(program->RecordName())); } queue_ = new CompileFuncQueue(threadCount_, &context); diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index b4185b1f7aa944d8fb11f145bbd76bd595e012e3..7e179b2fb8b9df0bcf4d6bde8513bace3892f1fd 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -294,7 +294,9 @@ Emitter::Emitter(const CompilerContext *context) // For Type Extractor // Global record to show type extractor is enabled or not - GenTypeInfoRecord(); + if (!context->IsMergeAbc()) { + GenTypeInfoRecord(); + } GenESTypeAnnotationRecord(); if (context->IsMergeAbc()) { @@ -409,9 +411,14 @@ void Emitter::AddSourceTextModuleRecord(ModuleRecordEmitter *module, CompilerCon prog_->literalarray_table.emplace(static_cast(moduleLiteral), std::move(literalArrayInstance)); } -void Emitter::FillTypeInfoRecord(bool typeFlag, int64_t typeSummaryIndex) const +void Emitter::FillTypeInfoRecord(CompilerContext *context, bool typeFlag, int64_t typeSummaryIndex, + const std::string &recordName) const { - TypeExtractorEmitter::GenTypeInfoRecord(prog_, typeFlag, typeSummaryIndex); + if (!context->IsMergeAbc()) { + TypeExtractorEmitter::GenTypeInfoRecord(prog_, typeFlag, typeSummaryIndex, recordName); + } else { + TypeExtractorEmitter::GenTypeInfoRecordForMergeABC(prog_, typeFlag, typeSummaryIndex, recordName); + } } void Emitter::FillTypeLiteralBuffers(const extractor::TypeRecorder *recorder) const @@ -480,6 +487,16 @@ void Emitter::GenBufferLiterals(ArenaVectorGetInt(); break; } + case ir::LiteralTag::LITERALARRAY: { + valueLit.tag_ = panda::panda_file::LiteralTag::LITERALARRAY; + valueLit.value_ = literal->GetString().Mutf8(); + break; + } + case ir::LiteralTag::BUILTINTYPEINDEX: { + valueLit.tag_ = panda::panda_file::LiteralTag::BUILTINTYPEINDEX; + valueLit.value_ = static_cast(literal->GetInt()); + break; + } // TODO: support ir::LiteralTag::ASYNC_GENERATOR_METHOD case ir::LiteralTag::NULL_VALUE: { valueLit.tag_ = panda::panda_file::LiteralTag::NULLVALUE; @@ -554,4 +571,10 @@ panda::pandasm::Program *Emitter::Finalize(bool dumpDebugInfo, util::Hotfix *hot prog_ = nullptr; return prog; } + +panda::pandasm::Program *Emitter::GetProgram() const +{ + return prog_; +} + } // namespace panda::es2panda::compiler diff --git a/es2panda/compiler/core/emitter/emitter.h b/es2panda/compiler/core/emitter/emitter.h index 1f7d2253edbd9487f283542f8cb8e51da6efd2ee..c58afaf4214d599707c6cad1b3b7160d4a5a3336 100644 --- a/es2panda/compiler/core/emitter/emitter.h +++ b/es2panda/compiler/core/emitter/emitter.h @@ -107,12 +107,14 @@ public: void AddFunction(FunctionEmitter *func, CompilerContext *context); void AddSourceTextModuleRecord(ModuleRecordEmitter *module, CompilerContext *context); - void FillTypeInfoRecord(bool typeFlag, int64_t typeSummaryIndex) const; + void FillTypeInfoRecord(CompilerContext *context, bool typeFlag, int64_t typeSummaryIndex, + const std::string &recordName) const; void FillTypeLiteralBuffers(const extractor::TypeRecorder *recorder) const; static void GenBufferLiterals(ArenaVector>> &literalBuffers, const LiteralBuffer *buff); static void DumpAsm(const panda::pandasm::Program *prog); panda::pandasm::Program *Finalize(bool dumpDebugInfo, util::Hotfix *hotfixHelper); + panda::pandasm::Program *GetProgram() const; void GenJsonContentRecord(const CompilerContext *context); private: diff --git a/es2panda/compiler/core/emitter/typeExtractorEmitter.cpp b/es2panda/compiler/core/emitter/typeExtractorEmitter.cpp index 3ac375b8ab2387eaf8cbc13e39b5bab38b1be3fb..d42d7a661997a68f4aabde3906bfdb3d3c636a42 100644 --- a/es2panda/compiler/core/emitter/typeExtractorEmitter.cpp +++ b/es2panda/compiler/core/emitter/typeExtractorEmitter.cpp @@ -26,123 +26,200 @@ using AnnotationData = panda::pandasm::AnnotationData; using AnnotationElement = panda::pandasm::AnnotationElement; using ArrayValue = panda::pandasm::ArrayValue; using Field = panda::pandasm::Field; +using Record = panda::pandasm::Record; using ScalarValue = panda::pandasm::ScalarValue; -using ValueType = panda::pandasm::Value::Type; using Type = panda::pandasm::Type; +using ValueType = panda::pandasm::Value::Type; + +int32_t TypeExtractorEmitter::literalId_ = -1; TypeExtractorEmitter::TypeExtractorEmitter(const PandaGen *pg, panda::pandasm::Function *func) : pg_(pg), func_(func) { - GenFunctionTypeInfo(); - if (func->name == binder::Binder::MAIN_FUNC_NAME) { + auto prog = pg_->Context()->GetEmitter()->GetProgram(); + GenFunctionTypeInfo(prog); + if (IsFuncMain0(func->name, pg_->Context()->IsMergeAbc())) { if (pg_->Context()->TypeRecorder()->ExportType().size() > 0U) { - GenExportTypeInfo(); + GenExportTypeInfo(prog); } if (pg_->Context()->TypeRecorder()->DeclareType().size() > 0U) { - GenDeclareTypeInfo(); + GenDeclareTypeInfo(prog); } } } -void TypeExtractorEmitter::GenFunctionTypeInfo() const +bool TypeExtractorEmitter::IsFuncMain0(const std::string &funcName, bool isMergeAbc) const +{ + std::string expectedName(binder::Binder::MAIN_FUNC_NAME); + if (isMergeAbc) { + expectedName = std::string(pg_->Context()->RecordName()) + "." + expectedName; + } + return funcName == expectedName; +} + +static void GenTypeInfo(const extractor::TypeRecorder *recorder, int64_t typeIndex, std::vector &typeInfo) +{ + Literal typeTag; + Literal typeValue; + typeTag.tag_ = panda::panda_file::LiteralTag::TAGVALUE; + if (typeIndex >= recorder->GetUserTypeIndexShift()) { + typeTag.value_ = static_cast(panda::panda_file::LiteralTag::LITERALARRAY); + typeValue.tag_ = panda::panda_file::LiteralTag::LITERALARRAY; + typeValue.value_ = std::string(recorder->GetRecordName()) + "_" + + std::to_string(typeIndex - recorder->GetUserTypeIndexShift()); + } else { + typeTag.value_ = static_cast(panda::panda_file::LiteralTag::BUILTINTYPEINDEX); + typeValue.tag_ = panda::panda_file::LiteralTag::BUILTINTYPEINDEX; + typeValue.value_ = static_cast(typeIndex); + } + typeInfo.emplace_back(typeTag); + typeInfo.emplace_back(typeValue); +} + +static void GenInsnTypeInfo(const extractor::TypeRecorder *recorder, uint32_t orderIndex, int64_t typeIndex, + std::vector &typedInsns) { - std::vector typedInsns; - typedInsns.reserve(pg_->TypedInsns().size()); + Literal insnOrderTag; + Literal insnOrderValue; + insnOrderTag.tag_ = panda::panda_file::LiteralTag::TAGVALUE; + insnOrderTag.value_ = static_cast(panda::panda_file::LiteralTag::INTEGER); + insnOrderValue.tag_ = panda::panda_file::LiteralTag::INTEGER; + insnOrderValue.value_ = static_cast(orderIndex); + typedInsns.emplace_back(insnOrderTag); + typedInsns.emplace_back(insnOrderValue); + + GenTypeInfo(recorder, typeIndex, typedInsns); +} + +void TypeExtractorEmitter::GenFunctionTypeInfo(panda::pandasm::Program *prog) const +{ + auto recorder = pg_->Context()->TypeRecorder(); + std::vector typedInsns; + typedInsns.reserve(pg_->TypedInsns().size() * 4U); // Expand to 4 pieces of information size_t index = 0U; for (const auto *ins : pg_->Insns()) { auto t = pg_->TypedInsns().find(ins); if (t != pg_->TypedInsns().end()) { - const auto &insn = func_->ins[index]; int64_t typeIndex = t->second; - int32_t orderIndex = index; - if (typeIndex < extractor::TypeRecorder::PRIMITIVETYPE_ANY) { - // Decode type and order index for params - typeIndex = -(typeIndex + 1); - orderIndex = static_cast(func_->regs_num) - static_cast(insn.regs[1]) - 1; - } + uint32_t orderIndex = index; if (typeIndex > extractor::TypeRecorder::PRIMITIVETYPE_ANY) { - ScalarValue insnOrder(ScalarValue::Create(orderIndex)); - typedInsns.emplace_back(std::move(insnOrder)); - ScalarValue insnType(ScalarValue::Create(typeIndex)); - typedInsns.emplace_back(std::move(insnType)); -#ifndef NDEBUG - std::cout << "[LOG]" << func_->name << ": " << insn.ToString("", true, func_->regs_num) << " | " - << orderIndex << " | " << typeIndex << std::endl; -#endif + GenInsnTypeInfo(recorder, orderIndex, typeIndex, typedInsns); + DCOUT << "[LOG]" << func_->name << ": " << func_->ins[index].ToString("", true, func_->regs_num) << + " | " << orderIndex << " | " << typeIndex << std::endl; } } index++; } + if (pg_->TypedFunc().first > extractor::TypeRecorder::PRIMITIVETYPE_ANY) { + // -1 for function type + GenInsnTypeInfo(recorder, static_cast(-1), pg_->TypedFunc().first, typedInsns); + DCOUT << "[LOG]" << func_->name << ": -1 | " << pg_->TypedFunc().first << std::endl; + } + if (pg_->TypedFunc().second > extractor::TypeRecorder::PRIMITIVETYPE_ANY) { + // -2 for method 'this' type + GenInsnTypeInfo(recorder, static_cast(-2), pg_->TypedFunc().second, typedInsns); + DCOUT << "[LOG]" << func_->name << ": -2 | " << pg_->TypedFunc().second << std::endl; + } + + std::string literalId = std::string(recorder->GetRecordName()) + "_" + + std::to_string(literalId_--); + auto literalArrayInstance = panda::pandasm::LiteralArray(std::move(typedInsns)); + prog->literalarray_table.emplace(literalId, std::move(literalArrayInstance)); + AnnotationData funcTypeAnnotation(TypeExtractorEmitter::TYPE_ANNOTATION); AnnotationElement funcTypeAnnotationElement(TypeExtractorEmitter::TYPE_INSTRUCTION, - std::make_unique(ArrayValue(ValueType::U32, typedInsns))); + std::make_unique(ScalarValue::Create(literalId))); funcTypeAnnotation.AddElement(std::move(funcTypeAnnotationElement)); func_->metadata->AddAnnotations({ funcTypeAnnotation }); } -template -static void GenTypeInfo(const M &map, F &funcTypeAnnotation) +template +static void GenImportOrDeclareTypeInfo(panda::pandasm::Program *prog, const extractor::TypeRecorder *recorder, + const M &map, AnnotationData &funcTypeAnnotation) { - std::string symbolStr; std::string symbolTypeStr; if constexpr (isExport) { - symbolStr = TypeExtractorEmitter::EXPORTED_SYMBOLS; symbolTypeStr = TypeExtractorEmitter::EXPORTED_SYMBOL_TYPES; } else { - symbolStr = TypeExtractorEmitter::DECLARED_SYMBOLS; symbolTypeStr = TypeExtractorEmitter::DECLARED_SYMBOL_TYPES; } - std::vector symbolElements; - std::vector symbolTypeElements; + std::vector typedSymbols; + typedSymbols.reserve(map.size() * 4U); // Expand to 4 pieces of information for (const auto &t : map) { - ScalarValue symbol(ScalarValue::Create(t.first)); - symbolElements.emplace_back(std::move(symbol)); - ScalarValue symbolType(ScalarValue::Create(t.second)); - symbolTypeElements.emplace_back(std::move(symbolType)); + Literal symbolTag; + Literal symbolValue; + symbolTag.tag_ = panda::panda_file::LiteralTag::TAGVALUE; + symbolTag.value_ = static_cast(panda::panda_file::LiteralTag::STRING); + symbolValue.tag_ = panda::panda_file::LiteralTag::STRING; + symbolValue.value_ = t.first; + typedSymbols.emplace_back(symbolTag); + typedSymbols.emplace_back(symbolValue); + + GenTypeInfo(recorder, t.second, typedSymbols); } - AnnotationElement funcSymbolsElements(symbolStr, - std::make_unique(ArrayValue(ValueType::STRING, symbolElements))); - AnnotationElement funcSymbolTypeElement(symbolTypeStr, - std::make_unique(ArrayValue(ValueType::U32, symbolTypeElements))); + std::string literalId = std::string(recorder->GetRecordName()) + "_" + + std::to_string(TypeExtractorEmitter::literalId_--); + auto literalArrayInstance = panda::pandasm::LiteralArray(std::move(typedSymbols)); + prog->literalarray_table.emplace(literalId, std::move(literalArrayInstance)); - funcTypeAnnotation.AddElement(std::move(funcSymbolsElements)); + AnnotationElement funcSymbolTypeElement(symbolTypeStr, + std::make_unique(ScalarValue::Create(literalId))); funcTypeAnnotation.AddElement(std::move(funcSymbolTypeElement)); } -void TypeExtractorEmitter::GenExportTypeInfo() const +void TypeExtractorEmitter::GenExportTypeInfo(panda::pandasm::Program *prog) const { AnnotationData funcTypeAnnotation(TypeExtractorEmitter::TYPE_ANNOTATION); - GenTypeInfo(pg_->Context()->TypeRecorder()->ExportType(), funcTypeAnnotation); + GenImportOrDeclareTypeInfo(prog, pg_->Context()->TypeRecorder(), + pg_->Context()->TypeRecorder()->ExportType(), funcTypeAnnotation); func_->metadata->AddAnnotations({ funcTypeAnnotation }); } -void TypeExtractorEmitter::GenDeclareTypeInfo() const +void TypeExtractorEmitter::GenDeclareTypeInfo(panda::pandasm::Program *prog) const { AnnotationData funcTypeAnnotation(TypeExtractorEmitter::TYPE_ANNOTATION); - GenTypeInfo(pg_->Context()->TypeRecorder()->DeclareType(), funcTypeAnnotation); + GenImportOrDeclareTypeInfo(prog, pg_->Context()->TypeRecorder(), + pg_->Context()->TypeRecorder()->DeclareType(), funcTypeAnnotation); func_->metadata->AddAnnotations({ funcTypeAnnotation }); } -// static -void TypeExtractorEmitter::GenTypeInfoRecord(panda::pandasm::Program *prog, bool typeFlag, int64_t typeSummaryIndex) +static void GenTypeSummaryInfo(bool typeFlag, int64_t typeSummaryIndex, const std::string &recordName, Record &record) { constexpr const auto LANG_EXT = panda::pandasm::extensions::Language::ECMASCRIPT; - auto &typeInfoRecord = prog->record_table.find(TypeExtractorEmitter::TYPE_INFO_RECORD)->second; auto typeFlagField = Field(LANG_EXT); typeFlagField.name = TypeExtractorEmitter::TYPE_FLAG; typeFlagField.type = Type("u8", 0); typeFlagField.metadata->SetValue(ScalarValue::Create(static_cast(typeFlag))); - typeInfoRecord.field_list.emplace_back(std::move(typeFlagField)); - - auto typeSummaryIndexField = Field(LANG_EXT); - typeSummaryIndexField.name = TypeExtractorEmitter::TYPE_SUMMARY; - typeSummaryIndexField.type = Type("u32", 0); - typeSummaryIndexField.metadata->SetValue(ScalarValue::Create( - static_cast(typeSummaryIndex))); - typeInfoRecord.field_list.emplace_back(std::move(typeSummaryIndexField)); + record.field_list.emplace_back(std::move(typeFlagField)); + + if (typeFlag) { + auto typeSummaryIndexField = Field(LANG_EXT); + typeSummaryIndexField.name = TypeExtractorEmitter::TYPE_SUMMARY; + typeSummaryIndexField.type = Type("u32", 0); + typeSummaryIndexField.metadata->SetValue(ScalarValue::Create( + "" + recordName + "_" + std::to_string(typeSummaryIndex))); + record.field_list.emplace_back(std::move(typeSummaryIndexField)); + } +} + +// static +void TypeExtractorEmitter::GenTypeInfoRecord(panda::pandasm::Program *prog, bool typeFlag, + int64_t typeSummaryIndex, const std::string &recordName) +{ + auto iter = prog->record_table.find(TypeExtractorEmitter::TYPE_INFO_RECORD); + ASSERT(iter != prog->record_table.end()); + GenTypeSummaryInfo(typeFlag, typeSummaryIndex, recordName, iter->second); +} + +void TypeExtractorEmitter::GenTypeInfoRecordForMergeABC(panda::pandasm::Program *prog, bool typeFlag, + int64_t typeSummaryIndex, const std::string &recordName) +{ + auto iter = prog->record_table.find(recordName); + ASSERT(iter != prog->record_table.end()); + GenTypeSummaryInfo(typeFlag, typeSummaryIndex, recordName, iter->second); } void TypeExtractorEmitter::GenTypeLiteralBuffers(panda::pandasm::Program *prog, @@ -154,8 +231,9 @@ void TypeExtractorEmitter::GenTypeLiteralBuffers(panda::pandasm::Program *prog, } for (auto &[idx, buf] : literalBuffers) { + std::string literalId = std::string(recorder->GetRecordName()) + "_" + std::to_string(idx); auto literalArrayInstance = panda::pandasm::LiteralArray(std::move(buf)); - prog->literalarray_table.emplace(std::to_string(idx), std::move(literalArrayInstance)); + prog->literalarray_table.emplace(literalId, std::move(literalArrayInstance)); } } diff --git a/es2panda/compiler/core/emitter/typeExtractorEmitter.h b/es2panda/compiler/core/emitter/typeExtractorEmitter.h index e82b585cf0a3ad48940fefa9b1c162aefae06526..0c85293affdbdceda98b89c76ed26cd50ec88621 100644 --- a/es2panda/compiler/core/emitter/typeExtractorEmitter.h +++ b/es2panda/compiler/core/emitter/typeExtractorEmitter.h @@ -33,27 +33,31 @@ public: NO_COPY_SEMANTIC(TypeExtractorEmitter); NO_MOVE_SEMANTIC(TypeExtractorEmitter); - static void GenTypeInfoRecord(panda::pandasm::Program *prog, bool typeFlag, int64_t typeSummaryIndex); + static void GenTypeInfoRecord(panda::pandasm::Program *prog, bool typeFlag, int64_t typeSummaryIndex, + const std::string &recordName); + static void GenTypeInfoRecordForMergeABC(panda::pandasm::Program *prog, bool typeFlag, int64_t typeSummaryIndex, + const std::string &recordName); static void GenTypeLiteralBuffers(panda::pandasm::Program *prog, const extractor::TypeRecorder *recorder); + static int32_t literalId_; + static constexpr const char *TYPE_INFO_RECORD = "_ESTypeInfoRecord"; static constexpr const char *TYPE_ANNOTATION = "_ESTypeAnnotation"; static constexpr const char *TYPE_INSTRUCTION = "_TypeOfInstruction"; static constexpr const char *TYPE_FLAG = "typeFlag"; - static constexpr const char *TYPE_SUMMARY = "typeSummaryIndex"; - static constexpr const char *EXPORTED_SYMBOLS = "exportedSymbols"; + static constexpr const char *TYPE_SUMMARY = "typeSummaryOffset"; static constexpr const char *EXPORTED_SYMBOL_TYPES = "exportedSymbolTypes"; - static constexpr const char *DECLARED_SYMBOLS = "declaredSymbols"; static constexpr const char *DECLARED_SYMBOL_TYPES = "declaredSymbolTypes"; private: const PandaGen *pg_; panda::pandasm::Function *func_; - void GenFunctionTypeInfo() const; - void GenExportTypeInfo() const; - void GenDeclareTypeInfo() const; + bool IsFuncMain0(const std::string &funcName, bool isMergeAbc) const; + void GenFunctionTypeInfo(panda::pandasm::Program *prog) const; + void GenExportTypeInfo(panda::pandasm::Program *prog) const; + void GenDeclareTypeInfo(panda::pandasm::Program *prog) const; }; } // namespace panda::es2panda::compiler diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 26faa98df35c681ffe3999e36bb5074e2667d666..ae5017dd6f5324023cd8b5f36a1d6595f77dfec3 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -223,15 +224,28 @@ void PandaGen::CopyFunctionArguments(const ir::AstNode *node) StoreLexicalVar(node, 0, param->LexIdx(), targetReg++); continue; } - if (context_->IsTypeExtractorEnabled()) { - auto typeIndex = context_->TypeRecorder()->GetVariableTypeIndex(param); - if (typeIndex != extractor::TypeRecorder::PRIMITIVETYPE_ANY) { - // Simply encode type index for params - MoveVregWithType(node, -(typeIndex + 1), param->Vreg(), targetReg++); - continue; + MoveVreg(node, param->Vreg(), targetReg++); + } + + auto fn = [this](const ir::AstNode *node) { + // For function type, node here is ScriptFunction or BlockStatement + if (node->IsScriptFunction()) { + typedFunc_.first = context_->TypeRecorder()->GetNodeTypeIndex(node); + } + // For method 'this' type, node's parent should be FunctionExpression + if (node->Parent() != nullptr && node->Parent()->Parent() != nullptr) { + auto method = node->Parent()->Parent(); + if (method->IsMethodDefinition()) { + auto typeIndex = context_->TypeRecorder()->GetNodeTypeIndex(method->Parent()); + if (!method->AsMethodDefinition()->IsStatic()) { + typeIndex = context_->TypeRecorder()->GetClassInst(typeIndex); + } + typedFunc_.second = typeIndex; } } - MoveVreg(node, param->Vreg(), targetReg++); + }; + if (context_->IsTypeExtractorEnabled()) { + fn(node); } } @@ -695,11 +709,6 @@ void PandaGen::MoveVreg(const ir::AstNode *node, VReg vd, VReg vs) ra_.Emit(node, vd, vs); } -void PandaGen::MoveVregWithType(const ir::AstNode *node, int64_t typeIndex, VReg vd, VReg vs) -{ - ra_.EmitWithType(node, typeIndex, vd, vs); -} - void PandaGen::SetLabel([[maybe_unused]] const ir::AstNode *node, Label *label) { ra_.AddLabel(label); @@ -1799,15 +1808,35 @@ void PandaGen::StoreLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t ra_.Emit(node, level, slot); } -void PandaGen::StoreLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t slot, const util::StringView &name) +void PandaGen::StoreLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t slot, + const binder::LocalVariable *local) { if (context_->HotfixHelper() && context_->HotfixHelper()->IsPatchVar(slot)) { - uint32_t patchSlot = context_->HotfixHelper()->GetPatchLexicalIdx(std::string(name)); + uint32_t patchSlot = context_->HotfixHelper()->GetPatchLexicalIdx(std::string(local->Name())); ra_.Emit(node, patchSlot); return; } RegScope rs(this); VReg value = AllocReg(); + if (context_->IsTypeExtractorEnabled()) { + auto typeIndex = context_->TypeRecorder()->GetVariableTypeIndex(local); + if (typeIndex != extractor::TypeRecorder::PRIMITIVETYPE_ANY) { + StoreAccumulatorWithType(node, typeIndex, value); + DCOUT << "[LOG]Lexical vreg in variable has type index: " << local->Name() << "@" << + local << " | " << typeIndex << std::endl; + StoreLexicalVar(node, level, slot, value); + return; + } + typeIndex = context_->TypeRecorder()->GetNodeTypeIndex(node); + if (typeIndex != extractor::TypeRecorder::PRIMITIVETYPE_ANY) { + StoreAccumulatorWithType(node, typeIndex, value); + DCOUT << "[LOG]Lexical vreg in declnode has type index: " << local->Name() << "@" << + local << " | " << typeIndex << std::endl; + StoreLexicalVar(node, level, slot, value); + return; + } + DCOUT << "[WARNING]Lexical vreg lose type index: " << local->Name() << "@" << local << std::endl; + } StoreAccumulator(node, value); StoreLexicalVar(node, level, slot, value); } diff --git a/es2panda/compiler/core/pandagen.h b/es2panda/compiler/core/pandagen.h index 26b53b69f10f116b44a04e7402f93a7c8a39fe1f..b947192568ff96c64c85b0ed0498fee500639e27 100644 --- a/es2panda/compiler/core/pandagen.h +++ b/es2panda/compiler/core/pandagen.h @@ -156,6 +156,16 @@ public: return typedInsns_; } + std::pair &TypedFunc() + { + return typedFunc_; + } + + const std::pair &TypedFunc() const + { + return typedFunc_; + } + VReg AllocReg() { if (usedRegs_ > UINT16_MAX) { @@ -293,7 +303,6 @@ public: void LoadConst(const ir::AstNode *node, Constant id); void StoreConst(const ir::AstNode *node, VReg reg, Constant id); void MoveVreg(const ir::AstNode *node, VReg vd, VReg vs); - void MoveVregWithType(const ir::AstNode *node, int64_t typeIndex, VReg vd, VReg vs); void SetLabel(const ir::AstNode *node, Label *label); void Branch(const ir::AstNode *node, class Label *label); @@ -417,7 +426,7 @@ public: void LoadLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t slot); void LoadLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t slot, const util::StringView &name); void StoreLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t slot); - void StoreLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t slot, const util::StringView &name); + void StoreLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t slot, const binder::LocalVariable *local); void StoreLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t slot, VReg value); void StoreLexicalEnv(const ir::AstNode *node); @@ -484,6 +493,7 @@ private: const ir::AstNode *rootNode_; ArenaList insns_; ArenaMap typedInsns_; + std::pair typedFunc_ {}; ArenaVector catchList_; ArenaSet strings_; ArenaVector buffStorage_; diff --git a/es2panda/ir/expressions/literal.cpp b/es2panda/ir/expressions/literal.cpp index 26a1920a5a0314e05ac2fa80c15168ee29044c44..367b717536f3d04d584bc661dd4685bfa76c1a06 100644 --- a/es2panda/ir/expressions/literal.cpp +++ b/es2panda/ir/expressions/literal.cpp @@ -43,8 +43,11 @@ double Literal::GetDouble() const const util::StringView &Literal::GetString() const { - ASSERT(IsStringLiteral()); - return AsStringLiteral()->Str(); + if (IsStringLiteral()) { + return AsStringLiteral()->Str(); + } + ASSERT(IsNumberLiteral()); + return AsNumberLiteral()->Str(); } const util::StringView &Literal::GetMethod() const @@ -62,7 +65,7 @@ uint16_t Literal::GetMethodAffiliate() const std::optional Literal::GetName() const { if (IsStringLiteral()) { - return GetString(); + return AsStringLiteral()->Str(); } if (IsNumberLiteral()) { return AsNumberLiteral()->Str(); diff --git a/es2panda/ir/expressions/literal.h b/es2panda/ir/expressions/literal.h index bb3d5e5b8b242040a852908a6570c4cef0ca5243..c842a4137ac334ac8f2ff6af033ca05d6da0066f 100644 --- a/es2panda/ir/expressions/literal.h +++ b/es2panda/ir/expressions/literal.h @@ -44,6 +44,8 @@ enum class LiteralTag { // 0x0a - 0x15 for ARRAY_Type ASYNC_GENERATOR_METHOD = 22, LITERALBUFFERINDEX = 23, + LITERALARRAY = 24, + BUILTINTYPEINDEX = 25, NULL_VALUE = 255, }; diff --git a/es2panda/ir/expressions/literals/numberLiteral.h b/es2panda/ir/expressions/literals/numberLiteral.h index 1aaf97960eb7e59c736352f3394c112725d69413..6684b5ff43d9d0161765a8a721cf0e31b9b04809 100644 --- a/es2panda/ir/expressions/literals/numberLiteral.h +++ b/es2panda/ir/expressions/literals/numberLiteral.h @@ -72,6 +72,26 @@ private: util::StringView str_; }; +class UserTypeIndexLiteral : public NumberLiteral { +public: + explicit UserTypeIndexLiteral(double num, util::StringView str) : NumberLiteral(num, str) {} + + LiteralTag Tag() const override + { + return LiteralTag::LITERALARRAY; + } +}; + +class BuiltinTypeIndexLiteral : public NumberLiteral { +public: + explicit BuiltinTypeIndexLiteral(double num) : NumberLiteral(num) {} + + LiteralTag Tag() const override + { + return LiteralTag::BUILTINTYPEINDEX; + } +}; + } // namespace panda::es2panda::ir #endif /* NUMBER_LITERAL_H */ diff --git a/es2panda/typescript/extractor/typeExtractor.cpp b/es2panda/typescript/extractor/typeExtractor.cpp index a23648674d6e5ce85a7ea51aea38a247917f8953..543b4652aca8102b20a89a4db3f67a98b9701c66 100644 --- a/es2panda/typescript/extractor/typeExtractor.cpp +++ b/es2panda/typescript/extractor/typeExtractor.cpp @@ -269,7 +269,7 @@ const ir::AstNode *TypeExtractor::GetDeclNodeFromIdentifier(const ir::Identifier } for (const auto &v : variables) { - if (v != nullptr && v->Declaration() != nullptr && v->Declaration()->Node() == nullptr) { + if (v == nullptr || v->Declaration() == nullptr || v->Declaration()->Node() == nullptr) { continue; } diff --git a/es2panda/typescript/extractor/typeExtractor.h b/es2panda/typescript/extractor/typeExtractor.h index 51d4fd245b6e6e3abb1320d84be62b9f6acaab52..524e5f0700f4b54028c91d05058fd8e21678c098 100644 --- a/es2panda/typescript/extractor/typeExtractor.h +++ b/es2panda/typescript/extractor/typeExtractor.h @@ -44,6 +44,7 @@ public: int64_t GetTypeIndexFromAnnotation(const ir::Expression *typeAnnotation); int64_t GetTypeIndexFromIdentifier(const ir::Identifier *identifier); int64_t GetTypeIndexFromInitializer(const ir::Expression *initializer); + int64_t GetTypeIndexFromClassInst(int64_t typeIndex); void SetGenericParamTypeMap(const ArenaMap *genericParamTypeMap) { @@ -64,7 +65,7 @@ private: std::unique_ptr recorder_; std::unordered_map getterMap_; std::unordered_map handlerMap_; - const ArenaMap *genericParamTypeMap_; + const ArenaMap *genericParamTypeMap_ {nullptr}; void ExtractNodesType(const ir::AstNode *parent); void ExtractNodeType(const ir::AstNode *parent, const ir::AstNode *childNode); @@ -94,7 +95,6 @@ private: void HandleTypeAliasDeclaration(const ir::AstNode *node); // Helpers - int64_t GetTypeIndexFromClassInst(int64_t typeIndex); int64_t GetTypeIndexFromTypeReference(const ir::TSTypeReference *typeReference); int64_t GetTypeIndexFromTSLiteralType(const ir::TSLiteralType *tsLiteralType); diff --git a/es2panda/typescript/extractor/typeRecorder.cpp b/es2panda/typescript/extractor/typeRecorder.cpp index 2098a409ba14884add857c4153a7a55f372a5506..4b071d3fa8c6a83078e3af327a3877fc09b1dc1d 100644 --- a/es2panda/typescript/extractor/typeRecorder.cpp +++ b/es2panda/typescript/extractor/typeRecorder.cpp @@ -90,6 +90,11 @@ void TypeRecorder::SetLiteralBuffer(int64_t index, compiler::LiteralBuffer *buff buffer->SetIndex(index); } +util::StringView TypeRecorder::GetRecordName() const +{ + return context_->Binder()->Program()->RecordName(); +} + util::StringView TypeRecorder::GetAnonymousFunctionNames(const ir::ScriptFunction *func) const { const auto &m = context_->Binder()->AnonymousFunctionNames(); @@ -97,9 +102,9 @@ util::StringView TypeRecorder::GetAnonymousFunctionNames(const ir::ScriptFunctio return (res != m.end()) ? std::move(res->second) : std::move(DEFAULT_NAME); } -int64_t TypeRecorder::CalculateUserType() const +const std::set &TypeRecorder::GetUserType() const { - return userType_.size(); + return userType_; } void TypeRecorder::AddUserType(int64_t index) diff --git a/es2panda/typescript/extractor/typeRecorder.h b/es2panda/typescript/extractor/typeRecorder.h index 11519d490f113abe21265e59d17f8d1c64db0ab0..5f83102da4104d6fa370696435f5eb49ed866037 100644 --- a/es2panda/typescript/extractor/typeRecorder.h +++ b/es2panda/typescript/extractor/typeRecorder.h @@ -51,9 +51,10 @@ public: compiler::LiteralBuffer *GetLiteralBuffer(int64_t index) const; void SetLiteralBuffer(int64_t index, compiler::LiteralBuffer *buffer); + util::StringView GetRecordName() const; util::StringView GetAnonymousFunctionNames(const ir::ScriptFunction *func) const; - int64_t CalculateUserType() const; + const std::set &GetUserType() const; void AddUserType(int64_t index); int64_t GetTypeSummaryIndex() const; diff --git a/es2panda/typescript/extractor/typeSystem.h b/es2panda/typescript/extractor/typeSystem.h index c7fb96430c6e9958e1f3da3af5d33e4f3ff5f649..d3c1dfda5372e36f95c6b4edd62a0e52bfb0838c 100644 --- a/es2panda/typescript/extractor/typeSystem.h +++ b/es2panda/typescript/extractor/typeSystem.h @@ -261,6 +261,20 @@ protected: TypeRecorder *recorder_; compiler::LiteralBuffer *buffer_; + void FillTypeIndexLiteralBuffer(int64_t typeIndex) + { + if (typeIndex >= recorder_->GetUserTypeIndexShift()) { + std::stringstream ss; + ss << std::string(recorder_->GetRecordName()) << "_" << (typeIndex - recorder_->GetUserTypeIndexShift()); + buffer_->Add(recorder_->Allocator()->New(typeIndex, + util::UString(ss.str(), recorder_->Allocator()).View())); + } else if (typeIndex >= PrimitiveType::ANY) { + buffer_->Add(recorder_->Allocator()->New(typeIndex)); + } else { + buffer_->Add(recorder_->Allocator()->New(typeIndex)); + } + } + void CalculateIndex(const util::StringView &name, int64_t &typeIndex, int64_t &typeIndexShift, bool forBuiltin) { if (forBuiltin && extractor_->GetTypeDtsBuiltin()) { @@ -343,14 +357,16 @@ public: void FillLiteralBuffer() { - int64_t userTypeNumber = recorder_->CalculateUserType(); - buffer_->Add(recorder_->Allocator()->New(UserType::COUNTER)); + const auto &userType = recorder_->GetUserType(); if (extractor_->GetTypeDtsExtractor()) { - buffer_->Add(recorder_->Allocator()->New(userTypeNumber + + buffer_->Add(recorder_->Allocator()->New(userType.size() + TypeRecorder::USERTYPEINDEXHEAD - BuiltinType::BT_HEAD)); } else { - buffer_->Add(recorder_->Allocator()->New(userTypeNumber)); + buffer_->Add(recorder_->Allocator()->New(userType.size())); } + std::for_each(userType.begin(), userType.end(), [this](const auto &t) { + FillTypeIndexLiteralBuffer(t); + }); const auto &anonymousReExport = recorder_->GetAnonymousReExport(); buffer_->Add(recorder_->Allocator()->New(anonymousReExport.size())); std::for_each(anonymousReExport.begin(), anonymousReExport.end(), [this](const auto &t) { @@ -393,13 +409,13 @@ private: void FillLiteralBuffer(const ArenaMap *indexSignatures) { buffer_->Add(recorder_->Allocator()->New(UserType::INDEXSIG)); - buffer_->Add(recorder_->Allocator()->New(typeIndexRefShift_)); + FillTypeIndexLiteralBuffer(typeIndexRefShift_); ASSERT(indexSignatures != nullptr); buffer_->Add(recorder_->Allocator()->New(indexSignatures->size())); std::for_each(indexSignatures->begin(), indexSignatures->end(), [this](const auto &t) { - buffer_->Add(recorder_->Allocator()->New(t.first)); - buffer_->Add(recorder_->Allocator()->New(t.second)); + FillTypeIndexLiteralBuffer(t.first); + FillTypeIndexLiteralBuffer(t.second); }); } }; @@ -563,19 +579,19 @@ private: buffer_->Add(recorder_->Allocator()->New(name_)); if (containThis_) { buffer_->Add(recorder_->Allocator()->New(1)); - buffer_->Add(recorder_->Allocator()->New(paramsTypeIndex_.at(0))); + FillTypeIndexLiteralBuffer(paramsTypeIndex_.at(0)); buffer_->Add(recorder_->Allocator()->New(paramsTypeIndex_.size() - 1)); for (size_t i = 1; i < paramsTypeIndex_.size(); i++) { - buffer_->Add(recorder_->Allocator()->New(paramsTypeIndex_.at(i))); + FillTypeIndexLiteralBuffer(paramsTypeIndex_.at(i)); } } else { buffer_->Add(recorder_->Allocator()->New(0)); buffer_->Add(recorder_->Allocator()->New(paramsTypeIndex_.size())); for (size_t i = 0; i < paramsTypeIndex_.size(); i++) { - buffer_->Add(recorder_->Allocator()->New(paramsTypeIndex_.at(i))); + FillTypeIndexLiteralBuffer(paramsTypeIndex_.at(i)); } } - buffer_->Add(recorder_->Allocator()->New(typeIndexReturn_)); + FillTypeIndexLiteralBuffer(typeIndexReturn_); } }; @@ -638,6 +654,9 @@ private: int64_t typeIndex_ = PrimitiveType::ANY; int64_t typeIndexShift_ = PrimitiveType::ANY; + size_t fieldsWithInitNum_ = 0U; + size_t methodsWithBodyNum_ = 0U; + void FillModifier(const ir::ClassDefinition *classDef) { if (classDef->Abstract()) { @@ -702,6 +721,10 @@ private: fn(identifier->Name()); } } + + if (field->Value() != nullptr) { + fieldsWithInitNum_++; + } } void FillMethod(const ir::MethodDefinition *method) @@ -728,6 +751,10 @@ private: fn(functionType, name); } } + + if (method->Function()->Body() != nullptr) { + methodsWithBodyNum_++; + } } void FillFieldsandMethods(const ir::ClassDefinition *classDef) @@ -748,6 +775,11 @@ private: FillMethod(t->AsMethodDefinition()); } } + + // Create class instance type stands for 'this' + if (!classDef->Abstract() && (fieldsWithInitNum_ > 0U || methodsWithBodyNum_ > 0U)) { + (void)extractor_->GetTypeIndexFromClassInst(typeIndexShift_); + } } void FillIndexSignatures(const ir::ClassDefinition *classDef) @@ -772,7 +804,7 @@ private: buffer_->Add(recorder_->Allocator()->New(map.size())); std::for_each(map.begin(), map.end(), [this](const auto &t) { buffer_->Add(recorder_->Allocator()->New(t.first)); - buffer_->Add(recorder_->Allocator()->New(t.second[0])); // 0. typeIndex + FillTypeIndexLiteralBuffer(t.second[0]); // 0. typeIndex buffer_->Add(recorder_->Allocator()->New(t.second[1])); // 1. accessFlag buffer_->Add(recorder_->Allocator()->New(t.second[2])); // 2. modifier }); @@ -791,7 +823,7 @@ private: buffer_->Add(recorder_->Allocator()->New(map.size())); std::for_each(map.begin(), map.end(), [this](const auto &t) { buffer_->Add(recorder_->Allocator()->New(t.first)); - buffer_->Add(recorder_->Allocator()->New(t.second)); + FillTypeIndexLiteralBuffer(t.second); }); }; @@ -806,10 +838,10 @@ private: { buffer_->Add(recorder_->Allocator()->New(UserType::CLASS)); buffer_->Add(recorder_->Allocator()->New(modifierAB_)); - buffer_->Add(recorder_->Allocator()->New(extendsHeritage_)); + FillTypeIndexLiteralBuffer(extendsHeritage_); buffer_->Add(recorder_->Allocator()->New(implementsHeritages_.size())); std::for_each(implementsHeritages_.begin(), implementsHeritages_.end(), [this](const auto &t) { - buffer_->Add(recorder_->Allocator()->New(t)); + FillTypeIndexLiteralBuffer(t); }); FillFieldsLiteralBuffer(false); @@ -849,7 +881,7 @@ private: void FillLiteralBuffer() { buffer_->Add(recorder_->Allocator()->New(UserType::CLASSINST)); - buffer_->Add(recorder_->Allocator()->New(typeIndexRefShift_)); + FillTypeIndexLiteralBuffer(typeIndexRefShift_); } }; @@ -992,7 +1024,7 @@ private: buffer_->Add(recorder_->Allocator()->New(fields_.size())); std::for_each(fields_.begin(), fields_.end(), [this](const auto &t) { buffer_->Add(recorder_->Allocator()->New(t.first)); - buffer_->Add(recorder_->Allocator()->New(t.second[0])); // 0. typeIndex + FillTypeIndexLiteralBuffer(t.second[0]); // 0. typeIndex buffer_->Add(recorder_->Allocator()->New(t.second[1])); // 1. accessFlag buffer_->Add(recorder_->Allocator()->New(t.second[2])); // 2. modifier }); @@ -1002,7 +1034,7 @@ private: { buffer_->Add(recorder_->Allocator()->New(methods_.size())); std::for_each(methods_.begin(), methods_.end(), [this](const auto &t) { - buffer_->Add(recorder_->Allocator()->New(t)); + FillTypeIndexLiteralBuffer(t); }); } @@ -1011,7 +1043,7 @@ private: buffer_->Add(recorder_->Allocator()->New(UserType::INTERFACE)); buffer_->Add(recorder_->Allocator()->New(heritages_.size())); std::for_each(heritages_.begin(), heritages_.end(), [this](const auto &t) { - buffer_->Add(recorder_->Allocator()->New(t)); + FillTypeIndexLiteralBuffer(t); }); FillFieldsLiteralBuffer(); @@ -1025,7 +1057,7 @@ public: const util::StringView &redirectPath) : BaseType(extractor) { std::stringstream ss; - ss << "#" + std::string(importName) + "#" + std::string(redirectPath); + ss << "#" << std::string(importName) << "#" << std::string(redirectPath); redirectPath_ = util::UString(ss.str(), recorder_->Allocator()).View(); typeIndex_ = recorder_->AddLiteralBuffer(buffer_); typeIndexShift_ = typeIndex_ + recorder_->GetUserTypeIndexShift(); @@ -1099,7 +1131,7 @@ private: buffer_->Add(recorder_->Allocator()->New(UserType::UNION)); buffer_->Add(recorder_->Allocator()->New(unionTypes_.size())); std::for_each(unionTypes_.begin(), unionTypes_.end(), [this](const auto &t) { - buffer_->Add(recorder_->Allocator()->New(t)); + FillTypeIndexLiteralBuffer(t); }); } }; @@ -1138,7 +1170,7 @@ private: void FillLiteralBuffer() { buffer_->Add(recorder_->Allocator()->New(UserType::ARRAY)); - buffer_->Add(recorder_->Allocator()->New(typeIndexRefShift_)); + FillTypeIndexLiteralBuffer(typeIndexRefShift_); } }; @@ -1259,11 +1291,11 @@ private: buffer_->Add(recorder_->Allocator()->New(properties_.size())); std::for_each(properties_.begin(), properties_.end(), [this](const auto &t) { buffer_->Add(recorder_->Allocator()->New(t.first)); - buffer_->Add(recorder_->Allocator()->New(t.second)); + FillTypeIndexLiteralBuffer(t.second); }); buffer_->Add(recorder_->Allocator()->New(methods_.size())); std::for_each(methods_.begin(), methods_.end(), [this](const auto &t) { - buffer_->Add(recorder_->Allocator()->New(t)); + FillTypeIndexLiteralBuffer(t); }); } }; @@ -1307,10 +1339,10 @@ private: void FillLiteralBuffer() { buffer_->Add(recorder_->Allocator()->New(UserType::BUILTININST)); - buffer_->Add(recorder_->Allocator()->New(typeIndexBuiltin_)); + FillTypeIndexLiteralBuffer(typeIndexBuiltin_); buffer_->Add(recorder_->Allocator()->New(paramTypes_.size())); std::for_each(paramTypes_.begin(), paramTypes_.end(), [this](const auto &t) { - buffer_->Add(recorder_->Allocator()->New(t)); + FillTypeIndexLiteralBuffer(t); }); } }; @@ -1354,10 +1386,10 @@ private: void FillLiteralBuffer() { buffer_->Add(recorder_->Allocator()->New(UserType::GENERICINST)); - buffer_->Add(recorder_->Allocator()->New(typeIndexGeneric_)); + FillTypeIndexLiteralBuffer(typeIndexGeneric_); buffer_->Add(recorder_->Allocator()->New(paramTypes_.size())); std::for_each(paramTypes_.begin(), paramTypes_.end(), [this](const auto &t) { - buffer_->Add(recorder_->Allocator()->New(t)); + FillTypeIndexLiteralBuffer(t); }); } }; diff --git a/es2panda/util/ustring.h b/es2panda/util/ustring.h index f3df4024f160eeccc96bf9d4f3ceac601895d64d..dc73aaf4e1f07af186483a84adea0bfb3665096a 100644 --- a/es2panda/util/ustring.h +++ b/es2panda/util/ustring.h @@ -478,4 +478,10 @@ ostream &operator<<(ostream &os, const panda::es2panda::util::StringView &us); } // namespace std +#ifndef NDEBUG +#define DCOUT std::cout +#else +#define DCOUT false && std::cout +#endif // NDEBUG + #endif