Class: Carbon::Compiler::Metanostic::List
- Inherits:
-
Object
- Object
- Carbon::Compiler::Metanostic::List
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/carbon/compiler/metanostic/list.rb
Overview
A list of diagnostics. This handles setting up the modes of new, emitted diagnostics, and reporting diagnostic types.
Constant Summary collapse
- THRESHOLDS =
{ "warnings" => 100, "errors" => 20 }.freeze
Instance Attribute Summary collapse
-
#defaults ⇒ {::Hash => Metanostic}
readonly
The default hash of metanostics.
-
#files ⇒ Object
readonly
The project files for the metanostic list.
-
#state ⇒ State
readonly
The current state.
Instance Method Summary collapse
-
#emit(name, location = Location.default, format = []) ⇒ Object
(also: #<<, #push)
Emits a diagnostic to the list.
-
#errors ⇒ <Diagnostic>
Returns a list of diagnostics that have the Mode::ERROR mode.
-
#initialize ⇒ List
constructor
Initialize the list.
-
#output(io) ⇒ void
Outputs all of the diagnostics in this list.
-
#panics ⇒ <Diagnostic>
Returns a list of diagnostics that have the Mode::PANIC mode.
-
#warnings ⇒ <Diagnostic>
Returns a list of diagnostics that have the Mode::WARNING mode.
Constructor Details
#initialize ⇒ List
Initialize the list.
36 37 38 39 40 41 |
# File 'lib/carbon/compiler/metanostic/list.rb', line 36 def initialize @defaults = Metanostic::Defaults.defaults @state = State.new @list = Concurrent::Array.new @files = Concurrent::Hash.new end |
Instance Attribute Details
#defaults ⇒ {::Hash => Metanostic} (readonly)
The default hash of metanostics.
21 22 23 |
# File 'lib/carbon/compiler/metanostic/list.rb', line 21 def defaults @defaults end |
#files ⇒ Object (readonly)
The project files for the metanostic list. This is to provide context for diagnostic errors.
26 27 28 |
# File 'lib/carbon/compiler/metanostic/list.rb', line 26 def files @files end |
#state ⇒ State (readonly)
The current state. This contains information about what modes each diagnostic should inherit.
16 17 18 |
# File 'lib/carbon/compiler/metanostic/list.rb', line 16 def state @state end |
Instance Method Details
#emit(name, location = Location.default, format = []) ⇒ Object Also known as: <<, push
Emits a diagnostic to the list. It sets up the data to pass to the diagnostic. If the diagnostic cannot be found, it instead emits a ‘System/Error` diagnostic.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/carbon/compiler/metanostic/list.rb', line 67 def emit(name, location = Location.default, format = []) mode, = @state.fetch(name) do return emit("System/Error", location, [name]) end = format.is_a?(::String) ? format : sprintf(., *format) stack = caller[2..7] diagnostic = Diagnostic.new(meta: , location: location, message: , mode: mode, list: self, stack: stack) @list << diagnostic diagnostic.output($stderr) diagnostic_check end |
#errors ⇒ <Diagnostic>
Returns a list of diagnostics that have the Mode::ERROR mode.
53 54 55 |
# File 'lib/carbon/compiler/metanostic/list.rb', line 53 def errors select { |d| d..default == Mode::ERROR } end |
#output(io) ⇒ void
This method returns an undefined value.
Outputs all of the diagnostics in this list. Does nothing if Carbon.quiet? is true.
92 93 94 95 |
# File 'lib/carbon/compiler/metanostic/list.rb', line 92 def output(io) return if Carbon.quiet? each { |i| i.output(io, @files) } end |
#panics ⇒ <Diagnostic>
Returns a list of diagnostics that have the Mode::PANIC mode.
46 47 48 |
# File 'lib/carbon/compiler/metanostic/list.rb', line 46 def panics select { |d| d..default == Mode::PANIC } end |
#warnings ⇒ <Diagnostic>
Returns a list of diagnostics that have the Mode::WARNING mode.
60 61 62 |
# File 'lib/carbon/compiler/metanostic/list.rb', line 60 def warnings select { |d| d..default == Mode::WARNING } end |