<commit_before>/*
 * Copyright 2008, 2009 Google Inc.
 * Copyright 2006, 2007 Nintendo Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF Any KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef GOOGLE_ESIDL_REFLECT_H_INCLUDED
#define GOOGLE_ESIDL_REFLECT_H_INCLUDED

#include <cctype>
#include <cstring>
#include <cstdlib>
#include <string>

/**
 * This class provides access to the string-encoded interface meta-data.
 *
 *  ws -> ' '
 *  name -> digits identifier  // digits represents the # of characters in the identifier
 *
 *  interface ->
 *    I name
 *    extends*
 *    [ operation, setter, getter, constructor, constant ]*
 *
 *  extends -> X name
 *  operation -> F digits type name (type name)* raises*   // digits represent the # of parameters
 *  setter -> S 1 v name type raises*
 *  getter -> G 0 type name raises*
 *  constructor -> N digits type name (type name)* raises* // digits represent the # of parameters
 *  constant  -> C name value ws  // value represents a double value parseable by strtold()
 *
 *  type ->
 *    A: any
 *    D: DOMString
 *    Q type: sequence<type>
 *    O name: Object
 *    B type: Boxed valuetype
 *    V type: [Variadic] in type
 *    v: void
 *    b: boolean
 *    h: octet
 *    s: short
 *    t: unsigned short
 *    l: long
 *    m: unsigned long
 *    x: long long
 *    y: unsigned long long
 *    f: float
 *    d: double
 *    p: void*                              // XXX To be unsupported
 *    YnT: array of n elements of type T    // XXX To be unsupported
 *
 *  raises ->
 *    R name
 *
 *  TODO: embed other extended attributes in the meta-data.
 */
class Reflect
{
public:
    // Type
    static const char kVoid = 'v';
    static const char kBoolean = 'b';
    static const char kOctet = 'h';
    static const char kShort = 's';
    static const char kUnsignedShort = 't';
    static const char kLong = 'l';
    static const char kUnsignedLong = 'm';
    static const char kLongLong = 'x';
    static const char kUnsignedLongLong = 'y';
    static const char kFloat = 'f';
    static const char kDouble = 'd';
    static const char kString = 'D';
    static const char kAny = 'A';
    static const char kObject = 'O';
    static const char kBoxedValueType = 'B';
    static const char kSequence = 'Q';
    static const char kVariadic = 'V';
    // Misc.
    static const char kInterface = 'I';
    static const char kExtends = 'X';
    static const char kConstant = 'C';
    static const char kOperation = 'F';
    static const char kGetter = 'S';
    static const char kSetter = 'G';
    static const char kConstructor = 'N';
    static const char kException = 'E';
    static const char kRaises = 'R';
    // Obsolete
    static const char kArray = 'Y';
    static const char kPointer = 'p';

    static bool isParam(const char* info)
    {
        switch (*info)
        {
        case kBoolean:
        case kOctet:
        case kShort:
        case kUnsignedShort:
        case kLong:
        case kUnsignedLong:
        case kLongLong:
        case kUnsignedLongLong:
        case kFloat:
        case kDouble:
        case kString:
        case kAny:
        case kObject:
        case kBoxedValueType:
        case kSequence:
        case kVariadic:
        case kArray:
            return true;
        default:
            return false;
        }
    }

    static const char* skipDigits(const char* info, unsigned* value = 0)
    {
        unsigned n = 0;
        while (std::isdigit(*info))
        {
            n = 10 * n + (*info - '0');
            ++info;
        }
        if (value)
        {
            *value = n;
        }
        return info;
    }

    static const char* skipName(const char* info)
    {
        unsigned length;
        info = skipDigits(info, &length);
        return info + length;
    }

    static const char* skipType(const char* info)
    {
        switch (*info)
        {
        case kVoid:
        case kBoolean:
        case kOctet:
        case kShort:
        case kUnsignedShort:
        case kLong:
        case kUnsignedLong:
        case kLongLong:
        case kUnsignedLongLong:
        case kFloat:
        case kDouble:
        case kString:
        case kAny:
            return ++info;
        case kBoxedValueType:
        case kSequence:
        case kVariadic:
            return skipType(++info);
        case kObject:
            return skipName(++info);
        case kArray:
            return skipType(skipDigits(++info));
        default:
            return 0;
        }
    }

