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

Only record member accesses when origins and occurrences are enabled #627

Merged
merged 2 commits into from
Feb 25, 2021
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: 7 additions & 5 deletions runtime/sema/check_member_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ func (checker *Checker) VisitMemberExpression(expression *ast.MemberExpression)
}
}

checker.MemberAccesses.Put(
expression.AccessPos,
expression.EndPosition(),
memberAccessType,
)
if checker.originsAndOccurrencesEnabled {
checker.MemberAccesses.Put(
expression.AccessPos,
expression.EndPosition(),
memberAccessType,
)
}
}

if member == nil {
Expand Down
11 changes: 7 additions & 4 deletions runtime/sema/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ func WithImportHandler(handler ImportHandlerFunc) Option {
func WithOriginsAndOccurrencesEnabled(enabled bool) Option {
return func(checker *Checker) error {
checker.originsAndOccurrencesEnabled = enabled
if enabled {
checker.memberOrigins = map[Type]map[string]*Origin{}
checker.variableOrigins = map[*Variable]*Origin{}
checker.Occurrences = NewOccurrences()
checker.MemberAccesses = NewMemberAccesses()
}

return nil
}
}
Expand Down Expand Up @@ -240,10 +247,6 @@ func NewChecker(program *ast.Program, location common.Location, options ...Optio
resources: NewResources(),
typeActivations: typeActivations,
functionActivations: functionActivations,
Occurrences: NewOccurrences(),
variableOrigins: map[*Variable]*Origin{},
memberOrigins: map[Type]map[string]*Origin{},
MemberAccesses: NewMemberAccesses(),
containerTypes: map[Type]bool{},
Elaboration: NewElaboration(),
}
Expand Down