diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index bf970cc1f765ca4ed85b045a68b6a7b2e90772ba..7d56cfb73cda5854536aa510be4af5dee0ff57da 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -17,6 +17,7 @@ #include "mergeProgram.h" #include "os/file.h" +#include #include #if defined(PANDA_TARGET_WINDOWS) #include @@ -29,11 +30,6 @@ #include namespace panda::es2panda::aot { -template -T BaseName(T const &path, T const &delims = std::string(panda::os::file::File::GetPathDelim())) -{ - return path.substr(path.find_last_of(delims) + 1); -} template T RemoveExtension(T const &filename) @@ -107,7 +103,7 @@ bool Options::CollectInputFilesFromFileDirectory(const std::string &input, const return false; } for (auto &f : files) { - es2panda::SourceFile src(f, BaseName(f), scriptKind_); + es2panda::SourceFile src(f, util::Helpers::BaseName(f), scriptKind_); sourceFiles_.push_back(src); } @@ -271,13 +267,14 @@ bool Options::Parse(int argc, const char **argv) } else if (!outputIsEmpty) { compilerOutput_ = outputFile.GetValue(); } else if (outputIsEmpty && !inputIsEmpty) { - compilerOutput_ = RemoveExtension(BaseName(sourceFile_)).append(".abc"); + compilerOutput_ = RemoveExtension(util::Helpers::BaseName(sourceFile_)).append(".abc"); } if (opMergeAbc.GetValue()) { recordName_ = recordName.GetValue(); if (recordName_.empty()) { - recordName_ = compilerOutput_.empty() ? "Base64Output" : RemoveExtension(BaseName(compilerOutput_)); + recordName_ = compilerOutput_.empty() ? "Base64Output" : + RemoveExtension(util::Helpers::BaseName(compilerOutput_)); } recordName_ = FormatRecordName(recordName_); } diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 20663fe3fc9c025fb6c71a08b1925fb9fd977147..002a1ddf2e4b04a3847a6b6823bfa6536e9c08df 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -70,10 +71,6 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil std::cout << ast.Dump() << std::endl; } - if (options.parseOnly) { - return nullptr; - } - std::string debugInfoSourceFile = options.debugInfoSourceFile.empty() ? fname : options.debugInfoSourceFile; auto *prog = compiler_->Compile(&ast, options, debugInfoSourceFile); @@ -198,6 +195,7 @@ panda::pandasm::Program *Compiler::CompileFile(CompilerOptions &options, SourceF src->hash = GetHash32String(reinterpret_cast(buffer.c_str())); } } + src->fileName = util::Helpers::BaseName(src->fileName); auto *program = Compile(*src, options, symbolTable); if (!program) { diff --git a/es2panda/util/helpers.h b/es2panda/util/helpers.h index e970162905332f364a6e1fbbf4abe53fd3ed0404..d9021aa9e2b383837240f561c9aff15c2866af41 100644 --- a/es2panda/util/helpers.h +++ b/es2panda/util/helpers.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -75,6 +76,8 @@ public: uint32_t index); static bool OptimizeProgram(panda::pandasm::Program *prog, es2panda::CompilerOptions *options); + template + static T BaseName(T const &path, T const &delims = std::string(panda::os::file::File::GetPathDelim())); static const uint32_t INVALID_INDEX = 4294967295L; static const uint32_t MAX_INT32 = 2147483647; @@ -94,6 +97,12 @@ bool Helpers::IsInteger(double number) return false; } +template +T Helpers::BaseName(T const &path, T const &delims) +{ + return path.substr(path.find_last_of(delims) + 1); +} + } // namespace panda::es2panda::util #endif