    /**
     * This represents a type record from the specified reflection data.<commit_msg>(skipType) : Check kPointer.<commit_after>/*
 * Copyright 2008, 2009 Google Inc.
 * Copyright 2006, 2007 Nintendo Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF Any KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef GOOGLE_ESIDL_REFLECT_H_INCLUDED
#define GOOGLE_ESIDL_REFLECT_H_INCLUDED

#include <cctype>
#include <cstring>
#include <cstdlib>
#include <string>

/**
 * This class provides access to the string-encoded interface meta-data.
 *
 *  ws -> ' '
 *  name -> digits identifier  // digits represents the # of characters in the identifier
 *
 *  interface ->
 *    I name
 *    extends*
 *    [ operation, setter, getter, constructor, constant ]*
 *
 *  extends -> X name
 *  operation -> F digits type name (type name)* raises*   // digits represent the # of parameters
 *  setter -> S 1 v name type raises*
 *  getter -> G 0 type name raises*
 *  constructor -> N digits type name (type name)* raises* // digits represent the # of parameters
 *  constant  -> C name value ws  // value represents a double value parseable by strtold()
 *
 *  type ->
 *    A: any
 *    D: DOMString
 *    Q type: sequence<type>
 *    O name: Object
 *    B type: Boxed valuetype
 *    V type: [Variadic] in type
 *    v: void
 *    b: boolean
 *    h: octet
 *    s: short
 *    t: unsigned short
 *    l: long
 *    m: unsigned long
 *    x: long long
 *    y: unsigned long long
 *    f: float
 *    d: double
 *    p: void*                              // XXX To be unsupported
 *    YnT: array of n elements of type T    // XXX To be unsupported
 *
 *  raises ->
 *    R name
 *
 *  TODO: embed other extended attributes in the meta-data.
 */
class Reflect
{
public:
    // Type
    static const char kVoid = 'v';
    static const char kBoolean = 'b';
    static const char kOctet = 'h';
    static const char kShort = 's';
    static const char kUnsignedShort = 't';
    static const char kLong = 'l';
    static const char kUnsignedLong = 'm';
    static const char kLongLong = 'x';
    static const char kUnsignedLongLong = 'y';
    static const char kFloat = 'f';
    static const char kDouble = 'd';
    static const char kString = 'D';
    static const char kAny = 'A';
    static const char kObject = 'O';
    static const char kBoxedValueType = 'B';
    static const char kSequence = 'Q';
    static const char kVariadic = 'V';
    // Misc.
    static const char kInterface = 'I';
    static const char kExtends = 'X';
    static const char kConstant = 'C';
    static const char kOperation = 'F';
    static const char kGetter = 'S';
    static const char kSetter = 'G';
    static const char kConstructor = 'N';
    static const char kException = 'E';
    static const char kRaises = 'R';
    // Obsolete
    static const char kArray = 'Y';
    static const char kPointer = 'p';

    static bool isParam(const char* info)
    {
        switch (*info)
        {
        case kBoolean:
        case kOctet:
        case kShort:
        case kUnsignedShort:
        case kLong:
        case kUnsignedLong:
        case kLongLong:
        case kUnsignedLongLong:
        case kFloat:
        case kDouble:
        case kString:
        case kAny:
        case kObject:
        case kBoxedValueType:
        case kSequence:
        case kVariadic:
        case kArray:
            return true;
        default:
            return false;
        }
    }

    static const char* skipDigits(const char* info, unsigned* value = 0)
    {
        unsigned n = 0;
        while (std::isdigit(*info))
        {
            n = 10 * n + (*info - '0');
            ++info;
        }
        if (value)
        {
            *value = n;
        }
        return info;
    }

    static const char* skipName(const char* info)
    {
        unsigned length;
        info = skipDigits(info, &length);
        return info + length;
    }

    static const char* skipType(const char* info)
    {
        switch (*info)
        {
        case kVoid:
        case kBoolean:
        case kOctet:
        case kShort:
        case kUnsignedShort:
        case kLong:
        case kUnsignedLong:
        case kLongLong:
        case kUnsignedLongLong:
        case kFloat:
        case kDouble:
        case kString:
        case kAny:
        case kPointer:
            return ++info;
        case kBoxedValueType:
        case kSequence:
        case kVariadic:
            return skipType(++info);
        case kObject:
            return skipName(++info);
        case kArray:
            return skipType(skipDigits(++info));
        default:
            return 0;
        }
    }

    /**
     * This represents a type record from the specified reflection data.
{'fraction_non_alphanumeric': 0.09134521245349521, 'fraction_numerical': 0.005482670843939691, 'mean_word_length': 2.0284613104061666, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1515032', 'n_tokens_mistral': 3048, 'n_tokens_neox': 2957, 'n_words': 1123}