FreeBASIC  0.91.0
ast-node-idx.bas
Go to the documentation of this file.
1 '' AST array index nodes
2 '' l = index expression; r = var expression
3 ''
4 '' chng: sep/2004 written [v1ctor]
5 
6 
7 #include once "fb.bi"
8 #include once "fbint.bi"
9 #include once "ir.bi"
10 #include once "ast.bi"
11 
12 '':::::
13 function astNewIDX _
14  ( _
15  byval var_ as ASTNODE ptr, _
16  byval idx as ASTNODE ptr, _
17  byval dtype as integer, _
18  byval subtype as FBSYMBOL ptr _
19  ) as ASTNODE ptr
20 
21  dim as ASTNODE ptr n = any
22 
23  if( dtype = FB_DATATYPE_INVALID ) then
24  dtype = astGetFullType( var_ )
25  subtype = astGetSubType( var_ )
26  end if
27 
28  '' alloc new node
29  n = astNewNode( AST_NODECLASS_IDX, dtype, subtype )
30 
31  n->l = idx
32  n->r = var_
33  n->sym = var_->sym
34  n->idx.mult = 1
35  n->idx.ofs = 0
36 
37  function = n
38 
39 end function
40 
41 function astLoadIDX( byval n as ASTNODE ptr ) as IRVREG ptr
42  dim as ASTNODE ptr var_ = any, idx = any
43  dim as IRVREG ptr vidx = any, vr = any
44  dim as FBSYMBOL ptr s = any
45  dim as longint ofs = any
46 
47  var_ = n->r
48  if( var_ = NULL ) then
49  return NULL
50  end if
51 
52  idx = n->l
53  if( idx <> NULL ) then
54  vidx = astLoad( idx )
55  else
56  vidx = NULL
57  end if
58 
59  if( ast.doemit ) then
60  '' ofs * length + difference (non-base 0 indexes) + offset (UDT's offset)
61  s = var_->sym
62 
63  symbSetIsAccessed( s )
64 
65  ofs = n->idx.ofs
66  if( symbGetIsDynamic( s ) = FALSE ) then
67  ofs += symbGetArrayDiff( s ) + symbGetOfs( s ) + var_->var_.ofs
68  else
69  s = NULL
70  end if
71 
72  if( vidx <> NULL ) then
73  '' not a reg already? load
74  if( irIsREG( vidx ) = FALSE ) then
75  irEmitLOAD( vidx )
76  end if
77 
78  vr = irAllocVRIDX( astGetDataType( n ), n->subtype, s, ofs, n->idx.mult, vidx )
79  else
80  vr = irAllocVRVAR( astGetDataType( n ), n->subtype, s, ofs )
81  end if
82 
83  vr->vector = n->vector
84  end if
85 
86  astDelNode( idx )
87  astDelNode( var_ )
88 
89  function = vr
90 end function
91