diff --git a/lib/cmock.rb b/lib/cmock.rb index f5a3eeb..7b4245c 100644 --- a/lib/cmock.rb +++ b/lib/cmock.rb @@ -10,6 +10,13 @@ require "cmock_plugin_manager" require "cmock_generator_utils" require "cmock_unityhelper_parser" +#gem install test-unit -v 1.2.3 +ruby_version = RUBY_VERSION.split('.') +if (ruby_version[1].to_i == 9) and (ruby_version[2].to_i > 1) + require 'gems' + gem 'test-unit' + require 'test/unit' +end class CMock @@ -18,7 +25,7 @@ class CMock end def setup_mocks(files) - files.each do |src| + [files].flatten.each do |src| generate_mock src end end diff --git a/lib/cmock_file_writer.rb b/lib/cmock_file_writer.rb index 160144f..aac2424 100644 --- a/lib/cmock_file_writer.rb +++ b/lib/cmock_file_writer.rb @@ -1,7 +1,6 @@ class CMockFileWriter - require 'ftools' attr_reader :config def initialize(config) @@ -21,8 +20,9 @@ class CMockFileWriter private ################################### def update_file(dest, src) - File.delete(dest) if (File.exist?(dest)) - File.copy(src, dest) - File.delete(src) + require 'fileutils' + FileUtils.rm(dest) if (File.exist?(dest)) + FileUtils.cp(src, dest) + FileUtils.rm(src) end end diff --git a/lib/cmock_function_prototype_node_classes.rb b/lib/cmock_function_prototype_node_classes.rb index bb07c69..3212d6e 100644 --- a/lib/cmock_function_prototype_node_classes.rb +++ b/lib/cmock_function_prototype_node_classes.rb @@ -223,7 +223,7 @@ module CMockFunctionPrototype # dive down into nested parentheses to pull out deepest node info def get_deepest_name_and_args_node node = name_and_args - while (node.methods.include?('name_and_args')) + while (node.respond_to?(:name_and_args)) node = node.name_and_args end return node diff --git a/lib/cmock_function_prototype_parser.rb b/lib/cmock_function_prototype_parser.rb index ffdec8e..5760a13 100644 --- a/lib/cmock_function_prototype_parser.rb +++ b/lib/cmock_function_prototype_parser.rb @@ -1,2128 +1,2128 @@ -module CMockFunctionPrototype - include Treetop::Runtime - - def root - @root || :function_prototype - end - - def _nt_function_prototype - start_index = index - if node_cache[:function_prototype].has_key?(index) - cached = node_cache[:function_prototype][index] - @index = cached.interval.end if cached - return cached - end - - i0 = index - r1 = _nt_function_prototype_function_pointer_return - if r1 - r0 = r1 - else - r2 = _nt_function_prototype_standard - if r2 - r0 = r2 - else - self.index = i0 - r0 = nil - end - end - - node_cache[:function_prototype][start_index] = r0 - - return r0 - end - - module FunctionPrototypeStandard0 - def return_type - elements[0] - end - - def name - elements[1] - end - - def argument_list - elements[2] - end - end - - def _nt_function_prototype_standard - start_index = index - if node_cache[:function_prototype_standard].has_key?(index) - cached = node_cache[:function_prototype_standard][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - r1 = _nt_return_type - s0 << r1 - if r1 - r2 = _nt_name - s0 << r2 - if r2 - r3 = _nt_argument_list - s0 << r3 - end - end - if s0.last - r0 = instantiate_node(FunctionPrototypeStandardNode,input, i0...index, s0) - r0.extend(FunctionPrototypeStandard0) - else - self.index = i0 - r0 = nil - end - - node_cache[:function_prototype_standard][start_index] = r0 - - return r0 - end - - module FunctionPrototypeFunctionPointerReturn0 - def return_type - elements[0] - end - - def left_paren - elements[1] - end - - def asterisk - elements[2] - end - - def name - elements[3] - end - - def function_arglist - elements[4] - end - - def right_paren - elements[5] - end - - def function_return_arglist - elements[6] - end - end - - def _nt_function_prototype_function_pointer_return - start_index = index - if node_cache[:function_prototype_function_pointer_return].has_key?(index) - cached = node_cache[:function_prototype_function_pointer_return][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - r1 = _nt_return_type - s0 << r1 - if r1 - r2 = _nt_left_paren - s0 << r2 - if r2 - r3 = _nt_asterisk - s0 << r3 - if r3 - r4 = _nt_name - s0 << r4 - if r4 - r5 = _nt_argument_list - s0 << r5 - if r5 - r6 = _nt_right_paren - s0 << r6 - if r6 - r7 = _nt_argument_list - s0 << r7 - end - end - end - end - end - end - if s0.last - r0 = instantiate_node(FunctionPrototypeFunctionPointerReturnNode,input, i0...index, s0) - r0.extend(FunctionPrototypeFunctionPointerReturn0) - else - self.index = i0 - r0 = nil - end - - node_cache[:function_prototype_function_pointer_return][start_index] = r0 - - return r0 - end - - def _nt_return_type - start_index = index - if node_cache[:return_type].has_key?(index) - cached = node_cache[:return_type][index] - @index = cached.interval.end if cached - return cached - end - - i0 = index - r1 = _nt_void - if r1 - r0 = r1 - else - r2 = _nt_type - if r2 - r0 = r2 - else - self.index = i0 - r0 = nil - end - end - - node_cache[:return_type][start_index] = r0 - - return r0 - end - - module ArgumentList0 - def argument - elements[0] - end - - end - - module ArgumentList1 - def left_paren - elements[0] - end - - def arguments - elements[1] - end - - def right_paren - elements[2] - end - end - - def _nt_argument_list - start_index = index - if node_cache[:argument_list].has_key?(index) - cached = node_cache[:argument_list][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - r1 = _nt_left_paren - s0 << r1 - if r1 - s2, i2 = [], index - loop do - i3, s3 = index, [] - r4 = _nt_argument - s3 << r4 - if r4 - r6 = _nt_comma - if r6 - r5 = r6 - else - r5 = instantiate_node(SyntaxNode,input, index...index) - end - s3 << r5 - end - if s3.last - r3 = instantiate_node(SyntaxNode,input, i3...index, s3) - r3.extend(ArgumentList0) - else - self.index = i3 - r3 = nil - end - if r3 - s2 << r3 - else - break - end - end - r2 = instantiate_node(SyntaxNode,input, i2...index, s2) - s0 << r2 - if r2 - r7 = _nt_right_paren - s0 << r7 - end - end - if s0.last - r0 = instantiate_node(ArgumentListNode,input, i0...index, s0) - r0.extend(ArgumentList1) - else - self.index = i0 - r0 = nil - end - - node_cache[:argument_list][start_index] = r0 - - return r0 - end - - def _nt_argument - start_index = index - if node_cache[:argument].has_key?(index) - cached = node_cache[:argument][index] - @index = cached.interval.end if cached - return cached - end - - i0 = index - r1 = _nt_func_ptr_prototype - if r1 - r0 = r1 - else - r2 = _nt_void - if r2 - r0 = r2 - else - r3 = _nt_type_and_name - if r3 - r0 = r3 - else - r4 = _nt_variable_argument - if r4 - r0 = r4 - else - self.index = i0 - r0 = nil - end - end - end - end - - node_cache[:argument][start_index] = r0 - - return r0 - end - - module VariableArgument0 - def space - elements[1] - end - end - - def _nt_variable_argument - start_index = index - if node_cache[:variable_argument].has_key?(index) - cached = node_cache[:variable_argument][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index('...', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 3)) - @index += 3 - else - terminal_parse_failure('...') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - end - if s0.last - r0 = instantiate_node(VarArgNode,input, i0...index, s0) - r0.extend(VariableArgument0) - else - self.index = i0 - r0 = nil - end - - node_cache[:variable_argument][start_index] = r0 - - return r0 - end - - module FuncPtrPrototype0 - def return_type - elements[0] - end - - def name_and_args - elements[1] - end - end - - def _nt_func_ptr_prototype - start_index = index - if node_cache[:func_ptr_prototype].has_key?(index) - cached = node_cache[:func_ptr_prototype][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - r1 = _nt_return_type - s0 << r1 - if r1 - r2 = _nt_parenthesized_func_ptr_name_with_arglist - s0 << r2 - end - if s0.last - r0 = instantiate_node(FunctionPointerNode,input, i0...index, s0) - r0.extend(FuncPtrPrototype0) - else - self.index = i0 - r0 = nil - end - - node_cache[:func_ptr_prototype][start_index] = r0 - - return r0 - end - - module ParenthesizedFuncPtrNameWithArglist0 - def left_paren - elements[0] - end - - def name_and_args - elements[1] - end - - def right_paren - elements[2] - end - end - - module ParenthesizedFuncPtrNameWithArglist1 - def left_paren - elements[0] - end - - def asterisk - elements[1] - end - - def const - elements[2] - end - - def name - elements[3] - end - - def right_paren - elements[4] - end - - def argument_list - elements[5] - end - end - - def _nt_parenthesized_func_ptr_name_with_arglist - start_index = index - if node_cache[:parenthesized_func_ptr_name_with_arglist].has_key?(index) - cached = node_cache[:parenthesized_func_ptr_name_with_arglist][index] - @index = cached.interval.end if cached - return cached - end - - i0 = index - i1, s1 = index, [] - r2 = _nt_left_paren - s1 << r2 - if r2 - r3 = _nt_parenthesized_func_ptr_name_with_arglist - s1 << r3 - if r3 - r4 = _nt_right_paren - s1 << r4 - end - end - if s1.last - r1 = instantiate_node(SyntaxNode,input, i1...index, s1) - r1.extend(ParenthesizedFuncPtrNameWithArglist0) - else - self.index = i1 - r1 = nil - end - if r1 - r0 = r1 - else - i5, s5 = index, [] - r6 = _nt_left_paren - s5 << r6 - if r6 - r7 = _nt_asterisk - s5 << r7 - if r7 - r9 = _nt_const - if r9 - r8 = r9 - else - r8 = instantiate_node(SyntaxNode,input, index...index) - end - s5 << r8 - if r8 - r11 = _nt_name - if r11 - r10 = r11 - else - r10 = instantiate_node(SyntaxNode,input, index...index) - end - s5 << r10 - if r10 - r12 = _nt_right_paren - s5 << r12 - if r12 - r13 = _nt_argument_list - s5 << r13 - end - end - end - end - end - if s5.last - r5 = instantiate_node(SyntaxNode,input, i5...index, s5) - r5.extend(ParenthesizedFuncPtrNameWithArglist1) - else - self.index = i5 - r5 = nil - end - if r5 - r0 = r5 - else - self.index = i0 - r0 = nil - end - end - - node_cache[:parenthesized_func_ptr_name_with_arglist][start_index] = r0 - - return r0 - end - - module TypeAndName0 - def type - elements[0] - end - - def name - elements[1] - end - - end - - def _nt_type_and_name - start_index = index - if node_cache[:type_and_name].has_key?(index) - cached = node_cache[:type_and_name][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - r1 = _nt_type - s0 << r1 - if r1 - r3 = _nt_name_with_brackets - if r3 - r2 = r3 - else - r2 = instantiate_node(SyntaxNode,input, index...index) - end - s0 << r2 - if r2 - i4 = index - i5 = index - r6 = _nt_comma - if r6 - r5 = r6 - else - r7 = _nt_left_paren - if r7 - r5 = r7 - else - r8 = _nt_right_paren - if r8 - r5 = r8 - else - self.index = i5 - r5 = nil - end - end - end - if r5 - self.index = i4 - r4 = instantiate_node(SyntaxNode,input, index...index) - else - r4 = nil - end - s0 << r4 - end - end - if s0.last - r0 = instantiate_node(TypeWithNameNode,input, i0...index, s0) - r0.extend(TypeAndName0) - else - self.index = i0 - r0 = nil - end - - node_cache[:type_and_name][start_index] = r0 - - return r0 - end - - module Type0 - def brackets - elements[2] - end - end - - def _nt_type - start_index = index - if node_cache[:type].has_key?(index) - cached = node_cache[:type][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - r2 = _nt_const - if r2 - r1 = r2 - else - r1 = instantiate_node(SyntaxNode,input, index...index) - end - s0 << r1 - if r1 - i3 = index - r4 = _nt_type_struct - if r4 - r3 = r4 - else - r5 = _nt_type_union - if r5 - r3 = r5 - else - r6 = _nt_type_enum - if r6 - r3 = r6 - else - r7 = _nt_type_void_ptr - if r7 - r3 = r7 - else - r8 = _nt_type_primitive - if r8 - r3 = r8 - else - r9 = _nt_type_custom - if r9 - r3 = r9 - else - self.index = i3 - r3 = nil - end - end - end - end - end - end - s0 << r3 - if r3 - r11 = _nt_array_brackets - if r11 - r10 = r11 - else - r10 = instantiate_node(SyntaxNode,input, index...index) - end - s0 << r10 - end - end - if s0.last - r0 = instantiate_node(TypeNode,input, i0...index, s0) - r0.extend(Type0) - else - self.index = i0 - r0 = nil - end - - node_cache[:type][start_index] = r0 - - return r0 - end - - module TypeStruct0 - def space - elements[1] - end - - def name - elements[2] - end - - def space - elements[3] - end - - end - - def _nt_type_struct - start_index = index - if node_cache[:type_struct].has_key?(index) - cached = node_cache[:type_struct][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index('struct', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 6)) - @index += 6 - else - terminal_parse_failure('struct') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - if r2 - r3 = _nt_name - s0 << r3 - if r3 - r4 = _nt_space - s0 << r4 - if r4 - r6 = _nt_type_const_and_ptr_suffix - if r6 - r5 = r6 - else - r5 = instantiate_node(SyntaxNode,input, index...index) - end - s0 << r5 - end - end - end - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(TypeStruct0) - else - self.index = i0 - r0 = nil - end - - node_cache[:type_struct][start_index] = r0 - - return r0 - end - - module TypeUnion0 - def space - elements[1] - end - - def name - elements[2] - end - - def space - elements[3] - end - - end - - def _nt_type_union - start_index = index - if node_cache[:type_union].has_key?(index) - cached = node_cache[:type_union][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index('union', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 5)) - @index += 5 - else - terminal_parse_failure('union') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - if r2 - r3 = _nt_name - s0 << r3 - if r3 - r4 = _nt_space - s0 << r4 - if r4 - r6 = _nt_type_const_and_ptr_suffix - if r6 - r5 = r6 - else - r5 = instantiate_node(SyntaxNode,input, index...index) - end - s0 << r5 - end - end - end - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(TypeUnion0) - else - self.index = i0 - r0 = nil - end - - node_cache[:type_union][start_index] = r0 - - return r0 - end - - module TypeEnum0 - def space - elements[1] - end - - def name - elements[2] - end - - def space - elements[3] - end - - end - - def _nt_type_enum - start_index = index - if node_cache[:type_enum].has_key?(index) - cached = node_cache[:type_enum][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index('enum', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 4)) - @index += 4 - else - terminal_parse_failure('enum') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - if r2 - r3 = _nt_name - s0 << r3 - if r3 - r4 = _nt_space - s0 << r4 - if r4 - r6 = _nt_type_const_and_ptr_suffix - if r6 - r5 = r6 - else - r5 = instantiate_node(SyntaxNode,input, index...index) - end - s0 << r5 - end - end - end - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(TypeEnum0) - else - self.index = i0 - r0 = nil - end - - node_cache[:type_enum][start_index] = r0 - - return r0 - end - - module TypeVoidPtr0 - def space - elements[1] - end - - def type_const_and_ptr_suffix - elements[2] - end - end - - def _nt_type_void_ptr - start_index = index - if node_cache[:type_void_ptr].has_key?(index) - cached = node_cache[:type_void_ptr][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index('void', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 4)) - @index += 4 - else - terminal_parse_failure('void') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - if r2 - r3 = _nt_type_const_and_ptr_suffix - s0 << r3 - end - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(TypeVoidPtr0) - else - self.index = i0 - r0 = nil - end - - node_cache[:type_void_ptr][start_index] = r0 - - return r0 - end - - module TypePrimitive0 - def space - elements[1] - end - end - - module TypePrimitive1 - def space - elements[1] - end - - end - - module TypePrimitive2 - def space - elements[1] - end - - end - - module TypePrimitive3 - def space - elements[2] - end - - end - - def _nt_type_primitive - start_index = index - if node_cache[:type_primitive].has_key?(index) - cached = node_cache[:type_primitive][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - i2, s2 = index, [] - i3 = index - if input.index('unsigned', index) == index - r4 = instantiate_node(SyntaxNode,input, index...(index + 8)) - @index += 8 - else - terminal_parse_failure('unsigned') - r4 = nil - end - if r4 - r3 = r4 - else - if input.index('signed', index) == index - r5 = instantiate_node(SyntaxNode,input, index...(index + 6)) - @index += 6 - else - terminal_parse_failure('signed') - r5 = nil - end - if r5 - r3 = r5 - else - self.index = i3 - r3 = nil - end - end - s2 << r3 - if r3 - r6 = _nt_space - s2 << r6 - end - if s2.last - r2 = instantiate_node(SyntaxNode,input, i2...index, s2) - r2.extend(TypePrimitive0) - else - self.index = i2 - r2 = nil - end - if r2 - r1 = r2 - else - r1 = instantiate_node(SyntaxNode,input, index...index) - end - s0 << r1 - if r1 - i7 = index - i8, s8 = index, [] - if input.index('long', index) == index - r9 = instantiate_node(SyntaxNode,input, index...(index + 4)) - @index += 4 - else - terminal_parse_failure('long') - r9 = nil - end - s8 << r9 - if r9 - r10 = _nt_space - s8 << r10 - if r10 - if input.index('int', index) == index - r11 = instantiate_node(SyntaxNode,input, index...(index + 3)) - @index += 3 - else - terminal_parse_failure('int') - r11 = nil - end - s8 << r11 - end - end - if s8.last - r8 = instantiate_node(SyntaxNode,input, i8...index, s8) - r8.extend(TypePrimitive1) - else - self.index = i8 - r8 = nil - end - if r8 - r7 = r8 - else - i12, s12 = index, [] - if input.index('long', index) == index - r13 = instantiate_node(SyntaxNode,input, index...(index + 4)) - @index += 4 - else - terminal_parse_failure('long') - r13 = nil - end - s12 << r13 - if r13 - r14 = _nt_space - s12 << r14 - if r14 - if input.index('long', index) == index - r15 = instantiate_node(SyntaxNode,input, index...(index + 4)) - @index += 4 - else - terminal_parse_failure('long') - r15 = nil - end - s12 << r15 - end - end - if s12.last - r12 = instantiate_node(SyntaxNode,input, i12...index, s12) - r12.extend(TypePrimitive2) - else - self.index = i12 - r12 = nil - end - if r12 - r7 = r12 - else - if input.index('long', index) == index - r16 = instantiate_node(SyntaxNode,input, index...(index + 4)) - @index += 4 - else - terminal_parse_failure('long') - r16 = nil - end - if r16 - r7 = r16 - else - if input.index('int', index) == index - r17 = instantiate_node(SyntaxNode,input, index...(index + 3)) - @index += 3 - else - terminal_parse_failure('int') - r17 = nil - end - if r17 - r7 = r17 - else - if input.index('short', index) == index - r18 = instantiate_node(SyntaxNode,input, index...(index + 5)) - @index += 5 - else - terminal_parse_failure('short') - r18 = nil - end - if r18 - r7 = r18 - else - if input.index('char', index) == index - r19 = instantiate_node(SyntaxNode,input, index...(index + 4)) - @index += 4 - else - terminal_parse_failure('char') - r19 = nil - end - if r19 - r7 = r19 - else - if input.index('float', index) == index - r20 = instantiate_node(SyntaxNode,input, index...(index + 5)) - @index += 5 - else - terminal_parse_failure('float') - r20 = nil - end - if r20 - r7 = r20 - else - if input.index('double', index) == index - r21 = instantiate_node(SyntaxNode,input, index...(index + 6)) - @index += 6 - else - terminal_parse_failure('double') - r21 = nil - end - if r21 - r7 = r21 - else - self.index = i7 - r7 = nil - end - end - end - end - end - end - end - end - s0 << r7 - if r7 - r22 = _nt_space - s0 << r22 - if r22 - r24 = _nt_type_const_and_ptr_suffix - if r24 - r23 = r24 - else - r23 = instantiate_node(SyntaxNode,input, index...index) - end - s0 << r23 - end - end - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(TypePrimitive3) - else - self.index = i0 - r0 = nil - end - - node_cache[:type_primitive][start_index] = r0 - - return r0 - end - - module TypeCustom0 - def name - elements[0] - end - - def space - elements[1] - end - - end - - def _nt_type_custom - start_index = index - if node_cache[:type_custom].has_key?(index) - cached = node_cache[:type_custom][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - r1 = _nt_name - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - if r2 - r4 = _nt_type_const_and_ptr_suffix - if r4 - r3 = r4 - else - r3 = instantiate_node(SyntaxNode,input, index...index) - end - s0 << r3 - end - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(TypeCustom0) - else - self.index = i0 - r0 = nil - end - - node_cache[:type_custom][start_index] = r0 - - return r0 - end - - module TypeConstAndPtrSuffix0 - def const - elements[0] - end - - def lookahead_const - elements[2] - end - end - - module TypeConstAndPtrSuffix1 - def const - elements[0] - end - - end - - module TypeConstAndPtrSuffix2 - def lookahead_const - elements[1] - end - end - - def _nt_type_const_and_ptr_suffix - start_index = index - if node_cache[:type_const_and_ptr_suffix].has_key?(index) - cached = node_cache[:type_const_and_ptr_suffix][index] - @index = cached.interval.end if cached - return cached - end - - i0 = index - i1, s1 = index, [] - r2 = _nt_const - s1 << r2 - if r2 - s3, i3 = [], index - loop do - r4 = _nt_asterisk - if r4 - s3 << r4 - else - break - end - end - if s3.empty? - self.index = i3 - r3 = nil - else - r3 = instantiate_node(SyntaxNode,input, i3...index, s3) - end - s1 << r3 - if r3 - r5 = _nt_lookahead_const - s1 << r5 - end - end - if s1.last - r1 = instantiate_node(SyntaxNode,input, i1...index, s1) - r1.extend(TypeConstAndPtrSuffix0) - else - self.index = i1 - r1 = nil - end - if r1 - r0 = r1 - else - i6, s6 = index, [] - r7 = _nt_const - s6 << r7 - if r7 - s8, i8 = [], index - loop do - r9 = _nt_asterisk - if r9 - s8 << r9 - else - break - end - end - if s8.empty? - self.index = i8 - r8 = nil - else - r8 = instantiate_node(SyntaxNode,input, i8...index, s8) - end - s6 << r8 - end - if s6.last - r6 = instantiate_node(SyntaxNode,input, i6...index, s6) - r6.extend(TypeConstAndPtrSuffix1) - else - self.index = i6 - r6 = nil - end - if r6 - r0 = r6 - else - i10, s10 = index, [] - s11, i11 = [], index - loop do - r12 = _nt_asterisk - if r12 - s11 << r12 - else - break - end - end - if s11.empty? - self.index = i11 - r11 = nil - else - r11 = instantiate_node(SyntaxNode,input, i11...index, s11) - end - s10 << r11 - if r11 - r13 = _nt_lookahead_const - s10 << r13 - end - if s10.last - r10 = instantiate_node(SyntaxNode,input, i10...index, s10) - r10.extend(TypeConstAndPtrSuffix2) - else - self.index = i10 - r10 = nil - end - if r10 - r0 = r10 - else - s14, i14 = [], index - loop do - r15 = _nt_asterisk - if r15 - s14 << r15 - else - break - end - end - if s14.empty? - self.index = i14 - r14 = nil - else - r14 = instantiate_node(SyntaxNode,input, i14...index, s14) - end - if r14 - r0 = r14 - else - r16 = _nt_lookahead_const - if r16 - r0 = r16 - else - self.index = i0 - r0 = nil - end - end - end - end - end - - node_cache[:type_const_and_ptr_suffix][start_index] = r0 - - return r0 - end - - module LookaheadConst0 - end - - module LookaheadConst1 - def space - elements[0] - end - - end - - module LookaheadConst2 - def space - elements[0] - end - - end - - module LookaheadConst3 - def space - elements[0] - end - - end - - module LookaheadConst4 - end - - def _nt_lookahead_const - start_index = index - if node_cache[:lookahead_const].has_key?(index) - cached = node_cache[:lookahead_const][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index('const', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 5)) - @index += 5 - else - terminal_parse_failure('const') - r1 = nil - end - s0 << r1 - if r1 - i2 = index - i3, s3 = index, [] - s4, i4 = [], index - loop do - if input.index(' ', index) == index - r5 = instantiate_node(SyntaxNode,input, index...(index + 1)) - @index += 1 - else - terminal_parse_failure(' ') - r5 = nil - end - if r5 - s4 << r5 - else - break - end - end - if s4.empty? - self.index = i4 - r4 = nil - else - r4 = instantiate_node(SyntaxNode,input, i4...index, s4) - end - s3 << r4 - if r4 - i6 = index - r7 = _nt_name - if r7 - self.index = i6 - r6 = instantiate_node(SyntaxNode,input, index...index) - else - r6 = nil - end - s3 << r6 - end - if s3.last - r3 = instantiate_node(SyntaxNode,input, i3...index, s3) - r3.extend(LookaheadConst0) - else - self.index = i3 - r3 = nil - end - if r3 - r2 = r3 - else - i8, s8 = index, [] - r9 = _nt_space - s8 << r9 - if r9 - i10 = index - r11 = _nt_comma - if r11 - self.index = i10 - r10 = instantiate_node(SyntaxNode,input, index...index) - else - r10 = nil - end - s8 << r10 - end - if s8.last - r8 = instantiate_node(SyntaxNode,input, i8...index, s8) - r8.extend(LookaheadConst1) - else - self.index = i8 - r8 = nil - end - if r8 - r2 = r8 - else - i12, s12 = index, [] - r13 = _nt_space - s12 << r13 - if r13 - i14 = index - r15 = _nt_right_paren - if r15 - self.index = i14 - r14 = instantiate_node(SyntaxNode,input, index...index) - else - r14 = nil - end - s12 << r14 - end - if s12.last - r12 = instantiate_node(SyntaxNode,input, i12...index, s12) - r12.extend(LookaheadConst2) - else - self.index = i12 - r12 = nil - end - if r12 - r2 = r12 - else - i16, s16 = index, [] - r17 = _nt_space - s16 << r17 - if r17 - i18 = index - r19 = _nt_left_paren - if r19 - self.index = i18 - r18 = instantiate_node(SyntaxNode,input, index...index) - else - r18 = nil - end - s16 << r18 - end - if s16.last - r16 = instantiate_node(SyntaxNode,input, i16...index, s16) - r16.extend(LookaheadConst3) - else - self.index = i16 - r16 = nil - end - if r16 - r2 = r16 - else - self.index = i2 - r2 = nil - end - end - end - end - s0 << r2 - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(LookaheadConst4) - else - self.index = i0 - r0 = nil - end - - node_cache[:lookahead_const][start_index] = r0 - - return r0 - end - - module Name0 - def space - elements[1] - end - end - - def _nt_name - start_index = index - if node_cache[:name].has_key?(index) - cached = node_cache[:name][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - s1, i1 = [], index - loop do - if input.index(Regexp.new('[a-zA-Z0-9_]'), index) == index - r2 = instantiate_node(SyntaxNode,input, index...(index + 1)) - @index += 1 - else - r2 = nil - end - if r2 - s1 << r2 - else - break - end - end - if s1.empty? - self.index = i1 - r1 = nil - else - r1 = instantiate_node(SyntaxNode,input, i1...index, s1) - end - s0 << r1 - if r1 - r3 = _nt_space - s0 << r3 - end - if s0.last - r0 = instantiate_node(NameNode,input, i0...index, s0) - r0.extend(Name0) - else - self.index = i0 - r0 = nil - end - - node_cache[:name][start_index] = r0 - - return r0 - end - - module NameWithBrackets0 - def name - elements[0] - end - - def brackets - elements[1] - end - end - - def _nt_name_with_brackets - start_index = index - if node_cache[:name_with_brackets].has_key?(index) - cached = node_cache[:name_with_brackets][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - r1 = _nt_name - s0 << r1 - if r1 - r3 = _nt_array_brackets - if r3 - r2 = r3 - else - r2 = instantiate_node(SyntaxNode,input, index...index) - end - s0 << r2 - end - if s0.last - r0 = instantiate_node(NameWithBracketsNode,input, i0...index, s0) - r0.extend(NameWithBrackets0) - else - self.index = i0 - r0 = nil - end - - node_cache[:name_with_brackets][start_index] = r0 - - return r0 - end - - module Void0 - def space - elements[1] - end - - end - - def _nt_void - start_index = index - if node_cache[:void].has_key?(index) - cached = node_cache[:void][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index('void', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 4)) - @index += 4 - else - terminal_parse_failure('void') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - if r2 - i3 = index - r4 = _nt_asterisk - if r4 - r3 = nil - else - self.index = i3 - r3 = instantiate_node(SyntaxNode,input, index...index) - end - s0 << r3 - end - end - if s0.last - r0 = instantiate_node(VoidNode,input, i0...index, s0) - r0.extend(Void0) - else - self.index = i0 - r0 = nil - end - - node_cache[:void][start_index] = r0 - - return r0 - end - - module ArrayBrackets0 - def left_bracket - elements[0] - end - - def number - elements[1] - end - - def right_bracket - elements[2] - end - end - - module ArrayBrackets1 - def left_bracket - elements[0] - end - - def right_bracket - elements[1] - end - - end - - def _nt_array_brackets - start_index = index - if node_cache[:array_brackets].has_key?(index) - cached = node_cache[:array_brackets][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - r1 = _nt_left_bracket - s0 << r1 - if r1 - r2 = _nt_right_bracket - s0 << r2 - if r2 - s3, i3 = [], index - loop do - i4, s4 = index, [] - r5 = _nt_left_bracket - s4 << r5 - if r5 - r6 = _nt_number - s4 << r6 - if r6 - r7 = _nt_right_bracket - s4 << r7 - end - end - if s4.last - r4 = instantiate_node(SyntaxNode,input, i4...index, s4) - r4.extend(ArrayBrackets0) - else - self.index = i4 - r4 = nil - end - if r4 - s3 << r4 - else - break - end - end - r3 = instantiate_node(SyntaxNode,input, i3...index, s3) - s0 << r3 - end - end - if s0.last - r0 = instantiate_node(ArrayBracketsNode,input, i0...index, s0) - r0.extend(ArrayBrackets1) - else - self.index = i0 - r0 = nil - end - - node_cache[:array_brackets][start_index] = r0 - - return r0 - end - - module Const0 - def space - elements[1] - end - end - - def _nt_const - start_index = index - if node_cache[:const].has_key?(index) - cached = node_cache[:const][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index('const', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 5)) - @index += 5 - else - terminal_parse_failure('const') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(Const0) - else - self.index = i0 - r0 = nil - end - - node_cache[:const][start_index] = r0 - - return r0 - end - - module Asterisk0 - def space - elements[1] - end - end - - def _nt_asterisk - start_index = index - if node_cache[:asterisk].has_key?(index) - cached = node_cache[:asterisk][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index('*', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) - @index += 1 - else - terminal_parse_failure('*') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(Asterisk0) - else - self.index = i0 - r0 = nil - end - - node_cache[:asterisk][start_index] = r0 - - return r0 - end - - module LeftParen0 - def space - elements[1] - end - end - - def _nt_left_paren - start_index = index - if node_cache[:left_paren].has_key?(index) - cached = node_cache[:left_paren][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index('(', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) - @index += 1 - else - terminal_parse_failure('(') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(LeftParen0) - else - self.index = i0 - r0 = nil - end - - node_cache[:left_paren][start_index] = r0 - - return r0 - end - - module RightParen0 - def space - elements[1] - end - end - - def _nt_right_paren - start_index = index - if node_cache[:right_paren].has_key?(index) - cached = node_cache[:right_paren][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index(')', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) - @index += 1 - else - terminal_parse_failure(')') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(RightParen0) - else - self.index = i0 - r0 = nil - end - - node_cache[:right_paren][start_index] = r0 - - return r0 - end - - module LeftBracket0 - def space - elements[1] - end - end - - def _nt_left_bracket - start_index = index - if node_cache[:left_bracket].has_key?(index) - cached = node_cache[:left_bracket][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index('[', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) - @index += 1 - else - terminal_parse_failure('[') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(LeftBracket0) - else - self.index = i0 - r0 = nil - end - - node_cache[:left_bracket][start_index] = r0 - - return r0 - end - - module RightBracket0 - def space - elements[1] - end - end - - def _nt_right_bracket - start_index = index - if node_cache[:right_bracket].has_key?(index) - cached = node_cache[:right_bracket][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index(']', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) - @index += 1 - else - terminal_parse_failure(']') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(RightBracket0) - else - self.index = i0 - r0 = nil - end - - node_cache[:right_bracket][start_index] = r0 - - return r0 - end - - module Comma0 - def space - elements[1] - end - end - - def _nt_comma - start_index = index - if node_cache[:comma].has_key?(index) - cached = node_cache[:comma][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index(',', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) - @index += 1 - else - terminal_parse_failure(',') - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(Comma0) - else - self.index = i0 - r0 = nil - end - - node_cache[:comma][start_index] = r0 - - return r0 - end - - module Number0 - def space - elements[1] - end - end - - def _nt_number - start_index = index - if node_cache[:number].has_key?(index) - cached = node_cache[:number][index] - @index = cached.interval.end if cached - return cached - end - - i0, s0 = index, [] - if input.index(Regexp.new('[0-9]'), index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) - @index += 1 - else - r1 = nil - end - s0 << r1 - if r1 - r2 = _nt_space - s0 << r2 - end - if s0.last - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(Number0) - else - self.index = i0 - r0 = nil - end - - node_cache[:number][start_index] = r0 - - return r0 - end - - def _nt_space - start_index = index - if node_cache[:space].has_key?(index) - cached = node_cache[:space][index] - @index = cached.interval.end if cached - return cached - end - - s0, i0 = [], index - loop do - if input.index(' ', index) == index - r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) - @index += 1 - else - terminal_parse_failure(' ') - r1 = nil - end - if r1 - s0 << r1 - else - break - end - end - r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - - node_cache[:space][start_index] = r0 - - return r0 - end - -end - -class CMockFunctionPrototypeParser < Treetop::Runtime::CompiledParser - include CMockFunctionPrototype -end - +module CMockFunctionPrototype + include Treetop::Runtime + + def root + @root || :function_prototype + end + + def _nt_function_prototype + start_index = index + if node_cache[:function_prototype].has_key?(index) + cached = node_cache[:function_prototype][index] + @index = cached.interval.end if cached + return cached + end + + i0 = index + r1 = _nt_function_prototype_function_pointer_return + if r1 + r0 = r1 + else + r2 = _nt_function_prototype_standard + if r2 + r0 = r2 + else + self.index = i0 + r0 = nil + end + end + + node_cache[:function_prototype][start_index] = r0 + + return r0 + end + + module FunctionPrototypeStandard0 + def return_type + elements[0] + end + + def name + elements[1] + end + + def argument_list + elements[2] + end + end + + def _nt_function_prototype_standard + start_index = index + if node_cache[:function_prototype_standard].has_key?(index) + cached = node_cache[:function_prototype_standard][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + r1 = _nt_return_type + s0 << r1 + if r1 + r2 = _nt_name + s0 << r2 + if r2 + r3 = _nt_argument_list + s0 << r3 + end + end + if s0.last + r0 = instantiate_node(FunctionPrototypeStandardNode,input, i0...index, s0) + r0.extend(FunctionPrototypeStandard0) + else + self.index = i0 + r0 = nil + end + + node_cache[:function_prototype_standard][start_index] = r0 + + return r0 + end + + module FunctionPrototypeFunctionPointerReturn0 + def return_type + elements[0] + end + + def left_paren + elements[1] + end + + def asterisk + elements[2] + end + + def name + elements[3] + end + + def function_arglist + elements[4] + end + + def right_paren + elements[5] + end + + def function_return_arglist + elements[6] + end + end + + def _nt_function_prototype_function_pointer_return + start_index = index + if node_cache[:function_prototype_function_pointer_return].has_key?(index) + cached = node_cache[:function_prototype_function_pointer_return][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + r1 = _nt_return_type + s0 << r1 + if r1 + r2 = _nt_left_paren + s0 << r2 + if r2 + r3 = _nt_asterisk + s0 << r3 + if r3 + r4 = _nt_name + s0 << r4 + if r4 + r5 = _nt_argument_list + s0 << r5 + if r5 + r6 = _nt_right_paren + s0 << r6 + if r6 + r7 = _nt_argument_list + s0 << r7 + end + end + end + end + end + end + if s0.last + r0 = instantiate_node(FunctionPrototypeFunctionPointerReturnNode,input, i0...index, s0) + r0.extend(FunctionPrototypeFunctionPointerReturn0) + else + self.index = i0 + r0 = nil + end + + node_cache[:function_prototype_function_pointer_return][start_index] = r0 + + return r0 + end + + def _nt_return_type + start_index = index + if node_cache[:return_type].has_key?(index) + cached = node_cache[:return_type][index] + @index = cached.interval.end if cached + return cached + end + + i0 = index + r1 = _nt_void + if r1 + r0 = r1 + else + r2 = _nt_type + if r2 + r0 = r2 + else + self.index = i0 + r0 = nil + end + end + + node_cache[:return_type][start_index] = r0 + + return r0 + end + + module ArgumentList0 + def argument + elements[0] + end + + end + + module ArgumentList1 + def left_paren + elements[0] + end + + def arguments + elements[1] + end + + def right_paren + elements[2] + end + end + + def _nt_argument_list + start_index = index + if node_cache[:argument_list].has_key?(index) + cached = node_cache[:argument_list][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + r1 = _nt_left_paren + s0 << r1 + if r1 + s2, i2 = [], index + loop do + i3, s3 = index, [] + r4 = _nt_argument + s3 << r4 + if r4 + r6 = _nt_comma + if r6 + r5 = r6 + else + r5 = instantiate_node(SyntaxNode,input, index...index) + end + s3 << r5 + end + if s3.last + r3 = instantiate_node(SyntaxNode,input, i3...index, s3) + r3.extend(ArgumentList0) + else + self.index = i3 + r3 = nil + end + if r3 + s2 << r3 + else + break + end + end + r2 = instantiate_node(SyntaxNode,input, i2...index, s2) + s0 << r2 + if r2 + r7 = _nt_right_paren + s0 << r7 + end + end + if s0.last + r0 = instantiate_node(ArgumentListNode,input, i0...index, s0) + r0.extend(ArgumentList1) + else + self.index = i0 + r0 = nil + end + + node_cache[:argument_list][start_index] = r0 + + return r0 + end + + def _nt_argument + start_index = index + if node_cache[:argument].has_key?(index) + cached = node_cache[:argument][index] + @index = cached.interval.end if cached + return cached + end + + i0 = index + r1 = _nt_func_ptr_prototype + if r1 + r0 = r1 + else + r2 = _nt_void + if r2 + r0 = r2 + else + r3 = _nt_type_and_name + if r3 + r0 = r3 + else + r4 = _nt_variable_argument + if r4 + r0 = r4 + else + self.index = i0 + r0 = nil + end + end + end + end + + node_cache[:argument][start_index] = r0 + + return r0 + end + + module VariableArgument0 + def space + elements[1] + end + end + + def _nt_variable_argument + start_index = index + if node_cache[:variable_argument].has_key?(index) + cached = node_cache[:variable_argument][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index('...', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 3)) + @index += 3 + else + terminal_parse_failure('...') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + end + if s0.last + r0 = instantiate_node(VarArgNode,input, i0...index, s0) + r0.extend(VariableArgument0) + else + self.index = i0 + r0 = nil + end + + node_cache[:variable_argument][start_index] = r0 + + return r0 + end + + module FuncPtrPrototype0 + def return_type + elements[0] + end + + def name_and_args + elements[1] + end + end + + def _nt_func_ptr_prototype + start_index = index + if node_cache[:func_ptr_prototype].has_key?(index) + cached = node_cache[:func_ptr_prototype][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + r1 = _nt_return_type + s0 << r1 + if r1 + r2 = _nt_parenthesized_func_ptr_name_with_arglist + s0 << r2 + end + if s0.last + r0 = instantiate_node(FunctionPointerNode,input, i0...index, s0) + r0.extend(FuncPtrPrototype0) + else + self.index = i0 + r0 = nil + end + + node_cache[:func_ptr_prototype][start_index] = r0 + + return r0 + end + + module ParenthesizedFuncPtrNameWithArglist0 + def left_paren + elements[0] + end + + def name_and_args + elements[1] + end + + def right_paren + elements[2] + end + end + + module ParenthesizedFuncPtrNameWithArglist1 + def left_paren + elements[0] + end + + def asterisk + elements[1] + end + + def const + elements[2] + end + + def name + elements[3] + end + + def right_paren + elements[4] + end + + def argument_list + elements[5] + end + end + + def _nt_parenthesized_func_ptr_name_with_arglist + start_index = index + if node_cache[:parenthesized_func_ptr_name_with_arglist].has_key?(index) + cached = node_cache[:parenthesized_func_ptr_name_with_arglist][index] + @index = cached.interval.end if cached + return cached + end + + i0 = index + i1, s1 = index, [] + r2 = _nt_left_paren + s1 << r2 + if r2 + r3 = _nt_parenthesized_func_ptr_name_with_arglist + s1 << r3 + if r3 + r4 = _nt_right_paren + s1 << r4 + end + end + if s1.last + r1 = instantiate_node(SyntaxNode,input, i1...index, s1) + r1.extend(ParenthesizedFuncPtrNameWithArglist0) + else + self.index = i1 + r1 = nil + end + if r1 + r0 = r1 + else + i5, s5 = index, [] + r6 = _nt_left_paren + s5 << r6 + if r6 + r7 = _nt_asterisk + s5 << r7 + if r7 + r9 = _nt_const + if r9 + r8 = r9 + else + r8 = instantiate_node(SyntaxNode,input, index...index) + end + s5 << r8 + if r8 + r11 = _nt_name + if r11 + r10 = r11 + else + r10 = instantiate_node(SyntaxNode,input, index...index) + end + s5 << r10 + if r10 + r12 = _nt_right_paren + s5 << r12 + if r12 + r13 = _nt_argument_list + s5 << r13 + end + end + end + end + end + if s5.last + r5 = instantiate_node(SyntaxNode,input, i5...index, s5) + r5.extend(ParenthesizedFuncPtrNameWithArglist1) + else + self.index = i5 + r5 = nil + end + if r5 + r0 = r5 + else + self.index = i0 + r0 = nil + end + end + + node_cache[:parenthesized_func_ptr_name_with_arglist][start_index] = r0 + + return r0 + end + + module TypeAndName0 + def type + elements[0] + end + + def name + elements[1] + end + + end + + def _nt_type_and_name + start_index = index + if node_cache[:type_and_name].has_key?(index) + cached = node_cache[:type_and_name][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + r1 = _nt_type + s0 << r1 + if r1 + r3 = _nt_name_with_brackets + if r3 + r2 = r3 + else + r2 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r2 + if r2 + i4 = index + i5 = index + r6 = _nt_comma + if r6 + r5 = r6 + else + r7 = _nt_left_paren + if r7 + r5 = r7 + else + r8 = _nt_right_paren + if r8 + r5 = r8 + else + self.index = i5 + r5 = nil + end + end + end + if r5 + self.index = i4 + r4 = instantiate_node(SyntaxNode,input, index...index) + else + r4 = nil + end + s0 << r4 + end + end + if s0.last + r0 = instantiate_node(TypeWithNameNode,input, i0...index, s0) + r0.extend(TypeAndName0) + else + self.index = i0 + r0 = nil + end + + node_cache[:type_and_name][start_index] = r0 + + return r0 + end + + module Type0 + def brackets + elements[2] + end + end + + def _nt_type + start_index = index + if node_cache[:type].has_key?(index) + cached = node_cache[:type][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + r2 = _nt_const + if r2 + r1 = r2 + else + r1 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r1 + if r1 + i3 = index + r4 = _nt_type_struct + if r4 + r3 = r4 + else + r5 = _nt_type_union + if r5 + r3 = r5 + else + r6 = _nt_type_enum + if r6 + r3 = r6 + else + r7 = _nt_type_void_ptr + if r7 + r3 = r7 + else + r8 = _nt_type_primitive + if r8 + r3 = r8 + else + r9 = _nt_type_custom + if r9 + r3 = r9 + else + self.index = i3 + r3 = nil + end + end + end + end + end + end + s0 << r3 + if r3 + r11 = _nt_array_brackets + if r11 + r10 = r11 + else + r10 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r10 + end + end + if s0.last + r0 = instantiate_node(TypeNode,input, i0...index, s0) + r0.extend(Type0) + else + self.index = i0 + r0 = nil + end + + node_cache[:type][start_index] = r0 + + return r0 + end + + module TypeStruct0 + def space + elements[1] + end + + def name + elements[2] + end + + def space + elements[3] + end + + end + + def _nt_type_struct + start_index = index + if node_cache[:type_struct].has_key?(index) + cached = node_cache[:type_struct][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index('struct', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 6)) + @index += 6 + else + terminal_parse_failure('struct') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + if r2 + r3 = _nt_name + s0 << r3 + if r3 + r4 = _nt_space + s0 << r4 + if r4 + r6 = _nt_type_const_and_ptr_suffix + if r6 + r5 = r6 + else + r5 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r5 + end + end + end + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(TypeStruct0) + else + self.index = i0 + r0 = nil + end + + node_cache[:type_struct][start_index] = r0 + + return r0 + end + + module TypeUnion0 + def space + elements[1] + end + + def name + elements[2] + end + + def space + elements[3] + end + + end + + def _nt_type_union + start_index = index + if node_cache[:type_union].has_key?(index) + cached = node_cache[:type_union][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index('union', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 5)) + @index += 5 + else + terminal_parse_failure('union') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + if r2 + r3 = _nt_name + s0 << r3 + if r3 + r4 = _nt_space + s0 << r4 + if r4 + r6 = _nt_type_const_and_ptr_suffix + if r6 + r5 = r6 + else + r5 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r5 + end + end + end + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(TypeUnion0) + else + self.index = i0 + r0 = nil + end + + node_cache[:type_union][start_index] = r0 + + return r0 + end + + module TypeEnum0 + def space + elements[1] + end + + def name + elements[2] + end + + def space + elements[3] + end + + end + + def _nt_type_enum + start_index = index + if node_cache[:type_enum].has_key?(index) + cached = node_cache[:type_enum][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index('enum', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 4)) + @index += 4 + else + terminal_parse_failure('enum') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + if r2 + r3 = _nt_name + s0 << r3 + if r3 + r4 = _nt_space + s0 << r4 + if r4 + r6 = _nt_type_const_and_ptr_suffix + if r6 + r5 = r6 + else + r5 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r5 + end + end + end + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(TypeEnum0) + else + self.index = i0 + r0 = nil + end + + node_cache[:type_enum][start_index] = r0 + + return r0 + end + + module TypeVoidPtr0 + def space + elements[1] + end + + def type_const_and_ptr_suffix + elements[2] + end + end + + def _nt_type_void_ptr + start_index = index + if node_cache[:type_void_ptr].has_key?(index) + cached = node_cache[:type_void_ptr][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index('void', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 4)) + @index += 4 + else + terminal_parse_failure('void') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + if r2 + r3 = _nt_type_const_and_ptr_suffix + s0 << r3 + end + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(TypeVoidPtr0) + else + self.index = i0 + r0 = nil + end + + node_cache[:type_void_ptr][start_index] = r0 + + return r0 + end + + module TypePrimitive0 + def space + elements[1] + end + end + + module TypePrimitive1 + def space + elements[1] + end + + end + + module TypePrimitive2 + def space + elements[1] + end + + end + + module TypePrimitive3 + def space + elements[2] + end + + end + + def _nt_type_primitive + start_index = index + if node_cache[:type_primitive].has_key?(index) + cached = node_cache[:type_primitive][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + i2, s2 = index, [] + i3 = index + if input.index('unsigned', index) == index + r4 = instantiate_node(SyntaxNode,input, index...(index + 8)) + @index += 8 + else + terminal_parse_failure('unsigned') + r4 = nil + end + if r4 + r3 = r4 + else + if input.index('signed', index) == index + r5 = instantiate_node(SyntaxNode,input, index...(index + 6)) + @index += 6 + else + terminal_parse_failure('signed') + r5 = nil + end + if r5 + r3 = r5 + else + self.index = i3 + r3 = nil + end + end + s2 << r3 + if r3 + r6 = _nt_space + s2 << r6 + end + if s2.last + r2 = instantiate_node(SyntaxNode,input, i2...index, s2) + r2.extend(TypePrimitive0) + else + self.index = i2 + r2 = nil + end + if r2 + r1 = r2 + else + r1 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r1 + if r1 + i7 = index + i8, s8 = index, [] + if input.index('long', index) == index + r9 = instantiate_node(SyntaxNode,input, index...(index + 4)) + @index += 4 + else + terminal_parse_failure('long') + r9 = nil + end + s8 << r9 + if r9 + r10 = _nt_space + s8 << r10 + if r10 + if input.index('int', index) == index + r11 = instantiate_node(SyntaxNode,input, index...(index + 3)) + @index += 3 + else + terminal_parse_failure('int') + r11 = nil + end + s8 << r11 + end + end + if s8.last + r8 = instantiate_node(SyntaxNode,input, i8...index, s8) + r8.extend(TypePrimitive1) + else + self.index = i8 + r8 = nil + end + if r8 + r7 = r8 + else + i12, s12 = index, [] + if input.index('long', index) == index + r13 = instantiate_node(SyntaxNode,input, index...(index + 4)) + @index += 4 + else + terminal_parse_failure('long') + r13 = nil + end + s12 << r13 + if r13 + r14 = _nt_space + s12 << r14 + if r14 + if input.index('long', index) == index + r15 = instantiate_node(SyntaxNode,input, index...(index + 4)) + @index += 4 + else + terminal_parse_failure('long') + r15 = nil + end + s12 << r15 + end + end + if s12.last + r12 = instantiate_node(SyntaxNode,input, i12...index, s12) + r12.extend(TypePrimitive2) + else + self.index = i12 + r12 = nil + end + if r12 + r7 = r12 + else + if input.index('long', index) == index + r16 = instantiate_node(SyntaxNode,input, index...(index + 4)) + @index += 4 + else + terminal_parse_failure('long') + r16 = nil + end + if r16 + r7 = r16 + else + if input.index('int', index) == index + r17 = instantiate_node(SyntaxNode,input, index...(index + 3)) + @index += 3 + else + terminal_parse_failure('int') + r17 = nil + end + if r17 + r7 = r17 + else + if input.index('short', index) == index + r18 = instantiate_node(SyntaxNode,input, index...(index + 5)) + @index += 5 + else + terminal_parse_failure('short') + r18 = nil + end + if r18 + r7 = r18 + else + if input.index('char', index) == index + r19 = instantiate_node(SyntaxNode,input, index...(index + 4)) + @index += 4 + else + terminal_parse_failure('char') + r19 = nil + end + if r19 + r7 = r19 + else + if input.index('float', index) == index + r20 = instantiate_node(SyntaxNode,input, index...(index + 5)) + @index += 5 + else + terminal_parse_failure('float') + r20 = nil + end + if r20 + r7 = r20 + else + if input.index('double', index) == index + r21 = instantiate_node(SyntaxNode,input, index...(index + 6)) + @index += 6 + else + terminal_parse_failure('double') + r21 = nil + end + if r21 + r7 = r21 + else + self.index = i7 + r7 = nil + end + end + end + end + end + end + end + end + s0 << r7 + if r7 + r22 = _nt_space + s0 << r22 + if r22 + r24 = _nt_type_const_and_ptr_suffix + if r24 + r23 = r24 + else + r23 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r23 + end + end + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(TypePrimitive3) + else + self.index = i0 + r0 = nil + end + + node_cache[:type_primitive][start_index] = r0 + + return r0 + end + + module TypeCustom0 + def name + elements[0] + end + + def space + elements[1] + end + + end + + def _nt_type_custom + start_index = index + if node_cache[:type_custom].has_key?(index) + cached = node_cache[:type_custom][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + r1 = _nt_name + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + if r2 + r4 = _nt_type_const_and_ptr_suffix + if r4 + r3 = r4 + else + r3 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r3 + end + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(TypeCustom0) + else + self.index = i0 + r0 = nil + end + + node_cache[:type_custom][start_index] = r0 + + return r0 + end + + module TypeConstAndPtrSuffix0 + def const + elements[0] + end + + def lookahead_const + elements[2] + end + end + + module TypeConstAndPtrSuffix1 + def const + elements[0] + end + + end + + module TypeConstAndPtrSuffix2 + def lookahead_const + elements[1] + end + end + + def _nt_type_const_and_ptr_suffix + start_index = index + if node_cache[:type_const_and_ptr_suffix].has_key?(index) + cached = node_cache[:type_const_and_ptr_suffix][index] + @index = cached.interval.end if cached + return cached + end + + i0 = index + i1, s1 = index, [] + r2 = _nt_const + s1 << r2 + if r2 + s3, i3 = [], index + loop do + r4 = _nt_asterisk + if r4 + s3 << r4 + else + break + end + end + if s3.empty? + self.index = i3 + r3 = nil + else + r3 = instantiate_node(SyntaxNode,input, i3...index, s3) + end + s1 << r3 + if r3 + r5 = _nt_lookahead_const + s1 << r5 + end + end + if s1.last + r1 = instantiate_node(SyntaxNode,input, i1...index, s1) + r1.extend(TypeConstAndPtrSuffix0) + else + self.index = i1 + r1 = nil + end + if r1 + r0 = r1 + else + i6, s6 = index, [] + r7 = _nt_const + s6 << r7 + if r7 + s8, i8 = [], index + loop do + r9 = _nt_asterisk + if r9 + s8 << r9 + else + break + end + end + if s8.empty? + self.index = i8 + r8 = nil + else + r8 = instantiate_node(SyntaxNode,input, i8...index, s8) + end + s6 << r8 + end + if s6.last + r6 = instantiate_node(SyntaxNode,input, i6...index, s6) + r6.extend(TypeConstAndPtrSuffix1) + else + self.index = i6 + r6 = nil + end + if r6 + r0 = r6 + else + i10, s10 = index, [] + s11, i11 = [], index + loop do + r12 = _nt_asterisk + if r12 + s11 << r12 + else + break + end + end + if s11.empty? + self.index = i11 + r11 = nil + else + r11 = instantiate_node(SyntaxNode,input, i11...index, s11) + end + s10 << r11 + if r11 + r13 = _nt_lookahead_const + s10 << r13 + end + if s10.last + r10 = instantiate_node(SyntaxNode,input, i10...index, s10) + r10.extend(TypeConstAndPtrSuffix2) + else + self.index = i10 + r10 = nil + end + if r10 + r0 = r10 + else + s14, i14 = [], index + loop do + r15 = _nt_asterisk + if r15 + s14 << r15 + else + break + end + end + if s14.empty? + self.index = i14 + r14 = nil + else + r14 = instantiate_node(SyntaxNode,input, i14...index, s14) + end + if r14 + r0 = r14 + else + r16 = _nt_lookahead_const + if r16 + r0 = r16 + else + self.index = i0 + r0 = nil + end + end + end + end + end + + node_cache[:type_const_and_ptr_suffix][start_index] = r0 + + return r0 + end + + module LookaheadConst0 + end + + module LookaheadConst1 + def space + elements[0] + end + + end + + module LookaheadConst2 + def space + elements[0] + end + + end + + module LookaheadConst3 + def space + elements[0] + end + + end + + module LookaheadConst4 + end + + def _nt_lookahead_const + start_index = index + if node_cache[:lookahead_const].has_key?(index) + cached = node_cache[:lookahead_const][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index('const', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 5)) + @index += 5 + else + terminal_parse_failure('const') + r1 = nil + end + s0 << r1 + if r1 + i2 = index + i3, s3 = index, [] + s4, i4 = [], index + loop do + if input.index(' ', index) == index + r5 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + terminal_parse_failure(' ') + r5 = nil + end + if r5 + s4 << r5 + else + break + end + end + if s4.empty? + self.index = i4 + r4 = nil + else + r4 = instantiate_node(SyntaxNode,input, i4...index, s4) + end + s3 << r4 + if r4 + i6 = index + r7 = _nt_name + if r7 + self.index = i6 + r6 = instantiate_node(SyntaxNode,input, index...index) + else + r6 = nil + end + s3 << r6 + end + if s3.last + r3 = instantiate_node(SyntaxNode,input, i3...index, s3) + r3.extend(LookaheadConst0) + else + self.index = i3 + r3 = nil + end + if r3 + r2 = r3 + else + i8, s8 = index, [] + r9 = _nt_space + s8 << r9 + if r9 + i10 = index + r11 = _nt_comma + if r11 + self.index = i10 + r10 = instantiate_node(SyntaxNode,input, index...index) + else + r10 = nil + end + s8 << r10 + end + if s8.last + r8 = instantiate_node(SyntaxNode,input, i8...index, s8) + r8.extend(LookaheadConst1) + else + self.index = i8 + r8 = nil + end + if r8 + r2 = r8 + else + i12, s12 = index, [] + r13 = _nt_space + s12 << r13 + if r13 + i14 = index + r15 = _nt_right_paren + if r15 + self.index = i14 + r14 = instantiate_node(SyntaxNode,input, index...index) + else + r14 = nil + end + s12 << r14 + end + if s12.last + r12 = instantiate_node(SyntaxNode,input, i12...index, s12) + r12.extend(LookaheadConst2) + else + self.index = i12 + r12 = nil + end + if r12 + r2 = r12 + else + i16, s16 = index, [] + r17 = _nt_space + s16 << r17 + if r17 + i18 = index + r19 = _nt_left_paren + if r19 + self.index = i18 + r18 = instantiate_node(SyntaxNode,input, index...index) + else + r18 = nil + end + s16 << r18 + end + if s16.last + r16 = instantiate_node(SyntaxNode,input, i16...index, s16) + r16.extend(LookaheadConst3) + else + self.index = i16 + r16 = nil + end + if r16 + r2 = r16 + else + self.index = i2 + r2 = nil + end + end + end + end + s0 << r2 + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(LookaheadConst4) + else + self.index = i0 + r0 = nil + end + + node_cache[:lookahead_const][start_index] = r0 + + return r0 + end + + module Name0 + def space + elements[1] + end + end + + def _nt_name + start_index = index + if node_cache[:name].has_key?(index) + cached = node_cache[:name][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + s1, i1 = [], index + loop do + if input.index(Regexp.new('[a-zA-Z0-9_]'), index) == index + r2 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + r2 = nil + end + if r2 + s1 << r2 + else + break + end + end + if s1.empty? + self.index = i1 + r1 = nil + else + r1 = instantiate_node(SyntaxNode,input, i1...index, s1) + end + s0 << r1 + if r1 + r3 = _nt_space + s0 << r3 + end + if s0.last + r0 = instantiate_node(NameNode,input, i0...index, s0) + r0.extend(Name0) + else + self.index = i0 + r0 = nil + end + + node_cache[:name][start_index] = r0 + + return r0 + end + + module NameWithBrackets0 + def name + elements[0] + end + + def brackets + elements[1] + end + end + + def _nt_name_with_brackets + start_index = index + if node_cache[:name_with_brackets].has_key?(index) + cached = node_cache[:name_with_brackets][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + r1 = _nt_name + s0 << r1 + if r1 + r3 = _nt_array_brackets + if r3 + r2 = r3 + else + r2 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r2 + end + if s0.last + r0 = instantiate_node(NameWithBracketsNode,input, i0...index, s0) + r0.extend(NameWithBrackets0) + else + self.index = i0 + r0 = nil + end + + node_cache[:name_with_brackets][start_index] = r0 + + return r0 + end + + module Void0 + def space + elements[1] + end + + end + + def _nt_void + start_index = index + if node_cache[:void].has_key?(index) + cached = node_cache[:void][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index('void', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 4)) + @index += 4 + else + terminal_parse_failure('void') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + if r2 + i3 = index + r4 = _nt_asterisk + if r4 + r3 = nil + else + self.index = i3 + r3 = instantiate_node(SyntaxNode,input, index...index) + end + s0 << r3 + end + end + if s0.last + r0 = instantiate_node(VoidNode,input, i0...index, s0) + r0.extend(Void0) + else + self.index = i0 + r0 = nil + end + + node_cache[:void][start_index] = r0 + + return r0 + end + + module ArrayBrackets0 + def left_bracket + elements[0] + end + + def number + elements[1] + end + + def right_bracket + elements[2] + end + end + + module ArrayBrackets1 + def left_bracket + elements[0] + end + + def right_bracket + elements[1] + end + + end + + def _nt_array_brackets + start_index = index + if node_cache[:array_brackets].has_key?(index) + cached = node_cache[:array_brackets][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + r1 = _nt_left_bracket + s0 << r1 + if r1 + r2 = _nt_right_bracket + s0 << r2 + if r2 + s3, i3 = [], index + loop do + i4, s4 = index, [] + r5 = _nt_left_bracket + s4 << r5 + if r5 + r6 = _nt_number + s4 << r6 + if r6 + r7 = _nt_right_bracket + s4 << r7 + end + end + if s4.last + r4 = instantiate_node(SyntaxNode,input, i4...index, s4) + r4.extend(ArrayBrackets0) + else + self.index = i4 + r4 = nil + end + if r4 + s3 << r4 + else + break + end + end + r3 = instantiate_node(SyntaxNode,input, i3...index, s3) + s0 << r3 + end + end + if s0.last + r0 = instantiate_node(ArrayBracketsNode,input, i0...index, s0) + r0.extend(ArrayBrackets1) + else + self.index = i0 + r0 = nil + end + + node_cache[:array_brackets][start_index] = r0 + + return r0 + end + + module Const0 + def space + elements[1] + end + end + + def _nt_const + start_index = index + if node_cache[:const].has_key?(index) + cached = node_cache[:const][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index('const', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 5)) + @index += 5 + else + terminal_parse_failure('const') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(Const0) + else + self.index = i0 + r0 = nil + end + + node_cache[:const][start_index] = r0 + + return r0 + end + + module Asterisk0 + def space + elements[1] + end + end + + def _nt_asterisk + start_index = index + if node_cache[:asterisk].has_key?(index) + cached = node_cache[:asterisk][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index('*', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + terminal_parse_failure('*') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(Asterisk0) + else + self.index = i0 + r0 = nil + end + + node_cache[:asterisk][start_index] = r0 + + return r0 + end + + module LeftParen0 + def space + elements[1] + end + end + + def _nt_left_paren + start_index = index + if node_cache[:left_paren].has_key?(index) + cached = node_cache[:left_paren][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index('(', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + terminal_parse_failure('(') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(LeftParen0) + else + self.index = i0 + r0 = nil + end + + node_cache[:left_paren][start_index] = r0 + + return r0 + end + + module RightParen0 + def space + elements[1] + end + end + + def _nt_right_paren + start_index = index + if node_cache[:right_paren].has_key?(index) + cached = node_cache[:right_paren][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index(')', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + terminal_parse_failure(')') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(RightParen0) + else + self.index = i0 + r0 = nil + end + + node_cache[:right_paren][start_index] = r0 + + return r0 + end + + module LeftBracket0 + def space + elements[1] + end + end + + def _nt_left_bracket + start_index = index + if node_cache[:left_bracket].has_key?(index) + cached = node_cache[:left_bracket][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index('[', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + terminal_parse_failure('[') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(LeftBracket0) + else + self.index = i0 + r0 = nil + end + + node_cache[:left_bracket][start_index] = r0 + + return r0 + end + + module RightBracket0 + def space + elements[1] + end + end + + def _nt_right_bracket + start_index = index + if node_cache[:right_bracket].has_key?(index) + cached = node_cache[:right_bracket][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index(']', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + terminal_parse_failure(']') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(RightBracket0) + else + self.index = i0 + r0 = nil + end + + node_cache[:right_bracket][start_index] = r0 + + return r0 + end + + module Comma0 + def space + elements[1] + end + end + + def _nt_comma + start_index = index + if node_cache[:comma].has_key?(index) + cached = node_cache[:comma][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index(',', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + terminal_parse_failure(',') + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(Comma0) + else + self.index = i0 + r0 = nil + end + + node_cache[:comma][start_index] = r0 + + return r0 + end + + module Number0 + def space + elements[1] + end + end + + def _nt_number + start_index = index + if node_cache[:number].has_key?(index) + cached = node_cache[:number][index] + @index = cached.interval.end if cached + return cached + end + + i0, s0 = index, [] + if input.index(Regexp.new('[0-9]'), index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + r1 = nil + end + s0 << r1 + if r1 + r2 = _nt_space + s0 << r2 + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(Number0) + else + self.index = i0 + r0 = nil + end + + node_cache[:number][start_index] = r0 + + return r0 + end + + def _nt_space + start_index = index + if node_cache[:space].has_key?(index) + cached = node_cache[:space][index] + @index = cached.interval.end if cached + return cached + end + + s0, i0 = [], index + loop do + if input.index(' ', index) == index + r1 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + terminal_parse_failure(' ') + r1 = nil + end + if r1 + s0 << r1 + else + break + end + end + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + + node_cache[:space][start_index] = r0 + + return r0 + end + +end + +class CMockFunctionPrototypeParser < Treetop::Runtime::CompiledParser + include CMockFunctionPrototype +end + diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index bb10be3..8667606 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -7,13 +7,14 @@ class CMockGenerator attr_reader :config, :file_writer, :tab, :module_name, :mock_name, :utils, :plugins def initialize(config, module_name, file_writer, utils, plugins=[]) - @config = config @file_writer = file_writer - @tab = @config.tab @module_name = module_name - @mock_name = @config.mock_prefix + @module_name - @utils = utils - @plugins = plugins + @utils = utils + @plugins = plugins + @config = config + @tab = @config.tab + @mock_name = @config.mock_prefix + @module_name + @ordered = @config.enforce_strict_ordering end def create_mock(parsed_stuff) @@ -97,21 +98,23 @@ class CMockGenerator file << "#{@tab}unsigned char placeHolder;\n" end file << "#{@tab}unsigned char allocFailure;\n" - file << functions.collect{|function| @plugins.run(:instance_structure, function)}.flatten + file << functions.collect{|function| @plugins.run(:instance_structure, function)}.join file << "} Mock;\n\n" end def create_extern_declarations(file) file << "extern jmp_buf AbortFrame;\n" - file << "extern int GlobalExpectOrder;\n" - file << "extern int GlobalVerifyOrder;\n" + if (@ordered) + file << "extern int GlobalExpectCount;\n" + file << "extern int GlobalVerifyOrder;\n" + end file << "\n" end def create_mock_verify_function(file, functions) file << "void #{@mock_name}_Verify(void)\n{\n" file << "#{@tab}TEST_ASSERT_EQUAL(0, Mock.allocFailure);\n" - file << functions.collect {|function| @plugins.run(:mock_verify, function)}.flatten + file << functions.collect {|function| @plugins.run(:mock_verify, function)}.join file << "}\n\n" end @@ -123,8 +126,12 @@ class CMockGenerator def create_mock_destroy_function(file, functions) file << "void #{@mock_name}_Destroy(void)\n{\n" - file << functions.collect {|function| @plugins.run(:mock_destroy, function) }.flatten + file << functions.collect {|function| @plugins.run(:mock_destroy, function) }.join file << "#{@tab}memset(&Mock, 0, sizeof(Mock));\n" + if (@ordered) + file << "#{@tab}GlobalExpectCount = 0;\n" + file << "#{@tab}GlobalVerifyOrder = 0;\n" + end file << "}\n\n" end @@ -148,7 +155,7 @@ class CMockGenerator # Return expected value, if necessary if (function[:return_type] != "void") - file << @utils.code_handle_return_value(function, "#{@tab}") + file << @utils.code_handle_return_value(function, "#{@tab}").join end # Close out the function diff --git a/lib/cmock_generator_plugin_cexception.rb b/lib/cmock_generator_plugin_cexception.rb index c97e130..2cff595 100644 --- a/lib/cmock_generator_plugin_cexception.rb +++ b/lib/cmock_generator_plugin_cexception.rb @@ -16,7 +16,7 @@ class CMockGeneratorPluginCException def include_files include = @config.cexception_include include = "Exception.h" if (include.nil?) - return "#include \"#{include}\"\n" + return ["#include \"#{include}\"\n"] end def instance_structure(function) @@ -32,9 +32,9 @@ class CMockGeneratorPluginCException def mock_function_declarations(function) if (function[:args_string] == "void") - return "void #{function[:name]}_ExpectAndThrow(#{@config.cexception_throw_type} toThrow);\n" + return ["void #{function[:name]}_ExpectAndThrow(#{@config.cexception_throw_type} toThrow);\n"] else - return "void #{function[:name]}_ExpectAndThrow(#{function[:args_string]}, #{@config.cexception_throw_type} toThrow);\n" + return ["void #{function[:name]}_ExpectAndThrow(#{function[:args_string]}, #{@config.cexception_throw_type} toThrow);\n"] end end diff --git a/lib/cmock_generator_plugin_expect.rb b/lib/cmock_generator_plugin_expect.rb index 0ab12f2..5a3ba3e 100644 --- a/lib/cmock_generator_plugin_expect.rb +++ b/lib/cmock_generator_plugin_expect.rb @@ -24,9 +24,9 @@ class CMockGeneratorPluginExpect end if (@ordered) - lines << [ "#{@tab}#{function[:return_type]} *#{function[:name]}_CallOrder;\n", - "#{@tab}#{function[:return_type]} *#{function[:name]}_CallOrder_Head;\n", - "#{@tab}#{function[:return_type]} *#{function[:name]}_CallOrder_Tail;\n" ] + lines << [ "#{@tab}int *#{function[:name]}_CallOrder;\n", + "#{@tab}int *#{function[:name]}_CallOrder_Head;\n", + "#{@tab}int *#{function[:name]}_CallOrder_Tail;\n" ] end function[:args].each do |arg| @@ -40,15 +40,15 @@ class CMockGeneratorPluginExpect def mock_function_declarations(function) if (function[:args_string] == "void") if (function[:return_type] == 'void') - return "void #{function[:name]}_Expect(void);\n" + return ["void #{function[:name]}_Expect(void);\n"] else - return "void #{function[:name]}_ExpectAndReturn(#{function[:return_string]});\n" + return ["void #{function[:name]}_ExpectAndReturn(#{function[:return_string]});\n"] end else if (function[:return_type] == 'void') - return "void #{function[:name]}_Expect(#{function[:args_string]});\n" + return ["void #{function[:name]}_Expect(#{function[:args_string]});\n"] else - return "void #{function[:name]}_ExpectAndReturn(#{function[:args_string]}, #{function[:return_string]});\n" + return ["void #{function[:name]}_ExpectAndReturn(#{function[:args_string]}, #{function[:return_string]});\n"] end end end @@ -115,7 +115,7 @@ class CMockGeneratorPluginExpect end def mock_verify(function) - return "#{@tab}TEST_ASSERT_EQUAL_MESSAGE(Mock.#{function[:name]}_CallsExpected, Mock.#{function[:name]}_CallCount, \"Function '#{function[:name]}' called unexpected number of times.\");\n" + return ["#{@tab}TEST_ASSERT_EQUAL_MESSAGE(Mock.#{function[:name]}_CallsExpected, Mock.#{function[:name]}_CallCount, \"Function '#{function[:name]}' called unexpected number of times.\");\n"] end def mock_destroy(function) @@ -128,6 +128,14 @@ class CMockGeneratorPluginExpect "#{@tab}#{@tab}Mock.#{function[:name]}_Return_Tail=NULL;\n", "#{@tab}}\n" ] end + if (@ordered) + lines << [ "#{@tab}if (Mock.#{function[:name]}_CallOrder_Head)\n", + "#{@tab}{\n", + "#{@tab}#{@tab}free(Mock.#{function[:name]}_CallOrder_Head);\n", + "#{@tab}#{@tab}Mock.#{function[:name]}_CallOrder_Head=NULL;\n", + "#{@tab}#{@tab}Mock.#{function[:name]}_CallOrder_Tail=NULL;\n", + "#{@tab}}\n" ] + end function[:args].each do |arg| lines << [ "#{@tab}if (Mock.#{function[:name]}_Expected_#{arg[:name]}_Head)\n", "#{@tab}{\n", diff --git a/lib/cmock_generator_plugin_ignore.rb b/lib/cmock_generator_plugin_ignore.rb index c7ef6e7..d8eee3e 100644 --- a/lib/cmock_generator_plugin_ignore.rb +++ b/lib/cmock_generator_plugin_ignore.rb @@ -14,14 +14,14 @@ class CMockGeneratorPluginIgnore end def instance_structure(function) - return "#{@tab}#{@config.ignore_bool_type} #{function[:name]}_IgnoreBool;\n" + return ["#{@tab}#{@config.ignore_bool_type} #{function[:name]}_IgnoreBool;\n"] end def mock_function_declarations(function) if (function[:return_type] == "void") - return "void #{function[:name]}_Ignore(void);\n" + return ["void #{function[:name]}_Ignore(void);\n"] else - return "void #{function[:name]}_IgnoreAndReturn(#{function[:return_string]});\n" + return ["void #{function[:name]}_IgnoreAndReturn(#{function[:return_string]});\n"] end end diff --git a/lib/cmock_generator_utils.rb b/lib/cmock_generator_utils.rb index 7393184..aac79be 100644 --- a/lib/cmock_generator_utils.rb +++ b/lib/cmock_generator_utils.rb @@ -61,7 +61,7 @@ class CMockGeneratorUtils lines << [ "#{@tab}++GlobalExpectCount;\n", code_insert_item_into_expect_array("int", "Mock.#{func_name}_CallOrder_Head", "GlobalExpectCount"), "#{@tab}Mock.#{func_name}_CallOrder = Mock.#{func_name}_CallOrder_Head;\n", - "#{@tab}Mock.#{func_name}_CallOrder += Mock.#{func_name}_CallOrder;\n" ] + "#{@tab}Mock.#{func_name}_CallOrder += Mock.#{func_name}_CallCount;\n" ] end lines.flatten end @@ -85,7 +85,7 @@ class CMockGeneratorUtils unity_msg = (unity_func =~ /_MESSAGE/) ? ", #{msg}" : '' case(unity_func) when "TEST_ASSERT_EQUAL_MEMORY_MESSAGE" - full_expected = (expected.strip[0] == 42) ? expected.slice(1..-1) : "&(#{expected})" + full_expected = (expected =~ /^\*/) ? expected.slice(1..-1) : "&(#{expected})" return "#{indent}#{unity_func}((void*)#{full_expected}, (void*)&(#{actual}), sizeof(#{c_type})#{unity_msg});\n" when /_ARRAY/ return [ "#{indent}if (*p_expected == NULL)\n", diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 0c8b6b4..414c1b2 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -39,7 +39,10 @@ class CMockHeaderParser # void must be void for cmock _ExpectAndReturn calls to process properly. # to a certain extent, this action assumes we're chewing on pre-processed header files void_types = source.scan(/typedef\s+(\(\s*)?void(\s*\))?\s+([\w\d]+)\s*;/) - void_types.each {|type| source.gsub!(/#{type}/, 'void')} if void_types.size > 0 + if void_types + void_types = void_types.flatten.uniq - ['(',')',nil] + void_types.each {|type| source.gsub!(/#{type}/, 'void')} if void_types.size > 0 + end source.gsub!(/\s*\\\s*/m, ' ') # smush multiline statements into single line source.gsub!(/\/\*.*?\*\//m, '') # remove block comments (do it first to avoid trouble with embedded line comments) diff --git a/lib/cmock_plugin_manager.rb b/lib/cmock_plugin_manager.rb index 6f44f0b..ae7a29c 100644 --- a/lib/cmock_plugin_manager.rb +++ b/lib/cmock_plugin_manager.rb @@ -17,9 +17,9 @@ class CMockPluginManager def run(method, args=nil) if args.nil? - return @plugins.collect{ |plugin| plugin.send(method) if plugin.respond_to?(method) }.flatten + return @plugins.collect{ |plugin| plugin.send(method) if plugin.respond_to?(method) }.flatten.join else - return @plugins.collect{ |plugin| plugin.send(method, args) if plugin.respond_to?(method) }.flatten + return @plugins.collect{ |plugin| plugin.send(method, args) if plugin.respond_to?(method) }.flatten.join end end end diff --git a/test/system/systest_generator.rb b/test/system/systest_generator.rb index b355e1d..feb295c 100644 --- a/test/system/systest_generator.rb +++ b/test/system/systest_generator.rb @@ -102,7 +102,7 @@ class SystemTestGenerator includes << [MOCK_PREFIX + namix + MOCKABLE_H] includes << [name + H_EXTENSION] - write_source_file(GENERATED_PATH + TEST_PREFIX + name + C_EXTENSION, includes) do |out| + write_source_file(GENERATED_PATH + TEST_PREFIX + name + C_EXTENSION, includes.flatten) do |out| out.puts(tests[:common]) out.puts('') @@ -120,7 +120,7 @@ class SystemTestGenerator header_file = name + H_EXTENSION - includes = (namix + TYPES_H) if not yaml_hash[:systest][:types].nil? + includes = yaml_hash[:systest][:types].nil? ? [] : [(namix + TYPES_H)] write_header_file(GENERATED_PATH + header_file, name.upcase, includes) do |out| out.puts(source[:header]) @@ -131,7 +131,7 @@ class SystemTestGenerator includes << (namix + MOCKABLE_H) if not yaml_hash[:systest][:mockable].nil? includes << header_file - write_source_file(GENERATED_PATH + name + C_EXTENSION, includes) do |out| + write_source_file(GENERATED_PATH + name + C_EXTENSION, includes.flatten) do |out| out.puts(source[:code]) end end diff --git a/test/system/test_interactions/enforce_strict_ordering.yml b/test/system/test_interactions/enforce_strict_ordering.yml new file mode 100644 index 0000000..237be6d --- /dev/null +++ b/test/system/test_interactions/enforce_strict_ordering.yml @@ -0,0 +1,122 @@ +--- +:cmock: + :enforce_strict_ordering: 1 + :plugins: + - # none + +:systest: + :types: | + #define UINT32 unsigned int + + typedef signed int custom_type; + + :mockable: | + UINT32 foo(custom_type a); + UINT32 bar(custom_type b); + + :source: + :header: | + UINT32 function_a(int a, int b); + void function_b(void); + + :code: | + UINT32 function_a(int a, int b) + { + return foo((custom_type)a) + bar((custom_type)b); + } + + void function_b(void) { } + + void function_c(void) + { + foo((custom_type)1); + foo((custom_type)2); + bar((custom_type)3); + bar((custom_type)4); + foo((custom_type)5); + } + + :tests: + :common: | + void setUp(void) {} + void tearDown(void) {} + + :units: + - :pass: TRUE + :should: 'successfully exercise two simple ExpectAndReturn mock calls' + :code: | + test() + { + foo_ExpectAndReturn((custom_type)1, 10); + bar_ExpectAndReturn((custom_type)2, 20); + TEST_ASSERT_EQUAL(30, function_a(1, 2)); + } + + - :pass: FALSE + :should: 'fail because bar() is not called but is expected' + :code: | + test() + { + foo_ExpectAndReturn((custom_type)1, 10); + TEST_ASSERT_EQUAL(30, function_a(1, 2)); + } + + - :pass: FALSE + :should: 'fail because bar() is called but is not expected' + :code: | + test() + { + bar_ExpectAndReturn((custom_type)1, 10); + function_b(); + } + + - :pass: FALSE + :should: 'fail because bar and foo called in reverse order' + :code: | + test() + { + bar_ExpectAndReturn((custom_type)2, 20); + foo_ExpectAndReturn((custom_type)1, 10); + TEST_ASSERT_EQUAL(30, function_a(1, 2)); + } + + - :pass: TRUE + :should: 'fail because bar and foo called out of order' + :code: | + test() + { + foo_ExpectAndReturn((custom_type)1, 10); + foo_ExpectAndReturn((custom_type)2, 10); + bar_ExpectAndReturn((custom_type)3, 20); + bar_ExpectAndReturn((custom_type)4, 10); + foo_ExpectAndReturn((custom_type)5, 10); + function_c(); + } + + - :pass: FALSE + :should: 'fail because bar and foo called out of order at end' + :code: | + test() + { + foo_ExpectAndReturn((custom_type)1, 10); + foo_ExpectAndReturn((custom_type)2, 10); + bar_ExpectAndReturn((custom_type)3, 20); + foo_ExpectAndReturn((custom_type)5, 10); + bar_ExpectAndReturn((custom_type)4, 10); + function_c(); + } + + - :pass: FALSE + :should: 'fail because bar and foo called out of order at start' + :code: | + test() + { + foo_ExpectAndReturn((custom_type)2, 10); + foo_ExpectAndReturn((custom_type)1, 10); + bar_ExpectAndReturn((custom_type)3, 20); + bar_ExpectAndReturn((custom_type)4, 10); + foo_ExpectAndReturn((custom_type)5, 10); + function_c(); + } + +... diff --git a/test/unit/cmock_generator_main_test.rb b/test/unit/cmock_generator_main_test.rb index 2573dce..bc90099 100644 --- a/test/unit/cmock_generator_main_test.rb +++ b/test/unit/cmock_generator_main_test.rb @@ -39,9 +39,17 @@ class CMockGeneratorTest < Test::Unit::TestCase create_mocks :config, :file_writer, :utils, :plugins @module_name = "PoutPoutFish" + #no strict handling @config.expect.tab.returns(" ") @config.expect.mock_prefix.returns("Mock") + @config.expect.enforce_strict_ordering.returns(false) @cmock_generator = CMockGenerator.new(@config, @module_name, @file_writer, @utils, @plugins) + + #strict handling + @config.expect.tab.returns(" ") + @config.expect.mock_prefix.returns("Mock") + @config.expect.enforce_strict_ordering.returns(true) + @cmock_generator_strict = CMockGenerator.new(@config, @module_name, @file_writer, @utils, @plugins) end def teardown @@ -141,6 +149,7 @@ class CMockGeneratorTest < Test::Unit::TestCase "{\n", " unsigned char placeHolder;\n", " unsigned char allocFailure;\n", + "", "} Mock;\n\n" ] @@ -157,9 +166,9 @@ class CMockGeneratorTest < Test::Unit::TestCase expected = [ "static struct MockPoutPoutFishInstance\n", "{\n", " unsigned char allocFailure;\n", - " Uno_First(int Candy, int)", - " Dos_First(int Candy, int)", - " Uno_Second(bool Smarty, char)", + " Uno_First(int Candy, int)" + + " Dos_First(int Candy, int)" + + " Uno_Second(bool Smarty, char)" + " Dos_Second(bool Smarty, char)", "} Mock;\n\n" ] @@ -174,8 +183,6 @@ class CMockGeneratorTest < Test::Unit::TestCase should "create extern declarations for source file" do output = [] expected = [ "extern jmp_buf AbortFrame;\n", - "extern int GlobalExpectOrder;\n", - "extern int GlobalVerifyOrder;\n", "\n" ] @cmock_generator.create_extern_declarations(output) @@ -183,11 +190,24 @@ class CMockGeneratorTest < Test::Unit::TestCase assert_equal(expected, output.flatten) end + should "create extern declarations for source file when using strict ordering" do + output = [] + expected = [ "extern jmp_buf AbortFrame;\n", + "extern int GlobalExpectCount;\n", + "extern int GlobalVerifyOrder;\n", + "\n" ] + + @cmock_generator_strict.create_extern_declarations(output) + + assert_equal(expected, output.flatten) + end + should "create mock verify functions in source file when no functions specified" do functions = [] output = [] expected = [ "void MockPoutPoutFish_Verify(void)\n{\n", " TEST_ASSERT_EQUAL(0, Mock.allocFailure);\n", + "", "}\n\n" ] @@ -203,9 +223,9 @@ class CMockGeneratorTest < Test::Unit::TestCase output = [] expected = [ "void MockPoutPoutFish_Verify(void)\n{\n", " TEST_ASSERT_EQUAL(0, Mock.allocFailure);\n", - " Uno_First", - " Dos_First", - " Uno_Second", + " Uno_First" + + " Dos_First" + + " Uno_Second" + " Dos_Second", "}\n\n" ] @@ -233,6 +253,7 @@ class CMockGeneratorTest < Test::Unit::TestCase functions = [] output = [] expected = [ "void MockPoutPoutFish_Destroy(void)\n{\n", + "", " memset(&Mock, 0, sizeof(Mock));\n", "}\n\n" ] @@ -248,9 +269,9 @@ class CMockGeneratorTest < Test::Unit::TestCase ] output = [] expected = [ "void MockPoutPoutFish_Destroy(void)\n{\n", - " Uno_First(int Candy, int)", - " Dos_First(int Candy, int)", - " Uno_Second(bool Smarty, char)", + " Uno_First(int Candy, int)" + + " Dos_First(int Candy, int)" + + " Uno_Second(bool Smarty, char)" + " Dos_Second(bool Smarty, char)", " memset(&Mock, 0, sizeof(Mock));\n", "}\n\n" @@ -263,6 +284,29 @@ class CMockGeneratorTest < Test::Unit::TestCase assert_equal(expected, output.flatten) end + should "create mock destroy functions in source file when extra functions specified with strict ordering" do + functions = [ { :name => "First", :args => "int Candy", :return_type => "int" }, + { :name => "Second", :args => "bool Smarty", :return_type => "char" } + ] + output = [] + expected = [ "void MockPoutPoutFish_Destroy(void)\n{\n", + " Uno_First(int Candy, int)" + + " Dos_First(int Candy, int)" + + " Uno_Second(bool Smarty, char)" + + " Dos_Second(bool Smarty, char)", + " memset(&Mock, 0, sizeof(Mock));\n", + " GlobalExpectCount = 0;\n", + " GlobalVerifyOrder = 0;\n", + "}\n\n" + ] + @plugins.expect.run(:mock_destroy, functions[0]).returns([" Uno_First(int Candy, int)"," Dos_First(int Candy, int)"]) + @plugins.expect.run(:mock_destroy, functions[1]).returns([" Uno_Second(bool Smarty, char)"," Dos_Second(bool Smarty, char)"]) + + @cmock_generator_strict.create_mock_destroy_function(output, functions) + + assert_equal(expected, output.flatten) + end + should "create mock implementation functions in source file" do function = { :modifier => "static", :return_type => "bool", @@ -285,7 +329,7 @@ class CMockGeneratorTest < Test::Unit::TestCase ] @plugins.expect.run(:mock_implementation_prefix, function).returns([" PreSupaFunctionUno.bool"," PreSupaFunctionDos.bool"]) @plugins.expect.run(:mock_implementation, function).returns([" MockSupaFunctionUno(uint32 sandwiches, const char* named)"," MockSupaFunctionDos(uint32 sandwiches, const char* named)"]) - @utils.expect.code_handle_return_value(function," ").returns(" UtilsSupaFunction.bool") + @utils.expect.code_handle_return_value(function," ").returns([" UtilsSupaFunction.bool"]) @cmock_generator.create_mock_implementation(output, function) @@ -313,7 +357,7 @@ class CMockGeneratorTest < Test::Unit::TestCase ] @plugins.expect.run(:mock_implementation_prefix, function).returns([" PreSupaFunctionUno.int"," PreSupaFunctionDos.int"]) @plugins.expect.run(:mock_implementation, function).returns([" MockSupaFunctionUno(uint32 sandwiches)"," MockSupaFunctionDos(uint32 sandwiches)"]) - @utils.expect.code_handle_return_value(function," ").returns(" UtilsSupaFunction.int") + @utils.expect.code_handle_return_value(function," ").returns([" UtilsSupaFunction.int"]) @cmock_generator.create_mock_implementation(output, function) diff --git a/test/unit/cmock_generator_plugin_cexception_test.rb b/test/unit/cmock_generator_plugin_cexception_test.rb index 2961455..ee7f55c 100644 --- a/test/unit/cmock_generator_plugin_cexception_test.rb +++ b/test/unit/cmock_generator_plugin_cexception_test.rb @@ -19,14 +19,14 @@ class CMockGeneratorPluginCExceptionTest < Test::Unit::TestCase end should "include the cexception library" do - expected = "#include \"Exception.h\"\n" + expected = ["#include \"Exception.h\"\n"] @config.expect.cexception_include.returns(nil) returned = @cmock_generator_plugin_cexception.include_files assert_equal(expected, returned) end should "include the cexception library with a custom path if specified" do - expected = "#include \"../cexception/lib/Exception.h\"\n" + expected = ["#include \"../cexception/lib/Exception.h\"\n"] @config.expect.cexception_include.returns("../cexception/lib/Exception.h") returned = @cmock_generator_plugin_cexception.include_files assert_equal(expected, returned) @@ -52,7 +52,7 @@ class CMockGeneratorPluginCExceptionTest < Test::Unit::TestCase function = { :name => "Spruce", :args_string => "void", :return_type => "void" } @config.expect.cexception_throw_type.returns("EXCEPTION_TYPE") - expected = "void Spruce_ExpectAndThrow(EXCEPTION_TYPE toThrow);\n" + expected = ["void Spruce_ExpectAndThrow(EXCEPTION_TYPE toThrow);\n"] returned = @cmock_generator_plugin_cexception.mock_function_declarations(function) assert_equal(expected, returned) end @@ -61,7 +61,7 @@ class CMockGeneratorPluginCExceptionTest < Test::Unit::TestCase function = { :name => "Spruce", :args_string => "const char* Petunia, uint32_t Lily", :return_type => "void" } @config.expect.cexception_throw_type.returns("EXCEPTION_TYPE") - expected = "void Spruce_ExpectAndThrow(const char* Petunia, uint32_t Lily, EXCEPTION_TYPE toThrow);\n" + expected = ["void Spruce_ExpectAndThrow(const char* Petunia, uint32_t Lily, EXCEPTION_TYPE toThrow);\n"] returned = @cmock_generator_plugin_cexception.mock_function_declarations(function) assert_equal(expected, returned) end diff --git a/test/unit/cmock_generator_plugin_expect_test.rb b/test/unit/cmock_generator_plugin_expect_test.rb index 9753ed5..a1aaecf 100644 --- a/test/unit/cmock_generator_plugin_expect_test.rb +++ b/test/unit/cmock_generator_plugin_expect_test.rb @@ -4,12 +4,22 @@ require 'cmock_generator_plugin_expect' class CMockGeneratorPluginExpectTest < Test::Unit::TestCase def setup create_mocks :config, :utils + + #no strict ordering @config.expect.tab.returns(" ") @config.expect.when_ptr_star.returns(:compare_data) @config.expect.enforce_strict_ordering.returns(false) @config.stubs!(:respond_to?).returns(true) @utils.expect.helpers.returns({}) @cmock_generator_plugin_expect = CMockGeneratorPluginExpect.new(@config, @utils) + + #strict ordering + @config.expect.tab.returns(" ") + @config.expect.when_ptr_star.returns(:compare_data) + @config.expect.enforce_strict_ordering.returns(true) + @config.stubs!(:respond_to?).returns(true) + @utils.expect.helpers.returns({}) + @cmock_generator_plugin_expect_strict = CMockGeneratorPluginExpect.new(@config, @utils) end def teardown @@ -89,9 +99,24 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase assert_equal(expected, returned) end + should "add to control structure mock needs of functions of style 'void func(void)' and global ordering" do + function = {:name => "Oak", :args => [], :return_type => "void"} + count_type = "uint32" + @config.expect.expect_call_count_type.returns(count_type) + + expected = [" #{count_type} #{function[:name]}_CallCount;\n", + " #{count_type} #{function[:name]}_CallsExpected;\n", + " int *#{function[:name]}_CallOrder;\n", + " int *#{function[:name]}_CallOrder_Head;\n", + " int *#{function[:name]}_CallOrder_Tail;\n" + ] + returned = @cmock_generator_plugin_expect_strict.instance_structure(function) + assert_equal(expected, returned) + end + should "add mock function declaration for functions of style 'void func(void)'" do function = {:name => "Maple", :args_string => "void", :return_type => "void"} - expected = "void #{function[:name]}_Expect(#{function[:args_string]});\n" + expected = ["void #{function[:name]}_Expect(#{function[:args_string]});\n"] returned = @cmock_generator_plugin_expect.mock_function_declarations(function) assert_equal(expected, returned) end @@ -99,7 +124,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase should "add mock function declaration for functions of style 'int func(void)'" do function = {:name => "Spruce", :args_string => "void", :return_string => "int #{CMOCK_RETURN_PARAM_NAME}"} - expected = "void #{function[:name]}_ExpectAndReturn(#{function[:return_string]});\n" + expected = ["void #{function[:name]}_ExpectAndReturn(#{function[:return_string]});\n"] returned = @cmock_generator_plugin_expect.mock_function_declarations(function) assert_equal(expected, returned) end @@ -107,7 +132,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase should "add mock function declaration for functions of style 'const char* func(int tofu)'" do function = {:name => "Pine", :args_string => "int tofu", :return_string => "const char* #{CMOCK_RETURN_PARAM_NAME}"} - expected = "void #{function[:name]}_ExpectAndReturn(#{function[:args_string]}, #{function[:return_string]});\n" + expected = ["void #{function[:name]}_ExpectAndReturn(#{function[:args_string]}, #{function[:return_string]});\n"] returned = @cmock_generator_plugin_expect.mock_function_declarations(function) assert_equal(expected, returned) end @@ -167,6 +192,26 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase assert_equal(expected, returned) end + should "add mock function implementation for functions of style 'void func(void)' and strict ordering" do + function = {:name => "Apple", :args => [], :return_type => "void"} + expected = [" Mock.Apple_CallCount++;\n", + " if (Mock.Apple_CallCount > Mock.Apple_CallsExpected)\n", + " {\n", + " TEST_FAIL(\"Apple Called More Times Than Expected\");\n", + " }\n", + " {\n", + " int* p_expected = Mock.Apple_CallOrder;\n", + " ++GlobalVerifyOrder;\n", + " if (Mock.Apple_CallOrder != Mock.Apple_CallOrder_Tail)\n", + " Mock.Apple_CallOrder++;\n", + " BLEH", + " }\n" + ] + @utils.expect.expect_helper('int', '*p_expected', 'GlobalVerifyOrder', "\"Function 'Apple' Called Out Of Order.\""," ").returns(" BLEH") + returned = @cmock_generator_plugin_expect_strict.mock_implementation(function) + assert_equal(expected, returned) + end + should "add mock interfaces for functions of style 'void func(void)'" do @utils.expect.code_add_base_expectation("Pear").returns("mock_retval_0") function = {:name => "Pear", :args => [], :args_string => "void", :return_type => "void"} @@ -236,7 +281,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase should "add mock verify lines" do function = {:name => "Banana" } - expected = " TEST_ASSERT_EQUAL_MESSAGE(Mock.Banana_CallsExpected, Mock.Banana_CallCount, \"Function 'Banana' called unexpected number of times.\");\n" + expected = [" TEST_ASSERT_EQUAL_MESSAGE(Mock.Banana_CallsExpected, Mock.Banana_CallCount, \"Function 'Banana' called unexpected number of times.\");\n"] returned = @cmock_generator_plugin_expect.mock_verify(function) assert_equal(expected, returned) end @@ -279,4 +324,16 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase returned = @cmock_generator_plugin_expect.mock_destroy(function) assert_equal(expected, returned) end + + should "add mock destroy for functions with strict ordering" do + function = {:name => "Peach", :args => [], :return_type => "void" } + expected = [ " if (Mock.Peach_CallOrder_Head)\n", + " {\n", + " free(Mock.Peach_CallOrder_Head);\n", + " Mock.Peach_CallOrder_Head=NULL;\n", + " Mock.Peach_CallOrder_Tail=NULL;\n", + " }\n" ] + returned = @cmock_generator_plugin_expect_strict.mock_destroy(function) + assert_equal(expected, returned) + end end diff --git a/test/unit/cmock_generator_plugin_ignore_test.rb b/test/unit/cmock_generator_plugin_ignore_test.rb index 78c2fe5..72aeb47 100644 --- a/test/unit/cmock_generator_plugin_ignore_test.rb +++ b/test/unit/cmock_generator_plugin_ignore_test.rb @@ -26,21 +26,21 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase function = {:name => "Grass", :args => [], :return_type => "void"} @config.expect.ignore_bool_type.returns("BOOL") - expected = " BOOL Grass_IgnoreBool;\n" + expected = [" BOOL Grass_IgnoreBool;\n"] returned = @cmock_generator_plugin_ignore.instance_structure(function) assert_equal(expected, returned) end should "handle function declarations for functions without return values" do function = {:name => "Mold", :args_string => "void", :return_type => "void"} - expected = "void Mold_Ignore(void);\n" + expected = ["void Mold_Ignore(void);\n"] returned = @cmock_generator_plugin_ignore.mock_function_declarations(function) assert_equal(expected, returned) end should "handle function declarations for functions that returns something" do function = {:name => "Fungus", :args_string => "void", :return_type => "const char*", :return_string => "const char* #{CMOCK_RETURN_PARAM_NAME}"} - expected = "void Fungus_IgnoreAndReturn(const char* #{CMOCK_RETURN_PARAM_NAME});\n" + expected = ["void Fungus_IgnoreAndReturn(const char* #{CMOCK_RETURN_PARAM_NAME});\n"] returned = @cmock_generator_plugin_ignore.mock_function_declarations(function) assert_equal(expected, returned) end diff --git a/test/unit/cmock_generator_utils_test.rb b/test/unit/cmock_generator_utils_test.rb index ccae92c..fb625f6 100644 --- a/test/unit/cmock_generator_utils_test.rb +++ b/test/unit/cmock_generator_utils_test.rb @@ -24,10 +24,10 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase @config.expect.tab.returns(" ") @config.expect.when_ptr_star.returns(:compare_ptr) @config.expect.enforce_strict_ordering.returns(false) - @cmock_generator_utils = CMockGeneratorUtils.new(@config, {:A, :B}) + @cmock_generator_utils = CMockGeneratorUtils.new(@config, {:A=>1, :B=>2}) assert_equal(@config, @cmock_generator_utils.config) assert_equal(" ", @cmock_generator_utils.tab) - assert_equal({:A, :B},@cmock_generator_utils.helpers) + assert_equal({:A=>1, :B=>2},@cmock_generator_utils.helpers) end should "set up an empty call list if no arguments passed" do @@ -168,7 +168,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase " Mock.Nectarine_CallOrder_Tail = &Mock.Nectarine_CallOrder_Head[sz+1];\n", " }\n", " Mock.Nectarine_CallOrder = Mock.Nectarine_CallOrder_Head;\n", - " Mock.Nectarine_CallOrder += Mock.Nectarine_CallOrder;\n" ] + " Mock.Nectarine_CallOrder += Mock.Nectarine_CallCount;\n" ] @cmock_generator_utils.ordered = true returned = @cmock_generator_utils.code_add_base_expectation("Nectarine") assert_equal(expected, returned) diff --git a/test/unit/cmock_plugin_manager_test.rb b/test/unit/cmock_plugin_manager_test.rb index 20486f6..4ac6219 100644 --- a/test/unit/cmock_plugin_manager_test.rb +++ b/test/unit/cmock_plugin_manager_test.rb @@ -57,12 +57,12 @@ class CMockPluginManagerTest < Test::Unit::TestCase @cmock_plugins = CMockPluginManager.new(@config, @utils) @cmock_plugins.plugins = [@pluginA, @pluginB] - @pluginA.stubs!(:test_method).returns("This Is An Awesome Test") - @pluginB.stubs!(:test_method).returns(["And This is Part 2","Of An Awesome Test"]) + @pluginA.stubs!(:test_method).returns(["This Is An Awesome Test-"]) + @pluginB.stubs!(:test_method).returns(["And This is Part 2-","Of An Awesome Test"]) - expected = ["This Is An Awesome Test","And This is Part 2","Of An Awesome Test"] + expected = "This Is An Awesome Test-And This is Part 2-Of An Awesome Test" output = @cmock_plugins.run(:test_method) - assert_equal(expected, output.flatten) + assert_equal(expected, output) end should "run a desired method and arg list over each plugin requested and return the results" do @@ -72,11 +72,11 @@ class CMockPluginManagerTest < Test::Unit::TestCase @cmock_plugins = CMockPluginManager.new(@config, @utils) @cmock_plugins.plugins = [@pluginA, @pluginB] - @pluginA.stubs!(:test_method).returns("This Is An Awesome Test") - @pluginB.stubs!(:test_method).returns(["And This is Part 2","Of An Awesome Test"]) + @pluginA.stubs!(:test_method).returns(["This Is An Awesome Test-"]) + @pluginB.stubs!(:test_method).returns(["And This is Part 2-","Of An Awesome Test"]) - expected = ["This Is An Awesome Test","And This is Part 2","Of An Awesome Test"] + expected = "This Is An Awesome Test-And This is Part 2-Of An Awesome Test" output = @cmock_plugins.run(:test_method, "chickenpotpie") - assert_equal(expected, output.flatten) + assert_equal(expected, output) end end