Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qqmljsast.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QString>
5#include <QLocale>
7#include "qqmljsast_p.h"
8
10#include <qlocale.h>
11
12#include <algorithm>
13#include <array>
14
16
17namespace QQmlJS { namespace AST {
18
20{
21 if (!n)
22 return nullptr;
24 if (!f || !f->name.isNull())
25 return nullptr;
26 return f;
27}
28
30{
31 if (!n)
32 return nullptr;
34 if (!c || !c->name.isNull())
35 return nullptr;
36 return c;
37}
38
40{
41 return nullptr;
42}
43
45{
46 return nullptr;
47}
48
50{
51 return nullptr;
52}
53
55{
56 return nullptr;
57}
58
60{
61 return nullptr;
62}
63
65{
66 return nullptr;
67}
68
70{
71 return nullptr;
72}
73
75{
76 return nullptr;
77}
78
80{
81 static const bool doIgnore = qEnvironmentVariableIsSet("QV4_CRASH_ON_STACKOVERFLOW");
82 return doIgnore;
83}
84
86{
87 return this;
88}
89
91{
92 for (const Node *node = this;;) {
93 switch (node->kind) {
95 const auto *fme = AST::cast<const FieldMemberExpression*>(node);
96 if (fme->isOptional)
97 return true;
98 node = fme->base;
99 break;
100 }
102 const auto *ame = AST::cast<const ArrayMemberExpression*>(node);
103 if (ame->isOptional)
104 return true;
105 node = ame->base;
106 break;
107 }
108 case Kind_CallExpression: {
109 const auto *ce = AST::cast<const CallExpression*>(node);
110 if (ce->isOptional)
111 return true;
112 node = ce->base;
113 break;
114 }
116 const auto *ne = AST::cast<const NestedExpression*>(node);
117 node = ne->expression;
118 break;
119 }
120 default:
121 // These unhandled nodes lead to invalid lvalues anyway, so they do not need to be handled here.
122 return false;
123 }
124 }
125 return false;
126}
127
129{
130 AST::ExpressionNode *expr = this;
131 AST::FormalParameterList *f = nullptr;
132 if (AST::Expression *commaExpr = AST::cast<AST::Expression *>(expr)) {
133 f = commaExpr->left->reparseAsFormalParameterList(pool);
134 if (!f)
135 return nullptr;
136
137 expr = commaExpr->right;
138 }
139
140 AST::ExpressionNode *rhs = nullptr;
141 if (AST::BinaryExpression *assign = AST::cast<AST::BinaryExpression *>(expr)) {
142 if (assign->op != QSOperator::Assign)
143 return nullptr;
144 expr = assign->left;
145 rhs = assign->right;
146 }
147 AST::PatternElement *binding = nullptr;
148 if (AST::IdentifierExpression *idExpr = AST::cast<AST::IdentifierExpression *>(expr)) {
149 binding = new (pool) AST::PatternElement(idExpr->name, /*type annotation*/nullptr, rhs);
150 binding->identifierToken = idExpr->identifierToken;
151 } else if (AST::Pattern *p = expr->patternCast()) {
152 SourceLocation loc;
153 QString s;
154 if (!p->convertLiteralToAssignmentPattern(pool, &loc, &s))
155 return nullptr;
156 binding = new (pool) AST::PatternElement(p, rhs);
157 binding->identifierToken = p->firstSourceLocation();
158 }
159 if (!binding)
160 return nullptr;
161 return new (pool) AST::FormalParameterList(f, binding);
162}
163
165{
166 return this;
167}
168
170{
171 visitor->visit(this);
172 visitor->endVisit(this);
173}
174
176{
177 return this;
178}
179
181{
182 return this;
183}
184
186{
187 if (visitor->visit(this)) {
188 accept(expression, visitor);
189 }
190 visitor->endVisit(this);
191}
192
194{
196}
197
199{
201}
202
204{
205 if (visitor->visit(this)) {
206 }
207
208 visitor->endVisit(this);
209}
210
212{
213 if (visitor->visit(this)) {
214 }
215
216 visitor->endVisit(this);
217}
218
220{
221 if (visitor->visit(this)) {
222 }
223
224 visitor->endVisit(this);
225}
226
228{
229 if (visitor->visit(this)) {
230 }
231
232 visitor->endVisit(this);
233}
234
236{
237 if (visitor->visit(this)) {
238 }
239
240 visitor->endVisit(this);
241}
242
244{
245 if (visitor->visit(this)) {
246 }
247
248 visitor->endVisit(this);
249}
250
251
253{
254 if (visitor->visit(this)) {
255 }
256
257 visitor->endVisit(this);
258}
259
261{
262 bool accepted = true;
263 for (TemplateLiteral *it = this; it && accepted; it = it->next) {
264 accepted = visitor->visit(it);
265 visitor->endVisit(it);
266 }
267}
268
270{
271 if (visitor->visit(this)) {
272 }
273
274 visitor->endVisit(this);
275}
276
278{
279 if (visitor->visit(this)) {
280 }
281
282 visitor->endVisit(this);
283}
284
286{
287 if (visitor->visit(this))
288 accept(elements, visitor);
289
290 visitor->endVisit(this);
291}
292
294 for (PatternElementList *it = elements; it != nullptr; it = it->next) {
295 PatternElement *e = it->element;
296 if (e && e->bindingTarget != nullptr) {
297 if (errorLocation)
298 *errorLocation = e->firstSourceLocation();
299 return false;
300 }
301 }
302 return true;
303}
304
306{
307 if (visitor->visit(this)) {
308 accept(properties, visitor);
309 }
310
311 visitor->endVisit(this);
312}
313
314/*
315 This is the grammar for AssignmentPattern that we need to convert the literal to:
316
317 AssignmentPattern:
318 ObjectAssignmentPattern
319 ArrayAssignmentPattern
320 ArrayAssignmentPattern:
321 [ ElisionOpt AssignmentRestElementOpt ]
322 [ AssignmentElementList ]
323 [ AssignmentElementList , ElisionOpt AssignmentRestElementOpt ]
324 AssignmentElementList:
325 AssignmentElisionElement
326 AssignmentElementList , AssignmentElisionElement
327 AssignmentElisionElement:
328 ElisionOpt AssignmentElement
329 AssignmentRestElement:
330 ... DestructuringAssignmentTarget
331
332 ObjectAssignmentPattern:
333 {}
334 { AssignmentPropertyList }
335 { AssignmentPropertyList, }
336 AssignmentPropertyList:
337 AssignmentProperty
338 AssignmentPropertyList , AssignmentProperty
339 AssignmentProperty:
340 IdentifierReference InitializerOpt_In
341 PropertyName:
342 AssignmentElement
343
344 AssignmentElement:
345 DestructuringAssignmentTarget InitializerOpt_In
346 DestructuringAssignmentTarget:
347 LeftHandSideExpression
348
349 It was originally parsed with the following grammar:
350
351ArrayLiteral:
352 [ ElisionOpt ]
353 [ ElementList ]
354 [ ElementList , ElisionOpt ]
355ElementList:
356 ElisionOpt AssignmentExpression_In
357 ElisionOpt SpreadElement
358 ElementList , ElisionOpt AssignmentExpression_In
359 ElementList , Elisionopt SpreadElement
360SpreadElement:
361 ... AssignmentExpression_In
362ObjectLiteral:
363 {}
364 { PropertyDefinitionList }
365 { PropertyDefinitionList , }
366PropertyDefinitionList:
367 PropertyDefinition
368 PropertyDefinitionList , PropertyDefinition
369PropertyDefinition:
370 IdentifierReference
371 CoverInitializedName
372 PropertyName : AssignmentExpression_In
373 MethodDefinition
374PropertyName:
375 LiteralPropertyName
376 ComputedPropertyName
377
378*/
380{
381 if (parseMode == Binding)
382 return true;
383 for (auto *it = elements; it; it = it->next) {
384 if (!it->element)
385 continue;
386 if (it->element->type == PatternElement::SpreadElement && it->next) {
387 *errorLocation = it->element->firstSourceLocation();
388 *errorMessage = QString::fromLatin1("'...' can only appear as last element in a destructuring list.");
389 return false;
390 }
391 if (!it->element->convertLiteralToAssignmentPattern(pool, errorLocation, errorMessage))
392 return false;
393 }
395 return true;
396}
397
399{
400 if (parseMode == Binding)
401 return true;
402 for (auto *it = properties; it; it = it->next) {
403 if (!it->property->convertLiteralToAssignmentPattern(pool, errorLocation, errorMessage))
404 return false;
405 }
407 return true;
408}
409
411{
414 Q_ASSERT(bindingTarget == nullptr);
415 Q_ASSERT(bindingTarget == nullptr);
418
419 initializer = nullptr;
420 LeftHandSideExpression *lhs = init->leftHandSideExpressionCast();
421 if (type == SpreadElement) {
422 if (!lhs) {
423 *errorLocation = init->firstSourceLocation();
424 *errorMessage = QString::fromLatin1("Invalid lhs expression after '...' in destructuring expression.");
425 return false;
426 }
427 } else {
429
430 if (BinaryExpression *b = init->binaryExpressionCast()) {
431 if (b->op != QSOperator::Assign) {
432 *errorLocation = b->operatorToken;
433 *errorMessage = QString::fromLatin1("Invalid assignment operation in destructuring expression");
434 return false;
435 }
436 lhs = b->left->leftHandSideExpressionCast();
437 initializer = b->right;
438 Q_ASSERT(lhs);
439 } else {
440 lhs = init->leftHandSideExpressionCast();
441 }
442 if (!lhs) {
443 *errorLocation = init->firstSourceLocation();
444 *errorMessage = QString::fromLatin1("Destructuring target is not a left hand side expression.");
445 return false;
446 }
447 }
448
449 if (auto *i = cast<IdentifierExpression *>(lhs)) {
450 bindingIdentifier = i->name;
451 identifierToken = i->identifierToken;
452 return true;
453 }
454
455 bindingTarget = lhs;
456 if (auto *p = lhs->patternCast()) {
457 if (!p->convertLiteralToAssignmentPattern(pool, errorLocation, errorMessage))
458 return false;
459 }
460 return true;
461}
462
464{
466 if (type == Binding)
467 return true;
468 if (type == Getter || type == Setter) {
469 *errorLocation = firstSourceLocation();
470 *errorMessage = QString::fromLatin1("Invalid getter/setter in destructuring expression.");
471 return false;
472 }
473 if (type == Method)
474 type = Literal;
477}
478
479
481{
482 if (visitor->visit(this)) {
483 // ###
484 }
485
486 visitor->endVisit(this);
487}
488
490{
491 if (visitor->visit(this)) {
492 }
493
494 visitor->endVisit(this);
495}
496
498{
499 if (visitor->visit(this)) {
500 }
501
502 visitor->endVisit(this);
503}
504
506{
507 if (visitor->visit(this)) {
508 }
509
510 visitor->endVisit(this);
511}
512
513namespace {
514struct LocaleWithoutZeroPadding : public QLocale
515{
516 LocaleWithoutZeroPadding()
517 : QLocale(QLocale::C)
518 {
520 }
521};
522}
523
525{
526 // Can't use QString::number here anymore as it does zero padding by default now.
527
528 // In C++11 this initialization is thread-safe (6.7 [stmt.dcl] p4)
529 static LocaleWithoutZeroPadding locale;
530 // Because of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83562 we can't use thread_local
531 // for the locale variable and therefore rely on toString(double) to be thread-safe.
532 return locale.toString(id, 'g', 16);
533}
534
536{
537 if (visitor->visit(this)) {
538 accept(base, visitor);
539 accept(expression, visitor);
540 }
541
542 visitor->endVisit(this);
543}
544
546{
547 if (visitor->visit(this)) {
548 accept(base, visitor);
549 }
550
551 visitor->endVisit(this);
552}
553
555{
556 if (visitor->visit(this)) {
557 accept(base, visitor);
558 accept(arguments, visitor);
559 }
560
561 visitor->endVisit(this);
562}
563
565{
566 if (visitor->visit(this)) {
567 accept(expression, visitor);
568 }
569
570 visitor->endVisit(this);
571}
572
574{
575 if (visitor->visit(this)) {
576 accept(base, visitor);
577 accept(arguments, visitor);
578 }
579
580 visitor->endVisit(this);
581}
582
584{
585 if (visitor->visit(this)) {
586 for (ArgumentList *it = this; it; it = it->next) {
587 accept(it->expression, visitor);
588 }
589 }
590
591 visitor->endVisit(this);
592}
593
595{
596 if (visitor->visit(this)) {
597 accept(base, visitor);
598 }
599
600 visitor->endVisit(this);
601}
602
604{
605 if (visitor->visit(this)) {
606 accept(base, visitor);
607 }
608
609 visitor->endVisit(this);
610}
611
613{
614 if (visitor->visit(this)) {
615 accept(expression, visitor);
616 }
617
618 visitor->endVisit(this);
619}
620
622{
623 if (visitor->visit(this)) {
624 accept(expression, visitor);
625 }
626
627 visitor->endVisit(this);
628}
629
631{
632 if (visitor->visit(this)) {
633 accept(expression, visitor);
634 }
635
636 visitor->endVisit(this);
637}
638
640{
641 if (visitor->visit(this)) {
642 accept(expression, visitor);
643 }
644
645 visitor->endVisit(this);
646}
647
649{
650 if (visitor->visit(this)) {
651 accept(expression, visitor);
652 }
653
654 visitor->endVisit(this);
655}
656
658{
659 if (visitor->visit(this)) {
660 accept(expression, visitor);
661 }
662
663 visitor->endVisit(this);
664}
665
667{
668 if (visitor->visit(this)) {
669 accept(expression, visitor);
670 }
671
672 visitor->endVisit(this);
673}
674
676{
677 if (visitor->visit(this)) {
678 accept(expression, visitor);
679 }
680
681 visitor->endVisit(this);
682}
683
685{
686 if (visitor->visit(this)) {
687 accept(expression, visitor);
688 }
689
690 visitor->endVisit(this);
691}
692
694{
695 if (visitor->visit(this)) {
696 accept(left, visitor);
697 accept(right, visitor);
698 }
699
700 visitor->endVisit(this);
701}
702
704{
705 if (visitor->visit(this)) {
706 accept(expression, visitor);
707 accept(ok, visitor);
708 accept(ko, visitor);
709 }
710
711 visitor->endVisit(this);
712}
713
715{
716 if (visitor->visit(this)) {
717 accept(left, visitor);
718 accept(right, visitor);
719 }
720
721 visitor->endVisit(this);
722}
723
724void Block::accept0(BaseVisitor *visitor)
725{
726 if (visitor->visit(this)) {
727 accept(statements, visitor);
728 }
729
730 visitor->endVisit(this);
731}
732
734{
735 if (visitor->visit(this)) {
736 for (StatementList *it = this; it; it = it->next) {
737 accept(it->statement, visitor);
738 }
739 }
740
741 visitor->endVisit(this);
742}
743
745{
746 if (visitor->visit(this)) {
747 accept(declarations, visitor);
748 }
749
750 visitor->endVisit(this);
751}
752
754{
755 if (visitor->visit(this)) {
756 for (VariableDeclarationList *it = this; it; it = it->next) {
757 accept(it->declaration, visitor);
758 }
759 }
760
761 visitor->endVisit(this);
762}
763
765{
766 if (visitor->visit(this)) {
767 }
768
769 visitor->endVisit(this);
770}
771
773{
774 if (visitor->visit(this)) {
775 accept(expression, visitor);
776 }
777
778 visitor->endVisit(this);
779}
780
782{
783 if (visitor->visit(this)) {
784 accept(expression, visitor);
785 accept(ok, visitor);
786 accept(ko, visitor);
787 }
788
789 visitor->endVisit(this);
790}
791
793{
794 if (visitor->visit(this)) {
795 accept(statement, visitor);
796 accept(expression, visitor);
797 }
798
799 visitor->endVisit(this);
800}
801
803{
804 if (visitor->visit(this)) {
805 accept(expression, visitor);
806 accept(statement, visitor);
807 }
808
809 visitor->endVisit(this);
810}
811
813{
814 if (visitor->visit(this)) {
815 accept(initialiser, visitor);
816 accept(declarations, visitor);
817 accept(condition, visitor);
818 accept(expression, visitor);
819 accept(statement, visitor);
820 }
821
822 visitor->endVisit(this);
823}
824
826{
827 if (visitor->visit(this)) {
828 accept(lhs, visitor);
829 accept(expression, visitor);
830 accept(statement, visitor);
831 }
832
833 visitor->endVisit(this);
834}
835
837{
838 if (visitor->visit(this)) {
839 }
840
841 visitor->endVisit(this);
842}
843
845{
846 if (visitor->visit(this)) {
847 }
848
849 visitor->endVisit(this);
850}
851
853{
854 if (visitor->visit(this)) {
855 accept(expression, visitor);
856 }
857
858 visitor->endVisit(this);
859}
860
862{
863 if (visitor->visit(this)) {
864 accept(expression, visitor);
865 }
866
867 visitor->endVisit(this);
868}
869
870
872{
873 if (visitor->visit(this)) {
874 accept(expression, visitor);
875 accept(statement, visitor);
876 }
877
878 visitor->endVisit(this);
879}
880
882{
883 if (visitor->visit(this)) {
884 accept(expression, visitor);
885 accept(block, visitor);
886 }
887
888 visitor->endVisit(this);
889}
890
892{
893 if (visitor->visit(this)) {
894 accept(clauses, visitor);
895 accept(defaultClause, visitor);
896 accept(moreClauses, visitor);
897 }
898
899 visitor->endVisit(this);
900}
901
903{
904 if (visitor->visit(this)) {
905 for (CaseClauses *it = this; it; it = it->next) {
906 accept(it->clause, visitor);
907 }
908 }
909
910 visitor->endVisit(this);
911}
912
914{
915 if (visitor->visit(this)) {
916 accept(expression, visitor);
917 accept(statements, visitor);
918 }
919
920 visitor->endVisit(this);
921}
922
924{
925 if (visitor->visit(this)) {
926 accept(statements, visitor);
927 }
928
929 visitor->endVisit(this);
930}
931
933{
934 if (visitor->visit(this)) {
935 accept(statement, visitor);
936 }
937
938 visitor->endVisit(this);
939}
940
942{
943 if (visitor->visit(this)) {
944 accept(expression, visitor);
945 }
946
947 visitor->endVisit(this);
948}
949
951{
952 if (visitor->visit(this)) {
953 accept(statement, visitor);
954 accept(catchExpression, visitor);
955 accept(finallyExpression, visitor);
956 }
957
958 visitor->endVisit(this);
959}
960
962{
963 if (visitor->visit(this)) {
964 accept(patternElement, visitor);
965 accept(statement, visitor);
966 }
967
968 visitor->endVisit(this);
969}
970
972{
973 if (visitor->visit(this)) {
974 accept(statement, visitor);
975 }
976
977 visitor->endVisit(this);
978}
979
981{
982 if (visitor->visit(this)) {
983 accept(formals, visitor);
984 accept(typeAnnotation, visitor);
985 accept(body, visitor);
986 }
987
988 visitor->endVisit(this);
989}
990
992{
993 if (visitor->visit(this)) {
994 accept(formals, visitor);
995 accept(typeAnnotation, visitor);
996 accept(body, visitor);
997 }
998
999 visitor->endVisit(this);
1000}
1001
1003{
1004 return this;
1005}
1006
1008{
1010 int i = 0;
1011 for (const FormalParameterList *it = this; it; it = it->next) {
1012 if (it->element) {
1013 QString name = it->element->bindingIdentifier.toString();
1014 int duplicateIndex = formals.indexOf(name);
1015 if (duplicateIndex >= 0) {
1016 // change the name of the earlier argument to enforce the lookup semantics from the spec
1017 formals[duplicateIndex].id += QLatin1String("#") + QString::number(i);
1018 }
1019 formals += { name, it->element->firstSourceLocation(), it->element->typeAnnotation,
1020 it->element->isInjectedSignalParameter ? BoundName::Injected
1022 }
1023 ++i;
1024 }
1025 return formals;
1026}
1027
1029{
1031 for (const FormalParameterList *it = this; it; it = it->next) {
1032 if (it->element)
1033 it->element->boundNames(&names);
1034 }
1035 return names;
1036}
1037
1039{
1040 bool accepted = true;
1041 for (FormalParameterList *it = this; it && accepted; it = it->next) {
1042 accepted = visitor->visit(it);
1043 if (accepted)
1044 accept(it->element, visitor);
1045 visitor->endVisit(it);
1046 }
1047}
1048
1050{
1051 FormalParameterList *front = next;
1052 next = nullptr;
1053
1054 int i = 0;
1055 for (const FormalParameterList *it = this; it; it = it->next) {
1056 if (it->element && it->element->bindingIdentifier.isEmpty())
1057 it->element->bindingIdentifier = pool->newString(QLatin1String("arg#") + QString::number(i));
1058 ++i;
1059 }
1060 return front;
1061}
1062
1064{
1065 if (visitor->visit(this)) {
1066 accept(statements, visitor);
1067 }
1068
1069 visitor->endVisit(this);
1070}
1071
1073{
1074 if (visitor->visit(this)) {
1075
1076 }
1077 visitor->endVisit(this);
1078}
1079
1081{
1082 if (visitor->visit(this)) {
1083 for (ImportsList *it = this; it; it = it->next) {
1084 accept(it->importSpecifier, visitor);
1085 }
1086 }
1087
1088 visitor->endVisit(this);
1089}
1090
1092{
1093 if (visitor->visit(this)) {
1094 accept(importsList, visitor);
1095 }
1096
1097 visitor->endVisit(this);
1098}
1099
1101{
1102 if (visitor->visit(this)) {
1103 }
1104
1105 visitor->endVisit(this);
1106}
1107
1109{
1110 if (visitor->visit(this)) {
1111 }
1112
1113 visitor->endVisit(this);
1114}
1115
1117{
1118 if (visitor->visit(this)) {
1119 accept(nameSpaceImport, visitor);
1120 accept(namedImports, visitor);
1121 }
1122
1123 visitor->endVisit(this);
1124}
1125
1127{
1128 if (visitor->visit(this)) {
1129 accept(importClause, visitor);
1130 accept(fromClause, visitor);
1131 }
1132
1133 visitor->endVisit(this);
1134}
1135
1137{
1138 if (visitor->visit(this)) {
1139
1140 }
1141
1142 visitor->endVisit(this);
1143}
1144
1146{
1147 if (visitor->visit(this)) {
1148 for (ExportsList *it = this; it; it = it->next) {
1149 accept(it->exportSpecifier, visitor);
1150 }
1151 }
1152
1153 visitor->endVisit(this);
1154}
1155
1157{
1158 if (visitor->visit(this)) {
1159 accept(exportsList, visitor);
1160 }
1161
1162 visitor->endVisit(this);
1163}
1164
1166{
1167 if (visitor->visit(this)) {
1168 accept(fromClause, visitor);
1169 accept(exportClause, visitor);
1171 }
1172
1173 visitor->endVisit(this);
1174}
1175
1177{
1178 if (visitor->visit(this)) {
1179 accept(body, visitor);
1180 }
1181
1182 visitor->endVisit(this);
1183}
1184
1186{
1187 if (visitor->visit(this)) {
1188 }
1189
1190 visitor->endVisit(this);
1191}
1192
1194{
1195 if (visitor->visit(this)) {
1196 accept(headers, visitor);
1197 accept(members, visitor);
1198 }
1199
1200 visitor->endVisit(this);
1201}
1202
1204{
1205 if (visitor->visit(this)) {
1206 // accept(annotations, visitor); // accept manually in visit if interested
1207 // accept(memberType, visitor); // accept manually in visit if interested
1208 accept(statement, visitor);
1209 accept(binding, visitor);
1210 // accept(parameters, visitor); // accept manually in visit if interested
1211 }
1212
1213 visitor->endVisit(this);
1214}
1215
1217{
1218 if (visitor->visit(this)) {
1219 // accept(annotations, visitor); // accept manually in visit if interested
1220 accept(qualifiedTypeNameId, visitor);
1221 accept(initializer, visitor);
1222 }
1223
1224 visitor->endVisit(this);
1225}
1226
1228{
1229 if (visitor->visit(this)) {
1230 accept(members, visitor);
1231 }
1232
1233 visitor->endVisit(this);
1234}
1235
1237{
1238 if (visitor->visit(this)) {
1239 // accept(type, visitor); // accept manually in visit if interested
1240 }
1241 visitor->endVisit(this);
1242}
1243
1245{
1246 if (visitor->visit(this)) {
1247 // accept(annotations, visitor); // accept manually in visit if interested
1248 accept(qualifiedId, visitor);
1249 accept(qualifiedTypeNameId, visitor);
1250 accept(initializer, visitor);
1251 }
1252
1253 visitor->endVisit(this);
1254}
1255
1257{
1258 if (visitor->visit(this)) {
1259 // accept(annotations, visitor); // accept manually in visit if interested
1260 accept(qualifiedId, visitor);
1261 accept(statement, visitor);
1262 }
1263
1264 visitor->endVisit(this);
1265}
1266
1268{
1269 if (visitor->visit(this)) {
1270 // accept(annotations, visitor); // accept manually in visit if interested
1271 accept(qualifiedId, visitor);
1272 accept(members, visitor);
1273 }
1274
1275 visitor->endVisit(this);
1276}
1277
1279{
1280 if (visitor->visit(this)) {
1281 for (UiObjectMemberList *it = this; it; it = it->next)
1282 accept(it->member, visitor);
1283 }
1284
1285 visitor->endVisit(this);
1286}
1287
1289{
1290 if (visitor->visit(this)) {
1291 for (UiArrayMemberList *it = this; it; it = it->next)
1292 accept(it->member, visitor);
1293 }
1294
1295 visitor->endVisit(this);
1296}
1297
1299{
1300 if (visitor->visit(this)) {
1301 // accept(next, visitor) // accept manually in visit if interested
1302 }
1303
1304 visitor->endVisit(this);
1305}
1306
1307void Type::accept0(BaseVisitor *visitor)
1308{
1309 if (visitor->visit(this)) {
1310 accept(typeId, visitor);
1311 accept(typeArgument, visitor);
1312 }
1313
1314 visitor->endVisit(this);
1315}
1316
1318{
1319 if (visitor->visit(this)) {
1320 accept(type, visitor);
1321 }
1322
1323 visitor->endVisit(this);
1324}
1325
1327{
1328 if (visitor->visit(this)) {
1329 accept(importUri, visitor);
1330 // accept(version, visitor); // accept manually in visit if interested
1331 }
1332
1333 visitor->endVisit(this);
1334}
1335
1337{
1338 if (visitor->visit(this)) {
1339 }
1340
1341 visitor->endVisit(this);
1342}
1343
1344
1346{
1347 if (visitor->visit(this)) {
1348 }
1349
1350 visitor->endVisit(this);
1351}
1352
1354{
1355 bool accepted = true;
1356 for (UiHeaderItemList *it = this; it && accepted; it = it->next) {
1357 accepted = visitor->visit(it);
1358 if (accepted)
1359 accept(it->headerItem, visitor);
1360
1361 visitor->endVisit(it);
1362 }
1363}
1364
1365
1367{
1368 if (visitor->visit(this)) {
1369 // accept(annotations, visitor); // accept manually in visit if interested
1370 accept(sourceElement, visitor);
1371 }
1372
1373 visitor->endVisit(this);
1374}
1375
1377{
1378 if (visitor->visit(this)) {
1379 // accept(annotations, visitor); // accept manually in visit if interested
1380 accept(members, visitor);
1381 }
1382
1383 visitor->endVisit(this);
1384}
1385
1387{
1388 if (visitor->visit(this)) {
1389 }
1390
1391 visitor->endVisit(this);
1392}
1393
1395{
1396 if (visitor->visit(this)) {
1397 accept(base, visitor);
1398 accept(templateLiteral, visitor);
1399 }
1400
1401 visitor->endVisit(this);
1402}
1403
1405{
1406 if (visitor->visit(this)) {
1407 accept(bindingTarget, visitor);
1408 accept(typeAnnotation, visitor);
1409 accept(initializer, visitor);
1410 }
1411
1412 visitor->endVisit(this);
1413}
1414
1416{
1417 if (bindingTarget) {
1419 e->boundNames(names);
1420 else if (PatternPropertyList *p = propertyList())
1421 p->boundNames(names);
1422 } else {
1425 }
1426}
1427
1429{
1430 bool accepted = true;
1431 for (PatternElementList *it = this; it && accepted; it = it->next) {
1432 accepted = visitor->visit(it);
1433 if (accepted) {
1434 accept(it->elision, visitor);
1435 accept(it->element, visitor);
1436 }
1437 visitor->endVisit(it);
1438 }
1439}
1440
1442{
1443 for (PatternElementList *it = this; it; it = it->next) {
1444 if (it->element)
1445 it->element->boundNames(names);
1446 }
1447}
1448
1450{
1451 if (visitor->visit(this)) {
1452 accept(name, visitor);
1453 accept(bindingTarget, visitor);
1454 accept(typeAnnotation, visitor);
1455 accept(initializer, visitor);
1456 }
1457
1458 visitor->endVisit(this);
1459}
1460
1462{
1464}
1465
1467{
1468 bool accepted = true;
1469 for (PatternPropertyList *it = this; it && accepted; it = it->next) {
1470 accepted = visitor->visit(it);
1471 if (accepted)
1472 accept(it->property, visitor);
1473 visitor->endVisit(it);
1474 }
1475}
1476
1478{
1479 for (PatternPropertyList *it = this; it; it = it->next)
1480 it->property->boundNames(names);
1481}
1482
1484{
1485 if (visitor->visit(this)) {
1486 accept(expression, visitor);
1487 }
1488
1489 visitor->endVisit(this);
1490}
1491
1493{
1494 if (visitor->visit(this)) {
1495 accept(heritage, visitor);
1496 accept(elements, visitor);
1497 }
1498
1499 visitor->endVisit(this);
1500}
1501
1503{
1504 return this;
1505}
1506
1508{
1509 if (visitor->visit(this)) {
1510 accept(heritage, visitor);
1511 accept(elements, visitor);
1512 }
1513
1514 visitor->endVisit(this);
1515}
1516
1518{
1519 bool accepted = true;
1520 for (ClassElementList *it = this; it && accepted; it = it->next) {
1521 accepted = visitor->visit(it);
1522 if (accepted)
1523 accept(it->property, visitor);
1524
1525 visitor->endVisit(it);
1526 }
1527}
1528
1530{
1531 ClassElementList *front = next;
1532 next = nullptr;
1533 return front;
1534}
1535
1537{
1538 return this;
1539}
1540
1542{
1543 return this;
1544}
1545
1547{
1548 if (visitor->visit(this)) {
1549 }
1550 visitor->endVisit(this);
1551}
1552
1553QString Type::toString() const
1554{
1556 toString(&result);
1557 return result;
1558}
1559
1560void Type::toString(QString *out) const
1561{
1563
1564 if (typeArgument) {
1565 out->append(QLatin1Char('<'));
1567 out->append(QLatin1Char('>'));
1568 };
1569}
1570
1572{
1573 if (visitor->visit(this)) {
1574 // accept(annotations, visitor); // accept manually in visit if interested
1575 accept(component, visitor);
1576 }
1577
1578 visitor->endVisit(this);
1579}
1580
1582{
1583 if (visitor->visit(this)) {
1584 }
1585
1586 visitor->endVisit(this);
1587}
1588
1590{
1591 if (visitor->visit(this)) {
1592 for (UiAnnotationList *it = this; it; it = it->next)
1593 accept(it->annotation, visitor);
1594 }
1595
1596 visitor->endVisit(this);
1597}
1598
1600{
1601 if (visitor->visit(this)) {
1602 accept(qualifiedTypeNameId, visitor);
1603 accept(initializer, visitor);
1604 }
1605
1606 visitor->endVisit(this);
1607}
1608
1610{
1611 std::array<const SourceLocation *, 4> tokens {&m_propertyToken, &m_defaultToken, &m_readonlyToken, &m_requiredToken};
1612 const auto it = std::min_element(tokens.begin(), tokens.end(), compareLocationsByBegin<true>);
1613 return **it;
1614}
1615
1617{
1618 std::array<const SourceLocation *, 4> tokens {&m_propertyToken, &m_defaultToken, &m_readonlyToken, &m_requiredToken};
1619 const auto it = std::max_element(tokens.begin(), tokens.end(), compareLocationsByBegin<false>);
1620 return **it;
1621}
1622
1623} } // namespace QQmlJS::AST
1624
1626
1627
@ OmitGroupSeparator
Definition qlocale.h:869
@ OmitLeadingZeroInExponent
Definition qlocale.h:871
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
bool isValidArrayLiteral(SourceLocation *errorLocation=nullptr) const
PatternElementList * elements
bool convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage) override
void accept0(BaseVisitor *visitor) override
BinaryExpression * binaryExpressionCast() override
StatementList * statements
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
CaseClauses * moreClauses
DefaultClause * defaultClause
void accept0(BaseVisitor *visitor) override
ExpressionNode * expression
void accept0(BaseVisitor *visitor) override
StatementList * statements
void accept0(BaseVisitor *visitor) override
PatternElement * patternElement
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
ClassElementList * finish()
ClassExpression * asClassDefinition() override
void accept0(BaseVisitor *visitor) override
ClassElementList * elements
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
StatementList * body
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
AST::FormalParameterList * reparseAsFormalParameterList(MemoryPool *pool)
bool containsOptionalChain() const
Definition qqmljsast.cpp:90
ExpressionNode * expressionCast() override
Definition qqmljsast.cpp:85
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
ExpressionNode * expression
VariableDeclarationList * declarations
ExpressionNode * initialiser
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
FormalParameterList * finish(MemoryPool *pool)
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
FormalParameterList * formals
FunctionExpression * asFunctionDefinition() override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
ExpressionNode * expression
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
NamedImports * namedImports
NameSpaceImport * nameSpaceImport
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
LeftHandSideExpression * leftHandSideExpressionCast() override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
ClassExpression * asClassDefinition() override
void accept0(BaseVisitor *visitor) override
FunctionExpression * asFunctionDefinition() override
void accept0(BaseVisitor *visitor) override
ExpressionNode * expression
void accept0(BaseVisitor *visitor) override
virtual UiObjectMember * uiObjectMemberCast()
Definition qqmljsast.cpp:54
void accept(BaseVisitor *visitor)
virtual ClassExpression * asClassDefinition()
Definition qqmljsast.cpp:74
virtual Statement * statementCast()
Definition qqmljsast.cpp:49
virtual BinaryExpression * binaryExpressionCast()
Definition qqmljsast.cpp:44
virtual ExpressionNode * expressionCast()
Definition qqmljsast.cpp:39
bool ignoreRecursionDepth() const
Definition qqmljsast.cpp:79
virtual FunctionExpression * asFunctionDefinition()
Definition qqmljsast.cpp:69
virtual Pattern * patternCast()
Definition qqmljsast.cpp:64
virtual LeftHandSideExpression * leftHandSideExpressionCast()
Definition qqmljsast.cpp:59
ExpressionNode * expression
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
QString asString() const override
void accept0(BaseVisitor *visitor) override
bool convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage) override
PatternPropertyList * properties
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void boundNames(BoundNames *names)
PatternPropertyList * propertyList() const
PatternElementList * elementList() const
void accept0(BaseVisitor *visitor) override
SourceLocation identifierToken
SourceLocation firstSourceLocation() const override
ExpressionNode * initializer
TypeAnnotation * typeAnnotation
virtual bool convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage)
virtual void boundNames(BoundNames *names)
ExpressionNode * bindingTarget
void boundNames(BoundNames *names)
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
bool convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage) override
void boundNames(BoundNames *names) override
SourceLocation firstSourceLocation() const override
Pattern * patternCast() override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
StatementList * statements
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
Statement * statementCast() override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
TemplateLiteral * templateLiteral
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
ExpressionNode * expression
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
QString toString() const
UiQualifiedId * typeArgument
UiQualifiedId * typeId
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
UiQualifiedId * qualifiedTypeNameId
UiObjectInitializer * initializer
void accept0(BaseVisitor *visitor) override
UiArrayMemberList * members
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
UiQualifiedId * importUri
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
UiObjectDefinition * component
UiQualifiedId * qualifiedTypeNameId
void accept0(BaseVisitor *visitor) override
UiObjectInitializer * initializer
UiObjectInitializer * initializer
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
UiObjectMember * uiObjectMemberCast() override
void accept0(BaseVisitor *) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
UiHeaderItemList * headers
void accept0(BaseVisitor *visitor) override
UiObjectMemberList * members
SourceLocation firstSourceLocation() const override
SourceLocation lastSourceLocation() const override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
VariableDeclarationList * declarations
void accept0(BaseVisitor *visitor) override
ExpressionNode * expression
void accept0(BaseVisitor *visitor) override
ExpressionNode * expression
void accept0(BaseVisitor *visitor) override
void accept0(BaseVisitor *visitor) override
ExpressionNode * expression
void accept0(BaseVisitor *visitor) override
bool isEmpty() const
Definition qset.h:52
QString toString() const
Returns a deep copy of this string view's data as a QString.
Definition qstring.h:1014
constexpr bool isNull() const noexcept
Returns whether this string view is null - that is, whether {data() == nullptr}.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5710
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:7822
double e
QSet< QString >::iterator it
FunctionExpression * asAnonymousFunctionDefinition(Node *n)
Definition qqmljsast.cpp:19
ClassExpression * asAnonymousClassDefinition(Node *n)
Definition qqmljsast.cpp:29
Combined button and popup list for selecting options.
GLboolean GLboolean GLboolean b
GLenum condition
GLdouble GLdouble right
GLfloat GLfloat f
GLint left
GLenum type
GLuint name
GLfloat n
const GLubyte * c
GLuint GLuint * names
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &errorSource, qsizetype errorPosition)
Definition qurl.cpp:3503
QTextStream out(stdout)
[7]
\inmodule QtCore \reentrant
Definition qchar.h:17
int indexOf(const QString &name, int from=0) const