pulumi/pkg/codegen/hcl2/model/functions.go
CyrusNajmabadi 66bd3f4aa8
Breaking changes due to Feature 2.0 work
* 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)
2020-04-14 09:30:25 +01:00

84 lines
3.3 KiB
Go

// Copyright 2016-2020, Pulumi Corporation.
//
// 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 model
import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2/syntax"
)
// FunctionSignature represents a possibly-type-polymorphic function signature.
type FunctionSignature interface {
// GetSignature returns the static signature for the function when invoked with the given arguments.
GetSignature(arguments []Expression) (StaticFunctionSignature, hcl.Diagnostics)
}
// Parameter represents a single function parameter.
type Parameter struct {
Name string // The name of the parameter.
Type Type // The type of the parameter.
}
// StaticFunctionSignature records the parameters and return type of a function.
type StaticFunctionSignature struct {
// The function's fixed parameters.
Parameters []Parameter
// The function's variadic parameter, if any. Any arguments that follow a function's fixed arguments must be
// assignable to this parameter.
VarargsParameter *Parameter
// The return type of the function.
ReturnType Type
}
// GetSignature returns the static signature itself.
func (fs StaticFunctionSignature) GetSignature(arguments []Expression) (StaticFunctionSignature, hcl.Diagnostics) {
return fs, nil
}
// GenericFunctionSignature represents a type-polymorphic function signature. The underlying function will be
// invoked by GenericFunctionSignature.GetSignature to compute the static signature of the function.
type GenericFunctionSignature func(arguments []Expression) (StaticFunctionSignature, hcl.Diagnostics)
// GetSignature returns the static function signature when it is invoked with the given arguments.
func (fs GenericFunctionSignature) GetSignature(arguments []Expression) (StaticFunctionSignature, hcl.Diagnostics) {
return fs(arguments)
}
// Function represents a function definition.
type Function struct {
signature FunctionSignature
}
// NewFunction creates a new function with the given signature.
func NewFunction(signature FunctionSignature) *Function {
return &Function{signature: signature}
}
// SyntaxNode returns the syntax node for the function, which is always syntax.None.
func (f *Function) SyntaxNode() hclsyntax.Node {
return syntax.None
}
// Traverse attempts to traverse the function definition. This will always fail: functions are not traversable.
func (f *Function) Traverse(traverser hcl.Traverser) (Traversable, hcl.Diagnostics) {
return DynamicType, hcl.Diagnostics{cannotTraverseFunction(traverser.SourceRange())}
}
// GetSignature returns the static signature of the function when it is invoked with the given arguments.
func (f *Function) GetSignature(arguments []Expression) (StaticFunctionSignature, hcl.Diagnostics) {
return f.signature.GetSignature(arguments)
}