Ruby: include/ruby/internal/scan_args.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Macros | Functions
scan_args.h File Reference

Compile-time static implementation of rb_scan_args(). More...

`#include "ruby/internal/attr/diagnose_if.h"`
`#include "ruby/internal/attr/error.h"`
`#include "ruby/internal/attr/forceinline.h"`
`#include "ruby/internal/attr/noreturn.h"`
`#include "ruby/internal/config.h"`
`#include "ruby/internal/dllexport.h"`
`#include "ruby/internal/has/attribute.h"`
`#include "ruby/internal/intern/array.h"`
`#include "ruby/internal/intern/error.h"`
`#include "ruby/internal/intern/hash.h"`
`#include "ruby/internal/intern/proc.h"`
`#include "ruby/internal/iterator.h"`
`#include "ruby/internal/static_assert.h"`
`#include "ruby/internal/stdbool.h"`
`#include "ruby/internal/value.h"`
`#include "ruby/assert.h"`

Go to the source code of this file.

## Macros
#define | RB_SCAN_ARGS_PASS_CALLED_KEYWORDS 0
#define | RB_SCAN_ARGS_KEYWORDS 1
#define | RB_SCAN_ARGS_LAST_HASH_KEYWORDS 3
#define | RB_NO_KEYWORDS 0
#define | RB_PASS_KEYWORDS 1
#define | RB_PASS_CALLED_KEYWORDS rb_keyword_given_p()
#define | HAVE_RB_SCAN_ARGS_OPTIONAL_HASH 1
#define | rb_scan_args_isdigit(c) (RBIMPL_CAST((unsigned char)((c)-'0'))<10)
#define | rb_scan_args_count_end(fmt, ofs, vari) ((fmt)[ofs] ? -1 : (vari))
#define | rb_scan_args_count_block(fmt, ofs, vari)
#define | rb_scan_args_count_hash(fmt, ofs, vari)
#define | rb_scan_args_count_trail(fmt, ofs, vari)
#define | rb_scan_args_count_var(fmt, ofs, vari)
#define | rb_scan_args_count_opt(fmt, ofs, vari)
#define | rb_scan_args_count_lead(fmt, ofs, vari)
#define | rb_scan_args_count(fmt) rb_scan_args_count_lead(fmt, 0, 0)
#define | rb_scan_args_verify(fmt, varc)
#define | rb_scan_args0(argc, argv, fmt, varc, vars)
#define | rb_scan_args_kw0(kw_flag, argc, argv, fmt, varc, vars)
#define | rb_scan_args_next_param() vars[vari++]

## Functions
int | rb_scan_args (int, const VALUE *, const char *,...)
int | rb_scan_args_kw (int, int, const VALUE *, const char *,...)
void | rb_scan_args_bad_format (const char *)
void | rb_scan_args_length_mismatch (const char *, int)

## Detailed Description

Compile-time static implementation of rb_scan_args().

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Warning
  Symbols prefixed with either `RBIMPL` or `rbimpl` are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.

Note
  To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance `__VA_ARGS__` is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

This is a beast. It statically analyses the argument spec string, and expands the assignment of variables into dedicated codes.

Definition in file scan_args.h.

## Macro Definition Documentation

## ◆ HAVE_RB_SCAN_ARGS_OPTIONAL_HASH

#define HAVE_RB_SCAN_ARGS_OPTIONAL_HASH 1

Definition at line 50 of file scan_args.h.

## ◆ RB_NO_KEYWORDS

#define RB_NO_KEYWORDS 0

Definition at line 46 of file scan_args.h.

## ◆ RB_PASS_CALLED_KEYWORDS

#define RB_PASS_CALLED_KEYWORDS rb_keyword_given_p()

Definition at line 48 of file scan_args.h.

## ◆ RB_PASS_KEYWORDS

#define RB_PASS_KEYWORDS 1

Definition at line 47 of file scan_args.h.

## ◆ rb_scan_args0

