Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/openscad_cpp_parser/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ std::unique_ptr<Scope> buildScopes(const std::vector<std::unique_ptr<ASTNode>>&
// why this exists. Never takes ownership.
std::unique_ptr<Scope> buildScopes(const std::vector<ASTNode*>& ast);

// Same, but recording into a table the CALLER owns, and not attaching it to
// the returned root.
//
// For a resolution that spans several files: `use <file>` builds a separate
// root Scope per used file, but all of them are read back through one
// evaluation, so their nodes' scopes have to land in ONE table. A per-root
// table would leave the outer evaluation unable to see anything the nested
// resolutions recorded -- every node of a used file would read back as
// having no scope.
std::unique_ptr<Scope> buildScopesInto(const std::vector<std::unique_ptr<ASTNode>>& ast, ScopeTable& table);
std::unique_ptr<Scope> buildScopesInto(const std::vector<ASTNode*>& ast, ScopeTable& table);

// Parses `code`. Throws ParseError (with the full caret diagnostic) on a
// syntax error.
//
Expand Down
22 changes: 16 additions & 6 deletions src/scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,36 @@

namespace oscad {

std::unique_ptr<Scope> buildScopes(const std::vector<std::unique_ptr<ASTNode>>& ast) {
auto owned = std::make_unique<ScopeTable>();
ScopeTableScope recording(*owned);
std::unique_ptr<Scope> buildScopesInto(const std::vector<std::unique_ptr<ASTNode>>& ast, ScopeTable& table) {
ScopeTableScope recording(table);
auto root = std::make_unique<Scope>();
collectHoistedDeclarations(ast, *root);
for (auto& node : ast) {
node->buildScope(*root);
}
root->adoptTable(std::move(owned));
return root;
}

std::unique_ptr<Scope> buildScopes(const std::vector<ASTNode*>& ast) {
std::unique_ptr<Scope> buildScopes(const std::vector<std::unique_ptr<ASTNode>>& ast) {
auto owned = std::make_unique<ScopeTable>();
ScopeTableScope recording(*owned);
auto root = buildScopesInto(ast, *owned);
root->adoptTable(std::move(owned));
return root;
}

std::unique_ptr<Scope> buildScopesInto(const std::vector<ASTNode*>& ast, ScopeTable& table) {
ScopeTableScope recording(table);
auto root = std::make_unique<Scope>();
collectHoistedDeclarations(ast, *root);
for (ASTNode* node : ast) {
node->buildScope(*root);
}
return root;
}

std::unique_ptr<Scope> buildScopes(const std::vector<ASTNode*>& ast) {
auto owned = std::make_unique<ScopeTable>();
auto root = buildScopesInto(ast, *owned);
root->adoptTable(std::move(owned));
return root;
}
Expand Down
Loading