Class: Udb::ExtensionTerm

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
Comparable
Defined in:
lib/udb/logic.rb

Overview

a terminal for an Extension with a version specifier (a-la an ExtensionRequirement) we don’t use ExtensionRequirement for terminals just to keep LogicNode independent of the rest of UDB

Defined Under Namespace

Classes: ComparisonOp

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, op, ver)

Parameters:



144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/udb/logic.rb', line 144

def initialize(name, op, ver)
  @name = name
  @op = T.let(
    if op.is_a?(String)
      ComparisonOp.deserialize(op)
    else
      op
    end,

    ComparisonOp)
  @version = ver.is_a?(String) ? VersionSpec.new(ver) : ver
end

Instance Attribute Details

#nameString (readonly)

Returns:

  • (String)


135
136
137
# File 'lib/udb/logic.rb', line 135

def name
  @name
end

#versionVersionSpec (readonly)

Returns:



138
139
140
# File 'lib/udb/logic.rb', line 138

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Integer?

Parameters:

  • other (T.untyped)

Returns:

  • (Integer, nil)


257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/udb/logic.rb', line 257

def <=>(other)
  return nil unless other.is_a?(ExtensionTerm)

  other_ext = other
  if @op == ComparisonOp::Equal && other_ext.comparison == ComparisonOp::Equal
    if @name == other_ext.name
      T.must(@version <=> other_ext.version)
    else
      T.must(@name <=> other_ext.name)
    end
  else
    if @name == other_ext.name
      if min_possible_version == other_ext.min_possible_version
        max_possible_version <=> other_ext.max_possible_version
      else
        min_possible_version <=> other_ext.min_possible_version
      end
    else
      T.must(@name <=> other_ext.name)
    end
  end
end

#comparisonComparisonOp

Returns:



141
# File 'lib/udb/logic.rb', line 141

def comparison = @op

#eql?(other) ⇒ Boolean

Parameters:

  • other (T.untyped)

Returns:

  • (Boolean)


290
291
292
# File 'lib/udb/logic.rb', line 290

def eql?(other)
  (self <=> other) == 0
end

#hashInteger

hash and eql? must be implemented to use ExtensionTerm as a Hash key

Returns:

  • (Integer)


282
# File 'lib/udb/logic.rb', line 282

def hash = to_s.hash

#matches_any_version?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/udb/logic.rb', line 158

def matches_any_version?
  @op == ComparisonOp::Equal && @version == VersionSpec.new("0")
end

#max_possible_versionVersionSpec

return the maximum version possible that would satisfy this term

Returns:



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/udb/logic.rb', line 234

def max_possible_version
  case @op
  when ComparisonOp::Equal, ComparisonOp::LessThanOrEqual, ComparisonOp::Compatible
    @version
  when ComparisonOp::LessThan
    if @version.zero?
      nil
    else
      @version.decrement_patch
    end
  when ComparisonOp::GreaterThanOrEqual, ComparisonOp::GreaterThan
    VersionSpec.new("0")
  else
    T.absurd(@op)
  end
end

#min_possible_versionObject

return the minimum version possible that would satisfy this term



219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/udb/logic.rb', line 219

def min_possible_version
  case @op
  when ComparisonOp::Equal, ComparisonOp::GreaterThanOrEqual, ComparisonOp::Compatible
    @version
  when ComparisonOp::GreaterThan
    @version.increment_patch
  when ComparisonOp::LessThanOrEqual, ComparisonOp::LessThan
    VersionSpec.new("0")
  else
    T.absurd(@op)
  end
end

#requirement_specRequirementSpec

Returns:



208
209
210
# File 'lib/udb/logic.rb', line 208

def requirement_spec
  @requirement_spec ||= RequirementSpec.new("#{@op.serialize} #{@version}")
end

#to_condition(cfg_arch) ⇒ Condition

Parameters:

Returns:



176
177
178
# File 'lib/udb/logic.rb', line 176

def to_condition(cfg_arch)
  Condition.new({ "extension" => { "name" => name, "version" => "#{@op.serialize} #{@version}" } }, cfg_arch)
end

#to_ext_req(cfg_arch) ⇒ ExtensionRequirement

Parameters:

Returns:



163
164
165
# File 'lib/udb/logic.rb', line 163

def to_ext_req(cfg_arch)
  cfg_arch.extension_requirement(@name, "#{@op.serialize} #{@version}")
end

#to_ext_ver(cfg_arch) ⇒ ExtensionVersion

Parameters:

Returns:



169
170
171
172
173
# File 'lib/udb/logic.rb', line 169

def to_ext_ver(cfg_arch)
  raise "Not an extension version" unless @op == ComparisonOp::Equal

  cfg_arch.extension_version(@name, @version.to_s)
end

#to_hHash{String => String}

Returns:

  • (Hash{String => String})


191
192
193
194
195
196
# File 'lib/udb/logic.rb', line 191

def to_h
  {
    "name" => @name,
    "version" => "#{@op.serialize} #{@version}"
  }
end

#to_idl(cfg_arch) ⇒ String

Parameters:

Returns:

  • (String)


199
200
201
202
203
204
205
# File 'lib/udb/logic.rb', line 199

def to_idl(cfg_arch)
  if @op == ComparisonOp::GreaterThanOrEqual && @version.eql?("0")
    "implemented?(ExtensionName::#{@name})"
  else
    "implemented_version?(ExtensionName::#{@name}, \"#{@op.serialize} #{@version}\")"
  end
end

#to_sString

Returns:

  • (String)


181
182
183
# File 'lib/udb/logic.rb', line 181

def to_s
  "#{@name}#{@op.serialize}#{@version}"
end

#to_s_prettyString

Returns:

  • (String)


186
187
188
# File 'lib/udb/logic.rb', line 186

def to_s_pretty
  "Extension #{@name}, version #{@version}"
end

#to_z3(solver, cfg_arch) ⇒ Z3::BoolExpr

Parameters:

Returns:

  • (Z3::BoolExpr)


213
214
215
216
# File 'lib/udb/logic.rb', line 213

def to_z3(solver, cfg_arch)
  ext = solver.ext_req(name, requirement_spec, cfg_arch)
  ext.term
end