#define rb_scan_args0 | ( |  | argc,
|  |  | argv,
|  |  | fmt,
|  |  | varc,
|  |  | vars
| ) |  |

Value:
rb_scan_args_set(RB_SCAN_ARGS_PASS_CALLED_KEYWORDS, argc, argv, \
rb_scan_args_n_lead(fmt), \
rb_scan_args_n_opt(fmt), \
rb_scan_args_n_trail(fmt), \
rb_scan_args_f_var(fmt), \
rb_scan_args_f_hash(fmt), \
rb_scan_args_f_block(fmt), \
(rb_scan_args_verify(fmt, varc), vars), (char *)fmt, varc)
argc
int argc
Definition: ruby.c:240
argv
char ** argv
Definition: ruby.c:241
rb_scan_args_verify
#define rb_scan_args_verify(fmt, varc)
Definition: scan_args.h:116
RB_SCAN_ARGS_PASS_CALLED_KEYWORDS
#define RB_SCAN_ARGS_PASS_CALLED_KEYWORDS
Definition: scan_args.h:43

Definition at line 239 of file scan_args.h.

## ◆ rb_scan_args_count

#define rb_scan_args_count | ( |  | fmt | ) | rb_scan_args_count_lead(fmt, 0, 0)

Definition at line 102 of file scan_args.h.

## ◆ rb_scan_args_count_block

#define rb_scan_args_count_block | ( |  | fmt,
|  |  | ofs,
|  |  | vari
| ) |  |

Value:
((fmt)[ofs]!='&' ? \
rb_scan_args_count_end(fmt, ofs, vari) : \
rb_scan_args_count_end(fmt, (ofs)+1, (vari)+1))
rb_scan_args_count_end
#define rb_scan_args_count_end(fmt, ofs, vari)
Definition: scan_args.h:69

Definition at line 72 of file scan_args.h.

## ◆ rb_scan_args_count_end

#define rb_scan_args_count_end | ( |  | fmt,
|  |  | ofs,
|  |  | vari
| ) |  | ((fmt)[ofs] ? -1 : (vari))

Definition at line 69 of file scan_args.h.

## ◆ rb_scan_args_count_hash

#define rb_scan_args_count_hash | ( |  | fmt,
|  |  | ofs,
|  |  | vari
| ) |  |

Value:
((fmt)[ofs]!=':' ? \
rb_scan_args_count_block(fmt, ofs, vari) : \
rb_scan_args_count_block(fmt, (ofs)+1, (vari)+1))
rb_scan_args_count_block
#define rb_scan_args_count_block(fmt, ofs, vari)
Definition: scan_args.h:72

Definition at line 77 of file scan_args.h.

## ◆ rb_scan_args_count_lead

#define rb_scan_args_count_lead | ( |  | fmt,
|  |  | ofs,
|  |  | vari
| ) |  |

Value:
(!rb_scan_args_isdigit((fmt)[ofs]) ? \
rb_scan_args_count_var(fmt, ofs, vari) : \
rb_scan_args_count_opt(fmt, (ofs)+1, (vari)+(fmt)[ofs]-'0'))
rb_scan_args_count_opt
#define rb_scan_args_count_opt(fmt, ofs, vari)
Definition: scan_args.h:92
rb_scan_args_isdigit
#define rb_scan_args_isdigit(c)
Definition: scan_args.h:67

Definition at line 97 of file scan_args.h.

## ◆ rb_scan_args_count_opt

#define rb_scan_args_count_opt | ( |  | fmt,
|  |  | ofs,
|  |  | vari
| ) |  |

Value:
(!rb_scan_args_isdigit((fmt)[ofs]) ? \
rb_scan_args_count_var(fmt, ofs, vari) : \
rb_scan_args_count_var(fmt, (ofs)+1, (vari)+(fmt)[ofs]-'0'))
rb_scan_args_count_var
#define rb_scan_args_count_var(fmt, ofs, vari)
Definition: scan_args.h:87

