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:



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

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)


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

def name
  @name
end

#versionVersionSpec (readonly)

Returns:



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

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Integer?

Parameters:

  • other (T.untyped)

Returns:

  • (Integer, nil)


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

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:



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

def comparison = @op

#eql?(other) ⇒ Boolean

Parameters:

  • other (T.untyped)

Returns:

  • (Boolean)


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

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

#hashInteger

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

Returns:

  • (Integer)


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

def hash = to_s.hash

#matches_any_version?Boolean

Returns:

  • (Boolean)


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

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:



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

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



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

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:



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

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

#to_condition(cfg_arch) ⇒ Condition

Parameters:

Returns:



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

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:



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

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

#to_ext_ver(cfg_arch) ⇒ ExtensionVersion

Parameters:

Returns:



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

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})


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

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

#to_idl(cfg_arch) ⇒ String

Parameters:

Returns:

  • (String)


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

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)


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

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

#to_s_prettyString

Returns:

  • (String)


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

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

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

Parameters:

Returns:

  • (Z3::BoolExpr)


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

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