module Metasm::C::Attributes
Constants
- DECLSPECS
Attributes
attributes[RW]
Public Instance Methods
add_attribute(attr)
click to toggle source
adds an attribute to the object attribute list if it is not already in it
# File metasm/parse_c.rb, line 105 def add_attribute(attr) (@attributes ||= []) << attr if not has_attribute(attr) end
dump_attributes()
click to toggle source
# File metasm/parse_c.rb, line 3450 def dump_attributes if attributes (attributes - DECLSPECS).map { |a| " __attribute__((#{a}))" }.join else '' end end
dump_attributes_pre()
click to toggle source
# File metasm/parse_c.rb, line 3456 def dump_attributes_pre if attributes (attributes & DECLSPECS).map { |a| "__#{a} " }.join else '' end end
has_attribute(attr)
click to toggle source
checks if the object has an attribute in its attribute list
# File metasm/parse_c.rb, line 100 def has_attribute(attr) attributes.to_a.include? attr end
has_attribute_var(attr)
click to toggle source
checks if the object has an attributes a la __attribute__((attr(stuff))), returns 'stuff' (raw, no split on ',' or anything)
# File metasm/parse_c.rb, line 110 def has_attribute_var(attr) $1 if attributes.to_a.find { |a| a =~ /^#{attr}\((.*)\)$/ } end
parse_attributes(parser, allow_declspec = false)
click to toggle source
parses a sequence of __attribute__((anything)) into self.attributes (array of string)
# File metasm/parse_c.rb, line 60 def parse_attributes(parser, allow_declspec = false) while tok = parser.skipspaces and tok.type == :string case keyword = tok.raw when '__attribute__', '__declspec' # synonymous: __attribute__((foo)) == __declspec(foo) raise tok || parser if not tok = parser.skipspaces or tok.type != :punct or tok.raw != '(' raise tok || parser if keyword == '__attribute__' and (not tok = parser.skipspaces or tok.type != :punct or tok.raw != '(') nest = 0 attrib = '' loop do raise parser if not tok = parser.skipspaces if tok.type == :punct and tok.raw == ')' if nest == 0 raise tok || parser if keyword == '__attribute__' and (not tok = parser.skipspaces or tok.type != :punct or tok.raw != ')') break else nest -= 1 end elsif tok.type == :punct and tok.raw == '(' nest += 1 elsif nest == 0 and tok.type == :punct and tok.raw == ',' raise tok || parser if not allow_declspec and DECLSPECS.include? attrib add_attribute attrib attrib = '' next end attrib << tok.raw end raise tok || parser, "attr #{attrib.inspect} not allowed here" if not allow_declspec and DECLSPECS.include? attrib else if allow_declspec and DECLSPECS.include? keyword.gsub('_', '') attrib = keyword.gsub('_', '') else break end end add_attribute(attrib) end parser.unreadtok tok end