1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQMLJSAST_P_H
41#define QQMLJSAST_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include "qqmljsastvisitor_p.h"
55#include "qqmljsglobal_p.h"
56
57#include <private/qqmljsmemorypool_p.h>
58
59#include <QtCore/qstring.h>
60
61QT_BEGIN_NAMESPACE
62
63#define QQMLJS_DECLARE_AST_NODE(name) \
64 enum { K = Kind_##name };
65
66namespace QSOperator // ### rename
67{
68
69enum Op {
70 Add,
71 And,
72 InplaceAnd,
73 Assign,
74 BitAnd,
75 BitOr,
76 BitXor,
77 InplaceSub,
78 Div,
79 InplaceDiv,
80 Equal,
81 Exp,
82 InplaceExp,
83 Ge,
84 Gt,
85 In,
86 InplaceAdd,
87 InstanceOf,
88 Le,
89 LShift,
90 InplaceLeftShift,
91 Lt,
92 Mod,
93 InplaceMod,
94 Mul,
95 InplaceMul,
96 NotEqual,
97 Or,
98 InplaceOr,
99 RShift,
100 InplaceRightShift,
101 StrictEqual,
102 StrictNotEqual,
103 Sub,
104 URShift,
105 InplaceURightShift,
106 InplaceXor,
107 As,
108 Coalesce,
109 Invalid
110};
111
112} // namespace QSOperator
113
114namespace QQmlJS {
115
116namespace AST {
117
118enum class VariableScope {
119 NoScope,
120 Var,
121 Let,
122 Const
123};
124
125template <typename T1, typename T2>
126T1 cast(T2 *ast)
127{
128 if (ast && ast->kind == static_cast<T1>(0)->K)
129 return static_cast<T1>(ast);
130
131 return 0;
132}
133
134FunctionExpression *asAnonymousFunctionDefinition(AST::Node *n);
135ClassExpression *asAnonymousClassDefinition(AST::Node *n);
136
137class QML_PARSER_EXPORT Node: public Managed
138{
139public:
140 enum Kind {
141 Kind_Undefined,
142
143 Kind_ArgumentList,
144 Kind_ArrayPattern,
145 Kind_ArrayMemberExpression,
146 Kind_BinaryExpression,
147 Kind_Block,
148 Kind_BreakStatement,
149 Kind_CallExpression,
150 Kind_CaseBlock,
151 Kind_CaseClause,
152 Kind_CaseClauses,
153 Kind_Catch,
154 Kind_ConditionalExpression,
155 Kind_ContinueStatement,
156 Kind_DebuggerStatement,
157 Kind_DefaultClause,
158 Kind_DeleteExpression,
159 Kind_DoWhileStatement,
160 Kind_ElementList,
161 Kind_Elision,
162 Kind_EmptyStatement,
163 Kind_Expression,
164 Kind_ExpressionStatement,
165 Kind_FalseLiteral,
166 Kind_SuperLiteral,
167 Kind_FieldMemberExpression,
168 Kind_Finally,
169 Kind_ForEachStatement,
170 Kind_ForStatement,
171 Kind_FormalParameterList,
172 Kind_FunctionBody,
173 Kind_FunctionDeclaration,
174 Kind_FunctionExpression,
175 Kind_ClassExpression,
176 Kind_ClassDeclaration,
177 Kind_IdentifierExpression,
178 Kind_IdentifierPropertyName,
179 Kind_ComputedPropertyName,
180 Kind_IfStatement,
181 Kind_LabelledStatement,
182 Kind_NameSpaceImport,
183 Kind_ImportSpecifier,
184 Kind_ImportsList,
185 Kind_NamedImports,
186 Kind_ImportClause,
187 Kind_FromClause,
188 Kind_ImportDeclaration,
189 Kind_Module,
190 Kind_ExportSpecifier,
191 Kind_ExportsList,
192 Kind_ExportClause,
193 Kind_ExportDeclaration,
194 Kind_NewExpression,
195 Kind_NewMemberExpression,
196 Kind_NotExpression,
197 Kind_NullExpression,
198 Kind_YieldExpression,
199 Kind_NumericLiteral,
200 Kind_NumericLiteralPropertyName,
201 Kind_ObjectPattern,
202 Kind_PostDecrementExpression,
203 Kind_PostIncrementExpression,
204 Kind_PreDecrementExpression,
205 Kind_PreIncrementExpression,
206 Kind_Program,
207 Kind_PropertyDefinitionList,
208 Kind_PropertyGetterSetter,
209 Kind_PropertyName,
210 Kind_PropertyNameAndValue,
211 Kind_RegExpLiteral,
212 Kind_ReturnStatement,
213 Kind_StatementList,
214 Kind_StringLiteral,
215 Kind_StringLiteralPropertyName,
216 Kind_SwitchStatement,
217 Kind_TemplateLiteral,
218 Kind_TaggedTemplate,
219 Kind_ThisExpression,
220 Kind_ThrowStatement,
221 Kind_TildeExpression,
222 Kind_TrueLiteral,
223 Kind_TryStatement,
224 Kind_TypeOfExpression,
225 Kind_UnaryMinusExpression,
226 Kind_UnaryPlusExpression,
227 Kind_VariableDeclaration,
228 Kind_VariableDeclarationList,
229 Kind_VariableStatement,
230 Kind_VoidExpression,
231 Kind_WhileStatement,
232 Kind_WithStatement,
233 Kind_NestedExpression,
234 Kind_ClassElementList,
235 Kind_PatternElement,
236 Kind_PatternElementList,
237 Kind_PatternProperty,
238 Kind_PatternPropertyList,
239 Kind_Type,
240 Kind_TypeArgumentList,
241 Kind_TypeAnnotation,
242
243 Kind_UiArrayBinding,
244 Kind_UiImport,
245 Kind_UiObjectBinding,
246 Kind_UiObjectDefinition,
247 Kind_UiInlineComponent,
248 Kind_UiObjectInitializer,
249 Kind_UiObjectMemberList,
250 Kind_UiArrayMemberList,
251 Kind_UiPragma,
252 Kind_UiProgram,
253 Kind_UiParameterList,
254 Kind_UiPublicMember,
255 Kind_UiQualifiedId,
256 Kind_UiScriptBinding,
257 Kind_UiSourceElement,
258 Kind_UiHeaderItemList,
259 Kind_UiEnumDeclaration,
260 Kind_UiEnumMemberList,
261 Kind_UiVersionSpecifier,
262 Kind_UiRequired,
263 Kind_UiAnnotation,
264 Kind_UiAnnotationList
265 };
266
267 inline Node() {}
268
269 // NOTE: node destructors are never called,
270 // instead we block free the memory
271 // (see the NodePool class)
272 virtual ~Node() {}
273
274 virtual ExpressionNode *expressionCast();
275 virtual BinaryExpression *binaryExpressionCast();
276 virtual Statement *statementCast();
277 virtual UiObjectMember *uiObjectMemberCast();
278 virtual LeftHandSideExpression *leftHandSideExpressionCast();
279 virtual Pattern *patternCast();
280 // implements the IsFunctionDefinition rules in the spec
281 virtual FunctionExpression *asFunctionDefinition();
282 virtual ClassExpression *asClassDefinition();
283
284 bool ignoreRecursionDepth() const;
285
286 inline void accept(BaseVisitor *visitor)
287 {
288 BaseVisitor::RecursionDepthCheck recursionCheck(visitor);
289
290 // Stack overflow is uncommon, ignoreRecursionDepth() only returns true if
291 // QV4_CRASH_ON_STACKOVERFLOW is set, and ignoreRecursionDepth() needs to be out of line.
292 // Therefore, check for ignoreRecursionDepth() _after_ calling the inline recursionCheck().
293 if (recursionCheck() || ignoreRecursionDepth()) {
294 if (visitor->preVisit(this))
295 accept0(visitor);
296 visitor->postVisit(this);
297 } else {
298 visitor->throwRecursionDepthError();
299 }
300 }
301
302 inline static void accept(Node *node, BaseVisitor *visitor)
303 {
304 if (node)
305 node->accept(visitor);
306 }
307
308 // ### Remove when we can. This is part of the qmldevtools library, though.
309 inline static void acceptChild(Node *node, BaseVisitor *visitor)
310 {
311 return accept(node, visitor);
312 }
313
314 virtual void accept0(BaseVisitor *visitor) = 0;
315 virtual SourceLocation firstSourceLocation() const = 0;
316 virtual SourceLocation lastSourceLocation() const = 0;
317
318// attributes
319 int kind = Kind_Undefined;
320};
321
322template<typename T>
323T lastListElement(T head)
324{
325 auto current = head;
326 while (current->next)
327 current = current->next;
328 return current;
329}
330
331class QML_PARSER_EXPORT UiQualifiedId: public Node
332{
333public:
334 QQMLJS_DECLARE_AST_NODE(UiQualifiedId)
335
336 UiQualifiedId(const QStringRef &name)
337 : next(this), name(name)
338 { kind = K; }
339
340 UiQualifiedId(UiQualifiedId *previous, const QStringRef &name)
341 : name(name)
342 {
343 kind = K;
344 next = previous->next;
345 previous->next = this;
346 }
347
348 UiQualifiedId *finish()
349 {
350 UiQualifiedId *head = next;
351 next = nullptr;
352 return head;
353 }
354
355 void accept0(BaseVisitor *visitor) override;
356
357 SourceLocation firstSourceLocation() const override
358 { return identifierToken; }
359
360 SourceLocation lastSourceLocation() const override
361 { return lastListElement(head: this)->identifierToken; }
362
363// attributes
364 UiQualifiedId *next;
365 QStringRef name;
366 SourceLocation identifierToken;
367};
368
369class QML_PARSER_EXPORT Type: public Node
370{
371public:
372 QQMLJS_DECLARE_AST_NODE(Type)
373
374 Type(UiQualifiedId *typeId, Node *typeArguments = nullptr)
375 : typeId(typeId)
376 , typeArguments(typeArguments)
377 { kind = K; }
378
379 void accept0(BaseVisitor *visitor) override;
380
381 SourceLocation firstSourceLocation() const override
382 { return typeId->firstSourceLocation(); }
383
384 SourceLocation lastSourceLocation() const override
385 { return typeArguments ? typeArguments->lastSourceLocation() : typeId->lastSourceLocation(); }
386
387 QString toString() const;
388 void toString(QString *out) const;
389
390// attributes
391 UiQualifiedId *typeId;
392 Node *typeArguments; // TypeArgumentList
393};
394
395
396class QML_PARSER_EXPORT TypeArgumentList: public Node
397{
398public:
399 QQMLJS_DECLARE_AST_NODE(TypeArgumentList)
400
401 TypeArgumentList(Type *typeId)
402 : typeId(typeId)
403 , next(nullptr)
404 { kind = K; }
405
406 TypeArgumentList(TypeArgumentList *previous, Type *typeId)
407 : typeId(typeId)
408 {
409 kind = K;
410 next = previous->next;
411 previous->next = this;
412 }
413
414 void accept0(BaseVisitor *visitor) override;
415
416 SourceLocation firstSourceLocation() const override
417 { return typeId->firstSourceLocation(); }
418
419 SourceLocation lastSourceLocation() const override
420 { return lastListElement(head: this)->typeId->lastSourceLocation(); }
421
422 inline TypeArgumentList *finish()
423 {
424 TypeArgumentList *front = next;
425 next = nullptr;
426 return front;
427 }
428
429// attributes
430 Type *typeId;
431 TypeArgumentList *next;
432};
433
434class QML_PARSER_EXPORT TypeAnnotation: public Node
435{
436public:
437 QQMLJS_DECLARE_AST_NODE(TypeAnnotation)
438
439 TypeAnnotation(Type *type)
440 : type(type)
441 { kind = K; }
442
443 void accept0(BaseVisitor *visitor) override;
444
445 SourceLocation firstSourceLocation() const override
446 { return colonToken; }
447
448 SourceLocation lastSourceLocation() const override
449 { return type->lastSourceLocation(); }
450
451// attributes
452 Type *type;
453 SourceLocation colonToken;
454};
455class QML_PARSER_EXPORT ExpressionNode: public Node
456{
457public:
458 ExpressionNode() {}
459
460 ExpressionNode *expressionCast() override;
461
462 AST::FormalParameterList *reparseAsFormalParameterList(MemoryPool *pool);
463
464};
465
466class QML_PARSER_EXPORT LeftHandSideExpression : public ExpressionNode
467{
468 LeftHandSideExpression *leftHandSideExpressionCast() override;
469};
470
471class QML_PARSER_EXPORT Statement: public Node
472{
473public:
474 Statement() {}
475
476 Statement *statementCast() override;
477};
478
479class QML_PARSER_EXPORT NestedExpression: public LeftHandSideExpression
480{
481public:
482 QQMLJS_DECLARE_AST_NODE(NestedExpression)
483
484 NestedExpression(ExpressionNode *expression)
485 : expression(expression)
486 { kind = K; }
487
488 void accept0(BaseVisitor *visitor) override;
489
490 SourceLocation firstSourceLocation() const override
491 { return lparenToken; }
492
493 SourceLocation lastSourceLocation() const override
494 { return rparenToken; }
495
496 FunctionExpression *asFunctionDefinition() override;
497 ClassExpression *asClassDefinition() override;
498
499
500// attributes
501 ExpressionNode *expression;
502 SourceLocation lparenToken;
503 SourceLocation rparenToken;
504};
505
506class QML_PARSER_EXPORT ThisExpression: public LeftHandSideExpression
507{
508public:
509 QQMLJS_DECLARE_AST_NODE(ThisExpression)
510
511 ThisExpression() { kind = K; }
512
513 void accept0(BaseVisitor *visitor) override;
514
515 SourceLocation firstSourceLocation() const override
516 { return thisToken; }
517
518 SourceLocation lastSourceLocation() const override
519 { return thisToken; }
520
521// attributes
522 SourceLocation thisToken;
523};
524
525class QML_PARSER_EXPORT IdentifierExpression: public LeftHandSideExpression
526{
527public:
528 QQMLJS_DECLARE_AST_NODE(IdentifierExpression)
529
530 IdentifierExpression(const QStringRef &n):
531 name (n) { kind = K; }
532
533 void accept0(BaseVisitor *visitor) override;
534
535 SourceLocation firstSourceLocation() const override
536 { return identifierToken; }
537
538 SourceLocation lastSourceLocation() const override
539 { return identifierToken; }
540
541// attributes
542 QStringRef name;
543 SourceLocation identifierToken;
544};
545
546class QML_PARSER_EXPORT NullExpression: public LeftHandSideExpression
547{
548public:
549 QQMLJS_DECLARE_AST_NODE(NullExpression)
550
551 NullExpression() { kind = K; }
552
553 void accept0(BaseVisitor *visitor) override;
554
555 SourceLocation firstSourceLocation() const override
556 { return nullToken; }
557
558 SourceLocation lastSourceLocation() const override
559 { return nullToken; }
560
561// attributes
562 SourceLocation nullToken;
563};
564
565class QML_PARSER_EXPORT TrueLiteral: public LeftHandSideExpression
566{
567public:
568 QQMLJS_DECLARE_AST_NODE(TrueLiteral)
569
570 TrueLiteral() { kind = K; }
571
572 void accept0(BaseVisitor *visitor) override;
573
574 SourceLocation firstSourceLocation() const override
575 { return trueToken; }
576
577 SourceLocation lastSourceLocation() const override
578 { return trueToken; }
579
580// attributes
581 SourceLocation trueToken;
582};
583
584class QML_PARSER_EXPORT FalseLiteral: public LeftHandSideExpression
585{
586public:
587 QQMLJS_DECLARE_AST_NODE(FalseLiteral)
588
589 FalseLiteral() { kind = K; }
590
591 void accept0(BaseVisitor *visitor) override;
592
593 SourceLocation firstSourceLocation() const override
594 { return falseToken; }
595
596 SourceLocation lastSourceLocation() const override
597 { return falseToken; }
598
599// attributes
600 SourceLocation falseToken;
601};
602
603class QML_PARSER_EXPORT SuperLiteral : public LeftHandSideExpression
604{
605public:
606 QQMLJS_DECLARE_AST_NODE(SuperLiteral)
607
608 SuperLiteral() { kind = K; }
609
610 void accept0(BaseVisitor *visitor) override;
611
612 SourceLocation firstSourceLocation() const override
613 { return superToken; }
614
615 SourceLocation lastSourceLocation() const override
616 { return superToken; }
617
618// attributes
619 SourceLocation superToken;
620};
621
622
623class QML_PARSER_EXPORT NumericLiteral: public LeftHandSideExpression
624{
625public:
626 QQMLJS_DECLARE_AST_NODE(NumericLiteral)
627
628 NumericLiteral(double v):
629 value(v) { kind = K; }
630
631 void accept0(BaseVisitor *visitor) override;
632
633 SourceLocation firstSourceLocation() const override
634 { return literalToken; }
635
636 SourceLocation lastSourceLocation() const override
637 { return literalToken; }
638
639// attributes:
640 double value;
641 SourceLocation literalToken;
642};
643
644class QML_PARSER_EXPORT UiVersionSpecifier : public Node
645{
646public:
647 QQMLJS_DECLARE_AST_NODE(UiVersionSpecifier)
648
649 UiVersionSpecifier(int majorum, int minorum) : majorVersion(majorum), minorVersion(minorum) { kind = K; }
650
651 void accept0(BaseVisitor *visitor) override;
652
653 SourceLocation firstSourceLocation() const override { return majorToken; }
654
655 SourceLocation lastSourceLocation() const override
656 {
657 return minorToken.isValid() ? minorToken : majorToken;
658 }
659
660 // attributes:
661 int majorVersion;
662 int minorVersion;
663 SourceLocation majorToken;
664 SourceLocation minorToken;
665};
666
667class QML_PARSER_EXPORT StringLiteral : public LeftHandSideExpression
668{
669public:
670 QQMLJS_DECLARE_AST_NODE(StringLiteral)
671
672 StringLiteral(const QStringRef &v):
673 value (v) { kind = K; }
674
675 void accept0(BaseVisitor *visitor) override;
676
677 SourceLocation firstSourceLocation() const override
678 { return literalToken; }
679
680 SourceLocation lastSourceLocation() const override
681 { return literalToken; }
682
683// attributes:
684 QStringRef value;
685 SourceLocation literalToken;
686};
687
688class QML_PARSER_EXPORT TemplateLiteral : public LeftHandSideExpression
689{
690public:
691 QQMLJS_DECLARE_AST_NODE(TemplateLiteral)
692
693 TemplateLiteral(const QStringRef &str, const QStringRef &raw, ExpressionNode *e)
694 : value(str), rawValue(raw), expression(e), next(nullptr)
695 { kind = K; }
696
697 SourceLocation firstSourceLocation() const override
698 { return literalToken; }
699
700 SourceLocation lastSourceLocation() const override
701 {
702 auto last = lastListElement(head: this);
703 return (last->expression ? last->expression->lastSourceLocation() : last->literalToken);
704 }
705
706 void accept0(BaseVisitor *visitor) override;
707
708 QStringRef value;
709 QStringRef rawValue;
710 ExpressionNode *expression;
711 TemplateLiteral *next;
712 SourceLocation literalToken;
713};
714
715class QML_PARSER_EXPORT RegExpLiteral: public LeftHandSideExpression
716{
717public:
718 QQMLJS_DECLARE_AST_NODE(RegExpLiteral)
719
720 RegExpLiteral(const QStringRef &p, int f):
721 pattern (p), flags (f) { kind = K; }
722
723 void accept0(BaseVisitor *visitor) override;
724
725 SourceLocation firstSourceLocation() const override
726 { return literalToken; }
727
728 SourceLocation lastSourceLocation() const override
729 { return literalToken; }
730
731// attributes:
732 QStringRef pattern;
733 int flags;
734 SourceLocation literalToken;
735};
736
737class QML_PARSER_EXPORT Pattern : public LeftHandSideExpression
738{
739public:
740 enum ParseMode {
741 Literal,
742 Binding
743 };
744 Pattern *patternCast() override;
745 virtual bool convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage) = 0;
746 ParseMode parseMode = Literal;
747};
748
749class QML_PARSER_EXPORT ArrayPattern : public Pattern
750{
751public:
752 QQMLJS_DECLARE_AST_NODE(ArrayPattern)
753
754 ArrayPattern(PatternElementList *elts)
755 : elements(elts)
756 { kind = K; }
757
758 void accept0(BaseVisitor *visitor) override;
759
760 SourceLocation firstSourceLocation() const override
761 { return lbracketToken; }
762
763 SourceLocation lastSourceLocation() const override
764 { return rbracketToken; }
765
766 bool isValidArrayLiteral(SourceLocation *errorLocation = nullptr) const;
767
768 bool convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage) override;
769
770// attributes
771 PatternElementList *elements = nullptr;
772 SourceLocation lbracketToken;
773 SourceLocation commaToken;
774 SourceLocation rbracketToken;
775};
776
777class QML_PARSER_EXPORT ObjectPattern : public Pattern
778{
779public:
780 QQMLJS_DECLARE_AST_NODE(ObjectPattern)
781
782 ObjectPattern()
783 { kind = K; }
784
785 ObjectPattern(PatternPropertyList *plist)
786 : properties(plist)
787 { kind = K; }
788
789 void accept0(BaseVisitor *visitor) override;
790
791 SourceLocation firstSourceLocation() const override
792 { return lbraceToken; }
793
794 SourceLocation lastSourceLocation() const override
795 { return rbraceToken; }
796
797 bool convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage) override;
798
799// attributes
800 PatternPropertyList *properties = nullptr;
801 SourceLocation lbraceToken;
802 SourceLocation rbraceToken;
803};
804
805class QML_PARSER_EXPORT Elision: public Node
806{
807public:
808 QQMLJS_DECLARE_AST_NODE(Elision)
809
810 Elision():
811 next (this) { kind = K; }
812
813 Elision(Elision *previous)
814 {
815 kind = K;
816 next = previous->next;
817 previous->next = this;
818 }
819
820 void accept0(BaseVisitor *visitor) override;
821
822 SourceLocation firstSourceLocation() const override
823 { return commaToken; }
824
825 SourceLocation lastSourceLocation() const override
826 { return lastListElement(head: this)->commaToken; }
827
828 inline Elision *finish ()
829 {
830 Elision *front = next;
831 next = nullptr;
832 return front;
833 }
834
835// attributes
836 Elision *next;
837 SourceLocation commaToken;
838};
839
840class QML_PARSER_EXPORT PropertyName: public Node
841{
842public:
843 QQMLJS_DECLARE_AST_NODE(PropertyName)
844
845 PropertyName() { kind = K; }
846
847 SourceLocation firstSourceLocation() const override
848 { return propertyNameToken; }
849
850 SourceLocation lastSourceLocation() const override
851 { return propertyNameToken; }
852
853 virtual QString asString() const = 0;
854
855// attributes
856 SourceLocation propertyNameToken;
857};
858
859struct QML_PARSER_EXPORT BoundName
860{
861 QString id;
862 TypeAnnotation *typeAnnotation = nullptr;
863 BoundName(const QString &id, TypeAnnotation *typeAnnotation)
864 : id(id), typeAnnotation(typeAnnotation)
865 {}
866 BoundName() = default;
867 QString typeName() const { return typeAnnotation ? typeAnnotation->type->toString() : QString(); }
868};
869
870struct BoundNames : public QVector<BoundName>
871{
872 int indexOf(const QString &name, int from = 0) const
873 {
874 auto found = std::find_if(first: constBegin() + from, last: constEnd(),
875 pred: [name](const BoundName &it) { return it.id == name; });
876 if (found == constEnd())
877 return -1;
878 return found - constBegin();
879 }
880
881 bool contains(const QString &name) const
882 {
883 return indexOf(name) != -1;
884 }
885};
886
887class QML_PARSER_EXPORT PatternElement : public Node
888{
889public:
890 QQMLJS_DECLARE_AST_NODE(PatternElement)
891
892 enum Type {
893 // object literal types
894 Literal,
895 Method,
896 Getter,
897 Setter,
898
899 // used by both bindings and literals
900 SpreadElement,
901 RestElement = SpreadElement,
902
903 // binding types
904 Binding,
905 };
906
907 PatternElement(ExpressionNode *i = nullptr, Type t = Literal)
908 : initializer(i), type(t)
909 { kind = K; }
910
911 PatternElement(const QStringRef &n, TypeAnnotation *typeAnnotation = nullptr, ExpressionNode *i = nullptr, Type t = Binding)
912 : bindingIdentifier(n), initializer(i), type(t)
913 , typeAnnotation(typeAnnotation)
914 {
915 Q_ASSERT(t >= RestElement);
916 kind = K;
917 }
918
919 PatternElement(Pattern *pattern, ExpressionNode *i = nullptr, Type t = Binding)
920 : bindingTarget(pattern), initializer(i), type(t)
921 {
922 Q_ASSERT(t >= RestElement);
923 kind = K;
924 }
925
926 void accept0(BaseVisitor *visitor) override;
927 virtual bool convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage);
928
929 SourceLocation firstSourceLocation() const override
930 { return identifierToken.isValid() ? identifierToken : (bindingTarget ? bindingTarget->firstSourceLocation() : initializer->firstSourceLocation()); }
931
932 SourceLocation lastSourceLocation() const override
933 { return initializer ? initializer->lastSourceLocation() : (bindingTarget ? bindingTarget->lastSourceLocation() : (typeAnnotation ? typeAnnotation->lastSourceLocation() : identifierToken)); }
934
935 ExpressionNode *destructuringTarget() const { return bindingTarget; }
936 Pattern *destructuringPattern() const { return bindingTarget ? bindingTarget->patternCast() : nullptr; }
937 PatternElementList *elementList() const { ArrayPattern *a = cast<ArrayPattern *>(ast: bindingTarget); return a ? a->elements : nullptr; }
938 PatternPropertyList *propertyList() const { ObjectPattern *o = cast<ObjectPattern *>(ast: bindingTarget); return o ? o->properties : nullptr; }
939
940 bool isVariableDeclaration() const { return scope != VariableScope::NoScope; }
941 bool isLexicallyScoped() const { return scope == VariableScope::Let || scope == VariableScope::Const; }
942
943 virtual void boundNames(BoundNames *names);
944
945// attributes
946 SourceLocation identifierToken;
947 QStringRef bindingIdentifier;
948 ExpressionNode *bindingTarget = nullptr;
949 ExpressionNode *initializer = nullptr;
950 Type type = Literal;
951 TypeAnnotation *typeAnnotation = nullptr;
952 // when used in a VariableDeclarationList
953 VariableScope scope = VariableScope::NoScope;
954 bool isForDeclaration = false;
955};
956
957class QML_PARSER_EXPORT PatternElementList : public Node
958{
959public:
960 QQMLJS_DECLARE_AST_NODE(PatternElementList)
961
962 PatternElementList(Elision *elision, PatternElement *element)
963 : elision(elision), element(element), next(this)
964 { kind = K; }
965
966 PatternElementList *append(PatternElementList *n) {
967 n->next = next;
968 next = n;
969 return n;
970 }
971
972 inline PatternElementList *finish ()
973 {
974 PatternElementList *front = next;
975 next = 0;
976 return front;
977 }
978
979 void accept0(BaseVisitor *visitor) override;
980
981 void boundNames(BoundNames *names);
982
983 SourceLocation firstSourceLocation() const override
984 { return elision ? elision->firstSourceLocation() : element->firstSourceLocation(); }
985
986 SourceLocation lastSourceLocation() const override
987 {
988 auto last = lastListElement(head: this);
989 return last->element ? last->element->lastSourceLocation() : last->elision->lastSourceLocation();
990 }
991
992 Elision *elision = nullptr;
993 PatternElement *element = nullptr;
994 PatternElementList *next;
995};
996
997class QML_PARSER_EXPORT PatternProperty : public PatternElement
998{
999public:
1000 QQMLJS_DECLARE_AST_NODE(PatternProperty)
1001
1002 PatternProperty(PropertyName *name, ExpressionNode *i = nullptr, Type t = Literal)
1003 : PatternElement(i, t), name(name)
1004 { kind = K; }
1005
1006 PatternProperty(PropertyName *name, const QStringRef &n, ExpressionNode *i = nullptr)
1007 : PatternElement(n, /*type annotation*/nullptr, i), name(name)
1008 { kind = K; }
1009
1010 PatternProperty(PropertyName *name, Pattern *pattern, ExpressionNode *i = nullptr)
1011 : PatternElement(pattern, i), name(name)
1012 { kind = K; }
1013
1014 void accept0(BaseVisitor *visitor) override;
1015
1016 SourceLocation firstSourceLocation() const override
1017 { return name->firstSourceLocation(); }
1018 SourceLocation lastSourceLocation() const override
1019 {
1020 SourceLocation loc = PatternElement::lastSourceLocation();
1021 return loc.isValid() ? loc : name->lastSourceLocation();
1022 }
1023
1024 void boundNames(BoundNames *names) override;
1025 bool convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage) override;
1026
1027// attributes
1028 PropertyName *name;
1029 SourceLocation colonToken;
1030};
1031
1032
1033class QML_PARSER_EXPORT PatternPropertyList : public Node
1034{
1035public:
1036 QQMLJS_DECLARE_AST_NODE(PatternPropertyList)
1037
1038 PatternPropertyList(PatternProperty *property)
1039 : property(property), next(this)
1040 { kind = K; }
1041
1042 PatternPropertyList(PatternPropertyList *previous, PatternProperty *property)
1043 : property(property), next(this)
1044 {
1045 kind = K;
1046 next = previous->next;
1047 previous->next = this;
1048 }
1049
1050 void accept0(BaseVisitor *visitor) override;
1051
1052 void boundNames(BoundNames *names);
1053
1054 inline PatternPropertyList *finish ()
1055 {
1056 PatternPropertyList *front = next;
1057 next = 0;
1058 return front;
1059 }
1060
1061 SourceLocation firstSourceLocation() const override
1062 { return property->firstSourceLocation(); }
1063
1064 SourceLocation lastSourceLocation() const override
1065 { return lastListElement(head: this)->property->lastSourceLocation(); }
1066
1067 PatternProperty *property;
1068 PatternPropertyList *next;
1069};
1070
1071class QML_PARSER_EXPORT IdentifierPropertyName: public PropertyName
1072{
1073public:
1074 QQMLJS_DECLARE_AST_NODE(IdentifierPropertyName)
1075
1076 IdentifierPropertyName(const QStringRef &n):
1077 id (n) { kind = K; }
1078
1079 void accept0(BaseVisitor *visitor) override;
1080
1081 QString asString() const override { return id.toString(); }
1082
1083// attributes
1084 QStringRef id;
1085};
1086
1087class QML_PARSER_EXPORT StringLiteralPropertyName: public PropertyName
1088{
1089public:
1090 QQMLJS_DECLARE_AST_NODE(StringLiteralPropertyName)
1091
1092 StringLiteralPropertyName(const QStringRef &n):
1093 id (n) { kind = K; }
1094
1095 void accept0(BaseVisitor *visitor) override;
1096
1097 QString asString() const override { return id.toString(); }
1098
1099// attributes
1100 QStringRef id;
1101};
1102
1103class QML_PARSER_EXPORT NumericLiteralPropertyName: public PropertyName
1104{
1105public:
1106 QQMLJS_DECLARE_AST_NODE(NumericLiteralPropertyName)
1107
1108 NumericLiteralPropertyName(double n):
1109 id (n) { kind = K; }
1110
1111 void accept0(BaseVisitor *visitor) override;
1112
1113 QString asString() const override;
1114
1115// attributes
1116 double id;
1117};
1118
1119class QML_PARSER_EXPORT ComputedPropertyName : public PropertyName
1120{
1121public:
1122 QQMLJS_DECLARE_AST_NODE(ComputedPropertyName)
1123
1124 ComputedPropertyName(ExpressionNode *expression)
1125 : expression(expression)
1126 { kind = K; }
1127
1128 void accept0(BaseVisitor *visitor) override;
1129
1130 QString asString() const override { return QString(); }
1131
1132 SourceLocation firstSourceLocation() const override
1133 { return expression->firstSourceLocation(); }
1134
1135 SourceLocation lastSourceLocation() const override
1136 { return expression->lastSourceLocation(); }
1137
1138// attributes
1139 ExpressionNode *expression;
1140};
1141
1142
1143class QML_PARSER_EXPORT ArrayMemberExpression: public LeftHandSideExpression
1144{
1145public:
1146 QQMLJS_DECLARE_AST_NODE(ArrayMemberExpression)
1147
1148 ArrayMemberExpression(ExpressionNode *b, ExpressionNode *e):
1149 base (b), expression (e)
1150 { kind = K; }
1151
1152 void accept0(BaseVisitor *visitor) override;
1153
1154 SourceLocation firstSourceLocation() const override
1155 { return base->firstSourceLocation(); }
1156
1157 SourceLocation lastSourceLocation() const override
1158 { return rbracketToken; }
1159
1160// attributes
1161 ExpressionNode *base;
1162 ExpressionNode *expression;
1163 SourceLocation lbracketToken;
1164 SourceLocation rbracketToken;
1165};
1166
1167class QML_PARSER_EXPORT FieldMemberExpression: public LeftHandSideExpression
1168{
1169public:
1170 QQMLJS_DECLARE_AST_NODE(FieldMemberExpression)
1171
1172 FieldMemberExpression(ExpressionNode *b, const QStringRef &n):
1173 base (b), name (n)
1174 { kind = K; }
1175
1176 void accept0(BaseVisitor *visitor) override;
1177
1178 SourceLocation firstSourceLocation() const override
1179 { return base->firstSourceLocation(); }
1180
1181 SourceLocation lastSourceLocation() const override
1182 { return identifierToken; }
1183
1184 // attributes
1185 ExpressionNode *base;
1186 QStringRef name;
1187 SourceLocation dotToken;
1188 SourceLocation identifierToken;
1189};
1190
1191class QML_PARSER_EXPORT TaggedTemplate : public LeftHandSideExpression
1192{
1193public:
1194 QQMLJS_DECLARE_AST_NODE(TaggedTemplate)
1195
1196 TaggedTemplate(ExpressionNode *b, TemplateLiteral *t)
1197 : base (b), templateLiteral(t)
1198 { kind = K; }
1199
1200 void accept0(BaseVisitor *visitor) override;
1201
1202 SourceLocation firstSourceLocation() const override
1203 { return base->firstSourceLocation(); }
1204
1205 SourceLocation lastSourceLocation() const override
1206 { return templateLiteral->lastSourceLocation(); }
1207
1208 // attributes
1209 ExpressionNode *base;
1210 TemplateLiteral *templateLiteral;
1211};
1212
1213class QML_PARSER_EXPORT NewMemberExpression: public LeftHandSideExpression
1214{
1215public:
1216 QQMLJS_DECLARE_AST_NODE(NewMemberExpression)
1217
1218 NewMemberExpression(ExpressionNode *b, ArgumentList *a):
1219 base (b), arguments (a)
1220 { kind = K; }
1221
1222 void accept0(BaseVisitor *visitor) override;
1223
1224 SourceLocation firstSourceLocation() const override
1225 { return newToken; }
1226
1227 SourceLocation lastSourceLocation() const override
1228 { return rparenToken; }
1229
1230 // attributes
1231 ExpressionNode *base;
1232 ArgumentList *arguments;
1233 SourceLocation newToken;
1234 SourceLocation lparenToken;
1235 SourceLocation rparenToken;
1236};
1237
1238class QML_PARSER_EXPORT NewExpression: public LeftHandSideExpression
1239{
1240public:
1241 QQMLJS_DECLARE_AST_NODE(NewExpression)
1242
1243 NewExpression(ExpressionNode *e):
1244 expression (e) { kind = K; }
1245
1246 void accept0(BaseVisitor *visitor) override;
1247
1248 SourceLocation firstSourceLocation() const override
1249 { return newToken; }
1250
1251 SourceLocation lastSourceLocation() const override
1252 { return expression->lastSourceLocation(); }
1253
1254// attributes
1255 ExpressionNode *expression;
1256 SourceLocation newToken;
1257};
1258
1259class QML_PARSER_EXPORT CallExpression: public LeftHandSideExpression
1260{
1261public:
1262 QQMLJS_DECLARE_AST_NODE(CallExpression)
1263
1264 CallExpression(ExpressionNode *b, ArgumentList *a):
1265 base (b), arguments (a)
1266 { kind = K; }
1267
1268 void accept0(BaseVisitor *visitor) override;
1269
1270 SourceLocation firstSourceLocation() const override
1271 { return base->firstSourceLocation(); }
1272
1273 SourceLocation lastSourceLocation() const override
1274 { return rparenToken; }
1275
1276// attributes
1277 ExpressionNode *base;
1278 ArgumentList *arguments;
1279 SourceLocation lparenToken;
1280 SourceLocation rparenToken;
1281};
1282
1283class QML_PARSER_EXPORT ArgumentList: public Node
1284{
1285public:
1286 QQMLJS_DECLARE_AST_NODE(ArgumentList)
1287
1288 ArgumentList(ExpressionNode *e):
1289 expression (e), next (this)
1290 { kind = K; }
1291
1292 ArgumentList(ArgumentList *previous, ExpressionNode *e):
1293 expression (e)
1294 {
1295 kind = K;
1296 next = previous->next;
1297 previous->next = this;
1298 }
1299
1300 void accept0(BaseVisitor *visitor) override;
1301
1302 SourceLocation firstSourceLocation() const override
1303 { return expression->firstSourceLocation(); }
1304
1305 SourceLocation lastSourceLocation() const override
1306 {
1307 if (next)
1308 return next->lastSourceLocation();
1309 return expression->lastSourceLocation();
1310 }
1311
1312 inline ArgumentList *finish ()
1313 {
1314 ArgumentList *front = next;
1315 next = nullptr;
1316 return front;
1317 }
1318
1319// attributes
1320 ExpressionNode *expression;
1321 ArgumentList *next;
1322 SourceLocation commaToken;
1323 bool isSpreadElement = false;
1324};
1325
1326class QML_PARSER_EXPORT PostIncrementExpression: public ExpressionNode
1327{
1328public:
1329 QQMLJS_DECLARE_AST_NODE(PostIncrementExpression)
1330
1331 PostIncrementExpression(ExpressionNode *b):
1332 base (b) { kind = K; }
1333
1334 void accept0(BaseVisitor *visitor) override;
1335
1336 SourceLocation firstSourceLocation() const override
1337 { return base->firstSourceLocation(); }
1338
1339 SourceLocation lastSourceLocation() const override
1340 { return incrementToken; }
1341
1342// attributes
1343 ExpressionNode *base;
1344 SourceLocation incrementToken;
1345};
1346
1347class QML_PARSER_EXPORT PostDecrementExpression: public ExpressionNode
1348{
1349public:
1350 QQMLJS_DECLARE_AST_NODE(PostDecrementExpression)
1351
1352 PostDecrementExpression(ExpressionNode *b):
1353 base (b) { kind = K; }
1354
1355 void accept0(BaseVisitor *visitor) override;
1356
1357 SourceLocation firstSourceLocation() const override
1358 { return base->firstSourceLocation(); }
1359
1360 SourceLocation lastSourceLocation() const override
1361 { return decrementToken; }
1362
1363// attributes
1364 ExpressionNode *base;
1365 SourceLocation decrementToken;
1366};
1367
1368class QML_PARSER_EXPORT DeleteExpression: public ExpressionNode
1369{
1370public:
1371 QQMLJS_DECLARE_AST_NODE(DeleteExpression)
1372
1373 DeleteExpression(ExpressionNode *e):
1374 expression (e) { kind = K; }
1375
1376 void accept0(BaseVisitor *visitor) override;
1377
1378 SourceLocation firstSourceLocation() const override
1379 { return deleteToken; }
1380
1381 SourceLocation lastSourceLocation() const override
1382 { return expression->lastSourceLocation(); }
1383
1384// attributes
1385 ExpressionNode *expression;
1386 SourceLocation deleteToken;
1387};
1388
1389class QML_PARSER_EXPORT VoidExpression: public ExpressionNode
1390{
1391public:
1392 QQMLJS_DECLARE_AST_NODE(VoidExpression)
1393
1394 VoidExpression(ExpressionNode *e):
1395 expression (e) { kind = K; }
1396
1397 void accept0(BaseVisitor *visitor) override;
1398
1399 SourceLocation firstSourceLocation() const override
1400 { return voidToken; }
1401
1402 SourceLocation lastSourceLocation() const override
1403 { return expression->lastSourceLocation(); }
1404
1405// attributes
1406 ExpressionNode *expression;
1407 SourceLocation voidToken;
1408};
1409
1410class QML_PARSER_EXPORT TypeOfExpression: public ExpressionNode
1411{
1412public:
1413 QQMLJS_DECLARE_AST_NODE(TypeOfExpression)
1414
1415 TypeOfExpression(ExpressionNode *e):
1416 expression (e) { kind = K; }
1417
1418 void accept0(BaseVisitor *visitor) override;
1419
1420 SourceLocation firstSourceLocation() const override
1421 { return typeofToken; }
1422
1423 SourceLocation lastSourceLocation() const override
1424 { return expression->lastSourceLocation(); }
1425
1426// attributes
1427 ExpressionNode *expression;
1428 SourceLocation typeofToken;
1429};
1430
1431class QML_PARSER_EXPORT PreIncrementExpression: public ExpressionNode
1432{
1433public:
1434 QQMLJS_DECLARE_AST_NODE(PreIncrementExpression)
1435
1436 PreIncrementExpression(ExpressionNode *e):
1437 expression (e) { kind = K; }
1438
1439 void accept0(BaseVisitor *visitor) override;
1440
1441 SourceLocation firstSourceLocation() const override
1442 { return incrementToken; }
1443
1444 SourceLocation lastSourceLocation() const override
1445 { return expression->lastSourceLocation(); }
1446
1447// attributes
1448 ExpressionNode *expression;
1449 SourceLocation incrementToken;
1450};
1451
1452class QML_PARSER_EXPORT PreDecrementExpression: public ExpressionNode
1453{
1454public:
1455 QQMLJS_DECLARE_AST_NODE(PreDecrementExpression)
1456
1457 PreDecrementExpression(ExpressionNode *e):
1458 expression (e) { kind = K; }
1459
1460 void accept0(BaseVisitor *visitor) override;
1461
1462 SourceLocation firstSourceLocation() const override
1463 { return decrementToken; }
1464
1465 SourceLocation lastSourceLocation() const override
1466 { return expression->lastSourceLocation(); }
1467
1468// attributes
1469 ExpressionNode *expression;
1470 SourceLocation decrementToken;
1471};
1472
1473class QML_PARSER_EXPORT UnaryPlusExpression: public ExpressionNode
1474{
1475public:
1476 QQMLJS_DECLARE_AST_NODE(UnaryPlusExpression)
1477
1478 UnaryPlusExpression(ExpressionNode *e):
1479 expression (e) { kind = K; }
1480
1481 void accept0(BaseVisitor *visitor) override;
1482
1483 SourceLocation firstSourceLocation() const override
1484 { return plusToken; }
1485
1486 SourceLocation lastSourceLocation() const override
1487 { return expression->lastSourceLocation(); }
1488
1489// attributes
1490 ExpressionNode *expression;
1491 SourceLocation plusToken;
1492};
1493
1494class QML_PARSER_EXPORT UnaryMinusExpression: public ExpressionNode
1495{
1496public:
1497 QQMLJS_DECLARE_AST_NODE(UnaryMinusExpression)
1498
1499 UnaryMinusExpression(ExpressionNode *e):
1500 expression (e) { kind = K; }
1501
1502 void accept0(BaseVisitor *visitor) override;
1503
1504 SourceLocation firstSourceLocation() const override
1505 { return minusToken; }
1506
1507 SourceLocation lastSourceLocation() const override
1508 { return expression->lastSourceLocation(); }
1509
1510// attributes
1511 ExpressionNode *expression;
1512 SourceLocation minusToken;
1513};
1514
1515class QML_PARSER_EXPORT TildeExpression: public ExpressionNode
1516{
1517public:
1518 QQMLJS_DECLARE_AST_NODE(TildeExpression)
1519
1520 TildeExpression(ExpressionNode *e):
1521 expression (e) { kind = K; }
1522
1523 void accept0(BaseVisitor *visitor) override;
1524
1525 SourceLocation firstSourceLocation() const override
1526 { return tildeToken; }
1527
1528 SourceLocation lastSourceLocation() const override
1529 { return expression->lastSourceLocation(); }
1530
1531// attributes
1532 ExpressionNode *expression;
1533 SourceLocation tildeToken;
1534};
1535
1536class QML_PARSER_EXPORT NotExpression: public ExpressionNode
1537{
1538public:
1539 QQMLJS_DECLARE_AST_NODE(NotExpression)
1540
1541 NotExpression(ExpressionNode *e):
1542 expression (e) { kind = K; }
1543
1544 void accept0(BaseVisitor *visitor) override;
1545
1546 SourceLocation firstSourceLocation() const override
1547 { return notToken; }
1548
1549 SourceLocation lastSourceLocation() const override
1550 { return expression->lastSourceLocation(); }
1551
1552// attributes
1553 ExpressionNode *expression;
1554 SourceLocation notToken;
1555};
1556
1557class QML_PARSER_EXPORT BinaryExpression: public ExpressionNode
1558{
1559public:
1560 QQMLJS_DECLARE_AST_NODE(BinaryExpression)
1561
1562 BinaryExpression(ExpressionNode *l, int o, ExpressionNode *r):
1563 left (l), op (o), right (r)
1564 { kind = K; }
1565
1566 BinaryExpression *binaryExpressionCast() override;
1567
1568 void accept0(BaseVisitor *visitor) override;
1569
1570 SourceLocation firstSourceLocation() const override
1571 { return left->firstSourceLocation(); }
1572
1573 SourceLocation lastSourceLocation() const override
1574 { return right->lastSourceLocation(); }
1575
1576// attributes
1577 ExpressionNode *left;
1578 int op;
1579 ExpressionNode *right;
1580 SourceLocation operatorToken;
1581};
1582
1583class QML_PARSER_EXPORT ConditionalExpression: public ExpressionNode
1584{
1585public:
1586 QQMLJS_DECLARE_AST_NODE(ConditionalExpression)
1587
1588 ConditionalExpression(ExpressionNode *e, ExpressionNode *t, ExpressionNode *f):
1589 expression (e), ok (t), ko (f)
1590 { kind = K; }
1591
1592 void accept0(BaseVisitor *visitor) override;
1593
1594 SourceLocation firstSourceLocation() const override
1595 { return expression->firstSourceLocation(); }
1596
1597 SourceLocation lastSourceLocation() const override
1598 { return ko->lastSourceLocation(); }
1599
1600// attributes
1601 ExpressionNode *expression;
1602 ExpressionNode *ok;
1603 ExpressionNode *ko;
1604 SourceLocation questionToken;
1605 SourceLocation colonToken;
1606};
1607
1608class QML_PARSER_EXPORT Expression: public ExpressionNode // ### rename
1609{
1610public:
1611 QQMLJS_DECLARE_AST_NODE(Expression)
1612
1613 Expression(ExpressionNode *l, ExpressionNode *r):
1614 left (l), right (r) { kind = K; }
1615
1616 void accept0(BaseVisitor *visitor) override;
1617
1618 SourceLocation firstSourceLocation() const override
1619 { return left->firstSourceLocation(); }
1620
1621 SourceLocation lastSourceLocation() const override
1622 { return right->lastSourceLocation(); }
1623
1624// attributes
1625 ExpressionNode *left;
1626 ExpressionNode *right;
1627 SourceLocation commaToken;
1628};
1629
1630class QML_PARSER_EXPORT Block: public Statement
1631{
1632public:
1633 QQMLJS_DECLARE_AST_NODE(Block)
1634
1635 Block(StatementList *slist):
1636 statements (slist) { kind = K; }
1637
1638 void accept0(BaseVisitor *visitor) override;
1639
1640 SourceLocation firstSourceLocation() const override
1641 { return lbraceToken; }
1642
1643 SourceLocation lastSourceLocation() const override
1644 { return rbraceToken; }
1645
1646 // attributes
1647 StatementList *statements;
1648 SourceLocation lbraceToken;
1649 SourceLocation rbraceToken;
1650};
1651
1652class QML_PARSER_EXPORT StatementList: public Node
1653{
1654public:
1655 QQMLJS_DECLARE_AST_NODE(StatementList)
1656
1657 // ### This should be a Statement, but FunctionDeclaration currently doesn't inherit it.
1658 StatementList(Node *stmt)
1659 : statement(stmt), next (this)
1660 { kind = K; }
1661
1662 StatementList *append(StatementList *n) {
1663 n->next = next;
1664 next = n;
1665 return n;
1666 }
1667
1668 void accept0(BaseVisitor *visitor) override;
1669
1670 SourceLocation firstSourceLocation() const override
1671 { return statement->firstSourceLocation(); }
1672
1673 SourceLocation lastSourceLocation() const override
1674 {
1675 return lastListElement(head: this)->statement->lastSourceLocation();
1676 }
1677
1678 inline StatementList *finish ()
1679 {
1680 StatementList *front = next;
1681 next = nullptr;
1682 return front;
1683 }
1684
1685// attributes
1686 Node *statement = nullptr;
1687 StatementList *next;
1688};
1689
1690class QML_PARSER_EXPORT VariableDeclarationList: public Node
1691{
1692public:
1693 QQMLJS_DECLARE_AST_NODE(VariableDeclarationList)
1694
1695 VariableDeclarationList(PatternElement *decl)
1696 : declaration(decl), next(this)
1697 { kind = K; }
1698
1699 VariableDeclarationList(VariableDeclarationList *previous, PatternElement *decl)
1700 : declaration(decl)
1701 {
1702 kind = K;
1703 next = previous->next;
1704 previous->next = this;
1705 }
1706
1707 void accept0(BaseVisitor *visitor) override;
1708
1709 SourceLocation firstSourceLocation() const override
1710 { return declaration->firstSourceLocation(); }
1711
1712 SourceLocation lastSourceLocation() const override
1713 {
1714 if (next)
1715 return next->lastSourceLocation();
1716 return declaration->lastSourceLocation();
1717 }
1718
1719 inline VariableDeclarationList *finish(VariableScope s)
1720 {
1721 VariableDeclarationList *front = next;
1722 next = nullptr;
1723 VariableDeclarationList *vdl;
1724 for (vdl = front; vdl != nullptr; vdl = vdl->next) {
1725 vdl->declaration->scope = s;
1726 }
1727 return front;
1728 }
1729
1730// attributes
1731 PatternElement *declaration;
1732 VariableDeclarationList *next;
1733 SourceLocation commaToken;
1734};
1735
1736class QML_PARSER_EXPORT VariableStatement: public Statement
1737{
1738public:
1739 QQMLJS_DECLARE_AST_NODE(VariableStatement)
1740
1741 VariableStatement(VariableDeclarationList *vlist):
1742 declarations (vlist)
1743 { kind = K; }
1744
1745 void accept0(BaseVisitor *visitor) override;
1746
1747 SourceLocation firstSourceLocation() const override
1748 { return declarationKindToken; }
1749
1750 SourceLocation lastSourceLocation() const override
1751 { return declarations->lastSourceLocation(); }
1752
1753// attributes
1754 VariableDeclarationList *declarations;
1755 SourceLocation declarationKindToken;
1756};
1757
1758class QML_PARSER_EXPORT EmptyStatement: public Statement
1759{
1760public:
1761 QQMLJS_DECLARE_AST_NODE(EmptyStatement)
1762
1763 EmptyStatement() { kind = K; }
1764
1765 void accept0(BaseVisitor *visitor) override;
1766
1767 SourceLocation firstSourceLocation() const override
1768 { return semicolonToken; }
1769
1770 SourceLocation lastSourceLocation() const override
1771 { return semicolonToken; }
1772
1773// attributes
1774 SourceLocation semicolonToken;
1775};
1776
1777class QML_PARSER_EXPORT ExpressionStatement: public Statement
1778{
1779public:
1780 QQMLJS_DECLARE_AST_NODE(ExpressionStatement)
1781
1782 ExpressionStatement(ExpressionNode *e):
1783 expression (e) { kind = K; }
1784
1785 void accept0(BaseVisitor *visitor) override;
1786
1787 SourceLocation firstSourceLocation() const override
1788 { return expression->firstSourceLocation(); }
1789
1790 SourceLocation lastSourceLocation() const override
1791 { return semicolonToken; }
1792
1793// attributes
1794 ExpressionNode *expression;
1795 SourceLocation semicolonToken;
1796};
1797
1798class QML_PARSER_EXPORT IfStatement: public Statement
1799{
1800public:
1801 QQMLJS_DECLARE_AST_NODE(IfStatement)
1802
1803 IfStatement(ExpressionNode *e, Statement *t, Statement *f = nullptr):
1804 expression (e), ok (t), ko (f)
1805 { kind = K; }
1806
1807 void accept0(BaseVisitor *visitor) override;
1808
1809 SourceLocation firstSourceLocation() const override
1810 { return ifToken; }
1811
1812 SourceLocation lastSourceLocation() const override
1813 {
1814 if (ko)
1815 return ko->lastSourceLocation();
1816
1817 return ok->lastSourceLocation();
1818 }
1819
1820// attributes
1821 ExpressionNode *expression;
1822 Statement *ok;
1823 Statement *ko;
1824 SourceLocation ifToken;
1825 SourceLocation lparenToken;
1826 SourceLocation rparenToken;
1827 SourceLocation elseToken;
1828};
1829
1830class QML_PARSER_EXPORT DoWhileStatement: public Statement
1831{
1832public:
1833 QQMLJS_DECLARE_AST_NODE(DoWhileStatement)
1834
1835 DoWhileStatement(Statement *stmt, ExpressionNode *e):
1836 statement (stmt), expression (e)
1837 { kind = K; }
1838
1839 void accept0(BaseVisitor *visitor) override;
1840
1841 SourceLocation firstSourceLocation() const override
1842 { return doToken; }
1843
1844 SourceLocation lastSourceLocation() const override
1845 { return semicolonToken; }
1846
1847// attributes
1848 Statement *statement;
1849 ExpressionNode *expression;
1850 SourceLocation doToken;
1851 SourceLocation whileToken;
1852 SourceLocation lparenToken;
1853 SourceLocation rparenToken;
1854 SourceLocation semicolonToken;
1855};
1856
1857class QML_PARSER_EXPORT WhileStatement: public Statement
1858{
1859public:
1860 QQMLJS_DECLARE_AST_NODE(WhileStatement)
1861
1862 WhileStatement(ExpressionNode *e, Statement *stmt):
1863 expression (e), statement (stmt)
1864 { kind = K; }
1865
1866 void accept0(BaseVisitor *visitor) override;
1867
1868 SourceLocation firstSourceLocation() const override
1869 { return whileToken; }
1870
1871 SourceLocation lastSourceLocation() const override
1872 { return statement->lastSourceLocation(); }
1873
1874// attributes
1875 ExpressionNode *expression;
1876 Statement *statement;
1877 SourceLocation whileToken;
1878 SourceLocation lparenToken;
1879 SourceLocation rparenToken;
1880};
1881
1882class QML_PARSER_EXPORT ForStatement: public Statement
1883{
1884public:
1885 QQMLJS_DECLARE_AST_NODE(ForStatement)
1886
1887 ForStatement(ExpressionNode *i, ExpressionNode *c, ExpressionNode *e, Statement *stmt):
1888 initialiser (i), condition (c), expression (e), statement (stmt)
1889 { kind = K; }
1890
1891 ForStatement(VariableDeclarationList *vlist, ExpressionNode *c, ExpressionNode *e, Statement *stmt):
1892 declarations (vlist), condition (c), expression (e), statement (stmt)
1893 { kind = K; }
1894
1895
1896 void accept0(BaseVisitor *visitor) override;
1897
1898 SourceLocation firstSourceLocation() const override
1899 { return forToken; }
1900
1901 SourceLocation lastSourceLocation() const override
1902 { return statement->lastSourceLocation(); }
1903
1904// attributes
1905 ExpressionNode *initialiser = nullptr;
1906 VariableDeclarationList *declarations = nullptr;
1907 ExpressionNode *condition;
1908 ExpressionNode *expression;
1909 Statement *statement;
1910 SourceLocation forToken;
1911 SourceLocation lparenToken;
1912 SourceLocation firstSemicolonToken;
1913 SourceLocation secondSemicolonToken;
1914 SourceLocation rparenToken;
1915};
1916
1917enum class ForEachType {
1918 In,
1919 Of
1920};
1921
1922class QML_PARSER_EXPORT ForEachStatement: public Statement
1923{
1924public:
1925 QQMLJS_DECLARE_AST_NODE(ForEachStatement)
1926
1927 ForEachStatement(ExpressionNode *i, ExpressionNode *e, Statement *stmt)
1928 : lhs(i), expression(e), statement(stmt)
1929 { kind = K; }
1930 ForEachStatement(PatternElement *v, ExpressionNode *e, Statement *stmt)
1931 : lhs(v), expression(e), statement(stmt)
1932 { kind = K; }
1933
1934 void accept0(BaseVisitor *visitor) override;
1935
1936 SourceLocation firstSourceLocation() const override
1937 { return forToken; }
1938
1939 SourceLocation lastSourceLocation() const override
1940 { return statement->lastSourceLocation(); }
1941
1942 PatternElement *declaration() const {
1943 return AST::cast<PatternElement *>(ast: lhs);
1944 }
1945
1946// attributes
1947 Node *lhs;
1948 ExpressionNode *expression;
1949 Statement *statement;
1950 SourceLocation forToken;
1951 SourceLocation lparenToken;
1952 SourceLocation inOfToken;
1953 SourceLocation rparenToken;
1954 ForEachType type;
1955};
1956
1957class QML_PARSER_EXPORT ContinueStatement: public Statement
1958{
1959public:
1960 QQMLJS_DECLARE_AST_NODE(ContinueStatement)
1961
1962 ContinueStatement(const QStringRef &l = QStringRef()):
1963 label (l) { kind = K; }
1964
1965 void accept0(BaseVisitor *visitor) override;
1966
1967 SourceLocation firstSourceLocation() const override
1968 { return continueToken; }
1969
1970 SourceLocation lastSourceLocation() const override
1971 { return semicolonToken; }
1972
1973// attributes
1974 QStringRef label;
1975 SourceLocation continueToken;
1976 SourceLocation identifierToken;
1977 SourceLocation semicolonToken;
1978};
1979
1980class QML_PARSER_EXPORT BreakStatement: public Statement
1981{
1982public:
1983 QQMLJS_DECLARE_AST_NODE(BreakStatement)
1984
1985 BreakStatement(const QStringRef &l):
1986 label (l) { kind = K; }
1987
1988 void accept0(BaseVisitor *visitor) override;
1989
1990 SourceLocation firstSourceLocation() const override
1991 { return breakToken; }
1992
1993 SourceLocation lastSourceLocation() const override
1994 { return semicolonToken; }
1995
1996 // attributes
1997 QStringRef label;
1998 SourceLocation breakToken;
1999 SourceLocation identifierToken;
2000 SourceLocation semicolonToken;
2001};
2002
2003class QML_PARSER_EXPORT ReturnStatement: public Statement
2004{
2005public:
2006 QQMLJS_DECLARE_AST_NODE(ReturnStatement)
2007
2008 ReturnStatement(ExpressionNode *e):
2009 expression (e) { kind = K; }
2010
2011 void accept0(BaseVisitor *visitor) override;
2012
2013 SourceLocation firstSourceLocation() const override
2014 { return returnToken; }
2015
2016 SourceLocation lastSourceLocation() const override
2017 { return semicolonToken; }
2018
2019// attributes
2020 ExpressionNode *expression;
2021 SourceLocation returnToken;
2022 SourceLocation semicolonToken;
2023};
2024
2025class QML_PARSER_EXPORT YieldExpression: public ExpressionNode
2026{
2027public:
2028 QQMLJS_DECLARE_AST_NODE(YieldExpression)
2029
2030 YieldExpression(ExpressionNode *e = nullptr):
2031 expression (e) { kind = K; }
2032
2033 void accept0(BaseVisitor *visitor) override;
2034
2035 SourceLocation firstSourceLocation() const override
2036 { return yieldToken; }
2037
2038 SourceLocation lastSourceLocation() const override
2039 { return expression ? expression->lastSourceLocation() : yieldToken; }
2040
2041// attributes
2042 ExpressionNode *expression;
2043 bool isYieldStar = false;
2044 SourceLocation yieldToken;
2045};
2046
2047class QML_PARSER_EXPORT WithStatement: public Statement
2048{
2049public:
2050 QQMLJS_DECLARE_AST_NODE(WithStatement)
2051
2052 WithStatement(ExpressionNode *e, Statement *stmt):
2053 expression (e), statement (stmt)
2054 { kind = K; }
2055
2056 void accept0(BaseVisitor *visitor) override;
2057
2058 SourceLocation firstSourceLocation() const override
2059 { return withToken; }
2060
2061 SourceLocation lastSourceLocation() const override
2062 { return statement->lastSourceLocation(); }
2063
2064// attributes
2065 ExpressionNode *expression;
2066 Statement *statement;
2067 SourceLocation withToken;
2068 SourceLocation lparenToken;
2069 SourceLocation rparenToken;
2070};
2071
2072class QML_PARSER_EXPORT CaseBlock: public Node
2073{
2074public:
2075 QQMLJS_DECLARE_AST_NODE(CaseBlock)
2076
2077 CaseBlock(CaseClauses *c, DefaultClause *d = nullptr, CaseClauses *r = nullptr):
2078 clauses (c), defaultClause (d), moreClauses (r)
2079 { kind = K; }
2080
2081 void accept0(BaseVisitor *visitor) override;
2082
2083 SourceLocation firstSourceLocation() const override
2084 { return lbraceToken; }
2085
2086 SourceLocation lastSourceLocation() const override
2087 { return rbraceToken; }
2088
2089// attributes
2090 CaseClauses *clauses;
2091 DefaultClause *defaultClause;
2092 CaseClauses *moreClauses;
2093 SourceLocation lbraceToken;
2094 SourceLocation rbraceToken;
2095};
2096
2097class QML_PARSER_EXPORT SwitchStatement: public Statement
2098{
2099public:
2100 QQMLJS_DECLARE_AST_NODE(SwitchStatement)
2101
2102 SwitchStatement(ExpressionNode *e, CaseBlock *b):
2103 expression (e), block (b)
2104 { kind = K; }
2105
2106 void accept0(BaseVisitor *visitor) override;
2107
2108 SourceLocation firstSourceLocation() const override
2109 { return switchToken; }
2110
2111 SourceLocation lastSourceLocation() const override
2112 { return block->rbraceToken; }
2113
2114// attributes
2115 ExpressionNode *expression;
2116 CaseBlock *block;
2117 SourceLocation switchToken;
2118 SourceLocation lparenToken;
2119 SourceLocation rparenToken;
2120};
2121
2122class QML_PARSER_EXPORT CaseClause: public Node
2123{
2124public:
2125 QQMLJS_DECLARE_AST_NODE(CaseClause)
2126
2127 CaseClause(ExpressionNode *e, StatementList *slist):
2128 expression (e), statements (slist)
2129 { kind = K; }
2130
2131 void accept0(BaseVisitor *visitor) override;
2132
2133 SourceLocation firstSourceLocation() const override
2134 { return caseToken; }
2135
2136 SourceLocation lastSourceLocation() const override
2137 { return statements ? statements->lastSourceLocation() : colonToken; }
2138
2139// attributes
2140 ExpressionNode *expression;
2141 StatementList *statements;
2142 SourceLocation caseToken;
2143 SourceLocation colonToken;
2144};
2145
2146class QML_PARSER_EXPORT CaseClauses: public Node
2147{
2148public:
2149 QQMLJS_DECLARE_AST_NODE(CaseClauses)
2150
2151 CaseClauses(CaseClause *c):
2152 clause (c), next (this)
2153 { kind = K; }
2154
2155 CaseClauses(CaseClauses *previous, CaseClause *c):
2156 clause (c)
2157 {
2158 kind = K;
2159 next = previous->next;
2160 previous->next = this;
2161 }
2162
2163 void accept0(BaseVisitor *visitor) override;
2164
2165 SourceLocation firstSourceLocation() const override
2166 { return clause->firstSourceLocation(); }
2167
2168 SourceLocation lastSourceLocation() const override
2169 {
2170 return lastListElement(head: this)->clause->lastSourceLocation();
2171 }
2172
2173 inline CaseClauses *finish ()
2174 {
2175 CaseClauses *front = next;
2176 next = nullptr;
2177 return front;
2178 }
2179
2180//attributes
2181 CaseClause *clause;
2182 CaseClauses *next;
2183};
2184
2185class QML_PARSER_EXPORT DefaultClause: public Node
2186{
2187public:
2188 QQMLJS_DECLARE_AST_NODE(DefaultClause)
2189
2190 DefaultClause(StatementList *slist):
2191 statements (slist)
2192 { kind = K; }
2193
2194 void accept0(BaseVisitor *visitor) override;
2195
2196 SourceLocation firstSourceLocation() const override
2197 { return defaultToken; }
2198
2199 SourceLocation lastSourceLocation() const override
2200 { return statements ? statements->lastSourceLocation() : colonToken; }
2201
2202// attributes
2203 StatementList *statements;
2204 SourceLocation defaultToken;
2205 SourceLocation colonToken;
2206};
2207
2208class QML_PARSER_EXPORT LabelledStatement: public Statement
2209{
2210public:
2211 QQMLJS_DECLARE_AST_NODE(LabelledStatement)
2212
2213 LabelledStatement(const QStringRef &l, Statement *stmt):
2214 label (l), statement (stmt)
2215 { kind = K; }
2216
2217 void accept0(BaseVisitor *visitor) override;
2218
2219 SourceLocation firstSourceLocation() const override
2220 { return identifierToken; }
2221
2222 SourceLocation lastSourceLocation() const override
2223 { return statement->lastSourceLocation(); }
2224
2225// attributes
2226 QStringRef label;
2227 Statement *statement;
2228 SourceLocation identifierToken;
2229 SourceLocation colonToken;
2230};
2231
2232class QML_PARSER_EXPORT ThrowStatement: public Statement
2233{
2234public:
2235 QQMLJS_DECLARE_AST_NODE(ThrowStatement)
2236
2237 ThrowStatement(ExpressionNode *e):
2238 expression (e) { kind = K; }
2239
2240 void accept0(BaseVisitor *visitor) override;
2241
2242 SourceLocation firstSourceLocation() const override
2243 { return throwToken; }
2244
2245 SourceLocation lastSourceLocation() const override
2246 { return semicolonToken; }
2247
2248 // attributes
2249 ExpressionNode *expression;
2250 SourceLocation throwToken;
2251 SourceLocation semicolonToken;
2252};
2253
2254class QML_PARSER_EXPORT Catch: public Node
2255{
2256public:
2257 QQMLJS_DECLARE_AST_NODE(Catch)
2258
2259 Catch(PatternElement *p, Block *stmt)
2260 : patternElement(p), statement(stmt)
2261 { kind = K; }
2262
2263 void accept0(BaseVisitor *visitor) override;
2264
2265 SourceLocation firstSourceLocation() const override
2266 { return catchToken; }
2267
2268 SourceLocation lastSourceLocation() const override
2269 { return statement->lastSourceLocation(); }
2270
2271// attributes
2272 PatternElement *patternElement;
2273 Block *statement;
2274 SourceLocation catchToken;
2275 SourceLocation lparenToken;
2276 SourceLocation identifierToken;
2277 SourceLocation rparenToken;
2278};
2279
2280class QML_PARSER_EXPORT Finally: public Node
2281{
2282public:
2283 QQMLJS_DECLARE_AST_NODE(Finally)
2284
2285 Finally(Block *stmt):
2286 statement (stmt)
2287 { kind = K; }
2288
2289 void accept0(BaseVisitor *visitor) override;
2290
2291 SourceLocation firstSourceLocation() const override
2292 { return finallyToken; }
2293
2294 SourceLocation lastSourceLocation() const override
2295 { return statement ? statement->lastSourceLocation() : finallyToken; }
2296
2297// attributes
2298 Block *statement;
2299 SourceLocation finallyToken;
2300};
2301
2302class QML_PARSER_EXPORT TryStatement: public Statement
2303{
2304public:
2305 QQMLJS_DECLARE_AST_NODE(TryStatement)
2306
2307 TryStatement(Statement *stmt, Catch *c, Finally *f):
2308 statement (stmt), catchExpression (c), finallyExpression (f)
2309 { kind = K; }
2310
2311 TryStatement(Statement *stmt, Finally *f):
2312 statement (stmt), catchExpression (nullptr), finallyExpression (f)
2313 { kind = K; }
2314
2315 TryStatement(Statement *stmt, Catch *c):
2316 statement (stmt), catchExpression (c), finallyExpression (nullptr)
2317 { kind = K; }
2318
2319 void accept0(BaseVisitor *visitor) override;
2320
2321 SourceLocation firstSourceLocation() const override
2322 { return tryToken; }
2323
2324 SourceLocation lastSourceLocation() const override
2325 {
2326 if (finallyExpression)
2327 return finallyExpression->statement->rbraceToken;
2328 else if (catchExpression)
2329 return catchExpression->statement->rbraceToken;
2330
2331 return statement->lastSourceLocation();
2332 }
2333
2334// attributes
2335 Statement *statement;
2336 Catch *catchExpression;
2337 Finally *finallyExpression;
2338 SourceLocation tryToken;
2339};
2340
2341class QML_PARSER_EXPORT FunctionExpression: public ExpressionNode
2342{
2343public:
2344 QQMLJS_DECLARE_AST_NODE(FunctionExpression)
2345
2346 FunctionExpression(const QStringRef &n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr):
2347 name (n), formals (f), body (b),
2348 typeAnnotation(typeAnnotation)
2349 { kind = K; }
2350
2351 void accept0(BaseVisitor *visitor) override;
2352
2353 SourceLocation firstSourceLocation() const override
2354 { return functionToken; }
2355
2356 SourceLocation lastSourceLocation() const override
2357 { return rbraceToken; }
2358
2359 FunctionExpression *asFunctionDefinition() override;
2360
2361// attributes
2362 QStringRef name;
2363 bool isArrowFunction = false;
2364 bool isGenerator = false;
2365 FormalParameterList *formals;
2366 StatementList *body;
2367 TypeAnnotation *typeAnnotation;
2368 SourceLocation functionToken;
2369 SourceLocation identifierToken;
2370 SourceLocation lparenToken;
2371 SourceLocation rparenToken;
2372 SourceLocation lbraceToken;
2373 SourceLocation rbraceToken;
2374};
2375
2376class QML_PARSER_EXPORT FunctionDeclaration: public FunctionExpression
2377{
2378public:
2379 QQMLJS_DECLARE_AST_NODE(FunctionDeclaration)
2380
2381 FunctionDeclaration(const QStringRef &n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr):
2382 FunctionExpression(n, f, b, typeAnnotation)
2383 { kind = K; }
2384
2385 void accept0(BaseVisitor *visitor) override;
2386};
2387
2388class QML_PARSER_EXPORT FormalParameterList: public Node
2389{
2390public:
2391 QQMLJS_DECLARE_AST_NODE(FormalParameterList)
2392
2393 FormalParameterList(FormalParameterList *previous, PatternElement *e)
2394 : element(e)
2395 {
2396 kind = K;
2397 if (previous) {
2398 next = previous->next;
2399 previous->next = this;
2400 } else {
2401 next = this;
2402 }
2403 }
2404
2405 FormalParameterList *append(FormalParameterList *n) {
2406 n->next = next;
2407 next = n;
2408 return n;
2409 }
2410
2411 bool isSimpleParameterList()
2412 {
2413 AST::FormalParameterList *formals = this;
2414 while (formals) {
2415 PatternElement *e = formals->element;
2416 if (e && e->type == PatternElement::RestElement)
2417 return false;
2418 if (e && (e->initializer || e->bindingTarget))
2419 return false;
2420 formals = formals->next;
2421 }
2422 return true;
2423 }
2424
2425 int length()
2426 {
2427 // the length property of Function objects
2428 int l = 0;
2429 AST::FormalParameterList *formals = this;
2430 while (formals) {
2431 PatternElement *e = formals->element;
2432 if (!e || e->initializer)
2433 break;
2434 if (e->type == PatternElement::RestElement)
2435 break;
2436 ++l;
2437 formals = formals->next;
2438 }
2439 return l;
2440 }
2441
2442 bool containsName(const QString &name) const {
2443 for (const FormalParameterList *it = this; it; it = it->next) {
2444 PatternElement *b = it->element;
2445 // ### handle binding patterns
2446 if (b && b->bindingIdentifier == name)
2447 return true;
2448 }
2449 return false;
2450 }
2451
2452 BoundNames formals() const;
2453
2454 BoundNames boundNames() const;
2455
2456 void accept0(BaseVisitor *visitor) override;
2457
2458 SourceLocation firstSourceLocation() const override
2459 { return element->firstSourceLocation(); }
2460
2461 SourceLocation lastSourceLocation() const override
2462 {
2463 return lastListElement(head: this)->element->lastSourceLocation();
2464 }
2465
2466 FormalParameterList *finish(MemoryPool *pool);
2467
2468// attributes
2469 PatternElement *element = nullptr;
2470 FormalParameterList *next;
2471};
2472
2473class QML_PARSER_EXPORT ClassExpression : public ExpressionNode
2474{
2475public:
2476 QQMLJS_DECLARE_AST_NODE(ClassExpression)
2477
2478 ClassExpression(const QStringRef &n, ExpressionNode *heritage, ClassElementList *elements)
2479 : name(n), heritage(heritage), elements(elements)
2480 { kind = K; }
2481
2482 void accept0(BaseVisitor *visitor) override;
2483
2484 SourceLocation firstSourceLocation() const override
2485 { return classToken; }
2486
2487 SourceLocation lastSourceLocation() const override
2488 { return rbraceToken; }
2489
2490 ClassExpression *asClassDefinition() override;
2491
2492// attributes
2493 QStringRef name;
2494 ExpressionNode *heritage;
2495 ClassElementList *elements;
2496 SourceLocation classToken;
2497 SourceLocation identifierToken;
2498 SourceLocation lbraceToken;
2499 SourceLocation rbraceToken;
2500};
2501
2502class QML_PARSER_EXPORT ClassDeclaration: public ClassExpression
2503{
2504public:
2505 QQMLJS_DECLARE_AST_NODE(ClassDeclaration)
2506
2507 ClassDeclaration(const QStringRef &n, ExpressionNode *heritage, ClassElementList *elements)
2508 : ClassExpression(n, heritage, elements)
2509 { kind = K; }
2510
2511 void accept0(BaseVisitor *visitor) override;
2512};
2513
2514
2515class QML_PARSER_EXPORT ClassElementList : public Node
2516{
2517public:
2518 QQMLJS_DECLARE_AST_NODE(ClassElementList)
2519
2520 ClassElementList(PatternProperty *property, bool isStatic)
2521 : isStatic(isStatic), property(property)
2522 {
2523 kind = K;
2524 next = this;
2525 }
2526
2527 ClassElementList *append(ClassElementList *n) {
2528 n->next = next;
2529 next = n;
2530 return n;
2531 }
2532
2533 void accept0(BaseVisitor *visitor) override;
2534
2535 SourceLocation firstSourceLocation() const override
2536 { return property->firstSourceLocation(); }
2537
2538 SourceLocation lastSourceLocation() const override
2539 {
2540 if (next)
2541 return next->lastSourceLocation();
2542 return property->lastSourceLocation();
2543 }
2544
2545 ClassElementList *finish();
2546
2547 bool isStatic;
2548 ClassElementList *next;
2549 PatternProperty *property;
2550};
2551
2552class QML_PARSER_EXPORT Program: public Node
2553{
2554public:
2555 QQMLJS_DECLARE_AST_NODE(Program)
2556
2557 Program(StatementList *statements)
2558 : statements(statements)
2559 { kind = K; }
2560
2561 void accept0(BaseVisitor *visitor) override;
2562
2563 SourceLocation firstSourceLocation() const override
2564 { return statements ? statements->firstSourceLocation() : SourceLocation(); }
2565
2566 SourceLocation lastSourceLocation() const override
2567 { return statements ? statements->lastSourceLocation() : SourceLocation(); }
2568
2569// attributes
2570 StatementList *statements;
2571};
2572
2573class QML_PARSER_EXPORT ImportSpecifier: public Node
2574{
2575public:
2576 QQMLJS_DECLARE_AST_NODE(ImportSpecifier)
2577
2578 ImportSpecifier(const QStringRef &importedBinding)
2579 : importedBinding(importedBinding)
2580 {
2581 kind = K;
2582 }
2583
2584 ImportSpecifier(const QStringRef &identifier, const QStringRef &importedBinding)
2585 : identifier(identifier), importedBinding(importedBinding)
2586 {
2587 kind = K;
2588 }
2589
2590 void accept0(BaseVisitor *visitor) override;
2591
2592 SourceLocation firstSourceLocation() const override
2593 { return identifier.isNull() ? importedBindingToken : identifierToken; }
2594 SourceLocation lastSourceLocation() const override
2595 { return importedBindingToken; }
2596
2597// attributes
2598 SourceLocation identifierToken;
2599 SourceLocation importedBindingToken;
2600 QStringRef identifier;
2601 QStringRef importedBinding;
2602};
2603
2604class QML_PARSER_EXPORT ImportsList: public Node
2605{
2606public:
2607 QQMLJS_DECLARE_AST_NODE(ImportsList)
2608
2609 ImportsList(ImportSpecifier *importSpecifier)
2610 : importSpecifier(importSpecifier)
2611 {
2612 kind = K;
2613 next = this;
2614 }
2615
2616 ImportsList(ImportsList *previous, ImportSpecifier *importSpecifier)
2617 : importSpecifier(importSpecifier)
2618 {
2619 kind = K;
2620 if (previous) {
2621 next = previous->next;
2622 previous->next = this;
2623 } else {
2624 next = this;
2625 }
2626 }
2627
2628 ImportsList *finish()
2629 {
2630 ImportsList *head = next;
2631 next = nullptr;
2632 return head;
2633 }
2634
2635 void accept0(BaseVisitor *visitor) override;
2636
2637 SourceLocation firstSourceLocation() const override
2638 { return importSpecifierToken; }
2639
2640 SourceLocation lastSourceLocation() const override
2641 {
2642 return lastListElement(head: this)->importSpecifierToken;
2643 }
2644
2645// attributes
2646 SourceLocation importSpecifierToken;
2647 ImportSpecifier *importSpecifier;
2648 ImportsList *next = this;
2649};
2650
2651class QML_PARSER_EXPORT NamedImports: public Node
2652{
2653public:
2654 QQMLJS_DECLARE_AST_NODE(NamedImports)
2655
2656 NamedImports()
2657 {
2658 kind = K;
2659 }
2660
2661 NamedImports(ImportsList *importsList)
2662 : importsList(importsList)
2663 {
2664 kind = K;
2665 }
2666
2667 void accept0(BaseVisitor *visitor) override;
2668
2669 SourceLocation firstSourceLocation() const override
2670 { return leftBraceToken; }
2671 SourceLocation lastSourceLocation() const override
2672 { return rightBraceToken; }
2673
2674// attributes
2675 SourceLocation leftBraceToken;
2676 SourceLocation rightBraceToken;
2677 ImportsList *importsList = nullptr;
2678};
2679
2680class QML_PARSER_EXPORT NameSpaceImport: public Node
2681{
2682public:
2683 QQMLJS_DECLARE_AST_NODE(NameSpaceImport)
2684
2685 NameSpaceImport(const QStringRef &importedBinding)
2686 : importedBinding(importedBinding)
2687 {
2688 kind = K;
2689 }
2690
2691 void accept0(BaseVisitor *visitor) override;
2692
2693 virtual SourceLocation firstSourceLocation() const override
2694 { return starToken; }
2695 virtual SourceLocation lastSourceLocation() const override
2696 { return importedBindingToken; }
2697
2698// attributes
2699 SourceLocation starToken;
2700 SourceLocation importedBindingToken;
2701 QStringRef importedBinding;
2702};
2703
2704class QML_PARSER_EXPORT ImportClause: public Node
2705{
2706public:
2707 QQMLJS_DECLARE_AST_NODE(ImportClause)
2708
2709 ImportClause(const QStringRef &importedDefaultBinding)
2710 : importedDefaultBinding(importedDefaultBinding)
2711 {
2712 kind = K;
2713 }
2714
2715 ImportClause(NameSpaceImport *nameSpaceImport)
2716 : nameSpaceImport(nameSpaceImport)
2717 {
2718 kind = K;
2719 }
2720
2721 ImportClause(NamedImports *namedImports)
2722 : namedImports(namedImports)
2723 {
2724 kind = K;
2725 }
2726
2727 ImportClause(const QStringRef &importedDefaultBinding, NameSpaceImport *nameSpaceImport)
2728 : importedDefaultBinding(importedDefaultBinding)
2729 , nameSpaceImport(nameSpaceImport)
2730 {
2731 kind = K;
2732 }
2733
2734 ImportClause(const QStringRef &importedDefaultBinding, NamedImports *namedImports)
2735 : importedDefaultBinding(importedDefaultBinding)
2736 , namedImports(namedImports)
2737 {
2738 kind = K;
2739 }
2740
2741 void accept0(BaseVisitor *visitor) override;
2742
2743 virtual SourceLocation firstSourceLocation() const override
2744 { return importedDefaultBinding.isNull() ? (nameSpaceImport ? nameSpaceImport->firstSourceLocation() : namedImports->firstSourceLocation()) : importedDefaultBindingToken; }
2745 virtual SourceLocation lastSourceLocation() const override
2746 { return importedDefaultBinding.isNull() ? (nameSpaceImport ? nameSpaceImport->lastSourceLocation() : namedImports->lastSourceLocation()) : importedDefaultBindingToken; }
2747
2748// attributes
2749 SourceLocation importedDefaultBindingToken;
2750 QStringRef importedDefaultBinding;
2751 NameSpaceImport *nameSpaceImport = nullptr;
2752 NamedImports *namedImports = nullptr;
2753};
2754
2755class QML_PARSER_EXPORT FromClause: public Node
2756{
2757public:
2758 QQMLJS_DECLARE_AST_NODE(FromClause)
2759
2760 FromClause(const QStringRef &moduleSpecifier)
2761 : moduleSpecifier(moduleSpecifier)
2762 {
2763 kind = K;
2764 }
2765
2766 void accept0(BaseVisitor *visitor) override;
2767
2768 SourceLocation firstSourceLocation() const override
2769 { return fromToken; }
2770
2771 SourceLocation lastSourceLocation() const override
2772 { return moduleSpecifierToken; }
2773
2774// attributes
2775 SourceLocation fromToken;
2776 SourceLocation moduleSpecifierToken;
2777 QStringRef moduleSpecifier;
2778};
2779
2780class QML_PARSER_EXPORT ImportDeclaration: public Statement
2781{
2782public:
2783 QQMLJS_DECLARE_AST_NODE(ImportDeclaration)
2784
2785 ImportDeclaration(ImportClause *importClause, FromClause *fromClause)
2786 : importClause(importClause), fromClause(fromClause)
2787 {
2788 kind = K;
2789 }
2790
2791 ImportDeclaration(const QStringRef &moduleSpecifier)
2792 : moduleSpecifier(moduleSpecifier)
2793 {
2794 kind = K;
2795 }
2796
2797 void accept0(BaseVisitor *visitor) override;
2798
2799 SourceLocation firstSourceLocation() const override
2800 { return importToken; }
2801
2802 SourceLocation lastSourceLocation() const override
2803 { return moduleSpecifier.isNull() ? fromClause->lastSourceLocation() : moduleSpecifierToken; }
2804
2805// attributes
2806 SourceLocation importToken;
2807 SourceLocation moduleSpecifierToken;
2808 QStringRef moduleSpecifier;
2809 ImportClause *importClause = nullptr;
2810 FromClause *fromClause = nullptr;
2811};
2812
2813class QML_PARSER_EXPORT ExportSpecifier: public Node
2814{
2815public:
2816 QQMLJS_DECLARE_AST_NODE(ExportSpecifier)
2817
2818 ExportSpecifier(const QStringRef &identifier)
2819 : identifier(identifier), exportedIdentifier(identifier)
2820 {
2821 kind = K;
2822 }
2823
2824 ExportSpecifier(const QStringRef &identifier, const QStringRef &exportedIdentifier)
2825 : identifier(identifier), exportedIdentifier(exportedIdentifier)
2826 {
2827 kind = K;
2828 }
2829
2830 void accept0(BaseVisitor *visitor) override;
2831
2832 SourceLocation firstSourceLocation() const override
2833 { return identifierToken; }
2834 SourceLocation lastSourceLocation() const override
2835 { return exportedIdentifierToken.isValid() ? exportedIdentifierToken : identifierToken; }
2836
2837// attributes
2838 SourceLocation identifierToken;
2839 SourceLocation exportedIdentifierToken;
2840 QStringRef identifier;
2841 QStringRef exportedIdentifier;
2842};
2843
2844class QML_PARSER_EXPORT ExportsList: public Node
2845{
2846public:
2847 QQMLJS_DECLARE_AST_NODE(ExportsList)
2848
2849 ExportsList(ExportSpecifier *exportSpecifier)
2850 : exportSpecifier(exportSpecifier)
2851 {
2852 kind = K;
2853 next = this;
2854 }
2855
2856 ExportsList(ExportsList *previous, ExportSpecifier *exportSpecifier)
2857 : exportSpecifier(exportSpecifier)
2858 {
2859 kind = K;
2860 if (previous) {
2861 next = previous->next;
2862 previous->next = this;
2863 } else {
2864 next = this;
2865 }
2866 }
2867
2868 ExportsList *finish()
2869 {
2870 ExportsList *head = next;
2871 next = nullptr;
2872 return head;
2873 }
2874
2875 void accept0(BaseVisitor *visitor) override;
2876
2877 SourceLocation firstSourceLocation() const override
2878 { return exportSpecifier->firstSourceLocation(); }
2879 SourceLocation lastSourceLocation() const override
2880 { return lastListElement(head: this)->exportSpecifier->lastSourceLocation(); }
2881
2882// attributes
2883 ExportSpecifier *exportSpecifier;
2884 ExportsList *next;
2885};
2886
2887class QML_PARSER_EXPORT ExportClause: public Node
2888{
2889public:
2890 QQMLJS_DECLARE_AST_NODE(ExportClause)
2891
2892 ExportClause()
2893 {
2894 kind = K;
2895 }
2896
2897 ExportClause(ExportsList *exportsList)
2898 : exportsList(exportsList)
2899 {
2900 kind = K;
2901 }
2902
2903 void accept0(BaseVisitor *visitor) override;
2904
2905 SourceLocation firstSourceLocation() const override
2906 { return leftBraceToken; }
2907 SourceLocation lastSourceLocation() const override
2908 { return rightBraceToken; }
2909
2910// attributes
2911 SourceLocation leftBraceToken;
2912 SourceLocation rightBraceToken;
2913 ExportsList *exportsList = nullptr;
2914};
2915
2916class QML_PARSER_EXPORT ExportDeclaration: public Statement
2917{
2918public:
2919 QQMLJS_DECLARE_AST_NODE(ExportDeclaration)
2920
2921 ExportDeclaration(FromClause *fromClause)
2922 : fromClause(fromClause)
2923 {
2924 exportAll = true;
2925 kind = K;
2926 }
2927
2928 ExportDeclaration(ExportClause *exportClause, FromClause *fromClause)
2929 : exportClause(exportClause), fromClause(fromClause)
2930 {
2931 kind = K;
2932 }
2933
2934 ExportDeclaration(ExportClause *exportClause)
2935 : exportClause(exportClause)
2936 {
2937 kind = K;
2938 }
2939
2940 ExportDeclaration(bool exportDefault, Node *variableStatementOrDeclaration)
2941 : variableStatementOrDeclaration(variableStatementOrDeclaration)
2942 , exportDefault(exportDefault)
2943 {
2944 kind = K;
2945 }
2946
2947 void accept0(BaseVisitor *visitor) override;
2948
2949 SourceLocation firstSourceLocation() const override
2950 { return exportToken; }
2951 SourceLocation lastSourceLocation() const override
2952 { return fromClause ? fromClause->lastSourceLocation() : (exportClause ? exportClause->lastSourceLocation() : variableStatementOrDeclaration->lastSourceLocation()); }
2953
2954// attributes
2955 SourceLocation exportToken;
2956 bool exportAll = false;
2957 ExportClause *exportClause = nullptr;
2958 FromClause *fromClause = nullptr;
2959 Node *variableStatementOrDeclaration = nullptr;
2960 bool exportDefault = false;
2961};
2962
2963class QML_PARSER_EXPORT ESModule: public Node
2964{
2965public:
2966 QQMLJS_DECLARE_AST_NODE(Module)
2967
2968 ESModule(StatementList *body)
2969 : body(body)
2970 {
2971 kind = K;
2972 }
2973
2974 void accept0(BaseVisitor *visitor) override;
2975
2976 SourceLocation firstSourceLocation() const override
2977 { return body ? body->firstSourceLocation() : SourceLocation(); }
2978
2979 SourceLocation lastSourceLocation() const override
2980 { return body ? body->lastSourceLocation() : SourceLocation(); }
2981
2982// attributes
2983 StatementList *body;
2984};
2985
2986class QML_PARSER_EXPORT DebuggerStatement: public Statement
2987{
2988public:
2989 QQMLJS_DECLARE_AST_NODE(DebuggerStatement)
2990
2991 DebuggerStatement()
2992 { kind = K; }
2993
2994 void accept0(BaseVisitor *visitor) override;
2995
2996 SourceLocation firstSourceLocation() const override
2997 { return debuggerToken; }
2998
2999 SourceLocation lastSourceLocation() const override
3000 { return semicolonToken; }
3001
3002// attributes
3003 SourceLocation debuggerToken;
3004 SourceLocation semicolonToken;
3005};
3006
3007class QML_PARSER_EXPORT UiImport: public Node
3008{
3009public:
3010 QQMLJS_DECLARE_AST_NODE(UiImport)
3011
3012 UiImport(const QStringRef &fileName)
3013 : fileName(fileName), importUri(nullptr)
3014 { kind = K; }
3015
3016 UiImport(UiQualifiedId *uri)
3017 : importUri(uri)
3018 { kind = K; }
3019
3020 void accept0(BaseVisitor *visitor) override;
3021
3022 SourceLocation firstSourceLocation() const override
3023 { return importToken; }
3024
3025 SourceLocation lastSourceLocation() const override
3026 { return semicolonToken; }
3027
3028// attributes
3029 QStringRef fileName;
3030 UiQualifiedId *importUri;
3031 QStringRef importId;
3032 SourceLocation importToken;
3033 SourceLocation fileNameToken;
3034 SourceLocation asToken;
3035 SourceLocation importIdToken;
3036 SourceLocation semicolonToken;
3037 UiVersionSpecifier *version = nullptr;
3038};
3039
3040class QML_PARSER_EXPORT UiObjectMember: public Node
3041{
3042public:
3043 SourceLocation firstSourceLocation() const override = 0;
3044 SourceLocation lastSourceLocation() const override = 0;
3045
3046 UiObjectMember *uiObjectMemberCast() override;
3047
3048// attributes
3049 UiAnnotationList *annotations = nullptr;
3050};
3051
3052class QML_PARSER_EXPORT UiObjectMemberList: public Node
3053{
3054public:
3055 QQMLJS_DECLARE_AST_NODE(UiObjectMemberList)
3056
3057 UiObjectMemberList(UiObjectMember *member)
3058 : next(this), member(member)
3059 { kind = K; }
3060
3061 UiObjectMemberList(UiObjectMemberList *previous, UiObjectMember *member)
3062 : member(member)
3063 {
3064 kind = K;
3065 next = previous->next;
3066 previous->next = this;
3067 }
3068
3069 void accept0(BaseVisitor *visitor) override;
3070
3071 SourceLocation firstSourceLocation() const override
3072 { return member->firstSourceLocation(); }
3073
3074 SourceLocation lastSourceLocation() const override
3075 { return lastListElement(head: this)->member->lastSourceLocation(); }
3076
3077 UiObjectMemberList *finish()
3078 {
3079 UiObjectMemberList *head = next;
3080 next = nullptr;
3081 return head;
3082 }
3083
3084// attributes
3085 UiObjectMemberList *next;
3086 UiObjectMember *member;
3087};
3088
3089class QML_PARSER_EXPORT UiPragma: public Node
3090{
3091public:
3092 QQMLJS_DECLARE_AST_NODE(UiPragma)
3093
3094 UiPragma(QStringRef name)
3095 : name(name)
3096 { kind = K; }
3097
3098 void accept0(BaseVisitor *visitor) override;
3099
3100 SourceLocation firstSourceLocation() const override
3101 { return pragmaToken; }
3102
3103 SourceLocation lastSourceLocation() const override
3104 { return semicolonToken; }
3105
3106// attributes
3107 QStringRef name;
3108 SourceLocation pragmaToken;
3109 SourceLocation semicolonToken;
3110};
3111
3112class QML_PARSER_EXPORT UiRequired: public Node
3113{
3114public:
3115 QQMLJS_DECLARE_AST_NODE(UiRequired)
3116
3117 UiRequired(QStringRef name)
3118 :name(name)
3119 { kind = K; }
3120
3121 void accept0(BaseVisitor *visitor) override;
3122
3123 SourceLocation firstSourceLocation() const override
3124 { return requiredToken; }
3125
3126 SourceLocation lastSourceLocation() const override
3127 { return semicolonToken; }
3128
3129 QStringRef name;
3130 SourceLocation requiredToken;
3131 SourceLocation semicolonToken;
3132};
3133
3134class QML_PARSER_EXPORT UiHeaderItemList: public Node
3135{
3136public:
3137 QQMLJS_DECLARE_AST_NODE(UiHeaderItemList)
3138
3139 UiHeaderItemList(UiImport *import)
3140 : headerItem(import), next(this)
3141 { kind = K; }
3142
3143 UiHeaderItemList(UiPragma *pragma)
3144 : headerItem(pragma), next(this)
3145 { kind = K; }
3146
3147 UiHeaderItemList(UiHeaderItemList *previous, UiImport *import)
3148 : headerItem(import)
3149 {
3150 kind = K;
3151 next = previous->next;
3152 previous->next = this;
3153 }
3154
3155 UiHeaderItemList(UiHeaderItemList *previous, UiPragma *pragma)
3156 : headerItem(pragma)
3157 {
3158 kind = K;
3159 next = previous->next;
3160 previous->next = this;
3161 }
3162
3163 UiHeaderItemList *finish()
3164 {
3165 UiHeaderItemList *head = next;
3166 next = nullptr;
3167 return head;
3168 }
3169
3170 void accept0(BaseVisitor *visitor) override;
3171
3172 SourceLocation firstSourceLocation() const override
3173 { return headerItem->firstSourceLocation(); }
3174
3175 SourceLocation lastSourceLocation() const override
3176 { return lastListElement(head: this)->headerItem->lastSourceLocation(); }
3177
3178// attributes
3179 Node *headerItem;
3180 UiHeaderItemList *next;
3181};
3182
3183class QML_PARSER_EXPORT UiProgram: public Node
3184{
3185public:
3186 QQMLJS_DECLARE_AST_NODE(UiProgram)
3187
3188 UiProgram(UiHeaderItemList *headers, UiObjectMemberList *members)
3189 : headers(headers), members(members)
3190 { kind = K; }
3191
3192 void accept0(BaseVisitor *visitor) override;
3193
3194 SourceLocation firstSourceLocation() const override
3195 {
3196 if (headers)
3197 return headers->firstSourceLocation();
3198 else if (members)
3199 return members->firstSourceLocation();
3200 return SourceLocation();
3201 }
3202
3203 SourceLocation lastSourceLocation() const override
3204 {
3205 if (members)
3206 return members->lastSourceLocation();
3207 else if (headers)
3208 return headers->lastSourceLocation();
3209 return SourceLocation();
3210 }
3211
3212// attributes
3213 UiHeaderItemList *headers;
3214 UiObjectMemberList *members;
3215};
3216
3217class QML_PARSER_EXPORT UiArrayMemberList: public Node
3218{
3219public:
3220 QQMLJS_DECLARE_AST_NODE(UiArrayMemberList)
3221
3222 UiArrayMemberList(UiObjectMember *member)
3223 : next(this), member(member)
3224 { kind = K; }
3225
3226 UiArrayMemberList(UiArrayMemberList *previous, UiObjectMember *member)
3227 : member(member)
3228 {
3229 kind = K;
3230 next = previous->next;
3231 previous->next = this;
3232 }
3233
3234 void accept0(BaseVisitor *visitor) override;
3235
3236 SourceLocation firstSourceLocation() const override
3237 { return member->firstSourceLocation(); }
3238
3239 SourceLocation lastSourceLocation() const override
3240 { return lastListElement(head: this)->member->lastSourceLocation(); }
3241
3242 UiArrayMemberList *finish()
3243 {
3244 UiArrayMemberList *head = next;
3245 next = nullptr;
3246 return head;
3247 }
3248
3249// attributes
3250 UiArrayMemberList *next;
3251 UiObjectMember *member;
3252 SourceLocation commaToken;
3253};
3254
3255class QML_PARSER_EXPORT UiObjectInitializer: public Node
3256{
3257public:
3258 QQMLJS_DECLARE_AST_NODE(UiObjectInitializer)
3259
3260 UiObjectInitializer(UiObjectMemberList *members)
3261 : members(members)
3262 { kind = K; }
3263
3264 void accept0(BaseVisitor *visitor) override;
3265
3266 SourceLocation firstSourceLocation() const override
3267 { return lbraceToken; }
3268
3269 SourceLocation lastSourceLocation() const override
3270 { return rbraceToken; }
3271
3272// attributes
3273 SourceLocation lbraceToken;
3274 UiObjectMemberList *members;
3275 SourceLocation rbraceToken;
3276};
3277
3278class QML_PARSER_EXPORT UiParameterList: public Node
3279{
3280public:
3281 QQMLJS_DECLARE_AST_NODE(UiParameterList)
3282
3283 UiParameterList(UiQualifiedId *t, const QStringRef &n):
3284 type (t), name (n), next (this)
3285 { kind = K; }
3286
3287 UiParameterList(UiParameterList *previous, UiQualifiedId *t, const QStringRef &n):
3288 type (t), name (n)
3289 {
3290 kind = K;
3291 next = previous->next;
3292 previous->next = this;
3293 }
3294
3295 void accept0(BaseVisitor *) override;
3296
3297 SourceLocation firstSourceLocation() const override
3298 { return colonToken.isValid() ? identifierToken : propertyTypeToken; }
3299
3300 SourceLocation lastSourceLocation() const override
3301 {
3302 auto last = lastListElement(head: this);
3303 return (last->colonToken.isValid() ? last->propertyTypeToken : last->identifierToken);
3304 }
3305
3306 inline UiParameterList *finish ()
3307 {
3308 UiParameterList *front = next;
3309 next = nullptr;
3310 return front;
3311 }
3312
3313// attributes
3314 UiQualifiedId *type;
3315 QStringRef name;
3316 UiParameterList *next;
3317 SourceLocation commaToken;
3318 SourceLocation propertyTypeToken;
3319 SourceLocation identifierToken;
3320 SourceLocation colonToken;
3321};
3322
3323class QML_PARSER_EXPORT UiPublicMember: public UiObjectMember
3324{
3325public:
3326 QQMLJS_DECLARE_AST_NODE(UiPublicMember)
3327
3328 UiPublicMember(UiQualifiedId *memberType,
3329 const QStringRef &name)
3330 : type(Property), memberType(memberType), name(name), statement(nullptr), binding(nullptr), isDefaultMember(false), isReadonlyMember(false), parameters(nullptr)
3331 { kind = K; }
3332
3333 UiPublicMember(UiQualifiedId *memberType,
3334 const QStringRef &name,
3335 Statement *statement)
3336 : type(Property), memberType(memberType), name(name), statement(statement), binding(nullptr), isDefaultMember(false), isReadonlyMember(false), parameters(nullptr)
3337 { kind = K; }
3338
3339 void accept0(BaseVisitor *visitor) override;
3340
3341 SourceLocation firstSourceLocation() const override
3342 {
3343 if (defaultToken.isValid())
3344 return defaultToken;
3345 else if (readonlyToken.isValid())
3346 return readonlyToken;
3347 else if (requiredToken.isValid())
3348 return requiredToken;
3349
3350 return propertyToken;
3351 }
3352
3353 SourceLocation lastSourceLocation() const override
3354 {
3355 if (binding)
3356 return binding->lastSourceLocation();
3357 if (statement)
3358 return statement->lastSourceLocation();
3359
3360 return semicolonToken;
3361 }
3362
3363// attributes
3364 enum { Signal, Property } type;
3365 QStringRef typeModifier;
3366 UiQualifiedId *memberType;
3367 QStringRef name;
3368 Statement *statement; // initialized with a JS expression
3369 UiObjectMember *binding; // initialized with a QML object or array.
3370 bool isDefaultMember;
3371 bool isReadonlyMember;
3372 bool isRequired = false;
3373 UiParameterList *parameters;
3374 // TODO: merge source locations
3375 SourceLocation defaultToken;
3376 SourceLocation readonlyToken;
3377 SourceLocation propertyToken;
3378 SourceLocation requiredToken;
3379 SourceLocation typeModifierToken;
3380 SourceLocation typeToken;
3381 SourceLocation identifierToken;
3382 SourceLocation colonToken;
3383 SourceLocation semicolonToken;
3384};
3385
3386class QML_PARSER_EXPORT UiObjectDefinition: public UiObjectMember
3387{
3388public:
3389 QQMLJS_DECLARE_AST_NODE(UiObjectDefinition)
3390
3391 UiObjectDefinition(UiQualifiedId *qualifiedTypeNameId,
3392 UiObjectInitializer *initializer)
3393 : qualifiedTypeNameId(qualifiedTypeNameId), initializer(initializer)
3394 { kind = K; }
3395
3396 void accept0(BaseVisitor *visitor) override;
3397
3398 SourceLocation firstSourceLocation() const override
3399 { return qualifiedTypeNameId->identifierToken; }
3400
3401 SourceLocation lastSourceLocation() const override
3402 { return initializer->rbraceToken; }
3403
3404// attributes
3405 UiQualifiedId *qualifiedTypeNameId;
3406 UiObjectInitializer *initializer;
3407};
3408
3409class QML_PARSER_EXPORT UiInlineComponent: public UiObjectMember
3410{
3411public:
3412 QQMLJS_DECLARE_AST_NODE(UiInlineComponent)
3413
3414 UiInlineComponent(const QStringRef& inlineComponentName, UiObjectDefinition* inlineComponent)
3415 : name(inlineComponentName), component(inlineComponent)
3416 { kind = K; }
3417
3418 SourceLocation lastSourceLocation() const override
3419 {return component->lastSourceLocation();}
3420
3421 SourceLocation firstSourceLocation() const override
3422 {return componentToken;}
3423
3424 void accept0(BaseVisitor *visitor) override;
3425
3426 // attributes
3427 QStringRef name;
3428 UiObjectDefinition* component;
3429 SourceLocation componentToken;
3430};
3431
3432class QML_PARSER_EXPORT UiSourceElement: public UiObjectMember
3433{
3434public:
3435 QQMLJS_DECLARE_AST_NODE(UiSourceElement)
3436
3437 UiSourceElement(Node *sourceElement)
3438 : sourceElement(sourceElement)
3439 { kind = K; }
3440
3441 SourceLocation firstSourceLocation() const override
3442 {
3443 if (FunctionExpression *funDecl = sourceElement->asFunctionDefinition())
3444 return funDecl->firstSourceLocation();
3445 else if (VariableStatement *varStmt = cast<VariableStatement *>(ast: sourceElement))
3446 return varStmt->firstSourceLocation();
3447
3448 return SourceLocation();
3449 }
3450
3451 SourceLocation lastSourceLocation() const override
3452 {
3453 if (FunctionExpression *funDecl = sourceElement->asFunctionDefinition())
3454 return funDecl->lastSourceLocation();
3455 else if (VariableStatement *varStmt = cast<VariableStatement *>(ast: sourceElement))
3456 return varStmt->lastSourceLocation();
3457
3458 return SourceLocation();
3459 }
3460
3461 void accept0(BaseVisitor *visitor) override;
3462
3463
3464// attributes
3465 Node *sourceElement;
3466};
3467
3468class QML_PARSER_EXPORT UiObjectBinding: public UiObjectMember
3469{
3470public:
3471 QQMLJS_DECLARE_AST_NODE(UiObjectBinding)
3472
3473 UiObjectBinding(UiQualifiedId *qualifiedId,
3474 UiQualifiedId *qualifiedTypeNameId,
3475 UiObjectInitializer *initializer)
3476 : qualifiedId(qualifiedId),
3477 qualifiedTypeNameId(qualifiedTypeNameId),
3478 initializer(initializer),
3479 hasOnToken(false)
3480 { kind = K; }
3481
3482 SourceLocation firstSourceLocation() const override
3483 {
3484 if (hasOnToken && qualifiedTypeNameId)
3485 return qualifiedTypeNameId->identifierToken;
3486
3487 return qualifiedId->identifierToken;
3488 }
3489
3490 SourceLocation lastSourceLocation() const override
3491 { return initializer->rbraceToken; }
3492
3493 void accept0(BaseVisitor *visitor) override;
3494
3495
3496// attributes
3497 UiQualifiedId *qualifiedId;
3498 UiQualifiedId *qualifiedTypeNameId;
3499 UiObjectInitializer *initializer;
3500 SourceLocation colonToken;
3501 bool hasOnToken;
3502};
3503
3504class QML_PARSER_EXPORT UiScriptBinding: public UiObjectMember
3505{
3506public:
3507 QQMLJS_DECLARE_AST_NODE(UiScriptBinding)
3508
3509 UiScriptBinding(UiQualifiedId *qualifiedId,
3510 Statement *statement)
3511 : qualifiedId(qualifiedId),
3512 statement(statement)
3513 { kind = K; }
3514
3515 SourceLocation firstSourceLocation() const override
3516 { return qualifiedId->identifierToken; }
3517
3518 SourceLocation lastSourceLocation() const override
3519 { return statement->lastSourceLocation(); }
3520
3521 void accept0(BaseVisitor *visitor) override;
3522
3523// attributes
3524 UiQualifiedId *qualifiedId;
3525 Statement *statement;
3526 SourceLocation colonToken;
3527};
3528
3529class QML_PARSER_EXPORT UiArrayBinding: public UiObjectMember
3530{
3531public:
3532 QQMLJS_DECLARE_AST_NODE(UiArrayBinding)
3533
3534 UiArrayBinding(UiQualifiedId *qualifiedId,
3535 UiArrayMemberList *members)
3536 : qualifiedId(qualifiedId),
3537 members(members)
3538 { kind = K; }
3539
3540 SourceLocation firstSourceLocation() const override
3541 { return qualifiedId->identifierToken; }
3542
3543 SourceLocation lastSourceLocation() const override
3544 { return rbracketToken; }
3545
3546 void accept0(BaseVisitor *visitor) override;
3547
3548// attributes
3549 UiQualifiedId *qualifiedId;
3550 UiArrayMemberList *members;
3551 SourceLocation colonToken;
3552 SourceLocation lbracketToken;
3553 SourceLocation rbracketToken;
3554};
3555
3556class QML_PARSER_EXPORT UiEnumMemberList: public Node
3557{
3558 QQMLJS_DECLARE_AST_NODE(UiEnumMemberList)
3559public:
3560 UiEnumMemberList(const QStringRef &member, double v = 0.0)
3561 : next(this), member(member), value(v)
3562 { kind = K; }
3563
3564 UiEnumMemberList(UiEnumMemberList *previous, const QStringRef &member)
3565 : member(member)
3566 {
3567 kind = K;
3568 next = previous->next;
3569 previous->next = this;
3570 value = previous->value + 1;
3571 }
3572
3573 UiEnumMemberList(UiEnumMemberList *previous, const QStringRef &member, double v)
3574 : member(member), value(v)
3575 {
3576 kind = K;
3577 next = previous->next;
3578 previous->next = this;
3579 }
3580
3581 SourceLocation firstSourceLocation() const override
3582 { return memberToken; }
3583
3584 SourceLocation lastSourceLocation() const override
3585 {
3586 auto last = lastListElement(head: this);
3587 return last->valueToken.isValid() ? last->valueToken : last->memberToken;
3588 }
3589
3590 void accept0(BaseVisitor *visitor) override;
3591
3592 UiEnumMemberList *finish()
3593 {
3594 UiEnumMemberList *head = next;
3595 next = nullptr;
3596 return head;
3597 }
3598
3599// attributes
3600 UiEnumMemberList *next;
3601 QStringRef member;
3602 double value;
3603 SourceLocation memberToken;
3604 SourceLocation valueToken;
3605};
3606
3607class QML_PARSER_EXPORT UiEnumDeclaration: public UiObjectMember
3608{
3609public:
3610 QQMLJS_DECLARE_AST_NODE(UiEnumDeclaration)
3611
3612 UiEnumDeclaration(const QStringRef &name,
3613 UiEnumMemberList *members)
3614 : name(name)
3615 , members(members)
3616 { kind = K; }
3617
3618 SourceLocation firstSourceLocation() const override
3619 { return enumToken; }
3620
3621 SourceLocation lastSourceLocation() const override
3622 { return rbraceToken; }
3623
3624 void accept0(BaseVisitor *visitor) override;
3625
3626// attributes
3627 SourceLocation enumToken;
3628 SourceLocation rbraceToken;
3629 QStringRef name;
3630 UiEnumMemberList *members;
3631};
3632
3633class QML_PARSER_EXPORT UiAnnotation: public Node
3634{
3635public:
3636 QQMLJS_DECLARE_AST_NODE(UiAnnotation)
3637
3638 UiAnnotation(UiQualifiedId *qualifiedTypeNameId,
3639 UiObjectInitializer *initializer)
3640 : qualifiedTypeNameId(qualifiedTypeNameId), initializer(initializer)
3641 { kind = K; }
3642
3643 void accept0(BaseVisitor *visitor) override;
3644
3645 SourceLocation firstSourceLocation() const override
3646 { return qualifiedTypeNameId->identifierToken; }
3647
3648 SourceLocation lastSourceLocation() const override
3649 { return initializer->rbraceToken; }
3650
3651// attributes
3652 UiQualifiedId *qualifiedTypeNameId;
3653 UiObjectInitializer *initializer;
3654};
3655
3656class QML_PARSER_EXPORT UiAnnotationList: public Node
3657{
3658public:
3659 QQMLJS_DECLARE_AST_NODE(UiAnnotationList)
3660
3661 UiAnnotationList(UiAnnotation *annotation)
3662 : next(this), annotation(annotation)
3663 { kind = K; }
3664
3665 UiAnnotationList(UiAnnotationList *previous, UiAnnotation *annotation)
3666 : annotation(annotation)
3667 {
3668 kind = K;
3669 next = previous->next;
3670 previous->next = this;
3671 }
3672
3673 void accept0(BaseVisitor *visitor) override;
3674
3675 SourceLocation firstSourceLocation() const override
3676 { return annotation->firstSourceLocation(); }
3677
3678 SourceLocation lastSourceLocation() const override
3679 { return lastListElement(head: this)->annotation->lastSourceLocation(); }
3680
3681 UiAnnotationList *finish()
3682 {
3683 UiAnnotationList *head = next;
3684 next = nullptr;
3685 return head;
3686 }
3687
3688// attributes
3689 UiAnnotationList *next;
3690 UiAnnotation *annotation;
3691};
3692
3693} } // namespace AST
3694
3695
3696QT_END_NAMESPACE
3697
3698#endif
3699

source code of qtdeclarative/src/qml/parser/qqmljsast_p.h