Skip to content

Commit

Permalink
👷 Populate env with contract declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
ChmielewskiKamil committed Dec 15, 2024
1 parent c89b56d commit ca287c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 18 additions & 0 deletions analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,29 @@ func (a *Analyzer) discoverSymbols(node ast.Node, env *symbols.Environment) {
for _, decl := range n.Declarations {
a.discoverSymbols(decl, env)
}
case *ast.ContractDeclaration:
a.populateContractDeclaration(n, env)
case *ast.FunctionDeclaration:
a.populateFunctionDeclaration(n, env)
}
}

func (a *Analyzer) populateContractDeclaration(
node *ast.ContractDeclaration, env *symbols.Environment) {
baseSymbol := symbols.BaseSymbol{
Name: node.Name.Value,
SourceFile: a.currentFile.SourceFile,
Offset: node.Pos,
AstNode: node,
}

contractSymbol := &symbols.Contract{
BaseSymbol: baseSymbol,
}

env.Set(node.Name.Value, contractSymbol)
}

func (a *Analyzer) populateFunctionDeclaration(
node *ast.FunctionDeclaration, env *symbols.Environment) {
baseSymbol := symbols.BaseSymbol{
Expand Down
3 changes: 2 additions & 1 deletion analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
)

func Test_PopulateSymbols_GetSymbolsByName(t *testing.T) {
func Test_DiscoverSymbols_GetSymbolsByName(t *testing.T) {
testContractPath := "testdata/foundry/src/002_SimpleCounter.sol"
analyzer := Analyzer{}
analyzer.Init(testContractPath)
Expand All @@ -15,6 +15,7 @@ func Test_PopulateSymbols_GetSymbolsByName(t *testing.T) {
tests := []struct {
expectedSymbolName string
}{
{"Counter"},
{"increment"},
{"decrement"},
{"reset"},
Expand Down

0 comments on commit ca287c2

Please sign in to comment.