From b915ce3041812be1291a47e729caf37b5be6024b Mon Sep 17 00:00:00 2001 From: dong Date: Thu, 27 Jul 2023 11:03:52 +0800 Subject: [PATCH 1/4] Add the argument of compile command Issue: I7ODQS Signed-off-by: dong Change-Id: I64678d5204dad80fd2795db8efb3d178a297e885 --- es2panda/aot/main.cpp | 1 + es2panda/aot/options.cpp | 3 +++ es2panda/aot/options.h | 6 ++++++ es2panda/compiler/core/emitter/emitter.cpp | 9 +++++++-- es2panda/es2panda.cpp | 1 + es2panda/es2panda.h | 1 + legacy_bin/api8/package-lock.json | 5 +++++ 7 files changed, 24 insertions(+), 2 deletions(-) diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index ecb6860511..e604f1ded8 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -176,6 +176,7 @@ int Run(int argc, const char **argv) std::cerr << options->ErrorMsg() << std::endl; return 1; } + CompilerOptions::staticShowSource = options->SourceCode(); if (options->CompilerOptions().bcVersion || options->CompilerOptions().bcMinVersion) { std::string version = options->CompilerOptions().bcVersion ? diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 95085c9067..07da41fa0b 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -199,6 +199,7 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opDumpTransformedAst("dump-transformed-ast", false, "Dump the parsed AST after transform"); panda::PandArg opCheckTransformedAstStructure("check-transformed-ast-structure", false, "Check the AST structure after transform"); + panda::PandArg opShowSourceCode("showsource", false, "Show the source code"); // type extractor panda::PandArg opTypeExtractor("type-extractor", false, "Enable type extractor for typescript"); @@ -249,6 +250,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opDumpAst); argparser_->Add(&opDumpTransformedAst); argparser_->Add(&opCheckTransformedAstStructure); + argparser_->Add(&opShowSourceCode); argparser_->Add(&opParseOnly); argparser_->Add(&opEnableTypeCheck); argparser_->Add(&opTypeExtractor); @@ -433,6 +435,7 @@ bool Options::Parse(int argc, const char **argv) options_ |= OptionFlags::SIZE_STAT; } + sourceCode_ = opShowSourceCode.GetValue(); compilerOptions_.dumpAsm = opDumpAssembly.GetValue(); compilerOptions_.dumpAst = opDumpAst.GetValue(); compilerOptions_.dumpTransformedAst = opDumpTransformedAst.GetValue(); diff --git a/es2panda/aot/options.h b/es2panda/aot/options.h index 00a2b7cf99..0b73fa351e 100644 --- a/es2panda/aot/options.h +++ b/es2panda/aot/options.h @@ -131,6 +131,11 @@ public: bool CollectInputFilesFromFileDirectory(const std::string &input, const std::string &extension); void ParseCacheFileOption(const std::string &cacheInput); + bool SourceCode() const + { + return sourceCode_; + } + private: es2panda::CompilerOptions compilerOptions_ {}; es2panda::parser::ScriptKind scriptKind_ {es2panda::parser::ScriptKind::SCRIPT}; @@ -143,6 +148,7 @@ private: std::string recordName_; std::string errorMsg_; std::string compilerProtoOutput_; + bool sourceCode_; int optLevel_ {0}; int functionThreadCount_ {0}; int fileThreadCount_ {0}; diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 6a4a4b98cf..7f07ab7641 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -247,11 +247,16 @@ void FunctionEmitter::GenFunctionSource() return; } - if (!(static_cast(pg_->RootNode()))->ShowSource()) { + if(panda::es2panda::CompilerOptions::staticShowSource){ + func_->source_code = SourceCode().Mutf8(); return; } - func_->source_code = SourceCode().Mutf8(); + if ((static_cast(pg_->RootNode()))->ShowSource()) { + func_->source_code = SourceCode().Mutf8(); + return; + } + } void FunctionEmitter::GenScopeVariableInfo(const binder::Scope *scope) diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 13bde87984..e90f136d36 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -31,6 +31,7 @@ namespace panda::es2panda { // Compiler constexpr size_t DEFAULT_THREAD_COUNT = 2; +bool CompilerOptions::staticShowSource = false; Compiler::Compiler(ScriptExtension ext) : Compiler(ext, DEFAULT_THREAD_COUNT) {} diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index a1778653f5..0795c1dd6d 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -94,6 +94,7 @@ struct CompilerOptions { bool bcVersion {false}; bool bcMinVersion {false}; std::unordered_map cacheFiles; + static bool staticShowSource; }; enum class ErrorType { diff --git a/legacy_bin/api8/package-lock.json b/legacy_bin/api8/package-lock.json index 4f5ea9f21e..692033ca26 100644 --- a/legacy_bin/api8/package-lock.json +++ b/legacy_bin/api8/package-lock.json @@ -8,6 +8,11 @@ "version": "9.4.0", "resolved": "https://repo.huaweicloud.com/repository/npm/commander/-/commander-9.4.0.tgz", "integrity": "sha512-sRPT+umqkz90UA8M1yqYfnHlZA7fF6nSphDtxeywPZ49ysjxDQybzk13CL+mXekDRG92skbcqCLVovuCusNmFw==" + }, + "typescript": { + "version": "4.2.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/typescript/-/typescript-4.2.3.tgz", + "integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==" } } } -- Gitee From 0346b0b10240dff20da392c887e03277c3cc79fe Mon Sep 17 00:00:00 2001 From: dong Date: Wed, 9 Aug 2023 14:23:27 +0800 Subject: [PATCH 2/4] revise Signed-off-by: dong Change-Id: I8e92f7503bb4c1b60de46101158a510efb3e6892 --- legacy_bin/api8/package-lock.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/legacy_bin/api8/package-lock.json b/legacy_bin/api8/package-lock.json index 692033ca26..4f5ea9f21e 100644 --- a/legacy_bin/api8/package-lock.json +++ b/legacy_bin/api8/package-lock.json @@ -8,11 +8,6 @@ "version": "9.4.0", "resolved": "https://repo.huaweicloud.com/repository/npm/commander/-/commander-9.4.0.tgz", "integrity": "sha512-sRPT+umqkz90UA8M1yqYfnHlZA7fF6nSphDtxeywPZ49ysjxDQybzk13CL+mXekDRG92skbcqCLVovuCusNmFw==" - }, - "typescript": { - "version": "4.2.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/typescript/-/typescript-4.2.3.tgz", - "integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==" } } } -- Gitee From b7e0da6560ee0fd634c9610ebc8891f11aeb9f97 Mon Sep 17 00:00:00 2001 From: dong Date: Wed, 9 Aug 2023 14:16:51 +0800 Subject: [PATCH 3/4] Signed-off-by: dong Change-Id: I06988832e4ce32bb10a783f77b012543b9cef291 --- es2panda/aot/main.cpp | 2 +- es2panda/aot/options.cpp | 6 +++--- es2panda/aot/options.h | 6 +++--- es2panda/compiler/core/emitter/emitter.cpp | 7 +------ 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index e604f1ded8..1b0587e9a0 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -176,7 +176,7 @@ int Run(int argc, const char **argv) std::cerr << options->ErrorMsg() << std::endl; return 1; } - CompilerOptions::staticShowSource = options->SourceCode(); + CompilerOptions::staticShowSource = options->RecordSource(); if (options->CompilerOptions().bcVersion || options->CompilerOptions().bcMinVersion) { std::string version = options->CompilerOptions().bcVersion ? diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 07da41fa0b..89cc07bb4d 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -199,7 +199,7 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opDumpTransformedAst("dump-transformed-ast", false, "Dump the parsed AST after transform"); panda::PandArg opCheckTransformedAstStructure("check-transformed-ast-structure", false, "Check the AST structure after transform"); - panda::PandArg opShowSourceCode("showsource", false, "Show the source code"); + panda::PandArg opRecordSource("record-source", false, "Show the source code"); // type extractor panda::PandArg opTypeExtractor("type-extractor", false, "Enable type extractor for typescript"); @@ -250,7 +250,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opDumpAst); argparser_->Add(&opDumpTransformedAst); argparser_->Add(&opCheckTransformedAstStructure); - argparser_->Add(&opShowSourceCode); + argparser_->Add(&opRecordSource); argparser_->Add(&opParseOnly); argparser_->Add(&opEnableTypeCheck); argparser_->Add(&opTypeExtractor); @@ -435,7 +435,7 @@ bool Options::Parse(int argc, const char **argv) options_ |= OptionFlags::SIZE_STAT; } - sourceCode_ = opShowSourceCode.GetValue(); + recordSource_ = opRecordSource.GetValue(); compilerOptions_.dumpAsm = opDumpAssembly.GetValue(); compilerOptions_.dumpAst = opDumpAst.GetValue(); compilerOptions_.dumpTransformedAst = opDumpTransformedAst.GetValue(); diff --git a/es2panda/aot/options.h b/es2panda/aot/options.h index 0b73fa351e..1e4da262e5 100644 --- a/es2panda/aot/options.h +++ b/es2panda/aot/options.h @@ -131,9 +131,9 @@ public: bool CollectInputFilesFromFileDirectory(const std::string &input, const std::string &extension); void ParseCacheFileOption(const std::string &cacheInput); - bool SourceCode() const + bool RecordSource() const { - return sourceCode_; + return recordSource_; } private: @@ -148,7 +148,7 @@ private: std::string recordName_; std::string errorMsg_; std::string compilerProtoOutput_; - bool sourceCode_; + bool recordSource_; int optLevel_ {0}; int functionThreadCount_ {0}; int fileThreadCount_ {0}; diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 7f07ab7641..af661db774 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -247,12 +247,7 @@ void FunctionEmitter::GenFunctionSource() return; } - if(panda::es2panda::CompilerOptions::staticShowSource){ - func_->source_code = SourceCode().Mutf8(); - return; - } - - if ((static_cast(pg_->RootNode()))->ShowSource()) { + if (panda::es2panda::CompilerOptions::staticShowSource || (static_cast(pg_->RootNode()))->ShowSource()) { func_->source_code = SourceCode().Mutf8(); return; } -- Gitee From eeb33700e96552b31251df2da00c3bfc079e5f2f Mon Sep 17 00:00:00 2001 From: dong Date: Thu, 10 Aug 2023 10:08:04 +0800 Subject: [PATCH 4/4] Signed-off-by: dong Change-Id: I2bf63c17260da62fa02c811dafb06e3b6c2eddb3 --- es2panda/aot/main.cpp | 1 - es2panda/aot/options.cpp | 2 +- es2panda/aot/options.h | 6 ------ es2panda/compiler/core/compilerContext.cpp | 11 +++++++++++ es2panda/compiler/core/compilerContext.h | 10 ++++++++++ es2panda/compiler/core/compilerImpl.cpp | 4 ++-- es2panda/compiler/core/emitter/emitter.cpp | 2 +- es2panda/es2panda.cpp | 1 - es2panda/es2panda.h | 2 +- 9 files changed, 26 insertions(+), 13 deletions(-) diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 1b0587e9a0..ecb6860511 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -176,7 +176,6 @@ int Run(int argc, const char **argv) std::cerr << options->ErrorMsg() << std::endl; return 1; } - CompilerOptions::staticShowSource = options->RecordSource(); if (options->CompilerOptions().bcVersion || options->CompilerOptions().bcMinVersion) { std::string version = options->CompilerOptions().bcVersion ? diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 89cc07bb4d..2aca4f0b9e 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -435,7 +435,7 @@ bool Options::Parse(int argc, const char **argv) options_ |= OptionFlags::SIZE_STAT; } - recordSource_ = opRecordSource.GetValue(); + compilerOptions_.recordSource = opRecordSource.GetValue(); compilerOptions_.dumpAsm = opDumpAssembly.GetValue(); compilerOptions_.dumpAst = opDumpAst.GetValue(); compilerOptions_.dumpTransformedAst = opDumpTransformedAst.GetValue(); diff --git a/es2panda/aot/options.h b/es2panda/aot/options.h index 1e4da262e5..00a2b7cf99 100644 --- a/es2panda/aot/options.h +++ b/es2panda/aot/options.h @@ -131,11 +131,6 @@ public: bool CollectInputFilesFromFileDirectory(const std::string &input, const std::string &extension); void ParseCacheFileOption(const std::string &cacheInput); - bool RecordSource() const - { - return recordSource_; - } - private: es2panda::CompilerOptions compilerOptions_ {}; es2panda::parser::ScriptKind scriptKind_ {es2panda::parser::ScriptKind::SCRIPT}; @@ -148,7 +143,6 @@ private: std::string recordName_; std::string errorMsg_; std::string compilerProtoOutput_; - bool recordSource_; int optLevel_ {0}; int functionThreadCount_ {0}; int fileThreadCount_ {0}; diff --git a/es2panda/compiler/core/compilerContext.cpp b/es2panda/compiler/core/compilerContext.cpp index 78edb8abbd..0080f85f48 100644 --- a/es2panda/compiler/core/compilerContext.cpp +++ b/es2panda/compiler/core/compilerContext.cpp @@ -31,6 +31,17 @@ CompilerContext::CompilerContext(binder::Binder *binder, bool isDebug, bool isDe { } +CompilerContext::CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, + bool isMergeAbc, bool isTypeExtractorEnabled, bool isJsonInputFile, bool isRecordCode, + std::string sourceFile, std::string pkgName, util::StringView recordName, + util::PatchFix *patchFixHelper) + : binder_(binder), isDebug_(isDebug), isDebuggerEvaluateExpressionMode_(isDebuggerEvaluateExpressionMode), + isMergeAbc_(isMergeAbc), isTypeExtractorEnabled_(isTypeExtractorEnabled), isJsonInputFile_(isJsonInputFile), + isRecordCode_(isRecordCode), sourceFile_(sourceFile), pkgName_(pkgName), recordName_(recordName), patchFixHelper_(patchFixHelper), + emitter_(std::make_unique(this)) +{ +} + void CompilerContext::SetTypeRecorder(extractor::TypeRecorder *recorder) { ASSERT(emitter_ != nullptr); diff --git a/es2panda/compiler/core/compilerContext.h b/es2panda/compiler/core/compilerContext.h index 0581f4c2d1..f243790df3 100644 --- a/es2panda/compiler/core/compilerContext.h +++ b/es2panda/compiler/core/compilerContext.h @@ -46,6 +46,10 @@ public: CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, bool isMergeAbc, bool isTypeExtractorEnabled, bool isJsonInputFile, std::string sourceFile, std::string pkgName, util::StringView recordName, util::PatchFix *patchFixHelper); + CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, + bool isMergeAbc, bool isTypeExtractorEnabled, bool isJsonInputFile, bool isRecordCode, std::string sourceFile, + std::string pkgName, util::StringView recordName, util::PatchFix *patchFixHelper); + NO_COPY_SEMANTIC(CompilerContext); NO_MOVE_SEMANTIC(CompilerContext); ~CompilerContext() = default; @@ -134,6 +138,11 @@ public: return isJsonInputFile_; } + bool IsRecordCode() const + { + return isRecordCode_; + } + private: binder::Binder *binder_; int32_t literalBufferIdx_ {0}; @@ -145,6 +154,7 @@ private: bool isTypeExtractorEnabled_; // true when input file is json file bool isJsonInputFile_; + bool isRecordCode_; extractor::TypeRecorder *recorder_ {}; extractor::TypeExtractor *extractor_ {}; std::string sourceFile_; diff --git a/es2panda/compiler/core/compilerImpl.cpp b/es2panda/compiler/core/compilerImpl.cpp index 1d2c8bffc5..823187f1ed 100644 --- a/es2panda/compiler/core/compilerImpl.cpp +++ b/es2panda/compiler/core/compilerImpl.cpp @@ -41,8 +41,8 @@ panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const e { bool isTypeExtractorEnabled = ((program->Extension() == ScriptExtension::TS) && options.typeExtractor); CompilerContext context(program->Binder(), options.isDebug, options.isDebuggerEvaluateExpressionMode, - options.mergeAbc, isTypeExtractorEnabled, false, debugInfoSourceFile, pkgName, - program->RecordName(), patchFixHelper_); + options.mergeAbc, isTypeExtractorEnabled, false, options.recordSource, debugInfoSourceFile, + pkgName, program->RecordName(), patchFixHelper_); ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index af661db774..053ad306f2 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -247,7 +247,7 @@ void FunctionEmitter::GenFunctionSource() return; } - if (panda::es2panda::CompilerOptions::staticShowSource || (static_cast(pg_->RootNode()))->ShowSource()) { + if (pg_->Context()->IsRecordCode() || (static_cast(pg_->RootNode()))->ShowSource()) { func_->source_code = SourceCode().Mutf8(); return; } diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index e90f136d36..13bde87984 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -31,7 +31,6 @@ namespace panda::es2panda { // Compiler constexpr size_t DEFAULT_THREAD_COUNT = 2; -bool CompilerOptions::staticShowSource = false; Compiler::Compiler(ScriptExtension ext) : Compiler(ext, DEFAULT_THREAD_COUNT) {} diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index 0795c1dd6d..76552a3563 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -84,6 +84,7 @@ struct CompilerOptions { bool mergeAbc {false}; bool typeExtractor {false}; bool typeDtsBuiltin {false}; + bool recordSource {false}; int fileThreadCount {0}; int functionThreadCount {0}; int optLevel {0}; @@ -94,7 +95,6 @@ struct CompilerOptions { bool bcVersion {false}; bool bcMinVersion {false}; std::unordered_map cacheFiles; - static bool staticShowSource; }; enum class ErrorType { -- Gitee