Coding style, some C++11-ification
This commit is contained in:
parent
b76eb2f745
commit
e3896a184e
3 changed files with 28 additions and 27 deletions
|
|
@ -65,16 +65,14 @@ void FileModule::registerUse(const std::string path) {
|
|||
void FileModule::registerInclude(const std::string &localpath,
|
||||
const std::string &fullpath)
|
||||
{
|
||||
struct stat st;
|
||||
memset(&st, 0, sizeof(struct stat));
|
||||
struct stat st{};
|
||||
bool valid = stat(fullpath.c_str(), &st) == 0;
|
||||
IncludeFile inc = {fullpath, valid, st.st_mtime};
|
||||
this->includes[localpath] = inc;
|
||||
this->includes[localpath] = {fullpath, valid, st.st_mtime};
|
||||
}
|
||||
|
||||
bool FileModule::includesChanged() const
|
||||
{
|
||||
for(const auto &item : this->includes) {
|
||||
for (const auto &item : this->includes) {
|
||||
if (include_modified(item.second)) return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -82,8 +80,7 @@ bool FileModule::includesChanged() const
|
|||
|
||||
bool FileModule::include_modified(const IncludeFile &inc) const
|
||||
{
|
||||
struct stat st;
|
||||
memset(&st, 0, sizeof(struct stat));
|
||||
struct stat st{};
|
||||
|
||||
fs::path fullpath = find_valid_path(this->path, inc.filename);
|
||||
bool valid = !fullpath.empty() ? (stat(fullpath.generic_string().c_str(), &st) == 0) : false;
|
||||
|
|
@ -109,7 +106,7 @@ bool FileModule::handleDependencies()
|
|||
// If a lib in usedlibs was previously missing, we need to relocate it
|
||||
// by searching the applicable paths. We can identify a previously missing module
|
||||
// as it will have a relative path.
|
||||
for(auto filename : this->usedlibs) {
|
||||
for (auto filename : this->usedlibs) {
|
||||
|
||||
bool wasmissing = false;
|
||||
bool found = true;
|
||||
|
|
@ -137,6 +134,9 @@ bool FileModule::handleDependencies()
|
|||
if (changed) {
|
||||
PRINTDB(" %s: %p -> %p", filename % oldmodule % newmodule);
|
||||
}
|
||||
else {
|
||||
PRINTDB(" %s: %p", filename % oldmodule);
|
||||
}
|
||||
somethingchanged |= changed;
|
||||
// Only print warning if we're not part of an automatic reload
|
||||
if (!newmodule && !wascached && !wasmissing) {
|
||||
|
|
@ -145,9 +145,9 @@ bool FileModule::handleDependencies()
|
|||
}
|
||||
}
|
||||
|
||||
// Relative filenames which were located is reinserted as absolute filenames
|
||||
// Relative filenames which were located are reinserted as absolute filenames
|
||||
typedef std::pair<std::string,std::string> stringpair;
|
||||
for(const auto &files : updates) {
|
||||
for (const auto &files : updates) {
|
||||
this->usedlibs.erase(files.first);
|
||||
this->usedlibs.insert(files.second);
|
||||
}
|
||||
|
|
@ -155,17 +155,19 @@ bool FileModule::handleDependencies()
|
|||
return somethingchanged;
|
||||
}
|
||||
|
||||
AbstractNode *FileModule::instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx) const
|
||||
AbstractNode *FileModule::instantiate(const Context *ctx, const ModuleInstantiation *inst,
|
||||
EvalContext *evalctx) const
|
||||
{
|
||||
assert(evalctx == NULL);
|
||||
assert(evalctx == nullptr);
|
||||
|
||||
FileContext context(ctx);
|
||||
return this->instantiateWithFileContext(&context, inst, evalctx);
|
||||
}
|
||||
|
||||
AbstractNode *FileModule::instantiateWithFileContext(FileContext *ctx, const ModuleInstantiation *inst, EvalContext *evalctx) const
|
||||
AbstractNode *FileModule::instantiateWithFileContext(FileContext *ctx, const ModuleInstantiation *inst,
|
||||
EvalContext *evalctx) const
|
||||
{
|
||||
assert(evalctx == NULL);
|
||||
assert(evalctx == nullptr);
|
||||
|
||||
AbstractNode *node = new RootNode(inst);
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ public:
|
|||
FileModule() : is_handling_dependencies(false) {}
|
||||
virtual ~FileModule();
|
||||
|
||||
virtual AbstractNode *instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx = NULL) const;
|
||||
virtual AbstractNode *instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx = nullptr) const;
|
||||
virtual std::string dump(const std::string &indent, const std::string &name) const;
|
||||
AbstractNode *instantiateWithFileContext(class FileContext *ctx, const ModuleInstantiation *inst, EvalContext *evalctx) const;
|
||||
|
||||
void setModulePath(const std::string &path) { this->path = path; }
|
||||
void setModulePath(const std::string &path) { this->path = path; }
|
||||
const std::string &modulePath() const { return this->path; }
|
||||
void registerUse(const std::string path);
|
||||
void registerUse(const std::string path);
|
||||
void registerInclude(const std::string &localpath, const std::string &fullpath);
|
||||
bool includesChanged() const;
|
||||
bool handleDependencies();
|
||||
|
|
|
|||
|
|
@ -18,21 +18,22 @@ namespace fs=boost::filesystem;
|
|||
FIXME: Implement an LRU scheme to avoid having an ever-growing module cache
|
||||
*/
|
||||
|
||||
ModuleCache *ModuleCache::inst = NULL;
|
||||
ModuleCache *ModuleCache::inst = nullptr;
|
||||
|
||||
/*!
|
||||
Reevaluate the given file and all it's dependencies and recompile anything
|
||||
needing reevaluation. Updates the cache if necessary.
|
||||
The given filename must be absolute.
|
||||
|
||||
Sets the module reference to the new module, or NULL on any error (e.g. compile
|
||||
Sets the module reference to the new module, or nullptr on any error (e.g. compile
|
||||
error or file not found).
|
||||
|
||||
Returns true if anything was compiled (module or dependencies) and false otherwise.
|
||||
*/
|
||||
bool ModuleCache::evaluate(const std::string &filename, FileModule *&module)
|
||||
{
|
||||
FileModule *lib_mod = NULL;
|
||||
module = nullptr;
|
||||
FileModule *lib_mod = nullptr;
|
||||
bool found = false;
|
||||
if (this->entries.find(filename) != this->entries.end()) {
|
||||
found = true;
|
||||
|
|
@ -44,8 +45,7 @@ bool ModuleCache::evaluate(const std::string &filename, FileModule *&module)
|
|||
if (lib_mod && lib_mod->isHandlingDependencies()) return false;
|
||||
|
||||
// Create cache ID
|
||||
struct stat st;
|
||||
memset(&st, 0, sizeof(struct stat));
|
||||
struct stat st{};
|
||||
bool valid = (stat(filename.c_str(), &st) == 0);
|
||||
|
||||
// If file isn't there, just return and let the cache retain the old module
|
||||
|
|
@ -57,7 +57,7 @@ bool ModuleCache::evaluate(const std::string &filename, FileModule *&module)
|
|||
cache_entry &entry = this->entries[filename];
|
||||
// Initialize entry, if new
|
||||
if (!found) {
|
||||
entry.module = NULL;
|
||||
entry.module = nullptr;
|
||||
entry.cache_id = cache_id;
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ bool ModuleCache::evaluate(const std::string &filename, FileModule *&module)
|
|||
shouldCompile = false;
|
||||
// Recompile if includes changed
|
||||
if (lib_mod && lib_mod->includesChanged()) {
|
||||
lib_mod = NULL;
|
||||
lib_mod = nullptr;
|
||||
shouldCompile = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -105,7 +105,7 @@ bool ModuleCache::evaluate(const std::string &filename, FileModule *&module)
|
|||
|
||||
FileModule *oldmodule = lib_mod;
|
||||
|
||||
fs::path pathname = fs::path(filename);
|
||||
fs::path pathname = fs::path(filename);
|
||||
lib_mod = parse(textbuf.str().c_str(), pathname, false);
|
||||
PRINTDB(" compiled module: %p", lib_mod);
|
||||
|
||||
|
|
@ -131,11 +131,10 @@ void ModuleCache::clear()
|
|||
|
||||
FileModule *ModuleCache::lookup(const std::string &filename)
|
||||
{
|
||||
return isCached(filename) ? this->entries[filename].module : NULL;
|
||||
return isCached(filename) ? this->entries[filename].module : nullptr;
|
||||
}
|
||||
|
||||
bool ModuleCache::isCached(const std::string &filename)
|
||||
{
|
||||
return this->entries.find(filename) != this->entries.end();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue