fix fatal errors in symbol check
This commit is contained in:
@ -30,7 +30,7 @@ class LocalScope : public ScopeBase {
|
|||||||
std::unordered_map<std::string, ExprTypeInfo> local_variables;
|
std::unordered_map<std::string, ExprTypeInfo> local_variables;
|
||||||
bool add_variable(const std::string &name, const ExprTypeInfo &type) override {
|
bool add_variable(const std::string &name, const ExprTypeInfo &type) override {
|
||||||
if (!VariableNameAvailable(name, 0)) {
|
if (!VariableNameAvailable(name, 0)) {
|
||||||
throw std::runtime_error("Variable name " + name + " is not available");
|
return false;
|
||||||
}
|
}
|
||||||
local_variables[name] = type;
|
local_variables[name] = type;
|
||||||
return true;
|
return true;
|
||||||
@ -78,7 +78,7 @@ class ClassDefScope : public ScopeBase {
|
|||||||
std::unordered_map<std::string, std::shared_ptr<FunctionScope>> member_functions;
|
std::unordered_map<std::string, std::shared_ptr<FunctionScope>> member_functions;
|
||||||
bool add_variable(const std::string &name, const ExprTypeInfo &type) override {
|
bool add_variable(const std::string &name, const ExprTypeInfo &type) override {
|
||||||
if (!VariableNameAvailable(name, 0)) {
|
if (!VariableNameAvailable(name, 0)) {
|
||||||
throw std::runtime_error("Variable name " + name + " is not available");
|
return false;
|
||||||
}
|
}
|
||||||
member_variables[name] = type;
|
member_variables[name] = type;
|
||||||
return true;
|
return true;
|
||||||
@ -98,6 +98,11 @@ class ClassDefScope : public ScopeBase {
|
|||||||
if (ttl == 0 && IsKeyWord(name)) {
|
if (ttl == 0 && IsKeyWord(name)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (ttl == 0) {
|
||||||
|
if (member_variables.find(name) != member_variables.end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (member_functions.find(name) != member_functions.end()) {
|
if (member_functions.find(name) != member_functions.end()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -139,7 +144,7 @@ class GlobalScope : public ScopeBase {
|
|||||||
}
|
}
|
||||||
bool add_variable(const std::string &name, const ExprTypeInfo &type) override {
|
bool add_variable(const std::string &name, const ExprTypeInfo &type) override {
|
||||||
if (!VariableNameAvailable(name, 0)) {
|
if (!VariableNameAvailable(name, 0)) {
|
||||||
throw std::runtime_error("Variable name " + name + " is not available");
|
return false;
|
||||||
}
|
}
|
||||||
global_variables[name] = type;
|
global_variables[name] = type;
|
||||||
return true;
|
return true;
|
||||||
@ -148,13 +153,15 @@ class GlobalScope : public ScopeBase {
|
|||||||
if (ttl == 0 && IsKeyWord(name)) {
|
if (ttl == 0 && IsKeyWord(name)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (ttl == 0) {
|
||||||
if (global_variables.find(name) != global_variables.end()) {
|
if (global_variables.find(name) != global_variables.end()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (classes.find(name) != classes.end()) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (classes.find(name) != classes.end()) {
|
// if (classes.find(name) != classes.end()) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
if (global_functions.find(name) != global_functions.end()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -453,6 +453,12 @@ std::any Visitor::visitDefine_statement(MXParser::Define_statementContext *conte
|
|||||||
def_stmt->end_char_pos = context->getStop()->getCharPositionInLine();
|
def_stmt->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||||
assert(nodetype_stk.size() > 0);
|
assert(nodetype_stk.size() > 0);
|
||||||
def_stmt->current_scope = nodetype_stk.back().second;
|
def_stmt->current_scope = nodetype_stk.back().second;
|
||||||
|
if (nodetype_stk.size() > 0 && (nodetype_stk.back().first == ASTNodeType::IfStatement ||
|
||||||
|
nodetype_stk.back().first == ASTNodeType::WhileStatement ||
|
||||||
|
nodetype_stk.back().first == ASTNodeType::ForStatement)) {
|
||||||
|
def_stmt->current_scope = std::make_shared<LocalScope>();
|
||||||
|
def_stmt->current_scope->parent = nodetype_stk.back().second.get();
|
||||||
|
}
|
||||||
nodetype_stk.push_back({ASTNodeType::DefinitionStatement, def_stmt->current_scope});
|
nodetype_stk.push_back({ASTNodeType::DefinitionStatement, def_stmt->current_scope});
|
||||||
std::cerr << std::string(nodetype_stk.size() * 2, ' ') << "Adding a definition statement" << std::endl;
|
std::cerr << std::string(nodetype_stk.size() * 2, ' ') << "Adding a definition statement" << std::endl;
|
||||||
std::string define_type_base;
|
std::string define_type_base;
|
||||||
|
Reference in New Issue
Block a user