node/lib/metasm/metasm/parse_c.rb
# creates a new CParser, parses all top-level statements
creates a new CParser, parses all top-level statements
creates a new CParser parses all top - level statements
def parse_pragma_callback(otok)
			case otok.raw
			when 'pack'
				nil while lp = @lexer.readtok and lp.type == :space
				nil while rp = @lexer.readtok and rp.type == :space
				if not rp or rp.type != :punct or rp.raw != ')'
					v1 = rp
					nil while rp = @lexer.readtok and rp.type == :space
				end
				if rp and rp.type == :punct and rp.raw == ','
					nil while v2 = @lexer.readtok and v2.type == :space
					nil while rp = @lexer.readtok and rp.type == :space
				end
				raise otok if not rp or lp.type != :punct or rp.type != :punct or lp.raw != '(' or rp.raw != ')'
				raise otok if (v1 and v1.type != :string) or (v2 and (v2.type != :string or v2.raw =~ /[^\d]/))
				if not v1
					@pragma_pack = nil
				elsif v1.raw == 'push'
					@pragma_pack_stack ||= []
					@pragma_pack_stack << pragma_pack
					@pragma_pack = v2.raw.to_i if v2
					raise v2, 'bad pack value' if pragma_pack == 0
				elsif v1.raw == 'pop'
					@pragma_pack_stack ||= []
					raise v1, 'pack stack empty' if @pragma_pack_stack.empty?
					@pragma_pack = @pragma_pack_stack.pop
					@pragma_pack = v2.raw.to_i if v2 and v2.raw	
					raise v2, 'bad pack value' if @pragma_pack == 0
				elsif v1.raw =~ /^\d+$/
					raise v2, '2nd arg unexpected' if v2
					@pragma_pack = v1.raw.to_i
					raise v1, 'bad pack value' if @pragma_pack == 0
				else raise otok
				end
			when 'warning'
				if $DEBUG
					@prev_pragma_callback[otok]
				else
					nil while tok = @lexer.readtok_nopp and tok.type != :eol
					@lexer.unreadtok tok
				end
			when 'prepare_visualstudio'
				prepare_visualstudio
			when 'prepare_gcc'
				prepare_gcc
			when 'data_model'	
				nil while lp = @lexer.readtok and lp.type == :space
				if lp.type != :string or lp.raw !~ /^s?[il]?lp(16|32|64)$/ or not respond_to? lp.raw
					raise lp, "invalid data model (use lp32/lp64/llp64/ilp64)"
				else
					send lp.raw
				end
			else @prev_pragma_callback[otok]
			end
		end
def parse_pragma_callback ( otok ) case otok . raw when 'pack' nil while lp = @lexer . readtok and lp . type == :space nil while rp = @lexer . readtok and rp . type == :space if not rp or rp . type != :punct or rp . raw != ')' v1 = rp nil while rp = @lexer . readtok and rp . type == :space end if rp and rp . type == :punct and rp . raw == ',' nil while v2 = @lexer . readtok and v2 . type == :space nil while rp = @lexer . readtok and rp . type == :space end raise otok if not rp or lp . type != :punct or rp . type != :punct or lp . raw != '(' or rp . raw != ')' raise otok if ( v1 and v1 . type != :string ) or ( v2 and ( v2 . type != :string or v2 . raw =~ / [^ \d ] / ) ) if not v1 @pragma_pack = nil elsif v1 . raw == 'push' @pragma_pack_stack ||= [ ] @pragma_pack_stack << pragma_pack @pragma_pack = v2 . raw . to_i if v2 raise v2 , 'bad pack value' if pragma_pack == 0 elsif v1 . raw == 'pop' @pragma_pack_stack ||= [ ] raise v1 , 'pack stack empty' if @pragma_pack_stack . empty? @pragma_pack = @pragma_pack_stack . pop @pragma_pack = v2 . raw . to_i if v2 and v2 . raw raise v2 , 'bad pack value' if @pragma_pack == 0 elsif v1 . raw =~ / ^ \d +$ / raise v2 , '2nd arg unexpected' if v2 @pragma_pack = v1 . raw . to_i raise v1 , 'bad pack value' if @pragma_pack == 0 else raise otok end when 'warning' if $DEBUG @prev_pragma_callback [ otok ] else nil while tok = @lexer . readtok_nopp and tok . type != :eol @lexer . unreadtok tok end when 'prepare_visualstudio' prepare_visualstudio when 'prepare_gcc' prepare_gcc when 'data_model' nil while lp = @lexer . readtok and lp . type == :space if lp . type != :string or lp . raw !~ / ^s?[il]?lp(16|32|64)$ / or not respond_to? lp . raw raise lp , "invalid data model (use lp32/lp64/llp64/ilp64)" else send lp . raw end else @prev_pragma_callback [ otok ] end end
creates a new CParser, parses all top-level statements
creates a new CParser parses all top - level statements
# #pragma pack(pop, 4) => pop stack, but use 4 as pack value (imho) # the caller checks for :eol # silent discard # XXX use carefully, should be the very first thing parsed
otok