Class: Preprocessor::Parser

Inherits:
Racc::Parser
  • Object
show all
Defined in:
lib/caphir/preprocessor.rb,
lib/caphir/preprocessor_conf.rb

Constant Summary collapse

Racc_arg =
[
racc_action_table,
racc_action_check,
racc_action_default,
racc_action_pointer,
racc_goto_table,
racc_goto_check,
racc_goto_default,
racc_goto_pointer,
racc_nt_base,
racc_reduce_table,
racc_token_table,
racc_shift_n,
racc_reduce_n,
racc_use_result_var ]
Racc_token_to_s_table =
[
'$end',
'error',
'"defined"',
'UPLUS',
'UMINUS',
'"!"',
'"~"',
'"*"',
'"/"',
'"%"',
'"+"',
'"-"',
'"<<"',
'">>"',
'"<"',
'"<="',
'">"',
'">="',
'"=="',
'"!="',
'"&"',
'"^"',
'"|"',
'"&&"',
'"||"',
'CONSTANT',
'CHARACTER',
'STRING',
'IDENTIFIER',
'NEWLINE',
'SPACE',
'COMMENT',
'SYMBOL',
'UNKNOWN',
'IGNORE',
'IGNORE_ALL',
'"else"',
'"endif"',
'"elif"',
'"ifdef"',
'"ifndef"',
'"if"',
'"include"',
'"include_next"',
'"define"',
'"undef"',
'"line"',
'"error"',
'"warning"',
'"pragma"',
'"#"',
'"##"',
'"("',
'")"',
'"?"',
'":"',
'"..."',
'","',
'$start',
'target',
'statement',
'end_of_statement',
'ignore_statement',
'directive',
'macro_statement',
'conditional_comp',
'include_directive',
'ignore_token',
'ignore_all_token',
'ignore_newline',
'ignore_all_newline',
'ignore_open',
'ignore_other',
'elif_start',
'expression',
'non_space_token',
'identifier',
'if_start',
'elif_else_statement',
'pragma_directive',
'directive_text',
'error_directive',
'warning_directive',
'line_directive',
'text',
'include_start',
'include_file',
'include_next_start',
'include_text',
'include_text_token',
'completely_reserved_word',
'define_identifier',
'parameters',
'text_nospace',
'param_start',
'param_finish',
'init_parameter_list',
'parameter_ellipsis',
'parameter_list',
'partially_reserved_word',
'space_token',
'text_token',
'symbol_token',
'defined_check',
'defined_identifier',
'constant_exp',
'unary_expression',
'cast_expression',
'multiplicative_expression',
'additive_expression',
'shift_expression',
'relational_expression',
'equality_expression',
'and_expression',
'exclusive_or_expression',
'inclusive_or_expression',
'logical_and_expression',
'logical_or_expression',
'conditional_expression']
Racc_debug_parser =
false

Instance Method Summary collapse

Instance Method Details

#_reduce_none(val, _values, result) ⇒ Object

reduce 231 omitted


2167
2168
2169
# File 'lib/caphir/preprocessor.rb', line 2167

def _reduce_none( val, _values, result )
 result
end

#configure(options, includes, compiler = nil, version = nil) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/caphir/preprocessor_conf.rb', line 13

def configure(options, includes, compiler=nil, version=nil)

	# __FILE__ and __LINE__ macros are define in preprocessor.y

	# so '##' is used to paste tokens, not '/**/'
	self.define('__STDC__', nil, '1')
	self.define('__STDC_VERSION__', nil, '199901L')
	comp_time = Time.now
	self.define('__DATE__', nil, comp_time.strftime('%m %d %Y'))
	self.define('__TIME__', nil, comp_time.strftime('%H:%M:%S'))

	case RUBY_PLATFORM
		when /i[0-9]86/
			self.define('__i386__', nil, '1')
		when /powerpc/
			self.define('__ppc__', nil, '1')
