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