def renderOperation(out, interface, operation):
  assert(not operation.extended_attributes)
  assert(not operation.stringifier)
  assert(not operation.static)
  assert(not operation.setter)
  assert(not operation.creator)
  assert(not operation.deleter)
  assert(not operation.legacycaller)

  impl = implArgument(interface)

  print >>out, "%s %s::%s {" % ( \
    emitType(operation.return_type),
    interface.name,
    operationSignature(operation))

  if not isinstance(operation.return_type, pywidl.InterfaceType):
    print >>out, "  return CSSOM_%s_%s(%s%s);" % (
      interface.name,
      interfaceMemberName(interface, operation),
      impl,
      "".join([", %s" % arg.name for arg in operation.arguments]))
  else:
    print >>out, "  return %s(CSSOM_%s_%s(%s%s));" % (
      emitType(operation.return_type),
      interface.name,
      interfaceMemberName(interface, operation),
      impl,
      "".join([", %s" % arg.name for arg in operation.arguments]))

  print >>out, "}"
def renderAttribute(out, interface, attribute, definitions):
  assert(not attribute.inherit)

  impl = implArgument(interface)

  print >>out, "%s %s::%s {" % ( \
    emitType(attribute.type),
    interface.name,
    attributeGetterSignature(attribute))

  if not isinstance(attribute.type, pywidl.InterfaceType):
    print >>out, "  return CSSOM_%s_%s(%s);" % ( \
      interface.name,
      interfaceMemberName(interface, attribute),
      impl)
  else:
    print >>out, "  return %s(CSSOM_%s_%s(%s));" % ( \
      emitType(attribute.type),
      interface.name,
      interfaceMemberName(interface, attribute),
      impl)

  print >>out, "}"

  if not attribute.readonly:
    print >>out
    print >>out
    print >>out
    print >>out, "void %s::%s {" % ( \
      interface.name,
      attributeSetterSignature(attribute))

    print >>out, "  CSSOM_%s_%s(%s, %s);" % ( \
      interface.name,
      attributeSetterName(interfaceMemberName(interface, attribute)),
      impl,
      attribute.name)

    print >>out, "}"

  forwarded_attribute = attributeExtendedAttributes(attribute, definitions)
  if forwarded_attribute:
    print >>out
    print >>out
    print >>out
    print >>out, "void %s::%s {" % ( \
      interface.name,
      attributeSetterSignature(forwarded_attribute))

    print >>out, "  CSSOM_%s_%s(%s, %s);" % ( \
      interface.name,
      attributeSetterName(interfaceMemberName(interface, forwarded_attribute)),
      impl,
      attribute.name)

    print >>out, "}"
def renderSpecialOperations(out, interface):
  stringifier = None
  getter_operations = []

  for member in interface.members:
    if isinstance(member, pywidl.Attribute) and member.stringifier:
      assert(stringifier is None, "Multiple stringifiers not allowed")
      stringifier = member

    if isinstance(member, pywidl.Operation):
      assert(not member.setter)
      assert(not member.creator)
      assert(not member.deleter)
      assert(not member.legacycaller)
      assert(not member.stringifier)

      if member.getter: getter_operations.append(member)

  if stringifier:
    impl = implArgument(interface)

    print >>out
    print >>out
    print >>out
    print >>out, "%s::operator const char *() {" % interface.name
    print >>out, "  return CSSOM_%s_%s(%s);" % ( \
      interface.name,
      interfaceMemberName(interface, stringifier),
      impl)
    print >>out, "}"

  for operation in getter_operations:
    assert(len(operation.arguments) == 1)

    print >>out
    print >>out
    print >>out
    print >>out, "%s %s::%s {" % ( \
      emitType(operation.return_type),
      interface.name,
      getterOperationSignature(operation))
    print >>out, "  return CSSOM_%s_%s(%s%s);" % ( \
      interface.name,
      interfaceMemberName(interface, operation),
      implArgument(interface),
      "".join([", %s" % arg.name for arg in operation.arguments]))
    print >>out, "}"

    if stringifier \
    and isStringType(operation.return_type) \
    and isNumeralArgument(operation.arguments[0]):
      print >>out
      print >>out
      print >>out
      print >>out, "const char * %s::operator[](int %s) const {" % ( \
        interface.name,
        operation.arguments[0].name
      )
      print >>out, "  return %s::operator[]((%s)%s);" % ( \
        interface.name,
        emitType(operation.arguments[0].type),
        operation.arguments[0].name
      )
      print >>out, "}"