Revision f96c51a0

b/lib/build/sphinx_ext.py
130 130
      yield "  %s" % line
131 131

  
132 132

  
133
def _BuildOpcodeResult(op_id):
134
  """Build opcode result documentation.
135

  
136
  @type op_id: string
137
  @param op_id: Opcode ID
138

  
139
  """
140
  op_cls = opcodes.OP_MAPPING[op_id]
141

  
142
  result_fn = getattr(op_cls, "OP_RESULT", None)
143

  
144
  if not result_fn:
145
    raise OpcodeError("Opcode '%s' has no result description" % op_id)
146

  
147
  return "``%s``" % result_fn
148

  
149

  
133 150
class OpcodeParams(sphinx.util.compat.Directive):
134 151
  """Custom directive for opcode parameters.
135 152

  
......
161 178
    return []
162 179

  
163 180

  
181
class OpcodeResult(sphinx.util.compat.Directive):
182
  """Custom directive for opcode result.
183

  
184
  See also <http://docutils.sourceforge.net/docs/howto/rst-directives.html>.
185

  
186
  """
187
  has_content = False
188
  required_arguments = 1
189
  optional_arguments = 0
190
  final_argument_whitespace = False
191

  
192
  def run(self):
193
    op_id = self.arguments[0]
194

  
195
    tab_width = 2
196
    path = op_id
197
    include_text = _BuildOpcodeResult(op_id)
198

  
199
    # Inject into state machine
200
    include_lines = docutils.statemachine.string2lines(include_text, tab_width,
201
                                                       convert_whitespace=1)
202
    self.state_machine.insert_input(include_lines, path)
203

  
204
    return []
205

  
206

  
164 207
def PythonEvalRole(role, rawtext, text, lineno, inliner,
165 208
                   options={}, content=[]):
166 209
  """Custom role to evaluate Python expressions.
......
240 283

  
241 284
  """
242 285
  app.add_directive("opcode_params", OpcodeParams)
286
  app.add_directive("opcode_result", OpcodeResult)
243 287
  app.add_directive("pyassert", PythonAssert)
244 288
  app.add_role("pyeval", PythonEvalRole)

Also available in: Unified diff