diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 681de4c471fd27a7e012319f1b71aa3da57415ec..1d3019047601d8d0d2c18fc3135292cb1f0ef5a7 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -188,10 +188,19 @@ uint32_t FunctionEmitter::UpdateForReturnIns(const ir::AstNode *astNode, panda:: astNode = astNode->AsBlockStatement()->Scope()->Node(); break; } + if (astNode->IsProgram()) { + break; + } astNode = astNode->Parent(); } - pandaIns->ins_debug.line_number = astNode ? astNode->Range().end.line : INVALID_LINE; - columnNum = astNode ? (GetLineIndex().GetLocation(astNode->Range().end).col - OFFSET_COL) : INVALID_COL; + + if (astNode != nullptr && astNode->IsProgram()) { + pandaIns->ins_debug.line_number = pg_->Debuginfo().lastStmt->Range().end.line; + columnNum = GetLineIndex().GetLocation(pg_->Debuginfo().lastStmt->Range().end).col - OFFSET_COL; + } else { + pandaIns->ins_debug.line_number = astNode ? astNode->Range().end.line : INVALID_LINE; + columnNum = astNode ? (GetLineIndex().GetLocation(astNode->Range().end).col - OFFSET_COL) : INVALID_COL; + } } else { pandaIns->ins_debug.line_number = astNode ? astNode->Range().start.line : INVALID_LINE; columnNum = astNode ? (GetLineIndex().GetLocation(astNode->Range().start).col - OFFSET_COL) : INVALID_COL; @@ -467,12 +476,25 @@ void FunctionEmitter::GenAnnotations() void FunctionEmitter::GenFunctionInstructions() { + constexpr size_t INVALID_LINE = -1; + func_->ins.reserve(pg_->Insns().size()); + std::vector pendingInvalidLineIns; + for (const auto *ins : pg_->Insns()) { auto *pandaIns = ins->Transform(); func_->ins.emplace_back(pandaIns); GenInstructionDebugInfo(ins, pandaIns); + + if (pandaIns->ins_debug.line_number == INVALID_LINE) { + pendingInvalidLineIns.push_back(pandaIns); + } else if (!pendingInvalidLineIns.empty()) { + for (auto *invalidIns : pendingInvalidLineIns) { + invalidIns->ins_debug.line_number = pandaIns->ins_debug.line_number; + } + pendingInvalidLineIns.clear(); + } } } diff --git a/es2panda/compiler/core/function.cpp b/es2panda/compiler/core/function.cpp index 98ec8de00793e16be310cc846cbb38edcf3ed877..3564ce0e673b3be7c7e2da62731a701ad2264381 100644 --- a/es2panda/compiler/core/function.cpp +++ b/es2panda/compiler/core/function.cpp @@ -57,11 +57,13 @@ static void CompileSourceBlock(PandaGen *pg, const ir::BlockStatement *block) return; } - const ir::AstNode *associatedNode = block; + const ir::AstNode *lastNode = block; if (!statements.empty()) { - FindLastStatement(associatedNode, statements.back()); + FindLastStatement(lastNode, statements.back()); } - pg->ImplicitReturn(associatedNode); + pg->SetLastStmt(lastNode->AsStatement()); + + pg->ImplicitReturn(lastNode); } static void CompileFunctionParameterDeclaration(PandaGen *pg, const ir::ScriptFunction *func) diff --git a/es2panda/compiler/core/pandagen.h b/es2panda/compiler/core/pandagen.h index da65b30dc49950437b9fb667838d751641707422..a25087c8ff497f969bab7d86fae4fcd423c4e0cf 100644 --- a/es2panda/compiler/core/pandagen.h +++ b/es2panda/compiler/core/pandagen.h @@ -74,6 +74,7 @@ public: ArenaVector variableDebugInfo; const ir::Statement *firstStmt {}; + const ir::Statement *lastStmt {}; }; class PandaGen { @@ -494,6 +495,11 @@ public: debugInfo_.firstStmt = stmt; } + void SetLastStmt(const ir::Statement *stmt) + { + debugInfo_.lastStmt = stmt; + } + [[noreturn]] static void Unimplemented() { throw Error(ErrorType::GENERIC, "Unimplemented code path"); diff --git a/es2panda/test/base64/availableTargetApiVersion/10/expected.txt b/es2panda/test/base64/availableTargetApiVersion/10/expected.txt index ea65d584ae2cfdff4b04e21864de8947fb8f8a77..f2d73b15ece7fbb603fcf14a0ffdcb9be952c436 100644 --- a/es2panda/test/base64/availableTargetApiVersion/10/expected.txt +++ b/es2panda/test/base64/availableTargetApiVersion/10/expected.txt @@ -11,4 +11,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -UEFOREEAAAAAAAAACQAAAGQBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAGABAAAAAAAARAAAAAEAAABEAAAAqgAAAN0AAACEAAAAZAEAAAIAAABsAAAAAwAAAHQAAAAAAAAAgAAAAAEAAACAAAAAqgAAAN0AAACEAAAAngAAAKUAAAAOAQAAMWhlbGxvIHdvcmxkLCB2ZXJzaW9uIDEwIQALcHJpbnQAB3N0cgAzTF9FU1Nsb3ROdW1iZXJBbm5vdGF0aW9uOwAAAAAAgUAAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAAAA0AAAAIgCASsBAAACAAVWAQAABh4BAAAA7u4AABVTbG90TnVtYmVyAAAAAQASAQAABQAAADcHAyEARHBEgUSSPgAASAAAAgA/AQEAYQU/AgIAYQZgBSoDBgBlC2uJAQ4A/////w8AAgARAFABAAA= +UEFOREEAAAAAAAAACQAAAFwBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAFgBAAAAAAAARAAAAAEAAABEAAAAqgAAAN0AAACEAAAAXAEAAAIAAABsAAAAAwAAAHQAAAAAAAAAgAAAAAEAAACAAAAAqgAAAN0AAACEAAAAngAAAKUAAAAOAQAAMWhlbGxvIHdvcmxkLCB2ZXJzaW9uIDEwIQALcHJpbnQAB3N0cgAzTF9FU1Nsb3ROdW1iZXJBbm5vdGF0aW9uOwAAAAAAgUAAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAAAA0AAAAIgCASsBAAACAAVTAQAABh4BAAAA7u4AABVTbG90TnVtYmVyAAAAAQASAQAABQAAADcHAyEARHBEgUSSPgAASAAAAgA/AQEAYQU/AgIAYQZgBSoDBgBlC+MAAAABAABQAQAA diff --git a/es2panda/test/base64/availableTargetApiVersion/11/expected.txt b/es2panda/test/base64/availableTargetApiVersion/11/expected.txt index e4039082c8b3e142fe762b3e74c6659b351f6819..dc6afe740b03823ce45226075df7cc70d7772509 100644 --- a/es2panda/test/base64/availableTargetApiVersion/11/expected.txt +++ b/es2panda/test/base64/availableTargetApiVersion/11/expected.txt @@ -11,4 +11,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -UEFOREEAAAAAAAAACwACAGQBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAGABAAAAAAAARAAAAAEAAABEAAAAqgAAAN0AAACEAAAAZAEAAAIAAABsAAAAAwAAAHQAAAAAAAAAgAAAAAEAAACAAAAAqgAAAN0AAACEAAAAngAAAKUAAAAOAQAAMWhlbGxvIHdvcmxkLCB2ZXJzaW9uIDExIQALcHJpbnQAB3N0cgAzTF9FU1Nsb3ROdW1iZXJBbm5vdGF0aW9uOwAAAAAAgUAAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAAAA0AAAAIgCASsBAAACAAVWAQAABh4BAAAA7u4AABVTbG90TnVtYmVyAAAAAQASAQAABQAAADcHAyEARHBEgUSSPgAASAAAAgA/AQEAYQU/AgIAYQZgBSoDBgBlC2uJAQ4A/////w8AAgARAFABAAA= +UEFOREEAAAAAAAAACwACAFwBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAFgBAAAAAAAARAAAAAEAAABEAAAAqgAAAN0AAACEAAAAXAEAAAIAAABsAAAAAwAAAHQAAAAAAAAAgAAAAAEAAACAAAAAqgAAAN0AAACEAAAAngAAAKUAAAAOAQAAMWhlbGxvIHdvcmxkLCB2ZXJzaW9uIDExIQALcHJpbnQAB3N0cgAzTF9FU1Nsb3ROdW1iZXJBbm5vdGF0aW9uOwAAAAAAgUAAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAAAA0AAAAIgCASsBAAACAAVTAQAABh4BAAAA7u4AABVTbG90TnVtYmVyAAAAAQASAQAABQAAADcHAyEARHBEgUSSPgAASAAAAgA/AQEAYQU/AgIAYQZgBSoDBgBlC+MAAAABAABQAQAA diff --git a/es2panda/test/base64/availableTargetApiVersion/12/expected.txt b/es2panda/test/base64/availableTargetApiVersion/12/expected.txt index 5851b369e143eaff057f4c075e8764ac61acc54e..ed59a63f19b681492b8d9950a31da3ced1b4669f 100644 --- a/es2panda/test/base64/availableTargetApiVersion/12/expected.txt +++ b/es2panda/test/base64/availableTargetApiVersion/12/expected.txt @@ -11,4 +11,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -UEFOREEAAAAAAAAADAAGAKQBAAAAAAAAAAAAAAMAAAA8AAAAAQAAAKABAAABAAAASAAAAAEAAABMAAAAtgAAAOgAAAAbAQAATAEAAJAAAACkAQAABAAAAHQAAAADAAAAhAAAAP////////////////////8GAAAAtgAAAOgAAAAbAQAAkAAAAKoAAACxAAAAMWhlbGxvIHdvcmxkLCB2ZXJzaW9uIDEyIQALcHJpbnQAB3N0cgArTF9FU1Njb3BlTmFtZXNSZWNvcmQ7AAAAAAABAQACAAABAAAA5gAAAAACTAEAAAABADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACBQAAAAgAAF2Z1bmNfbWFpbl8wABNMX0dMT0JBTDsAAAAAAAEAAQIAAAMA//8OAQAAiAIBaQEAAAIABZQBAAAGXAEAAAAAAAAAFVNsb3ROdW1iZXIAAgABAFABAAAFAAAANwcDIQBEcESBRJI+AABIAAACAD8BAQBhBT8CAgBhBmAFKgMGAGULa4kBDgD/////DwACABEAAACOAQAA +UEFOREEAAAAAAAAADAAGAJwBAAAAAAAAAAAAAAMAAAA8AAAAAQAAAJgBAAABAAAASAAAAAEAAABMAAAAtgAAAOgAAAAbAQAATAEAAJAAAACcAQAABAAAAHQAAAADAAAAhAAAAP////////////////////8GAAAAtgAAAOgAAAAbAQAAkAAAAKoAAACxAAAAMWhlbGxvIHdvcmxkLCB2ZXJzaW9uIDEyIQALcHJpbnQAB3N0cgArTF9FU1Njb3BlTmFtZXNSZWNvcmQ7AAAAAAABAQACAAABAAAA5gAAAAACTAEAAAABADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACBQAAAAgAAF2Z1bmNfbWFpbl8wABNMX0dMT0JBTDsAAAAAAAEAAQIAAAMA//8OAQAAiAIBaQEAAAIABZEBAAAGXAEAAAAAAAAAFVNsb3ROdW1iZXIAAgABAFABAAAFAAAANwcDIQBEcESBRJI+AABIAAACAD8BAQBhBT8CAgBhBmAFKgMGAGUL4wAAAAEAAAAAjgEAAA== diff --git a/es2panda/test/base64/availableTargetApiVersion/9/expected.txt b/es2panda/test/base64/availableTargetApiVersion/9/expected.txt index 3a5ba6e9a24ed7dcf3b447e691140b28d93df3de..597f72e8a5b2e5d572afb66b4d1b4e04bfb19411 100644 --- a/es2panda/test/base64/availableTargetApiVersion/9/expected.txt +++ b/es2panda/test/base64/availableTargetApiVersion/9/expected.txt @@ -11,4 +11,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -UEFOREEAAAAAAAAACQAAAGQBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAGABAAAAAAAARAAAAAEAAABEAAAAqQAAANwAAACEAAAAZAEAAAIAAABsAAAAAwAAAHQAAAAAAAAAgAAAAAEAAACAAAAAqQAAANwAAACEAAAAnQAAAKQAAAAOAQAAL2hlbGxvIHdvcmxkLCB2ZXJzaW9uIDkhAAtwcmludAAHc3RyADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACBQAAAAgAAF2Z1bmNfbWFpbl8wABNMX0dMT0JBTDsAAAAAAAEAAQIAAAEAAADPAAAAiAIBKwEAAAIABVYBAAAGHgEAAAAA7u4AABVTbG90TnVtYmVyAAAAAQASAQAABQAAADcHAyEARHBEgUSSPgAASAAAAgA/AQEAYQU/AgIAYQZgBSoDBgBlC2uJAQ4A/////w8AAgARAFABAAA= +UEFOREEAAAAAAAAACQAAAFwBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAFgBAAAAAAAARAAAAAEAAABEAAAAqQAAANwAAACEAAAAXAEAAAIAAABsAAAAAwAAAHQAAAAAAAAAgAAAAAEAAACAAAAAqQAAANwAAACEAAAAnQAAAKQAAAAOAQAAL2hlbGxvIHdvcmxkLCB2ZXJzaW9uIDkhAAtwcmludAAHc3RyADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACBQAAAAgAAF2Z1bmNfbWFpbl8wABNMX0dMT0JBTDsAAAAAAAEAAQIAAAEAAADPAAAAiAIBKwEAAAIABVMBAAAGHgEAAAAA7u4AABVTbG90TnVtYmVyAAAAAQASAQAABQAAADcHAyEARHBEgUSSPgAASAAAAgA/AQEAYQU/AgIAYQZgBSoDBgBlC+MAAAABAABQAQAA diff --git a/es2panda/test/base64/inputFile/expected.txt b/es2panda/test/base64/inputFile/expected.txt index a2846afef5227d1287b350bf9ecbf8e09519353d..3654a956f416cb8ada87a828ecb0aa08beac33a9 100644 --- a/es2panda/test/base64/inputFile/expected.txt +++ b/es2panda/test/base64/inputFile/expected.txt @@ -11,4 +11,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -UEFOREEAAAAAAAAADQABANgBAAAAAAAAAAAAAAQAAAA8AAAAAQAAANQBAAD//////////wEAAABMAAAAqgAAANsAAAAVAQAASAEAAJAAAADYAQAABAAAAHQAAAADAAAAhAAAAP////////////////////8GAAAA2wAAABUBAABIAQAAkAAAAJ4AAAClAAAAGWhlbGxvIHdvcmxkIQALcHJpbnQAB3N0cgBJTF9FU0V4cGVjdGVkUHJvcGVydHlDb3VudEFubm90YXRpb247AAAAAACBQAAAAgAAK0xfRVNTY29wZU5hbWVzUmVjb3JkOwAAAAAAAQEAAgAAAQAAAAsBAAAAAnkBAAAAEWlucHV0LmpzADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACBQAAAAgAAF2Z1bmNfbWFpbl8wABNMX0dMT0JBTDsAAAAAAAEAAQIAAAMA//87AQAAiAIBlgEAAAIABcUBAAAGiQEAAAAAAAAAFVNsb3ROdW1iZXIAAgABAH0BAAAFAAAANwcDIQBEcESBRJI+AABIAAACAD8BAQBhBT8CAgBhBmAFKgMGAGUJCwECEIkBAhAA/////w8AB4sCAAYQEW8AuwEAAA== +UEFOREEAAAAAAAAADQABAMwBAAAAAAAAAAAAAAQAAAA8AAAAAQAAAMgBAAD//////////wEAAABMAAAAqgAAANsAAAAVAQAASAEAAJAAAADMAQAABAAAAHQAAAADAAAAhAAAAP////////////////////8GAAAA2wAAABUBAABIAQAAkAAAAJ4AAAClAAAAGWhlbGxvIHdvcmxkIQALcHJpbnQAB3N0cgBJTF9FU0V4cGVjdGVkUHJvcGVydHlDb3VudEFubm90YXRpb247AAAAAACBQAAAAgAAK0xfRVNTY29wZU5hbWVzUmVjb3JkOwAAAAAAAQEAAgAAAQAAAAsBAAAAAnkBAAAAEWlucHV0LmpzADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACBQAAAAgAAF2Z1bmNfbWFpbl8wABNMX0dMT0JBTDsAAAAAAAEAAQIAAAMA//87AQAAiAIBlgEAAAIABb8BAAAGiQEAAAAAAAAAFVNsb3ROdW1iZXIAAgABAH0BAAAFAAAANwcDIQBEcESBRJI+AABIAAACAD8BAQBhBT8CAgBhBmAFKgMGAGUJC+MADwADiwIAAAAAuwEAAA== diff --git a/es2panda/test/base64/inputString/expected.txt b/es2panda/test/base64/inputString/expected.txt index d2be555c2d4950ea8cc9ef1ee3b18c43edcb9090..16fcc48098652a5117da8ced759d70a7b9d99444 100644 --- a/es2panda/test/base64/inputString/expected.txt +++ b/es2panda/test/base64/inputString/expected.txt @@ -11,4 +11,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -UEFOREEAAAAAAAAADQABAMgBAAAAAAAAAAAAAAQAAAA8AAAAAQAAAMQBAAD//////////wEAAABMAAAAqgAAANsAAAANAQAAQAEAAJAAAADIAQAABAAAAHQAAAADAAAAhAAAAP////////////////////8GAAAA2wAAAA0BAABAAQAAkAAAAJ4AAAClAAAAGWhlbGxvIHdvcmxkIQALcHJpbnQAB3N0cgBJTF9FU0V4cGVjdGVkUHJvcGVydHlDb3VudEFubm90YXRpb247AAAAAACBQAAAAgAAK0xfRVNTY29wZU5hbWVzUmVjb3JkOwAAAAAAAQEAAgAAAQAAAAsBAAAAAnEBAAAAAQAzTF9FU1Nsb3ROdW1iZXJBbm5vdGF0aW9uOwAAAAAAgUAAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAADAP//MwEAAIgCAY4BAAACAAW5AQAABoEBAAAAAAAAABVTbG90TnVtYmVyAAIAAQB1AQAABQAAADcHAyEARHBEgUSSPgAASAAAAgA/AQEAYQU/AgIAYQZgBSoDBgBlC2uJAQ4A/////w8AAgARAACzAQAA +UEFOREEAAAAAAAAADQABAMABAAAAAAAAAAAAAAQAAAA8AAAAAQAAALwBAAD//////////wEAAABMAAAAqgAAANsAAAANAQAAQAEAAJAAAADAAQAABAAAAHQAAAADAAAAhAAAAP////////////////////8GAAAA2wAAAA0BAABAAQAAkAAAAJ4AAAClAAAAGWhlbGxvIHdvcmxkIQALcHJpbnQAB3N0cgBJTF9FU0V4cGVjdGVkUHJvcGVydHlDb3VudEFubm90YXRpb247AAAAAACBQAAAAgAAK0xfRVNTY29wZU5hbWVzUmVjb3JkOwAAAAAAAQEAAgAAAQAAAAsBAAAAAnEBAAAAAQAzTF9FU1Nsb3ROdW1iZXJBbm5vdGF0aW9uOwAAAAAAgUAAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAADAP//MwEAAIgCAY4BAAACAAW2AQAABoEBAAAAAAAAABVTbG90TnVtYmVyAAIAAQB1AQAABQAAADcHAyEARHBEgUSSPgAASAAAAgA/AQEAYQU/AgIAYQZgBSoDBgBlC+MAAAABAAAAswEAAA== diff --git a/es2panda/test/compiler/debugInfo/test-for-loop-expected.txt b/es2panda/test/compiler/debugInfo/test-for-loop-expected.txt index 1de34365394260c519f6047728e4a78fff60c5f9..bcb864ff3ea9982a7ce709ae7b49ab398ae060c8 100644 --- a/es2panda/test/compiler/debugInfo/test-for-loop-expected.txt +++ b/es2panda/test/compiler/debugInfo/test-for-loop-expected.txt @@ -21,7 +21,7 @@ "imms": [], "label": "", "debug_pos_info": { - "sourceLineNum": -1 + "sourceLineNum": 15 } }, { @@ -34,7 +34,7 @@ "imms": [], "label": "", "debug_pos_info": { - "sourceLineNum": -1 + "sourceLineNum": 15 } }, { @@ -47,7 +47,7 @@ "imms": [], "label": "", "debug_pos_info": { - "sourceLineNum": -1 + "sourceLineNum": 15 } }, { @@ -1187,7 +1187,7 @@ "imms": [], "label": "", "debug_pos_info": { - "sourceLineNum": -1 + "sourceLineNum": 26 } }, { @@ -1197,7 +1197,7 @@ "imms": [], "label": "", "debug_pos_info": { - "sourceLineNum": -1 + "sourceLineNum": 26 } } ], diff --git a/es2panda/test/compiler/debugInfo/test-invalid-node-1-expected.txt b/es2panda/test/compiler/debugInfo/test-invalid-node-1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e385fcca755c60d4594a422062bfd12e17822cb1 --- /dev/null +++ b/es2panda/test/compiler/debugInfo/test-invalid-node-1-expected.txt @@ -0,0 +1,981 @@ +{ + "functions": [ + { + "name": ".#*#", + "signature": { + "retType": "any", + "params": [ + "any", + "any", + "any", + "any" + ] + }, + "ins": [ + { + "opcode": "mov", + "regs": [ + 0, + 8 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "mov", + "regs": [ + 1, + 9 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "mov", + "regs": [ + 2, + 10 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "mov", + "regs": [ + 3, + 11 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "tryldglobalbyname", + "regs": [], + "ids": [ + "console" + ], + "imms": [ + 0 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "sta", + "regs": [ + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "lda", + "regs": [ + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "ldobjbyname", + "regs": [], + "ids": [ + "log" + ], + "imms": [ + 1 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "sta", + "regs": [ + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "lda", + "regs": [ + 3 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "sta", + "regs": [ + 7 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "lda", + "regs": [ + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "callthis1", + "regs": [ + 6, + 7 + ], + "ids": [], + "imms": [ + 3 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "return", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + } + ], + "variables": [ + { + "name": "v", + "signature": "any", + "signatureType": "any", + "reg": 3, + "start": 4, + "length": 10 + }, + { + "name": "4funcObj", + "signature": "any", + "signatureType": "any", + "reg": 0, + "start": 4, + "length": 10 + }, + { + "name": "0this", + "signature": "any", + "signatureType": "any", + "reg": 2, + "start": 4, + "length": 10 + }, + { + "name": "0newTarget", + "signature": "any", + "signatureType": "any", + "reg": 1, + "start": 4, + "length": 10 + } + ], + "sourceFile": "debug-info.js", + "sourceCode": "", + "SlotNumber": 5, }, + { + "name": ".#*#Test", + "signature": { + "retType": "any", + "params": [ + "any", + "any", + "any" + ] + }, + "ins": [ + { + "opcode": "mov", + "regs": [ + 0, + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "mov", + "regs": [ + 1, + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "mov", + "regs": [ + 2, + 7 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "ldundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "sta", + "regs": [ + 3 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "ldai", + "regs": [], + "ids": [], + "imms": [ + 1 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "sta", + "regs": [ + 3 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "ldai", + "regs": [], + "ids": [], + "imms": [ + 2 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 18 + } + }, + { + "opcode": "sta", + "regs": [ + 3 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 18 + } + }, + { + "opcode": "ldundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + }, + { + "opcode": "returnundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + } + ], + "variables": [ + { + "name": "this", + "signature": "any", + "signatureType": "any", + "reg": 2, + "start": 3, + "length": 8 + }, + { + "name": "d", + "signature": "any", + "signatureType": "any", + "reg": 3, + "start": 3, + "length": 8 + }, + { + "name": "4newTarget", + "signature": "any", + "signatureType": "any", + "reg": 1, + "start": 3, + "length": 8 + }, + { + "name": "4funcObj", + "signature": "any", + "signatureType": "any", + "reg": 0, + "start": 3, + "length": 8 + } + ], + "sourceFile": "debug-info.js", + "sourceCode": "", + "SlotNumber": 0, }, + { + "name": ".#*#foo", + "signature": { + "retType": "any", + "params": [ + "any", + "any", + "any" + ] + }, + "ins": [ + { + "opcode": "mov", + "regs": [ + 0, + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 25 + } + }, + { + "opcode": "mov", + "regs": [ + 1, + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 25 + } + }, + { + "opcode": "mov", + "regs": [ + 2, + 7 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 25 + } + }, + { + "opcode": "asyncfunctionenter", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 25 + } + }, + { + "opcode": "sta", + "regs": [ + 3 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 25 + } + }, + { + "opcode": "LABEL_0: ", + "regs": [], + "ids": [], + "imms": [], + "label": "LABEL_0", + "debug_pos_info": { + "sourceLineNum": 25 + } + }, + { + "opcode": "ldai", + "regs": [], + "ids": [], + "imms": [ + 42 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 25 + } + }, + { + "opcode": "asyncfunctionresolve", + "regs": [ + 3 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 25 + } + }, + { + "opcode": "return", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 26 + } + }, + { + "opcode": "LABEL_1: ", + "regs": [], + "ids": [], + "imms": [], + "label": "LABEL_1", + "debug_pos_info": { + "sourceLineNum": 25 + } + }, + { + "opcode": "LABEL_2: ", + "regs": [], + "ids": [], + "imms": [], + "label": "LABEL_2", + "debug_pos_info": { + "sourceLineNum": 25 + } + }, + { + "opcode": "sta", + "regs": [ + 4 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 24 + } + }, + { + "opcode": "asyncfunctionreject", + "regs": [ + 3 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 24 + } + }, + { + "opcode": "return", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 26 + } + }, + { + "opcode": "LABEL_3: ", + "regs": [], + "ids": [], + "imms": [], + "label": "LABEL_3", + "debug_pos_info": { + "sourceLineNum": 25 + } + } + ], + "variables": [ + { + "name": "this", + "signature": "any", + "signatureType": "any", + "reg": 2, + "start": 3, + "length": 12 + }, + { + "name": "4newTarget", + "signature": "any", + "signatureType": "any", + "reg": 1, + "start": 3, + "length": 12 + }, + { + "name": "4funcObj", + "signature": "any", + "signatureType": "any", + "reg": 0, + "start": 3, + "length": 12 + } + ], + "sourceFile": "debug-info.js", + "sourceCode": "", + "SlotNumber": 0, }, + { + "name": ".func_main_0", + "signature": { + "retType": "any", + "params": [ + "any", + "any", + "any" + ] + }, + "ins": [ + { + "opcode": "mov", + "regs": [ + 0, + 7 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "mov", + "regs": [ + 1, + 8 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "mov", + "regs": [ + 2, + 9 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "definefunc", + "regs": [], + "ids": [ + ".#*#Test" + ], + "imms": [ + 0, + 0 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "stglobalvar", + "regs": [], + "ids": [ + "Test" + ], + "imms": [ + 1 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "definefunc", + "regs": [], + "ids": [ + ".#*#foo" + ], + "imms": [ + 2, + 0 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "stglobalvar", + "regs": [], + "ids": [ + "foo" + ], + "imms": [ + 3 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "ldglobalvar", + "regs": [], + "ids": [ + "Test" + ], + "imms": [ + 4 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "sta", + "regs": [ + 4 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "lda", + "regs": [ + 4 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "callarg0", + "regs": [], + "ids": [], + "imms": [ + 5 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "ldglobalvar", + "regs": [], + "ids": [ + "foo" + ], + "imms": [ + 7 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "sta", + "regs": [ + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "lda", + "regs": [ + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "callarg0", + "regs": [], + "ids": [], + "imms": [ + 8 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "sta", + "regs": [ + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "lda", + "regs": [ + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "ldobjbyname", + "regs": [], + "ids": [ + "then" + ], + "imms": [ + 10 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "sta", + "regs": [ + 4 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "definefunc", + "regs": [], + "ids": [ + ".#*#" + ], + "imms": [ + 12, + 1 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "sta", + "regs": [ + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "lda", + "regs": [ + 4 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "callthis1", + "regs": [ + 5, + 6 + ], + "ids": [], + "imms": [ + 13 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "ldundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + }, + { + "opcode": "returnundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 28 + } + } + ], + "variables": [ + { + "name": "this", + "signature": "any", + "signatureType": "any", + "reg": 2, + "start": 3, + "length": 22 + }, + { + "name": "4newTarget", + "signature": "any", + "signatureType": "any", + "reg": 1, + "start": 3, + "length": 22 + }, + { + "name": "4funcObj", + "signature": "any", + "signatureType": "any", + "reg": 0, + "start": 3, + "length": 22 + } + ], + "sourceFile": "debug-info.js", + "sourceCode": "not supported", + "SlotNumber": 15, } + ] +} diff --git a/es2panda/test/compiler/debugInfo/test-invalid-node-1.ts b/es2panda/test/compiler/debugInfo/test-invalid-node-1.ts new file mode 100644 index 0000000000000000000000000000000000000000..dd91d8edf32e00eeb8dbeb37b43be7c56e27e214 --- /dev/null +++ b/es2panda/test/compiler/debugInfo/test-invalid-node-1.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +// function +function Test() { + var d = 1; + d = 2; +} + +Test(); + +// async function +async function foo() { + return 42; +} + +foo().then(v => console.log(v)); \ No newline at end of file diff --git a/es2panda/test/compiler/debugInfo/test-invalid-node-2-expected.txt b/es2panda/test/compiler/debugInfo/test-invalid-node-2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..02acef72b817eb65ae5285b6a62e78f5fe090c80 --- /dev/null +++ b/es2panda/test/compiler/debugInfo/test-invalid-node-2-expected.txt @@ -0,0 +1,451 @@ +{ + "functions": [ + { + "name": ".#*#foo", + "signature": { + "retType": "any", + "params": [ + "any", + "any", + "any" + ] + }, + "ins": [ + { + "opcode": "mov", + "regs": [ + 0, + 4 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 23 + } + }, + { + "opcode": "mov", + "regs": [ + 1, + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 23 + } + }, + { + "opcode": "mov", + "regs": [ + 2, + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 23 + } + }, + { + "opcode": "tryldglobalbyname", + "regs": [], + "ids": [ + "A" + ], + "imms": [ + 0 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 23 + } + }, + { + "opcode": "return", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 24 + } + } + ], + "variables": [ + { + "name": "this", + "signature": "any", + "signatureType": "any", + "reg": 2, + "start": 3, + "length": 2 + }, + { + "name": "4newTarget", + "signature": "any", + "signatureType": "any", + "reg": 1, + "start": 3, + "length": 2 + }, + { + "name": "4funcObj", + "signature": "any", + "signatureType": "any", + "reg": 0, + "start": 3, + "length": 2 + } + ], + "sourceFile": "debug-info.js", + "sourceCode": "", + "SlotNumber": 1, }, + { + "name": ".#~A=#A", + "signature": { + "retType": "any", + "params": [ + "any", + "any", + "any" + ] + }, + "ins": [ + { + "opcode": "mov", + "regs": [ + 0, + 4 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 18 + } + }, + { + "opcode": "mov", + "regs": [ + 1, + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 18 + } + }, + { + "opcode": "mov", + "regs": [ + 2, + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 18 + } + }, + { + "opcode": "lda.str", + "regs": [], + "ids": [ + "use sendable" + ], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 18 + } + }, + { + "opcode": "lda", + "regs": [ + 2 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + }, + { + "opcode": "return", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + } + ], + "variables": [ + { + "name": "this", + "signature": "any", + "signatureType": "any", + "reg": 2, + "start": 3, + "length": 3 + }, + { + "name": "4newTarget", + "signature": "any", + "signatureType": "any", + "reg": 1, + "start": 3, + "length": 3 + }, + { + "name": "4funcObj", + "signature": "any", + "signatureType": "any", + "reg": 0, + "start": 3, + "length": 3 + } + ], + "sourceFile": "debug-info.js", + "sourceCode": "", + "SlotNumber": 0, }, + { + "name": ".func_main_0", + "signature": { + "retType": "any", + "params": [ + "any", + "any", + "any" + ] + }, + "ins": [ + { + "opcode": "newlexenvwithname", + "regs": [], + "ids": [ + "_3" + ], + "imms": [ + 1 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "mov", + "regs": [ + 0, + 7 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "mov", + "regs": [ + 1, + 8 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "mov", + "regs": [ + 2, + 9 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "definefunc", + "regs": [], + "ids": [ + ".#*#foo" + ], + "imms": [ + 0, + 0 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "stglobalvar", + "regs": [], + "ids": [ + "foo" + ], + "imms": [ + 1 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "ldhole", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "sta", + "regs": [ + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "callruntime.definesendableclass", + "regs": [ + 6 + ], + "ids": [ + ".#~A=#A", + "_2" + ], + "imms": [ + 2, + 0 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "sta", + "regs": [ + 4 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "sta", + "regs": [ + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "sttoglobalrecord", + "regs": [], + "ids": [ + "A" + ], + "imms": [ + 3 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "ldundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 24 + } + }, + { + "opcode": "returnundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 24 + } + } + ], + "variables": [ + { + "name": "A", + "signature": "any", + "signatureType": "any", + "reg": 5, + "start": 6, + "length": 5 + }, + { + "name": "this", + "signature": "any", + "signatureType": "any", + "reg": 2, + "start": 4, + "length": 10 + }, + { + "name": "4newTarget", + "signature": "any", + "signatureType": "any", + "reg": 1, + "start": 4, + "length": 10 + }, + { + "name": "4funcObj", + "signature": "any", + "signatureType": "any", + "reg": 0, + "start": 4, + "length": 10 + } + ], + "sourceFile": "debug-info.js", + "sourceCode": "not supported", + "SlotNumber": 4, } + ] +} diff --git a/es2panda/test/compiler/debugInfo/test-invalid-node-2.ts b/es2panda/test/compiler/debugInfo/test-invalid-node-2.ts new file mode 100644 index 0000000000000000000000000000000000000000..a268f1302860acc02011a66ae4db0d6dafaf7b18 --- /dev/null +++ b/es2panda/test/compiler/debugInfo/test-invalid-node-2.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +// sendable env +class A { + constructor () { + "use sendable" + } +} + +function foo() { + return A; +} \ No newline at end of file diff --git a/es2panda/test/compiler/debugInfo/test-invalid-node-3-expected.txt b/es2panda/test/compiler/debugInfo/test-invalid-node-3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..34698873256cde0d1a0200a142d7eca291dc06f4 --- /dev/null +++ b/es2panda/test/compiler/debugInfo/test-invalid-node-3-expected.txt @@ -0,0 +1,424 @@ +{ + "functions": [ + { + "name": ".#*#test", + "signature": { + "retType": "any", + "params": [ + "any", + "any", + "any" + ] + }, + "ins": [ + { + "opcode": "mov", + "regs": [ + 0, + 8 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "mov", + "regs": [ + 1, + 9 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "mov", + "regs": [ + 2, + 10 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "ldfalse", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "sta", + "regs": [ + 3 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "lda", + "regs": [ + 3 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 18 + } + }, + { + "opcode": "callruntime.isfalse", + "regs": [], + "ids": [], + "imms": [ + 0 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 18 + } + }, + { + "opcode": "jnez", + "regs": [], + "ids": [ + "LABEL_0" + ], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 18 + } + }, + { + "opcode": "tryldglobalbyname", + "regs": [], + "ids": [ + "console" + ], + "imms": [ + 1 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + }, + { + "opcode": "sta", + "regs": [ + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + }, + { + "opcode": "lda", + "regs": [ + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + }, + { + "opcode": "ldobjbyname", + "regs": [], + "ids": [ + "log" + ], + "imms": [ + 2 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + }, + { + "opcode": "sta", + "regs": [ + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + }, + { + "opcode": "lda.str", + "regs": [], + "ids": [ + "test" + ], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + }, + { + "opcode": "sta", + "regs": [ + 7 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + }, + { + "opcode": "lda", + "regs": [ + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + }, + { + "opcode": "callthis1", + "regs": [ + 6, + 7 + ], + "ids": [], + "imms": [ + 4 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 19 + } + }, + { + "opcode": "LABEL_0: ", + "regs": [], + "ids": [], + "imms": [], + "label": "LABEL_0", + "debug_pos_info": { + "sourceLineNum": 17 + } + }, + { + "opcode": "ldundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "returnundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + } + ], + "variables": [ + { + "name": "this", + "signature": "any", + "signatureType": "any", + "reg": 2, + "start": 3, + "length": 17 + }, + { + "name": "flag", + "signature": "any", + "signatureType": "any", + "reg": 3, + "start": 3, + "length": 17 + }, + { + "name": "4newTarget", + "signature": "any", + "signatureType": "any", + "reg": 1, + "start": 3, + "length": 17 + }, + { + "name": "4funcObj", + "signature": "any", + "signatureType": "any", + "reg": 0, + "start": 3, + "length": 17 + } + ], + "sourceFile": "debug-info.js", + "sourceCode": "", + "SlotNumber": 6, }, + { + "name": ".func_main_0", + "signature": { + "retType": "any", + "params": [ + "any", + "any", + "any" + ] + }, + "ins": [ + { + "opcode": "mov", + "regs": [ + 0, + 4 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "mov", + "regs": [ + 1, + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "mov", + "regs": [ + 2, + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "definefunc", + "regs": [], + "ids": [ + ".#*#test" + ], + "imms": [ + 0, + 0 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "stglobalvar", + "regs": [], + "ids": [ + "test" + ], + "imms": [ + 1 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "ldundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + }, + { + "opcode": "returnundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 21 + } + } + ], + "variables": [ + { + "name": "this", + "signature": "any", + "signatureType": "any", + "reg": 2, + "start": 3, + "length": 4 + }, + { + "name": "4newTarget", + "signature": "any", + "signatureType": "any", + "reg": 1, + "start": 3, + "length": 4 + }, + { + "name": "4funcObj", + "signature": "any", + "signatureType": "any", + "reg": 0, + "start": 3, + "length": 4 + } + ], + "sourceFile": "debug-info.js", + "sourceCode": "not supported", + "SlotNumber": 2, } + ] +} diff --git a/es2panda/test/compiler/debugInfo/test-invalid-node-3.ts b/es2panda/test/compiler/debugInfo/test-invalid-node-3.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c7e7ed278b6cd0536e8d92a3a9104d2e7440ba --- /dev/null +++ b/es2panda/test/compiler/debugInfo/test-invalid-node-3.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + +// ImplicitReturn +function test() { + let flag = false + if (flag) { + console.log("test") + } +} \ No newline at end of file diff --git a/es2panda/test/compiler/debugInfo/test-invalid-node-4-expected.txt b/es2panda/test/compiler/debugInfo/test-invalid-node-4-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..4475a779b221c6d313d77f113f3634300bb844a4 --- /dev/null +++ b/es2panda/test/compiler/debugInfo/test-invalid-node-4-expected.txt @@ -0,0 +1,228 @@ +{ + "functions": [ + { + "name": ".func_main_0", + "signature": { + "retType": "any", + "params": [ + "any", + "any", + "any" + ] + }, + "ins": [ + { + "opcode": "mov", + "regs": [ + 0, + 7 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "mov", + "regs": [ + 1, + 8 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "mov", + "regs": [ + 2, + 9 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "createobjectwithbuffer", + "regs": [], + "ids": [ + "_1" + ], + "imms": [ + 0 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "sta", + "regs": [ + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "ldai", + "regs": [], + "ids": [], + "imms": [ + 1 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "sta", + "regs": [ + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "lda", + "regs": [ + 6 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "neg", + "regs": [], + "ids": [], + "imms": [ + 1 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "definepropertybyname", + "regs": [ + 5 + ], + "ids": [ + "c" + ], + "imms": [ + 2 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "lda", + "regs": [ + 5 + ], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "sttoglobalrecord", + "regs": [], + "ids": [ + "obj" + ], + "imms": [ + 4 + ], + "label": "", + "debug_pos_info": { + "sourceLineNum": 16 + } + }, + { + "opcode": "ldundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 20 + } + }, + { + "opcode": "returnundefined", + "regs": [], + "ids": [], + "imms": [], + "label": "", + "debug_pos_info": { + "sourceLineNum": 20 + } + } + ], + "variables": [ + { + "name": "this", + "signature": "any", + "signatureType": "any", + "reg": 2, + "start": 3, + "length": 11 + }, + { + "name": "obj", + "signature": "any", + "signatureType": "any", + "reg": 3, + "start": 3, + "length": 11 + }, + { + "name": "4newTarget", + "signature": "any", + "signatureType": "any", + "reg": 1, + "start": 3, + "length": 11 + }, + { + "name": "4funcObj", + "signature": "any", + "signatureType": "any", + "reg": 0, + "start": 3, + "length": 11 + } + ], + "sourceFile": "debug-info.js", + "sourceCode": "not supported", + "SlotNumber": 5, } + ] +} diff --git a/es2panda/test/compiler/debugInfo/test-invalid-node-4.ts b/es2panda/test/compiler/debugInfo/test-invalid-node-4.ts new file mode 100644 index 0000000000000000000000000000000000000000..0d8b5d9d7caf597c67c2b000e54a62c1fc3f4ff0 --- /dev/null +++ b/es2panda/test/compiler/debugInfo/test-invalid-node-4.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +// object literal +let obj = { + a: 1, + b: 0, + c: -1 +} \ No newline at end of file diff --git a/es2panda/test/compiler/debugInfo/test-local-variable-expected.txt b/es2panda/test/compiler/debugInfo/test-local-variable-expected.txt index be4b8491f7caf58d8d88913e48c0cffe18ee2c25..a62deb583184bd50164485b2d38d3559c09ea68e 100644 --- a/es2panda/test/compiler/debugInfo/test-local-variable-expected.txt +++ b/es2panda/test/compiler/debugInfo/test-local-variable-expected.txt @@ -21,7 +21,7 @@ "imms": [], "label": "", "debug_pos_info": { - "sourceLineNum": -1 + "sourceLineNum": 15 } }, { @@ -34,7 +34,7 @@ "imms": [], "label": "", "debug_pos_info": { - "sourceLineNum": -1 + "sourceLineNum": 15 } }, { @@ -47,7 +47,7 @@ "imms": [], "label": "", "debug_pos_info": { - "sourceLineNum": -1 + "sourceLineNum": 15 } }, { @@ -203,7 +203,7 @@ "imms": [], "label": "", "debug_pos_info": { - "sourceLineNum": -1 + "sourceLineNum": 27 } }, { @@ -213,7 +213,7 @@ "imms": [], "label": "", "debug_pos_info": { - "sourceLineNum": -1 + "sourceLineNum": 27 } } ],