chromium/v8/src/torque/types.h

// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_TORQUE_TYPES_H_
#define V8_TORQUE_TYPES_H_

#include <algorithm>
#include <optional>
#include <set>
#include <string>
#include <vector>

#include "src/torque/ast.h"
#include "src/torque/constants.h"
#include "src/torque/source-positions.h"
#include "src/torque/utils.h"

namespace v8::internal::torque {

class AggregateType;
struct Identifier;
class Macro;
class Method;
class GenericType;
class StructType;
class Type;
class ClassType;
class Value;
class Namespace;

class TypeBase {};

#define DECLARE_TYPE_BOILERPLATE(x)

TypeVector;

template <typename T>
struct SpecializationKey {};

MaybeSpecializationKey;

struct TypeChecker {};

class V8_EXPORT_PRIVATE Type : public TypeBase {};

inline size_t hash_value(const TypeVector& types) {}

struct NameAndType {};

std::ostream& operator<<(std::ostream& os, const NameAndType& name_and_type);

struct Field {};

std::ostream& operator<<(std::ostream& os, const Field& name_and_type);

class TopType final : public Type {};

class AbstractType final : public Type {};

// For now, builtin pointers are restricted to Torque-defined builtins.
class V8_EXPORT_PRIVATE BuiltinPointerType final : public Type {};

bool operator<(const Type& a, const Type& b);
struct TypeLess {};

class V8_EXPORT_PRIVATE UnionType final : public Type {};

const Type* SubtractType(const Type* a, const Type* b);

struct BitField {};

class V8_EXPORT_PRIVATE BitFieldStructType final : public Type {};

class AggregateType : public Type {};

class StructType final : public AggregateType {};

class TypeAlias;

enum class ObjectSlotKind : uint8_t {};

inline std::optional<ObjectSlotKind> Combine(ObjectSlotKind a,
                                             ObjectSlotKind b) {}

class ClassType final : public AggregateType {};

inline std::ostream& operator<<(std::ostream& os, const Type& t) {}

template <bool success = false>
std::ostream& operator<<(std::ostream& os, const Type* t) {}

// Don't emit an error if a Type* is printed due to CHECK macros.
inline std::ostream& operator<<(base::CheckMessageStream& os, const Type* t) {}

class VisitResult {};

VisitResult ProjectStructField(VisitResult structure,
                               const std::string& fieldname);

class VisitResultVector : public std::vector<VisitResult> {};

std::ostream& operator<<(std::ostream& os, const TypeVector& types);

NameAndTypeVector;

struct LabelDefinition {};

LabelDefinitionVector;

struct LabelDeclaration {};

LabelDeclarationVector;

struct ParameterTypes {};

std::ostream& operator<<(std::ostream& os, const ParameterTypes& parameters);

enum class ParameterMode {};

NameVector;

struct Signature {};

void PrintSignature(std::ostream& os, const Signature& sig, bool with_names);
std::ostream& operator<<(std::ostream& os, const Signature& sig);

bool IsAssignableFrom(const Type* to, const Type* from);

TypeVector LowerType(const Type* type);
size_t LoweredSlotCount(const Type* type);
TypeVector LowerParameterTypes(const TypeVector& parameters);
TypeVector LowerParameterTypes(const ParameterTypes& parameter_types,
                               size_t vararg_count = 0);

std::optional<std::tuple<size_t, std::string>> SizeOf(const Type* type);
bool IsAnyUnsignedInteger(const Type* type);
bool IsAllowedAsBitField(const Type* type);
bool IsPointerSizeIntegralType(const Type* type);
bool Is32BitIntegralType(const Type* type);

std::optional<NameAndType> ExtractSimpleFieldArraySize(
    const ClassType& class_type, Expression* array_size);

}  // namespace v8::internal::torque

#endif  // V8_TORQUE_TYPES_H_