123456789_123456789_123456789_123456789_123456789_

Class: YARD::Handlers::C::Base

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: YARD::Handlers::Base
Defined in: lib/yard/handlers/c/base.rb

Overview

Since:

  • 0.8.0

Constant Summary

  • ERROR_CLASS_NAMES =

    Generated by update_error_map.rb (Copy+past results)

    Since:

    • 0.8.0

    # File 'lib/yard/handlers/c/base.rb', line 131
    {
      'rb_eArgError' => 'ArgumentError',
      'rb_eEncodingError' => 'EncodingError',
      'rb_eException' => 'Exception',
      'rb_eFatal' => 'fatal',
      'rb_eFrozenError' => 'FrozenError',
      'rb_eIndexError' => 'IndexError',
      'rb_eInterrupt' => 'Interrupt',
      'rb_eKeyError' => 'KeyError',
      'rb_eLoadError' => 'LoadError',
      'rb_eNameError' => 'NameError',
      'rb_eNoMatchingPatternError' => 'NoMatchingPatternError',
      'rb_eNoMemError' => 'NoMemoryError',
      'rb_eNoMethodError' => 'NoMethodError',
      'rb_eNotImpError' => 'NotImplementedError',
      'rb_eRangeError' => 'RangeError',
      'rb_eRuntimeError' => 'RuntimeError',
      'rb_eScriptError' => 'ScriptError',
      'rb_eSecurityError' => 'SecurityError',
      'rb_eSignal' => 'SignalException',
      'rb_eStandardError' => 'StandardError',
      'rb_eSyntaxError' => 'SyntaxError',
      'rb_eSystemCallError' => 'SystemCallError',
      'rb_eSystemExit' => 'SystemExit',
      'rb_eTypeError' => 'TypeError',
    }

::YARD::CodeObjects - Included

BUILTIN_ALL, BUILTIN_CLASSES, BUILTIN_EXCEPTIONS, BUILTIN_EXCEPTIONS_HASH, BUILTIN_MODULES, CONSTANTMATCH, CONSTANTSTART, CSEP, CSEPQ, ISEP, ISEPQ, METHODMATCH, METHODNAMEMATCH, NAMESPACEMATCH, NSEP, NSEPQ, PROXY_MATCH

Registering objects

Looking up Symbol and Var Values

Parsing an Inner Block

Processing other files

Class Attribute Summary

::YARD::Handlers::Base - Inherited

.namespace_only

Declares that the handler should only be called when inside a ::YARD::CodeObjects::NamespaceObject, not a method body.

.namespace_only?

Class Method Summary

::YARD::Handlers::Base - Inherited

.clear_subclasses

Clear all registered subclasses.

.handlers,
.handles

Declares the statement type which will be processed by this handler.

.handles?
.in_file

Declares that a handler should only be called when inside a filename by its basename or a regex match for the full path.

.inherited, .matches_file?, .new,
.process

Generates a process method, equivalent to +def process; ...

.subclasses

Returns all registered handler subclasses.

Instance Attribute Summary

::YARD::Handlers::Base - Inherited

#extra_state

Share state across different handlers inside of a file.

#globals

::YARD::Handlers can share state for the entire post processing stage through this attribute.

#namespace, #namespace=, #owner, #owner=, #parser, #scope, #scope=, #statement, #visibility, #visibility=

Instance Method Summary

HandlerMethods - Included

::YARD::Handlers::Common::MethodHandler - Included

::YARD::Handlers::Base - Inherited

#abort!

Aborts a handler by raising ::YARD::Handlers::HandlerAborted.

#call_params, #caller_method,
#ensure_loaded!

Ensures that a specific object has been parsed and loaded into the registry.

#parse_block

Parses the semantic "block" contained in the statement node.

#process

The main handler method called by the parser on a statement that matches the handles declaration.

#push_state

Executes a given block with specific state values for #owner, #namespace and #scope.

#register

Do some post processing on a list of code objects.

#register_docstring

Registers any docstring found for the object and expands macros.

#register_dynamic

Registers the object as dynamic if the object is defined inside a method or block (owner != namespace).

