From b915ce3041812be1291a47e729caf37b5be6024b Mon Sep 17 00:00:00 2001 From: dong Date: Thu, 27 Jul 2023 11:03:52 +0800 Subject: [PATCH 1/3] 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 5067793008ec815c5a621eb1befbf97c4a358314 Mon Sep 17 00:00:00 2001 From: dong Date: Wed, 9 Aug 2023 14:16:51 +0800 Subject: [PATCH 2/3] 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 686ba8209183ea81978eb207fb056b94e4fb78bb Mon Sep 17 00:00:00 2001 From: dong Date: Wed, 9 Aug 2023 14:23:27 +0800 Subject: [PATCH 3/3] 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