Lines Matching refs:ir
21 #include <ir/astNode.h>
22 #include <ir/base/methodDefinition.h>
46 namespace panda::es2panda::ir {
121 } // namespace panda::es2panda::ir
130 ir::MethodDefinitionKind methodKind {};
132 ir::ModifierFlags modifiers {};
147 explicit ArrowFunctionDescriptor(ArenaVector<ir::Expression *> &&p, binder::FunctionParamScope *ps,
153 ArenaVector<ir::Expression *> params;
207 ir::Expression* SetupChainExpr(ir::Expression *const top, lexer::SourcePosition startLoc);
210 [[noreturn]] void ThrowParameterModifierError(ir::ModifierFlags status) const;
241 void AddCommonjsParams(ArenaVector<ir::Expression *> ¶ms);
242 void AddReflectApplyArgs(ArenaVector<ir::Expression *> &args, ir::FunctionExpression *wrapper);
244 bool CheckTopStatementsForRequiredDeclare(const ArenaVector<ir::Statement *> &statements);
251 static bool IsPropertyKeysAreSame(const ir::Expression *exp1, const ir::Expression *exp2);
252 static bool IsMemberExpressionsAreSame(const ir::MemberExpression *mExp1, const ir::MemberExpression *mExp2);
253 static bool IsMethodDefinitionsAreSame(const ir::MethodDefinition *property, ir::MethodDefinition *overload);
254 ir::TSTypeReference *ParseTsConstExpression();
255 ir::Expression *ParseTsTypeOperatorOrTypeReference(bool throwError);
256 ir::Expression *ParseTsIdentifierReference(TypeAnnotationParsingOptions options);
257 ir::Expression *ParseTsBasicType(TypeAnnotationParsingOptions options);
258 ir::TSIntersectionType *ParseTsIntersectionType(ir::Expression *type, bool inUnion, bool restrictExtends,
260 ir::TSUnionType *ParseTsUnionType(ir::Expression *type, bool restrictExtends, bool throwError);
261 ir::Expression *ParseTsParenthesizedOrFunctionType(ir::Expression *typeAnnotation, bool throwError);
262 ir::TSArrayType *ParseTsArrayType(ir::Expression *elementType);
264 ir::Expression *ParseTsFunctionType(lexer::SourcePosition startLoc, bool isConstructionType, bool throwError,
266 ir::TSTypeParameter *ParseTsMappedTypeParameter();
267 ir::MappedOption ParseMappedOption(lexer::TokenType tokenType);
268 ir::TSMappedType *ParseTsMappedType();
269 ir::TSTypePredicate *ParseTsTypePredicate();
271 ir::Expression *ParseTsTypeLiteralOrInterfaceKey(bool *computed, bool *signature, bool *isIndexSignature);
272 void ValidateIndexSignatureParameterType(ir::Expression *typeAnnotation);
273 ir::Expression *ParseTsConditionalType(ir::Expression *checkType, bool restrictExtends);
274 ir::Expression *ParseTsTypeLiteralOrInterfaceMember();
275 ArenaVector<ir::Expression *> ParseTsTypeLiteralOrInterface();
276 ir::Expression *ParseTsThisType(bool throwError);
277 ir::Expression *ParseTsIndexAccessType(ir::Expression *typeName, bool throwError);
278 ir::Expression *ParseTsQualifiedReference(ir::Expression *typeName);
279 ir::Expression *ParseTsTypeReferenceOrQuery(TypeAnnotationParsingOptions options, bool parseQuery = false);
281 void HandleRestType(ir::AstNodeType elementType, bool *hasRestType) const;
282 ir::Expression *ParseTsTupleElement(ir::TSTupleKind *kind, bool *seenOptional, bool *hasRestType);
283 ir::TSTupleType *ParseTsTupleType();
284 ir::TSImportType *ParseTsImportType(const lexer::SourcePosition &startLoc, bool isTypeof = false);
285 ir::Expression *ParseTsTypeAnnotation(TypeAnnotationParsingOptions *options);
286 ir::Expression *ParseTsTypeLiteralOrTsMappedType(ir::Expression *typeAnnotation);
287 ir::Expression *ParseTsTypeReferenceOrTsTypePredicate(ir::Expression *typeAnnotation, bool canBeTsTypePredicate,
289 ir::Expression *ParseTsThisTypeOrTsTypePredicate(ir::Expression *typeAnnotation, bool canBeTsTypePredicate,
291 ir::Expression *ParseTsTemplateLiteralType(bool throwError);
292 ir::Expression *ParseTsTypeAnnotationElement(ir::Expression *typeAnnotation, TypeAnnotationParsingOptions *options);
293 ir::ModifierFlags ParseModifiers();
298 void ValidateClassMethodStart(ClassElmentDescriptor *desc, ir::Expression *typeAnnotation);
299 ir::Expression *ParseClassKey(ClassElmentDescriptor *desc, bool isDeclare);
301 void ValidateClassSetter(ClassElmentDescriptor *desc, const ArenaVector<ir::Statement *> &properties,
302 ir::Expression *propName, ir::ScriptFunction *func, bool hasDecorator,
304 void ValidateClassGetter(ClassElmentDescriptor *desc, const ArenaVector<ir::Statement *> &properties,
305 ir::Expression *propName, ir::ScriptFunction *func, bool hasDecorator,
307 void ValidatePrivateProperty(ir::Statement *stmt, std::unordered_set<util::StringView> &privateNames,
309 ir::MethodDefinition *ParseClassMethod(ClassElmentDescriptor *desc, const ArenaVector<ir::Statement *> &properties,
310 ir::Expression *propName, lexer::SourcePosition *propEnd,
311 ArenaVector<ir::Decorator *> &&decorators,
312 ArenaVector<ir::Annotation *> &&annotations, bool isDeclare);
313 ir::ClassStaticBlock *ParseStaticBlock(ClassElmentDescriptor *desc);
314 ir::Statement *ParseClassProperty(ClassElmentDescriptor *desc, const ArenaVector<ir::Statement *> &properties,
315 ir::Expression *propName, ir::Expression *typeAnnotation,
316 ArenaVector<ir::Decorator *> &&decorators,
317 ArenaVector<ir::Annotation *> &&annotations, bool isDeclare,
322 void CheckFieldKey(ir::Expression *propName);
323 ir::Expression *ParseClassKeyAnnotation();
324 ir::Statement *ParseDecoratorAndAnnotation();
325 std::pair<ArenaVector<ir::Decorator *>, ArenaVector<ir::Annotation *>> ParseDecoratorsAndAnnotations();
326 ir::Statement *ParseClassElement(const ArenaVector<ir::Statement *> &properties,
327 ArenaVector<ir::TSIndexSignature *> *indexSignatures, bool hasSuperClass,
330 ir::Identifier *GetKeyByFuncFlag(ir::ScriptFunctionFlags funcFlag);
331 ir::MethodDefinition *CreateImplicitMethod(ir::Expression *superClass, bool hasSuperClass,
332 ir::ScriptFunctionFlags funcFlag, bool isDeclare = false);
333 ir::MethodDefinition *CheckClassMethodOverload(ir::Statement *property, ir::MethodDefinition **ctor, bool isDeclare,
334 lexer::SourcePosition errorInfo, ir::MethodDefinition *lastOverload,
336 ir::Identifier *SetIdentNodeInClassDefinition(bool isDeclare, binder::ConstDecl **decl);
337 ir::ClassDefinition *ParseClassDefinition(bool isDeclaration, bool idRequired = true, bool isDeclare = false,
339 ir::Expression *ParseSuperClass(bool isDeclare, bool *hasSuperClass, bool *isExtendsFromNull);
340 ArenaVector<ir::TSClassImplements *> ParseTSClassImplements(bool isDeclare);
341 void ValidateClassConstructor(const ir::MethodDefinition *ctor,
342 const ArenaVector<ir::Statement *> &properties,
345 void FindSuperCall(const ir::AstNode *parent, bool *hasSuperCall);
346 void FindSuperCallInCtorChildNode(const ir::AstNode *childNode, bool *hasSuperCall);
347 bool SuperCallShouldBeRootLevel(const ir::MethodDefinition *ctor, const ArenaVector<ir::Statement *> &properties);
348 void ValidateSuperCallLocation(const ir::MethodDefinition *ctor, bool superCallShouldBeRootLevel);
349 void FindThisOrSuperReference(const ir::AstNode *parent, bool *hasThisOrSuperReference);
350 void FindThisOrSuperReferenceInChildNode(const ir::AstNode *childNode, bool *hasThisOrSuperReference);
353 ir::Property *ParseShorthandProperty(const lexer::LexerPosition *startPos);
355 bool ParsePropertyModifiers(ExpressionParseFlags flags, ir::PropertyKind *propertyKind, ParserStatus *methodStatus);
356 ir::Expression *ParsePropertyKey(ExpressionParseFlags flags);
357 ir::Expression *ParsePropertyValue(const ir::PropertyKind *propertyKind, const ParserStatus *methodStatus,
361 ir::Expression *ParsePostfixTypeOrHigher(ir::Expression *typeAnnotation, TypeAnnotationParsingOptions *options);
362 ir::Expression *TryParseConstraintOfInferType(TypeAnnotationParsingOptions *options);
363 ir::Expression *ParsePropertyDefinition(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS);
366 ir::TSTypeParameter *ParseTsTypeParameter(bool throwError, bool addBinding = false, bool isAllowInOut = false);
367 ir::TSTypeParameterDeclaration *ParseTsTypeParameterDeclaration(bool throwError = true, bool isAllowInOut = false);
368 ir::TSTypeParameterInstantiation *ParseTsTypeParameterInstantiation(bool throwError = true);
369 ir::ScriptFunction *ParseFunction(ParserStatus newStatus = ParserStatus::NO_OPTS,
371 ArenaVector<ir::ParamDecorators> *paramDecorators = nullptr);
372 void ValidateFunctionParam(const ArenaVector<ir::Expression *> ¶ms, const ir::Expression *parameter,
374 void ValidateTsFunctionOverloadParams(const ArenaVector<ir::Expression *> ¶ms);
375 void CheckAccessorPair(const ArenaVector<ir::Statement *> &properties, const ir::Expression *propName,
376 ir::MethodDefinitionKind methodKind, ir::ModifierFlags access, bool hasDecorator,
378 ArenaVector<ir::Expression *> ParseFunctionParams(bool isDeclare = false,
379 ArenaVector<ir::ParamDecorators> *paramDecorators = nullptr);
380 ir::SpreadElement *ParseSpreadElement(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS);
381 ir::TSParameterProperty *CreateTsParameterProperty(ir::Expression *parameter, ir::ModifierFlags modifiers);
382 ir::Expression *ParseFunctionParameter(bool isDeclare);
383 void CreateTSVariableForProperty(ir::AstNode *node, const ir::Expression *key, binder::VariableFlags flags);
384 void CheckObjectTypeForDuplicatedProperties(ir::Expression *member, ArenaVector<ir::Expression *> const &members);
388 ir::Expression *ParseExpression(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS);
389 ir::ArrowFunctionExpression *ParseTsGenericArrowFunction();
390 ir::TSTypeAssertion *ParseTsTypeAssertion(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS);
391 ir::TSAsExpression *ParseTsAsExpression(ir::Expression *expr, ExpressionParseFlags flags);
392 ir::TSSatisfiesExpression *ParseTsSatisfiesExpression(ir::Expression *expr);
393 ir::Expression *ParseArrayExpression(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS);
394 ir::YieldExpression *ParseYieldExpression();
395 ir::Expression *ParsePotentialExpressionSequence(ir::Expression *expr, ExpressionParseFlags flags);
396 ParserStatus ValidateArrowParameter(ir::Expression *expr);
398 ArrowFunctionDescriptor ConvertToArrowParameter(ir::Expression *expr, bool isAsync,
400 ir::ArrowFunctionExpression *ParseArrowFunctionExpressionBody(ArrowFunctionContext *arrowFunctionContext,
403 ir::TSTypeParameterDeclaration *typeParamDecl,
404 ir::Expression *returnTypeAnnotation);
405 ir::ArrowFunctionExpression *ParseArrowFunctionExpression(ir::Expression *expr,
406 ir::TSTypeParameterDeclaration *typeParamDecl,
407 ir::Expression *returnTypeAnnotation, bool isAsync);
408 ir::Expression *ParseCoverParenthesizedExpressionAndArrowParameterList();
409 ir::Expression *ParseKeywordExpression();
410 ir::Expression *ParseBinaryExpression(ir::Expression *left);
411 ir::CallExpression *ParseCallExpression(ir::Expression *callee, bool isOptionalChain = false, bool isAsync = false);
412 ir::ArrowFunctionExpression *ParsePotentialArrowExpression(ir::Expression **returnExpression,
416 void ValidateUpdateExpression(ir::Expression *returnExpression, bool isChainExpression);
418 bool ParsePotentialTsGenericFunctionCall(ir::Expression **returnExpression, const lexer::SourcePosition &startLoc,
420 ir::Expression *ParsePostPrimaryExpression(ir::Expression *primaryExpr, lexer::SourcePosition startLoc,
422 ir::Expression *ParseMemberExpression(bool ignoreCallExpression = false,
424 ir::ObjectExpression *ParseObjectExpression(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS);
425 ir::SequenceExpression *ParseSequenceExpression(ir::Expression *startExpr, bool acceptRest = false,
427 ir::Expression *ParseUnaryOrPrefixUpdateExpression(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS);
428 ir::Expression *ParseLeftHandSideExpression(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS);
429 ir::MetaProperty *ParsePotentialNewTarget();
430 void CheckInvalidDestructuring(const ir::AstNode *object) const;
431 void ValidateParenthesizedExpression(ir::Expression *lhsExpression);
432 ir::Expression *ParseAssignmentExpression(ir::Expression *lhsExpression,
434 ir::Expression *ParsePrimaryExpression(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS);
435 ir::NewExpression *ParseNewExpression();
436 void ParsePotentialTsFunctionParameter(ExpressionParseFlags flags, ir::Expression *returnNode,
438 ir::Expression *ParsePatternElement(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS,
440 ir::TemplateLiteral *ParseTemplateLiteral(bool isTaggedTemplate = false);
441 ir::Expression *ParseImportExpression();
442 ir::ObjectExpression *ParseImportAssertionForDynamicImport();
443 void ValidateImportAssertionForDynamicImport(ir::ObjectExpression *importAssertion);
444 ir::AssertClause *ParseAssertClause();
445 ir::AssertEntry *ParseAssertEntry();
446 ir::FunctionExpression *ParseFunctionExpression(ParserStatus newStatus = ParserStatus::NO_OPTS);
447 ir::Expression *ParseOptionalChain(ir::Expression *leftSideExpr);
448 ir::Expression *ParseOptionalMemberExpression(ir::Expression *object);
449 void ParseNameSpaceImport(ArenaVector<ir::AstNode *> *specifiers, bool isType);
450 ir::Identifier *ParseNamedImport(const lexer::Token &importedToken);
456 ir::StringLiteral *ParseFromClause(bool requireFrom = true);
457 void ParseNamedImportSpecifiers(ArenaVector<ir::AstNode *> *specifiers, bool isType, bool isLazy);
459 ir::Expression *ParseModuleReference();
460 ir::AstNode *ParseImportDefaultSpecifier(ArenaVector<ir::AstNode *> *specifiers, bool isType);
461 ir::AstNode *ParseImportSpecifiers(ArenaVector<ir::AstNode *> *specifiers, bool isType, bool isLazy);
462 void ValidateAssignmentTarget(ExpressionParseFlags flags, ir::Expression *node);
463 void ValidateLvalueAssignmentTarget(ir::Expression *node) const;
464 void ValidateArrowParameterBindings(const ir::Expression *node);
466 ir::ExportDefaultDeclaration *ParseExportDefaultDeclaration(const lexer::SourcePosition &startLoc,
467 ArenaVector<ir::Decorator *> decorators,
468 ArenaVector<ir::Annotation *> annotations,
470 ir::ExportAllDeclaration *ParseExportAllDeclaration(const lexer::SourcePosition &startLoc);
471 ir::ExportNamedDeclaration *ParseExportNamedSpecifiers(const lexer::SourcePosition &startLoc, bool isType);
472 ir::ExportNamedDeclaration *ParseNamedExportDeclaration(const lexer::SourcePosition &startLoc,
473 ArenaVector<ir::Decorator *> &&decorators,
474 ArenaVector<ir::Annotation *> &&annotations);
475 ir::Identifier *ParseNamedExport(const lexer::Token &exportedToken);
477 ir::PrivateIdentifier *ParsePrivateIdentifier();
481 ir::Expression *DoOutsideOfDisallowConditinalTypesContext(Function func, Args &&... args);
485 ir::Expression *DoInsideOfDisallowConditinalTypesContext(Function func, Args &&... args);
493 void ConsumeSemicolon(ir::Statement *statement);
496 void CheckLabelledFunction(const ir::Statement *node);
501 void AddImportEntryItem(const ir::StringLiteral *source, const ArenaVector<ir::AstNode *> *specifiers, bool isType,
503 void AddImportEntryItemForImportSpecifier(const ir::StringLiteral *source, const ir::AstNode *specifier,
505 void AddImportEntryItemForImportDefaultOrNamespaceSpecifier(const ir::StringLiteral *source,
506 const ir::AstNode *specifier, bool isType);
507 void AddExportNamedEntryItem(const ArenaVector<ir::ExportSpecifier *> &specifiers,
508 const ir::StringLiteral *source, bool isType);
509 void AddExportStarEntryItem(const lexer::SourcePosition &startLoc, const ir::StringLiteral *source,
510 const ir::Identifier *exported);
511 void AddExportDefaultEntryItem(const ir::AstNode *declNode);
512 void AddExportLocalEntryItem(const ir::Statement *declNode, bool isTsModule);
513 void AddTsTypeExportLocalEntryItem(const ir::Statement *declNode, bool isTsModule,
518 bool ParseDirective(ArenaVector<ir::Statement *> *statements);
519 void ParseDirectivePrologue(ArenaVector<ir::Statement *> *statements);
520 ArenaVector<ir::Statement *> ParseStatementList(StatementParsingFlags flags = StatementParsingFlags::ALLOW_LEXICAL);
522 ir::Statement *ParseStatement(StatementParsingFlags flags = StatementParsingFlags::NONE);
523 ir::TSModuleDeclaration *ParseTsModuleDeclaration(bool isDeclare, bool isExport = false);
524 ir::TSModuleDeclaration *ParseTsAmbientExternalModuleDeclaration(const lexer::SourcePosition &startLoc,
526 ir::TSModuleDeclaration *ParseTsModuleOrNamespaceDelaration(const lexer::SourcePosition &startLoc,
529 bool IsInstantiatedInTsModuleBlock(ir::Statement **body);
531 ir::TSImportEqualsDeclaration *ParseTsImportEqualsDeclaration(const lexer::SourcePosition &startLoc,
533 ir::TSNamespaceExportDeclaration *ParseTsNamespaceExportDeclaration(const lexer::SourcePosition &startLoc);
534 ir::TSModuleBlock *ParseTsModuleBlock();
535 ir::BlockStatement *ParseFunctionBody();
536 ir::BlockStatement *ParseBlockStatement();
537 ir::BlockStatement *ParseBlockStatement(binder::Scope *scope);
538 ir::EmptyStatement *ParseEmptyStatement();
539 ir::DebuggerStatement *ParseDebuggerStatement();
540 ir::BreakStatement *ParseBreakStatement();
541 ir::ContinueStatement *ParseContinueStatement();
542 ir::DoWhileStatement *ParseDoWhileStatement();
543 ir::Statement *ParsePotentialExpressionStatement(StatementParsingFlags flags, bool isDeclare);
544 ir::Statement *ParseVarStatement(bool isDeclare);
545 ir::Statement *ParseLetStatement(StatementParsingFlags flags, bool isDeclare);
546 ir::Statement *ParseConstStatement(StatementParsingFlags flags, bool isDeclare);
547 ir::Statement *ParseExpressionStatement(StatementParsingFlags flags = StatementParsingFlags::NONE);
548 ir::Statement *ParseFunctionStatement(StatementParsingFlags flags, bool isDeclare);
549 ir::FunctionDeclaration *ParseFunctionDeclaration(bool canBeAnonymous = false,
552 void AddFunctionToBinder(ir::ScriptFunction *func, ParserStatus newStatus);
553 void CheckOptionalBindingPatternParameter(ir::ScriptFunction *func) const;
554 ir::Statement *ParseExportDeclaration(StatementParsingFlags flags, ArenaVector<ir::Decorator *> &&decorators,
555 ArenaVector<ir::Annotation *> &&annotations);
556 std::tuple<ForStatementKind, ir::AstNode *, ir::Expression *, ir::Expression *> ParseForInOf(
557 ir::Expression *leftNode, ExpressionParseFlags exprFlags, bool isAwait);
558 std::tuple<ForStatementKind, ir::Expression *, ir::Expression *> ParseForInOf(ir::AstNode *initNode,
561 std::tuple<ir::Expression *, ir::Expression *> ParseForUpdate(bool isAwait);
562 ir::Statement *ParseForStatement();
563 ir::IfStatement *ParseIfStatement();
565 ir::Statement *ParseImportDeclaration(StatementParsingFlags flags);
566 ir::LabelledStatement *ParseLabelledStatement(const lexer::LexerPosition &pos);
567 ir::ReturnStatement *ParseReturnStatement();
568 ir::ClassDeclaration *ParseClassStatement(StatementParsingFlags flags, bool isDeclare,
569 ArenaVector<ir::Decorator *> &&decorators,
570 ArenaVector<ir::Annotation *> &&annotations, bool isAbstract = false);
571 ir::ClassDeclaration *ParseClassDeclaration(bool idRequired, ArenaVector<ir::Decorator *> &&decorators,
572 ArenaVector<ir::Annotation *> &&annotations, bool isDeclare = false,
575 ir::TSTypeAliasDeclaration *ParseTsTypeAliasDeclaration(bool isDeclare);
576 ir::Expression *ParseEnumComputedPropertyKey(binder::EnumDecl *&decl, const lexer::SourcePosition &keyStartLoc,
578 ir::TSEnumDeclaration *ParseEnumMembers(ir::Identifier *key, const lexer::SourcePosition &enumStart,
580 ir::TSEnumDeclaration *ParseEnumDeclaration(bool isExport = false, bool isDeclare = false, bool isConst = false);
581 ir::TSInterfaceDeclaration *ParseTsInterfaceDeclaration(bool isDeclare);
583 ArenaVector<ir::TSInterfaceHeritage *> ParseTsInterfaceExtends();
584 ir::SwitchCaseStatement *ParseSwitchCaseStatement(bool *seenDefault);
585 ir::SwitchStatement *ParseSwitchStatement();
586 ir::ThrowStatement *ParseThrowStatement();
587 ir::Expression *ParseCatchParam();
588 ir::CatchClause *ParseCatchClause();
589 ir::TryStatement *ParseTryStatement();
591 ir::VariableDeclarator *ParseVariableDeclaratorInitializer(ir::Expression *init, VariableParsingFlags flags,
593 ir::VariableDeclarator *ParseVariableDeclarator(VariableParsingFlags flags, bool isDeclare);
594 ir::Expression *ParseVariableDeclaratorKey(VariableParsingFlags flags, bool isDeclare, bool *isDefinite);
595 ir::Statement *ParseVariableDeclaration(VariableParsingFlags flags = VariableParsingFlags::NO_OPTS,
597 ir::WhileStatement *ParseWhileStatement();
598 ir::VariableDeclaration *ParseContextualLet(VariableParsingFlags flags,
763 flags_ |= ir::ScriptFunctionFlags::GENERATOR;
767 flags_ |= ir::ScriptFunctionFlags::ASYNC;
771 flags_ |= ir::ScriptFunctionFlags::CONSTRUCTOR;
775 ir::ScriptFunctionFlags Flags() const
780 void AddFlag(ir::ScriptFunctionFlags flags)
790 ir::ScriptFunctionFlags flags_ {ir::ScriptFunctionFlags::NONE};
799 AddFlag(ir::ScriptFunctionFlags::ASYNC);
802 AddFlag(ir::ScriptFunctionFlags::ARROW);