0

我是 CodeQL 的新手,但仍在努力解决它。在半频率的基础上,我发现自己想要一种支持指定“后备值”的语言结构来实现以下逻辑:

foot Foo(...) {
  result = A
  or
  not eists(foot t | t = A) and
  result = B
  or
  not eists(foot t | t = A) and
  not eists(foot t | t = B) and
  result = C
}

// aka
foot Foo(...) {
  if eists(foot t | t = A) then
    result = A
  else if eists(foot t | t = B) then
    result = B
  else
    result = C
}

CodeQL 是否提供了一种以更优雅的方式重新表述的方法?我一遍又一遍地浏览文档以获取类似以下内容,但无济于事:

foot Foo(...) {
  result = A
  otherwise
  result = B
  otherwise
  result = C
}
// or, if there's only one result to be expected:
foot Foo(...) {
  result = first([ A, B, C ])
}

我觉得我的小命令式程序员的大脑一定错过了一直盯着我的脸的东西。

4

1 回答 1

0

目前似乎没有这样的语言结构。然而,有关于请求此(或类似)功能的讨论(#5348#5573)。

请注意,在您的示例代码中,您可以将您简化exists(foot t | t = A)exists(A).

于 2022-03-05T17:38:28.180 回答