mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
f7c2791c60
* template/id.h.tmpl (preserved_ids): move from parse.y. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
154 lines
3 KiB
C
154 lines
3 KiB
C
%# -*- c -*-
|
|
/* DO NOT EDIT THIS FILE DIRECTLY */
|
|
/**********************************************************************
|
|
|
|
id.h -
|
|
|
|
$Author$
|
|
created at: Sun Oct 19 21:12:51 2008
|
|
|
|
Copyright (C) 2007 Koichi Sasada
|
|
|
|
**********************************************************************/
|
|
<%
|
|
require 'optparse'
|
|
vpath = ["."]
|
|
input = nil
|
|
|
|
opt = OptionParser.new do |o|
|
|
o.on('-v', '--vpath=DIR') {|dirs| vpath.concat dirs.split(File::PATH_SEPARATOR)}
|
|
input, = o.order!(ARGV)
|
|
end or abort opt.opt_s
|
|
|
|
tokens = nil
|
|
vpath.find do |dir|
|
|
begin
|
|
if line = File.read(File.join(dir, input))[/^\s*enum\s+yytokentype\s*\{([^{}]*)\s*\};/m, 1]
|
|
tokens = line.scan(/\b(t(?:LAST_TOKEN|U(?:PLUS|MINUS)|POW|CMP|EQQ?|[NGL]EQ|(?:AND|OR)OP|N?MATCH|DOT\d|AREF|ASET|[LR]SHFT|LAMBDA)|id\w+)\s*=\s*(\d+),?/m)
|
|
end
|
|
rescue Errno::ENOENT
|
|
nil
|
|
else
|
|
true
|
|
end
|
|
end
|
|
|
|
method_ids = %w[
|
|
Intern
|
|
MethodMissing
|
|
Length
|
|
Size
|
|
Gets
|
|
Succ
|
|
Each
|
|
Lambda
|
|
Send
|
|
__send__
|
|
Initialize
|
|
UScore
|
|
Bitblt
|
|
Answer
|
|
]
|
|
|
|
preserved_ids = %w[
|
|
NULL
|
|
Respond_to
|
|
IFUNC
|
|
CFUNC
|
|
_core_set_method_alias
|
|
_core_set_variable_alias
|
|
_core_undef_method
|
|
_core_define_method
|
|
_core_define_singleton_method
|
|
_core_set_postexe
|
|
_core_hash_from_ary
|
|
_core_hash_merge_ary
|
|
_core_hash_merge_ptr
|
|
_core_hash_merge_kwd
|
|
]
|
|
%>
|
|
#ifndef RUBY_ID_H
|
|
#define RUBY_ID_H
|
|
|
|
#define ID_SCOPE_SHIFT 3
|
|
#define ID_SCOPE_MASK 0x07
|
|
#define ID_LOCAL 0x00
|
|
#define ID_INSTANCE 0x01
|
|
#define ID_GLOBAL 0x03
|
|
#define ID_ATTRSET 0x04
|
|
#define ID_CONST 0x05
|
|
#define ID_CLASS 0x06
|
|
#define ID_JUNK 0x07
|
|
#define ID_INTERNAL ID_JUNK
|
|
|
|
#ifdef USE_PARSE_H
|
|
#include "parse.h"
|
|
#endif
|
|
|
|
#define symIFUNC ID2SYM(idIFUNC)
|
|
#define symCFUNC ID2SYM(idCFUNC)
|
|
|
|
#if !defined tLAST_TOKEN && defined YYTOKENTYPE
|
|
#define tLAST_TOKEN tLAST_TOKEN
|
|
#endif
|
|
|
|
enum ruby_method_ids {
|
|
#ifndef tLAST_TOKEN
|
|
% tokens.each do |token, value|
|
|
<%=token%> = <%=value%>,
|
|
% end
|
|
#endif
|
|
idDot2 = tDOT2,
|
|
idDot3 = tDOT3,
|
|
idUPlus = tUPLUS,
|
|
idUMinus = tUMINUS,
|
|
idPow = tPOW,
|
|
idCmp = tCMP,
|
|
idPLUS = '+',
|
|
idMINUS = '-',
|
|
idMULT = '*',
|
|
idDIV = '/',
|
|
idMOD = '%',
|
|
idLT = '<',
|
|
idLTLT = tLSHFT,
|
|
idLE = tLEQ,
|
|
idGT = '>',
|
|
idGE = tGEQ,
|
|
idEq = tEQ,
|
|
idEqq = tEQQ,
|
|
idNeq = tNEQ,
|
|
idNot = '!',
|
|
idBackquote = '`',
|
|
idEqTilde = tMATCH,
|
|
idNeqTilde = tNMATCH,
|
|
idAREF = tAREF,
|
|
idASET = tASET,
|
|
tPRESERVED_ID_BEGIN = tLAST_TOKEN-1,
|
|
% preserved_ids.each do |token|
|
|
id<%=token%>,
|
|
% end
|
|
tPRESERVED_ID_END,
|
|
tLAST_OP_ID = tPRESERVED_ID_END-1,
|
|
idLAST_OP_ID = tLAST_OP_ID >> ID_SCOPE_SHIFT,
|
|
% method_ids.each do |token|
|
|
t<%=token%>,
|
|
% end
|
|
tLAST_ID,
|
|
#define TOKEN2ID(n) id##n = ((t##n<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
|
% method_ids.each do |token|
|
|
TOKEN2ID(<%=token%>),
|
|
% end
|
|
TOKEN2ID(LAST_ID)
|
|
};
|
|
|
|
#ifdef tLAST_TOKEN
|
|
struct ruby_method_ids_check {
|
|
#define ruby_method_id_check_for(name, value) \
|
|
int checking_for_##name[name == (value) ? 1 : -1]
|
|
% tokens.map do |token, value|
|
|
ruby_method_id_check_for(<%=token%>, <%=value%>);
|
|
% end
|
|
};
|
|
#endif
|
|
|
|
#endif /* RUBY_ID_H */
|