* Make `async:true` the default for `invoke` calls (#3750) * Switch away from native grpc impl. (#3728) * Remove usage of the 'deasync' library from @pulumi/pulumi. (#3752) * Only retry as long as we get unavailable back. Anything else continues. (#3769) * Handle all errors for now. (#3781) * Do not assume --yes was present when using pulumi in non-interactive mode (#3793) * Upgrade all paths for sdk and pkg to v2 * Backport C# invoke classes and other recent gen changes (#4288) Adjust C# generation * Replace IDeployment with a sealed class (#4318) Replace IDeployment with a sealed class * .NET: default to args subtype rather than Args.Empty (#4320) * Adding system namespace for Dotnet code gen This is required for using Obsolute attributes for deprecations ``` Iam/InstanceProfile.cs(142,10): error CS0246: The type or namespace name 'ObsoleteAttribute' could not be found (are you missing a using directive or an assembly reference?) [/Users/stack72/code/go/src/github.com/pulumi/pulumi-aws/sdk/dotnet/Pulumi.Aws.csproj] Iam/InstanceProfile.cs(142,10): error CS0246: The type or namespace name 'Obsolete' could not be found (are you missing a using directive or an assembly reference?) [/Users/stack72/code/go/src/github.com/pulumi/pulumi-aws/sdk/dotnet/Pulumi.Aws.csproj] ``` * Fix the nullability of config type properties in C# codegen (#4379)
101 lines
2.9 KiB
Go
101 lines
2.9 KiB
Go
package model
|
|
|
|
import (
|
|
"github.com/hashicorp/hcl/v2"
|
|
"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2/syntax"
|
|
)
|
|
|
|
var typeBuiltins = map[string]Type{
|
|
"string": StringType,
|
|
"number": NumberType,
|
|
"int": IntType,
|
|
"bool": BoolType,
|
|
}
|
|
|
|
var typeFunctions = map[string]FunctionSignature{
|
|
"list": GenericFunctionSignature(func(args []Expression) (StaticFunctionSignature, hcl.Diagnostics) {
|
|
resultType := Type(DynamicType)
|
|
if len(args) == 1 {
|
|
resultType = NewListType(args[0].Type())
|
|
}
|
|
return StaticFunctionSignature{
|
|
Parameters: []Parameter{{Name: "elementType", Type: DynamicType}},
|
|
ReturnType: resultType,
|
|
}, nil
|
|
}),
|
|
"set": GenericFunctionSignature(func(args []Expression) (StaticFunctionSignature, hcl.Diagnostics) {
|
|
resultType := Type(DynamicType)
|
|
if len(args) == 1 {
|
|
resultType = NewSetType(args[0].Type())
|
|
}
|
|
return StaticFunctionSignature{
|
|
Parameters: []Parameter{{Name: "elementType", Type: DynamicType}},
|
|
ReturnType: resultType,
|
|
}, nil
|
|
}),
|
|
"map": GenericFunctionSignature(func(args []Expression) (StaticFunctionSignature, hcl.Diagnostics) {
|
|
resultType := Type(DynamicType)
|
|
if len(args) == 1 {
|
|
resultType = NewMapType(args[0].Type())
|
|
}
|
|
return StaticFunctionSignature{
|
|
Parameters: []Parameter{{Name: "elementType", Type: DynamicType}},
|
|
ReturnType: resultType,
|
|
}, nil
|
|
}),
|
|
"object": GenericFunctionSignature(func(args []Expression) (StaticFunctionSignature, hcl.Diagnostics) {
|
|
var diagnostics hcl.Diagnostics
|
|
resultType := Type(DynamicType)
|
|
if len(args) == 1 {
|
|
if _, isObjectType := args[0].Type().(*ObjectType); isObjectType {
|
|
resultType = args[0].Type()
|
|
} else {
|
|
rng := args[0].SyntaxNode().Range()
|
|
diagnostics = hcl.Diagnostics{{
|
|
Severity: hcl.DiagError,
|
|
Summary: "the argument to object() must be an object type",
|
|
Subject: &rng,
|
|
}}
|
|
}
|
|
}
|
|
return StaticFunctionSignature{
|
|
Parameters: []Parameter{{Name: "objectType", Type: DynamicType}},
|
|
ReturnType: resultType,
|
|
}, diagnostics
|
|
}),
|
|
"tuple": GenericFunctionSignature(func(args []Expression) (StaticFunctionSignature, hcl.Diagnostics) {
|
|
var diagnostics hcl.Diagnostics
|
|
resultType := Type(DynamicType)
|
|
if len(args) == 1 {
|
|
if _, isTupleType := args[0].Type().(*TupleType); isTupleType {
|
|
resultType = args[0].Type()
|
|
} else {
|
|
rng := args[0].SyntaxNode().Range()
|
|
diagnostics = hcl.Diagnostics{{
|
|
Severity: hcl.DiagError,
|
|
Summary: "the argument to tuple() must be an tuple type",
|
|
Subject: &rng,
|
|
}}
|
|
}
|
|
}
|
|
return StaticFunctionSignature{
|
|
Parameters: []Parameter{{Name: "tupleType", Type: DynamicType}},
|
|
ReturnType: resultType,
|
|
}, diagnostics
|
|
}),
|
|
}
|
|
|
|
var TypeScope *Scope
|
|
|
|
func init() {
|
|
TypeScope = NewRootScope(syntax.None)
|
|
for name, typ := range typeBuiltins {
|
|
TypeScope.Define(name, &Variable{
|
|
Name: name,
|
|
VariableType: typ,
|
|
})
|
|
}
|
|
for name, sig := range typeFunctions {
|
|
TypeScope.DefineFunction(name, NewFunction(sig))
|
|
}
|
|
}
|