<commit_before># Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Generates C++ source files from a mojom.Module."""

from generate import mojom
from generate import mojom_pack
from generate import mojom_generator

from generate.template_expander import UseJinja


_kind_to_cpp_type = {
  mojom.BOOL:         "bool",
  mojom.INT8:         "int8_t",
  mojom.UINT8:        "uint8_t",
  mojom.INT16:        "int16_t",
  mojom.UINT16:       "uint16_t",
  mojom.INT32:        "int32_t",
  mojom.UINT32:       "uint32_t",
  mojom.FLOAT:        "float",
  mojom.HANDLE:       "mojo::Handle",
  mojom.DCPIPE:       "mojo::DataPipeConsumerHandle",
  mojom.DPPIPE:       "mojo::DataPipeProducerHandle",
  mojom.MSGPIPE:      "mojo::MessagePipeHandle",
  mojom.SHAREDBUFFER: "mojo::SharedBufferHandle",
  mojom.INT64:        "int64_t",
  mojom.UINT64:       "uint64_t",
  mojom.DOUBLE:       "double",
}


def NamespaceToArray(namespace):
  return namespace.split('.')

def GetNameForKind(kind, internal = False):
  parts = []
  if kind.imported_from:
    parts.extend(NamespaceToArray(kind.imported_from["namespace"]))
    if internal:
      parts.append("internal")
  if kind.parent_kind:
    parts.append(kind.parent_kind.name)
  parts.append(kind.name)
  return "::".join(parts)

def GetCppType(kind):
  if isinstance(kind, mojom.Struct):
    return "%s_Data*" % GetNameForKind(kind, internal=True)
  if isinstance(kind, mojom.Array):
    return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind)
  if isinstance(kind, mojom.Interface):
    return "%sHandle" % kind.name
  if isinstance(kind, mojom.Enum):
    return "int32_t"
  if kind.spec == 's':
    return "mojo::internal::String_Data*"
  return _kind_to_cpp_type[kind]

def GetCppArrayArgWrapperType(kind):<commit_msg>Mojo: Mojom: Fix no-namespace handling for C++ generator.<commit_after># Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Generates C++ source files from a mojom.Module."""

from generate import mojom
from generate import mojom_pack
from generate import mojom_generator

from generate.template_expander import UseJinja


_kind_to_cpp_type = {
  mojom.BOOL:         "bool",
  mojom.INT8:         "int8_t",
  mojom.UINT8:        "uint8_t",
  mojom.INT16:        "int16_t",
  mojom.UINT16:       "uint16_t",
  mojom.INT32:        "int32_t",
  mojom.UINT32:       "uint32_t",
  mojom.FLOAT:        "float",
  mojom.HANDLE:       "mojo::Handle",
  mojom.DCPIPE:       "mojo::DataPipeConsumerHandle",
  mojom.DPPIPE:       "mojo::DataPipeProducerHandle",
  mojom.MSGPIPE:      "mojo::MessagePipeHandle",
  mojom.SHAREDBUFFER: "mojo::SharedBufferHandle",
  mojom.INT64:        "int64_t",
  mojom.UINT64:       "uint64_t",
  mojom.DOUBLE:       "double",
}


def NamespaceToArray(namespace):
  return namespace.split('.') if namespace else []

def GetNameForKind(kind, internal = False):
  parts = []
  if kind.imported_from:
    parts.extend(NamespaceToArray(kind.imported_from["namespace"]))
    if internal:
      parts.append("internal")
  if kind.parent_kind:
    parts.append(kind.parent_kind.name)
  parts.append(kind.name)
  return "::".join(parts)

def GetCppType(kind):
  if isinstance(kind, mojom.Struct):
    return "%s_Data*" % GetNameForKind(kind, internal=True)
  if isinstance(kind, mojom.Array):
    return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind)
  if isinstance(kind, mojom.Interface):
    return "%sHandle" % kind.name
  if isinstance(kind, mojom.Enum):
    return "int32_t"
  if kind.spec == 's':
    return "mojo::internal::String_Data*"
  return _kind_to_cpp_type[kind]

def GetCppArrayArgWrapperType(kind):
{'fraction_non_alphanumeric': 0.1259432734842571, 'fraction_numerical': 0.017694509497788186, 'mean_word_length': 3.769230769230769, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6077593', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1379, 'n_words': 289}