parser: add `ASTDump` and `ANode::dump_tree`
[nit.git] / src / parser / parser_nodes.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # AST nodes of the Nit language
16 # Was previously based on parser_abs.nit.
17 module parser_nodes
18
19 import location
20 import ordered_tree
21
22 # Root of the AST class-hierarchy
23 abstract class ANode
24 # Location is set during AST building. Once built, location cannon be null.
25 # However, manual instantiated nodes may need more care.
26 var location: Location is writable, noinit
27
28 # The location of the important part of the node (identifier or whatever)
29 fun hot_location: Location do return location
30
31 # Display a message for the colored location of the node
32 fun debug(message: String)
33 do
34 sys.stderr.write "{hot_location} {self.class_name}: {message}\n{hot_location.colored_line("0;32")}\n"
35 end
36
37 # Write the subtree on stdout.
38 # See `ASTDump`
39 fun dump_tree
40 do
41 var d = new ASTDump
42 d.enter_visit(self)
43 d.write_to(sys.stdout)
44 end
45
46 # Parent of the node in the AST
47 var parent: nullable ANode = null
48
49 # The topmost ancestor of the element
50 # This just apply `parent` until the first one
51 fun root: ANode
52 do
53 var res = self
54 loop
55 var p = res.parent
56 if p == null then return res
57 res = p
58 end
59 end
60
61 # The most specific common parent between `self` and `other`
62 # Return null if the two node are unrelated (distinct root)
63 fun common_parent(other: ANode): nullable ANode
64 do
65 # First, get the same depth
66 var s: nullable ANode = self
67 var o: nullable ANode = other
68 var d = s.depth - o.depth
69 while d > 0 do
70 s = s.parent
71 d -= 1
72 end
73 while d < 0 do
74 o = o.parent
75 d += 1
76 end
77 assert o.depth == s.depth
78 # Second, go up until same in found
79 while s != o do
80 s = s.parent
81 o = o.parent
82 end
83 return s
84 end
85
86 # Number of nodes between `self` and the `root` of the AST
87 # ENSURE `self == self.root implies result == 0 `
88 # ENSURE `self != self.root implies result == self.parent.depth + 1`
89 fun depth: Int
90 do
91 var n = self
92 var res = 0
93 loop
94 var p = n.parent
95 if p == null then return res
96 n = p
97 res += 1
98 end
99 end
100
101 # Replace a child with an other node in the AST
102 private fun replace_child(old_child: ANode, new_child: nullable ANode) is abstract
103
104 # Detach a node from its parent
105 # Aborts if the node is not detachable. use `replace_with` instead
106 # REQUIRE: parent != null
107 # REQUIRE: is_detachable
108 # ENDURE: parent == null
109 fun detach
110 do
111 assert parent != null
112 parent.replace_child(self, null)
113 parent = null
114 end
115
116 # Replace itself with an other node in the AST
117 # REQUIRE: parent != null
118 # ENSURE: node.parent == old(parent)
119 # ENSURE: parent == null
120 fun replace_with(node: ANode)
121 do
122 assert parent != null
123 parent.replace_child(self, node)
124 parent = null
125 end
126
127 # Visit all nodes in order.
128 # Thus, call `v.enter_visit(e)` for each child `e`
129 fun visit_all(v: Visitor) is abstract
130
131 # Do a deep search and return an array of tokens that match a given text
132 fun collect_tokens_by_text(text: String): Array[Token]
133 do
134 var v = new CollectTokensByTextVisitor(text)
135 v.enter_visit(self)
136 return v.result
137 end
138
139 # Do a deep search and return an array of node that are annotated
140 # The attached node can be retrieved by two invocations of parent
141 fun collect_annotations_by_name(name: String): Array[AAnnotation]
142 do
143 var v = new CollectAnnotationsByNameVisitor(name)
144 v.enter_visit(self)
145 return v.result
146 end
147 end
148
149 private class CollectTokensByTextVisitor
150 super Visitor
151 var text: String
152 var result = new Array[Token]
153 redef fun visit(node)
154 do
155 node.visit_all(self)
156 if node isa Token and node.text == text then result.add(node)
157 end
158 end
159
160 private class CollectAnnotationsByNameVisitor
161 super Visitor
162 var name: String
163 var result = new Array[AAnnotation]
164 redef fun visit(node)
165 do
166 node.visit_all(self)
167 if node isa AAnnotation and node.n_atid.n_id.text == name then result.add(node)
168 end
169 end
170
171 # A helper class to handle (print) Nit AST as an OrderedTree
172 class ASTDump
173 super Visitor
174 super OrderedTree[ANode]
175
176 # Reference to the last parent in the Ordered Tree
177 # Is used to handle the initial node parent and workaround possible inconsistent `ANode::parent`
178 private var last_parent: nullable ANode = null
179
180 redef fun visit(n)
181 do
182 var p = last_parent
183 add(p, n)
184 last_parent = n
185 n.visit_all(self)
186 last_parent = p
187 end
188
189 redef fun display(n)
190 do
191 if n isa Token then
192 return "{n.class_name} \"{n.text.escape_to_c}\" @{n.location}"
193 else
194 return "{n.class_name} @{n.location}"
195 end
196 end
197 end
198
199 # A sequence of nodes
200 # It is a specific class (instead of using a Array) to track the parent/child relation when nodes are added or removed
201 class ANodes[E: ANode]
202 super Sequence[E]
203 private var parent: ANode
204 private var items = new Array[E]
205 redef fun iterator do return items.iterator
206 redef fun length do return items.length
207 redef fun is_empty do return items.is_empty
208 redef fun push(e)
209 do
210 hook_add(e)
211 items.push(e)
212 end
213 redef fun pop
214 do
215 var res = items.pop
216 hook_remove(res)
217 return res
218 end
219 redef fun unshift(e)
220 do
221 hook_add(e)
222 items.unshift(e)
223 end
224 redef fun shift
225 do
226 var res = items.shift
227 hook_remove(res)
228 return res
229 end
230 redef fun has(e)
231 do
232 return items.has(e)
233 end
234 redef fun [](index)
235 do
236 return items[index]
237 end
238 redef fun []=(index, e)
239 do
240 hook_remove(self[index])
241 hook_add(e)
242 items[index]=e
243 end
244 redef fun remove_at(index)
245 do
246 hook_remove(items[index])
247 items.remove_at(index)
248 end
249 private fun hook_add(e: E)
250 do
251 #assert e.parent == null
252 e.parent = parent
253 end
254 private fun hook_remove(e: E)
255 do
256 assert e.parent == parent
257 e.parent = null
258 end
259
260 # Used in parent constructor to fill elements
261 private fun unsafe_add_all(nodes: Collection[Object])
262 do
263 var parent = self.parent
264 for n in nodes do
265 assert n isa E
266 add n
267 n.parent = parent
268 end
269 end
270
271 private fun replace_child(old_child: ANode, new_child: nullable ANode): Bool
272 do
273 var parent = self.parent
274 for i in [0..length[ do
275 if self[i] == old_child then
276 if new_child != null then
277 assert new_child isa E
278 self[i] = new_child
279 new_child.parent = parent
280 else
281 self.remove_at(i)
282 end
283 return true
284 end
285 end
286 return false
287 end
288
289 private fun visit_all(v: Visitor)
290 do
291 for n in self do v.enter_visit(n)
292 end
293 end
294
295 # Ancestor of all tokens
296 # A token is a node that has a `text` but no children.
297 abstract class Token
298 super ANode
299
300 # The raw content on the token
301 fun text: String is abstract
302
303 # The raw content on the token
304 fun text=(text: String) is abstract
305
306 # The previous token in the Lexer.
307 # May have disappeared in the AST
308 var prev_token: nullable Token = null
309
310 # The next token in the Lexer.
311 # May have disappeared in the AST
312 var next_token: nullable Token = null
313
314 # The verbatim blank text between `prev_token` and `self`
315 fun blank_before: String
316 do
317 if prev_token == null then return ""
318 var from = prev_token.location.pend+1
319 var to = location.pstart
320 return location.file.string.substring(from,to-from)
321 end
322
323 redef fun to_s: String do
324 return "'{text}'"
325 end
326
327 redef fun visit_all(v: Visitor) do end
328 redef fun replace_child(old_child: ANode, new_child: nullable ANode) do end
329 end
330
331 redef class SourceFile
332 # The first token parser by the lexer
333 # May have disappeared in the final AST
334 var first_token: nullable Token = null
335
336 # The first token parser by the lexer
337 # May have disappeared in the final AST
338 var last_token: nullable Token = null
339 end
340
341 # Ancestor of all productions
342 # A production is a node without text but that usually has children.
343 abstract class Prod
344 super ANode
345
346 # All the annotations attached directly to the node
347 var n_annotations: nullable AAnnotations = null is writable
348
349 # Return all its annotations of a given name in the order of their declaration
350 # Retun an empty array if no such an annotation.
351 fun get_annotations(name: String): Array[AAnnotation]
352 do
353 var res = new Array[AAnnotation]
354 var nas = n_annotations
355 if nas == null then return res
356 for na in nas.n_items do
357 if na.name != name then continue
358 res.add(na)
359 end
360 return res
361 end
362
363 redef fun replace_with(n: ANode)
364 do
365 super
366 assert n isa Prod
367 if not isset n._location and isset _location then n._location = _location
368 end
369 end
370
371 # Abstract standard visitor on the AST
372 abstract class Visitor
373 # What the visitor do when a node is visited
374 # Concrete visitors should implement this method.
375 # @toimplement
376 protected fun visit(e: ANode) is abstract
377
378 # Ask the visitor to visit a given node.
379 # Usually automatically called by visit_all* methods.
380 # This method should not be redefined
381 fun enter_visit(e: nullable ANode)
382 do
383 if e == null then return
384 var old = _current_node
385 _current_node = e
386 visit(e)
387 _current_node = old
388 end
389
390 # The current visited node
391 var current_node: nullable ANode = null is writable
392 end
393
394 # Token of end of line (basically `\n`)
395 class TEol
396 super Token
397 redef fun to_s
398 do
399 return "end of line"
400 end
401 end
402
403 # Token of a line of comments
404 # Starts with the `#` and contains the final end-of-line (if any)
405 class TComment
406 super Token
407 end
408
409 # A token associated with a keyword
410 abstract class TokenKeyword
411 super Token
412 redef fun to_s
413 do
414 return "keyword '{text}'"
415 end
416 end
417
418 # The deprecated keyword `package`.
419 class TKwpackage
420 super TokenKeyword
421 end
422
423 # The keyword `module`
424 class TKwmodule
425 super TokenKeyword
426 end
427
428 # The keyword `import`
429 class TKwimport
430 super TokenKeyword
431 end
432
433 # The keyword `class`
434 class TKwclass
435 super TokenKeyword
436 end
437
438 # The keyword `abstract`
439 class TKwabstract
440 super TokenKeyword
441 end
442
443 # The keyword `interface`
444 class TKwinterface
445 super TokenKeyword
446 end
447
448 # The keywords `enum` ane `universal`
449 class TKwenum
450 super TokenKeyword
451 end
452
453 # The keyword `end`
454 class TKwend
455 super TokenKeyword
456 end
457
458 # The keyword `fun`
459 class TKwmeth
460 super TokenKeyword
461 end
462
463 # The keyword `type`
464 class TKwtype
465 super TokenKeyword
466 end
467
468 # The keyword `init`
469 class TKwinit
470 super TokenKeyword
471 end
472
473 # The keyword `redef`
474 class TKwredef
475 super TokenKeyword
476 end
477
478 # The keyword `is`
479 class TKwis
480 super TokenKeyword
481 end
482
483 # The keyword `do`
484 class TKwdo
485 super TokenKeyword
486 end
487
488 # The keyword `var`
489 class TKwvar
490 super TokenKeyword
491 end
492
493 # The keyword `extern`
494 class TKwextern
495 super TokenKeyword
496 end
497
498 # The keyword `public`
499 class TKwpublic
500 super TokenKeyword
501 end
502
503 # The keyword `protected`
504 class TKwprotected
505 super TokenKeyword
506 end
507
508 # The keyword `private`
509 class TKwprivate
510 super TokenKeyword
511 end
512
513 # The keyword `intrude`
514 class TKwintrude
515 super TokenKeyword
516 end
517
518 # The keyword `if`
519 class TKwif
520 super TokenKeyword
521 end
522
523 # The keyword `then`
524 class TKwthen
525 super TokenKeyword
526 end
527
528 # The keyword `else`
529 class TKwelse
530 super TokenKeyword
531 end
532
533 # The keyword `while`
534 class TKwwhile
535 super TokenKeyword
536 end
537
538 # The keyword `loop`
539 class TKwloop
540 super TokenKeyword
541 end
542
543 # The keyword `for`
544 class TKwfor
545 super TokenKeyword
546 end
547
548 # The keyword `in`
549 class TKwin
550 super TokenKeyword
551 end
552
553 # The keyword `and`
554 class TKwand
555 super TokenKeyword
556 end
557
558 # The keyword `or`
559 class TKwor
560 super TokenKeyword
561 end
562
563 # The keyword `implies`
564 class TKwimplies
565 super TokenKeyword
566 end
567
568 # The keyword `not`
569 class TKwnot
570 super TokenKeyword
571 end
572
573 # The keyword `return`
574 class TKwreturn
575 super TokenKeyword
576 end
577
578 # The keyword `continue`
579 class TKwcontinue
580 super TokenKeyword
581 end
582
583 # The keyword `break`
584 class TKwbreak
585 super TokenKeyword
586 end
587
588 # The keyword `abort`
589 class TKwabort
590 super TokenKeyword
591 end
592
593 # The keyword `assert`
594 class TKwassert
595 super TokenKeyword
596 end
597
598 # The keyword `new`
599 class TKwnew
600 super TokenKeyword
601 end
602
603 # The keyword `isa`
604 class TKwisa
605 super TokenKeyword
606 end
607
608 # The keyword `once`
609 class TKwonce
610 super TokenKeyword
611 end
612
613 # The keyword `super`
614 class TKwsuper
615 super TokenKeyword
616 end
617
618 # The keyword `self`
619 class TKwself
620 super TokenKeyword
621 end
622
623 # The keyword `true`
624 class TKwtrue
625 super TokenKeyword
626 end
627
628 # The keyword `false`
629 class TKwfalse
630 super TokenKeyword
631 end
632
633 # The keyword `null`
634 class TKwnull
635 super TokenKeyword
636 end
637
638 # The keyword `as`
639 class TKwas
640 super TokenKeyword
641 end
642
643 # The keyword `nullable`
644 class TKwnullable
645 super TokenKeyword
646 end
647
648 # The keyword `isset`
649 class TKwisset
650 super TokenKeyword
651 end
652
653 # The keyword `label`
654 class TKwlabel
655 super TokenKeyword
656 end
657
658 # The special keyword `__DEBUG__`
659 class TKwdebug
660 super Token
661 end
662
663 # The symbol `(`
664 class TOpar
665 super Token
666 end
667
668 # The symbol `)`
669 class TCpar
670 super Token
671 end
672
673 # The symbol `[`
674 class TObra
675 super Token
676 end
677
678 # The symbol `]`
679 class TCbra
680 super Token
681 end
682
683 # The symbol `,`
684 class TComma
685 super Token
686 end
687
688 # The symbol `:`
689 class TColumn
690 super Token
691 end
692
693 # The symbol `::`
694 class TQuad
695 super Token
696 end
697
698 # The symbol `=`
699 class TAssign
700 super Token
701 end
702
703 # A token associated with an operator (and other lookalike symbols)
704 abstract class TokenOperator
705 super Token
706 redef fun to_s
707 do
708 return "operator '{text}'"
709 end
710 end
711
712 # The operator `+=`
713 class TPluseq
714 super TokenOperator
715 end
716
717 # The operator `-=`
718 class TMinuseq
719 super TokenOperator
720 end
721
722 # The symbol `...`
723 class TDotdotdot
724 super Token
725 end
726
727 # The symbol `..`
728 class TDotdot
729 super Token
730 end
731
732 # The symbol `.`
733 class TDot
734 super Token
735 end
736
737 # The operator `+`
738 class TPlus
739 super TokenOperator
740 end
741
742 # The operator `-`
743 class TMinus
744 super TokenOperator
745 end
746
747 # The operator `*`
748 class TStar
749 super TokenOperator
750 end
751
752 # The operator `**`
753 class TStarstar
754 super TokenOperator
755 end
756
757 # The operator `/`
758 class TSlash
759 super TokenOperator
760 end
761
762 # The operator `+%
763 class TPercent
764 super TokenOperator
765 end
766
767 # The operator `==`
768 class TEq
769 super TokenOperator
770 end
771
772 # The operator `!=`
773 class TNe
774 super TokenOperator
775 end
776
777 # The operator `<`
778 class TLt
779 super TokenOperator
780 end
781
782 # The operator `<=`
783 class TLe
784 super TokenOperator
785 end
786
787 # The operator `<<`
788 class TLl
789 super TokenOperator
790 end
791
792 # The operator `>`
793 class TGt
794 super TokenOperator
795 end
796
797 # The operator `>=`
798 class TGe
799 super TokenOperator
800 end
801
802 # The operator `>>`
803 class TGg
804 super TokenOperator
805 end
806
807 # The operator `<=>`
808 class TStarship
809 super TokenOperator
810 end
811
812 # The operator `!`
813 class TBang
814 super TokenOperator
815 end
816
817 # The symbol `@`
818 class TAt
819 super Token
820 end
821
822 # A class (or formal type) identifier. They start with an uppercase.
823 class TClassid
824 super Token
825 redef fun to_s
826 do
827 do return "type identifier '{text}'"
828 end
829 end
830
831 # A standard identifier (variable, method...). They start with a lowercase.
832 class TId
833 super Token
834 redef fun to_s
835 do
836 do return "identifier '{text}'"
837 end
838 end
839
840 # An attribute identifier. They start with an underscore.
841 class TAttrid
842 super Token
843 redef fun to_s
844 do
845 do return "attribute '{text}'"
846 end
847 end
848
849 # A token of a literal value (string, integer, etc).
850 abstract class TokenLiteral
851 super Token
852 redef fun to_s
853 do
854 do return "literal value '{text}'"
855 end
856 end
857
858 # A literal decimal integer
859 class TNumber
860 super TokenLiteral
861 end
862
863 # A literal hexadecimal integer
864 class THexNumber
865 super TokenLiteral
866 end
867
868 # A literal floating point number
869 class TFloat
870 super TokenLiteral
871 end
872
873 # A literal character
874 class TChar
875 super TokenLiteral
876 end
877
878 # A literal string
879 class TString
880 super TokenLiteral
881 end
882
883 # The starting part of a super string (between `"` and `{`)
884 class TStartString
885 super TokenLiteral
886 end
887
888 # The middle part of a super string (between `}` and `{`)
889 class TMidString
890 super TokenLiteral
891 end
892
893 # The final part of a super string (between `}` and `"`)
894 class TEndString
895 super TokenLiteral
896 end
897
898 # A malformed string
899 class TBadString
900 super Token
901 redef fun to_s
902 do
903 do return "malformed string {text}"
904 end
905 end
906
907 # A malformed char
908 class TBadChar
909 super Token
910 redef fun to_s
911 do
912 do return "malformed character {text}"
913 end
914 end
915
916 # A extern code block
917 class TExternCodeSegment
918 super Token
919 end
920
921 # A end of file
922 class EOF
923 super Token
924 redef fun to_s
925 do
926 return "end of file"
927 end
928 end
929
930 # A mark of an error
931 class AError
932 super EOF
933 end
934 # A lexical error (unexpected character)
935 class ALexerError
936 super AError
937 end
938 # A syntactic error (unexpected token)
939 class AParserError
940 super AError
941 end
942
943 # The main node of a Nit source-file
944 class AModule
945 super Prod
946
947 # The declaration part of the module
948 var n_moduledecl: nullable AModuledecl = null is writable
949
950 # List of importation clauses
951 var n_imports = new ANodes[AImport](self)
952
953 # List of extern blocks
954 var n_extern_code_blocks = new ANodes[AExternCodeBlock](self)
955
956 # List of class definition (including top-level methods and the main)
957 var n_classdefs = new ANodes[AClassdef](self)
958 end
959
960 # Abstract class for definition of entities
961 abstract class ADefinition
962 super Prod
963 # The documentation
964 var n_doc: nullable ADoc = null is writable
965
966 # The `redef` keyword
967 var n_kwredef: nullable TKwredef = null is writable
968
969 # The declared visibility
970 var n_visibility: nullable AVisibility = null is writable
971 end
972
973 # The declaration of the module with the documentation, name, and annotations
974 class AModuledecl
975 super ADefinition
976
977 # The `module` keyword
978 var n_kwmodule: TKwmodule is writable, noinit
979
980 # The declared module name
981 var n_name: AModuleName is writable, noinit
982 end
983
984 # A import clause of a module
985 abstract class AImport
986 super Prod
987
988 # The declared visibility
989 var n_visibility: AVisibility is writable, noinit
990
991 # The `import` keyword
992 var n_kwimport: TKwimport is writable, noinit
993 end
994
995 # A standard import clause. eg `import x`
996 class AStdImport
997 super AImport
998 # The imported module name
999 var n_name: AModuleName is writable, noinit
1000 end
1001
1002 # The special import clause of the kernel module. eg `import end`
1003 class ANoImport
1004 super AImport
1005 # The `end` keyword, that indicate the root module
1006 var n_kwend: TKwend is writable, noinit
1007 end
1008
1009 # A visibility modifier
1010 #
1011 # The public visibility is an empty production (no keyword).
1012 #
1013 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
1014 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
1015 abstract class AVisibility
1016 super Prod
1017 end
1018
1019 # An implicit or explicit public visibility modifier
1020 class APublicVisibility
1021 super AVisibility
1022 # The `public` keyword, if any
1023 var n_kwpublic: nullable TKwpublic is writable
1024 end
1025 # An explicit private visibility modifier
1026 class APrivateVisibility
1027 super AVisibility
1028 # The `private` keyword
1029 var n_kwprivate: TKwprivate is writable, noinit
1030 end
1031 # An explicit protected visibility modifier
1032 class AProtectedVisibility
1033 super AVisibility
1034 # The `protected` keyword
1035 var n_kwprotected: TKwprotected is writable, noinit
1036 end
1037 # An explicit intrude visibility modifier
1038 class AIntrudeVisibility
1039 super AVisibility
1040 # The `intrude` keyword
1041 var n_kwintrude: TKwintrude is writable, noinit
1042 end
1043
1044 # A class definition
1045 # While most definition are `AStdClassdef`
1046 # There is tow special case of class definition
1047 abstract class AClassdef
1048 super Prod
1049 # All the declared properties (including the main method)
1050 var n_propdefs = new ANodes[APropdef](self)
1051 end
1052
1053 # A standard class definition with a name, superclasses and properties
1054 class AStdClassdef
1055 super AClassdef
1056 super ADefinition
1057
1058 # The class kind (interface, abstract class, etc.)
1059 var n_classkind: AClasskind is writable, noinit
1060
1061 # The name of the class
1062 var n_id: nullable TClassid = null is writable
1063
1064 # The list of formal parameter types
1065 var n_formaldefs = new ANodes[AFormaldef](self)
1066
1067 # The extern block code
1068 var n_extern_code_block: nullable AExternCodeBlock = null is writable
1069
1070 # The list of super-classes
1071 var n_superclasses = new ANodes[ASuperclass](self)
1072
1073 # The `end` keyword
1074 var n_kwend: TKwend is writable, noinit
1075
1076 redef fun hot_location do return n_id.location
1077 end
1078
1079 # The implicit class definition of the implicit main method
1080 class ATopClassdef
1081 super AClassdef
1082 end
1083
1084 # The implicit class definition of the top-level methods
1085 class AMainClassdef
1086 super AClassdef
1087 end
1088
1089 # The modifier for the kind of class (abstract, interface, etc.)
1090 abstract class AClasskind
1091 super Prod
1092 end
1093
1094 # A default, or concrete class modifier (just `class`)
1095 class AConcreteClasskind
1096 super AClasskind
1097
1098 # The `class` keyword.
1099 var n_kwclass: TKwclass is writable, noinit
1100 end
1101
1102 # An abstract class modifier (`abstract class`)
1103 class AAbstractClasskind
1104 super AClasskind
1105
1106 # The `abstract` keyword.
1107 var n_kwabstract: TKwabstract is writable, noinit
1108
1109 # The `class` keyword.
1110 var n_kwclass: TKwclass is writable, noinit
1111 end
1112
1113 # An interface class modifier (`interface`)
1114 class AInterfaceClasskind
1115 super AClasskind
1116
1117 # The `interface` keyword.
1118 var n_kwinterface: TKwinterface is writable, noinit
1119 end
1120
1121 # An enum/universal class modifier (`enum class`)
1122 class AEnumClasskind
1123 super AClasskind
1124
1125 # The `enum` keyword.
1126 var n_kwenum: TKwenum is writable, noinit
1127 end
1128
1129 # An extern class modifier (`extern class`)
1130 class AExternClasskind
1131 super AClasskind
1132
1133 # The `extern` keyword.
1134 var n_kwextern: TKwextern is writable, noinit
1135
1136 # The `class` keyword.
1137 var n_kwclass: nullable TKwclass = null is writable
1138 end
1139
1140 # The definition of a formal generic parameter type. eg `X: Y`
1141 class AFormaldef
1142 super Prod
1143
1144 # The name of the parameter type
1145 var n_id: TClassid is writable, noinit
1146
1147 # The bound of the parameter type
1148 var n_type: nullable AType = null is writable
1149 end
1150
1151 # A super-class. eg `super X`
1152 class ASuperclass
1153 super Prod
1154
1155 # The super keyword
1156 var n_kwsuper: TKwsuper is writable, noinit
1157
1158 # The super-class (indicated as a type)
1159 var n_type: AType is writable, noinit
1160 end
1161
1162 # The definition of a property
1163 abstract class APropdef
1164 super ADefinition
1165 end
1166
1167 # A definition of an attribute
1168 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1169 class AAttrPropdef
1170 super APropdef
1171
1172 # The identifier for a old-style attribute (null if new-style)
1173 var n_kwvar: TKwvar is writable, noinit
1174
1175 # The identifier for a new-style attribute (null if old-style)
1176 var n_id2: TId is writable, noinit
1177
1178 # The declared type of the attribute
1179 var n_type: nullable AType = null is writable
1180
1181 # The initial value, if any (set with `=`)
1182 var n_expr: nullable AExpr = null is writable
1183
1184 # The initial value, if any (set with `do return`)
1185 var n_block: nullable AExpr = null is writable
1186
1187 redef fun hot_location
1188 do
1189 return n_id2.location
1190 end
1191 end
1192
1193 # A definition of all kind of method (including constructors)
1194 class AMethPropdef
1195 super APropdef
1196
1197 # The `fun` keyword, if any
1198 var n_kwmeth: nullable TKwmeth = null is writable
1199
1200 # The `init` keyword, if any
1201 var n_kwinit: nullable TKwinit = null is writable
1202
1203 # The `new` keyword, if any
1204 var n_kwnew: nullable TKwnew = null is writable
1205
1206 # The name of the method, if any
1207 var n_methid: nullable AMethid = null is writable
1208
1209 # The signature of the method, if any
1210 var n_signature: nullable ASignature = null is writable
1211
1212 # The body (in Nit) of the method, if any
1213 var n_block: nullable AExpr = null is writable
1214
1215 # The list of declared callbacks (for extern methods)
1216 var n_extern_calls: nullable AExternCalls = null is writable
1217
1218 # The body (in extern code) of the method, if any
1219 var n_extern_code_block: nullable AExternCodeBlock = null is writable
1220
1221 redef fun hot_location
1222 do
1223 if n_methid != null then
1224 return n_methid.location
1225 else if n_kwinit != null then
1226 return n_kwinit.location
1227 else if n_kwnew != null then
1228 return n_kwnew.location
1229 else
1230 return location
1231 end
1232 end
1233 end
1234
1235 # The implicit main method
1236 class AMainMethPropdef
1237 super AMethPropdef
1238 end
1239
1240 # Declaration of callbacks for extern methods
1241 class AExternCalls
1242 super Prod
1243
1244 # The `import` keyword
1245 var n_kwimport: TKwimport is writable, noinit
1246
1247 # The list of declared callbacks
1248 var n_extern_calls: ANodes[AExternCall] = new ANodes[AExternCall](self)
1249 end
1250
1251 # A single callback declaration
1252 abstract class AExternCall
1253 super Prod
1254 end
1255
1256 # A single callback declaration on a method
1257 abstract class APropExternCall
1258 super AExternCall
1259 end
1260
1261 # A single callback declaration on a method on the current receiver
1262 class ALocalPropExternCall
1263 super APropExternCall
1264
1265 # The name of the called-back method
1266 var n_methid: AMethid is writable, noinit
1267 end
1268
1269 # A single callback declaration on a method on an explicit receiver type.
1270 class AFullPropExternCall
1271 super APropExternCall
1272
1273 # The type of the receiver of the called-back method
1274 var n_type: AType is writable, noinit
1275
1276 # The dot `.`
1277 var n_dot: nullable TDot = null is writable
1278
1279 # The name of the called-back method
1280 var n_methid: AMethid is writable, noinit
1281 end
1282
1283 # A single callback declaration on a method on a constructor
1284 class AInitPropExternCall
1285 super APropExternCall
1286
1287 # The allocated type
1288 var n_type: AType is writable, noinit
1289 end
1290
1291 # A single callback declaration on a `super` call
1292 class ASuperExternCall
1293 super AExternCall
1294
1295 # The `super` keyword
1296 var n_kwsuper: TKwsuper is writable, noinit
1297 end
1298
1299 # A single callback declaration on a cast
1300 abstract class ACastExternCall
1301 super AExternCall
1302 end
1303
1304 # A single callback declaration on a cast to a given type
1305 class ACastAsExternCall
1306 super ACastExternCall
1307
1308 # The origin type of the cast
1309 var n_from_type: AType is writable, noinit
1310
1311 # The dot (`.`)
1312 var n_dot: nullable TDot = null is writable
1313
1314 # The `as` keyword
1315 var n_kwas: TKwas is writable, noinit
1316
1317 # The destination of the cast
1318 var n_to_type: AType is writable, noinit
1319 end
1320
1321 # A single callback declaration on a cast to a nullable type
1322 class AAsNullableExternCall
1323 super ACastExternCall
1324
1325 # The origin type to cast as nullable
1326 var n_type: AType is writable, noinit
1327
1328 # The `as` keyword
1329 var n_kwas: TKwas is writable, noinit
1330
1331 # The `nullable` keyword
1332 var n_kwnullable: TKwnullable is writable, noinit
1333 end
1334
1335 # A single callback declaration on a cast to a non-nullable type
1336 class AAsNotNullableExternCall
1337 super ACastExternCall
1338
1339 # The destination type on a cast to not nullable
1340 var n_type: AType is writable, noinit
1341
1342 # The `as` keyword.
1343 var n_kwas: TKwas is writable, noinit
1344
1345 # The `not` keyword
1346 var n_kwnot: TKwnot is writable, noinit
1347
1348 # The `nullable` keyword
1349 var n_kwnullable: TKwnullable is writable, noinit
1350 end
1351
1352 # A definition of a virtual type
1353 class ATypePropdef
1354 super APropdef
1355
1356 # The `type` keyword
1357 var n_kwtype: TKwtype is writable, noinit
1358
1359 # The name of the virtual type
1360 var n_id: TClassid is writable, noinit
1361
1362 # The bound of the virtual type
1363 var n_type: AType is writable, noinit
1364 end
1365
1366 # The identifier of a method in a method declaration.
1367 # There is a specific class because of operator and setters.
1368 abstract class AMethid
1369 super Prod
1370 end
1371
1372 # A method name with a simple identifier
1373 class AIdMethid
1374 super AMethid
1375
1376 # The simple identifier
1377 var n_id: TId is writable, noinit
1378 end
1379
1380 # A method name `+`
1381 class APlusMethid
1382 super AMethid
1383
1384 # The `+` symbol
1385 var n_plus: TPlus is writable, noinit
1386 end
1387
1388 # A method name `-`
1389 class AMinusMethid
1390 super AMethid
1391
1392 # The `-` symbol
1393 var n_minus: TMinus is writable, noinit
1394 end
1395
1396 # A method name `*`
1397 class AStarMethid
1398 super AMethid
1399
1400 # The `*` symbol
1401 var n_star: TStar is writable, noinit
1402 end
1403
1404 # A method name `**`
1405 class AStarstarMethid
1406 super AMethid
1407
1408 # The `**` symbol
1409 var n_starstar: TStarstar is writable, noinit
1410 end
1411
1412 # A method name `/`
1413 class ASlashMethid
1414 super AMethid
1415
1416 # The `/` symbol
1417 var n_slash: TSlash is writable, noinit
1418 end
1419
1420 # A method name `%`
1421 class APercentMethid
1422 super AMethid
1423
1424 # The `%` symbol
1425 var n_percent: TPercent is writable, noinit
1426 end
1427
1428 # A method name `==`
1429 class AEqMethid
1430 super AMethid
1431
1432 # The `==` symbol
1433 var n_eq: TEq is writable, noinit
1434 end
1435
1436 # A method name `!=`
1437 class ANeMethid
1438 super AMethid
1439
1440 # The `!=` symbol
1441 var n_ne: TNe is writable, noinit
1442 end
1443
1444 # A method name `<=`
1445 class ALeMethid
1446 super AMethid
1447
1448 # The `<=` symbol
1449 var n_le: TLe is writable, noinit
1450 end
1451
1452 # A method name `>=`
1453 class AGeMethid
1454 super AMethid
1455
1456 # The `>=` symbol
1457 var n_ge: TGe is writable, noinit
1458 end
1459
1460 # A method name `<`
1461 class ALtMethid
1462 super AMethid
1463
1464 # The `<` symbol
1465 var n_lt: TLt is writable, noinit
1466 end
1467
1468 # A method name `>`
1469 class AGtMethid
1470 super AMethid
1471
1472 # The `>` symbol
1473 var n_gt: TGt is writable, noinit
1474 end
1475
1476 # A method name `<<`
1477 class ALlMethid
1478 super AMethid
1479
1480 # The `<<` symbol
1481 var n_ll: TLl is writable, noinit
1482 end
1483
1484 # A method name `>>`
1485 class AGgMethid
1486 super AMethid
1487
1488 # The `>>` symbol
1489 var n_gg: TGg is writable, noinit
1490 end
1491
1492 # A method name `[]`
1493 class ABraMethid
1494 super AMethid
1495
1496 # The `[` symbol
1497 var n_obra: TObra is writable, noinit
1498
1499 # The `]` symbol
1500 var n_cbra: TCbra is writable, noinit
1501 end
1502
1503 # A method name `<=>`
1504 class AStarshipMethid
1505 super AMethid
1506
1507 # The `<=>` symbol
1508 var n_starship: TStarship is writable, noinit
1509 end
1510
1511 # A setter method name with a simple identifier (with a `=`)
1512 class AAssignMethid
1513 super AMethid
1514
1515 # The base identifier
1516 var n_id: TId is writable, noinit
1517
1518 # The `=` symbol
1519 var n_assign: TAssign is writable, noinit
1520 end
1521
1522 # A method name `[]=`
1523 class ABraassignMethid
1524 super AMethid
1525
1526 # The `[` symbol
1527 var n_obra: TObra is writable, noinit
1528
1529 # The `]` symbol
1530 var n_cbra: TCbra is writable, noinit
1531
1532 # The `=` symbol
1533 var n_assign: TAssign is writable, noinit
1534 end
1535
1536 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1537 class ASignature
1538 super Prod
1539
1540 # The `(` symbol
1541 var n_opar: nullable TOpar = null is writable
1542
1543 # The list of parameters
1544 var n_params = new ANodes[AParam](self)
1545
1546 # The `)` symbol
1547 var n_cpar: nullable TCpar = null is writable
1548
1549 # The return type
1550 var n_type: nullable AType = null is writable
1551 end
1552
1553 # A parameter definition in a signature. eg `x:X`
1554 class AParam
1555 super Prod
1556
1557 # The name of the parameter
1558 var n_id: TId is writable, noinit
1559
1560 # The type of the parameter, if any
1561 var n_type: nullable AType = null is writable
1562
1563 # The `...` symbol to indicate varargs
1564 var n_dotdotdot: nullable TDotdotdot = null is writable
1565 end
1566
1567 # A static type. eg `nullable X[Y]`
1568 class AType
1569 super Prod
1570 # The `nullable` keyword
1571 var n_kwnullable: nullable TKwnullable = null is writable
1572
1573 # The name of the class or of the formal type
1574 var n_id: TClassid is writable, noinit
1575
1576 # Type arguments for a generic type
1577 var n_types = new ANodes[AType](self)
1578 end
1579
1580 # A label at the end of a block or in a break/continue statement. eg `label x`
1581 class ALabel
1582 super Prod
1583
1584 # The `label` keyword
1585 var n_kwlabel: TKwlabel is writable, noinit
1586
1587 # The name of the label, if any
1588 var n_id: nullable TId is writable
1589 end
1590
1591 # Expression and statements
1592 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1593 abstract class AExpr
1594 super Prod
1595 end
1596
1597 # A sequence of `AExpr` (usually statements)
1598 # The last `AExpr` gives the value of the whole block
1599 class ABlockExpr
1600 super AExpr
1601
1602 # The list of statements in the bloc.
1603 # The last element is often considered as an expression that give the value of the whole block.
1604 var n_expr = new ANodes[AExpr](self)
1605
1606 # The `end` keyword
1607 var n_kwend: nullable TKwend = null is writable
1608 end
1609
1610 # A declaration of a local variable. eg `var x: X = y`
1611 class AVardeclExpr
1612 super AExpr
1613
1614 # The `var` keyword
1615 var n_kwvar: TKwvar is writable, noinit
1616
1617 # The name of the local variable
1618 var n_id: TId is writable, noinit
1619
1620 # The declaration type of the local variable
1621 var n_type: nullable AType = null is writable
1622
1623 # The `=` symbol (for the initial value)
1624 var n_assign: nullable TAssign = null is writable
1625
1626 # The initial value, if any
1627 var n_expr: nullable AExpr = null is writable
1628 end
1629
1630 # A `return` statement. eg `return x`
1631 class AReturnExpr
1632 super AExpr
1633
1634 # The `return` keyword
1635 var n_kwreturn: nullable TKwreturn = null is writable
1636
1637 # The return value, if any
1638 var n_expr: nullable AExpr = null is writable
1639 end
1640
1641 # Something that has a label.
1642 abstract class ALabelable
1643 super Prod
1644
1645 # The associated label declatation
1646 var n_label: nullable ALabel = null is writable
1647 end
1648
1649 # A `break` or a `continue`
1650 abstract class AEscapeExpr
1651 super AExpr
1652 super ALabelable
1653
1654 # The return value, if nay (unused currently)
1655 var n_expr: nullable AExpr = null is writable
1656 end
1657
1658 # A `break` statement.
1659 class ABreakExpr
1660 super AEscapeExpr
1661
1662 # The `break` keyword
1663 var n_kwbreak: TKwbreak is writable, noinit
1664 end
1665
1666 # An `abort` statement
1667 class AAbortExpr
1668 super AExpr
1669
1670 # The `abort` keyword
1671 var n_kwabort: TKwabort is writable, noinit
1672 end
1673
1674 # A `continue` statement
1675 class AContinueExpr
1676 super AEscapeExpr
1677
1678 # The `continue` keyword.
1679 var n_kwcontinue: nullable TKwcontinue = null is writable
1680 end
1681
1682 # A `do` statement
1683 class ADoExpr
1684 super AExpr
1685 super ALabelable
1686
1687 # The `do` keyword
1688 var n_kwdo: TKwdo is writable, noinit
1689
1690 # The list of statements of the `do`.
1691 var n_block: nullable AExpr = null is writable
1692 end
1693
1694 # A `if` statement
1695 class AIfExpr
1696 super AExpr
1697
1698 # The `if` keyword
1699 var n_kwif: TKwif is writable, noinit
1700
1701 # The expression used as the condition of the `if`
1702 var n_expr: AExpr is writable, noinit
1703
1704 # The body of the `then` part
1705 var n_then: nullable AExpr = null is writable
1706
1707 # The body of the `else` part
1708 var n_else: nullable AExpr = null is writable
1709 end
1710
1711 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1712 class AIfexprExpr
1713 super AExpr
1714
1715 # The `if` keyword
1716 var n_kwif: TKwif is writable, noinit
1717
1718 # The expression used as the condition of the `if`
1719 var n_expr: AExpr is writable, noinit
1720
1721 # The `then` keyword
1722 var n_kwthen: TKwthen is writable, noinit
1723
1724 # The expression in the `then` part
1725 var n_then: AExpr is writable, noinit
1726
1727 # The `else` keyword
1728 var n_kwelse: TKwelse is writable, noinit
1729
1730 # The expression in the `else` part
1731 var n_else: AExpr is writable, noinit
1732 end
1733
1734 # A `while` statement
1735 class AWhileExpr
1736 super AExpr
1737 super ALabelable
1738
1739 # The `while` keyword
1740 var n_kwwhile: TKwwhile is writable, noinit
1741
1742 # The expression used as the condition of the `while`
1743 var n_expr: AExpr is writable, noinit
1744
1745 # The `do` keyword
1746 var n_kwdo: TKwdo is writable, noinit
1747
1748 # The body of the loop
1749 var n_block: nullable AExpr = null is writable
1750 end
1751
1752 # A `loop` statement
1753 class ALoopExpr
1754 super AExpr
1755 super ALabelable
1756
1757 # The `loop` keyword
1758 var n_kwloop: TKwloop is writable, noinit
1759
1760 # The body of the loop
1761 var n_block: nullable AExpr = null is writable
1762 end
1763
1764 # A `for` statement
1765 class AForExpr
1766 super AExpr
1767 super ALabelable
1768
1769 # The `for` keyword
1770 var n_kwfor: TKwfor is writable, noinit
1771
1772 # The list of name of the automatic variables
1773 var n_ids = new ANodes[TId](self)
1774
1775 # The expression used as the collection to iterate on
1776 var n_expr: AExpr is writable, noinit
1777
1778 # The `do` keyword
1779 var n_kwdo: TKwdo is writable, noinit
1780
1781 # The body of the loop
1782 var n_block: nullable AExpr = null is writable
1783 end
1784
1785 # An `assert` statement
1786 class AAssertExpr
1787 super AExpr
1788
1789 # The `assert` keyword
1790 var n_kwassert: TKwassert is writable, noinit
1791
1792 # The name of the assert, if any
1793 var n_id: nullable TId = null is writable
1794
1795 # The expression used as the condition of the `assert`
1796 var n_expr: AExpr is writable, noinit
1797
1798 # The body to execute when the assert fails
1799 var n_else: nullable AExpr = null is writable
1800 end
1801
1802 # Whatever is a simple assignment. eg `= something`
1803 abstract class AAssignFormExpr
1804 super AExpr
1805
1806 # The `=` symbol
1807 var n_assign: TAssign is writable, noinit
1808
1809 # The right-value to assign.
1810 var n_value: AExpr is writable, noinit
1811 end
1812
1813 # Whatever is a combined assignment. eg `+= something`
1814 abstract class AReassignFormExpr
1815 super AExpr
1816
1817 # The combined operator (eg. `+=`)
1818 var n_assign_op: AAssignOp is writable, noinit
1819
1820 # The right-value to apply on the combined operator.
1821 var n_value: AExpr is writable, noinit
1822 end
1823
1824 # A `once` expression. eg `once x`
1825 class AOnceExpr
1826 super AExpr
1827
1828 # The `once` keyword
1829 var n_kwonce: TKwonce is writable, noinit
1830
1831 # The expression to evaluate only one time
1832 var n_expr: AExpr is writable, noinit
1833 end
1834
1835 # A polymorphic invocation of a method
1836 # The form of the invocation (name, arguments, etc.) are specific
1837 abstract class ASendExpr
1838 super AExpr
1839 # The receiver of the method invocation
1840 var n_expr: AExpr is writable, noinit
1841 end
1842
1843 # A binary operation on a method
1844 abstract class ABinopExpr
1845 super ASendExpr
1846 # The second operand of the operation
1847 # Note: the receiver (`n_expr`) is the first operand
1848 var n_expr2: AExpr is writable, noinit
1849 end
1850
1851 # Something that is boolean expression
1852 abstract class ABoolExpr
1853 super AExpr
1854 end
1855
1856 # Something that is binary boolean expression
1857 abstract class ABinBoolExpr
1858 super ABoolExpr
1859
1860 # The first boolean operand
1861 var n_expr: AExpr is writable, noinit
1862
1863 # The second boolean operand
1864 var n_expr2: AExpr is writable, noinit
1865 end
1866
1867 # A `or` expression
1868 class AOrExpr
1869 super ABinBoolExpr
1870 end
1871
1872 # A `and` expression
1873 class AAndExpr
1874 super ABinBoolExpr
1875 end
1876
1877 # A `or else` expression
1878 class AOrElseExpr
1879 super ABinBoolExpr
1880 end
1881
1882 # A `implies` expression
1883 class AImpliesExpr
1884 super ABinBoolExpr
1885 end
1886
1887 # A `not` expression
1888 class ANotExpr
1889 super ABoolExpr
1890
1891 # The `not` keyword
1892 var n_kwnot: TKwnot is writable, noinit
1893
1894 # The boolean operand of the `not`
1895 var n_expr: AExpr is writable, noinit
1896 end
1897
1898 # A `==` expression
1899 class AEqExpr
1900 super ABinopExpr
1901 end
1902
1903 # A `!=` expression
1904 class ANeExpr
1905 super ABinopExpr
1906 end
1907
1908 # A `<` expression
1909 class ALtExpr
1910 super ABinopExpr
1911 end
1912
1913 # A `<=` expression
1914 class ALeExpr
1915 super ABinopExpr
1916 end
1917
1918 # A `<<` expression
1919 class ALlExpr
1920 super ABinopExpr
1921 end
1922
1923 # A `>` expression
1924 class AGtExpr
1925 super ABinopExpr
1926 end
1927
1928 # A `>=` expression
1929 class AGeExpr
1930 super ABinopExpr
1931 end
1932
1933 # A `>>` expression
1934 class AGgExpr
1935 super ABinopExpr
1936 end
1937
1938 # A type-ckeck expression. eg `x isa T`
1939 class AIsaExpr
1940 super ABoolExpr
1941
1942 # The expression to check
1943 var n_expr: AExpr is writable, noinit
1944
1945 # The destination type to check to
1946 var n_type: AType is writable, noinit
1947 end
1948
1949 # A `+` expression
1950 class APlusExpr
1951 super ABinopExpr
1952 end
1953
1954 # A `-` expression
1955 class AMinusExpr
1956 super ABinopExpr
1957 end
1958
1959 # A `<=>` expression
1960 class AStarshipExpr
1961 super ABinopExpr
1962 end
1963
1964 # A `*` expression
1965 class AStarExpr
1966 super ABinopExpr
1967 end
1968
1969 # A `**` expression
1970 class AStarstarExpr
1971 super ABinopExpr
1972 end
1973
1974 # A `/` expression
1975 class ASlashExpr
1976 super ABinopExpr
1977 end
1978
1979 # A `%` expression
1980 class APercentExpr
1981 super ABinopExpr
1982 end
1983
1984 # A unary minus expression. eg `-x`
1985 class AUminusExpr
1986 super ASendExpr
1987
1988 # The `-` symbol
1989 var n_minus: TMinus is writable, noinit
1990 end
1991
1992 # An explicit instantiation. eg `new T`
1993 class ANewExpr
1994 super AExpr
1995
1996 # The `new` keyword
1997 var n_kwnew: TKwnew is writable, noinit
1998
1999 # The `type` keyword
2000 var n_type: AType is writable, noinit
2001
2002 # The name of the named-constructor, if any
2003 var n_id: nullable TId = null is writable
2004
2005 # The arguments of the `new`
2006 var n_args: AExprs is writable, noinit
2007 end
2008
2009 # Whatever is a old-style attribute access
2010 abstract class AAttrFormExpr
2011 super AExpr
2012
2013 # The receiver of the attribute
2014 var n_expr: AExpr is writable, noinit
2015
2016 # The name of the attribute
2017 var n_id: TAttrid is writable, noinit
2018
2019 end
2020
2021 # The read of an attribute. eg `x._a`
2022 class AAttrExpr
2023 super AAttrFormExpr
2024 end
2025
2026 # The assignment of an attribute. eg `x._a=y`
2027 class AAttrAssignExpr
2028 super AAttrFormExpr
2029 super AAssignFormExpr
2030 end
2031
2032 # Whatever looks-like a call with a standard method and any number of arguments.
2033 abstract class ACallFormExpr
2034 super ASendExpr
2035
2036 # The name of the method
2037 var n_id: TId is writable, noinit
2038
2039 # The arguments of the call
2040 var n_args: AExprs is writable, noinit
2041 end
2042
2043 # A complex setter call (standard or brackets)
2044 abstract class ASendReassignFormExpr
2045 super ASendExpr
2046 super AReassignFormExpr
2047 end
2048
2049 # A complex attribute assignment. eg `x._a+=y`
2050 class AAttrReassignExpr
2051 super AAttrFormExpr
2052 super AReassignFormExpr
2053 end
2054
2055 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2056 # Note: because the parser cannot distinguish a variable read with a method call with an implicit receiver and no arguments, it always returns a `ACallExpr`.
2057 # Semantic analysis have to transform them to instance of `AVarExpr`.
2058 class ACallExpr
2059 super ACallFormExpr
2060 end
2061
2062 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2063 # Note: because the parser cannot distinguish a variable write with a setter call with an implicit receiver and no arguments, it always returns a `ACallAssignExpr`.
2064 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2065 class ACallAssignExpr
2066 super ACallFormExpr
2067 super AAssignFormExpr
2068 end
2069
2070 # A complex setter call with a standard method-name and any number of arguments. eg `x.m(y)+=z`. OR just a simple complex assignment.
2071 # Note: because the parser cannot distinguish a variable write with a complex setter call with an implicit receiver and no arguments, it always returns a `ACallReassignExpr`.
2072 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2073 class ACallReassignExpr
2074 super ACallFormExpr
2075 super ASendReassignFormExpr
2076 end
2077
2078 # A call to `super`. OR a call of a super-constructor
2079 class ASuperExpr
2080 super AExpr
2081
2082 # The qualifier part before the super (currenlty unused)
2083 var n_qualified: nullable AQualified = null is writable
2084
2085 # The `super` keyword
2086 var n_kwsuper: TKwsuper is writable, noinit
2087
2088 # The arguments of the super
2089 var n_args: AExprs is writable, noinit
2090 end
2091
2092 # A call to the `init` constructor.
2093 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2094 class AInitExpr
2095 super ASendExpr
2096
2097 # The `init` keyword
2098 var n_kwinit: TKwinit is writable, noinit
2099
2100 # The arguments of the init
2101 var n_args: AExprs is writable, noinit
2102 end
2103
2104 # Whatever looks-like a call of the brackets `[]` operator.
2105 abstract class ABraFormExpr
2106 super ASendExpr
2107
2108 # The arguments inside the brackets
2109 var n_args: AExprs is writable, noinit
2110 end
2111
2112 # A call of the brackets operator. eg `x[y,z]`
2113 class ABraExpr
2114 super ABraFormExpr
2115 end
2116
2117 # A setter call of the bracket operator. eg `x[y,z]=t`
2118 class ABraAssignExpr
2119 super ABraFormExpr
2120 super AAssignFormExpr
2121 end
2122
2123 # Whatever is an access to a local variable
2124 abstract class AVarFormExpr
2125 super AExpr
2126
2127 # The name of the attribute
2128 var n_id: TId is writable, noinit
2129 end
2130
2131 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2132 class ABraReassignExpr
2133 super ABraFormExpr
2134 super ASendReassignFormExpr
2135 end
2136
2137 # A local variable read access.
2138 # The parser cannot instantiate them, see `ACallExpr`.
2139 class AVarExpr
2140 super AVarFormExpr
2141 end
2142
2143 # A local variable simple assignment access
2144 # The parser cannot instantiate them, see `ACallAssignExpr`.
2145 class AVarAssignExpr
2146 super AVarFormExpr
2147 super AAssignFormExpr
2148 end
2149
2150 # A local variable complex assignment access
2151 # The parser cannot instantiate them, see `ACallReassignExpr`.
2152 class AVarReassignExpr
2153 super AVarFormExpr
2154 super AReassignFormExpr
2155 end
2156
2157 # A literal range, open or closed
2158 abstract class ARangeExpr
2159 super AExpr
2160
2161 # The left (lower) element of the range
2162 var n_expr: AExpr is writable, noinit
2163
2164 # The right (uppr) element of the range
2165 var n_expr2: AExpr is writable, noinit
2166 end
2167
2168 # A closed literal range. eg `[x..y]`
2169 class ACrangeExpr
2170 super ARangeExpr
2171
2172 # The opening bracket `[`
2173 var n_obra: TObra is writable, noinit
2174
2175 # The closing bracket `]`
2176 var n_cbra: TCbra is writable, noinit
2177 end
2178
2179 # An open literal range. eg `[x..y[`
2180 class AOrangeExpr
2181 super ARangeExpr
2182
2183 # The opening bracket `[`
2184 var n_obra: TObra is writable, noinit
2185
2186 # The closing bracket `[` (because open range)
2187 var n_cbra: TObra is writable, noinit
2188 end
2189
2190 # A literal array. eg. `[x,y,z]`
2191 class AArrayExpr
2192 super AExpr
2193
2194 # The opening bracket `[`
2195 var n_obra: TObra is writable, noinit
2196
2197 # The elements of the array
2198 var n_exprs = new ANodes[AExpr](self)
2199
2200 # The type of the element of the array (if any)
2201 var n_type: nullable AType = null is writable
2202
2203 # The closing bracket `]`
2204 var n_cbra: TCbra is writable, noinit
2205 end
2206
2207 # A read of `self`
2208 class ASelfExpr
2209 super AExpr
2210
2211 # The `self` keyword
2212 var n_kwself: nullable TKwself is writable
2213 end
2214
2215 # When there is no explicit receiver, `self` is implicit
2216 class AImplicitSelfExpr
2217 super ASelfExpr
2218 end
2219
2220 # A `true` boolean literal constant
2221 class ATrueExpr
2222 super ABoolExpr
2223
2224 # The `true` keyword
2225 var n_kwtrue: TKwtrue is writable, noinit
2226 end
2227
2228 # A `false` boolean literal constant
2229 class AFalseExpr
2230 super ABoolExpr
2231
2232 # The `false` keyword
2233 var n_kwfalse: TKwfalse is writable, noinit
2234 end
2235
2236 # A `null` literal constant
2237 class ANullExpr
2238 super AExpr
2239
2240 # The `null` keyword
2241 var n_kwnull: TKwnull is writable, noinit
2242 end
2243
2244 # An integer literal
2245 class AIntExpr
2246 super AExpr
2247 end
2248
2249 # An integer literal in decimal format
2250 class ADecIntExpr
2251 super AIntExpr
2252
2253 # The decimal token
2254 var n_number: TNumber is writable, noinit
2255 end
2256
2257 # An integer literal in hexadecimal format
2258 class AHexIntExpr
2259 super AIntExpr
2260
2261 # The hexadecimal token
2262 var n_hex_number: THexNumber is writable, noinit
2263 end
2264
2265 # A float literal
2266 class AFloatExpr
2267 super AExpr
2268
2269 # The float token
2270 var n_float: TFloat is writable, noinit
2271 end
2272
2273 # A character literal
2274 class ACharExpr
2275 super AExpr
2276
2277 # The character token
2278 var n_char: TChar is writable, noinit
2279 end
2280
2281 # A string literal
2282 abstract class AStringFormExpr
2283 super AExpr
2284
2285 # The string token
2286 var n_string: Token is writable, noinit
2287 end
2288
2289 # A simple string. eg. `"abc"`
2290 class AStringExpr
2291 super AStringFormExpr
2292 end
2293
2294 # The start of a superstring. eg `"abc{`
2295 class AStartStringExpr
2296 super AStringFormExpr
2297 end
2298
2299 # The middle of a superstring. eg `}abc{`
2300 class AMidStringExpr
2301 super AStringFormExpr
2302 end
2303
2304 # The end of a superstrng. eg `}abc"`
2305 class AEndStringExpr
2306 super AStringFormExpr
2307 end
2308
2309 # A superstring literal. eg `"a{x}b{y}c"`
2310 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2311 class ASuperstringExpr
2312 super AExpr
2313
2314 # The list of the expressions of the superstring
2315 var n_exprs = new ANodes[AExpr](self)
2316 end
2317
2318 # A simple parenthesis. eg `(x)`
2319 class AParExpr
2320 super AExpr
2321
2322 # The opening parenthesis
2323 var n_opar: TOpar is writable, noinit
2324
2325 # The inner expression
2326 var n_expr: AExpr is writable, noinit
2327
2328 # The closing parenthesis
2329 var n_cpar: TCpar is writable, noinit
2330 end
2331
2332 # A cast, against a type or `not null`
2333 class AAsCastForm
2334 super AExpr
2335
2336 # The expression to cast
2337 var n_expr: AExpr is writable, noinit
2338
2339 # The `as` keyword
2340 var n_kwas: TKwas is writable, noinit
2341
2342 # The opening parenthesis
2343 var n_opar: nullable TOpar = null is writable
2344
2345 # The closing parenthesis
2346 var n_cpar: nullable TCpar = null is writable
2347 end
2348
2349 # A type cast. eg `x.as(T)`
2350 class AAsCastExpr
2351 super AAsCastForm
2352
2353 # The target type to cast to
2354 var n_type: AType is writable, noinit
2355 end
2356
2357 # A as-not-null cast. eg `x.as(not null)`
2358 class AAsNotnullExpr
2359 super AAsCastForm
2360
2361 # The `not` keyword
2362 var n_kwnot: TKwnot is writable, noinit
2363
2364 # The `null` keyword
2365 var n_kwnull: TKwnull is writable, noinit
2366 end
2367
2368 # A is-set check of old-style attributes. eg `isset x._a`
2369 class AIssetAttrExpr
2370 super AAttrFormExpr
2371
2372 # The `isset` keyword
2373 var n_kwisset: TKwisset is writable, noinit
2374 end
2375
2376 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2377 class AVarargExpr
2378 super AExpr
2379
2380 # The passed expression
2381 var n_expr: AExpr is writable, noinit
2382
2383 # The `...` symbol
2384 var n_dotdotdot: TDotdotdot is writable, noinit
2385 end
2386
2387 # A list of expression separated with commas (arguments for instance)
2388 class AManyExpr
2389 super AExpr
2390
2391 # The list of expressions
2392 var n_exprs = new ANodes[AExpr](self)
2393 end
2394
2395 # A special expression that encapsulates a static type
2396 # Can only be found in special construction like arguments of annotations.
2397 class ATypeExpr
2398 super AExpr
2399
2400 # The encapsulated type
2401 var n_type: AType is writable, noinit
2402 end
2403
2404 # A special expression that encapsulates a method identifier
2405 # Can only be found in special construction like arguments of annotations.
2406 class AMethidExpr
2407 super AExpr
2408
2409 # The receiver
2410 var n_expr: AExpr is writable, noinit
2411
2412 # The encapsulated method identifier
2413 var n_id: AMethid is writable, noinit
2414 end
2415
2416 # A special expression that encapsulate an annotation
2417 # Can only be found in special construction like arguments of annotations.
2418 #
2419 # The encapsulated annotations are in `n_annotations`
2420 class AAtExpr
2421 super AExpr
2422 end
2423
2424 # A special expression to debug types
2425 class ADebugTypeExpr
2426 super AExpr
2427
2428 # The `debug` keyword
2429 var n_kwdebug: TKwdebug is writable, noinit
2430
2431 # The `type` keyword
2432 var n_kwtype: TKwtype is writable, noinit
2433
2434 # The expression to check
2435 var n_expr: AExpr is writable, noinit
2436
2437 # The type to check
2438 var n_type: AType is writable, noinit
2439 end
2440
2441 # A list of expression separated with commas (arguments for instance)
2442 abstract class AExprs
2443 super Prod
2444
2445 # The list of expressions
2446 var n_exprs = new ANodes[AExpr](self)
2447 end
2448
2449 # A simple list of expressions
2450 class AListExprs
2451 super AExprs
2452 end
2453
2454 # A list of expressions enclosed in parentheses
2455 class AParExprs
2456 super AExprs
2457
2458 # The opening parenthesis
2459 var n_opar: TOpar is writable, noinit
2460
2461 # The closing parenthesis
2462 var n_cpar: TCpar is writable, noinit
2463 end
2464
2465 # A list of expressions enclosed in brackets
2466 class ABraExprs
2467 super AExprs
2468
2469 # The opening bracket
2470 var n_obra: TObra is writable, noinit
2471
2472 # The closing bracket
2473 var n_cbra: TCbra is writable, noinit
2474 end
2475
2476 # A complex assignment operator. (`+=` and `-=`)
2477 abstract class AAssignOp
2478 super Prod
2479 end
2480
2481 # The `+=` assignment operation
2482 class APlusAssignOp
2483 super AAssignOp
2484
2485 # The `+=` operator
2486 var n_pluseq: TPluseq is writable, noinit
2487 end
2488
2489 # The `-=` assignment operator
2490 class AMinusAssignOp
2491 super AAssignOp
2492
2493 # The `-=` operator
2494 var n_minuseq: TMinuseq is writable, noinit
2495 end
2496
2497 # A possibly fully-qualified module identifier
2498 class AModuleName
2499 super Prod
2500
2501 # The starting quad (`::`)
2502 var n_quad: nullable TQuad = null is writable
2503
2504 # The list of quad-separated project/group identifiers
2505 var n_path = new ANodes[TId](self)
2506
2507 # The final module identifier
2508 var n_id: TId is writable, noinit
2509 end
2510
2511 # A language declaration for an extern block
2512 class AInLanguage
2513 super Prod
2514
2515 # The `in` keyword
2516 var n_kwin: TKwin is writable, noinit
2517
2518 # The language name
2519 var n_string: TString is writable, noinit
2520 end
2521
2522 # An full extern block
2523 class AExternCodeBlock
2524 super Prod
2525
2526 # The language declration
2527 var n_in_language: nullable AInLanguage = null is writable
2528
2529 # The block of extern code
2530 var n_extern_code_segment: TExternCodeSegment is writable, noinit
2531 end
2532
2533 # A possible full method qualifier.
2534 class AQualified
2535 super Prod
2536
2537 # The starting quad (`::`)
2538 var n_quad: nullable TQuad = null is writable
2539
2540 # The list of quad-separated project/group/module identifiers
2541 var n_id = new ANodes[TId](self)
2542
2543 # A class identifier
2544 var n_classid: nullable TClassid = null is writable
2545 end
2546
2547 # A documentation of a definition
2548 # It contains the block of comments just above the declaration
2549 class ADoc
2550 super Prod
2551
2552 # A list of lines of comment
2553 var n_comment = new ANodes[TComment](self)
2554 end
2555
2556 # A group of annotation on a node
2557 #
2558 # This same class is used for the 3 kind of annotations:
2559 #
2560 # * *is* annotations. eg `module foo is bar`.
2561 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2562 # * *class* annotations, defined in classes.
2563 class AAnnotations
2564 super Prod
2565
2566 # The `@` symbol, for *at* annotations
2567 var n_at: nullable TAt = null is writable
2568
2569 # The opening parenthesis in *at* annotations
2570 var n_opar: nullable TOpar = null is writable
2571
2572 # The list of annotations
2573 var n_items = new ANodes[AAnnotation](self)
2574
2575 # The closing parenthesis in *at* annotations
2576 var n_cpar: nullable TCpar = null is writable
2577 end
2578
2579 # A single annotation
2580 class AAnnotation
2581 super ADefinition
2582
2583 # The name of the annotation
2584 var n_atid: AAtid is writable, noinit
2585
2586 # The opening parenthesis of the arguments
2587 var n_opar: nullable TOpar = null is writable
2588
2589 # The list of arguments
2590 var n_args = new ANodes[AExpr](self)
2591
2592 # The closing parenthesis
2593 var n_cpar: nullable TCpar = null is writable
2594
2595 # The name of the annotation
2596 fun name: String
2597 do
2598 return n_atid.n_id.text
2599 end
2600 end
2601
2602 # An annotation name
2603 abstract class AAtid
2604 super Prod
2605
2606 # The identifier of the annotation.
2607 # Can be a TId of a keyword
2608 var n_id: Token is writable, noinit
2609 end
2610
2611 # An annotation name based on an identifier
2612 class AIdAtid
2613 super AAtid
2614 end
2615
2616 # An annotation name based on the keyword `extern`
2617 class AKwexternAtid
2618 super AAtid
2619 end
2620
2621 # An annotation name based on the keyword `import`
2622 class AKwimportAtid
2623 super AAtid
2624 end
2625
2626 # An annotation name based on the keyword `abstract`
2627 class AKwabstractAtid
2628 super AAtid
2629 end
2630
2631 # The root of the AST
2632 class Start
2633 super Prod
2634
2635 # The main module
2636 var n_base: nullable AModule is writable
2637
2638 # The end of file (or error) token
2639 var n_eof: EOF is writable
2640 end