PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/src/tools/wrappers-generator/c_argument.e

http://github.com/tybor/Liberty
Specman e | 104 lines | 82 code | 12 blank | 10 comment | 4 complexity | ebc4185935c002f4b7e2b76aa65b7071 MD5 | raw file
  1class C_ARGUMENT
  2   -- An "Argument" node of an XML file made by gccxml.
  3
  4inherit
  5   C_FUNCTION_ARGUMENT
  6   NAMED_NODE
  7   TYPED_NODE
  8 
  9insert
 10   NAME_CONVERTER
 11
 12create {GCCXML_TREE}
 13   make
 14
 15feature {ANY}
 16   is_ellipsis: BOOLEAN False
 17
 18   is_fundamental: BOOLEAN
 19      do
 20         Result := types.at(dequalify(type)).is_fundamental
 21      end
 22
 23   is_void: BOOLEAN
 24      do
 25         Result := types.at(dequalify(type)).is_void
 26      end
 27
 28   has_wrapper: BOOLEAN
 29      local dequalified: UNICODE_STRING; actual_type: C_TYPE
 30      do
 31         -- Previously it was "Result := types.at(dequalify(type)).has_wrapper" but that's too brittle
 32         check type/=Void end -- unnecessary when we will have attached types
 33         dequalified := dequalify(type)
 34         if dequalified /= Void then
 35             actual_type := types.reference_at(dequalified)
 36             if actual_type/=Void then
 37                 Result := actual_type.has_wrapper
 38             else
 39                 check 
 40                     Result=False
 41                 end
 42             end
 43         else
 44             check
 45                 Result=False
 46             end
 47         end
 48      rescue
 49         log("has_wrapper failed. Known types:%N")
 50         types.for_each_item(agent (a_type: C_TYPE)
 51            do
 52               io.put_string(a_type.out)
 53            end(?))
 54
 55         print_run_time_stack
 56         die_with_code(5)
 57      end
 58
 59   wrapper_type: STRING
 60      do
 61         Result := types.at(dequalify(type)).wrapper_type
 62      end
 63
 64   placeholder: STRING
 65         -- The placeholder name of Current, suitable for Liberty as a newly created string.
 66      do
 67         if c_name = Void then
 68            -- Nameless prototype: 
 69            if pos /= 0 then
 70                -- the position of Current argment has been set by its
 71                -- function. We trust it to be unique in the function and use
 72                -- it to give a name to this nameless argument
 73                Result := "argument_"
 74                pos.append_in(Result)
 75            else
 76                -- no position set. Using providing sound default, using
 77                -- line and column, which are locally unique. 
 78                Result := "an_argument_l"
 79                line.append_in(Result)
 80                Result.append(once "_c")
 81                column.append_in(Result)
 82            end
 83         else
 84            Result := eiffel_argument(c_name.to_utf8)
 85         end
 86      ensure
 87         Result /= Void
 88         not Result.is_empty
 89      end
 90
 91   put_on (a_buffer: FORMATTER)
 92      require else
 93         has_wrapper
 94      local
 95         a_placeholder, a_wrapper_type: STRING
 96      do
 97         -- Cache results of `placeholder' and `wrapper_type' queries
 98         a_placeholder := placeholder
 99         a_wrapper_type := wrapper_type
100         log(once "#(1): #(2) " # a_placeholder # a_wrapper_type)
101
102         a_buffer.append(once "#(1): #(2)" # a_placeholder # a_wrapper_type)
103      end
104end -- class C_ARGUMENT