Merge pull request #11492 from aschackmull/shared/util

Shared: Add Util qlpack.
This commit is contained in:
Anders Schack-Mulligen 2022-11-30 11:56:34 +01:00 коммит произвёл GitHub
Родитель 2f4cf592a7 758cb8b412
Коммит 3d04b267ef
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 73 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Initial release. Includes common utility classes and modules: Unit, Boolean, and Option.

Просмотреть файл

@ -0,0 +1,10 @@
/** Provides the `Boolean` class. */
/**
* A utility class that is equivalent to `boolean`.
*
* As opposed to `boolean`, this type does not require explicit binding.
*/
class Boolean extends boolean {
Boolean() { this = [true, false] }
}

Просмотреть файл

@ -0,0 +1,44 @@
/** Provides a module for constructing optional versions of types. */
/** A type with `toString`. */
signature class TypeWithToString {
string toString();
}
/**
* Constructs an `Option` type that is a disjoint union of the given type and an
* additional singleton element.
*/
module Option<TypeWithToString T> {
private newtype TOption =
TNone() or
TSome(T c)
/**
* An option type. This is either a singleton `None` or a `Some` wrapping the
* given type.
*/
class Option extends TOption {
/** Gets a textual representation of this element. */
string toString() {
this = TNone() and result = "(none)"
or
exists(T c | this = TSome(c) and result = c.toString())
}
/** Gets the wrapped element, if any. */
T asSome() { this = TSome(result) }
/** Holds if this option is the singleton `None`. */
predicate isNone() { this = TNone() }
}
/** The singleton `None` element. */
class None extends Option, TNone { }
/** A wrapper for the given type. */
class Some extends Option, TSome { }
/** Gets the given element wrapped as an `Option`. */
Some some(T c) { result = TSome(c) }
}

Просмотреть файл

@ -0,0 +1,10 @@
/** Provides the `Unit` class. */
/** The unit type. */
private newtype TUnit = TMkUnit()
/** The trivial type with a single element. */
class Unit extends TUnit {
/** Gets a textual representation of this element. */
string toString() { result = "unit" }
}

5
shared/util/qlpack.yml Normal file
Просмотреть файл

@ -0,0 +1,5 @@
name: codeql/util
version: 0.0.1-dev
groups: shared
library: true
dependencies: