diff options
author | 2011-06-14 17:58:07 +0800 | |
---|---|---|
committer | 2011-06-16 00:14:47 +0300 | |
commit | 797b43f26a5c387bbf1d2874fc22bf0eb56e3582 (patch) | |
tree | cefe3ef560712b918492bfa47a85ff916a595a78 /src | |
parent | Core: add namespace for interpreter_exception (diff) | |
download | libbash-797b43f26a5c387bbf1d2874fc22bf0eb56e3582.tar.gz libbash-797b43f26a5c387bbf1d2874fc22bf0eb56e3582.tar.bz2 libbash-797b43f26a5c387bbf1d2874fc22bf0eb56e3582.zip |
Builtin: cache parsing failures in source built-in
Diffstat (limited to 'src')
-rw-r--r-- | src/builtins/source_builtin.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/builtins/source_builtin.cpp b/src/builtins/source_builtin.cpp index 8a1838b..b2bf2db 100644 --- a/src/builtins/source_builtin.cpp +++ b/src/builtins/source_builtin.cpp @@ -44,15 +44,25 @@ int source_builtin::exec(const std::vector<std::string>& bash_args) // we need fix this to pass extra arguments as positional parameters const std::string& path = bash_args[0]; - auto& stored_ast = ast_cache[path]; - if(!stored_ast) - stored_ast.reset(new bash_ast(path)); + auto stored_ast = ast_cache.find(path); + if(stored_ast == ast_cache.end()) + { + // ensure the path is cached + auto iter = ast_cache.insert(make_pair(path, std::shared_ptr<bash_ast>())); + // this may throw exception + iter.first->second.reset(new bash_ast(path)); + stored_ast = iter.first; + } + else if(!(stored_ast->second)) + { + throw libbash::interpreter_exception(path + " cannot be fully parsed"); + } const std::string& original_path = _walker.resolve<std::string>("0"); try { _walker.define("0", path, true); - stored_ast->interpret_with(_walker); + stored_ast->second->interpret_with(_walker); } catch(return_exception& e) {} |