summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-03-10 23:40:57 -0800
committerGitHub <noreply@github.com>2023-03-10 23:40:57 -0800
commit3a02c7818cb6cbcc70957dfc449ebf32f9dd9e0b (patch)
treed730517014017cd1ae72ee31638ec287528e4076 /tool
parentac47b8df8f0a58d70eb35e95656d83da0c155aa0 (diff)
downloadruby-3a02c7818cb6cbcc70957dfc449ebf32f9dd9e0b.tar.gz
Change the syntax of Primitive.attr! to Symbol (#7501)
Diffstat (limited to 'tool')
-rw-r--r--tool/mk_builtin_loader.rb26
1 files changed, 22 insertions, 4 deletions
diff --git a/tool/mk_builtin_loader.rb b/tool/mk_builtin_loader.rb
index 112c82c8f4..dce76d1c5f 100644
--- a/tool/mk_builtin_loader.rb
+++ b/tool/mk_builtin_loader.rb
@@ -6,6 +6,7 @@ require_relative 'ruby_vm/helpers/c_escape'
SUBLIBS = {}
REQUIRED = {}
+BUILTIN_ATTRS = %w[inline]
def string_literal(lit, str = [])
while lit
@@ -25,6 +26,17 @@ def string_literal(lit, str = [])
end
end
+# e.g. [:symbol_literal, [:symbol, [:@ident, "inline", [19, 21]]]]
+def symbol_literal(lit)
+ symbol_literal, symbol_lit = lit
+ raise "#{lit.inspect} was not :symbol_literal" if symbol_literal != :symbol_literal
+ symbol, ident_lit = symbol_lit
+ raise "#{symbol_lit.inspect} was not :symbol" if symbol != :symbol
+ ident, symbol_name, = ident_lit
+ raise "#{ident.inspect} was not :@ident" if ident != :@ident
+ symbol_name
+end
+
def inline_text argc, arg1
raise "argc (#{argc}) of inline! should be 1" unless argc == 1
arg1 = string_literal(arg1)
@@ -32,6 +44,15 @@ def inline_text argc, arg1
arg1.join("").rstrip
end
+def inline_attr(argc, arg1)
+ raise "argc (#{argc}) of attr! should be 1" unless argc == 1
+ attr = symbol_literal(arg1)
+ unless BUILTIN_ATTRS.include?(attr)
+ raise "attr (#{attr}) was not in: #{BUILTIN_ATTRS.join(', ')}"
+ end
+ attr
+end
+
def make_cfunc_name inlines, name, lineno
case name
when /\[\]/
@@ -138,10 +159,7 @@ def collect_builtin base, tree, name, bs, inlines, locals = nil
if /(.+)[\!\?]\z/ =~ func_name
case $1
when 'attr'
- text = inline_text(argc, args.first)
- if text != 'inline'
- raise "Only 'inline' is allowed to be annotated (but got: '#{text}')"
- end
+ text = inline_attr(argc, args.first)
break
when 'cstmt'
text = inline_text argc, args.first