Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more restrictive visiting #1443

Merged
merged 1 commit into from
Dec 21, 2024
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: 9 additions & 3 deletions src/ast/ast_allocate_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ namespace das {
bool failedToCMRES = false;
bool isEverything = false;
protected:
virtual bool canVisitStructureFieldInit ( Structure * ) override { return false; }
virtual bool canVisitArgumentInit ( Function * , const VariablePtr &, Expression * ) override { return false; }
virtual bool canVisitQuoteSubexpression ( ExprQuote * ) override { return false; }
virtual bool canVisitGlobalVariable ( Variable * var ) override { return isEverything || var->used; }
virtual bool canVisitFunction ( Function * fun ) override { return isEverything || fun->used; }
// function
Expand Down Expand Up @@ -110,6 +113,9 @@ namespace das {
bool isPermanent = false;
bool isEverything = false;
protected:
virtual bool canVisitStructureFieldInit ( Structure * ) override { return false; }
virtual bool canVisitArgumentInit ( Function * , const VariablePtr &, Expression * ) override { return false; }
virtual bool canVisitQuoteSubexpression ( ExprQuote * ) override { return false; }
virtual bool canVisitGlobalVariable ( Variable * var ) override {
if ( var->stackResolved ) return false;
if ( !var->used && !isEverything ) return false;
Expand Down Expand Up @@ -176,9 +182,6 @@ namespace das {
return Visitor::visitGlobalLet(var);
}
// function
virtual bool canVisitArgumentInit ( Function *, const VariablePtr &, Expression * ) override {
return false;
}
virtual void preVisit ( Function * f ) override {
Visitor::preVisit(f);
func = f;
Expand Down Expand Up @@ -634,6 +637,9 @@ namespace das {
uint32_t bytesTotal = 0;
das_hash_set<string> uniStr;
public:
virtual bool canVisitStructureFieldInit ( Structure * ) override { return false; }
virtual bool canVisitArgumentInit ( Function * , const VariablePtr &, Expression * ) override { return false; }
virtual bool canVisitQuoteSubexpression ( ExprQuote * ) override { return false; }
virtual bool canVisitGlobalVariable ( Variable * var ) override { return var->used; }
virtual bool canVisitFunction ( Function * fun ) override { return fun->used; }
void allocateString ( const string & message ) {
Expand Down
6 changes: 6 additions & 0 deletions src/ast/ast_const_folding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ namespace das {

class NoSideEffectVisitor : public Visitor {
protected:
virtual bool canVisitStructureFieldInit ( Structure * ) override { return false; }
virtual bool canVisitArgumentInit ( Function * , const VariablePtr &, Expression * ) override { return false; }
virtual bool canVisitQuoteSubexpression ( ExprQuote * ) override { return false; }
// make block
virtual void preVisit ( ExprMakeBlock * expr ) override {
Visitor::preVisit(expr);
Expand Down Expand Up @@ -450,6 +453,9 @@ namespace das {
return nullptr;
}
protected:
virtual bool canVisitStructureFieldInit ( Structure * ) override { return false; }
virtual bool canVisitArgumentInit ( Function * , const VariablePtr &, Expression * ) override { return false; }
virtual bool canVisitQuoteSubexpression ( ExprQuote * ) override { return false; }
// swizzle
virtual ExpressionPtr visit ( ExprSwizzle * expr ) override {
if ( expr->type->baseType == expr->value->type->baseType ) {
Expand Down
3 changes: 3 additions & 0 deletions src/ast/ast_debug_info_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace das {

class CollectLocalVariables : public Visitor {
public:
virtual bool canVisitStructureFieldInit ( Structure * ) override { return false; }
virtual bool canVisitArgumentInit ( Function * , const VariablePtr &, Expression * ) override { return false; }
virtual bool canVisitQuoteSubexpression ( ExprQuote * ) override { return false; }
virtual void preVisit ( ExprLet * expr ) override {
for ( const auto & var : expr->variables) {
locals.push_back(make_tuple(var,expr->visibility,bool(var->type->ref)));
Expand Down
2 changes: 2 additions & 0 deletions src/ast/ast_derive_alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ namespace das {
public:
SourceCollector ( const ProgramPtr & prog, bool anyC, bool anyG ) : program(prog), anyCallAliasing(anyC), anyGlobals(anyG) {}
protected:
virtual bool canVisitStructureFieldInit ( Structure * ) override { return false; }
virtual bool canVisitArgumentInit ( Function * , const VariablePtr &, Expression * ) override { return false; }
// this speeds up walking
virtual bool canVisitIfSubexpr ( ExprIfThenElse * ) override {
return !disabled;
Expand Down
6 changes: 6 additions & 0 deletions src/ast/ast_unused.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ namespace das {
return flags;
}
protected:
virtual bool canVisitStructureFieldInit ( Structure * ) override { return false; }
virtual bool canVisitArgumentInit ( Function * , const VariablePtr &, Expression * ) override { return false; }
virtual bool canVisitQuoteSubexpression ( ExprQuote * ) override { return false; }
// Variable initializatoin
virtual void preVisitLetInit ( ExprLet * let, const VariablePtr & var, Expression * init ) override {
Visitor::preVisitLetInit(let, var, init);
Expand Down Expand Up @@ -609,6 +612,9 @@ namespace das {

class RemoveUnusedLocalVariables : public PassVisitor {
protected:
virtual bool canVisitStructureFieldInit ( Structure * ) override { return false; }
virtual bool canVisitArgumentInit ( Function * , const VariablePtr &, Expression * ) override { return false; }
virtual bool canVisitQuoteSubexpression ( ExprQuote * ) override { return false; }
// ExprLet
virtual VariablePtr visitLet ( ExprLet * let, const VariablePtr & var, bool last ) override {
if ( !var->access_get && !var->access_ref && !var->access_init && !var->access_pass ) {
Expand Down
Loading