Skip to content

Commit

Permalink
Improvements for local variables
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
  • Loading branch information
mballance committed Nov 27, 2023
1 parent 30fdcc7 commit 2e9c644
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
7 changes: 5 additions & 2 deletions ast/linking.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ classes:

- SymbolExecScope:
super: SymbolScope
data: {}
data:
- locals:
- type: list<P<ScopeChild>>
is_ctor: false

- SymbolExtendScope:
super: SymbolScope
Expand Down Expand Up @@ -104,7 +107,7 @@ classes:
- type: UP<SymbolScope>
- is_ctor: false
- body:
- type: UP<SymbolScope>
- type: UP<SymbolExecScope>
- is_ctor: false

- SymbolRefPath:
Expand Down
4 changes: 2 additions & 2 deletions src/AstBuilderInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1584,11 +1584,11 @@ antlrcpp::Any AstBuilderInt::visitString_literal(PSSParser::String_literalContex
DEBUG_ENTER("visitString_literal");
if (ctx->DOUBLE_QUOTED_STRING()) {
std::string value = ctx->DOUBLE_QUOTED_STRING()->getText();
value = value.substr(1, value.size()-1);
value = value.substr(1, value.size()-2);
m_expr = m_factory->mkExprString(value, false);
} else {
std::string value = ctx->TRIPLE_DOUBLE_QUOTED_STRING()->getText();
value = value.substr(3, value.size()-3);
value = value.substr(3, value.size()-6);
m_expr = m_factory->mkExprString(value, true);
}
DEBUG_LEAVE("visitString_literal");
Expand Down
8 changes: 5 additions & 3 deletions src/TaskBuildSymbolTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void TaskBuildSymbolTree::visitFunctionDefinition(ast::IFunctionDefinition *i) {

// Build the body (and subscopes) symbol scopes
int32_t id = func_sym->getChildren().size();
ast::ISymbolScope *body = m_factory->mkSymbolScope(id, "");
ast::ISymbolExecScope *body = m_factory->mkSymbolExecScope(id, "");
body->setLocation(i->getLocation());
body->setUpper(m_scope_s.back());
m_scope_s.push_back(body);
Expand Down Expand Up @@ -537,8 +537,8 @@ void TaskBuildSymbolTree::visitPyImportFromStmt(ast::IPyImportFromStmt *i) {
}

void TaskBuildSymbolTree::visitProceduralStmtDataDeclaration(ast::IProceduralStmtDataDeclaration *i) {
DEBUG_ENTER("visitProceduralStmtDataDeclaration");
ast::ISymbolScope *scope = m_scope_s.back();
DEBUG_ENTER("visitProceduralStmtDataDeclaration %s", i->getName()->getId().c_str());
ast::ISymbolExecScope *scope = dynamic_cast<ast::ISymbolExecScope *>(m_scope_s.back());

std::map<std::string, int32_t>::const_iterator it =
scope->getSymtab().find(i->getName()->getId());
Expand All @@ -551,6 +551,8 @@ void TaskBuildSymbolTree::visitProceduralStmtDataDeclaration(ast::IProceduralStm
);
} else {
int32_t id = scope->getChildren().size();
DEBUG("DataDeclaration %s: %d", i->getName()->getId().c_str(), id);
scope->getLocals().push_back(i);
scope->getSymtab().insert({i->getName()->getId(), id});
scope->getChildren().push_back(i);
}
Expand Down
4 changes: 2 additions & 2 deletions src/TaskResolveRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,13 @@ void TaskResolveRefs::visitSymbolFunctionScope(ast::ISymbolFunctionScope *i) {
m_symtab_it->pushScope(i);
DEBUG(" has i: %d", (m_symtab_it->getScope()->getSymtab().find("i") != m_symtab_it->getScope()->getSymtab().end()));
// DEBUG("Push function body scope");
// m_symtab_it->pushScope(i->getBody());
m_symtab_it->pushScope(i->getBody());
for (std::vector<ast::IScopeChild *>::const_iterator
it=i->getBody()->getChildren().begin();
it!=i->getBody()->getChildren().end(); it++) {
(*it)->accept(m_this);
}
// m_symtab_it->popScope();
m_symtab_it->popScope();
m_symtab_it->popScope();
}

Expand Down
4 changes: 2 additions & 2 deletions src/TaskResolveRootRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void TaskResolveRootRef::visitSymbolScope(ast::ISymbolScope *i) {

DEBUG("imports: %p", i->getImports());
if (it != i->getSymtab().end()) {
DEBUG("Found symbol @ index %d", it->second);
DEBUG("Found symbol %s @ index %d", m_id->getId().c_str(), it->second);
m_ref = m_scope->getScopeSymbolPath(); // Path to 'i'

// Now, add in the child element that we just found
Expand All @@ -90,7 +90,7 @@ void TaskResolveRootRef::visitSymbolScope(ast::ISymbolScope *i) {

void TaskResolveRootRef::visitSymbolExecScope(ast::ISymbolExecScope *i) {
DEBUG_ENTER("visitSymbolExecScope");

visitSymbolScope(i);
DEBUG_LEAVE("visitSymbolExecScope");
}

Expand Down

0 comments on commit 2e9c644

Please sign in to comment.