Class: Jade::Entry

Inherits:
Data
  • Object
show all
Defined in:
lib/jade/entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast

Returns:

  • (Object)

    the current value of ast



2
3
4
# File 'lib/jade/entry.rb', line 2

def ast
  @ast
end

#defined_typesObject (readonly)

Returns the value of attribute defined_types

Returns:

  • (Object)

    the current value of defined_types



2
3
4
# File 'lib/jade/entry.rb', line 2

def defined_types
  @defined_types
end

#defined_valuesObject (readonly)

Returns the value of attribute defined_values

Returns:

  • (Object)

    the current value of defined_values



2
3
4
# File 'lib/jade/entry.rb', line 2

def defined_values
  @defined_values
end

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics

Returns:

  • (Object)

    the current value of diagnostics



2
3
4
# File 'lib/jade/entry.rb', line 2

def diagnostics
  @diagnostics
end

#entryObject (readonly)

Returns the value of attribute entry

Returns:

  • (Object)

    the current value of entry



2
3
4
# File 'lib/jade/entry.rb', line 2

def entry
  @entry
end

#envObject (readonly)

Returns the value of attribute env

Returns:

  • (Object)

    the current value of env



2
3
4
# File 'lib/jade/entry.rb', line 2

def env
  @env
end

#exposesObject (readonly)

Returns the value of attribute exposes

Returns:

  • (Object)

    the current value of exposes



2
3
4
# File 'lib/jade/entry.rb', line 2

def exposes
  @exposes
end

#generatedObject (readonly)

Returns the value of attribute generated

Returns:

  • (Object)

    the current value of generated



2
3
4
# File 'lib/jade/entry.rb', line 2

def generated
  @generated
end

#implementationsObject (readonly)

Returns the value of attribute implementations

Returns:

  • (Object)

    the current value of implementations



2
3
4
# File 'lib/jade/entry.rb', line 2

def implementations
  @implementations
end

#importsObject (readonly)

Returns the value of attribute imports

Returns:

  • (Object)

    the current value of imports



2
3
4
# File 'lib/jade/entry.rb', line 2

def imports
  @imports
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/jade/entry.rb', line 2

def name
  @name
end

#sourceObject (readonly)

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



2
3
4
# File 'lib/jade/entry.rb', line 2

def source
  @source
end

#usage_indexObject (readonly)

Returns the value of attribute usage_index

Returns:

  • (Object)

    the current value of usage_index



2
3
4
# File 'lib/jade/entry.rb', line 2

def usage_index
  @usage_index
end

Class Method Details

.empty(name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jade/entry.rb', line 18

def self.empty(name)
  new(
    name:,
    defined_values: {},
    defined_types: {},
    imports: ::Set[],
    exposes: ::Set[],
    ast: nil,
    source: nil,
    generated: nil,
    env: nil,
    implementations: {},
    entry: false,
    diagnostics: Diagnostics::List.empty,
    usage_index: nil,
  )
end

Instance Method Details

#define(symbol) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/jade/entry.rb', line 90

def define(symbol)
  case symbol
  in Symbol::Union | Symbol::Struct | Symbol::Interface
    add_defined_type(symbol)

  in Symbol::Implementation
    add_implementation(symbol)

  in Symbol::Function | Symbol::StdlibFunction |
    Symbol::Constructor | Symbol::Variant |
    Symbol::InteropFunction | Symbol::InterfaceFunction
    add_defined_value(symbol)
  end
end

#expose(symbol) ⇒ Object



36
37
38
# File 'lib/jade/entry.rb', line 36

def expose(symbol)
  with(exposes: exposes + ::Set[symbol])
end

#exposed_type(unqualified_name) ⇒ Object



49
50
51
52
# File 'lib/jade/entry.rb', line 49

def exposed_type(unqualified_name)
  exposes
    .find { it.is_a?(Symbol::TypeRef) && it.name == unqualified_name }
end

#exposed_type_variants(unqualified_name) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/jade/entry.rb', line 54

def exposed_type_variants(unqualified_name)
  type_ref = exposes
    .find { it.is_a?(Symbol::TypeRef) && it.name == unqualified_name }

  return nil unless type_ref

  types[unqualified_name]
    .constructor_refs
    .then { it & exposes.to_a }
    .then { it.empty? ? nil : it }
end

#exposed_value(unqualified_name) ⇒ Object



44
45
46
47
# File 'lib/jade/entry.rb', line 44

def exposed_value(unqualified_name)
  exposes
    .find { it.is_a?(Symbol::ValueRef) && it.name == unqualified_name }
end

#import(import_entry) ⇒ Object



40
41
42
# File 'lib/jade/entry.rb', line 40

def import(import_entry)
  with(imports: imports + ::Set[import_entry])
end

#imported_typesObject



74
75
76
77
78
79
80
# File 'lib/jade/entry.rb', line 74

def imported_types
  imports
    .flat_map(&:unqualified_symbols)
    .select { it.is_a?(Symbol::TypeRef) }
    .map { [it.name, it] }
    .to_h
end

#imported_valuesObject



66
67
68
69
70
71
72
# File 'lib/jade/entry.rb', line 66

def imported_values
  imports
    .flat_map(&:unqualified_symbols)
    .select { it.is_a?(Symbol::ValueRef) }
    .map { [it.name, it] }
    .to_h
end

#interface_digestObject

Source spans are stripped so unrelated edits (e.g. whitespace) shifting one definition’s span don’t bust caches for consumers of others.



125
126
127
# File 'lib/jade/entry.rb', line 125

def interface_digest
  Digest::SHA256.hexdigest(Marshal.dump(interface_snapshot))
end

#lookup_qualified_type(as, type_name) ⇒ Object



113
114
115
116
117
# File 'lib/jade/entry.rb', line 113

def lookup_qualified_type(as, type_name)
  imports
    .find { it.alias == as }
    &.qualified_symbols&.find { it.is_a?(Symbol::TypeRef) && it.name == type_name }
end

#lookup_type(name) ⇒ Object



109
110
111
# File 'lib/jade/entry.rb', line 109

def lookup_type(name)
  types[name]
end

#lookup_value(name) ⇒ Object



105
106
107
# File 'lib/jade/entry.rb', line 105

def lookup_value(name)
  values[name]
end

#pathObject



119
120
121
# File 'lib/jade/entry.rb', line 119

def path
  source.uri.gsub('.jd', '.rb')
end

#typesObject



86
87
88
# File 'lib/jade/entry.rb', line 86

def types
  imported_types.merge(defined_types)
end

#valuesObject



82
83
84
# File 'lib/jade/entry.rb', line 82

def values
  imported_values.merge(defined_values)
end