#register_ensure_loaded

Ensures that the object's namespace is loaded before attaching it to the namespace.

#register_file_info

Registers the file/line of the declaration with the object.

#register_group

Registers the object as being inside a specific group.

#register_module_function

Registers the same method information on the module function, if the object was defined as a module function.

#register_source,
#register_transitive_tags

Registers any transitive tags from the namespace on the object.

#register_visibility

Registers visibility on a method object.

Constructor Details

This class inherits a constructor from YARD::Handlers::Base

Class Method Details

.handles?(statement, processor) ⇒ Boolean

Returns:

  • (Boolean)

    whether the handler handles this statement

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 10

def self.handles?(statement, processor)
  processor.globals.cruby_processed_files ||= {}
  processor.globals.cruby_processed_files[processor.file] = true

  src = statement.respond_to?(:declaration) ?
    statement.declaration : statement.source

  handlers.any? do |a_handler|
    statement_class >= statement.class &&
      case a_handler
      when String
        src == a_handler
      when Regexp
        src =~ a_handler
      end
  end
end

.statement_class(type = nil)

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 28

def self.statement_class(type = nil)
  if type
    @statement_class = type
  else
    (defined?(@statement_class) && @statement_class) || Statement
  end
end

Instance Method Details

#ensure_variable_defined!(var, max_retries = 1)

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 77

def ensure_variable_defined!(var, max_retries = 1)
  retries = 0
  object = nil

  loop do
    object = namespace_for_variable(var)
    break unless object.is_a?(Proxy)

    raise NamespaceMissingError, object if retries > max_retries
    log.debug "Missing namespace variable #{var} in file `#{parser.file}', moving it to the back of the line."
    parser.parse_remaining_files
    retries += 1
  end

  object
end

#namespace_for_variable(var)

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 64

def namespace_for_variable(var)
  return namespaces[var] if namespaces[var]

  # The global variables for Ruby's core error classes does not
  # represent their Ruby name. So we need to look up these names.
  name = ERROR_CLASS_NAMES[var]
  return P(name) if name

  # Otherwise the name is inferred from the C variable name.
  var = remove_var_prefix(var)
  var.empty? ? nil : P(var)
end

#namespaces

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 94

def namespaces
  globals.cruby_namespaces ||= {}
end

#override_comments

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 60

def override_comments
  globals.cruby_override_comments ||= []
end

#parse_block(opts = {})

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 104

def parse_block(opts = {})
  return if !statement.block || statement.block.empty?
  push_state(opts) do
    parser.process(statement.block)
  end
end

#process_file(file, object)

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 113

def process_file(file, object)
  file = File.cleanpath(file)
  return if processed_files[file]
  processed_files[file] = file
  begin
    log.debug "Processing embedded call to C source #{file}..."
    globals.ordered_parser.files.delete(file) if globals.ordered_parser
    parser.process(Parser::C::CParser.new(File.read(file), file).parse)
  rescue Errno::ENOENT
    log.warn "Missing source file `#{file}' when parsing #{object}"
  end
end

#processed_files

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 98

def processed_files
  globals.cruby_processed_files ||= {}
end

#register_docstring(object, docstring = nil, stmt = nil)

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 38

def register_docstring(object, docstring = nil, stmt = nil)
  super(object, docstring, stmt) if docstring
end

#register_file_info(object, file = nil, line = nil, comments = nil)

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 42

def register_file_info(object, file = nil, line = nil, comments = nil)
  super(object, file, line, comments) if file
end

#register_source(object, source = nil, type = nil)

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 46

def register_source(object, source = nil, type = nil)
  super(object, source, type) if source
end

#register_visibility(object, visibility = nil)

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 50

def register_visibility(object, visibility = nil)
  super(object, visibility) if visibility
end

#remove_var_prefix(var) (private)

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 158

def remove_var_prefix(var)
  var.gsub(/^rb_[mc]|^[a-z_]+/, '')
end

#symbols

Since:

  • 0.8.0

[ GitHub ]

  
# File 'lib/yard/handlers/c/base.rb', line 56

def symbols
  globals.cruby_symbols ||= {}
end