Skip to content

Commit

Permalink
Merge pull request #3042 from onflow/bastian/analysis-expose-checker
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Jan 24, 2024
2 parents 79a6c8c + 025a045 commit 2036ccc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
9 changes: 4 additions & 5 deletions tools/analysis/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ import (

"github.com/stretchr/testify/require"

"github.com/onflow/cadence/runtime/parser"
"github.com/onflow/cadence/runtime/tests/checker"

"github.com/onflow/cadence/runtime/ast"
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/parser"
"github.com/onflow/cadence/runtime/sema"
"github.com/onflow/cadence/runtime/tests/checker"
"github.com/onflow/cadence/tools/analysis"
)

Expand Down Expand Up @@ -102,7 +101,7 @@ func TestNeedSyntaxAndImport(t *testing.T) {

for _, program := range programs {
require.NotNil(t, program.Program)
require.NotNil(t, program.Elaboration)
require.NotNil(t, program.Checker)

// Run a simple analysis: Detect unnecessary cast

Expand All @@ -114,7 +113,7 @@ func TestNeedSyntaxAndImport(t *testing.T) {
return true
}

types := program.Elaboration.CastingExpressionTypes(castingExpression)
types := program.Checker.Elaboration.CastingExpressionTypes(castingExpression)
leftHandType := types.StaticValueType
rightHandType := types.TargetType

Expand Down
8 changes: 4 additions & 4 deletions tools/analysis/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
)

type Program struct {
Location common.Location
Program *ast.Program
Elaboration *sema.Elaboration
Code []byte
Location common.Location
Program *ast.Program
Checker *sema.Checker
Code []byte
}

// Run runs the given DAG of analyzers in parallel
Expand Down
18 changes: 9 additions & 9 deletions tools/analysis/programs.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ func (programs Programs) load(
return wrapError(err)
}

var elaboration *sema.Elaboration
var checker *sema.Checker
if config.Mode&NeedTypes != 0 {
elaboration, err = programs.check(config, program, location, seenImports)
checker, err = programs.check(config, program, location, seenImports)
if err != nil {
return wrapError(err)
}
}

programs[location] = &Program{
Location: location,
Code: code,
Program: program,
Elaboration: elaboration,
Location: location,
Code: code,
Program: program,
Checker: checker,
}

return nil
Expand All @@ -96,7 +96,7 @@ func (programs Programs) check(
location common.Location,
seenImports importResolutionResults,
) (
*sema.Elaboration,
*sema.Checker,
error,
) {
baseValueActivation := sema.NewVariableActivation(sema.BaseValueActivation)
Expand Down Expand Up @@ -145,7 +145,7 @@ func (programs Programs) check(
return nil, err
}

elaboration = programs[importedLocation].Elaboration
elaboration = programs[importedLocation].Checker.Elaboration
}

return sema.ElaborationImport{
Expand All @@ -163,5 +163,5 @@ func (programs Programs) check(
return nil, err
}

return checker.Elaboration, nil
return checker, nil
}

0 comments on commit 2036ccc

Please sign in to comment.