Skip to content

Commit

Permalink
Merge pull request #2806 from onflow/bastian/extend-type-code-generator
Browse files Browse the repository at this point in the history
Extend type code generator
  • Loading branch information
turbolent authored Sep 23, 2023
2 parents 0b7ce62 + 1e04b7a commit 8696c7f
Show file tree
Hide file tree
Showing 73 changed files with 1,238 additions and 420 deletions.
27 changes: 0 additions & 27 deletions runtime/sema/account.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions runtime/sema/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,31 @@ var FullyEntitledAccountReferenceTypeAnnotation = NewTypeAnnotation(FullyEntitle
func init() {
Account_ContractsTypeAddFunctionType.Arity = &Arity{Min: 2}

addToBaseActivation(AccountMappingType)
addToBaseActivation(CapabilitiesMappingType)
addToBaseActivation(StorageType)
addToBaseActivation(SaveValueType)
addToBaseActivation(LoadValueType)
addToBaseActivation(CopyValueType)
addToBaseActivation(BorrowValueType)
addToBaseActivation(ContractsType)
addToBaseActivation(AddContractType)
addToBaseActivation(UpdateContractType)
addToBaseActivation(RemoveContractType)
addToBaseActivation(KeysType)
addToBaseActivation(AddKeyType)
addToBaseActivation(RevokeKeyType)
addToBaseActivation(InboxType)
addToBaseActivation(PublishInboxCapabilityType)
addToBaseActivation(UnpublishInboxCapabilityType)
addToBaseActivation(ClaimInboxCapabilityType)
addToBaseActivation(CapabilitiesType)
addToBaseActivation(StorageCapabilitiesType)
addToBaseActivation(AccountCapabilitiesType)
addToBaseActivation(PublishCapabilityType)
addToBaseActivation(UnpublishCapabilityType)
addToBaseActivation(GetStorageCapabilityControllerType)
addToBaseActivation(IssueStorageCapabilityControllerType)
addToBaseActivation(GetAccountCapabilityControllerType)
addToBaseActivation(IssueAccountCapabilityControllerType)
}
2 changes: 1 addition & 1 deletion runtime/sema/account_capability_controller.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion runtime/sema/any_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var AnyType = &SimpleType{
Name: "Any",
QualifiedName: "Any",
TypeID: "Any",
tag: AnyTypeTag,
TypeTag: AnyTypeTag,
IsResource: false,
// `Any` is never a valid type in user programs
Storable: true,
Expand Down
4 changes: 2 additions & 2 deletions runtime/sema/anyattachment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var AnyResourceAttachmentType = &SimpleType{
Name: AnyResourceAttachmentTypeName,
QualifiedName: AnyResourceAttachmentTypeName,
TypeID: AnyResourceAttachmentTypeName,
tag: AnyResourceAttachmentTypeTag,
TypeTag: AnyResourceAttachmentTypeTag,
IsResource: true,
// The actual storability of a value is checked at run-time
Storable: true,
Expand All @@ -43,7 +43,7 @@ var AnyStructAttachmentType = &SimpleType{
Name: AnyStructAttachmentTypeName,
QualifiedName: AnyStructAttachmentTypeName,
TypeID: AnyStructAttachmentTypeName,
tag: AnyStructAttachmentTypeTag,
TypeTag: AnyStructAttachmentTypeTag,
IsResource: false,
// The actual storability of a value is checked at run-time
Storable: true,
Expand Down
2 changes: 1 addition & 1 deletion runtime/sema/anyresource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var AnyResourceType = &SimpleType{
Name: "AnyResource",
QualifiedName: "AnyResource",
TypeID: "AnyResource",
tag: AnyResourceTypeTag,
TypeTag: AnyResourceTypeTag,
IsResource: true,
// The actual storability of a value is checked at run-time
Storable: true,
Expand Down
2 changes: 1 addition & 1 deletion runtime/sema/anystruct_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var AnyStructType = &SimpleType{
Name: "AnyStruct",
QualifiedName: "AnyStruct",
TypeID: "AnyStruct",
tag: AnyStructTypeTag,
TypeTag: AnyStructTypeTag,
IsResource: false,
// The actual storability of a value is checked at run-time
Storable: true,
Expand Down
2 changes: 1 addition & 1 deletion runtime/sema/block.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion runtime/sema/bool_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var BoolType = &SimpleType{
Name: "Bool",
QualifiedName: "Bool",
TypeID: "Bool",
tag: BoolTypeTag,
TypeTag: BoolTypeTag,
IsResource: false,
Storable: true,
Equatable: true,
Expand Down
2 changes: 1 addition & 1 deletion runtime/sema/character.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion runtime/sema/deployedcontract.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions runtime/sema/entitlements.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions runtime/sema/entitlements.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@
package sema

//go:generate go run ./gen entitlements.cdc entitlements.gen.go

func init() {
addToBaseActivation(MutateType)
addToBaseActivation(InsertType)
addToBaseActivation(RemoveType)
}
95 changes: 95 additions & 0 deletions runtime/sema/gen/golden_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Cadence - The resource-oriented smart contract programming language
*
* Copyright Dapper Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/sema"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/comparable"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/composite_type_pragma"
"github.com/onflow/cadence/runtime/sema/gen/testdata/constructor"
"github.com/onflow/cadence/runtime/sema/gen/testdata/contract"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/contract"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/docstrings"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/entitlement"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/equatable"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/exportable"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/fields"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/functions"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/importable"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/member_accessible"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/nested"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/simple_resource"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/simple_struct"
_ "github.com/onflow/cadence/runtime/sema/gen/testdata/storable"
"github.com/onflow/cadence/runtime/stdlib"
"github.com/onflow/cadence/runtime/tests/checker"
)

func TestConstructor(t *testing.T) {

t.Parallel()

baseValueActivation := sema.NewVariableActivation(sema.BaseValueActivation)
baseValueActivation.DeclareValue(stdlib.StandardLibraryValue{
Name: constructor.FooType.Identifier,
Type: constructor.FooTypeConstructorType,
Kind: common.DeclarationKindFunction,
})

_, err := checker.ParseAndCheckWithOptions(t,
`
let x = Foo(bar: 1)
`,
checker.ParseAndCheckOptions{
Config: &sema.Config{
BaseValueActivation: baseValueActivation,
},
},
)
require.NoError(t, err)
}

func TestContract(t *testing.T) {

t.Parallel()

baseValueActivation := sema.NewVariableActivation(sema.BaseValueActivation)
baseValueActivation.DeclareValue(stdlib.StandardLibraryValue{
Name: contract.TestType.Identifier,
Type: contract.TestType,
Kind: common.DeclarationKindContract,
})

_, err := checker.ParseAndCheckWithOptions(t,
`
let x = Test.Foo(bar: 1)
`,
checker.ParseAndCheckOptions{
Config: &sema.Config{
BaseValueActivation: baseValueActivation,
},
},
)
require.NoError(t, err)
}
Loading

0 comments on commit 8696c7f

Please sign in to comment.