class AdLint::Cc1::DeclaratorInterpreter
Public Class Methods
new(type_tbl, interp, type)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7639 def initialize(type_tbl, interp, type) @type_table = type_tbl @interpreter = interp @type = type end
Public Instance Methods
visit_abbreviated_function_declarator(node)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7687 def visit_abbreviated_function_declarator(node) @type = qualify_by_pointer(@type, node) @type = @type_table.function_type(@type, []) @type = node.base.accept(self) end
visit_ansi_function_declarator(node)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7668 def visit_ansi_function_declarator(node) @type = qualify_by_pointer(@type, node) param_types = lookup_parameter_types(node) if param_types.include?(nil) return @type_table.unresolved_type else have_va_list = node.parameter_type_list.have_va_list? @type = @type_table.function_type(@type, param_types, have_va_list) @type = node.base.accept(self) end @type end
visit_array_abstract_declarator(node)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7704 def visit_array_abstract_declarator(node) @type = qualify_by_pointer(@type, node) if size_expr = node.size_expression if ary_size = evaluate_size_expression(size_expr) @type = @type_table.array_type(@type, ary_size) else return @type_table.unresolved_type end else @type = @type_table.array_type(@type) end @type = node.base.accept(self) if node.base @type end
visit_array_declarator(node)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7654 def visit_array_declarator(node) @type = qualify_by_pointer(@type, node) if size_expr = node.size_expression if ary_size = evaluate_size_expression(size_expr) @type = @type_table.array_type(@type, ary_size) else return @type_table.unresolved_type end else @type = @type_table.array_type(@type) end @type = node.base.accept(self) end
visit_function_abstract_declarator(node)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7719 def visit_function_abstract_declarator(node) @type = qualify_by_pointer(@type, node) param_types = lookup_parameter_types(node) if param_types.include?(nil) return @type_table.unresolved_type else @type = @type_table.function_type(@type, param_types) @type = node.base.accept(self) if node.base end @type end
visit_grouped_abstract_declarator(node)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7699 def visit_grouped_abstract_declarator(node) @type = qualify_by_pointer(@type, node) @type = node.base.accept(self) end
visit_grouped_declarator(node)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7649 def visit_grouped_declarator(node) @type = qualify_by_pointer(@type, node) @type = node.base.accept(self) end
visit_identifier_declarator(node)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7645 def visit_identifier_declarator(node) @type = qualify_by_pointer(@type, node) end
visit_kandr_function_declarator(node)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7681 def visit_kandr_function_declarator(node) @type = qualify_by_pointer(@type, node) @type = @type_table.function_type(@type, []) @type = node.base.accept(self) end
visit_pointer_abstract_declarator(node)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7693 def visit_pointer_abstract_declarator(node) @type = qualify_by_pointer(@type, node) @type = node.base.accept(self) if node.base @type end
Private Instance Methods
evaluate_size_expression(size_expr)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7760 def evaluate_size_expression(size_expr) if @interpreter obj = @interpreter.execute(size_expr) if obj.variable? && obj.value.scalar? size = obj.value.unique_sample end # NOTE: Size of an array should be greater than 0. size = 1 if size.nil? || size <= 0 else if size_expr.object_specifiers.empty? obj = Interpreter.new(@type_table).execute(size_expr) if obj.variable? && obj.value.scalar? size = obj.value.unique_sample end # NOTE: Size of an array should be greater than 0. size = 1 if size.nil? || size <= 0 else size = nil end end size ? size.to_i : nil end
lookup_parameter_types(dcr, interp = nil)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7750 def lookup_parameter_types(dcr, interp = nil) if param_type_list = dcr.parameter_type_list param_type_list.parameters.map do |param_dcl| @type_table.lookup_parameter_type(param_dcl, @interpreter) end else [] end end
qualify_by_pointer(type, dcr)
click to toggle source
# File lib/adlint/cc1/type.rb, line 7732 def qualify_by_pointer(type, dcr) if dcr.pointer dcr.pointer.each do |tok| case tok.type when "*" type = @type_table.pointer_type(type) when :CONST type = @type_table.qualified_type(type, :const) when :VOLATILE type = @type_table.qualified_type(type, :volatile) when :RESTRICT # TODO: Should support C99 features. end end end type end