提交 5e8d8e07 编写于 作者: Q qiaolongfei

refine GetOrCreateVariable

上级 2f47562d
...@@ -34,15 +34,17 @@ Variable* Scope::GetVariable(const std::string &name) const { ...@@ -34,15 +34,17 @@ Variable* Scope::GetVariable(const std::string &name) const {
} }
Variable* Scope::GetOrCreateVariable(const std::string &name) { Variable* Scope::GetOrCreateVariable(const std::string &name) {
Variable* var; Variable* var = GetVariable(name);
var = GetVariable(name); if (var != nullptr) {
if (var == nullptr) { return var;
auto err = CreateVariable(name); }
if (!err.isOK()) {
return nullptr; Error err = CreateVariable(name);
} if (!err.isOK()) {
return nullptr;
} else {
return GetVariable(name);
} }
return GetVariable(name);
} }
bool Scope::HaveVariable(const std::string &name) { bool Scope::HaveVariable(const std::string &name) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册