Skip to content

Commit

Permalink
Define PrimitiveType
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdrag00nv2 committed Dec 4, 2023
1 parent 787812f commit 9336753
Show file tree
Hide file tree
Showing 31 changed files with 125 additions and 6 deletions.
1 change: 1 addition & 0 deletions runtime/sema/account_capability_controller.gen.go

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

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

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

1 change: 1 addition & 0 deletions runtime/sema/bool_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var BoolType = &SimpleType{
TypeID: "Bool",
TypeTag: BoolTypeTag,
IsResource: false,
IsPrimitive: true,
Storable: true,
Equatable: true,
Comparable: true,
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/character.gen.go

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

1 change: 1 addition & 0 deletions runtime/sema/deployedcontract.gen.go

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

3 changes: 3 additions & 0 deletions runtime/sema/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,7 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr {
// TypeID: TestTypeName,
// tag: TestTypeTag,
// IsResource: true,
// IsPrimitive: false,
// Storable: false,
// Equatable: false,
// Comparable: false,
Expand All @@ -1583,12 +1584,14 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr {
//}

isResource := ty.compositeKind == common.CompositeKindResource
_, isPrimitive := sema.GeneratedPrimitiveSimpleTypes[ty.typeName]
elements := []dst.Expr{
goKeyValue("Name", typeNameVarIdent(ty.fullTypeName)),
goKeyValue("QualifiedName", typeNameVarIdent(ty.fullTypeName)),
goKeyValue("TypeID", typeNameVarIdent(ty.fullTypeName)),
goKeyValue("TypeTag", typeTagVarIdent(ty.fullTypeName)),
goKeyValue("IsResource", goBoolLit(isResource)),
goKeyValue("IsPrimitive", goBoolLit(isPrimitive)),
goKeyValue("Storable", goBoolLit(ty.storable)),
goKeyValue("Equatable", goBoolLit(ty.equatable)),
goKeyValue("Comparable", goBoolLit(ty.comparable)),
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/comparable/test.golden.go

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

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/docstrings/test.golden.go

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

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/equatable/test.golden.go

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

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/exportable/test.golden.go

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

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/fields/test.golden.go

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

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/functions/test.golden.go

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

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/importable/test.golden.go

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

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/member_accessible/test.golden.go

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

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/simple_resource/test.golden.go

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

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/simple_struct/test.golden.go

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

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/storable/test.golden.go

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

1 change: 1 addition & 0 deletions runtime/sema/invalid_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var InvalidType = &SimpleType{
TypeID: "<<invalid>>",
TypeTag: InvalidTypeTag,
IsResource: false,
IsPrimitive: false,
Storable: false,
Equatable: false,
Comparable: false,
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/meta_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var MetaType = &SimpleType{
TypeID: MetaTypeName,
TypeTag: MetaTypeTag,
IsResource: false,
IsPrimitive: false,
Storable: true,
Equatable: true,
Comparable: false,
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/never_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var NeverType = &SimpleType{
TypeID: "Never",
TypeTag: NeverTypeTag,
IsResource: false,
IsPrimitive: false,
Storable: false,
Equatable: false,
Comparable: false,
Expand Down
5 changes: 5 additions & 0 deletions runtime/sema/path_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var PathType = &SimpleType{
TypeID: "Path",
TypeTag: PathTypeTag,
IsResource: false,
IsPrimitive: true,
Storable: true,
Equatable: true,
Comparable: false,
Expand All @@ -45,6 +46,7 @@ var StoragePathType = &SimpleType{
TypeID: "StoragePath",
TypeTag: StoragePathTypeTag,
IsResource: false,
IsPrimitive: true,
Storable: true,
Equatable: true,
Comparable: false,
Expand All @@ -61,6 +63,7 @@ var CapabilityPathType = &SimpleType{
TypeID: "CapabilityPath",
TypeTag: CapabilityPathTypeTag,
IsResource: false,
IsPrimitive: true,
Storable: true,
Equatable: true,
Comparable: false,
Expand All @@ -81,6 +84,7 @@ var PublicPathType = &SimpleType{
TypeID: "PublicPath",
TypeTag: PublicPathTypeTag,
IsResource: false,
IsPrimitive: true,
Storable: true,
Equatable: true,
Comparable: false,
Expand All @@ -97,6 +101,7 @@ var PrivatePathType = &SimpleType{
TypeID: "PrivatePath",
TypeTag: PrivatePathTypeTag,
IsResource: false,
IsPrimitive: true,
Storable: true,
Equatable: true,
Comparable: false,
Expand Down
9 changes: 9 additions & 0 deletions runtime/sema/simple_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import (
"github.com/onflow/cadence/runtime/common"
)

var GeneratedPrimitiveSimpleTypes = map[string]bool{
CharacterTypeName: true,
}

type ValueIndexingInfo struct {
ElementType func(_ bool) Type
IndexingType *NumericType
Expand All @@ -50,6 +54,7 @@ type SimpleType struct {
Comparable bool
Storable bool
IsResource bool
IsPrimitive bool
ContainFields bool
}

Expand Down Expand Up @@ -83,6 +88,10 @@ func (t *SimpleType) IsResourceType() bool {
return t.IsResource
}

func (t *SimpleType) IsPrimitiveType() bool {
return t.IsPrimitive
}

func (t *SimpleType) IsInvalidType() bool {
return t == InvalidType
}
Expand Down
13 changes: 7 additions & 6 deletions runtime/sema/storable_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ var StorableType = &SimpleType{
// only used as e.g. a type bound, but is not accessible
// to user programs, i.e. can't be used in type annotations
// for e.g. parameters, return types, fields, etc.
IsResource: false,
Storable: true,
Equatable: false,
Comparable: false,
Exportable: false,
Importable: false,
IsResource: false,
IsPrimitive: false,
Storable: true,
Equatable: false,
Comparable: false,
Exportable: false,
Importable: false,
IsSuperTypeOf: func(subType Type) bool {
storableResults := map[*Member]bool{}
return subType.IsStorable(storableResults)
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/storage_capability_controller.gen.go

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

1 change: 1 addition & 0 deletions runtime/sema/string_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var StringType = &SimpleType{
TypeID: "String",
TypeTag: StringTypeTag,
IsResource: false,
IsPrimitive: true,
Storable: true,
Equatable: true,
Comparable: true,
Expand Down
Loading

0 comments on commit 9336753

Please sign in to comment.