-
-
Save torokati44/b644f08758d5f4cff3dffd3e8f7ad9f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ASTNode *NedResourceCache::getFile(const char *fname) const | |
{ | |
// hash table lookup | |
std::string key = tidyFilename(toAbsolutePath(fname).c_str()); | |
NedFileMap::const_iterator i = files.find(key); | |
ASTNode *result = i == files.end() ? nullptr : i->second; | |
std::cout << "getting file: " << fname << (result ? " it is found " : " NOT FOUND ") << std::endl; | |
return result; | |
} | |
NedFileElement *NedResourceCache::getParentPackageNedFile(NedFileElement *nedfile) const | |
{ | |
std::string nedfilename = tidyFilename(toAbsolutePath(nedfile->getFilename()).c_str(), true); | |
std::string dir, fname; | |
splitFileName(nedfilename.c_str(), dir, fname); | |
dir = tidyFilename(dir.c_str(), true); | |
std::cout << "getParentPackage for " << nedfile->getFilename() << std::endl; | |
std::string topDir = getNedSourceFolderForFolder(dir.c_str()); | |
std::cout << "topDir: " << topDir << std::endl; | |
if (topDir.empty()) | |
return nullptr; | |
if (fname != "package.ned") { | |
// get package.ned from same package | |
std::string _fn = tidyFilename(concatDirAndFile(dir.c_str(), "package.ned").c_str(), true); | |
ASTNode *e = getFile(_fn.c_str()); | |
if (e) { | |
std::cout << "early returning " << _fn << std::endl; | |
return (NedFileElement *)e; | |
} | |
} | |
// walk up in search for a package.ned | |
while (dir != topDir) { | |
// printf("%s ~ %s\n", dir.c_str(), topDir.c_str()); | |
std::cout << "checking for dir " << dir << std::endl; | |
// chop last segment | |
std::string parentDir, dummy; | |
splitFileName(dir.c_str(), parentDir, dummy); | |
Assert(dir != parentDir); // we should exit via reaching the NED source folder | |
dir = tidyFilename(parentDir.c_str(), true); | |
// return package.ned from this dir, if exists | |
std::string _fn = tidyFilename(concatDirAndFile(dir.c_str(), "package.ned").c_str(), true); | |
ASTNode *e = getFile(_fn.c_str()); | |
if (e) { | |
std::cout << "returning file: " << _fn << std::endl; | |
return (NedFileElement *)e; | |
} | |
} | |
std::cout << "package ned file not found" << std::endl; | |
return nullptr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment