node/lib/metasm/metasm/preprocessor.rb
# calls readtok_nopp and handles preprocessor directives
calls readtok_nopp and handles preprocessor directives
calls readtok_nopp and handles preprocessor directives
def readtok
		tok = readtok_nopp
		return tok if not @may_preprocess	
		if not tok
			if not @backtrace.empty?
				raise ParseError, "parse error in #@filename: unmatched #if/#endif" if @backtrace.last.pop != @ifelse_nesting.length
				@filename, @lineno, @text, @pos, @queue = @backtrace.pop
				tok = readtok
			end
		elsif tok.type == :punct and tok.raw == '#' and not tok.expanded_from and @ifelse_nesting.last != :testing
			pos = @pos-2
			while pos >= 0		
				case @text[pos, 1]
				when "\n"
					pos -= 1 if pos > 0 and @text[pos-1] == ?\r
					return tok if pos > 0 and @text[pos-1] == ?\\	
					return tok if pos > 2 and @text[pos-3, 3] == '??/'	
					break	
				when /\s/	
				else return tok	
				end
				pos -= 1
			end
			pretok = []
			rewind = true
			while ntok = readtok_nopp
				pretok << ntok
				if ntok.type == :space	
					next
				elsif ntok.type == :string and not ntok.expanded_from
					rewind = false if preprocessor_directive(ntok)
				end
				break
			end
			if rewind
				: revert
				pretok.reverse_each { |t| unreadtok t }
			else
				tok = readtok
			end
		elsif tok.type == :string and m = @definition[tok.raw] and not tok.expanded_from.to_a.find { |ef| ef.raw == m.name.raw } and
				((m.args and margs = Macro.parse_arglist(self)) or not m.args)
			if defined? @traced_macros and tok.backtrace[-2].to_s[0] == ?" and m.name and m.name.backtrace[-2].to_s[0] == ?<
				@traced_macros |= [tok.raw]	
			end
			m.apply(self, tok, margs).reverse_each { |t| unreadtok t }
			tok = readtok
		end
		tok
	end
def readtok tok = readtok_nopp return tok if not @may_preprocess if not tok if not @backtrace . empty? raise ParseError , "parse error in #@filename: unmatched #if/#endif" if @backtrace . last . pop != @ifelse_nesting . length @filename , @lineno , @text , @pos , @queue = @backtrace . pop tok = readtok end elsif tok . type == :punct and tok . raw == '#' and not tok . expanded_from and @ifelse_nesting . last != :testing pos = @pos - 2 while pos >= 0 case @text [ pos , 1 ] when "\n" pos -= 1 if pos > 0 and @text [ pos - 1 ] == ?\r return tok if pos > 0 and @text [ pos - 1 ] == ?\\ return tok if pos > 2 and @text [ pos - 3 , 3 ] == '??/' break when / \s / else return tok end pos -= 1 end pretok = [ ] rewind = true while ntok = readtok_nopp pretok << ntok if ntok . type == :space next elsif ntok . type == :string and not ntok . expanded_from rewind = false if preprocessor_directive ( ntok ) end break end if rewind pretok . reverse_each { | t | unreadtok t } else tok = readtok end elsif tok . type == :string and m = @definition [ tok . raw ] and not tok . expanded_from . to_a . find { | ef | ef . raw == m . name . raw } and ( ( m . args and margs = Macro . parse_arglist ( self ) ) or not m . args ) if defined? @traced_macros and tok . backtrace [ - 2 ] . to_s [ 0 ] == ?" and m . name and m . name . backtrace [ - 2 ] . to_s [ 0 ] == ?< @traced_macros |= [ tok . raw ] end m . apply ( self , tok , margs ) . reverse_each { | t | unreadtok t } tok = readtok end tok end
calls readtok_nopp and handles preprocessor directives
calls readtok_nopp and handles preprocessor directives
# shortcut # end of file: resume parent # backward check for :eol (skip the '#' itself) # if reach start of file, proceed # check if the newline was a line-continuation # trigraph # proceed # beware switch order, this matches "\n" too # false alarm # nothing # false alarm: revert # XXX return :eol ? # we are in a normal file and expand to an header-defined macro