当前位置: 首页>>代码示例>>Golang>>正文


Golang TypeGraph.AwaitableTypeReference方法代码示例

本文整理汇总了Golang中github.com/serulian/compiler/graphs/typegraph.TypeGraph.AwaitableTypeReference方法的典型用法代码示例。如果您正苦于以下问题:Golang TypeGraph.AwaitableTypeReference方法的具体用法?Golang TypeGraph.AwaitableTypeReference怎么用?Golang TypeGraph.AwaitableTypeReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/serulian/compiler/graphs/typegraph.TypeGraph的用法示例。


在下文中一共展示了TypeGraph.AwaitableTypeReference方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: decorateMember


//.........这里部分代码省略.........
		decorator.CreateReturnable(member.Node(), returnType)

		// Constructors have custom signature types that return 'any' to allow them to match
		// interfaces.
		var signatureType = graph.FunctionTypeReference(graph.AnyTypeReference())
		signatureType, _ = stc.addSRGParameterTypes(member, signatureType, graph, reporter)
		decorator.SignatureType(signatureType)

	case srg.OperatorMember:
		memberKind = typegraph.OperatorMemberSignature

		// Operators are read-only.
		isReadOnly = true

		// Operators have type function<DeclaredType>(parameters).
		returnType, _ := stc.resolvePossibleType(member.Node(), member.DeclaredType, graph, reporter)
		functionType := graph.NewTypeReference(graph.FunctionType(), returnType)
		memberType, _ = stc.addSRGParameterTypes(member, functionType, graph, reporter)

		// Make sure instance members under interfaces do not have bodies (and static members do).
		if parent.IsType() {
			parentType := parent.AsType()
			if parentType.TypeKind() == typegraph.ImplicitInterfaceType {
				opDef, found := graph.GetOperatorDefinition(member.Name())

				// Note: If not found, the type graph will emit an error.
				if found {
					if member.HasImplementation() != opDef.IsStatic {
						if opDef.IsStatic {
							reporter.ReportError(member.GraphNode, "Static operator %v under %v %v must have an implementation", member.Name(), parentType.Title(), parentType.Name())
						} else {
							reporter.ReportError(member.GraphNode, "Instance operator %v under %v %v cannot have an implementation", member.Name(), parentType.Title(), parentType.Name())
						}
					}
				}
			}
		}

		// Note: Operators get decorated with a returnable by the construction system automatically.

	case srg.FunctionMember:
		memberKind = typegraph.FunctionMemberSignature

		// Functions are read-only.
		isReadOnly = true

		// Functions have type function<ReturnType>(parameters).
		returnType, _ := stc.resolvePossibleType(member.Node(), member.ReturnType, graph, reporter)

		// Decorate the function with its return type.
		decorator.CreateReturnable(member.Node(), returnType)

		// If the function is an async function, make it non-promising and return a Awaitable instead.
		if member.IsAsyncFunction() {
			isPromising = false
			returnType = graph.AwaitableTypeReference(returnType)
		}

		functionType := graph.NewTypeReference(graph.FunctionType(), returnType)
		memberType, _ = stc.addSRGParameterTypes(member, functionType, graph, reporter)
	}

	// Decorate the member with whether it is exported.
	decorator.Exported(member.IsExported())

	// Decorate the member with whether it is an async function.
	decorator.InvokesAsync(member.IsAsyncFunction())

	// If the member is under a module, then it is static.
	decorator.Static(isStatic || !parent.IsType())

	// Decorate the member with whether it is promising.
	decorator.Promising(isPromising)

	// Decorate the member with whether it has a default value.
	decorator.HasDefaultValue(hasDefaultValue)

	// Decorate the member with whether it is a field.
	decorator.Field(isField)

	// Decorate the member with whether it is implicitly called.
	decorator.ImplicitlyCalled(isImplicitlyCalled)

	// Decorate the member with whether it is read-only.
	decorator.ReadOnly(isReadOnly)

	// Decorate the member with its type.
	decorator.MemberType(memberType)

	// Decorate the member with its kind.
	decorator.MemberKind(memberKind)

	// Decorate the member with its tags, if any.
	for name, value := range member.Tags() {
		decorator.WithTag(name, value)
	}

	// Finalize the member.
	decorator.Decorate()
}
开发者ID:Serulian,项目名称:compiler,代码行数:101,代码来源:typeconstructor.go


注:本文中的github.com/serulian/compiler/graphs/typegraph.TypeGraph.AwaitableTypeReference方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。