#include "src/torque/torque-parser.h"
#include <algorithm>
#include <cctype>
#include <optional>
#include <set>
#include <stdexcept>
#include <unordered_map>
#include "include/v8config.h"
#include "src/common/globals.h"
#include "src/flags/flags.h"
#include "src/torque/ast.h"
#include "src/torque/constants.h"
#include "src/torque/declarations.h"
#include "src/torque/earley-parser.h"
#include "src/torque/global-context.h"
#include "src/torque/utils.h"
namespace v8::internal::torque {
TypeList;
struct ExpressionWithSource { … };
struct TypeswitchCase { … };
struct EnumEntry { … };
class BuildFlags : public base::ContextualClass<BuildFlags> { … };
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<std::string>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<bool>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<int32_t>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<double>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<IntegerLiteral>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<std::string>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<Declaration*>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<TypeExpression*>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::optional<TypeExpression*>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<TryHandler*>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<Expression*>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<Identifier*>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::optional<Identifier*>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<Statement*>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<NameAndTypeExpression>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<EnumEntry>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<EnumEntry>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<NameAndExpression>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<Annotation>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<Annotation>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<AnnotationParameter>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::optional<AnnotationParameter>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<ClassFieldExpression>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<StructFieldExpression>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<BitFieldDeclaration>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<NameAndTypeExpression>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<ImplicitParameters>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::optional<ImplicitParameters>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<NameAndExpression>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<ClassFieldExpression>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<StructFieldExpression>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<BitFieldDeclaration>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<IncrementDecrementOperator>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::optional<std::string>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<Statement*>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<Declaration*>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<std::vector<Declaration*>>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<Expression*>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<ExpressionWithSource>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<ParameterList>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<TypeList>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::optional<TypeList>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId ParseResultHolder<LabelAndTypes>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<LabelAndTypes>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<TryHandler*>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::optional<Statement*>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::optional<Expression*>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<TypeswitchCase>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<TypeswitchCase>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<Identifier*>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::optional<ClassBody*>>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<GenericParameter>::id = …;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<GenericParameters>::id = …;
namespace {
bool ProcessIfAnnotation(ParseResultIterator* child_results);
std::optional<ParseResult> AddGlobalDeclarations(
ParseResultIterator* child_results) { … }
void NamingConventionError(const std::string& type, const std::string& name,
const std::string& convention,
SourcePosition pos = CurrentSourcePosition::Get()) { … }
void NamingConventionError(const std::string& type, const Identifier* name,
const std::string& convention) { … }
void LintGenericParameters(const GenericParameters& parameters) { … }
std::optional<ParseResult> ConcatList(ParseResultIterator* child_results) { … }
void CheckNotDeferredStatement(Statement* statement) { … }
TypeExpression* AddConstexpr(TypeExpression* type) { … }
Expression* MakeCall(IdentifierExpression* callee,
std::optional<Expression*> target,
std::vector<Expression*> arguments,
const std::vector<Statement*>& otherwise) { … }
Expression* MakeCall(Identifier* callee,
const std::vector<TypeExpression*>& generic_arguments,
const std::vector<Expression*>& arguments,
const std::vector<Statement*>& otherwise) { … }
std::optional<ParseResult> MakeCall(ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeMethodCall(ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeNewExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeBinaryOperator(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeIntrinsicCallExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeUnaryOperator(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeSpreadExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeImplicitParameterList(
ParseResultIterator* child_results) { … }
void AddParameter(ParameterList* parameter_list,
const NameAndTypeExpression& param) { … }
template <bool has_varargs, bool has_explicit_parameter_names>
std::optional<ParseResult> MakeParameterList(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeAssertStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeDebugStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> DeprecatedMakeVoidType(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeExternalMacro(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeIntrinsicDeclaration(
ParseResultIterator* child_results) { … }
namespace {
bool HasAnnotation(ParseResultIterator* child_results, const char* annotation,
const char* declaration) { … }
bool HasExportAnnotation(ParseResultIterator* child_results,
const char* declaration) { … }
}
std::optional<ParseResult> MakeTorqueMacroDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeConstDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeExternConstDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeTypeAliasDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeAbstractTypeDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeMethodDeclaration(
ParseResultIterator* child_results) { … }
class AnnotationSet { … };
bool ProcessIfAnnotation(ParseResultIterator* child_results) { … }
std::optional<ParseResult> YieldInt32(ParseResultIterator* child_results) { … }
std::optional<ParseResult> YieldDouble(ParseResultIterator* child_results) { … }
std::optional<ParseResult> YieldIntegerLiteral(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeStringAnnotationParameter(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeIntAnnotationParameter(
ParseResultIterator* child_results) { … }
int GetAnnotationValue(const AnnotationSet& annotations, const char* name,
int default_value) { … }
std::optional<ParseResult> MakeTorqueBuiltinDeclaration(
ParseResultIterator* child_results) { … }
InstanceTypeConstraints MakeInstanceTypeConstraints(
const AnnotationSet& annotations) { … }
std::optional<ParseResult> MakeClassBody(ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeClassDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeNamespaceDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeSpecializationDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeStructDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeBitFieldStructDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeCppIncludeDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> ProcessTorqueImportDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeExternalBuiltin(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeExternalRuntime(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> StringLiteralUnquoteAction(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeBasicTypeExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeFunctionTypeExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeReferenceTypeExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeUnionTypeExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeGenericParameter(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeExpressionStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeIfStatement(ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeEnumDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeTypeswitchStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeTypeswitchCase(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeWhileStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeReturnStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeTailCallStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeVarDeclarationStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeBreakStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeContinueStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeGotoStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeBlockStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeTryLabelExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeForLoopStatement(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeLabelBlock(ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeCatchBlock(ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeExpressionWithSource(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeIdentifier(ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeIdentifierFromMatchedInput(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeRightShiftIdentifier(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeNamespaceQualification(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeIdentifierExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeFieldAccessExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeReferenceFieldAccessExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeElementAccessExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeDereferenceExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeStructExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeAssignmentExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeFloatingPointLiteralExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeIntegerLiteralExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeStringLiteralExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeIncrementDecrementExpressionPostfix(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeIncrementDecrementExpressionPrefix(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeLogicalOrExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeLogicalAndExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeConditionalExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeLabelAndTypes(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeNameAndType(ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeEnumEntry(ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeNameAndExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeNameAndExpressionFromExpression(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeAnnotation(ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeClassField(ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeStructField(ParseResultIterator* child_results) { … }
std::optional<ParseResult> MakeBitFieldDeclaration(
ParseResultIterator* child_results) { … }
std::optional<ParseResult> ExtractAssignmentOperator(
ParseResultIterator* child_results) { … }
struct TorqueGrammar : Grammar { … };
}
void ParseTorque(const std::string& input) { … }
}