Definition at line 92 of file scan_args.h.

## ◆ rb_scan_args_count_trail

#define rb_scan_args_count_trail | ( |  | fmt,
|  |  | ofs,
|  |  | vari
| ) |  |

Value:
(!rb_scan_args_isdigit((fmt)[ofs]) ? \
rb_scan_args_count_hash(fmt, ofs, vari) : \
rb_scan_args_count_hash(fmt, (ofs)+1, (vari)+((fmt)[ofs]-'0')))
rb_scan_args_count_hash
#define rb_scan_args_count_hash(fmt, ofs, vari)
Definition: scan_args.h:77

Definition at line 82 of file scan_args.h.

## ◆ rb_scan_args_count_var

#define rb_scan_args_count_var | ( |  | fmt,
|  |  | ofs,
|  |  | vari
| ) |  |

Value:
((fmt)[ofs]!='*' ? \
rb_scan_args_count_trail(fmt, ofs, vari) : \
rb_scan_args_count_trail(fmt, (ofs)+1, (vari)+1))
rb_scan_args_count_trail
#define rb_scan_args_count_trail(fmt, ofs, vari)
Definition: scan_args.h:82

Definition at line 87 of file scan_args.h.

## ◆ rb_scan_args_isdigit

#define rb_scan_args_isdigit | ( |  | c | ) | (RBIMPL_CAST((unsigned char)((c)-'0'))<10)

Definition at line 67 of file scan_args.h.

## ◆ RB_SCAN_ARGS_KEYWORDS

#define RB_SCAN_ARGS_KEYWORDS 1

Definition at line 44 of file scan_args.h.

## ◆ rb_scan_args_kw0

#define rb_scan_args_kw0 | ( |  | kw_flag,
|  |  | argc,
|  |  | argv,
|  |  | fmt,
|  |  | varc,
|  |  | vars
| ) |  |

Value:
rb_scan_args_set(kw_flag, argc, argv, \
rb_scan_args_n_lead(fmt), \
rb_scan_args_n_opt(fmt), \
rb_scan_args_n_trail(fmt), \
rb_scan_args_f_var(fmt), \
rb_scan_args_f_hash(fmt), \
rb_scan_args_f_block(fmt), \
(rb_scan_args_verify(fmt, varc), vars), (char *)fmt, varc)

Definition at line 248 of file scan_args.h.

## ◆ RB_SCAN_ARGS_LAST_HASH_KEYWORDS

#define RB_SCAN_ARGS_LAST_HASH_KEYWORDS 3

Definition at line 45 of file scan_args.h.

## ◆ rb_scan_args_next_param

#define rb_scan_args_next_param | ( |  | ) | vars[vari++]

## ◆ RB_SCAN_ARGS_PASS_CALLED_KEYWORDS

#define RB_SCAN_ARGS_PASS_CALLED_KEYWORDS 0

Definition at line 43 of file scan_args.h.

## ◆ rb_scan_args_verify

#define rb_scan_args_verify | ( |  | fmt,
|  |  | varc
| ) |  |

Value:
(sizeof(char[1-2*(rb_scan_args_count(fmt)<0)])!=1 ? \
rb_scan_args_bad_format(fmt) : \
sizeof(char[1-2*(rb_scan_args_count(fmt)!=(varc))])!=1 ? \
rb_scan_args_length_mismatch(fmt, varc) : \
RBIMPL_ASSERT_NOTHING)
rb_scan_args_length_mismatch
void rb_scan_args_length_mismatch(const char *, int)
rb_scan_args_count
#define rb_scan_args_count(fmt)
Definition: scan_args.h:102

Definition at line 116 of file scan_args.h.

## Function Documentation

## ◆ rb_scan_args_bad_format()

void rb_scan_args_bad_format | ( | const char * |  | ) |

## ◆ rb_scan_args_length_mismatch()

void rb_scan_args_length_mismatch | ( | const char * | ,
|  | int |
| ) |  |