本文整理汇总了Golang中github.com/serulian/compiler/compilergraph.GraphNode.GetNodeId方法的典型用法代码示例。如果您正苦于以下问题:Golang GraphNode.GetNodeId方法的具体用法?Golang GraphNode.GetNodeId怎么用?Golang GraphNode.GetNodeId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/serulian/compiler/compilergraph.GraphNode
的用法示例。
在下文中一共展示了GraphNode.GetNodeId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkStaticDependencyCycle
// checkStaticDependencyCycle checks the given variable/field node for a initialization dependency
// cycle.
func (sb *scopeBuilder) checkStaticDependencyCycle(varNode compilergraph.GraphNode, currentDep *proto.ScopeReference, encountered *ordered_map.OrderedMap, path []typegraph.TGMember) bool {
// If we've already examined this dependency, nothing else to do.
if _, found := encountered.Get(currentDep.GetReferencedNode()); found {
return true
}
encountered.Set(currentDep.GetReferencedNode(), true)
// Lookup the dependency (which is a type or module member) in the type graph.
memberNodeId := compilergraph.GraphNodeId(currentDep.GetReferencedNode())
member := sb.sg.tdg.GetTypeOrMember(memberNodeId)
// Find the associated source node.
sourceNodeId, hasSourceNode := member.SourceNodeId()
if !hasSourceNode {
return true
}
updatedPath := append([]typegraph.TGMember(nil), path...)
updatedPath = append(updatedPath, member.(typegraph.TGMember))
// If we've found the variable itself, then we have a dependency cycle.
if sourceNodeId == varNode.GetNodeId() {
// Found a cycle.
var chain bytes.Buffer
chain.WriteString(member.Title())
chain.WriteRune(' ')
chain.WriteString(member.Name())
for _, cMember := range updatedPath {
chain.WriteString(" -> ")
chain.WriteString(cMember.Title())
chain.WriteRune(' ')
chain.WriteString(cMember.Name())
}
sb.decorateWithError(varNode, "Initialization cycle found on %v %v: %s", member.Title(), member.Name(), chain.String())
sb.Status = false
return false
}
// Lookup the dependency in the SRG, so we can recursively check *its* dependencies.
srgNode, hasSRGNode := sb.sg.srg.TryGetNode(sourceNodeId)
if !hasSRGNode {
return true
}
// Recursively lookup the static deps for the node and check them.
nodeScope := sb.getScopeForRootNode(srgNode)
for _, staticDep := range nodeScope.GetStaticDependencies() {
if !sb.checkStaticDependencyCycle(varNode, staticDep, encountered, updatedPath) {
return false
}
}
return true
}