diff --git a/src/V3EmitMk.cpp b/src/V3EmitMk.cpp index bd1f58c73..3d388b455 100644 --- a/src/V3EmitMk.cpp +++ b/src/V3EmitMk.cpp @@ -209,7 +209,7 @@ public: of.puts("VM_USER_CLASSES = \\\n"); const V3StringSet& cppFiles = v3Global.opt.cppFiles(); for (const auto& cppfile : cppFiles) { - of.puts("\t" + V3Os::filenameNonExt(cppfile) + " \\\n"); + of.puts("\t" + V3Os::filenameNonDirExt(cppfile) + " \\\n"); const string dir = V3Os::filenameDir(cppfile); dirs.insert(dir); } @@ -237,7 +237,7 @@ public: } for (const string& cppfile : cppFiles) { - const string basename = V3Os::filenameNonExt(cppfile); + const string basename = V3Os::filenameNonDirExt(cppfile); // NOLINTNEXTLINE(performance-inefficient-string-concatenation) of.puts(basename + ".o: " + cppfile + "\n"); of.puts("\t$(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_FAST) -c -o $@ $<\n"); diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 9f40d02b3..a24d87ec7 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -1025,10 +1025,9 @@ void V3Options::parseOpts(FileLine* fl, int argc, char** argv) VL_MT_DISABLED { } // Default prefix to the filename - if (prefix() == "" && topModule() != "") - m_prefix = string{"V"} + AstNode::encodeName(topModule()); + if (prefix() == "" && topModule() != "") m_prefix = "V"s + AstNode::encodeName(topModule()); if (prefix() == "" && vFilesList.size() >= 1) - m_prefix = string{"V"} + AstNode::encodeName(V3Os::filenameNonExt(*(vFilesList.begin()))); + m_prefix = "V"s + AstNode::encodeName(V3Os::filenameNonDirExt(*(vFilesList.begin()))); if (modPrefix() == "") m_modPrefix = prefix(); // Find files in makedir diff --git a/src/V3Os.cpp b/src/V3Os.cpp index 99661201d..ab0560e51 100644 --- a/src/V3Os.cpp +++ b/src/V3Os.cpp @@ -165,6 +165,17 @@ string V3Os::filenameDir(const string& filename) VL_PURE { } } +string V3Os::filenameExt(const string& filename) VL_PURE { + string base = filenameNonDir(filename); + string::size_type pos; + if ((pos = base.find('.')) != string::npos) { + base.erase(0, pos); + return base; + } else { + return ""; + } +} + string V3Os::filenameNonDir(const string& filename) VL_PURE { // std::filesystem::path::filename auto it = filename.rbegin(); @@ -174,17 +185,13 @@ string V3Os::filenameNonDir(const string& filename) VL_PURE { return string{it.base(), filename.end()}; } -string V3Os::filenameNonExt(const string& filename) VL_PURE { +string V3Os::filenameNonDirExt(const string& filename) VL_PURE { string base = filenameNonDir(filename); string::size_type pos; if ((pos = base.find('.')) != string::npos) base.erase(pos); return base; } -string V3Os::filenameNonDirExt(const string& filename) VL_PURE { - return filenameNonExt(filenameNonDir(filename)); -} - string V3Os::filenameSubstitute(const string& filename) { string result; // cppcheck-has-bug-suppress unusedLabel @@ -441,5 +448,9 @@ void V3Os::selfTest() { UASSERT_SELFTEST(string, filenameCleanup("aaa/bbb/ccc/"), "aaa/bbb/ccc"); UASSERT_SELFTEST(string, filenameCleanup("./aaa/bbb/ccc/"), "aaa/bbb/ccc"); UASSERT_SELFTEST(string, filenameCleanup("../aaa/bbb/ccc/"), "../aaa/bbb/ccc"); + UASSERT_SELFTEST(string, filenameDir("a.a/b.b/f.e"), "a.a/b.b"); + UASSERT_SELFTEST(string, filenameExt("a.a/b.b/f"), ""); + UASSERT_SELFTEST(string, filenameExt("a.a/b.b/f.e"), ".e"); + UASSERT_SELFTEST(string, filenameNonDirExt("a.a/b.b/f.e"), "f"); #endif } diff --git a/src/V3Os.h b/src/V3Os.h index 6232b2647..f0f281be5 100644 --- a/src/V3Os.h +++ b/src/V3Os.h @@ -43,10 +43,10 @@ public: }; ///< @return file path without repeated separators and ./ prefix static string filenameCleanup(const string& filename) VL_PURE; + ///< @return extension (.) part of filename + static string filenameExt(const string& filename) VL_PURE; ///< @return non-directory part of filename static string filenameNonDir(const string& filename) VL_PURE; - ///< @return non-extensioned (no .) part of filename - static string filenameNonExt(const string& filename) VL_PURE; ///< @return basename of filename static string filenameNonDirExt(const string& filename) VL_PURE; ///< @return directory part of filename diff --git a/src/V3ParseImp.cpp b/src/V3ParseImp.cpp index d467f81e5..37c107e8a 100644 --- a/src/V3ParseImp.cpp +++ b/src/V3ParseImp.cpp @@ -287,7 +287,7 @@ void V3ParseImp::preprocDumps(std::ostream& os, bool forInputs) { void V3ParseImp::parseFile(FileLine* fileline, const string& modfilename, bool inLibrary, const string& errmsg) { // "" for no error, make fake node const string nondirname = V3Os::filenameNonDir(modfilename); - const string modname = V3Os::filenameNonExt(modfilename); + const string modname = V3Os::filenameNonDirExt(modfilename); UINFO(2, __FUNCTION__ << ": " << modname << (inLibrary ? " [LIB]" : "") << endl); m_lexFileline = new FileLine{fileline};