#			when /ia64/
#				self.define('__ia64__', nil, '1')
		else
			warn "unrecognized platform: #{RUBY_PLATFORM}"
	end
	
	case RUBY_PLATFORM
		#when /darwin/
		#when /netbsd/
		when /mswin32/
			self.define('__WIN32', nil, '1')
		when /cygwin/
			self.define('__WIN32', nil, '1')
			self.define('__CYGWIN__', nil, '1')
		when /mingw/
			self.define('__WIN32', nil, '1')
			self.define('__MINGW32__', nil, '1')
		#when /bccwin/
		#when /os2/
		#when /sparc/
		#when /AIX/
	end

	case compiler # gcc is the default
		when nil, 'gcc'
			
			warn "invalid gcc version (got #{version} expecting major.minor.patch_level)" \
				if version and not version =~ /\A(\d+)\.(\d+)(?:\.(\d+))?\Z/

			# defaults to gcc 3.3.0
			self.define('__GNUC__', nil, $1 || '3')
			self.define('__GNUC_MINOR__', nil, $2 || '3')
			self.define('__GNUC_PATCHLEVEL__', nil, $3 || '0') # default must be '0'

			self.define('__complex__', nil, '_Complex')

			# define all these as blank
			empty_str = ''.freeze
			self.define('__asm__', ['...'], empty_str)
			self.define('__attribute__', ['...'], empty_str)

			# this is now handled by the parser
			#self.define('throw', ['...'], empty_str)

			# note that __cdecl is included here
			[	'__const__', '__extension__', '__inline__',
				'__signed__', '__volatile__', '__cdecl' ].each do |kw|
				self.define(kw, nil, empty_str)
			end

			self.define('__restrict_arr', nil, 'restrict')
			
			# define psuedo-ANSI C keywords.  Note these
			# may be redefined later in the code
			[ '__const', '__inline', '__restrict', '__signed', '__volatile' ].each do |kw|
				self.define(kw, nil, kw[2, kw.length-2])
			end

			# for gcc 3.4+ compatibility
			self.define('__GLIBC_HAVE_LONG_LONG', nil, '1')
			self.define('__builtin_va_list', nil, 'int *')
			self.define('SHLIB_COMPAT', ['...'], '(0)')
			
		when 'vc++'
			# win32 should already be defined

			self.define('__cdecl', nil, ' ')
			# make up a time stamp
			self.define('__TIMESTAMP__', nil, comp_time.strftime('%a %b %d %H:%M:%S %y'))

			# default version is 6.0 => 1200
			version = version ? ((version.to_f + 6) * 100).to_i.to_s : '1200'
			self.define('_MSC_VER', nil, version)

			# Not sure if these should be added
			#if RUBY_PLATFORM =~ /i[0-9]86/
			#	self.define('_M_IX86', nil, '500') # default
			#else
			#	self.define('_M_MPPC', nil, '601') # default
			#	self.define('_M_PPC', nil, '604') # default
			#end
		when 'tinyc'
			# tinyc compilers do not specify version numbers
			self.define('__TINYC__', nil, '1')
		
		when 'turboc'
			warn "ignoring version number, defaulting to 3.0" if version
			self.define('__TURBOC__', nil, '661') # 3.0

		when 'borland'
			version = version ? expand_version('0x', version) : '0x550'
			self.define('__BORLANDC__', nil, version)

		when 'intel'
			version = version ? expand_version(nil, version) : '600'
			self.define('__INTEL_COMPILER', nil, version)
			self.define('__ICC', nil, version)

		when 'mars'
			version = version ? expand_version('0x', version) : '0x800'
			self.define('__DMC__', nil, version)

		when 'watcom'
			version = version ? expand_version(version) << '0' : '1100'
			self.define('__WATCOMC__', nil, version)

		else
			warn "unrecognized compiler: #{compiler}"
			exit(2)
	end # case
	
	# options should be applied after the preprocessor is configured
	options.each do |opt|
		if opt[0] == :DEFINE
			self.define(opt[1], opt[2], opt[3])
		elsif opt[0] == :UNDEF
			self.undef(opt[1])
		else
			raise "impossible"
		end
	end
	includes.each { |f| self.include_arg(f) }
end