зеркало из https://github.com/github/codeql.git
Merge pull request #11492 from aschackmull/shared/util
Shared: Add Util qlpack.
This commit is contained in:
Коммит
3d04b267ef
|
@ -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" }
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
name: codeql/util
|
||||
version: 0.0.1-dev
|
||||
groups: shared
|
||||
library: true
|
||||
dependencies:
|
Загрузка…
Ссылка в новой задаче