FreeBASIC  0.91.0
ast.bi
Go to the documentation of this file.
1 #ifndef __AST_BI__
2 #define __AST_BI__
3 
4 #include once "list.bi"
5 #include once "ast-op.bi"
6 
7 const AST_INITNODES = 8192
8 const AST_INITPROCNODES = 128
9 
10 '' when changing, update ast.bas:ast_loadcallbacks() and ast-node-misc.bas:dbg_astNodeClassNames()
11 enum AST_NODECLASS
13 
26 
27  '' LOOP nodes, used to wrap loop code (e.g. new[]'s defctor calling)
28  '' that needs to be LINKed into expression trees, because it isn't
29  '' immediately astAdd()'ed, thus may be cloned. The LOOP wrapper node
30  '' allows astCloneTree() to duplicate the loop's LABEL and also update
31  '' the corresponding BRANCH.
33 
34  '' Only used to classify comparison operators, there are no COMP nodes.
36 
47 
49 
55 
58 
62 
70 
72 
74 end enum
75 
76 enum AST_OPOPT
77  AST_OPOPT_NONE = &h00000000
78 
79  AST_OPOPT_ALLOCRES = &h00000001
80  AST_OPOPT_LPTRARITH = &h00000002
81  AST_OPOPT_RPTRARITH = &h00000004
82  AST_OPOPT_NOCOERCION = &h00000008
83  AST_OPOPT_DONTCHKPTR = &h00000010
84  AST_OPOPT_DONTCHKOPOVL = &h00000020
85  AST_OPOPT_ISINI = &h00000040
86 
88 
90 end enum
91 
92 #ifndef ASTNODE_
94 #endif
95 
96 '' update astCloneCALL( ), astDelCALL() if the next structs are changed
98  sym as FBSYMBOL ptr
101 end type
102 
104  isrtl as integer
105  args as integer
106  currarg as FBSYMBOL ptr
107  argtail as ASTNODE_ ptr
109  tmpres as FBSYMBOL ptr '' temp result structure, if needed
110 end type
111 
113  mode as integer '' to pass NULL's to byref args, etc
114  lgt as longint '' length, used to push UDT's by value
115 end type
116 
118  ofs as longint '' offset
119 end type
120 
122  ofs as longint '' offset
123  mult as integer '' multipler
124  '' Note: the multiplier field is used in combination with x86 ASM-backend specific
125  '' optimizations only, see hOptConstIdxMult().
126 end type
127 
129  ofs as longint '' offset
130 end type
131 
133  falselabel as FBSYMBOL ptr
134 end type
135 
137  isres as integer
138 end type
139 
141  flush as integer
142 end type
143 
145  text as zstring ptr
146 end type
147 
148 enum AST_ASMTOKTYPE
151 end enum
152 
155  union
156  sym as FBSYMBOL ptr
157  text as zstring ptr
158  end union
159  next as ASTASMTOK ptr
160 end type
161 
164 end type
165 
166 type AST_NODE_OP '' used by: bop, uop, addr
167  op as integer
168  options as AST_OPOPT
169  ex as FBSYMBOL ptr '' (extra: label, etc)
170 end type
171 
173  ofs as longint
174 end type
175 
177  '' Dynamically allocated buffer holding the jmptb's value/label pairs
178  values as ulongint ptr
179  labels as FBSYMBOL ptr ptr
180  labelcount as integer
181 
182  deflabel as FBSYMBOL ptr
183  minval as ulongint
184  maxval as ulongint
185 end type
186 
188  ex as integer
189  op as integer
190 end type
191 
193  bytes as longint
194  op as integer
195 end type
196 
198  op as integer
199 end type
200 
202  ofs as longint
203  union
204  bytes as longint
205  elements as longint
206  end union
207  scp as FBSYMBOL ptr
208  lastscp as FBSYMBOL ptr
209 end type
210 
212  parent as ASTNODE_ ptr
213  scope as integer
214  linenum as integer
215  stmtnum as integer '' can't use colnum as it's unreliable
216 end type
217 
219  head as ASTNODE_ ptr
220  tail as ASTNODE_ ptr
221 end type
222 
224  ismain as integer
225  decl_last as ASTNODE_ ptr '' to support implicit variables decl
226 end type
227 
229  parent as ASTNODE_ ptr
230  inistmt as integer
231  endstmt as integer
232  initlabel as FBSYMBOL ptr
233  exitlabel as FBSYMBOL ptr
236 end type
237 
239  union
240  id as integer
241  elmts as integer
242  end union
243 end type
244 
246  ret_left as integer
247 end type
248 
250  doconv as integer '' do conversion (TRUE or FALSE)
251  do_convfd2fs as integer '' whether or not to ensure truncation in double2single conversions
252 end type
253 
254 ''
256  class as AST_NODECLASS
257 
258  dtype as integer
259  subtype as FBSYMBOL ptr
260 
261  sym as FBSYMBOL ptr '' attached symbol
262 
263  vector as integer '' 0, 2, 3, or 4 (> 2 for single only)
264 
265  union
266  val as FBVALUE '' CONST nodes
267  var_ as AST_NODE_VAR
268  idx as AST_NODE_IDX
269  ptr as AST_NODE_PTR
271  arg as AST_NODE_ARG
272  iif as AST_NODE_IIF
273  op as AST_NODE_OP
274  lod as AST_NODE_LOAD
276  ofs as AST_NODE_OFFS
277  lit as AST_NODE_LIT
278  asm as AST_NODE_ASM
280  dbg as AST_NODE_DBG
281  mem as AST_NODE_MEM
284  block as AST_NODE_BLOCK '' shared by PROC and SCOPE nodes
285  break as AST_NODE_BREAK
289  end union
290 
291  l as ASTNODE ptr '' left node
292  r as ASTNODE ptr '' right /
293 
294  prev as ASTNODE ptr '' used by astAdd()
295  next as ASTNODE ptr '' /
296 end type
297 
299  head as ASTNODE ptr '' procs list
300  tail as ASTNODE ptr '' / /
301  curr as ASTNODE ptr '' current proc
302 end type
303 
305  tmpstrlist as TLIST '' list of temp strings
306 end type
307 
309  list as TLIST '' global symbols with ctors/dtors
310  ctorcnt as integer '' number of ctors in the list above
311  dtorcnt as integer '' / dtors /
312 end type
313 
315  desc as FBSYMBOL ptr
316  lastsym as FBSYMBOL ptr
317  firstsym as FBSYMBOL ptr
318  lastlbl as FBSYMBOL ptr
319 end type
320 
322  sym as FBSYMBOL ptr
323 
324  '' Some integer used to identify temp vars from expressions nested
325  '' inside the true/false expressions of iif()'s, which may have to be
326  '' destroyed conditionally, depending on which code path was executed.
327  cookie as integer
328 
329  refcount as integer
330 end type
331 
333  '' Grow array; the stack of cookies of the current live dtorlist scopes
334  cookies as integer ptr
335  count as integer
336  room as integer
337 end type
338 
339 type ASTCTX
340  astTB as TLIST
341 
342  proc as AST_PROC_CTX
343  call as AST_CALL_CTX
344  globinst as AST_GLOBINST_CTX '' global instances
345  data as AST_DATASTMT_CTX '' DATA stmt garbage
346 
347  currblock as ASTNODE ptr '' current scope block (PROC or SCOPE)
348 
349  doemit as integer
350 
351  '' Count of TYPEINI nodes in expressions that are about to be astAdd()ed
352  '' (so astAdd() only bothers running astTypeIniUpdate() if it's really
353  '' necessary -- another pass besides astOptimizeTree() walking the
354  '' whole expression tree during every astAdd() would just be
355  '' unnecessarily slow)
356  typeinicount as integer
357 
358  '' Same for FIELD with bitfield type (for astUpdateBitfields())
359  bitfieldcount as integer
360 
361  '' The counters must always be >= the amount of corresponding nodes that
362  '' will be given to astAdd() so that the updating functions don't miss
363  '' anything. That's why it's important to update the counters during
364  '' astCloneTree() for example. On the other hand, nodes in field or
365  '' parameter initializers don't need to be counted, since these
366  '' expressions will always be cloned instead of being astAdd()ed
367  '' themselves. Unfortunately
368 
369  dtorlist as TLIST '' temp dtors list
370  dtorlistscopes as AST_DTORLIST_SCOPESTACK '' scope stack for astDtorListScope*()
371  dtorlistcookies as integer '' Cookie counter used to allocate new cookie numbers
372  flushdtorlist as integer
373 
374  asmtoklist as TLIST '' inline ASM token nodes
375 
376  '' Whether astCheckConst() (called from astNewCONV() called from astNewBOP() etc.)
377  '' should show warnings or not, allowing them to be disabled during optimizations,
378  '' because there overflows (wrap-arounds) can happen due to constant accumulation etc.,
379  '' and the user may not be able to see what the reason for the warning is.
380  '' The warning should only be shown for the user's code, not internals.
381  warn_convoverflow as integer
382 end Type
383 
384 #include once "ir.bi"
385 
386 enum AST_OPFLAGS
387  AST_OPFLAGS_NONE = &h00000000
388  AST_OPFLAGS_SELF = &h00000001 '' op=
389  AST_OPFLAGS_COMM = &h00000002 '' commutative
390  AST_OPFLAGS_NORES = &h00000004 '' no result (it's a SUB)
391 end enum
392 
394  class as AST_NODECLASS
395  flags as AST_OPFLAGS
396  id as const zstring ptr
397  selfop as AST_OP '' self version
398 end type
399 
400 '' astTypeIniFlush flags
401 enum AST_INIOPT
402  AST_INIOPT_NONE = &h00000000
403  AST_INIOPT_ISINI = &h00000001
404  AST_INIOPT_ISSTATIC = &h00000002
405  AST_INIOPT_DODEREF = &h00000004
406 end enum
407 
408 
409 declare sub astInit( )
410 declare sub astEnd( )
411 declare sub astProcListInit( )
412 declare sub astProcListEnd( )
413 declare sub astCallInit( )
414 declare sub astCallEnd( )
415 declare sub astMiscInit( )
416 declare sub astMiscEnd( )
417 declare sub astDataStmtInit( )
418 
419 declare sub astDelNode _
420  ( _
421  byval n as ASTNODE ptr _
422  )
423 
424 declare function astCloneTree( byval n as ASTNODE ptr ) as ASTNODE ptr
425 
426 declare sub astDelTree _
427  ( _
428  byval n as ASTNODE ptr _
429  )
430 
431 declare function astIsTreeEqual _
432  ( _
433  byval l as ASTNODE ptr, _
434  byval r as ASTNODE ptr _
435  ) as integer
436 
437 declare function astIsEqualParamInit _
438  ( _
439  byval l as ASTNODE ptr, _
440  byval r as ASTNODE ptr _
441  ) as integer
442 
443 declare function astIsConstant( byval expr as ASTNODE ptr ) as integer
444 
445 declare sub astProcBegin( byval proc as FBSYMBOL ptr, byval ismain as integer )
446 declare function astProcEnd( byval callrtexit as integer ) as integer
447 
448 declare sub astProcVectorize _
449  ( _
450  byval p as ASTNODE ptr _
451  )
452 
453 declare function astProcAddStaticInstance _
454  ( _
455  byval sym as FBSYMBOL ptr _
456  ) as FBSYMBOL ptr
457 
458 declare sub astProcAddGlobalInstance _
459  ( _
460  byval sym as FBSYMBOL ptr, _
461  byval initree as ASTNODE ptr, _
462  byval has_dtor as integer _
463  )
464 
465 declare function astScopeBegin( ) as ASTNODE ptr
466 declare sub astScopeBreak( byval tolabel as FBSYMBOL ptr )
467 declare sub astScopeEnd( byval s as ASTNODE ptr )
468 declare function astScopeUpdBreakList( byval proc as ASTNODE ptr ) as integer
469 declare sub astScopeDestroyVars( byval symtbtail as FBSYMBOL ptr )
470 declare sub astScopeAllocLocals( byval symtbhead as FBSYMBOL ptr )
471 declare function astTempScopeBegin _
472  ( _
473  byref lastscp as FBSYMBOL ptr, _
474  byval backnode as ASTNODE ptr _
475  ) as FBSYMBOL ptr
476 declare sub astTempScopeEnd _
477  ( _
478  byval scp as FBSYMBOL ptr, _
479  byval lastscp as FBSYMBOL ptr _
480  )
481 declare sub astTempScopeClone _
482  ( _
483  byval scp as FBSYMBOL ptr, _
484  byval clonetree as ASTNODE ptr _
485  )
486 declare sub astTempScopeDelete( byval scp as FBSYMBOL ptr )
487 
488 declare function astAdd _
489  ( _
490  byval n as ASTNODE ptr _
491  ) as ASTNODE ptr
492 
493 declare function astAddAfter _
494  ( _
495  byval n as ASTNODE ptr, _
496  byval ref as ASTNODE ptr _
497  ) as ASTNODE ptr
498 
499 declare sub astAddUnscoped _
500  ( _
501  byval n as ASTNODE ptr _
502  )
503 
504 declare function astFindFirstCode( byval proc as ASTNODE ptr ) as ASTNODE ptr
505 
506 declare function astBuildBranch _
507  ( _
508  byval expr as ASTNODE ptr, _
509  byval label as FBSYMBOL ptr, _
510  byval is_inverse as integer, _
511  byval is_iif as integer = FALSE _
512  ) as ASTNODE ptr
513 
514 declare function astPtrCheck _
515  ( _
516  byval pdtype as integer, _
517  byval psubtype as FBSYMBOL ptr, _
518  byval expr as ASTNODE ptr, _
519  byval strictcheck as integer = FALSE _
520  ) as integer
521 
522 declare function astNewNOP _
523  ( _
524  _
525  ) as ASTNODE ptr
526 
527 declare function astNewASSIGN _
528  ( _
529  byval l as ASTNODE ptr, _
530  byval r as ASTNODE ptr, _
531  byval options as AST_OPOPT = AST_OPOPT_NONE _
532  ) as ASTNODE ptr
533 
534 enum AST_CONVOPT
537  AST_CONVOPT_PTRONLY = &h4
539 end enum
540 
541 declare function astNewCONV _
542  ( _
543  byval to_dtype as integer, _
544  byval to_subtype as FBSYMBOL ptr, _
545  byval l as ASTNODE ptr, _
546  byval options as AST_CONVOPT = 0, _
547  byval perrmsg as integer ptr = NULL _
548  ) as ASTNODE ptr
549 
550 declare function astNewOvlCONV _
551  ( _
552  byval to_dtype as integer, _
553  byval to_subtype as FBSYMBOL ptr, _
554  byval l as ASTNODE ptr _
555  ) as ASTNODE ptr
556 
557 declare sub astUpdateCONVFD2FS _
558  ( _
559  byval n as ASTNODE ptr, _
560  byval dtype as integer, _
561  byval is_expr as integer _
562  )
563 
564 declare function astNewBOP _
565  ( _
566  byval op as integer, _
567  byval l as ASTNODE ptr, _
568  byval r as ASTNODE ptr, _
569  byval ex as FBSYMBOL ptr = NULL, _
570  byval options as AST_OPOPT = AST_OPOPT_DEFAULT _
571  ) as ASTNODE ptr
572 
573 declare function astNewSelfBOP _
574  ( _
575  byval op as integer, _
576  byval l as ASTNODE ptr, _
577  byval r as ASTNODE ptr, _
578  byval ex as FBSYMBOL ptr = NULL, _
579  byval options as AST_OPOPT = AST_OPOPT_DEFAULT _
580  ) as ASTNODE ptr
581 
582 declare function astNewUOP _
583  ( _
584  byval op as integer, _
585  byval o as ASTNODE ptr _
586  ) as ASTNODE ptr
587 
588 declare function astConstEqZero( byval n as ASTNODE ptr ) as integer
589 declare function astConstGeZero( byval n as ASTNODE ptr ) as integer
590 
591 declare function astNewCONST _
592  ( _
593  byval v as FBVALUE ptr, _
594  byval dtype as integer, _
595  byval subtype as FBSYMBOL ptr = NULL _
596  ) as ASTNODE ptr
597 
598 declare function astNewCONSTstr _
599  ( _
600  byval v as zstring ptr _
601  ) as ASTNODE ptr
602 
603 declare function astNewCONSTwstr _
604  ( _
605  byval v as wstring ptr _
606  ) as ASTNODE ptr
607 
608 declare function astNewCONSTi _
609  ( _
610  byval value as longint, _
611  byval dtype as integer = FB_DATATYPE_INTEGER, _
612  byval subtype as FBSYMBOL ptr = NULL _
613  ) as ASTNODE ptr
614 
615 declare function astNewCONSTf _
616  ( _
617  byval value as double, _
618  byval dtype as integer = FB_DATATYPE_DOUBLE _
619  ) as ASTNODE ptr
620 
621 declare function astNewCONSTz _
622  ( _
623  byval dtype as integer = FB_DATATYPE_CHAR, _
624  byval subtype as FBSYMBOL ptr = NULL _
625  ) as ASTNODE ptr
626 
627 declare function astConstFlushToInt( byval n as ASTNODE ptr ) as longint
628 declare function astConstFlushToStr( byval n as ASTNODE ptr ) as string
629 declare function astConstFlushToWstr( byval n as ASTNODE ptr ) as wstring ptr
630 declare function astConstGetAsInt64( byval n as ASTNODE ptr ) as longint
631 declare function astConstGetAsDouble( byval n as ASTNODE ptr ) as double
632 declare function astBuildConst( byval sym as FBSYMBOL ptr ) as ASTNODE ptr
633 declare function astConvertRawCONSTi _
634  ( _
635  byval dtype as integer, _
636  byval subtype as FBSYMBOL ptr, _
637  byval l as ASTNODE ptr _
638  ) as ASTNODE ptr
639 
640 declare function astNewVAR _
641  ( _
642  byval sym as FBSYMBOL ptr, _
643  byval ofs as longint = 0, _
644  byval dtype as integer = FB_DATATYPE_INVALID, _
645  byval subtype as FBSYMBOL ptr = NULL _
646  ) as ASTNODE ptr
647 
648 declare function astNewIDX _
649  ( _
650  byval v as ASTNODE ptr, _
651  byval i as ASTNODE ptr, _
652  byval dtype as integer, _
653  byval subtype as FBSYMBOL ptr _
654  ) as ASTNODE ptr
655 
656 declare function astNewFIELD _
657  ( _
658  byval l as ASTNODE ptr, _
659  byval sym as FBSYMBOL ptr _
660  ) as ASTNODE ptr
661 declare sub astForgetBitfields( byval n as ASTNODE ptr )
662 declare function astUpdateBitfields( byval n as ASTNODE ptr ) as ASTNODE ptr
663 
664 declare function astNewDEREF _
665  ( _
666  byval l as ASTNODE ptr, _
667  byval dtype as integer = FB_DATATYPE_INVALID, _
668  byval subtype as FBSYMBOL ptr = NULL, _
669  byval ofs as longint = 0 _
670  ) as ASTNODE ptr
671 
672 declare function astNewCALL _
673  ( _
674  byval sym as FBSYMBOL ptr, _
675  byval ptrexpr as ASTNODE ptr = NULL _
676  ) as ASTNODE ptr
677 
678 declare function astNewCALLCTOR _
679  ( _
680  byval procexpr as ASTNODE ptr, _
681  byval instptr as ASTNODE ptr _
682  ) as ASTNODE ptr
683 
684 declare sub astCloneCALL _
685  ( _
686  byval n as ASTNODE ptr, _
687  byval c as ASTNODE ptr _
688  )
689 
690 declare sub astDelCALL _
691  ( _
692  byval n as ASTNODE ptr _
693  )
694 
695 declare function astNewARG _
696  ( _
697  byval f as ASTNODE ptr, _
698  byval p as ASTNODE ptr, _
699  byval dtype as integer = FB_DATATYPE_INVALID, _
700  byval mode as integer = INVALID _
701  ) as ASTNODE ptr
702 
703 declare sub astReplaceInstanceArg _
704  ( _
705  byval parent as ASTNODE ptr, _
706  byval expr as ASTNODE ptr, _
707  byval mode as integer = INVALID _
708  )
709 
710 declare function astNewADDROF _
711  ( _
712  byval l as ASTNODE ptr _
713  ) as ASTNODE ptr
714 
715 declare function astNewLOAD _
716  ( _
717  byval l as ASTNODE ptr, _
718  byval dtype as integer, _
719  byval isresult as integer = FALSE _
720  ) as ASTNODE ptr
721 
722 declare function astNewBRANCH _
723  ( _
724  byval op as integer, _
725  byval label as FBSYMBOL ptr, _
726  byval l as ASTNODE ptr = NULL _
727  ) as ASTNODE ptr
728 
729 declare function astBuildJMPTB _
730  ( _
731  byval tempvar as FBSYMBOL ptr, _
732  byval values1 as ulongint ptr, _
733  byval labels1 as FBSYMBOL ptr ptr, _
734  byval labelcount as integer, _
735  byval deflabel as FBSYMBOL ptr, _
736  byval minval as ulongint, _
737  byval maxval as ulongint _
738  ) as ASTNODE ptr
739 
740 declare function astNewLOOP _
741  ( _
742  byval label as FBSYMBOL ptr, _
743  byval tree as ASTNODE ptr _
744  ) as ASTNODE ptr
745 
746 declare function astNewIIF _
747  ( _
748  byval condexpr as ASTNODE ptr, _
749  byval truexpr as ASTNODE ptr, _
750  byval truecookie as integer, _
751  byval falsexpr as ASTNODE ptr, _
752  byval falsecookie as integer _
753  ) as ASTNODE ptr
754 
755 declare function astNewLINK _
756  ( _
757  byval l as ASTNODE ptr, _
758  byval r as ASTNODE ptr, _
759  byval ret_left as integer = TRUE _
760  ) as ASTNODE ptr
761 
762 declare function astNewSTACK _
763  ( _
764  byval op as integer, _
765  byval l as ASTNODE ptr _
766  ) as ASTNODE ptr
767 
768 declare function astNewLABEL _
769  ( _
770  byval sym as FBSYMBOL ptr, _
771  byval doflush as integer = TRUE _
772  ) as ASTNODE ptr
773 
774 declare function astNewLIT _
775  ( _
776  byval text as zstring ptr _
777  ) as ASTNODE ptr
778 
779 declare function astAsmAppendText _
780  ( _
781  byval tail as ASTASMTOK ptr, _
782  byval text as zstring ptr _
783  ) as ASTASMTOK ptr
784 
785 declare function astAsmAppendSymb _
786  ( _
787  byval tail as ASTASMTOK ptr, _
788  byval sym as FBSYMBOL ptr _
789  ) as ASTASMTOK ptr
790 
791 declare function astNewASM( byval asmtokhead as ASTASMTOK ptr ) as ASTNODE ptr
792 
793 declare function astNewDBG _
794  ( _
795  byval op as integer, _
796  byval ex as integer = 0 _
797  ) as ASTNODE ptr
798 
799 declare function astNewMEM _
800  ( _
801  byval op as integer, _
802  byval l as ASTNODE ptr, _
803  byval r as ASTNODE ptr, _
804  byval bytes as longint = 0 _
805  ) as ASTNODE ptr
806 
807 declare function astBuildNewOp _
808  ( _
809  byval op as AST_OP, _
810  byval tmp as FBSYMBOL ptr, _
811  byval elementsexpr as ASTNODE ptr, _
812  byval initexpr as ASTNODE ptr, _
813  byval dtype as integer, _
814  byval subtype as FBSYMBOL ptr, _
815  byval do_clear as integer, _
816  byval newexpr as ASTNODE ptr _
817  ) as ASTNODE ptr
818 
819 declare function astBuildDeleteOp _
820  ( _
821  byval op as AST_OP, _
822  byval ptrexpr as ASTNODE ptr, _
823  byval dtype as integer, _
824  byval subtype as FBSYMBOL ptr _
825  ) as ASTNODE ptr
826 
827 declare function astNewBOUNDCHK _
828  ( _
829  byval l as ASTNODE ptr, _
830  byval lb as ASTNODE ptr, _
831  byval ub as ASTNODE ptr, _
832  byval linenum as integer, _
833  byval filename as zstring ptr _
834  ) as ASTNODE ptr
835 
836 declare function astBuildBOUNDCHK _
837  ( _
838  byval expr as ASTNODE ptr, _
839  byval lb as ASTNODE ptr, _
840  byval ub as ASTNODE ptr _
841  ) as ASTNODE ptr
842 
843 declare function astNewPTRCHK _
844  ( _
845  byval l as ASTNODE ptr, _
846  byval linenum as integer, _
847  byval filename as zstring ptr _
848  ) as ASTNODE ptr
849 
850 declare function astBuildPTRCHK( byval expr as ASTNODE ptr ) as ASTNODE ptr
851 
852 declare function astNewDECL _
853  ( _
854  byval sym as FBSYMBOL ptr, _
855  byval do_defaultinit as integer _
856  ) as ASTNODE ptr
857 
858 declare function astNewNIDXARRAY _
859  ( _
860  byval expr as ASTNODE ptr _
861  ) as ASTNODE ptr
862 
863 declare function astNewNode _
864  ( _
865  byval class_ as integer, _
866  byval dtype as integer, _
867  byval subtype as FBSYMBOL ptr = NULL _
868  ) as ASTNODE ptr
869 
870 declare function astLoad _
871  ( _
872  byval n as ASTNODE ptr _
873  ) as IRVREG ptr
874 
875 declare function astOptimizeTree _
876  ( _
877  byval n as ASTNODE ptr _
878  ) as ASTNODE ptr
879 
880 declare function astOptAssignment _
881  ( _
882  byval n as ASTNODE ptr _
883  ) as ASTNODE ptr
884 
885 declare sub astCheckConst _
886  ( _
887  byval dtype as integer, _
888  byval n as ASTNODE ptr _
889  )
890 
891 declare function astCheckASSIGN _
892  ( _
893  byval l as ASTNODE ptr, _
894  byval r as ASTNODE ptr _
895  ) as integer
896 
897 declare function astCheckASSIGNToType _
898  ( _
899  byval ldtype as integer, _
900  byval lsubtype as FBSYMBOL ptr, _
901  byval r as ASTNODE ptr _
902  ) as integer
903 
904 declare function astCheckCONV _
905  ( _
906  byval to_dtype as integer, _
907  byval to_subtype as FBSYMBOL ptr, _
908  byval l as ASTNODE ptr _
909  ) as integer
910 
911 declare function astUpdStrConcat( byval n as ASTNODE ptr ) as ASTNODE ptr
912 
913 declare function astIsClassOnTree _
914  ( _
915  byval class_ as integer, _
916  byval n as ASTNODE ptr _
917  ) as ASTNODE ptr
918 
919 declare function astIsSymbolOnTree _
920  ( _
921  byval sym as FBSYMBOL ptr, _
922  byval n as ASTNODE ptr _
923  ) as integer
924 
925 declare function astGetStrLitSymbol _
926  ( _
927  byval n as ASTNODE ptr _
928  ) as FBSYMBOL ptr
929 
930 declare function astTypeIniBegin _
931  ( _
932  byval dtype as integer, _
933  byval subtype as FBSYMBOL ptr, _
934  byval is_local as integer, _
935  byval ofs as longint = 0 _
936  ) as ASTNODE ptr
937 
938 declare sub astTypeIniEnd _
939  ( _
940  byval tree as ASTNODE ptr, _
941  byval is_initializer as integer _
942  )
943 
944 declare function astTypeIniAddPad _
945  ( _
946  byval tree as ASTNODE ptr, _
947  byval bytes as longint _
948  ) as ASTNODE ptr
949 
950 declare function astTypeIniAddAssign _
951  ( _
952  byval tree as ASTNODE ptr, _
953  byval expr as ASTNODE ptr, _
954  byval sym as FBSYMBOL ptr _
955  ) as ASTNODE ptr
956 
957 declare function astTypeIniAddCtorCall _
958  ( _
959  byval tree as ASTNODE ptr, _
960  byval sym as FBSYMBOL ptr, _
961  byval procexpr as ASTNODE ptr _
962  ) as ASTNODE ptr
963 
964 declare function astTypeIniAddCtorList _
965  ( _
966  byval tree as ASTNODE ptr, _
967  byval sym as FBSYMBOL ptr, _
968  byval elements as longint _
969  ) as ASTNODE ptr
970 
971 declare function astTypeIniScopeBegin _
972  ( _
973  byval tree as ASTNODE ptr, _
974  byval sym as FBSYMBOL ptr _
975  ) as ASTNODE ptr
976 
977 declare function astTypeIniScopeEnd _
978  ( _
979  byval tree as ASTNODE ptr, _
980  byval sym as FBSYMBOL ptr _
981  ) as ASTNODE ptr
982 
983 declare sub astTypeIniCopyElements _
984  ( _
985  byval tree as ASTNODE ptr, _
986  byval source as ASTNODE ptr, _
987  byval beginindex as integer _
988  )
989 
990 declare sub astTypeIniReplaceElement _
991  ( _
992  byval tree as ASTNODE ptr, _
993  byval element as integer, _
994  byval expr as ASTNODE ptr _
995  )
996 
997 declare function astTypeIniFlush _
998  ( _
999  byval tree as ASTNODE ptr, _
1000  byval basesym as FBSYMBOL ptr, _
1001  byval options as AST_INIOPT _
1002  ) as ASTNODE ptr
1003 
1004 declare function astTypeIniIsConst _
1005  ( _
1006  byval tree as ASTNODE ptr _
1007  ) as integer
1008 
1009 declare function astTypeIniUsesLocals _
1010  ( _
1011  byval n as ASTNODE ptr, _
1012  byval ignoreattrib as integer _
1013  ) as integer
1014 
1015 declare function astTypeIniUpdate _
1016  ( _
1017  byval tree as ASTNODE ptr _
1018  ) as ASTNODE ptr
1019 
1020 declare function astTypeIniClone( byval tree as ASTNODE ptr ) as ASTNODE ptr
1021 declare function astTypeIniTryRemove( byval tree as ASTNODE ptr ) as ASTNODE ptr
1022 declare sub astTypeIniDelete( byval tree as ASTNODE ptr )
1023 
1024 declare function astDataStmtBegin( ) as ASTNODE ptr
1025 
1026 declare function astDataStmtStore _
1027  ( _
1028  byval tree as ASTNODE ptr, _
1029  byval expr as ASTNODE ptr _
1030  ) as ASTNODE ptr
1031 
1032 declare sub astDataStmtEnd( byval tree as ASTNODE ptr )
1033 
1034 declare function astDataStmtAdd _
1035  ( _
1036  byval label as FBSYMBOL ptr, _
1037  byval elements as integer _
1038  ) as FBSYMBOL ptr
1039 
1040 declare function astGetInverseLogOp _
1041  ( _
1042  byval op as integer _
1043  ) as integer
1044 
1045 declare function astRemSideFx( byref n as ASTNODE ptr ) as ASTNODE ptr
1046 
1047 declare function astBuildVarDeref( byval sym as FBSYMBOL ptr ) as ASTNODE ptr
1048 declare function astBuildVarAddrof( byval sym as FBSYMBOL ptr ) as ASTNODE ptr
1049 
1050 declare function astBuildVarInc _
1051  ( _
1052  byval lhs as FBSYMBOL ptr, _
1053  byval rhs as integer _
1054  ) as ASTNODE ptr
1055 
1056 declare function astBuildVarAssign overload _
1057  ( _
1058  byval lhs as FBSYMBOL ptr, _
1059  byval rhs as integer _
1060  ) as ASTNODE ptr
1061 
1062 declare function astBuildVarAssign _
1063  ( _
1064  byval lhs as FBSYMBOL ptr, _
1065  byval rhs as ASTNODE ptr _
1066  ) as ASTNODE ptr
1067 
1068 declare function astBuildFakeWstringAccess( byval sym as FBSYMBOL ptr ) as ASTNODE ptr
1069 declare function astBuildFakeWstringAssign _
1070  ( _
1071  byval sym as FBSYMBOL ptr, _
1072  byval expr as ASTNODE ptr, _
1073  byval options as integer = 0 _
1074  ) as ASTNODE ptr
1075 
1076 declare function astBuildVarField _
1077  ( _
1078  byval sym as FBSYMBOL ptr, _
1079  byval fld as FBSYMBOL ptr = NULL, _
1080  byval ofs as longint = 0 _
1081  ) as ASTNODE ptr
1082 
1083 declare function astBuildTempVarClear( byval sym as FBSYMBOL ptr ) as ASTNODE ptr
1084 
1085 declare function astBuildCall _
1086  ( _
1087  byval proc as FBSYMBOL ptr, _
1088  byval arg1 as ASTNODE ptr = NULL, _
1089  byval arg2 as ASTNODE ptr = NULL, _
1090  byval arg3 as ASTNODE ptr = NULL _
1091  ) as ASTNODE ptr
1092 
1093 declare function astBuildVtableLookup _
1094  ( _
1095  byval proc as FBSYMBOL ptr, _
1096  byval thisexpr as ASTNODE ptr _
1097  ) as ASTNODE ptr
1098 
1099 declare function astBuildCtorCall _
1100  ( _
1101  byval sym as FBSYMBOL ptr, _
1102  byval thisexpr as ASTNODE ptr _
1103  ) as ASTNODE ptr
1104 
1105 declare function astBuildDtorCall _
1106  ( _
1107  byval sym as FBSYMBOL ptr, _
1108  byval thisexpr as ASTNODE ptr, _
1109  byval ignore_virtual as integer = FALSE _
1110  ) as ASTNODE ptr
1111 
1112 declare function astBuildForBegin _
1113  ( _
1114  byval tree as ASTNODE ptr, _
1115  byval cnt as FBSYMBOL ptr, _
1116  byval label as FBSYMBOL ptr, _
1117  byval inivalue as integer, _
1118  byval flush_label as integer = TRUE _
1119  ) as ASTNODE ptr
1120 
1121 declare function astBuildForEnd _
1122  ( _
1123  byval tree as ASTNODE ptr, _
1124  byval cnt as FBSYMBOL ptr, _
1125  byval label as FBSYMBOL ptr, _
1126  byval endvalue as ASTNODE ptr _
1127  ) as ASTNODE ptr
1128 
1129 declare function astBuildInstPtr _
1130  ( _
1131  byval sym as FBSYMBOL ptr, _
1132  byval fld as FBSYMBOL ptr = NULL, _
1133  byval idxexpr as ASTNODE ptr = NULL _
1134  ) as ASTNODE ptr
1135 
1136 declare function astBuildInstPtrAtOffset _
1137  ( _
1138  byval sym as FBSYMBOL ptr, _
1139  byval fld as FBSYMBOL ptr = NULL, _
1140  byval ofs as longint = 0 _
1141  ) as ASTNODE ptr
1142 
1143 declare function astBuildVarDtorCall _
1144  ( _
1145  byval s as FBSYMBOL ptr, _
1146  byval check_access as integer = FALSE _
1147  ) as ASTNODE ptr
1148 
1149 declare function astBuildTypeIniCtorList _
1150  ( _
1151  byval sym as FBSYMBOL ptr _
1152  ) as ASTNODE ptr
1153 
1154 declare function astBuildProcAddrof( byval proc as FBSYMBOL ptr ) as ASTNODE ptr
1155 
1156 declare function astBuildProcResultVar _
1157  ( _
1158  byval proc as FBSYMBOL ptr, _
1159  byval sym as FBSYMBOL ptr _
1160  ) as ASTNODE ptr
1161 
1162 declare function astPatchCtorCall _
1163  ( _
1164  byval procexpr as ASTNODE ptr, _
1165  byval thisexpr as ASTNODE ptr _
1166  ) as ASTNODE ptr
1167 
1168 declare function astCALLCTORToCALL _
1169  ( _
1170  byval n as ASTNODE ptr _
1171  ) as ASTNODE ptr
1172 
1173 declare function astBuildImplicitCtorCall _
1174  ( _
1175  byval subtype as FBSYMBOL ptr, _
1176  byval expr as ASTNODE ptr, _
1177  byval arg_mode as FB_PARAMMODE, _
1178  byref is_ctorcall as integer _
1179  ) as ASTNODE ptr
1180 
1181 declare function astBuildImplicitCtorCallEx _
1182  ( _
1183  byval sym as FBSYMBOL ptr, _
1184  byval expr as ASTNODE ptr, _
1185  byval arg_mode as FB_PARAMMODE, _
1186  byref is_ctorcall as integer _
1187  ) as ASTNODE ptr
1188 
1189 declare function astBuildArrayDescIniTree _
1190  ( _
1191  byval desc as FBSYMBOL ptr, _
1192  byval array as FBSYMBOL ptr, _
1193  byval array_expr as ASTNODE ptr _
1194  ) as ASTNODE ptr
1195 
1196 declare function astBuildArrayBound _
1197  ( _
1198  byval arrayexpr as ASTNODE ptr, _
1199  byval dimexpr as ASTNODE ptr, _
1200  byval tk as integer _
1201  ) as ASTNODE ptr
1202 
1203 declare function astBuildStrPtr( byval lhs as ASTNODE ptr ) as ASTNODE ptr
1204 
1205 declare function astBuildMultiDeref _
1206  ( _
1207  byval cnt as integer, _
1208  byval expr as ASTNODE ptr, _
1209  byval dtype as integer, _
1210  byval subtype as FBSYMBOL ptr _
1211  ) as ASTNODE ptr
1212 
1213 declare sub astReplaceSymbolOnTree _
1214  ( _
1215  byval n as ASTNODE ptr, _
1216  byval old_sym as FBSYMBOL ptr, _
1217  byval new_sym as FBSYMBOL ptr _
1218  )
1219 
1220 declare sub astReplaceFwdref _
1221  ( _
1222  byval n as ASTNODE ptr, _
1223  byval oldsubtype as FBSYMBOL ptr, _
1224  byval newdtype as integer, _
1225  byval newsubtype as FBSYMBOL ptr _
1226  )
1227 
1228 #if __FB_DEBUG__
1229 declare sub astDtorListDump( )
1230 #endif
1231 declare sub astDtorListAdd( byval sym as FBSYMBOL ptr )
1232 declare sub astDtorListAddRef( byval sym as FBSYMBOL ptr )
1233 declare sub astDtorListRemoveRef( byval sym as FBSYMBOL ptr )
1234 declare function astDtorListFlush( byval cookie as integer = 0 ) as ASTNODE ptr
1235 declare sub astDtorListDel( byval sym as FBSYMBOL ptr )
1236 declare sub astDtorListScopeBegin( byval cookie as integer = 0 )
1237 declare function astDtorListScopeEnd( ) as integer
1238 declare sub astDtorListUnscope( byval cookie as integer )
1239 
1240 declare sub astSetType _
1241  ( _
1242  byval n as ASTNODE ptr, _
1243  byval dtype as integer, _
1244  byval subtype as FBSYMBOL ptr _
1245  )
1246 
1247 declare function astSizeOf( byval n as ASTNODE ptr ) as longint
1248 declare function astIsAccessToLocal( byval expr as ASTNODE ptr ) as integer
1249 
1250 declare function astGetOFFSETChildOfs( byval l as ASTNODE ptr ) as longint
1251 
1252 declare function astBuildCallResultVar( byval expr as ASTNODE ptr ) as ASTNODE ptr
1253 declare function astBuildCallResultUdt( byval expr as ASTNODE ptr ) as ASTNODE ptr
1254 declare function astBuildByrefResultDeref( byval expr as ASTNODE ptr ) as ASTNODE ptr
1255 declare function astIsByrefResultDeref( byval expr as ASTNODE ptr ) as integer
1256 declare function astRemoveByrefResultDeref( byval expr as ASTNODE ptr ) as ASTNODE ptr
1257 
1258 declare sub astGosubAddInit( byval proc as FBSYMBOL ptr )
1259 
1260 declare sub astGosubAddJmp _
1261  ( _
1262  byval proc as FBSYMBOL ptr, _
1263  byval l as FBSYMBOL ptr _
1264  )
1265 
1266 declare sub astGosubAddJumpPtr _
1267  ( _
1268  byval proc as FBSYMBOL ptr, _
1269  byval expr as ASTNODE ptr, _
1270  byval exitlabel as FBSYMBOL ptr _
1271  )
1272 
1273 declare function astGosubAddReturn _
1274  ( _
1275  byval proc as FBSYMBOL ptr, _
1276  byval l as FBSYMBOL ptr _
1277  ) as integer
1278 
1279 declare sub astGosubAddExit(byval proc as FBSYMBOL ptr)
1280 
1281 declare function hTruncateInt _
1282  ( _
1283  byval dtype as integer, _
1284  byval value as integer ptr _
1285  ) as integer
1286 
1287 declare function astLoadNOP( byval n as ASTNODE ptr ) as IRVREG ptr
1288 declare function astLoadASSIGN( byval n as ASTNODE ptr ) as IRVREG ptr
1289 declare function astLoadCONV( byval n as ASTNODE ptr ) as IRVREG ptr
1290 declare function astLoadBOP( byval n as ASTNODE ptr ) as IRVREG ptr
1291 declare function astLoadUOP( byval n as ASTNODE ptr ) as IRVREG ptr
1292 declare function astLoadCONST( byval n as ASTNODE ptr ) as IRVREG ptr
1293 declare function astLoadVAR( byval n as ASTNODE ptr ) as IRVREG ptr
1294 declare function astLoadIDX( byval n as ASTNODE ptr ) as IRVREG ptr
1295 declare function astLoadDEREF( byval n as ASTNODE ptr ) as IRVREG ptr
1296 declare function astLoadCALL( byval n as ASTNODE ptr ) as IRVREG ptr
1297 declare function astLoadCALLCTOR( byval n as ASTNODE ptr ) as IRVREG ptr
1298 declare function astLoadADDROF( byval n as ASTNODE ptr ) as IRVREG ptr
1299 declare function astLoadLOAD( byval n as ASTNODE ptr ) as IRVREG ptr
1300 declare function astLoadBRANCH( byval n as ASTNODE ptr ) as IRVREG ptr
1301 declare function astLoadIIF( byval n as ASTNODE ptr ) as IRVREG ptr
1302 declare function astLoadOFFSET( byval n as ASTNODE ptr ) as IRVREG ptr
1303 declare function astLoadLINK( byval n as ASTNODE ptr ) as IRVREG ptr
1304 declare function astLoadFIELD( byval n as ASTNODE ptr ) as IRVREG ptr
1305 declare function astLoadSTACK( byval n as ASTNODE ptr ) as IRVREG ptr
1306 declare function astLoadLABEL( byval n as ASTNODE ptr ) as IRVREG ptr
1307 declare function astLoadLIT( byval n as ASTNODE ptr ) as IRVREG ptr
1308 declare function astLoadASM( byval n as ASTNODE ptr ) as IRVREG ptr
1309 declare function astLoadJMPTB( byval n as ASTNODE ptr ) as IRVREG ptr
1310 declare function astLoadLOOP( byval n as ASTNODE ptr ) as IRVREG ptr
1311 declare function astLoadDBG( byval n as ASTNODE ptr ) as IRVREG ptr
1312 declare function astLoadMEM( byval n as ASTNODE ptr ) as IRVREG ptr
1313 declare function astLoadBOUNDCHK( byval n as ASTNODE ptr ) as IRVREG ptr
1314 declare function astLoadPTRCHK( byval n as ASTNODE ptr ) as IRVREG ptr
1315 declare function astLoadSCOPEBEGIN( byval n as ASTNODE ptr ) as IRVREG ptr
1316 declare function astLoadSCOPEEND( byval n as ASTNODE ptr ) as IRVREG ptr
1317 declare function astLoadDECL( byval n as ASTNODE ptr ) as IRVREG ptr
1318 declare function astLoadNIDXARRAY( byval n as ASTNODE ptr ) as IRVREG ptr
1319 
1320 ''
1321 '' macros
1322 ''
1323 #macro astInitNode( n, class_, dtype_, subtype_ )
1324  (n)->class = class_
1325  (n)->dtype = dtype_
1326  (n)->subtype = subtype_
1327  (n)->l = NULL
1328  (n)->r = NULL
1329  (n)->sym = NULL
1330  (n)->vector = 0
1331 #endmacro
1332 
1333 #define astCopy(dst, src) *dst = *src
1334 
1335 #define astSwap(dst, src) swap *dst, *src
1336 
1337 #define astGetClass(n) n->class
1338 
1339 #define astGetLeft( n ) n->l
1340 
1341 #define astGetRight( n ) n->r
1342 
1343 #define astGetPrev( n ) n->prev
1344 
1345 #define astGetNext( n ) n->next
1346 
1347 #define astIsCONST(n) (n->class = AST_NODECLASS_CONST)
1348 
1349 #define astIsVAR(n) (n->class = AST_NODECLASS_VAR)
1350 
1351 #define astIsIDX(n) (n->class = AST_NODECLASS_IDX)
1352 
1353 #define astIsCALL(n) (n->class = AST_NODECLASS_CALL)
1354 
1355 #define astIsCALLCTOR(n) (n->class = AST_NODECLASS_CALLCTOR)
1356 
1357 #define astIsDEREF(n) (n->class = AST_NODECLASS_DEREF)
1358 
1359 #define astIsOFFSET(n) (n->class = AST_NODECLASS_OFFSET)
1360 
1361 #define astIsFIELD(n) (n->class = AST_NODECLASS_FIELD)
1362 
1363 #define astIsBITFIELD(n) iif( astIsFIELD(n), (astGetDataType( astGetLeft( n ) ) = FB_DATATYPE_BITFIELD), FALSE )
1364 
1365 #define astIsNIDXARRAY(n) (n->class = AST_NODECLASS_NIDXARRAY)
1366 
1367 #define astIsTYPEINI(n) (n->class = AST_NODECLASS_TYPEINI)
1368 
1369 #define astIsCAST(n) (n->class = AST_NODECLASS_CONV)
1370 
1371 #define astConstGetVal( n ) (@(n)->val)
1372 #define astConstGetFloat( n ) ((n)->val.f)
1373 #define astConstGetInt( n ) ((n)->val.i)
1374 #define astConstGetUint( n ) cunsg( (n)->val.i )
1375 
1376 #define astGetFullType(n) n->dtype
1377 #define astGetDataType(n) typeGetDtAndPtrOnly( astGetFullType( n ) )
1378 
1379 #define astGetSubtype(n) n->subtype
1380 
1381 #define astGetDataClass(n) typeGetClass( astGetDataType( n ) )
1382 
1383 #define astGetSymbol(n) n->sym
1384 
1385 #define astGetProcExitlabel(n) n->block.exitlabel
1386 
1387 #define astGetProc() ast.proc.curr
1388 
1389 #define astGetProcTailNode() ast.proc.curr->r
1390 
1391 #define astTypeIniGetOfs( n ) n->typeini.ofs
1392 
1393 #define astGetOpClass( op ) ast_opTB(op).class
1394 
1395 #define astGetOpIsCommutative( op ) ((ast_opTB(op).flags and AST_OPFLAGS_COMM) <> 0)
1396 
1397 #define astGetOpIsSelf( op ) ((ast_opTB(op).flags and AST_OPFLAGS_SELF) <> 0)
1398 
1399 #define astGetOpNoResult( op ) ((ast_opTB(op).flags and AST_OPFLAGS_NORES) <> 0)
1400 
1401 #define astGetOpSelfVer( op ) ast_opTB(op).selfop
1402 
1403 #define astGetOpId( op ) ast_opTB(op).id
1404 
1405 #define astGetFirstDataStmtSymbol( ) ast.data.firstsym
1406 
1407 #define astGetLastDataStmtSymbol( ) ast.data.lastsym
1408 
1409 #define astDTorListIsEmpty( ) (listGetHead( @ast.dtorlist ) = NULL)
1410 
1411 #define astGetCastDoConv( n ) n->cast.doconv
1412 
1413 #define astIsUOP( n, uop ) ( ((n)->class = AST_NODECLASS_UOP) andalso ((n)->op.op = (uop)) )
1414 
1415 #define astIsBOP( n, bop ) ( ((n)->class = AST_NODECLASS_BOP) andalso ((n)->op.op = (bop)) )
1416 
1417 ''
1418 '' inter-module globals
1419 ''
1420 extern ast as ASTCTX
1421 
1422 extern ast_bitmaskTB( 0 to 32 ) as uinteger
1423 
1424 extern ast_opTB( 0 to AST_OPCODES-1 ) as AST_OPINFO
1425 
1426 declare function astDumpOp( byval op as AST_OP ) as string
1427 
1428 declare sub astDumpTree _
1429  ( _
1430  byval n as ASTNODE ptr, _
1431  byval col as integer = 0 _
1432  )
1433 
1434 declare sub astDumpList _
1435  ( _
1436  byval n as ASTNODE ptr, _
1437  byval col as integer = 0 _
1438  )
1439 
1440 #if __FB_DEBUG__
1441 declare function astDumpInline( byval n as ASTNODE ptr ) as string
1442 #endif
1443 
1444 #endif '' __AST_BI__
1445