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